:root {
  --bg: #0f1115; --panel: #171a21; --panel2: #1e222b; --line: #2a2f3a;
  --text: #e8eaf0; --muted: #8b93a5; --green: #22c55e; --red: #f87171; --amber: #fbbf24; --blue: #60a5fa;
  --radius: 14px;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; -webkit-text-size-adjust: 100%; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.err { color: var(--red); min-height: 1.2em; margin: 6px 0 0; }
.pos { color: var(--green); }
.neg { color: var(--text); }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 340px; background: var(--panel); border: 1px solid var(--line); border-radius: 20px; padding: 28px 22px; display: grid; gap: 12px; text-align: center; }
.login-card h1 { margin: 0 0 6px; font-size: 22px; }
.logo { width: 52px; height: 52px; margin: 0 auto; border-radius: 14px; background: #16a34a; display: grid; place-items: center; font-size: 28px; font-weight: 700; }

/* Layout */
#app { max-width: 820px; margin: 0 auto; padding: 0 16px calc(90px + env(safe-area-inset-bottom)); }
.top { display: flex; justify-content: space-between; align-items: center; padding: 16px 0 10px; }
.brand { font-weight: 700; font-size: 20px; }
.tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 8px; margin-bottom: 8px; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button { flex: 0 0 auto; background: var(--panel); border: 1px solid var(--line); color: var(--muted); padding: 8px 14px; border-radius: 999px; font: inherit; cursor: pointer; }
.tabs button.active { background: var(--text); color: var(--bg); border-color: var(--text); font-weight: 600; }
.badge { display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 999px; background: var(--amber); color: #111; font-size: 12px; font-weight: 700; text-align: center; margin-left: 4px; }
@media (max-width: 640px) {
  .tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; margin: 0; padding: 8px 8px calc(8px + env(safe-area-inset-bottom)); background: rgba(15,17,21,.96); border-top: 1px solid var(--line); justify-content: space-between; backdrop-filter: blur(8px); }
  .tabs button { flex: 1 1 0; padding: 8px 4px; font-size: 12.5px; border-radius: 10px; }
  .tabs .badge { margin-left: 2px; min-width: 16px; padding: 0 4px; font-size: 11px; }
}

/* Cartes */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; }
.card h2 { margin: 0 0 12px; font-size: 16px; }
.card h3 { margin: 0 0 8px; font-size: 14px; color: var(--muted); font-weight: 600; }
.hero { text-align: left; }
.hero .big { font-size: 34px; font-weight: 700; letter-spacing: -0.5px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 14px; }
.stat { background: var(--panel2); border-radius: 10px; padding: 10px; }
.stat .v { font-weight: 650; font-size: 15px; }
.stat .k { color: var(--muted); font-size: 12px; }
@media (max-width: 420px) { .stats { grid-template-columns: 1fr 1fr; } .hero .big { font-size: 30px; } }

.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 10px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: 0 0 auto; background: var(--panel); border: 1px solid var(--line); color: var(--text); padding: 6px 12px; border-radius: 999px; font: inherit; font-size: 13.5px; cursor: pointer; }
.chip.active { border-color: var(--green); color: var(--green); }

/* Barres catégories */
.bar-row { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; margin-bottom: 10px; font-size: 14px; }
.bar { grid-column: 1 / -1; height: 6px; border-radius: 3px; background: var(--panel2); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--blue); border-radius: 3px; }

/* Listes d'opérations */
.op { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; padding: 11px 0; border-top: 1px solid var(--line); cursor: pointer; }
.op:first-child { border-top: 0; }
.op .t { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.op .d { color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.op .a { font-weight: 650; text-align: right; }
.tag { display: inline-block; font-size: 11.5px; padding: 1px 8px; border-radius: 999px; background: var(--panel2); color: var(--muted); }
.tag.warn { background: rgba(251,191,36,.15); color: var(--amber); }
.tag.save { background: rgba(96,165,250,.15); color: var(--blue); }

/* Formulaires */
label { display: block; font-size: 12.5px; color: var(--muted); margin: 10px 0 4px; }
input, select, textarea { width: 100%; background: var(--panel2); border: 1px solid var(--line); color: var(--text); border-radius: 10px; padding: 10px 12px; font: inherit; font-size: 16px; }
input:focus, select:focus { outline: 2px solid var(--blue); outline-offset: -1px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row > * { flex: 1 1 140px; }
.check { display: flex; gap: 8px; align-items: flex-start; font-size: 13.5px; color: var(--text); margin-top: 12px; }
.check input { width: auto; margin-top: 3px; }
.btn { background: var(--panel2); color: var(--text); border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; font: inherit; font-weight: 600; cursor: pointer; }
.btn.primary { background: var(--green); border-color: var(--green); color: #05230f; }
.btn.danger { color: var(--red); }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 10px; font-size: 13px; font-weight: 500; }
.btn:disabled { opacity: .5; }
.actions { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }

/* À vérifier */
.rv-head { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; }
.rv-amount { font-size: 18px; font-weight: 700; }
.rv-detail { color: var(--muted); font-size: 13px; word-break: break-word; }
.suggest { margin-top: 10px; padding: 10px; border-radius: 10px; background: rgba(34,197,94,.1); color: var(--green); font-size: 13.5px; }

.empty { text-align: center; color: var(--muted); padding: 30px 10px; }
.drop { border: 2px dashed var(--line); border-radius: var(--radius); padding: 28px 16px; text-align: center; cursor: pointer; }
.drop.over { border-color: var(--green); }

dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 18px; padding: 18px; width: min(520px, calc(100vw - 24px)); max-height: 90vh; }
dialog::backdrop { background: rgba(0,0,0,.6); }
.toast { position: fixed; left: 50%; bottom: calc(86px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-weight: 600; z-index: 50; max-width: calc(100vw - 32px); }
table.rules { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.rules td { padding: 7px 4px; border-top: 1px solid var(--line); vertical-align: middle; }

/* Charges fixes */
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.card-head h2 { margin: 0; }
.tag.ok { background: rgba(34,197,94,.13); color: var(--green); }
.total-row { display: flex; justify-content: space-between; padding-top: 10px; border-top: 1px solid var(--line); margin-top: 4px; }
.sugg-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 6px 0; font-size: 14px; }
.after { display: flex; justify-content: space-between; gap: 10px; margin-top: 12px; padding: 10px 12px; border-radius: 10px; background: var(--panel2); font-size: 14px; }
.negr { color: var(--red); }

/* Historique */
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; background: transparent; }
.chart-wrap { position: relative; }
.chart { width: 100%; height: auto; display: block; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { stroke: #4a5160; stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 11px; }
.chart .hit { fill: transparent; cursor: pointer; }
.chart .grp:hover .hit { fill: rgba(255,255,255,.04); }
.tip { position: absolute; top: 4px; width: 180px; background: #0b0d11; border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; font-size: 12.5px; pointer-events: none; box-shadow: 0 6px 20px rgba(0,0,0,.4); }
.tip-row { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 4px; margin-top: 3px; color: var(--muted); }
.tip-row .num { color: var(--text); }
.scroll-x { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl th { text-align: right; color: var(--muted); font-weight: 500; padding: 6px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl th:first-child, .tbl td:first-child { text-align: left; }
.tbl td { text-align: right; padding: 7px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl td.up { color: var(--amber); }
.tbl td.down { color: var(--green); }
@media (max-width: 640px) { .tabs button { font-size: 11.5px; padding: 8px 2px; } }
