:root {
  --bg: #f4f5f2; --surface: #ffffff; --surface-2: #f8f9f6; --line: #e2e4dd; --line-strong: #cdd1c6;
  --ink: #1b211f; --ink-2: #4a524e; --ink-3: #7a827d;
  --brand: #0f5e57; --brand-ink: #ffffff; --brand-soft: #e3f0ec;
  --ok: #1f7a4a; --ok-soft: #e2f3e8; --wait: #8a5a00; --wait-soft: #fbf0d9; --bad: #b2362b; --bad-soft: #fbe5e1;
  --info: #2a5a9c; --info-soft: #e4ecf8; --mute: #646c67; --mute-soft: #eceee9; --violet: #6b3fa0; --violet-soft: #efe7f8;
  --radius: 10px; --shadow: 0 1px 2px rgba(20,30,25,.05), 0 2px 8px rgba(20,30,25,.04);
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121615; --surface: #1a1f1d; --surface-2: #1f2523; --line: #2c3431; --line-strong: #3b4541;
    --ink: #e8ece9; --ink-2: #b4bcb7; --ink-3: #848d88;
    --brand: #4fb3a5; --brand-ink: #0b1d1a; --brand-soft: #18322d;
    --ok: #63c48c; --ok-soft: #173326; --wait: #e0b25a; --wait-soft: #33290f; --bad: #f08476; --bad-soft: #3a1d19;
    --info: #86aee6; --info-soft: #1a2638; --mute: #a2aaa5; --mute-soft: #262d2a; --violet: #c0a1e6; --violet-soft: #2b2238;
    --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.45 var(--font); -webkit-font-smoothing: antialiased; }
a { color: var(--brand); }
button, input, select, textarea { font: inherit; color: inherit; }
.num, td.num, .mono { font-variant-numeric: tabular-nums; }
.mono { font-family: var(--mono); font-size: 12.5px; }

/* Layout */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side { background: var(--surface); border-right: 1px solid var(--line); padding: 18px 12px; display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; background: var(--brand); display: grid; place-items: center; }
.brand-mark svg { width: 18px; height: 18px; }
.brand b { display: block; font-size: 14.5px; letter-spacing: -.01em; }
.brand small { color: var(--ink-3); font-size: 12px; }
.nav a { display: flex; align-items: center; justify-content: space-between; padding: 8px 10px; border-radius: 8px; color: var(--ink-2); text-decoration: none; font-weight: 500; }
.nav a:hover { background: var(--surface-2); color: var(--ink); }
.nav a.on { background: var(--brand-soft); color: var(--brand); }
.nav .count { background: var(--bad); color: #fff; border-radius: 999px; font-size: 11px; padding: 1px 7px; font-weight: 600; }
.side-foot { margin-top: auto; border-top: 1px solid var(--line); padding: 12px 8px 0; font-size: 12.5px; color: var(--ink-3); }
.side-foot b { color: var(--ink); font-weight: 600; display: block; overflow: hidden; text-overflow: ellipsis; }
.side-foot .links { display: flex; gap: 12px; margin-top: 8px; }
.side-foot button { background: none; border: 0; padding: 0; color: var(--brand); cursor: pointer; font-size: 12.5px; }
.main { padding: 26px 32px 60px; min-width: 0; max-width: 1400px; }
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.head h1 { margin: 0; font-size: 22px; letter-spacing: -.02em; font-weight: 650; }
.head p { margin: 4px 0 0; color: var(--ink-3); }
.mobile-bar { display: none; }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-h { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.card-h h2 { margin: 0; font-size: 14.5px; font-weight: 600; }
.card-b { padding: 16px; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: 1fr 1fr; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.muted { color: var(--ink-3); }
.small { font-size: 12.5px; }

/* KPIs */
.kpis { display: grid; grid-template-columns: 1.4fr repeat(5, 1fr); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); position: relative; overflow: hidden; }
.kpi .l { color: var(--ink-3); font-size: 12.5px; font-weight: 500; }
.kpi .v { font-size: 26px; font-weight: 650; letter-spacing: -.02em; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .s { color: var(--ink-3); font-size: 12px; margin-top: 2px; }
.kpi.hero { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.kpi.hero .l, .kpi.hero .s { color: inherit; opacity: .82; }
.kpi.hero .v { font-size: 34px; }
.kpi .dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 6px; vertical-align: 1px; }

/* Chart */
.bars { display: flex; align-items: flex-end; gap: 3px; height: 140px; padding-top: 8px; }
.bars .b { flex: 1; min-width: 4px; background: var(--brand); border-radius: 3px 3px 0 0; position: relative; opacity: .9; }
.bars .b:hover { opacity: 1; }
.bars .b:hover::after { content: attr(data-t); position: absolute; bottom: calc(100% + 6px); left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--surface); font-size: 11.5px; padding: 3px 7px; border-radius: 5px; white-space: nowrap; z-index: 2; }
.bars-x { display: flex; justify-content: space-between; color: var(--ink-3); font-size: 11.5px; margin-top: 6px; }
.states { display: flex; flex-direction: column; gap: 8px; }
.states .st { display: grid; grid-template-columns: 170px 1fr 44px; gap: 10px; align-items: center; font-size: 13px; }
.states .track { height: 8px; background: var(--mute-soft); border-radius: 99px; overflow: hidden; }
.states .fill { height: 100%; border-radius: 99px; }

/* Tables */
.tbl-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; white-space: nowrap; }
th { font-size: 12px; font-weight: 600; color: var(--ink-3); background: var(--surface-2); position: sticky; top: 0; }
td.num, th.num { text-align: right; }
tbody tr:hover { background: var(--surface-2); }
tr.click { cursor: pointer; }
tr.dim td { color: var(--ink-3); }
tr.total td { font-weight: 650; background: var(--surface-2); }
.empty { padding: 36px 16px; text-align: center; color: var(--ink-3); }
.pager { display: flex; align-items: center; justify-content: space-between; padding: 10px 16px; color: var(--ink-3); font-size: 12.5px; }

/* Badges */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 550; white-space: nowrap; }
.b-actif { background: var(--ok-soft); color: var(--ok); }
.b-signe { background: var(--info-soft); color: var(--info); }
.b-annule { background: var(--bad-soft); color: var(--bad); }
.b-en_cours { background: var(--wait-soft); color: var(--wait); }
.b-doublon, .b-doublon_fichier { background: var(--violet-soft); color: var(--violet); }
.b-autre_compte { background: var(--bad-soft); color: var(--bad); }
.b-introuvable, .b-invalide, .b-mute { background: var(--mute-soft); color: var(--mute); }
.b-brand { background: var(--brand-soft); color: var(--brand); }

/* Forms */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line-strong); background: var(--surface); padding: 7px 13px; border-radius: 8px; cursor: pointer; font-weight: 550; text-decoration: none; color: var(--ink); white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 4px 9px; font-size: 12.5px; }
.btn:disabled { opacity: .55; cursor: default; }
input[type=text], input[type=email], input[type=password], input[type=search], input[type=date], select, textarea {
  border: 1px solid var(--line-strong); background: var(--surface); border-radius: 8px; padding: 7px 10px; min-width: 0; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
textarea { width: 100%; min-height: 110px; font-family: var(--mono); font-size: 13px; resize: vertical; }
label.f { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; color: var(--ink-2); font-weight: 500; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.filters input[type=search] { width: 240px; }
.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: 6px 11px; cursor: pointer; font-size: 12.5px; color: var(--ink-2); }
.seg button + button { border-left: 1px solid var(--line-strong); }
.seg button.on { background: var(--brand-soft); color: var(--brand); font-weight: 600; }

.drop { border: 1.5px dashed var(--line-strong); border-radius: var(--radius); padding: 28px 16px; text-align: center; background: var(--surface-2); cursor: pointer; transition: border-color .15s, background .15s; }
.drop:hover, .drop.over { border-color: var(--brand); background: var(--brand-soft); }
.drop b { display: block; font-size: 15px; margin-bottom: 4px; }
.drop input { display: none; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 5px 12px 5px 10px; cursor: pointer; display: inline-flex; gap: 8px; align-items: center; font-size: 13px; }
.chip b { font-variant-numeric: tabular-nums; }
.chip.on { border-color: var(--brand); box-shadow: 0 0 0 1px var(--brand) inset; }

.note { border-radius: 8px; padding: 10px 12px; background: var(--info-soft); color: var(--info); font-size: 13px; }
.note.warn { background: var(--wait-soft); color: var(--wait); }
.note.ok { background: var(--ok-soft); color: var(--ok); }
.secret { font-family: var(--mono); background: var(--surface-2); border: 1px solid var(--line); padding: 8px 10px; border-radius: 8px; user-select: all; font-size: 14px; }

/* Drawer */
.overlay { position: fixed; inset: 0; background: rgba(10,15,13,.35); z-index: 20; display: flex; justify-content: flex-end; }
.drawer { width: min(560px, 100%); background: var(--surface); height: 100%; overflow-y: auto; box-shadow: -10px 0 30px rgba(0,0,0,.12); }
.drawer .card-h { position: sticky; top: 0; background: var(--surface); z-index: 1; }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 6px 12px; font-size: 13px; }
.kv dt { color: var(--ink-3); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 6px 0 6px 18px; border-left: 2px solid var(--line); position: relative; font-size: 13px; }
.timeline li::before { content: ""; position: absolute; left: -5px; top: 11px; width: 8px; height: 8px; border-radius: 50%; background: var(--brand); }
h3 { font-size: 13px; margin: 20px 0 8px; color: var(--ink-2); text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }

/* Modal */
.modal-bg { position: fixed; inset: 0; background: rgba(10,15,13,.4); z-index: 30; display: grid; place-items: center; padding: 16px; }
.modal { background: var(--surface); border-radius: 12px; width: min(440px, 100%); padding: 22px; box-shadow: 0 20px 60px rgba(0,0,0,.2); }
.modal h2 { margin: 0 0 12px; font-size: 17px; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: min(380px, 100%); padding: 28px; }
.login h1 { font-size: 20px; margin: 14px 0 4px; letter-spacing: -.02em; }
.login form { display: flex; flex-direction: column; gap: 12px; margin-top: 18px; }
.err { color: var(--bad); font-size: 13px; min-height: 18px; }

#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--ink); color: var(--surface); padding: 10px 16px; border-radius: 8px; opacity: 0; transition: all .2s; pointer-events: none; z-index: 50; font-size: 13.5px; max-width: 90vw; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.bad { background: var(--bad); color: #fff; }

@media (max-width: 1100px) { .kpis { grid-template-columns: repeat(3, 1fr); } .g2 { grid-template-columns: 1fr; } }
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; z-index: 25; left: 0; top: 0; width: 250px; transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; box-shadow: 10px 0 30px rgba(0,0,0,.15); }
  .mobile-bar { display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
  .mobile-bar button { border: 1px solid var(--line-strong); background: var(--surface); border-radius: 8px; padding: 5px 10px; }
  .main { padding: 18px 16px 50px; }
  .kpis { grid-template-columns: 1fr 1fr; }
  .kpi.hero { grid-column: 1 / -1; }
  .filters input[type=search] { width: 100%; }
  .states .st { grid-template-columns: 120px 1fr 36px; }
  .kv { grid-template-columns: 1fr; }
}
