:root {
  --bg: #ffffff;
  --card: #ffffff;
  --ink: #18181b;
  --muted: #71717a;
  --line: #e4e4e7;
  --soft: #f4f4f5;
  --accent: #18181b;
  --revenu: #16a34a;
  --fixe: #64748b;
  --variable: #d97706;
  --epargne: #6366f1;
  --danger: #dc2626;
  --ok: #16a34a;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(24, 24, 27, .04);
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --display: var(--font);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b0b0c; --card: #121214; --ink: #fafafa; --muted: #a1a1aa; --line: #27272a; --soft: #1c1c1f;
    --accent: #fafafa; --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b0b0c; --card: #121214; --ink: #fafafa; --muted: #a1a1aa; --line: #27272a; --soft: #1c1c1f;
  --accent: #fafafa; --shadow: none; color-scheme: dark;
}

* { 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); font-feature-settings: "tnum" 1, "cv11" 1;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
a { color: inherit; }
h1, h2, h3 { font-family: var(--display); font-weight: 600; letter-spacing: -.02em; margin: 0; line-height: 1.2; }
h1 { font-size: 26px; }
h2 { font-size: 16px; margin-bottom: 12px; }
h3 { font-size: 15px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.pos { color: var(--revenu); }
.neg { color: var(--danger); }

/* ---------- header / nav ---------- */
.top {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 16px;
  padding: 12px 20px; background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: saturate(1.4) blur(12px); border-bottom: 1px solid var(--line);
}
.brand { font-family: var(--display); font-weight: 600; font-size: 17px; letter-spacing: -.01em; text-decoration: none; display: flex; align-items: center; gap: 8px; }
.brand em { font-style: normal; color: var(--muted); font-weight: 500; margin-left: 2px; }
.brand-dot { width: 16px; height: 16px; border-radius: 5px; background: var(--ink); }
.nav { display: flex; gap: 4px; margin-left: auto; }
.nav a { position: relative; display: flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 8px; text-decoration: none; color: var(--muted); font-weight: 500; font-size: 14px; }
.nav a.on, .nav a:hover { color: var(--ink); background: var(--soft); }
.nav .ico { font-size: 14px; }
.nav-bottom { display: none; }
[hidden] { display: none !important; }

/* tableau annuel : première colonne figée quand on fait glisser vers la droite */
.year-grid td, .year-grid th { padding: 6px 8px; font-size: 13px; }
.year-grid td:first-child, .year-grid th:first-child { position: sticky; left: 0; background: var(--card); z-index: 1; }
.year-grid.compact td, .year-grid.compact th { padding: 6px 4px; font-size: 12px; }
.year-grid.compact th { font-size: 10px; letter-spacing: 0; }
.year-grid tr.grp td { background: var(--soft); padding-top: 8px; padding-bottom: 8px; }
.year-grid tr.sub td { border-top: 1px solid var(--line); font-weight: 600; }
.pill { background: var(--danger); color: #fff; border-radius: 999px; font-size: 11px; padding: 1px 6px; font-weight: 600; }
.me { display: flex; align-items: center; gap: 10px; }
.avatar { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: var(--c); color: #fff; font-weight: 600; font-size: 13px; }

@media (max-width: 760px) {
  .top { padding: 10px 16px; backdrop-filter: none; background: var(--bg); } /* sinon la barre fixe du bas se colle au header */
  .nav-top { display: none; }
  .nav-bottom {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; margin: 0; gap: 0; width: 100%; box-sizing: border-box;
    background: var(--card); border-top: 1px solid var(--line); padding: 6px 2px calc(6px + env(safe-area-inset-bottom));
  }
  /* 6 onglets : chacun prend 1/6 de la largeur, sans jamais déborder de l'écran */
  .nav a { flex: 1 1 0; min-width: 0; flex-direction: column; gap: 0; padding: 6px 0; font-size: 10px; border-radius: 8px; justify-content: center; text-align: center; white-space: nowrap; }
  .nav .ico { font-size: 18px; }
  .nav .pill { position: absolute; top: 0; right: 50%; margin-right: -22px; }
  .me { margin-left: auto; }
  h1 { font-size: 24px; }
  .wrap { padding-bottom: 96px; } /* le contenu ne passe pas sous le menu du bas */
}

/* ---------- layout ---------- */
.wrap { max-width: 1080px; margin: 0 auto; padding: 20px 16px 40px; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 860px) { .g3, .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 760px) { .g2 { grid-template-columns: 1fr; } }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); min-width: 0; }
.card.flat { box-shadow: none; }
.section { margin-top: 24px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.stack > * + * { margin-top: 10px; }

.month-nav { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; flex-wrap: wrap; }
.month-nav h1 { min-width: 0; }

/* ---------- hero ---------- */
.hero { display: grid; grid-template-columns: 1.3fr 1fr; gap: 16px; }
@media (max-width: 760px) { .hero { grid-template-columns: 1fr; } }
.hero .big { font-family: var(--display); font-size: 42px; font-weight: 600; letter-spacing: -.03em; line-height: 1; margin: 6px 0 10px; }
.label { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 500; }
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-top: 14px; }
@media (max-width: 520px) { .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } .hero .big { font-size: 38px; } }
.kpi { border-radius: 10px; padding: 10px 12px; background: transparent; border: 1px solid var(--line); }
.kpi b { display: block; font-size: 17px; font-weight: 600; }
.kpi i { font-style: normal; font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: var(--c, var(--muted)); flex: none; }

.split { display: flex; height: 6px; border-radius: 999px; overflow: hidden; background: var(--soft); margin-top: 6px; }
.split span { display: block; height: 100%; }

.person-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.person-head .avatar { width: 34px; height: 34px; font-size: 15px; }
.lines { width: 100%; border-collapse: collapse; }
.lines td { padding: 5px 0; border-bottom: 1px dashed var(--line); }
.lines tr:last-child td { border-bottom: 0; }
.lines td:last-child { text-align: right; }
.lines tr.total td { font-weight: 600; border-top: 1px solid var(--line); border-bottom: 0; padding-top: 8px; }

/* ---------- category bars ---------- */
.bars { display: grid; gap: 10px; }
.bar-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 10px; align-items: center; }
.bar-row .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-row .track { grid-column: 1 / -1; height: 6px; border-radius: 999px; background: var(--soft); overflow: hidden; position: relative; }
.bar-row .fill { height: 100%; border-radius: 999px; background: var(--c, var(--variable)); }
.bar-row .fill.over { background: var(--danger); }
.bar-row .mark { position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--ink); opacity: .35; }

/* ---------- trend chart ---------- */
.trend { display: grid; grid-template-columns: repeat(12, 1fr); gap: 6px; align-items: end; height: 160px; margin-top: 8px; }
.trend .col { display: flex; flex-direction: column; justify-content: flex-end; align-items: center; height: 100%; gap: 4px; text-decoration: none; }
.trend .stackbar { width: 100%; max-width: 28px; display: flex; flex-direction: column-reverse; border-radius: 4px; overflow: hidden; }
.trend .stackbar span { display: block; width: 100%; }
.trend .col small { font-size: 11px; color: var(--muted); }
.trend .col.on small { color: var(--ink); font-weight: 600; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-top: 10px; }
.legend span { display: flex; align-items: center; gap: 6px; }

/* ---------- forms ---------- */
input, select, textarea, button { font: inherit; color: inherit; }
input[type=text], input[type=password], input[type=number], input[type=date], input[type=search], input[type=email], select, textarea {
  width: 100%; padding: 9px 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--ink); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ink) 10%, transparent); }
label.f { display: block; }
label.f > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; font-weight: 500; }
.form-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); align-items: end; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 16px; border-radius: 8px;
  border: 1px solid var(--accent); background: var(--accent); color: var(--bg); font-weight: 500; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn.ghost:hover { background: var(--soft); }
.btn.danger { background: transparent; color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.btn.small { padding: 6px 12px; font-size: 13px; }
.btn.round { width: 36px; height: 36px; padding: 0; font-size: 18px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

/* ---------- table / list ---------- */
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.filters select, .filters input { width: auto; flex: 1 1 150px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { padding: 5px 12px; border-radius: 8px; border: 1px solid var(--line); text-decoration: none; font-size: 13px; color: var(--muted); }
.chip.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }

.ops { list-style: none; margin: 0; padding: 0; }
.op { display: grid; grid-template-columns: 44px minmax(0, 1fr) auto; gap: 4px 12px; padding: 12px 4px; border-bottom: 1px solid var(--line); align-items: center; }
.op:last-child { border-bottom: 0; }
.op .ic { width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; background: var(--soft); font-size: 18px; grid-row: span 2; }
.op .lbl { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.op .amt { font-weight: 600; text-align: right; }
.op .meta { grid-column: 2 / 4; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: 13px; color: var(--muted); }
.op .meta select { width: auto; max-width: 230px; padding: 4px 8px; font-size: 13px; border-radius: 6px; }
.op.todo .ic { background: color-mix(in srgb, var(--danger) 14%, var(--soft)); }
.op.todo .meta select { border-color: color-mix(in srgb, var(--danger) 50%, var(--line)); }
.tag { font-size: 11px; padding: 2px 8px; border-radius: 6px; background: var(--soft); color: var(--muted); font-weight: 500; }
.tag.shared { background: color-mix(in srgb, #e0567a 18%, var(--soft)); color: #b23a5d; }
.tag.auto { background: color-mix(in srgb, var(--revenu) 14%, var(--soft)); color: var(--revenu); }
.day { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; padding: 14px 4px 4px; }

table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
table.tbl th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; padding: 8px 6px; border-bottom: 1px solid var(--line); }
table.tbl td { padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.tbl td.r, table.tbl th.r { text-align: right; }
.scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* Catégories sur téléphone : chaque ligne passe sur deux rangées (icône + nom en grand, puis budget + boutons) */
@media (max-width: 760px) {
  table.cats, table.cats tbody { display: block; width: 100%; }
  table.cats .cats-head { display: none; }
  table.cats tr { display: grid; grid-template-columns: 52px minmax(0, 1fr) auto; gap: 8px; padding: 10px 0; border-bottom: 1px solid var(--line); align-items: center; }
  table.cats td { display: block; padding: 0; border: 0; width: auto !important; min-width: 0; }
  table.cats td.c-name { grid-column: 2 / 4; }
  table.cats td.c-bud { grid-column: 2; grid-row: 2; }
  table.cats td.c-act { grid-column: 3; grid-row: 2; display: flex; gap: 6px; align-items: center; justify-content: flex-end; }
  table.cats td.c-act form { display: inline-flex !important; }
  table.cats tr.cats-months { grid-template-columns: 1fr; }
  table.cats tr.cats-months td:first-child { display: none; }
  table.cats tr.cats-months td { grid-column: 1 / -1; }
}

/* ---------- jour / nuit ---------- */
.t-ico { display: none; font-size: 17px; }
@media (max-width: 760px) {
  .t-full { display: none; }
  .t-ico { display: inline; }
  .me { gap: 12px; }
}
.theme-btn { width: 34px; height: 34px; padding: 0; border-radius: 50%; border: 1px solid var(--line); background: transparent; cursor: pointer; font-size: 16px; line-height: 1; display: grid; place-items: center; flex: none; }
.theme-btn:hover { background: var(--soft); }

.flash { padding: 12px 16px; border-radius: 10px; margin-bottom: 14px; background: color-mix(in srgb, var(--ok) 14%, var(--card)); border: 1px solid color-mix(in srgb, var(--ok) 30%, transparent); }
.flash.err { background: color-mix(in srgb, var(--danger) 12%, var(--card)); border-color: color-mix(in srgb, var(--danger) 30%, transparent); }
.flash.warn { background: color-mix(in srgb, var(--variable) 14%, var(--card)); border-color: color-mix(in srgb, var(--variable) 35%, transparent); }

.empty { text-align: center; padding: 30px 10px; color: var(--muted); }
.balance-card { display: flex; align-items: center; gap: 14px; }
.balance-card .heart { font-size: 28px; }

details.adder { margin-top: 14px; }
details.adder summary { cursor: pointer; font-weight: 600; list-style: none; }
details.adder summary::-webkit-details-marker { display: none; }
details.adder[open] summary { margin-bottom: 12px; }

/* ---------- login ---------- */
.login { max-width: 380px; margin: 10vh auto 0; }
.login .brand { justify-content: center; font-size: 26px; margin-bottom: 20px; }

.bank-list { max-height: 360px; overflow: auto; border: 1px solid var(--line); border-radius: 10px; }
.bank-list label { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--line); cursor: pointer; }
.bank-list label:last-child { border-bottom: 0; }
.bank-list img { width: 28px; height: 28px; object-fit: contain; border-radius: 6px; background: #fff; }
.bank-list label:hover { background: var(--soft); }
