:root {
  color-scheme: dark;
  --bg: #0b1020; --side: #0d1326; --panel: #111a30; --panel-2: #16203a; --line: #1f2b47;
  --text: #e8ecf8; --muted: #8592b0; --accent: #3987e5; --accent-soft: rgba(57,135,229,.16);
  --pos: #34d399; --neg: #f87171; --warn: #fbbf24;
  --bar: #26365a; --grid: #1a2540;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #008300; --s7: #9085e9; --s-other: #64708c;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;
    --bg: #f3f5fa; --side: #fff; --panel: #fff; --panel-2: #f3f5fa; --line: #e2e7f1;
    --text: #0f172a; --muted: #5b6784; --accent: #2a78d6; --accent-soft: rgba(42,120,214,.12);
    --pos: #047857; --neg: #dc2626; --warn: #b45309;
    --bar: #c9d6ee; --grid: #e8ecf5;
    --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100; --s5: #e87ba4; --s6: #008300; --s7: #4a3aa7; --s-other: #94a0bb;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 Inter, system-ui, -apple-system, sans-serif; }
[hidden] { display: none !important; }
h1 { font-size: 1.25rem; margin: 0; } h2 { margin: 0; font-size: .8rem; letter-spacing: .06em; text-transform: uppercase; color: var(--text); }
button, input, select { font: inherit; color: var(--text); background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
button { cursor: pointer; } button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
button.wide { width: 100%; margin-top: 10px; }
button.link { background: none; border: 0; color: var(--accent); padding: 0; font-size: .8rem; }
.hint { color: var(--muted); font-size: .8rem; } .sub { color: var(--muted); margin: 2px 0 0; font-size: .8rem; }
.error { color: var(--neg); min-height: 1.2em; margin: 0; }
.pos { color: var(--pos); } .neg { color: var(--neg); } .warn { color: var(--warn); }

/* ---- Layout ---- */
.shell { display: grid; grid-template-columns: 230px 1fr; min-height: 100vh; }
.side { background: var(--side); border-right: 1px solid var(--line); padding: 16px 12px; display: flex; flex-direction: column; gap: 18px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px; }
.brand small { display: block; color: var(--muted); font-size: .7rem; letter-spacing: .08em; text-transform: uppercase; }
.logo { width: 34px; height: 34px; border-radius: 9px; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 700; }
nav { display: grid; gap: 4px; }
nav button { display: flex; align-items: center; gap: 10px; text-align: left; background: none; border: 0; color: var(--muted); padding: 10px 12px; border-radius: 9px; }
nav button i { font-style: normal; width: 18px; text-align: center; }
nav button:hover { color: var(--text); background: var(--panel-2); }
nav button.active { color: var(--text); background: var(--accent-soft); }
.badge { background: var(--accent); color: #fff; font-style: normal; border-radius: 10px; padding: 0 7px; font-size: .72rem; font-weight: 600; margin-left: auto; }
.badge:empty { display: none; }
.tabs .badge { margin-left: 4px; background: var(--warn); color: #000; }
.side-user { margin-top: auto; display: flex; gap: 10px; align-items: center; padding: 10px 8px; border-top: 1px solid var(--line); }
.side-user small { display: block; color: var(--muted); font-size: .72rem; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 600; text-transform: uppercase; }

.content { padding: 20px 24px 40px; max-width: 1240px; width: 100%; }
.top { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.month-nav { display: flex; align-items: center; gap: 10px; }
.month-nav strong { min-width: 9em; text-align: center; text-transform: capitalize; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px; margin-bottom: 14px; }
.panel-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 14px; gap: 10px; }

/* ---- KPI ---- */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 14px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px; }
.kpi.main { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent-soft) inset; }
.kpi span { display: block; color: var(--muted); font-size: .72rem; letter-spacing: .06em; text-transform: uppercase; }
.kpi b { display: block; font-size: 1.6rem; margin: 6px 0 4px; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.kpi small { color: var(--muted); font-size: .78rem; }
.grid-2 { display: grid; grid-template-columns: 1.6fr 1fr; gap: 14px; }

/* ---- Bar chart ---- */
.bars { position: relative; display: grid; grid-template-columns: 48px 1fr; height: 400px; }
.y-axis { position: relative; margin-bottom: 24px; }
.y-axis span { position: absolute; right: 8px; transform: translateY(50%); color: var(--muted); font-size: .7rem; font-variant-numeric: tabular-nums; }
.plot { position: relative; display: flex; align-items: stretch; margin-bottom: 24px; }
.grid-line { position: absolute; left: 0; right: 0; height: 1px; background: var(--grid); }
.grid-line.base { background: var(--line); }
.col { position: relative; flex: 1; cursor: pointer; z-index: 1; }
.col .bar { position: absolute; bottom: 0; left: 50%; transform: translateX(-50%); width: min(24px, 70%); background: var(--bar); border-radius: 4px 4px 0 0; min-height: 2px; transition: background .15s; }
.col.sel .bar, .col:hover .bar { background: var(--s1); }
.col .val { position: absolute; left: 50%; transform: translateX(-50%); font-size: .72rem; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.col .lbl { position: absolute; bottom: -22px; left: 50%; transform: translateX(-50%); font-size: .72rem; color: var(--muted); text-transform: capitalize; }
.col.sel .lbl { color: var(--text); font-weight: 600; }

/* ---- Donut ---- */
.donut-row { display: flex; justify-content: center; }
.donut { position: relative; width: 150px; height: 150px; }
.donut svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.donut circle { fill: none; stroke-width: 18; cursor: pointer; transition: opacity .15s; }
.donut:hover circle:not(:hover) { opacity: .45; }
.donut .center { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; pointer-events: none; }
.donut .center b { font-size: 1.05rem; font-variant-numeric: tabular-nums; } .donut .center small { color: var(--muted); font-size: .72rem; }
.legend { list-style: none; margin: 16px 0 0; padding: 0; display: grid; gap: 7px; }
.legend li { display: grid; grid-template-columns: 10px 1fr auto auto; gap: 8px; align-items: center; font-size: .82rem; }
.legend .dot { width: 10px; height: 10px; border-radius: 50%; }
.legend .pct { color: var(--muted); width: 3em; text-align: right; font-variant-numeric: tabular-nums; }
.legend .amt { font-variant-numeric: tabular-nums; min-width: 5.5em; text-align: right; }

/* ---- Recent ---- */
.recent-row { display: grid; grid-template-columns: 34px 1fr auto; gap: 12px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.recent-row:last-child { border-bottom: 0; }
.ico { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: var(--panel-2); }
.ico i { width: 10px; height: 10px; border-radius: 50%; display: block; }
.recent-row b { display: block; font-weight: 500; } .recent-row small { color: var(--muted); font-size: .75rem; }
.amt-col { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.amt-col small { display: block; font-weight: 400; }

/* ---- CB panel ---- */
.cbcard { border-radius: 12px; padding: 16px; margin-bottom: 14px; color: #fff; background: linear-gradient(135deg, #1e3a8a, #1d4ed8 60%, #3b82f6); }
.cbcard small { letter-spacing: .1em; text-transform: uppercase; opacity: .85; font-size: .7rem; }
.cbcard b { display: block; font-size: 1.7rem; margin: 4px 0; font-variant-numeric: tabular-nums; }
.stat-line { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.stat-line:last-child { border-bottom: 0; }
.stat-line span { color: var(--muted); } .stat-line b { font-variant-numeric: tabular-nums; }

/* ---- Opérations ---- */
.add { display: grid; grid-template-columns: 130px 1.5fr 1.1fr 110px 120px 1.3fr auto; gap: 10px; align-items: end; }
.add input, .add select { min-width: 0; width: 100%; }
label { display: grid; gap: 4px; color: var(--muted); font-size: .8rem; }
label span { color: var(--text); font-weight: 500; }
label em { color: var(--muted); font-style: normal; font-weight: 400; }
.add.editing { outline: 2px solid var(--accent); outline-offset: 6px; border-radius: 8px; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.tabs button.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.tabs small { opacity: .8; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 6px; border-bottom: 1px solid var(--line); text-align: left; }
th { color: var(--muted); font-weight: 500; font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.checked td:not(.chk) { opacity: .5; }
tfoot td { font-weight: 600; border-bottom: 0; }
.tag { font-size: .72rem; color: var(--muted); background: var(--panel-2); border-radius: 6px; padding: 2px 6px; }
.row-actions { white-space: nowrap; } .row-actions button { padding: 2px 8px; border: 0; background: none; color: var(--muted); }
.empty { color: var(--muted); text-align: center; padding: 20px; }
input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--accent); }
h3.sub { margin: 18px 0 4px; font-size: .95rem; } h3.sub small { color: var(--muted); font-weight: 400; }
tr.planned td { opacity: .75; font-style: italic; background: var(--accent-soft); }
tr.planned td.chk button { padding: 0 8px; font-style: normal; }

/* ---- Login / dialogs / tooltip ---- */
#login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 340px; display: grid; gap: 14px; }
.stack { display: grid; gap: 10px; }
dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 14px; width: min(760px, calc(100vw - 24px)); padding: 16px; }
dialog::backdrop { background: rgba(0,0,0,.55); }
.dlg-head { display: flex; justify-content: space-between; align-items: center; margin: 0 0 8px; }
.dlg-head h2 { font-size: 1rem; text-transform: none; letter-spacing: 0; }
dialog .add { grid-template-columns: 1.4fr 1.2fr 110px 90px 120px 1.6fr auto; margin-top: 12px; }
.tip { position: fixed; z-index: 50; pointer-events: none; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: .8rem; box-shadow: 0 6px 20px rgba(0,0,0,.35); max-width: 240px; }
.tip b { display: block; } .tip span { color: var(--muted); }

/* ---- Responsive ---- */
@media (max-width: 980px) {
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; padding-bottom: 64px; }
  .side { position: fixed; bottom: 0; left: 0; right: 0; top: auto; height: auto; flex-direction: row; padding: 6px; z-index: 20; border-right: 0; border-top: 1px solid var(--line); }
  .side .brand, .side-user { display: none; }
  nav { grid-auto-flow: column; grid-auto-columns: 1fr; width: 100%; }
  nav button { flex-direction: column; gap: 2px; padding: 6px 2px; font-size: .68rem; text-align: center; justify-content: center; position: relative; }
  nav .badge { position: absolute; top: 2px; right: 18%; margin: 0; }
  .content { padding: 14px 12px 24px; }
  .add, dialog .add { grid-template-columns: 1fr 1fr; }
  .add button.primary { grid-column: 1 / -1; }
  th.hide-m, td.hide-m { display: none; }
  .kpi b { font-size: 1.25rem; }
}

/* ---- Page opérations / récurrents ---- */
.page-actions { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-bottom: 14px; }
.tile { border-radius: 12px; padding: 14px 16px; border: 1px solid var(--line); }
.tile span { display: block; color: var(--muted); font-size: .75rem; }
.tile b { display: block; font-size: 1.35rem; margin-top: 4px; font-variant-numeric: tabular-nums; }
.tile small { color: var(--muted); font-size: .75rem; }
.t-green { background: color-mix(in srgb, var(--pos) 12%, var(--panel)); } .t-green b { color: var(--pos); }
.t-red { background: color-mix(in srgb, var(--neg) 12%, var(--panel)); } .t-red b { color: var(--neg); }
.t-amber { background: color-mix(in srgb, var(--warn) 12%, var(--panel)); } .t-amber b { color: var(--warn); }
.t-blue { background: var(--panel); }
.filters { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 12px; }
.filters input { flex: 1; min-width: 180px; }
.seg { display: flex; background: var(--panel-2); border: 1px solid var(--line); border-radius: 9px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: none; padding: 5px 12px; border-radius: 7px; color: var(--muted); }
.seg button.active { background: var(--panel); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.25); }
.day { margin: 16px -16px 0; padding: 7px 16px; background: var(--panel-2); color: var(--muted); font-size: .78rem; text-transform: capitalize; }
.day:first-of-type, .hint + .day { margin-top: 4px; }
.tx { display: grid; grid-template-columns: 22px 34px 1fr auto auto; gap: 12px; align-items: center; padding: 11px 0; border-bottom: 1px solid var(--line); }
.tx.done .tx-main, .tx.done .tx-amt, .tx.done .ico { opacity: .55; }
.tx-main b { font-weight: 500; display: block; }
.tx-tags { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 3px; }
.tag.todo { color: var(--warn); background: color-mix(in srgb, var(--warn) 14%, transparent); }
.tag.ok { color: var(--pos); background: color-mix(in srgb, var(--pos) 14%, transparent); }
.tx-amt { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tx .row-actions { opacity: .35; } .tx:hover .row-actions { opacity: 1; }
#rec-form { grid-template-columns: 1.4fr 1.2fr 110px 90px 120px 1.6fr auto; }
@media (max-width: 980px) { .tiles { grid-template-columns: 1fr; } }
@media (max-width: 760px) {
  #rec-form { grid-template-columns: 1fr 1fr; }
  .tx { grid-template-columns: 22px 1fr auto; } .tx .ico { display: none; } .tx .row-actions { grid-column: 2 / -1; opacity: 1; }
}

.edit-form { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.edit-form input, .edit-form select { width: 100%; }
.edit-form .full { grid-column: 1 / -1; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 4px; }
dialog { max-width: 520px; }
