:root {
  color-scheme: light;
  --bg: #f4f3ef; --surface: #fcfcfb; --surface-2: #eeede8; --line: #dddbd3;
  --text: #0b0b0b; --text-2: #52514e; --text-3: #85837c;
  --accent: #1c5cab; --accent-ink: #ffffff; --sel: #dfeafa;
  --neg: #b3261e; --pos: #17691c;
  --series-1: #2a78d6; --series-2: #eb6834;
  --warn-bg: #fdf1d3; --warn-line: #e5c467;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #121211; --surface: #1a1a19; --surface-2: #252523; --line: #383835;
    --text: #f0efec; --text-2: #c3c2b7; --text-3: #8f8d84;
    --accent: #6da7ec; --accent-ink: #0b0b0b; --sel: #1d3350;
    --neg: #f08a84; --pos: #7fd086;
    --series-1: #3987e5; --series-2: #d95926;
    --warn-bg: #3a3014; --warn-line: #7a6420;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.4 -apple-system, "Segoe UI", system-ui, Roboto, sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; font-weight: 600; }
h2 { font-size: 18px; } h3 { font-size: 14px; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.neg { color: var(--neg); } .pos { color: var(--pos); }
.muted { color: var(--text-3); } .small { font-size: 12px; }

/* contrôles */
.btn { border: 1px solid var(--line); background: var(--surface); border-radius: 7px; padding: 6px 12px; cursor: pointer; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.1); }
.btn.danger { color: var(--neg); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn:disabled { opacity: .5; cursor: default; }
input[type=text], input[type=search], input[type=date], input[type=password], select, textarea {
  border: 1px solid var(--line); background: var(--surface); border-radius: 7px; padding: 6px 8px; min-width: 0; }
input:focus-visible, select:focus-visible, button:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label.f { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--text-2); }
label.f > * { font-size: 14px; color: var(--text); }
label.chk { display: flex; gap: 6px; align-items: center; }

/* structure */
.shell { display: grid; grid-template-rows: auto 1fr; height: 100vh; }
.top { display: flex; align-items: center; gap: 4px; padding: 8px 16px; background: var(--surface); border-bottom: 1px solid var(--line); overflow-x: auto; }
.top .brand { font-weight: 700; margin-right: 16px; white-space: nowrap; }
.top .tab { border: 0; background: none; padding: 6px 12px; border-radius: 7px; cursor: pointer; color: var(--text-2); white-space: nowrap; }
.top .tab:hover { background: var(--surface-2); }
.top .tab.on { background: var(--sel); color: var(--text); font-weight: 600; }
.top .sp { flex: 1; }
.view { overflow: auto; min-height: 0; }
.page { max-width: 1100px; margin: 0 auto; padding: 20px 16px 60px; display: flex; flex-direction: column; gap: 16px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 16px; }
.row { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; }
.row.center { align-items: center; }
.grow { flex: 1; }

/* opérations */
.ops { display: grid; grid-template-columns: 270px 1fr; height: 100%; min-height: 0; }
.side { overflow: auto; border-right: 1px solid var(--line); background: var(--surface); padding: 8px; }
.side .grp { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-3); margin-top: 12px; }
.side .it { display: flex; align-items: center; gap: 8px; width: 100%; border: 0; background: none; text-align: left;
  padding: 6px 8px; border-radius: 7px; cursor: pointer; }
.side .it:hover { background: var(--surface-2); }
.side .it.on { background: var(--sel); }
.side .it .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side .it img, .side .it .noicon { width: 20px; height: 20px; object-fit: contain; flex: none; }
.side .it.hid { opacity: .55; }
.main { display: grid; grid-template-rows: auto auto 1fr; min-height: 0; min-width: 0; }
.head { display: flex; gap: 24px; align-items: end; padding: 14px 16px 8px; flex-wrap: wrap; }
.head .stat { display: flex; flex-direction: column; }
.head .stat b { font-size: 18px; font-variant-numeric: tabular-nums; }
.head .stat span { font-size: 12px; color: var(--text-2); }
.bar { display: flex; gap: 8px; padding: 6px 16px 10px; flex-wrap: wrap; align-items: center; }
.bar input[type=search] { width: 220px; }
.tablewrap { overflow: auto; min-height: 0; border-top: 1px solid var(--line); background: var(--surface); }
table { border-collapse: collapse; width: 100%; }
th { position: sticky; top: 0; background: var(--surface-2); text-align: left; font-weight: 600; font-size: 12px; color: var(--text-2);
  padding: 6px 10px; z-index: 1; white-space: nowrap; }
td { padding: 6px 10px; border-top: 1px solid var(--line); vertical-align: top; }
tr.tx { cursor: pointer; }
tr.tx:hover td { background: var(--surface-2); }
tr.future td { color: var(--text-2); font-style: italic; }
tr.future td.num { font-style: normal; }
td .c { font-size: 12px; color: var(--text-3); }
.chip { display: inline-flex; align-items: center; gap: 5px; margin-right: 8px; white-space: nowrap; }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; display: inline-block; border: 1px solid rgba(128,128,128,.4); }
.more { padding: 14px; text-align: center; }

/* dialogue */
dialog { border: 1px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--text); padding: 0;
  width: min(720px, calc(100vw - 24px)); max-height: calc(100vh - 24px); }
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog form { display: flex; flex-direction: column; gap: 14px; padding: 18px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.split { display: grid; grid-template-columns: 38px 120px 1fr 1fr 32px; gap: 6px; align-items: center; margin-bottom: 6px; }
.split .sign { padding: 6px 0; font-weight: 700; }
.split .sign.minus { color: var(--neg); } .split .sign.plus { color: var(--pos); }
.split input.amt { text-align: right; font-variant-numeric: tabular-nums; }
.actions { display: flex; gap: 8px; justify-content: flex-end; align-items: center; }

/* connexion */
.login { max-width: 360px; margin: 12vh auto; display: flex; flex-direction: column; gap: 12px; }
.err { color: var(--neg); min-height: 1.4em; }
.note { background: var(--warn-bg); border: 1px solid var(--warn-line); border-radius: 8px; padding: 10px 12px; }

/* graphiques */
.viz svg { display: block; width: 100%; height: auto; overflow: visible; }
.viz text { fill: var(--text-2); font-size: 11px; }
.viz .grid { stroke: var(--line); stroke-width: 1; }
.viz .zero { stroke: var(--text-3); stroke-width: 1; }
.viz .s1 { fill: var(--series-1); } .viz .s2 { fill: var(--series-2); }
.viz .l1 { stroke: var(--series-1); stroke-width: 2; fill: none; stroke-linejoin: round; }
.viz .cross { stroke: var(--text-3); stroke-width: 1; }
.viz .pt { fill: var(--series-1); stroke: var(--surface); stroke-width: 2; }
.viz .hit { fill: transparent; }
.viz .hit:hover { fill: rgba(128,128,128,.12); }
.legend { display: flex; gap: 16px; font-size: 12px; color: var(--text-2); margin: 4px 0 8px; }
.legend i { width: 10px; height: 10px; border-radius: 2px; display: inline-block; margin-right: 6px; }
.catbar { height: 10px; border-radius: 0 4px 4px 0; background: var(--series-2); min-width: 1px; }
.catbar.inc { background: var(--series-1); }

/* tri, pastilles, catégories, échéancier, import */
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover, th.sortable.on { color: var(--text); }
th .arr { font-size: 10px; }
.chip.pill { padding: 1px 8px 1px 6px; border-radius: 999px; font-size: 12px; line-height: 18px; margin: 1px 6px 1px 0;
  background: color-mix(in srgb, var(--c, #888) 16%, transparent); border: 1px solid color-mix(in srgb, var(--c, #888) 45%, transparent); }
.chip.pill.xfer { --c: var(--text-3); }
.stack { display: flex; flex-direction: column; gap: 12px; }
.stats { display: flex; gap: 24px; flex-wrap: wrap; }
.stat { display: flex; flex-direction: column; }
.stats .stat b { font-size: 18px; font-variant-numeric: tabular-nums; }
.stats .stat span { font-size: 12px; color: var(--text-2); }
.catgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; }
.catcard { background: var(--surface); border: 1px solid var(--line); border-top: 4px solid var(--c); border-radius: 10px;
  padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.catcard input[type=text] { flex: 1; font-weight: 600; }
input[type=color] { width: 34px; height: 30px; padding: 2px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); flex: none; }
.catnum { display: flex; align-items: baseline; gap: 8px; }
.catnum b { font-size: 18px; }
.meter { background: var(--surface-2); height: 10px; border-radius: 0 4px 4px 0; }
.legend i { vertical-align: -1px; }
tr.mrow td { background: var(--surface-2); font-weight: 600; text-transform: capitalize; }
tr.paused td { color: var(--text-3); }
tr.dim td { color: var(--text-3); }
.tag { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 999px; background: var(--surface-2);
  color: var(--text-2); white-space: nowrap; margin-left: 6px; border: 1px solid var(--line); }
td > .tag:first-child, td > div > .tag:first-child { margin-left: 0; }
.tag.ok { border-color: color-mix(in srgb, var(--pos) 50%, transparent); color: var(--pos); }
.tag.new { border-color: color-mix(in srgb, var(--accent) 50%, transparent); color: var(--accent); }
.newop { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.newop input { min-width: 160px; }
/* rectangles de catégorie */
.cat { display: inline-block; padding: 2px 9px; border-radius: 4px; font-size: 12px; font-weight: 600; line-height: 18px;
  margin: 1px 6px 1px 0; white-space: nowrap; }
.cat.xfer { background: transparent; color: var(--text-2); border: 1px dashed var(--text-3); padding: 1px 8px; font-weight: 500; }
.catcard { border-top-width: 1px; padding: 0; overflow: hidden; }
.catcard > *:not(.catband) { margin: 0 12px; }
.catcard > *:last-child { margin-bottom: 12px; }
.catband { display: flex; align-items: center; gap: 8px; padding: 10px 12px; }
.catband input[type=text] { background: transparent; border-color: transparent; color: inherit; font-weight: 700; font-size: 15px; }
.catband input[type=text]:hover, .catband input[type=text]:focus { border-color: currentColor; }
.catband input[type=color] { border-color: currentColor; background: transparent; }

/* groupes dépliables, séparateurs mensuels, banques */
.side .grp { display: flex; align-items: center; gap: 2px; }
.side .grp .it { flex: 1; min-width: 0; }
.fold { border: 0; background: none; cursor: pointer; color: var(--text-2); width: 22px; padding: 4px 0; font-size: 15px; line-height: 1; flex: none; text-transform: none; }
.fold:hover { color: var(--text); }
.fold svg { display: block; margin: 0 auto; transition: transform .15s; }
.fold[aria-expanded="true"] svg { transform: rotate(90deg); }
.side .kids .it { padding-left: 22px; }
tr.msep td { background: var(--surface-2); border-top: 2px solid var(--line); padding-top: 8px; padding-bottom: 8px; }
tr.msep td b { text-transform: capitalize; }
.banklink { text-decoration: none; display: inline-block; white-space: nowrap; }
.head .banklink { align-self: center; margin-left: auto; }
.banklist { display: flex; flex-direction: column; gap: 8px; }
.bankrow { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2); }

.drop { border: 2px dashed var(--line); border-radius: 10px; padding: 18px; text-align: center; }
.drop.over { border-color: var(--accent); background: var(--sel); }
.tip { position: fixed; z-index: 50; pointer-events: none; background: var(--text); color: var(--bg); padding: 6px 9px;
  border-radius: 6px; font-size: 12px; white-space: pre-line; max-width: 260px; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg);
  padding: 9px 16px; border-radius: 8px; z-index: 60; }
.scroll-x { overflow-x: auto; }

@media (max-width: 1150px) { .hide-md { display: none; } }
@media (max-width: 760px) {
  .ops { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .side { max-height: 30vh; border-right: 0; border-bottom: 1px solid var(--line); }
  .hide-sm { display: none; }
  .split { grid-template-columns: 38px 1fr 32px; }
  .split select, .split .cm { grid-column: 1 / -1; }
}
