/* Mes comptes — carnet de comptes à l'encre bleue sur papier Seyès */
:root {
  --paper: #FBFCFE;
  --surface: #FFFFFF;
  --ink: #2B4C9B;          /* encre bleue : action principale, année en cours */
  --ink-strong: #1F3A7C;
  --ink-soft: #E8EEF9;
  --text: #1B2233;
  --text-2: #4E586C;
  --line: #D6DEEC;
  --seyes: rgba(43, 76, 155, .075);
  --seyes-strong: rgba(43, 76, 155, .16);
  --margin: #C8423B;       /* trait de marge rouge */
  --danger: #B3261E;
  --ok: #1E7B4F;
  --s-cur: #2B4C9B;        /* séries graphiques — validées daltonisme */
  --s-n1: #B7832F;
  --s-n2: #14907A;
  --radius-l: 14px;
  --radius-s: 8px;
  --shadow: 0 1px 2px rgba(27, 34, 51, .06), 0 6px 20px rgba(27, 34, 51, .05);
  --nav-h: 68px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #0F1524; --surface: #161E31; --ink: #7F9DEB; --ink-strong: #A7BCF3; --ink-soft: #1E2A47;
    --text: #E7EBF4; --text-2: #A4AEC3; --line: #2A3552;
    --seyes: rgba(127,157,235,.06); --seyes-strong: rgba(127,157,235,.13);
    --margin: #E06A60; --danger: #F2847B; --ok: #5CC08F;
    --s-cur: #6F8FE0; --s-n1: #BE8628; --s-n2: #16A88C;
    --shadow: 0 1px 2px rgba(0,0,0,.3);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #0F1524; --surface: #161E31; --ink: #7F9DEB; --ink-strong: #A7BCF3; --ink-soft: #1E2A47;
  --text: #E7EBF4; --text-2: #A4AEC3; --line: #2A3552;
  --seyes: rgba(127,157,235,.06); --seyes-strong: rgba(127,157,235,.13);
  --margin: #E06A60; --danger: #F2847B; --ok: #5CC08F;
  --s-cur: #6F8FE0; --s-n1: #BE8628; --s-n2: #16A88C;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--text);
  font-family: "Atkinson Hyperlegible", system-ui, sans-serif;
  font-size: 18px;
  line-height: 1.5;
  font-variant-numeric: tabular-nums;
}
h1 { font-size: 1.75rem; line-height: 1.2; margin: 0 0 .25rem; }
h2 { font-size: 1.15rem; line-height: 1.3; margin: 0; }
h3 { font-size: 1rem; margin: 0 0 .25rem; }
.muted { color: var(--text-2); }
.small { font-size: .9rem; }
.lead { margin: 0 0 1.25rem; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; }

/* ---------- barre du haut / navigation ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .6rem max(16px, calc((100% - 980px) / 2));
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: .6rem; font-weight: 700; font-size: 1.1rem; }
.brand img { border-radius: 8px; }
.tabs { display: flex; gap: .25rem; }
.tab {
  display: flex; align-items: center; gap: .45rem;
  font: inherit; font-size: 1rem; color: var(--text-2);
  background: none; border: 0; padding: .55rem .9rem; border-radius: 999px; cursor: pointer;
}
.tab:hover { color: var(--text); background: var(--ink-soft); }
.tab[aria-current="page"] { color: var(--ink-strong); background: var(--ink-soft); font-weight: 700; }

@media (max-width: 720px) {
  .topbar { padding: .5rem 16px; }
  .tabs {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    height: calc(var(--nav-h) + env(safe-area-inset-bottom));
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
    background: var(--surface); border-top: 1px solid var(--line);
    justify-content: space-around;
  }
  .tab { flex-direction: column; gap: 2px; font-size: .85rem; padding: .35rem .5rem; border-radius: 12px; flex: 1; }
  .tab svg { width: 26px; height: 26px; }
  main { padding-bottom: calc(var(--nav-h) + 24px + env(safe-area-inset-bottom)) !important; }
}

main { max-width: 980px; margin: 0 auto; padding: 1.25rem 16px 3rem; }

/* ---------- bandeau ---------- */
.banner {
  max-width: 980px; margin: .9rem auto 0; padding: .8rem 1rem;
  display: flex; flex-wrap: wrap; align-items: center; gap: .6rem 1rem;
  background: var(--ink-soft); color: var(--text); border-radius: var(--radius-s);
  width: calc(100% - 32px);
}
.banner.warn { background: color-mix(in srgb, var(--margin) 12%, var(--surface)); }
.banner p { margin: 0; flex: 1 1 260px; }

/* ---------- formulaire : la page du carnet ---------- */
.ledger {
  position: relative;
  background-color: var(--surface);
  background-image:
    linear-gradient(to right, transparent 46px, var(--margin) 46px, var(--margin) 47.5px, transparent 47.5px),
    repeating-linear-gradient(to bottom, transparent 0 31px, var(--seyes-strong) 31px 32px),
    repeating-linear-gradient(to bottom, transparent 0 7px, var(--seyes) 7px 8px);
  border: 1px solid var(--line);
  border-radius: var(--radius-l);
  box-shadow: var(--shadow);
  padding: 1.25rem 1.25rem 1.5rem 68px;
}
@media (max-width: 520px) {
  .ledger { padding: 1rem 1rem 1.25rem 40px;
    background-image:
      linear-gradient(to right, transparent 22px, var(--margin) 22px, var(--margin) 23.5px, transparent 23.5px),
      repeating-linear-gradient(to bottom, transparent 0 31px, var(--seyes-strong) 31px 32px),
      repeating-linear-gradient(to bottom, transparent 0 7px, var(--seyes) 7px 8px); }
}

.field { display: flex; flex-direction: column; gap: .3rem; min-width: 0; }
.field label { font-weight: 700; font-size: .95rem; }
.hint { font-weight: 400; color: var(--text-2); }
input, select {
  font: inherit; color: var(--text);
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: var(--radius-s);
  padding: .65rem .75rem;
  min-height: 52px; width: 100%;
}
input:focus, select:focus { border-color: var(--ink); outline: none; box-shadow: 0 0 0 3px var(--ink-soft); }
select:disabled { opacity: .55; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-top: 1rem; }
@media (max-width: 600px) { .grid-2 { grid-template-columns: 1fr; } }

.amount-field { margin-top: 1rem; }
.amount-wrap { position: relative; display: flex; align-items: baseline; }
#f-montant {
  font-size: 3rem; font-weight: 700; color: var(--ink);
  border: 0; border-bottom: 2.5px solid var(--ink); border-radius: 0;
  background: transparent; padding: .1rem 2.5rem .1rem 0; min-height: 0; letter-spacing: -.01em;
}
#f-montant::placeholder { color: color-mix(in srgb, var(--ink) 35%, transparent); }
#f-montant:focus { box-shadow: none; border-bottom-width: 3.5px; }
.euro { position: absolute; right: .25rem; bottom: .55rem; font-size: 2rem; font-weight: 700; color: var(--ink); }

.ticket-row { display: flex; flex-wrap: wrap; gap: .75rem; align-items: center; }
.ocr-status { font-size: .95rem; color: var(--text-2); display: flex; align-items: center; gap: .6rem; }
.ocr-status img { width: 44px; height: 44px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); }

.tiers-field { position: relative; }
.suggest {
  position: absolute; top: 100%; left: 0; right: 0; z-index: 5;
  margin: 4px 0 0; padding: 4px; list-style: none;
  background: var(--surface); border: 1.5px solid var(--line); border-radius: var(--radius-s);
  box-shadow: var(--shadow); max-height: 300px; overflow: auto;
}
.suggest li { padding: .6rem .7rem; border-radius: 6px; cursor: pointer; display: flex; justify-content: space-between; gap: .5rem; }
.suggest li small { color: var(--text-2); text-align: right; }
.suggest li[aria-selected="true"], .suggest li:hover { background: var(--ink-soft); }

.form-error { color: var(--danger); font-weight: 700; margin: 1rem 0 0; }
.actions { display: flex; flex-wrap: wrap; gap: .75rem; margin-top: 1.5rem; }

/* ---------- boutons ---------- */
.btn {
  font: inherit; font-weight: 700; font-size: 1rem;
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  min-height: 52px; padding: .6rem 1.2rem; border-radius: 999px; cursor: pointer;
  border: 1.5px solid transparent; text-decoration: none;
}
.btn-primary { background: var(--ink); color: #fff; }
:root[data-theme="dark"] .btn-primary { color: #0F1524; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn-primary { color: #0F1524; } }
.btn-primary:hover { background: var(--ink-strong); }
.btn-ghost { background: var(--surface); color: var(--ink-strong); border-color: var(--line); }
.btn-ghost:hover { border-color: var(--ink); }
.btn-danger-ghost { background: none; color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.btn-small { min-height: 42px; padding: .4rem .9rem; font-size: .95rem; }
.btn-icon { min-height: 44px; min-width: 44px; padding: 0; border-radius: 10px; background: none; border: 0; color: var(--text-2); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; }
.btn-icon:hover { color: var(--ink); background: var(--ink-soft); }
.btn-row { display: flex; flex-wrap: wrap; gap: .75rem; margin: .75rem 0; }
.btn-row.end { justify-content: flex-end; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
@media (max-width: 520px) { .actions .btn, .ticket-btn { width: 100%; } }

/* ---------- dernières dépenses ---------- */
.recent { margin-top: 2rem; }
.recent-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; margin-bottom: .5rem; }
.entries { list-style: none; margin: 0; padding: 0; }
.entries li {
  display: grid; grid-template-columns: auto 1fr auto auto; align-items: center; gap: .25rem 1rem;
  padding: .7rem 0; border-bottom: 1px solid var(--line);
}
.e-date { color: var(--text-2); font-size: .95rem; width: 4.2rem; }
.e-main { min-width: 0; }
.e-tiers { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.e-cat { color: var(--text-2); font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.e-amt { font-weight: 700; color: var(--ink); white-space: nowrap; }
.e-act { display: flex; }
.e-flag { font-size: .8rem; color: var(--ok); }
.empty { padding: 1.5rem; text-align: center; color: var(--text-2); border: 1.5px dashed var(--line); border-radius: var(--radius-l); }

/* ---------- suivi ---------- */
.filters {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .75rem;
  align-items: end; margin-bottom: 1.5rem;
}
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.kpi { padding: .25rem 0 .25rem 1rem; border-left: 3px solid var(--line); }
.kpi:first-child { border-left-color: var(--s-cur); }
.kpi .k-label { color: var(--text-2); font-size: .95rem; }
.kpi .k-val { font-size: 1.8rem; font-weight: 700; line-height: 1.2; }
.kpi .k-sub { font-size: .9rem; color: var(--text-2); }
.chart-block, .table-block {
  margin: 0 0 1.25rem; padding: 1rem 1rem .75rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-l);
}
.chart-block figcaption { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: .5rem 1rem; margin-bottom: .5rem; }
.legend { display: flex; flex-wrap: wrap; gap: .25rem 1rem; font-size: .9rem; color: var(--text-2); }
.legend span { display: inline-flex; align-items: center; gap: .4rem; }
.legend i { display: inline-block; width: 18px; height: 3px; border-radius: 2px; }
.legend i.dash { background-image: linear-gradient(to right, currentColor 60%, transparent 60%) !important; background-size: 6px 3px; }
.chart-wrap { position: relative; height: 280px; }
.chart-wrap.tall { height: 420px; }
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .95rem; margin-top: .5rem; }
th, td { padding: .5rem .5rem; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; white-space: normal; }
thead th { color: var(--text-2); font-weight: 700; }
tfoot td { font-weight: 700; border-bottom: 0; }
.up { color: var(--danger); }
.down { color: var(--ok); }

/* ---------- réglages ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-l); padding: 1.1rem 1.1rem 1.2rem; margin: 1rem 0; }
.panel h2 { margin-bottom: .5rem; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; }
.divider { height: 1px; background: var(--line); margin: 1.1rem 0; }
.file-info { display: grid; grid-template-columns: 1fr auto; gap: .25rem 1rem; margin: .5rem 0; }
.file-info dt { color: var(--text-2); }
.file-info dd { margin: 0; font-weight: 700; text-align: right; overflow-wrap: anywhere; }
.seg { display: flex; flex-wrap: wrap; gap: .5rem; }
.seg label { display: flex; align-items: center; gap: .5rem; padding: .6rem 1rem; border: 1.5px solid var(--line); border-radius: 999px; cursor: pointer; }
.seg input { width: 20px; height: 20px; min-height: 0; accent-color: var(--ink); }
.seg label:has(input:checked) { border-color: var(--ink); background: var(--ink-soft); font-weight: 700; }
.fam-list { list-style: none; padding: 0; margin: .5rem 0 0; }
.fam { border-top: 1px solid var(--line); }
.fam > details > summary { list-style: none; display: flex; align-items: center; gap: .5rem; padding: .55rem 0; cursor: pointer; }
.fam > details > summary::-webkit-details-marker { display: none; }
.fam summary .chev { transition: transform .15s; color: var(--text-2); }
.fam details[open] .chev { transform: rotate(90deg); }
.fam .f-name { font-weight: 700; flex: 1; }
.fam .f-count { color: var(--text-2); font-size: .9rem; }
.subs { list-style: none; margin: 0 0 .75rem; padding: 0 0 0 2rem; }
.subs li { display: flex; align-items: center; gap: .5rem; padding: .15rem 0; }
.subs li span { flex: 1; }
.subs .add-sub { margin-top: .25rem; }
.version { text-align: center; margin-top: 2rem; }

/* ---------- toast & dialogue ---------- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(24px + env(safe-area-inset-bottom)); z-index: 50;
  background: var(--text); color: var(--paper); padding: .75rem 1.2rem; border-radius: 12px;
  font-weight: 700; max-width: calc(100% - 32px); box-shadow: var(--shadow);
}
@media (max-width: 720px) { .toast { bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom)); } }
.toast.error { background: var(--danger); color: #fff; }
@media (prefers-reduced-motion: no-preference) {
  .toast:not([hidden]) { animation: toast-in .2s ease-out; }
  @keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } }
  .entries li.just-added { animation: ink-in 1.2s ease-out; }
  @keyframes ink-in { from { background: var(--ink-soft); } to { background: transparent; } }
}
dialog { border: 0; border-radius: var(--radius-l); padding: 0; width: min(440px, calc(100% - 32px)); background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(15, 21, 36, .45); }
.dlg-body { padding: 1.25rem; }
.dlg-body h2 { margin-bottom: .5rem; }
.dlg-body input { margin: .5rem 0; }

@media (max-width: 520px) {
  .entries li { grid-template-columns: 1fr auto auto; gap: 0 .5rem; }
  .e-date { grid-column: 1 / -1; width: auto; font-size: .85rem; }
  .e-act .btn-icon { min-width: 40px; }
}
