:root {
  color-scheme: light;
  --bg: #f4f4f2;
  --surface: #fcfcfb;
  --surface-2: #efeeeb;
  --border: #e2e1dc;
  --text: #0b0b0b;
  --text-2: #52514e;
  --text-3: #7a7974;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --accent-soft: #e6f0fc;
  --series-1: #2a78d6;
  --grid: #e6e5e0;
  --good: #0a7a3e;   --good-soft: #e3f4ea;
  --warn: #9a5b00;   --warn-soft: #fbf0d9;
  --bad: #b42323;    --bad-soft: #fbe5e5;
  --neutral-soft: #ecebe7;
  --shadow: 0 1px 2px rgb(0 0 0 / .05), 0 8px 24px rgb(0 0 0 / .06);
  --radius: 10px;
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211; --surface: #1a1a19; --surface-2: #232321; --border: #2f2f2c;
    --text: #f0efec; --text-2: #c3c2b7; --text-3: #8f8e86;
    --accent: #3987e5; --accent-soft: #1b2a3d; --series-1: #3987e5; --grid: #2a2a28;
    --good: #5fcf8e; --good-soft: #15291e; --warn: #e8b453; --warn-soft: #2c2412;
    --bad: #f08080; --bad-soft: #301818; --neutral-soft: #2a2a28;
    --shadow: 0 1px 2px rgb(0 0 0 / .4), 0 8px 24px rgb(0 0 0 / .35);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211; --surface: #1a1a19; --surface-2: #232321; --border: #2f2f2c;
  --text: #f0efec; --text-2: #c3c2b7; --text-3: #8f8e86;
  --accent: #3987e5; --accent-soft: #1b2a3d; --series-1: #3987e5; --grid: #2a2a28;
  --good: #5fcf8e; --good-soft: #15291e; --warn: #e8b453; --warn-soft: #2c2412;
  --bad: #f08080; --bad-soft: #301818; --neutral-soft: #2a2a28;
  --shadow: 0 1px 2px rgb(0 0 0 / .4), 0 8px 24px rgb(0 0 0 / .35);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.45; -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
.tabnum { font-variant-numeric: tabular-nums; }
.muted { color: var(--text-3); }
.small { font-size: 12px; }
[hidden] { display: none !important; }

/* ---------- Layout ---------- */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.sidebar { background: var(--surface); border-right: 1px solid var(--border); 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 10px 18px; font-weight: 650; letter-spacing: -.01em; }
.brand-mark { width: 28px; height: 28px; border-radius: 8px; background: var(--accent); display: grid; place-items: center; color: #fff; }
.brand small { display: block; font-weight: 400; color: var(--text-3); font-size: 12px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--text-2); font-weight: 500; }
.nav a:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.nav svg { width: 18px; height: 18px; flex: none; }
.nav .count { margin-left: auto; background: var(--accent); color: var(--accent-ink); border-radius: 999px; font-size: 11px; padding: 1px 7px; font-weight: 600; }
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 4px; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 14px 28px; border-bottom: 1px solid var(--border); background: var(--surface); position: sticky; top: 0; z-index: 5; }
.topbar h1 { font-size: 18px; margin: 0; letter-spacing: -.01em; }
.topbar .spacer { flex: 1; }
.topbar .menu-btn { display: none; }
.content { padding: 24px 28px 48px; max-width: 1400px; width: 100%; }

/* ---------- Controls ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); background: var(--surface); padding: 7px 12px; border-radius: 8px; cursor: pointer; font-weight: 500; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--bad); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn svg { width: 16px; height: 16px; }
.btn:disabled { opacity: .55; cursor: default; }
.input, .select, textarea.input { border: 1px solid var(--border); background: var(--surface); border-radius: 8px; padding: 7px 10px; min-width: 0; }
.input:focus, .select:focus, .btn:focus-visible, .nav a:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
textarea.input { width: 100%; resize: vertical; min-height: 90px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 12px; color: var(--text-2); font-weight: 500; }
.field .input, .field .select { width: 100%; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.form-grid .full { grid-column: 1 / -1; }

/* ---------- Cards & KPI ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.card h2 { font-size: 14px; margin: 0 0 14px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.card h2 .link { margin-left: auto; font-weight: 500; font-size: 13px; }
.kpis { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; display: block; color: inherit; }
a.kpi:hover { text-decoration: none; border-color: var(--accent); }
.kpi .label { color: var(--text-2); font-size: 12.5px; font-weight: 500; }
.kpi .value { font-size: 28px; font-weight: 650; letter-spacing: -.02em; margin-top: 4px; }
.kpi .sub { color: var(--text-3); font-size: 12px; }
.grid-2 { display: grid; grid-template-columns: 3fr 2fr; gap: 18px; margin-bottom: 18px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; }

/* ---------- Charts ---------- */
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .axis-label { fill: var(--text-3); font-size: 11px; }
.chart .bar { fill: var(--series-1); }
.chart .hit { fill: transparent; cursor: default; }
.chart .hit:hover + .bar, .chart .bar.hover { opacity: .8; }
.tooltip { position: absolute; pointer-events: none; background: var(--text); color: var(--surface); padding: 6px 9px; border-radius: 6px; font-size: 12px; white-space: nowrap; transform: translate(-50%, -100%); margin-top: -8px; box-shadow: var(--shadow); }
.funnel { display: flex; flex-direction: column; gap: 9px; }
.funnel-row { display: grid; grid-template-columns: 150px 1fr 34px; gap: 10px; align-items: center; color: inherit; }
a.funnel-row:hover { text-decoration: none; }
a.funnel-row:hover .funnel-label { color: var(--accent); }
.funnel-label { color: var(--text-2); font-size: 13px; }
.funnel-track { display: block; height: 12px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.funnel-fill { display: block; height: 100%; background: var(--series-1); border-radius: 4px; min-width: 2px; }
.funnel-val { text-align: right; font-weight: 600; font-size: 13px; }

/* ---------- Lists ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-top: 1px solid var(--border); cursor: pointer; }
.list li:first-child { border-top: 0; padding-top: 0; }
.list .grow { min-width: 0; flex: 1; }
.list .title { font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list .meta { color: var(--text-3); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list li:hover .title { color: var(--accent); }
.empty { color: var(--text-3); padding: 8px 0; font-size: 13px; }

/* ---------- Badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 550; background: var(--neutral-soft); color: var(--text-2); white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.s-examiner, .badge.s-envoyer { background: var(--accent-soft); color: var(--accent); }
.badge.s-envoyee, .badge.s-relancer { background: var(--warn-soft); color: var(--warn); }
.badge.s-entretien, .badge.s-offre { background: var(--good-soft); color: var(--good); }
.badge.s-refus { background: var(--bad-soft); color: var(--bad); }
.score { display: inline-flex; gap: 2px; }
.score i { width: 7px; height: 7px; border-radius: 2px; background: var(--surface-2); border: 1px solid var(--border); }
.score i.on { background: var(--series-1); border-color: var(--series-1); }
.chip-src { font-size: 11px; color: var(--text-3); border: 1px solid var(--border); padding: 0 6px; border-radius: 5px; }

/* ---------- Table ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 14px; }
.toolbar .search { flex: 1 1 220px; max-width: 360px; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 12px; }
.tab { border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: 4px 11px; cursor: pointer; font-size: 13px; color: var(--text-2); }
.tab:hover { background: var(--surface-2); }
.tab.active { background: var(--text); color: var(--surface); border-color: var(--text); }
.tab .n { opacity: .7; margin-left: 4px; font-variant-numeric: tabular-nums; }
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12px; color: var(--text-3); font-weight: 600; background: var(--surface); position: sticky; top: 0; white-space: nowrap; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: 0; }
td .poste { font-weight: 550; }
td .ent { color: var(--text-2); font-size: 12.5px; }
td.nowrap { white-space: nowrap; }
.status-select { border: 1px solid transparent; background: transparent; border-radius: 6px; padding: 3px 4px; cursor: pointer; max-width: 170px; }
.status-select:hover { border-color: var(--border); background: var(--surface); }
.row-flag { color: var(--warn); font-size: 12px; font-weight: 550; }

/* ---------- Drawer ---------- */
.overlay { position: fixed; inset: 0; background: rgb(0 0 0 / .32); z-index: 20; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(640px, 100%); background: var(--surface); z-index: 21; box-shadow: var(--shadow); display: flex; flex-direction: column; }
.drawer header { display: flex; align-items: center; gap: 10px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.drawer header h3 { margin: 0; font-size: 16px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.drawer .body { padding: 18px 20px; overflow-y: auto; flex: 1; }
.drawer footer { display: flex; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); }
.drawer footer .spacer { flex: 1; }
.section-title { font-size: 12px; font-weight: 600; color: var(--text-3); text-transform: uppercase; letter-spacing: .04em; margin: 22px 0 10px; }
.timeline { list-style: none; padding: 0; margin: 0; font-size: 13px; }
.timeline li { display: flex; gap: 10px; padding: 5px 0; color: var(--text-2); }
.timeline time { color: var(--text-3); width: 120px; flex: none; }
.desc { white-space: pre-wrap; background: var(--surface-2); border-radius: 8px; padding: 12px; font-size: 13px; color: var(--text-2); max-height: 260px; overflow: auto; }

/* ---------- API page ---------- */
pre.code { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; overflow-x: auto; font-size: 12.5px; line-height: 1.55; margin: 0; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .92em; }
.kv { display: grid; grid-template-columns: 180px 1fr; gap: 8px 16px; font-size: 13px; }
.kv dt { color: var(--text-3); }
.kv dd { margin: 0; }
.token-box { display: flex; gap: 8px; align-items: center; background: var(--warn-soft); border: 1px solid var(--warn); border-radius: 8px; padding: 10px 12px; margin-top: 12px; }
.token-box code { flex: 1; word-break: break-all; }
.stack { display: flex; flex-direction: column; gap: 18px; }
table.fields td, table.fields th { padding: 7px 10px; font-size: 13px; }
table.fields tbody tr { cursor: default; }
table.fields tbody tr:hover { background: none; }

/* ---------- Login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login form { width: min(360px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 28px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 14px; }
.login h1 { font-size: 18px; margin: 0; }
.error { color: var(--bad); font-size: 13px; min-height: 18px; }

#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--surface); padding: 9px 16px; border-radius: 8px; font-size: 13px; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 50; }
#toast.show { opacity: 1; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; z-index: 30; width: 240px; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow); }
  .shell.nav-open .sidebar { transform: none; }
  .topbar .menu-btn { display: inline-flex; }
  .topbar { padding: 12px 16px; }
  .content { padding: 16px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-grid { grid-template-columns: 1fr; }
  .funnel-row { grid-template-columns: 110px 1fr 28px; }
  .kv { grid-template-columns: 1fr; gap: 2px 0; }
  .kv dd { margin-bottom: 8px; }
  .hide-sm { display: none; }
}
