:root {
  --bg: #f1f5f9; --card: #fff; --text: #0f172a; --muted: #64748b; --line: #e2e8f0;
  --accent: #2563eb; --pos: #15803d; --neg: #b91c1c; --warn-bg: #fef3c7;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0b1220; --card: #131c2e; --text: #e2e8f0; --muted: #94a3b8; --line: #1f2a40;
    --accent: #60a5fa; --pos: #4ade80; --neg: #f87171; --warn-bg: #3b2f0a; }
}
* { box-sizing: border-box; }
/* L'attribut hidden doit toujours gagner sur les display: grid/flex des composants. */
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
body { padding-bottom: env(safe-area-inset-bottom); }
button, input, select { font: inherit; color: inherit; }
button, .btn { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: .45rem .8rem; cursor: pointer; display: inline-block; }
button:hover, .btn:hover { border-color: var(--accent); }
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
button.ghost { background: transparent; border-color: transparent; }
button.ghost:hover { border-color: var(--line); }
button.small { padding: .15rem .45rem; font-size: .85em; }
button.danger { color: var(--neg); border-color: var(--neg); }
button:disabled { opacity: .5; cursor: not-allowed; }
input, select { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: .4rem .6rem; max-width: 100%; }
input[type=checkbox] { width: auto; }
input[type=color] { padding: 0; height: 2.2rem; width: 4rem; }
h1, h2 { margin: 0 0 .6rem; } h2 { font-size: 1.05rem; }
code { background: var(--bg); padding: 0 .3rem; border-radius: 4px; }
.muted { color: var(--muted); } .small { font-size: .85em; }
.pos { color: var(--pos); } .neg { color: var(--neg); }
.pos-bg { background: var(--pos); } .neg-bg { background: var(--neg); }
.nowrap { white-space: nowrap; }

.lock { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.lock-card { background: var(--card); padding: 2rem; border-radius: 16px; width: min(380px, 100%); display: grid; gap: .7rem; text-align: center; box-shadow: 0 10px 30px rgb(0 0 0 / .08); }
.lock-card img { margin: 0 auto; }
.error { color: var(--neg); min-height: 1.2em; margin: 0; }
.hint { color: var(--muted); font-size: .85em; margin: 0; }

.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 1rem; padding: .6rem 1rem;
  padding-top: max(.6rem, env(safe-area-inset-top)); background: #0f172a; color: #fff; }
.top .balance { margin-left: auto; font-weight: 700; }
.top .balance.pos { color: #86efac; } .top .balance.neg { color: #fca5a5; }
.top button { color: #fff; }
.nav { display: flex; gap: .25rem; overflow-x: auto; padding: .5rem 1rem; background: var(--card); border-bottom: 1px solid var(--line); scrollbar-width: none; }
.nav button { border: 0; background: transparent; white-space: nowrap; color: var(--muted); }
.nav button.active { color: var(--accent); font-weight: 600; box-shadow: inset 0 -2px var(--accent); border-radius: 0; }
main { max-width: 1000px; margin: 0 auto; padding: 1rem; display: grid; gap: 1rem; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 1rem; min-width: 0; }
.card.inner { padding: .75rem; }
.card.danger { border-color: color-mix(in srgb, var(--neg) 40%, var(--line)); }
.grid3 { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.stat span { color: var(--muted); font-size: .85em; display: block; }
.stat b { font-size: 1.5rem; }
.notice { background: var(--warn-bg); padding: .6rem 1rem; border-radius: 10px; margin: 0; }
.notice a { color: inherit; font-weight: 600; }
.row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.row.end { justify-content: flex-end; }
.toolbar { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin-bottom: .6rem; }
.toolbar input[type=search] { flex: 1 1 180px; }
.check { display: inline-flex; gap: .35rem; align-items: center; }
.form-inline { display: flex; flex-wrap: wrap; gap: .6rem; align-items: end; margin-bottom: .6rem; }
.form-inline label { display: grid; gap: .2rem; font-size: .85em; color: var(--muted); }
.form-inline label.check { display: inline-flex; }

.bars { display: grid; gap: .35rem; }
.bar-row { display: grid; grid-template-columns: 9rem 1fr 7.5rem; gap: .6rem; align-items: center; font-size: .9em; }
.bar-row b { text-align: right; }
.bar-track { background: var(--bg); border-radius: 6px; height: .8rem; overflow: hidden; }
.bar { height: 100%; border-radius: 6px; opacity: .8; }

.txlist { display: grid; }
.tx { border-top: 1px solid var(--line); padding: .5rem 0; }
.tx-main { display: flex; gap: .6rem; align-items: baseline; min-width: 0; }
.tx-main .date { color: var(--muted); font-size: .85em; flex: none; }
.tx-main .label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.amt { margin-left: auto; white-space: nowrap; font-variant-numeric: tabular-nums; }
.tx-sub { display: flex; gap: .3rem; align-items: center; margin-top: .3rem; flex-wrap: wrap; }
.tx-sub select { flex: 1 1 200px; font-size: .85em; padding: .2rem .4rem; }
.badge { color: var(--accent); }
.chip { display: inline-block; padding: .05rem .5rem; border-radius: 99px; font-size: .85em;
  background: color-mix(in srgb, var(--c) 18%, transparent); border: 1px solid color-mix(in srgb, var(--c) 45%, transparent); }

.rub { border-left: 4px solid var(--c); padding: .4rem .8rem; margin: .6rem 0; }
.rub-head { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.dot { width: .7rem; height: .7rem; border-radius: 50%; background: var(--c); }
.comptes { list-style: none; margin: .3rem 0 0; padding: 0; }
.comptes li { display: grid; grid-template-columns: 1fr auto auto; gap: .5rem; align-items: center; padding: .2rem 0 .2rem 1.2rem; border-top: 1px dashed var(--line); }

.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: .4rem .4rem; border-top: 1px solid var(--line); vertical-align: middle; }
.table th { color: var(--muted); font-weight: 500; font-size: .85em; }
.table td.amt, .fc td:not(:first-child), .fc th:not(:first-child) { text-align: right; font-variant-numeric: tabular-nums; }
.card { overflow-x: auto; }
.fc-item { display: grid; grid-template-columns: 6rem 1fr auto; gap: .5rem; padding: .2rem 0; font-size: .9em; }
.fc-detail td { background: var(--bg); text-align: left !important; }
.reclist { display: grid; gap: .6rem; }
.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .5rem; }
.kv div { background: var(--bg); border-radius: 8px; padding: .5rem .7rem; display: grid; }
.kv span, .kv small { color: var(--muted); font-size: .8em; }
.import-preview { margin-top: 1rem; display: grid; gap: .6rem; }

dialog { border: 1px solid var(--line); border-radius: 14px; background: var(--card); color: var(--text); width: min(480px, calc(100vw - 2rem)); padding: 1.2rem; }
dialog::backdrop { background: rgb(0 0 0 / .45); }
dialog form { display: grid; gap: .7rem; }
dialog label { display: grid; gap: .25rem; font-size: .9em; }
dialog label:has(input[type=checkbox]) { display: flex; flex-direction: row-reverse; justify-content: flex-end; gap: .5rem; align-items: center; }
.toast { position: fixed; left: 50%; bottom: 1.5rem; transform: translate(-50%, 200%); background: #0f172a; color: #fff;
  padding: .6rem 1rem; border-radius: 10px; transition: transform .25s; max-width: calc(100vw - 2rem); z-index: 20; }
.toast.show { transform: translate(-50%, 0); }

@media (max-width: 600px) {
  main { padding: .6rem; gap: .6rem; }
  .bar-row { grid-template-columns: 6.5rem 1fr 6.5rem; font-size: .8em; }
  .stat b { font-size: 1.25rem; }
  .table th:nth-child(4), .table td:nth-child(4) { display: none; }
  .fc th:nth-child(4), .fc td:nth-child(4) { display: table-cell; }
}
