/* money.chalco.website — palette validée (skill dataviz, palette de référence) ; clair et sombre. */
:root {
  color-scheme: light;
  --page: #f9f9f7; --surface: #fcfcfb; --surface-2: #f3f2ee; --raised: #ffffff;
  --text: #0b0b0b; --text-2: #52514e; --muted: #898781;
  --grid: #e1e0d9; --axis: #c3c2b7; --border: rgba(11, 11, 11, 0.10); --shadow: 0 1px 2px rgba(11, 11, 11, .04), 0 8px 24px rgba(11, 11, 11, .05);
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100; --s5: #e87ba4; --s6: #008300;
  --s1-wash: rgba(42, 120, 214, .10); --accent: #2a78d6; --accent-ink: #1c5cab;
  --good: #006300; --bad: #d03b3b; --muted-bar: #d9d7cf;
  --radius: 16px; --radius-s: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page: #0d0d0d; --surface: #1a1a19; --surface-2: #232321; --raised: #20201f;
    --text: #f0efec; --text-2: #c3c2b7; --muted: #898781;
    --grid: #2c2c2a; --axis: #383835; --border: rgba(255, 255, 255, 0.10); --shadow: none;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #008300;
    --s1-wash: rgba(57, 135, 229, .16); --accent: #3987e5; --accent-ink: #86b6ef;
    --good: #0ca30c; --bad: #e66767; --muted-bar: #383835;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d; --surface: #1a1a19; --surface-2: #232321; --raised: #20201f;
  --text: #f0efec; --text-2: #c3c2b7; --muted: #898781;
  --grid: #2c2c2a; --axis: #383835; --border: rgba(255, 255, 255, 0.10); --shadow: none;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #008300;
  --s1-wash: rgba(57, 135, 229, .16); --accent: #3987e5; --accent-ink: #86b6ef;
  --good: #0ca30c; --bad: #e66767; --muted-bar: #383835;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--page); color: var(--text); }
body { font-size: 15px; line-height: 1.45; -webkit-font-smoothing: antialiased; min-height: 100vh; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
[hidden] { display: none !important; }
bdi { unicode-bidi: isolate; }
.num { font-variant-numeric: tabular-nums; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Barre du haut ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 16px;
  padding: 12px max(20px, env(safe-area-inset-left)); background: color-mix(in srgb, var(--page) 86%, transparent);
  backdrop-filter: saturate(1.4) blur(12px); -webkit-backdrop-filter: saturate(1.4) blur(12px); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; letter-spacing: -.01em; white-space: nowrap; }
.brand img { width: 30px; height: 30px; }
.scope-tabs { display: flex; gap: 4px; padding: 4px; background: var(--surface-2); border-radius: 999px; }
.scope-tabs button { border: 0; background: transparent; padding: 7px 18px; border-radius: 999px; font-weight: 600; color: var(--text-2); }
.scope-tabs button[aria-selected="true"] { background: var(--raised); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
.topbar .spacer { flex: 1; }
.user { display: flex; align-items: center; gap: 8px; color: var(--text-2); }
.icon-btn { border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: 7px 12px; color: var(--text-2); }
.icon-btn:hover { color: var(--text); background: var(--surface-2); }
#logout .ico { display: none; }

/* ---------- Filtres ---------- */
.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 16px max(20px, env(safe-area-inset-left)) 4px; max-width: 1280px; margin: 0 auto; }
.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding: 2px; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; border: 1px solid var(--border); background: var(--surface); color: var(--text-2); padding: 7px 14px; border-radius: 999px; font-size: 14px; white-space: nowrap; }
.chip:hover { background: var(--surface-2); color: var(--text); }
.chip[aria-pressed="true"] { background: var(--text); color: var(--page); border-color: var(--text); font-weight: 600; }
.range { display: flex; align-items: center; gap: 6px; color: var(--text-2); font-size: 14px; }
.range input, .select { border: 1px solid var(--border); background: var(--surface); border-radius: 10px; padding: 7px 10px; }
.select { min-width: 190px; }
.period-label { margin-left: auto; color: var(--muted); font-size: 14px; }

/* ---------- Mise en page ---------- */
main { max-width: 1280px; margin: 0 auto; padding: 12px max(20px, env(safe-area-inset-left)) 40px; transition: opacity .2s; }
main.loading { opacity: .55; }
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-top: 16px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); min-width: 0; }
.card.wide { grid-column: 1 / -1; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.card h2 { margin: 0; font-size: 16px; font-weight: 650; letter-spacing: -.01em; }
.card .sub { color: var(--muted); font-size: 13px; }
.link-btn { border: 0; background: none; color: var(--accent-ink); padding: 2px 4px; font-size: 13px; font-weight: 600; }
.link-btn:hover { text-decoration: underline; }
.empty { color: var(--muted); padding: 20px 0; text-align: center; }

/* ---------- Chiffres clés ---------- */
.kpis { display: grid; grid-template-columns: 1.4fr repeat(3, 1fr); gap: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); min-width: 0; }
.kpi .label { color: var(--text-2); font-size: 14px; }
.kpi .value { font-size: 28px; font-weight: 650; letter-spacing: -.02em; margin-top: 4px; white-space: nowrap; }
.kpi.hero .value { font-size: 48px; line-height: 1.1; }
.kpi .delta { margin-top: 6px; font-size: 13px; color: var(--text-2); display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.delta .up-bad, .delta .down-bad { color: var(--bad); font-weight: 600; }
.delta .up-good, .delta .down-good { color: var(--good); font-weight: 600; }
.kpi .hint { color: var(--muted); font-size: 13px; margin-top: 2px; }

/* ---------- Graphique d'évolution ---------- */
.legend { display: flex; gap: 14px; flex-wrap: wrap; color: var(--text-2); font-size: 13px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; flex: none; }
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .baseline { stroke: var(--axis); stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 11px; }
.chart .col { cursor: pointer; }
.chart .col .hit { fill: transparent; }
.chart .col:hover .hit, .chart .col:focus .hit { fill: var(--s1-wash); }
.chart .col.out .seg { opacity: .38; }
.chart .col:focus { outline: none; }
.table-view { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 8px; }
.table-view th, .table-view td { text-align: right; padding: 6px 8px; border-bottom: 1px solid var(--grid); font-variant-numeric: tabular-nums; }
.table-view th:first-child, .table-view td:first-child { text-align: left; }
.table-view th { color: var(--text-2); font-weight: 600; }

/* ---------- Barres classées (thèmes, commerçants, tranches, revenus) ---------- */
.bars { display: flex; flex-direction: column; gap: 4px; }
.bar-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 12px; align-items: center; padding: 8px 10px; border-radius: 10px; border: 0; background: none; text-align: left; width: 100%; }
button.bar-row:hover, button.bar-row:focus-visible { background: var(--surface-2); }
.bar-row .name { display: flex; align-items: center; gap: 8px; min-width: 0; font-weight: 550; }
.bar-row .name .ico { width: 22px; text-align: center; flex: none; }
.bar-row .name bdi, .bar-row .name .txt { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row .amount { font-weight: 650; text-align: right; white-space: nowrap; }
.bar-row .track { grid-column: 1 / 2; height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.bar-row .fill { height: 100%; border-radius: 999px; background: var(--s1); min-width: 2px; }
.bar-row.income .fill { background: var(--s3); }
.bar-row .meta { color: var(--muted); font-size: 12.5px; text-align: right; white-space: nowrap; }

/* ---------- Barre segmentée (cartes et comptes) ---------- */
.segbar { display: flex; gap: 2px; height: 28px; margin: 4px 0 14px; }
.segbar .seg { border-radius: 4px; display: flex; align-items: center; padding-left: 8px; color: #fff; font-size: 12px; font-weight: 600; min-width: 0; overflow: hidden; white-space: nowrap; }
.segbar .seg.dark-ink { color: #0b0b0b; }
.acct-row { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 2px 10px; align-items: center; padding: 8px 4px; border-bottom: 1px solid var(--grid); }
.acct-row:last-child { border-bottom: 0; }
.acct-row .who { color: var(--muted); font-size: 12.5px; grid-column: 2; }
.acct-row .amount { font-weight: 650; text-align: right; }
.acct-row .meta { color: var(--muted); font-size: 12.5px; text-align: right; grid-column: 3; }

/* ---------- Listes de transactions ---------- */
.tx-list { display: flex; flex-direction: column; }
.tx { display: grid; grid-template-columns: 52px minmax(0, 1fr) auto; gap: 2px 12px; align-items: center; padding: 10px 4px; border-bottom: 1px solid var(--grid); }
.tx:last-child { border-bottom: 0; }
.tx .date { color: var(--text-2); font-size: 13px; line-height: 1.2; text-align: center; }
.tx .date b { display: block; font-size: 17px; color: var(--text); }
.tx .label { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx .detail { color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; grid-column: 2; }
.tx .amount { font-weight: 650; text-align: right; white-space: nowrap; grid-row: 1 / 3; grid-column: 3; }
.tx .amount.income { color: var(--good); }
.tx .amount small { display: block; color: var(--muted); font-weight: 400; font-size: 12px; }
.tag { display: inline-block; padding: 1px 7px; border-radius: 999px; background: var(--surface-2); color: var(--text-2); font-size: 11.5px; margin-left: 6px; vertical-align: 1px; }
.tx-tools { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.tx-tools input[type="search"] { flex: 1 1 220px; border: 1px solid var(--border); background: var(--surface); border-radius: 10px; padding: 8px 12px; }
.tx-summary { color: var(--text-2); font-size: 13px; margin: 4px 0 6px; }
.more { display: block; margin: 12px auto 0; }

/* ---------- Infobulle ---------- */
.tooltip { position: fixed; z-index: 50; pointer-events: none; background: var(--raised); color: var(--text); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: 0 8px 28px rgba(0, 0, 0, .18); padding: 10px 12px; font-size: 13px; min-width: 170px; }
.tooltip .t-title { color: var(--text-2); margin-bottom: 6px; }
.tooltip .t-row { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.tooltip .t-row b { font-variant-numeric: tabular-nums; }
.tooltip .key { width: 12px; height: 2px; border-radius: 2px; display: inline-block; margin-right: 6px; vertical-align: middle; }

/* ---------- Panneau de détail ---------- */
.drawer-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .35); z-index: 40; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(520px, 100vw); background: var(--surface); z-index: 41; display: flex; flex-direction: column;
  box-shadow: -12px 0 40px rgba(0, 0, 0, .2); border-left: 1px solid var(--border); }
.drawer header { display: flex; align-items: flex-start; gap: 12px; padding: 20px 20px 12px; border-bottom: 1px solid var(--grid); }
.drawer header h3 { margin: 0; font-size: 18px; }
.drawer header .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.drawer header .close { margin-left: auto; }
.drawer .body { overflow-y: auto; padding: 8px 20px 24px; flex: 1; }

/* ---------- Pied de page ---------- */
.freshness { color: var(--muted); font-size: 12.5px; margin-top: 24px; display: flex; flex-wrap: wrap; gap: 6px 18px; justify-content: center; }

/* ---------- Connexion ---------- */
.login-page { display: grid; place-items: center; min-height: 100vh; padding: 20px; }
.login-card { width: min(380px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: 20px; padding: 32px 28px; box-shadow: var(--shadow); }
.login-card .brand { justify-content: center; font-size: 24px; margin-bottom: 4px; }
.login-card p.tagline { text-align: center; color: var(--text-2); margin: 0 0 24px; }
.login-card label { display: block; font-size: 14px; color: var(--text-2); margin: 14px 0 6px; }
.login-card input { width: 100%; border: 1px solid var(--border); background: var(--page); border-radius: 12px; padding: 12px 14px; font-size: 16px; }
.login-card button { width: 100%; margin-top: 22px; border: 0; background: var(--text); color: var(--page); border-radius: 12px; padding: 13px; font-weight: 650; font-size: 16px; }
.login-card button:disabled { opacity: .6; }
.login-card .error { color: var(--bad); font-size: 14px; margin-top: 12px; text-align: center; min-height: 20px; }

/* ---------- Mobile ---------- */
@media (max-width: 960px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi.hero { grid-column: 1 / -1; }
  .kpi:last-child { grid-column: 1 / -1; }
  .grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 640px) {
  body { font-size: 14.5px; }
  .topbar { gap: 8px; padding: 10px 14px; }
  #logout .lbl { display: none; }
  #logout .ico { display: inline; }
  .bar-row .track { grid-column: 1 / -1; }
  .bar-row .meta { grid-column: 1 / -1; text-align: left; justify-content: flex-start; }
  .brand span { display: none; }
  .user .name { display: none; }
  .scope-tabs button { padding: 6px 14px; }
  .filters { padding: 12px 14px 0; }
  .chips { width: 100%; }
  .select { flex: 1; min-width: 0; }
  .period-label { width: 100%; margin: 0; }
  main { padding: 8px 14px 32px; }
  .kpi { padding: 14px 16px; }
  .kpi .value { font-size: 22px; }
  .kpi.hero .value { font-size: 40px; }
  .card { padding: 16px; border-radius: 14px; }
  .drawer { top: auto; width: 100vw; height: 88vh; border-radius: 18px 18px 0 0; border-left: 0; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
