/* MyBudget — feuille de style unique.
   Palette des séries : palette de référence validée (daltonisme, contraste) ; voir README. */

:root {
  color-scheme: light;
  --plane: #f1f3ee;
  --surface: #ffffff;
  --ink: #17211b;
  --ink-2: #5a665e;
  --line: #e0e4dc;
  --line-strong: #c8cec4;
  --accent: #2c3fd6;
  --accent-ink: #ffffff;
  --accent-wash: #e6e9fb;

  --grid: #e7e7e7;
  --axis: #c2c2c2;
  --neutral: #9aa39d;
  --series-1: #257de0;
  --series-2: #f47230;
  --series-3: #00b894;
  --series-4: #f2a600;
  --series-5: #ee7fac;
  --series-6: #008a17;
  --series-7: #6a4ce2;
  --series-8: #ec4647;

  --good: #0aac23;
  --warning: #fbb315;
  --critical: #dc3c3d;
  --good-text: #006c10;
  --warn-text: #8a5a00;
  --crit-text: #c4272a;
  --crit-solid: #c4272a;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --plane: #0b0b0b;
    --surface: #191919;
    --ink: #efefef;
    --ink-2: #9c9c9c;
    --line: #2a2a2a;
    --line-strong: #3d3d3d;
    --accent: #8d9bff;
    --accent-ink: #0b0b0b;
    --accent-wash: #1d2142;

    --grid: #303030;
    --axis: #474747;
    --neutral: #6f7772;
    --series-1: #338ced;
    --series-2: #e76624;
    --series-3: #00a888;
    --series-4: #d28e05;
    --series-5: #e24d8b;
    --series-6: #0aac23;
    --series-7: #9887ef;
    --series-8: #eb6263;

    --good-text: #53c556;
    --warn-text: #f5b93a;
    --crit-text: #ff7c7d;
    --crit-solid: #b3282b;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--plane);
  color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { line-height: 1.2; letter-spacing: -0.01em; }
h1 { margin: 0; font-size: 24px; font-weight: 650; }
h2 { margin: 0 0 12px; font-size: 17px; font-weight: 650; }
p { margin: 0 0 12px; }
a { color: var(--accent); text-underline-offset: 3px; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 60%, transparent); outline-offset: 2px; }

.i { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-2); }
.small { font-size: 14px; }
.strong { font-weight: 700; }
.lead { max-width: 64ch; margin: 0 0 24px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.desktop-only { display: none !important; }

/* ---------- Structure ---------- */
.shell { min-height: 100dvh; }
.rail { display: none; }
.main { padding: 20px 16px calc(104px + env(safe-area-inset-bottom)); }

@media (min-width: 900px) {
  .shell { display: grid; grid-template-columns: 248px minmax(0, 1fr); }
  .main { padding: 32px 44px 72px; max-width: 1160px; width: 100%; }
  .desktop-only { display: inline-flex !important; }
  .rail {
    display: flex; flex-direction: column; position: sticky; top: 0; height: 100dvh;
    padding: 24px 16px; border-right: 1px solid var(--line);
  }
  .brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 26px; font-size: 18px; font-weight: 700; color: var(--ink); text-decoration: none; }
  .brand .mark { width: 30px; height: 30px; color: var(--accent); }
  .rail nav { display: flex; flex-direction: column; gap: 2px; }
  .rail nav a, .rail .link {
    display: flex; align-items: center; gap: 12px; width: 100%; padding: 10px 12px;
    border-radius: 10px; color: var(--ink-2); font-weight: 560; text-decoration: none;
  }
  .rail nav a:hover, .rail .link:hover { background: color-mix(in srgb, var(--ink) 6%, transparent); color: var(--ink); }
  .rail nav a[aria-current="page"] { background: var(--accent-wash); color: var(--ink); }
  .rail hr { border: 0; border-top: 1px solid var(--line); margin: 10px 8px; }
  .rail-foot { margin-top: auto; }
  .tabbar { display: none !important; }
}
.link { background: none; border: 0; font: inherit; cursor: pointer; text-align: left; }

.tabbar {
  position: fixed; inset: auto 0 0 0; z-index: 20;
  display: grid; grid-template-columns: repeat(5, 1fr); align-items: end;
  padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
  background: var(--surface); border-top: 1px solid var(--line);
}
.tabbar a { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 0; color: var(--ink-2); font-size: 11px; font-weight: 560; text-decoration: none; }
.tabbar a[aria-current="page"] { color: var(--accent); }
.tabbar .add {
  width: 56px; height: 56px; margin: -22px auto 2px; padding: 0; justify-content: center;
  border-radius: 50%; background: var(--accent); color: var(--accent-ink);
  box-shadow: 0 4px 14px color-mix(in srgb, var(--accent) 45%, transparent);
}
.tabbar .add .i { width: 26px; height: 26px; stroke-width: 2.2; }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.month-nav { display: flex; align-items: center; gap: 4px; }
.month-nav h1 { min-width: 11ch; text-align: center; text-transform: capitalize; }
.icon-btn { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; color: var(--ink); }
.icon-btn:hover { background: color-mix(in srgb, var(--ink) 8%, transparent); }

.two-col { display: grid; gap: 8px 40px; }
@media (min-width: 900px) {
  .two-col { grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); }
  .two-col.even { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
.block { margin-bottom: 32px; }
.block-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 12px; }
.block-head h2 { margin: 0; }

/* ---------- Accueil : le chiffre du mois ---------- */
.hero { display: grid; gap: 22px; padding: 4px 0 28px; margin-bottom: 28px; border-bottom: 1px solid var(--line); }
@media (min-width: 800px) { .hero:not(.compact) { grid-template-columns: minmax(0, 1.5fr) minmax(240px, 1fr); align-items: end; } }
.kicker { margin: 0; font-size: 14px; color: var(--ink-2); }
.hero-figure { margin: 2px 0 8px; font-size: clamp(48px, 11vw, 76px); line-height: 1; font-weight: 700; letter-spacing: -0.035em; }
.hero-figure.is-negative { color: var(--crit-text); }
.hero-sub { margin: 0; color: var(--ink-2); }
.hero-side { display: grid; margin: 0; }
.hero-side div { display: flex; justify-content: space-between; align-items: baseline; gap: 16px; padding: 11px 0; border-top: 1px solid var(--line); }
.hero-side dt { color: var(--ink-2); font-size: 14px; }
.hero-side dd { margin: 0; font-weight: 650; }

.bar-thin { display: flex; gap: 2px; height: 8px; margin: 18px 0 10px; border-radius: 999px; overflow: hidden; background: color-mix(in srgb, var(--ink) 8%, var(--plane)); }
.seg { display: block; flex: 0 0 var(--w); }
.seg.expense, .sw.expense { background: var(--series-2); }
.seg.savings, .sw.savings { background: var(--series-3); }
.seg.left, .sw.left { background: var(--series-1); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 20px; margin: 0 0 12px; padding: 0; list-style: none; font-size: 14px; color: var(--ink-2); }
.legend .num { color: var(--ink); font-weight: 600; }
.sw { display: inline-block; width: 10px; height: 10px; margin-right: 6px; border-radius: 3px; }

.status { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; font-weight: 600; }
.status .i { width: 16px; height: 16px; stroke-width: 2; }
.status.good { color: var(--good-text); }
.status.warn { color: var(--warn-text); }
.status.crit { color: var(--crit-text); }

.dot { display: inline-block; flex: none; width: 10px; height: 10px; border-radius: 50%; background: var(--neutral); }
.s1 { background: var(--series-1); } .s2 { background: var(--series-2); } .s3 { background: var(--series-3); }
.s4 { background: var(--series-4); } .s5 { background: var(--series-5); } .s6 { background: var(--series-6); }
.s7 { background: var(--series-7); } .s8 { background: var(--series-8); } .s0 { background: var(--neutral); }

/* Lignes prévu / réalisé avec jauge */
.rows { margin: 0; padding: 0; list-style: none; }
.row {
  display: grid; align-items: center; gap: 6px 12px; padding: 12px 0; border-bottom: 1px solid var(--line);
  grid-template-columns: 12px minmax(0, 1fr) auto;
  grid-template-areas: "dot name end" ". meter meter";
}
.row > .dot { grid-area: dot; }
.row-name { grid-area: name; display: flex; flex-direction: column; min-width: 0; }
.row-name a { color: var(--ink); font-weight: 600; text-decoration: none; }
.row-name a:hover { text-decoration: underline; }
.row .meter { grid-area: meter; }
.row-end { grid-area: end; text-align: right; font-size: 14px; white-space: nowrap; }
@media (min-width: 1100px) {
  .row { grid-template-columns: 12px minmax(0, 1.2fr) minmax(80px, 1fr) 128px; grid-template-areas: "dot name meter end"; }
}

.meter { --fill: var(--series-1); position: relative; height: 8px; border-radius: 999px; background: color-mix(in srgb, var(--fill) 20%, var(--plane)); }
.meter > i { position: absolute; inset: 0 auto 0 0; width: var(--w); border-radius: 999px; background: var(--fill); }
.meter.warn { --fill: var(--warning); }
.meter.over { --fill: var(--critical); }
.meter.unplanned { --fill: var(--neutral); }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 16px; }
.chart-box { position: relative; height: 260px; }
.data-table { margin-top: 12px; }
.data-table summary { cursor: pointer; color: var(--ink-2); font-size: 14px; }
.data-table .table { margin-top: 10px; }

/* Listes d'opérations */
.tx-list, .list { margin: 0; padding: 0; list-style: none; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.tx { display: grid; grid-template-columns: 12px minmax(0, 1fr) auto; align-items: center; gap: 12px; padding: 12px 16px; color: inherit; text-decoration: none; }
.tx-list li + li .tx, .list li + li .list-row { border-top: 1px solid var(--line); }
.tx:hover, .list-row:hover { background: color-mix(in srgb, var(--ink) 4%, var(--surface)); }
.tx-main { display: flex; flex-direction: column; min-width: 0; }
.tx-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 560; }
.amount { white-space: nowrap; font-weight: 600; }
.amount.in { color: var(--good-text); }
.tx-list.compact .tx { padding: 10px 14px; }
.day-title { margin: 22px 0 8px; font-size: 14px; font-weight: 600; color: var(--ink-2); text-transform: capitalize; }
.day:first-of-type .day-title { margin-top: 8px; }
.totals { margin: 0 0 4px; }
.totals b { color: var(--ink); }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 24px; }
.foot-actions { margin-top: 28px; }
.foot-actions a { display: inline-flex; align-items: center; gap: 8px; }

.list-row { display: flex; align-items: center; gap: 12px; padding: 14px 16px; color: inherit; text-decoration: none; width: 100%; }
.grow { flex: 1; min-width: 0; }
.block-line { display: block; }
.menu .i { color: var(--ink-2); }
.more-logout { margin-top: 20px; }

.tag { display: inline-block; margin-left: 6px; padding: 1px 8px; border-radius: 999px; background: var(--accent-wash); color: var(--ink); font-size: 12px; font-weight: 600; }

/* ---------- Formulaires ---------- */
.form, .tx-form { max-width: 580px; }
.field { margin: 0 0 22px; padding: 0; border: 0; min-width: 0; }
.field > label, .label { display: block; margin-bottom: 6px; font-size: 14px; font-weight: 600; }
.field input:not([type="radio"]):not([type="checkbox"]), .field select,
.filters input, .filters select, .bfield input, .login .field input {
  width: 100%; min-height: 46px; padding: 10px 14px; font: inherit; color: inherit;
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: 10px;
}
.field input:focus, .field select:focus, .bfield input:focus, .filters input:focus, .filters select:focus { border-color: var(--accent); }
.field-row { display: grid; gap: 0 16px; }
@media (min-width: 560px) { .field-row { grid-template-columns: 200px minmax(0, 1fr); } }
.help { margin: 6px 0 0; font-size: 13px; color: var(--ink-2); }
.error, .form-error { margin: 6px 0 0; font-size: 14px; font-weight: 600; color: var(--crit-text); }
.has-error input, .has-error select { border-color: var(--crit-text) !important; }

.amount-field { margin-bottom: 26px; }
.amount-field > label { display: block; margin-bottom: 2px; font-size: 14px; font-weight: 600; }
.amount-wrap { display: flex; align-items: baseline; gap: 10px; }
.amount-wrap input { width: 100%; padding: 2px 0 6px; font: inherit; font-size: 48px; font-weight: 700; letter-spacing: -0.03em; color: inherit; background: transparent; border: 0; border-bottom: 2px solid var(--line-strong); border-radius: 0; }
.amount-wrap input:focus { outline: none; border-bottom-color: var(--accent); }
.amount-wrap span { font-size: 32px; font-weight: 600; color: var(--ink-2); }
input[type="number"] { -moz-appearance: textfield; appearance: textfield; }
input[type="number"]::-webkit-inner-spin-button, input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }

.chip-group { margin: 0 0 14px; padding: 0; border: 0; min-width: 0; }
.chip-group legend { margin-bottom: 8px; padding: 0; font-size: 13px; color: var(--ink-2); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip-wrap { position: relative; display: inline-block; }
.chip-wrap input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.chip { display: inline-flex; align-items: center; gap: 8px; min-height: 40px; padding: 8px 14px; border: 1px solid var(--line-strong); border-radius: 999px; background: var(--surface); font-size: 15px; }
.chip-wrap input:checked + .chip { border-color: var(--accent); background: var(--accent-wash); box-shadow: inset 0 0 0 1px var(--accent); font-weight: 600; }
.chip-wrap input:focus-visible + .chip { outline: 3px solid color-mix(in srgb, var(--accent) 60%, transparent); outline-offset: 2px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 18px; font: inherit; font-weight: 600; color: var(--accent-ink); text-decoration: none; background: var(--accent); border: 1px solid var(--accent); border-radius: 10px; cursor: pointer; }
.btn:hover { filter: brightness(1.08); }
.btn .i { width: 18px; height: 18px; }
.btn.ghost { color: var(--ink); background: transparent; border-color: var(--line-strong); }
.btn.ghost:hover { background: color-mix(in srgb, var(--ink) 6%, transparent); filter: none; }
.btn.danger { color: #fff; background: var(--crit-solid); border-color: var(--crit-solid); }
.btn.danger-ghost { color: var(--crit-text); background: transparent; border-color: color-mix(in srgb, var(--crit-text) 45%, transparent); }
.btn.block { width: 100%; }
.form-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 8px; }

.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 16px; }
.filters input[type="month"], .filters select { width: auto; }
.filters input[type="search"] { flex: 1 1 180px; width: auto; }

.seg-control { display: inline-flex; padding: 3px; border: 1px solid var(--line-strong); border-radius: 10px; background: var(--surface); }
.seg-control a { padding: 6px 14px; border-radius: 7px; color: var(--ink-2); font-size: 14px; font-weight: 600; text-decoration: none; }
.seg-control a[aria-current="true"] { background: var(--ink); color: var(--plane); }

.toasts { margin-bottom: 8px; }
.toast { margin: 0 0 10px; padding: 12px 16px; border-radius: 12px; background: var(--ink); color: var(--plane); font-size: 15px; }
.toast.error { background: var(--crit-solid); color: #fff; }
.toast.is-leaving { opacity: 0; transition: opacity .3s; }

.empty { max-width: 52ch; padding: 28px 0 8px; }
.empty h2 { font-size: 20px; }
.empty .actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }
.confirm { max-width: 520px; padding-top: 8px; }
.confirm .detail { font-size: 18px; font-weight: 600; margin: 12px 0 4px; }

/* ---------- Tableaux ---------- */
.table-scroll { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; }
.table { width: 100%; min-width: 520px; border-collapse: collapse; font-size: 15px; }
.table th, .table td { padding: 11px 14px; text-align: left; white-space: nowrap; border-bottom: 1px solid var(--line); }
.table thead th { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.table th.num, .table td.num { text-align: right; }
.table tbody tr, .table tfoot tr { background: var(--surface); }
.table tbody tr:last-child th, .table tbody tr:last-child td { border-bottom: 0; }
.table tfoot th, .table tfoot td { border-top: 1px solid var(--line-strong); border-bottom: 0; }
.table tr.current { background: var(--accent-wash); }
.table.sticky-first th:first-child { position: sticky; left: 0; background: inherit; }
.table .neg { color: var(--crit-text); }
.table .neg .i { width: 15px; height: 15px; margin-right: 4px; vertical-align: -2px; stroke-width: 2; }
.table th[scope="row"] { font-weight: 600; }
.data-table .table-scroll, .data-table .table { background: transparent; }
.note { margin-top: 12px; max-width: 70ch; }

/* ---------- Budgets ---------- */
.bgrid { overflow: hidden; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; }
.bhead, .brow { display: grid; grid-template-columns: minmax(0, 1.6fr) 110px 150px 120px; align-items: center; gap: 12px; padding: 10px 16px; }
.bhead { font-size: 13px; font-weight: 600; color: var(--ink-2); border-bottom: 1px solid var(--line); }
.brow + .brow { border-top: 1px solid var(--line); }
.bname { display: flex; align-items: center; gap: 10px; min-width: 0; }
.bname label { font-weight: 600; }
.bfield { position: relative; }
.bfield input { padding-right: 32px; text-align: right; font-variant-numeric: tabular-nums; }
.bfield span { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); color: var(--ink-2); pointer-events: none; }
.cell-label { display: none; }
.num.btotal { font-weight: 650; }
@media (max-width: 720px) {
  .bhead { display: none; }
  .brow { grid-template-columns: minmax(0, 1fr) 140px; grid-template-areas: "name field" "fixed total"; gap: 6px 12px; }
  .bname { grid-area: name; } .bfield { grid-area: field; }
  .bfixed { grid-area: fixed; text-align: left; } .btotal { grid-area: total; }
  .cell-label { display: inline; margin-right: 6px; font-size: 13px; font-weight: 400; color: var(--ink-2); }
}
.savebar {
  position: sticky; bottom: calc(84px + env(safe-area-inset-bottom)); z-index: 5;
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px 20px;
  padding: 12px 16px; background: var(--surface); border: 1px solid var(--line-strong); border-radius: 14px;
  box-shadow: 0 8px 24px color-mix(in srgb, #000 12%, transparent);
}
@media (min-width: 900px) { .savebar { bottom: 20px; } }
.savebar dl { display: flex; flex-wrap: wrap; gap: 6px 22px; margin: 0; }
.savebar dt { font-size: 12px; color: var(--ink-2); }
.savebar dd { margin: 0; font-weight: 600; }
.savebar .strong dd { font-weight: 750; }

/* ---------- Objectifs ---------- */
.goals { display: grid; gap: 30px; margin: 0; padding: 0; list-style: none; max-width: 720px; }
.goal-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; margin-bottom: 10px; }
.goal h2 { margin: 0; font-size: 19px; }
.goal h2 a { color: var(--ink); text-decoration: none; }
.goal h2 a:hover { text-decoration: underline; }
.goal .meter { --fill: var(--series-3); height: 10px; }
.goal-figures { margin: 10px 0 6px; font-size: 17px; }
.goal p { margin-bottom: 6px; }

/* ---------- Connexion ---------- */
.login { display: grid; place-items: center; min-height: 100dvh; padding: 24px; }
.login-card { width: min(400px, 100%); padding: 28px; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; }
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
.login-brand .mark { width: 38px; height: 38px; color: var(--accent); }
.login .field { margin-bottom: 16px; }

@media (prefers-reduced-motion: no-preference) {
  .btn, .chip, .tx, .list-row { transition: background-color .15s, border-color .15s, filter .15s; }
}
