/* Mes finances — feuille de style
   Direction : un registre de comptes moderne. Fond gris-bleu « papier à lettres »,
   encre bleu nuit, chiffres en serif à chasse fixe, rouge bordeaux pour les sorties. */

:root {
  --bg: #e7ebee;
  --surface: #fbfcfc;
  --surface-2: #f0f3f5;
  --ink: #17212b;
  --muted: #5b6876;
  --line: #cfd7de;
  --accent: #21507a;
  --accent-ink: #ffffff;
  --in: #22775a;
  --out: #8f3446;
  --warn: #9a6a0b;
  --warn-bg: #fbf1d9;
  --error-bg: #f7e3e7;
  --ok-bg: #e0f0e8;
  --bar: #17212b;
  --font-body: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-figures: Charter, "Bitstream Charter", "Sitka Text", Cambria, "Iowan Old Style", Georgia, serif;
  --radius: 6px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11171d;
    --surface: #182029;
    --surface-2: #1f2933;
    --ink: #e3e9ee;
    --muted: #93a1af;
    --line: #2d3945;
    --accent: #86afd9;
    --accent-ink: #0f1820;
    --in: #62bd99;
    --out: #e48b9b;
    --warn: #e2b35a;
    --warn-bg: #2e2716;
    --error-bg: #34202a;
    --ok-bg: #18302a;
    --bar: #0b1015;
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 var(--font-body);
}
a { color: var(--accent); text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
code { font-size: .92em; background: var(--surface-2); padding: .1em .35em; border-radius: 3px; }

h1, h2 { font-family: var(--font-figures); font-weight: 600; line-height: 1.2; margin: 0 0 .6rem; }
h1 { font-size: 1.9rem; letter-spacing: -.01em; }
h2 { font-size: 1.15rem; }
h2 a { color: inherit; text-decoration: none; }
h2 a:hover { text-decoration: underline; }

/* ---------- Barre supérieure ---------- */
.topbar {
  display: flex; align-items: center; gap: 1.5rem;
  background: var(--bar); color: #e9eef2;
  padding: 0 1.25rem; min-height: 54px;
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: .55rem; color: #fff; text-decoration: none; font-family: var(--font-figures); font-size: 1.1rem; font-weight: 600; white-space: nowrap; }
.brand-mark { width: 14px; height: 18px; border: 2px solid currentColor; border-radius: 2px; background: linear-gradient(transparent 45%, currentColor 45%, currentColor 55%, transparent 55%); }
.mainnav { display: flex; gap: .2rem; overflow-x: auto; flex: 1; scrollbar-width: none; }
.mainnav a, .usernav a { color: #b9c5cf; text-decoration: none; padding: .9rem .6rem; white-space: nowrap; border-bottom: 2px solid transparent; }
.mainnav a:hover, .usernav a:hover { color: #fff; }
.mainnav a[aria-current="page"], .usernav a[aria-current="page"] { color: #fff; border-bottom-color: #9ec3e6; }
.usernav { display: flex; align-items: center; gap: .4rem; }
.usernav form { margin: 0; }
.linkbtn { background: none; border: 0; color: #b9c5cf; font: inherit; cursor: pointer; padding: .9rem .6rem; }
.linkbtn:hover { color: #fff; }

/* ---------- Mise en page ---------- */
.page { max-width: 1180px; margin: 0 auto; padding: 1.75rem 1.25rem 4rem; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem; margin-bottom: 1.25rem; }
.panel.narrow { max-width: 720px; }
.two-col { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 1.25rem; align-items: start; }
.two-col > .panel { margin-bottom: 0; }
.two-col + * { margin-top: 1.25rem; }
.dash-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1.25rem; }
.dash-grid > .panel { margin: 0; }
.panel-wide { grid-column: 1 / -1; }
.row-between { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; flex-wrap: wrap; }
.page-title { margin-bottom: .75rem; }
.page-title h1 { margin: 0; }
.lead { color: var(--muted); max-width: 72ch; margin-top: 0; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.hint { color: var(--muted); font-size: .88rem; }
.empty { color: var(--muted); }
.nowrap { white-space: nowrap; }
.error-text { color: var(--out); }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.actions form { margin: 0; }
.stack { display: grid; gap: .9rem; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: .9rem; }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .9rem; }

/* ---------- Chiffres ---------- */
.num, .ledger dd, .big-num, .project-cost, .secret, .codes {
  font-family: var(--font-figures);
  font-variant-numeric: tabular-nums lining-nums;
}
.num { text-align: right; }
.amt-in { color: var(--in); }
.amt-out { color: var(--out); }
.big-num { font-size: 1.5rem; margin: 0; }

/* L'en-tête de mois : l'élément signature du tableau de bord */
.month-head {
  display: flex; justify-content: space-between; align-items: flex-end; gap: 1.5rem; flex-wrap: wrap;
  padding-bottom: 1.25rem; margin-bottom: 1.25rem; border-bottom: 2px solid var(--ink);
}
.month-switch { display: flex; align-items: center; gap: .5rem; }
.month-switch h1 { font-size: clamp(2rem, 5vw, 3rem); margin: 0; font-weight: 500; }
.month-arrow { display: inline-grid; place-items: center; width: 2rem; height: 2rem; border-radius: 50%; text-decoration: none; font-size: 1.5rem; line-height: 1; color: var(--muted); }
.month-arrow:hover { background: var(--surface); color: var(--ink); }
.ledger { display: flex; gap: 2rem; margin: 0; flex-wrap: wrap; }
.ledger div { display: grid; }
.ledger dt { color: var(--muted); font-size: .85rem; }
.ledger dd { margin: 0; font-size: 1.35rem; }
.ledger-total { padding-left: 2rem; border-left: 1px solid var(--line); }
.ledger-total dd { font-size: 1.8rem; font-weight: 600; }

.todo { margin: -.25rem 0 1.25rem; }
.todo a { display: inline-block; padding: .4rem .8rem; background: var(--warn-bg); color: var(--warn); border-radius: var(--radius); font-weight: 600; text-decoration: none; }
.todo a:hover { text-decoration: underline; }

/* ---------- Graphiques ---------- */
.chart { position: relative; }
.chart-donut { height: 220px; margin-bottom: 1rem; }
.chart-bars { height: 280px; }
.cat-list, .budget-list, .session-list, .log, .codes { list-style: none; margin: 0; padding: 0; }
.cat-list li { display: flex; justify-content: space-between; gap: 1rem; padding: .35rem 0; border-bottom: 1px dotted var(--line); }
.cat-list a { color: inherit; text-decoration: none; }
.cat-list a:hover { text-decoration: underline; }
.dot { display: inline-block; width: .7rem; height: .7rem; border-radius: 50%; margin-right: .5rem; vertical-align: baseline; }
.budget-list li { padding: .5rem 0; }
.budget-list li + li { border-top: 1px dotted var(--line); }

/* Jauges */
.meter { position: relative; height: 8px; background: var(--surface-2); border-radius: 4px; margin: .35rem 0 .2rem; overflow: visible; }
.meter-fill { position: absolute; inset: 0 auto 0 0; background: var(--in); border-radius: 4px; }
.meter.is-near .meter-fill { background: var(--warn); }
.meter.is-over .meter-fill { background: var(--out); }
.meter-pace { position: absolute; top: -4px; bottom: -4px; width: 2px; background: var(--ink); opacity: .55; }

/* ---------- Tableaux ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-weight: 600; font-size: .85rem; color: var(--muted); padding: .5rem .6rem; border-bottom: 1px solid var(--line); }
.table td { padding: .55rem .6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.table tbody tr:hover { background: var(--surface-2); }
.table th.num { text-align: right; font-family: var(--font-body); }
.tx-table { background: var(--surface); }
.col-check { width: 2rem; }
.tx-label { max-width: 28rem; }
.tx-label .muted { display: block; font-size: .85rem; }
.note { display: block; font-size: .85rem; font-style: italic; color: var(--muted); }
.note::before { content: "« "; }
.note::after { content: " »"; }
.edit-link { font-size: .88rem; }
.chip { display: inline-flex; align-items: center; white-space: nowrap; font-size: .88rem; }
.chip-empty { color: var(--warn); font-weight: 600; }
.budget-table .col-meter { min-width: 180px; }
.tx-form { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.bulkbar {
  position: sticky; bottom: 0; display: flex; flex-wrap: wrap; align-items: center; gap: .6rem;
  padding: .75rem 1rem; background: var(--surface-2); border-top: 1px solid var(--line);
  border-radius: 0 0 var(--radius) var(--radius);
}
.summary { display: flex; flex-wrap: wrap; gap: 1.25rem; align-items: baseline; font-family: var(--font-figures); font-variant-numeric: tabular-nums; }
.pager { display: flex; gap: .3rem; flex-wrap: wrap; margin-top: 1rem; }
.pager a { padding: .3rem .65rem; border: 1px solid var(--line); border-radius: var(--radius); text-decoration: none; background: var(--surface); }
.pager a[aria-current="page"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

/* ---------- Formulaires ---------- */
label { display: grid; gap: .3rem; font-size: .9rem; color: var(--muted); }
label.check { display: inline-flex; align-items: center; gap: .4rem; color: var(--ink); white-space: nowrap; }
input, select, textarea {
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: 4px; padding: .45rem .6rem; min-width: 0;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 25%, transparent); }
input[type="color"] { padding: 2px; width: 2.6rem; height: 2.3rem; }
input[type="checkbox"] { width: 1rem; height: 1rem; accent-color: var(--accent); }
.input-amount { width: 7rem; text-align: right; font-family: var(--font-figures); }
.input-small { width: 5rem; }
.code-input { font-family: var(--font-figures); font-size: 1.4rem; letter-spacing: .2em; text-align: center; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  font: inherit; font-weight: 600; font-size: .92rem; text-decoration: none; cursor: pointer;
  padding: .5rem .9rem; border-radius: 4px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink);
}
.btn:hover { border-color: var(--ink); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { filter: brightness(1.1); border-color: var(--accent); }
.btn-danger { background: var(--out); border-color: var(--out); color: #fff; }
.btn-ghost-danger { background: transparent; border-color: transparent; color: var(--out); }
.btn-ghost-danger:hover { border-color: var(--out); }

.filters { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-bottom: 1rem; }
.filters input[type="search"] { flex: 1 1 200px; }
.filter-month { display: flex; align-items: center; gap: .3rem; }

.cat-rows, .account-rows { display: grid; }
.cat-row { display: grid; grid-template-columns: auto minmax(140px, 1.4fr) minmax(110px, .8fr) auto minmax(90px, auto) auto; gap: .6rem; align-items: center; padding: .5rem 0; }
.cat-rows .cat-row + .cat-row { border-top: 1px dotted var(--line); }
.rule-form { display: flex; flex-wrap: wrap; gap: .6rem; align-items: end; padding: .8rem 0; }
.rule-form + .rule-form { border-top: 1px dotted var(--line); }
.rule-form .rule-pattern { flex: 1 1 220px; }
.rule-form select { max-width: 200px; }
.is-off { opacity: .6; }
.account-row { display: grid; grid-template-columns: minmax(200px, 1.4fr) auto minmax(160px, 1fr) auto auto; gap: .8rem; align-items: center; padding: .6rem 0; }
.account-row + .account-row { border-top: 1px dotted var(--line); }
.account-row input[type="text"] { width: 100%; }
.account-row .small { display: block; }

.facts { display: grid; grid-template-columns: max-content 1fr; gap: .3rem 1rem; margin: 0 0 1.25rem; padding: 1rem; background: var(--surface-2); border-radius: var(--radius); }
.facts div { display: contents; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }
.danger-zone { margin-top: 1.5rem; padding-top: 1rem; border-top: 1px solid var(--line); }
details.panel summary { cursor: pointer; font-weight: 600; }
details.panel[open] summary { margin-bottom: 1rem; }

/* ---------- Messages ---------- */
.flash { padding: .7rem 1rem; border-radius: var(--radius); margin: 0 0 1rem; border-left: 4px solid; }
.flash-ok { background: var(--ok-bg); border-color: var(--in); }
.flash-warn { background: var(--warn-bg); border-color: var(--warn); }
.flash-error { background: var(--error-bg); border-color: var(--out); }
.tag { display: inline-block; font-size: .8rem; padding: .1rem .5rem; border-radius: 99px; margin-top: .3rem; }
.tag-ok { background: var(--ok-bg); color: var(--in); }
.tag-warn { background: var(--warn-bg); color: var(--warn); }
.tag-error { background: var(--error-bg); color: var(--out); }
.session-list li { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; padding: .7rem 0; }
.session-list li + li { border-top: 1px dotted var(--line); }
.log li { padding: .25rem 0; font-size: .88rem; }
.log-error { color: var(--out); }
.log-warn { color: var(--warn); }

/* ---------- Projets ---------- */
.project-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.project-card {
  display: grid; gap: .2rem; padding: 1rem 1.1rem; text-decoration: none; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line); border-top: 4px solid var(--project); border-radius: var(--radius);
}
.project-card:hover { border-color: var(--ink); border-top-color: var(--project); }
.project-card.is-closed { opacity: .7; }
.project-name { font-weight: 600; }
.project-cost { font-size: 1.6rem; }
.project-head { display: grid; grid-template-columns: 1fr auto; gap: 1rem 2rem; align-items: end; padding: 0 0 1.25rem 1rem; margin-bottom: 1.25rem; border-left: 6px solid var(--project); border-bottom: 2px solid var(--ink); }
.project-head h1 { font-size: clamp(1.8rem, 4vw, 2.5rem); }
.project-meter { grid-column: 1 / -1; }

/* ---------- Authentification ---------- */
.is-bare .page { min-height: 100vh; display: grid; place-items: center; }
.auth { width: 100%; max-width: 380px; }
.auth-wide { max-width: 640px; }
.auth-title { font-size: 2rem; margin-bottom: 1.25rem; padding-bottom: .75rem; border-bottom: 2px solid var(--ink); }
.auth-form { display: grid; gap: 1rem; }
.setup-grid { display: grid; grid-template-columns: auto 1fr; gap: 1.5rem; align-items: start; margin-top: 1rem; }
.qr { background: #fff; padding: 8px; border-radius: var(--radius); width: max-content; line-height: 0; }
.qr svg { display: block; width: 200px; height: 200px; }
.secret { font-size: 1.1rem; letter-spacing: .08em; word-break: break-all; background: var(--surface); border: 1px dashed var(--line); padding: .5rem .75rem; border-radius: 4px; }
.codes { display: grid; grid-template-columns: repeat(2, max-content); gap: .4rem 2.5rem; font-size: 1.25rem; margin: 1.25rem 0; }

/* ---------- Petits écrans ---------- */
@media (max-width: 860px) {
  .dash-grid { grid-template-columns: 1fr; }
  .topbar { flex-wrap: wrap; gap: 0 1rem; padding-top: .5rem; }
  .mainnav { order: 3; flex-basis: 100%; }
  .usernav { margin-left: auto; }
  .ledger { gap: 1.25rem; }
  .ledger-total { padding-left: 0; border-left: 0; }
  .cat-row, .account-row { grid-template-columns: auto 1fr; }
  .cat-row > :nth-child(n+4), .account-row > * { grid-column: 1 / -1; }
  .setup-grid { grid-template-columns: 1fr; }
  .project-head { grid-template-columns: 1fr; }
  .tx-table th:nth-child(5), .tx-table td:nth-child(5), .hide-sm { display: none; }
}

@media print {
  .topbar, .actions, .btn { display: none !important; }
  body { background: #fff; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
