:root {
  --bg: #f5f4f0;
  --panel: #ffffff;
  --ink: #01133b;
  --ink-2: #3d4863;
  --muted: #7a8196;
  --line: #e4e2dc;
  --line-2: #efede8;
  --accent: #c8552b;
  --accent-soft: #fbe9e1;
  --ok: #1f7a4d;
  --ok-soft: #e2f3ea;
  --warn: #a86400;
  --warn-soft: #fdf0d9;
  --bad: #b3261e;
  --bad-soft: #fbe3e1;
  --info: #2d5bb9;
  --info-soft: #e5ecfa;
  --s1: #14213d; --s2: #2d5bb9; --s3: #c8552b; --s4: #1f7a4d; --s5: #8a5cc2;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20,33,61,.06), 0 4px 16px rgba(20,33,61,.05);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Inter, Roboto, sans-serif;
  color: var(--ink);
  font-size: 14px;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
[hidden] { display: none !important; }
a { color: var(--info); }
button { font: inherit; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }

/* ---------- layout */
.app { display: grid; grid-template-columns: 216px minmax(0, 1fr); min-height: 100vh; }
.side { background: var(--ink); color: #dfe3ee; display: flex; flex-direction: column; padding: 18px 12px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; flex-direction: column; align-items: stretch; gap: 6px; padding: 0 4px 20px; }
.brand img { background: #fff; border-radius: 10px; padding: 10px 18px; width: 100%; height: auto; }
.brand > span { text-align: center; font-size: 11px; letter-spacing: .18em; text-transform: uppercase; color: #9fb2d3; }
.brand b { display: block; color: #fff; letter-spacing: .04em; font-size: 13px; }
.brand span { font-size: 12px; color: #9aa4bd; }
nav a { display: flex; gap: 10px; align-items: center; padding: 9px 10px; border-radius: 8px; color: #c9cfdd; text-decoration: none; margin-bottom: 2px; }
nav a i { font-style: normal; width: 18px; text-align: center; opacity: .8; }
nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
nav a.on { background: rgba(159,178,211,.18); color: #fff; box-shadow: inset 3px 0 0 #9fb2d3; }
.side-foot { margin-top: auto; padding: 10px; font-size: 12px; color: #9aa4bd; }
.side-foot #who { color: #fff; margin-bottom: 4px; }
.side-foot .ver { margin-top: 6px; font-size: 10.5px; color: #6f7b99; }
.qs { padding: 0 2px 12px; }
.qs input { width: 100%; border: 1px solid rgba(255,255,255,.14); background: rgba(255,255,255,.07); color: #fff; border-radius: 8px; padding: 7px 10px; font-size: 12.5px; }
.qs input::placeholder { color: #8f9bb8; }
.qs input:focus { outline: 2px solid rgba(159,178,211,.5); background: rgba(255,255,255,.12); }
nav a { position: relative; }
nav .badge { margin-left: auto; background: var(--accent); color: #fff; border-radius: 999px; font-size: 10.5px; padding: 1px 7px; font-weight: 700; }
.link { background: none; border: 0; padding: 0; color: inherit; text-decoration: underline; }
main { padding: 22px 28px 60px; min-width: 0; }
h1 { font-size: 22px; margin: 0 0 4px; letter-spacing: -.01em; }
h2 { font-size: 15px; margin: 0; }
.sub { color: var(--muted); margin: 0 0 18px; }
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.head .sub { margin: 0; }

/* ---------- panels */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 16px; min-width: 0; }
.panel > header { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.panel > header p { margin: 2px 0 0; color: var(--muted); font-size: 12.5px; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g-21 { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
@media (max-width: 1100px) { .g2, .g3, .g-21 { grid-template-columns: 1fr; } }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi label { display: block; color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.kpi b { font-size: 22px; font-variant-numeric: tabular-nums; letter-spacing: -.01em; display: block; }
.kpi small { color: var(--muted); font-size: 12px; display: block; margin-top: 4px; }
.kpi.accent { border-top: 3px solid var(--accent); }
.kpi.alert b { color: var(--bad); }

.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.chip { background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 5px 11px; font-size: 12.5px; color: var(--ink-2); }
.chip.old { border-color: #f0c98a; background: var(--warn-soft); color: var(--warn); }

/* ---------- buttons & forms */
.btn { text-decoration: none; border: 1px solid var(--line); background: var(--panel); color: var(--ink); border-radius: 8px; padding: 7px 12px; font-size: 13px; display: inline-flex; gap: 6px; align-items: center; white-space: nowrap; }
.btn:hover { border-color: #c9c6bd; background: #fbfaf8; }
.btn.primary { background: var(--ink); color: #fff; border-color: var(--ink); }
.btn.primary:hover { background: #22325a; }
.btn.accent { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 4px 9px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btns { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.field label { font-size: 12px; color: var(--muted); }
.field input, .field select, .field textarea, .inp { border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; background: #fff; min-width: 0; }
.field input:focus, .field select:focus, .field textarea:focus, .inp:focus { outline: 2px solid #c7d4f0; border-color: var(--info); }
.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.hint { color: var(--muted); font-size: 12px; }
.check { display: flex; gap: 6px; align-items: center; font-size: 13px; }

/* ---------- pills */
.pill { display: inline-block; border-radius: 999px; padding: 2px 8px; font-size: 11.5px; font-weight: 600; white-space: nowrap; background: var(--line-2); color: var(--ink-2); }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.info { background: var(--info-soft); color: var(--info); }
.pill.acc { background: var(--accent-soft); color: var(--accent); }

/* ---------- tables */
.tbl-bar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.tbl-bar .grow { flex: 1; }
.tbl-bar input[type=search] { border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; min-width: 200px; }
.tbl-wrap { overflow: auto; max-height: 62vh; border: 1px solid var(--line-2); border-radius: 8px; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th { min-width: 0; position: sticky; top: 0; background: #faf9f6; text-align: left; font-weight: 600; color: var(--ink-2); font-size: 12px; padding: 8px 10px; border-bottom: 1px solid var(--line); cursor: pointer; white-space: nowrap; user-select: none; }
th.num { text-align: right; }
th .arr { color: var(--muted); font-size: 10px; }
td { padding: 7px 10px; border-bottom: 1px solid var(--line-2); vertical-align: top; }
tbody tr:hover { background: #fbfaf7; }
tr.click { cursor: pointer; }
tfoot td { font-weight: 600; background: #faf9f6; position: sticky; bottom: 0; border-top: 1px solid var(--line); }
.count { color: var(--muted); font-size: 12px; }
.empty { color: var(--muted); padding: 24px; text-align: center; }
td.more { text-align: center; background: #faf9f6; }

/* ---------- priorités (tableau de bord) */
.prio { border: 1px solid var(--line-2); border-radius: 8px; margin-bottom: 6px; background: #fcfbf9; }
.prio summary { cursor: pointer; padding: 9px 12px; font-size: 13.5px; list-style: none; display: flex; gap: 8px; align-items: center; }
.prio summary::before { content: "▸"; color: var(--muted); font-size: 11px; transition: transform .15s; }
.prio[open] summary::before { transform: rotate(90deg); }
.prio summary b { min-width: 28px; text-align: center; border-radius: 999px; padding: 1px 8px; font-variant-numeric: tabular-nums; background: var(--line-2); color: var(--ink-2); }
.prio.bad summary b { background: var(--bad-soft); color: var(--bad); } .prio.warn summary b { background: var(--warn-soft); color: var(--warn); } .prio.info summary b { background: var(--info-soft); color: var(--info); }
.prio summary .hint { margin-left: auto; }
.prio-body { padding: 2px 12px 8px; max-height: 320px; overflow: auto; }
.prio-item { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-top: 1px solid var(--line-2); font-size: 13px; flex-wrap: wrap; }
.prio-item a { color: var(--ink); text-decoration: none; } .prio-item a:hover { text-decoration: underline; }
.prio-item span { color: var(--ink-2); display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.prog { height: 7px; background: var(--line-2); border-radius: 4px; overflow: hidden; margin: 8px 0 4px; }
.prog div { height: 100%; border-radius: 4px; }
.timeline.act li { padding-bottom: 7px; }
.suivi-box { padding: 12px 14px; margin: 12px 0; background: #fbfaf6; }
.suivi-box h2 { margin-bottom: 8px; }
.hist summary { cursor: pointer; margin-top: 6px; }
.filtres .field { margin-bottom: 4px; }
.skel { color: var(--muted); }

/* ---------- extraction cards */
.scripts { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; margin-bottom: 16px; }
.script { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; gap: 8px; box-shadow: var(--shadow); }
.script h3 { margin: 0; font-size: 14.5px; }
.script p { margin: 0; color: var(--muted); font-size: 12.5px; line-height: 1.4; flex: 1; }
.script .last { font-size: 12px; color: var(--ink-2); }
.script .opts { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.script select, .script input[type=month] { border: 1px solid var(--line); border-radius: 7px; padding: 5px 7px; font-size: 12.5px; background: #fff; }
.console { background: #0f1830; color: #d6deef; font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; border-radius: 8px; padding: 12px 14px; height: 300px; overflow: auto; white-space: pre-wrap; word-break: break-word; }
.console .ok { color: #7ee2a8; } .console .bad { color: #ff9b91; } .console .dim { color: #7e8bab; } .console .hd { color: #fff; font-weight: 700; }
.runbar { background: var(--ink); color: #fff; border-radius: 10px; padding: 9px 14px; margin-bottom: 16px; display: flex; gap: 12px; align-items: center; }
.runbar a { color: #ffd0bc; }
.spin { width: 12px; height: 12px; border: 2px solid rgba(255,255,255,.35); border-top-color: #fff; border-radius: 50%; animation: sp 0.9s linear infinite; display: inline-block; }
.panel .spin, .script .spin { border-color: #d5d9e4; border-top-color: var(--ink); }
@keyframes sp { to { transform: rotate(360deg); } }

/* ---------- charts */
.chart { width: 100%; display: block; }
.chart text { font-size: 11px; fill: var(--muted); }
.chart .lbl { fill: var(--ink-2); font-size: 12px; }
.chart .val { fill: var(--ink); font-weight: 600; font-size: 11.5px; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--ink-2); margin-top: 6px; }
.legend span::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 3px; background: var(--c); margin-right: 5px; vertical-align: -1px; }
.funnel-row { display: grid; grid-template-columns: 150px 1fr 120px; gap: 10px; align-items: center; margin-bottom: 8px; font-size: 13px; }
.funnel-row .bar { height: 22px; background: var(--line-2); border-radius: 6px; overflow: hidden; }
.funnel-row .bar div { height: 100%; border-radius: 6px; }

/* ---------- modal / drawer */
.modal { position: fixed; inset: 0; background: rgba(15,24,48,.45); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; z-index: 50; overflow: auto; }
.modal-box { background: var(--panel); border-radius: 12px; width: min(680px, 100%); padding: 20px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal-box h2 { font-size: 17px; margin-bottom: 4px; }
.drawer { position: fixed; inset: 0; background: rgba(15,24,48,.35); z-index: 40; display: flex; justify-content: flex-end; }
.drawer-box { background: var(--panel); width: min(560px, 100%); height: 100%; overflow: auto; padding: 22px; box-shadow: -10px 0 40px rgba(0,0,0,.15); }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 6px 12px; font-size: 13px; margin: 12px 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }
.timeline { list-style: none; padding: 0; margin: 8px 0; border-left: 2px solid var(--line); }
.timeline li { padding: 0 0 10px 14px; position: relative; font-size: 13px; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: 4px; width: 10px; height: 10px; border-radius: 50%; background: var(--panel); border: 2px solid var(--info); }
.timeline small { color: var(--muted); display: block; }
.out { background: #f7f6f2; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; font-size: 13px; word-break: break-all; margin: 6px 0 10px; white-space: pre-wrap; }
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 80; max-width: 90vw; box-shadow: 0 10px 30px rgba(0,0,0,.25); font-size: 13.5px; }
.notice { background: var(--warn-soft); color: var(--warn); border: 1px solid #f0d29d; border-radius: 8px; padding: 9px 12px; margin-bottom: 14px; font-size: 13px; }
.notice.info { background: var(--info-soft); color: var(--info); border-color: #c9d7f3; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; }
.tabs button { background: none; border: 0; padding: 8px 12px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button.on { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }

/* ---------- auth */
.auth { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; background: radial-gradient(circle at 20% 10%, #1d3366, var(--ink)); }
.auth .logo { display: block; width: 170px; height: auto; margin: 0 auto 14px; }
.auth .card { background: #fff; border-radius: 14px; padding: 26px; width: min(440px, 100%); box-shadow: 0 30px 80px rgba(0,0,0,.35); }
.auth h1 { font-size: 19px; }

@media (max-width: 760px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  body { overflow-x: hidden; }
  .side { position: sticky; top: 0; z-index: 30; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 6px; padding: 10px 12px; }
  .brand { flex-direction: row; align-items: center; gap: 8px; padding: 0; }
  .brand img { width: 64px; padding: 4px 6px; } .brand > span { display: none; }
  .qs { flex: 1; padding: 0; min-width: 140px; }
  nav { display: flex; flex-wrap: nowrap; overflow-x: auto; width: 100%; gap: 2px; -webkit-overflow-scrolling: touch; }
  nav a { padding: 6px 9px; font-size: 13px; white-space: nowrap; }
  nav a i { display: none; }
  .side-foot { margin: 0; display: none; }
  main { padding: 14px 12px 40px; }
  h1 { font-size: 19px; }
  .kv { grid-template-columns: 1fr; }
  .funnel-row { grid-template-columns: 100px 1fr 90px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .kpi b { font-size: 19px; }
  .tbl-wrap { max-height: 70vh; }
  .drawer-box { width: 100%; padding: 16px; }
  .modal { padding: 10px; }
}
@media (max-width: 420px) { .kpis { grid-template-columns: 1fr; } }
@media print {
  .side, .runbar, .tbl-bar, .btn { display: none !important; }
  .app { display: block; }
  .tbl-wrap { max-height: none; overflow: visible; }
}
