/* Jetons de couleur : palette de référence validée (daltonisme, contraste),
   clair et sombre définis séparément. */
:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f3f2ee;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #6f6d68;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --border-strong: rgba(11, 11, 11, 0.18);
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --accent-soft: #e6f0fc;
  --danger: #c23434;
  --good-ink: #006300;
  --warn-ink: #8a5a00;
  --series-1: #2a78d6; --series-2: #eb6834; --series-3: #1baf7a; --series-4: #eda100;
  --series-5: #e87ba4; --series-6: #008300; --series-7: #6250d6; --series-8: #e34948;
  --seq-1: #cde2fb; --seq-2: #9ec5f4; --seq-3: #6da7ec; --seq-4: #3987e5;
  --seq-5: #256abf; --seq-6: #184f95; --seq-7: #0d366b;
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #232321;
    --text-primary: #f0efec;
    --text-secondary: #c3c2b7;
    --text-muted: #9a988f;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --border-strong: rgba(255, 255, 255, 0.18);
    --accent: #3987e5;
    --accent-ink: #ffffff;
    --accent-soft: #16263a;
    --danger: #e66767;
    --good-ink: #0ca30c;
    --warn-ink: #fab219;
    --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500;
    --series-5: #d55181; --series-6: #008300; --series-7: #9085e9; --series-8: #e66767;
    --seq-1: #0d366b; --seq-2: #104281; --seq-3: #1c5cab; --seq-4: #2a78d6;
    --seq-5: #5598e7; --seq-6: #86b6ef; --seq-7: #b7d3f6;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--text-primary);
  font: 15px/1.5 var(--font);
}
a { color: var(--accent); }
h1 { font-size: 1.35rem; margin: 0; font-weight: 650; letter-spacing: -0.01em; }
h2 { font-size: 1rem; margin: 0; font-weight: 600; }
.muted { color: var(--text-muted); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.nowrap { white-space: nowrap; }

/* -- barre du haut ---------------------------------------------------- */
.topbar {
  display: flex; align-items: center; gap: 24px;
  padding: 10px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
.brand { font-weight: 700; color: var(--text-primary); text-decoration: none; font-size: 1.05rem; }
.brand span, .login-card h1 span { color: var(--accent); }
.topbar nav { display: flex; gap: 4px; flex: 1; }
.topbar nav a {
  color: var(--text-secondary); text-decoration: none;
  padding: 6px 12px; border-radius: 8px;
}
.topbar nav a:hover { background: var(--surface-2); }
.topbar nav a[aria-current="page"] { color: var(--text-primary); background: var(--surface-2); font-weight: 600; }
.logout { display: flex; align-items: center; gap: 10px; margin: 0; }
.who { color: var(--text-muted); font-size: 0.9rem; }

.page { max-width: 1400px; margin: 0 auto; padding: 24px; }

/* -- boutons et champs ------------------------------------------------ */
.btn {
  font: inherit; font-size: 0.9rem; font-weight: 550;
  border-radius: 8px; border: 1px solid transparent;
  padding: 7px 14px; cursor: pointer; line-height: 1.2;
  background: transparent; color: var(--text-primary);
}
.btn:disabled { opacity: 0.4; cursor: default; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn-ghost { border-color: var(--border-strong); background: var(--surface); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); }
.btn-danger { color: var(--danger); }
.btn-icon { border-color: var(--border-strong); background: var(--surface); padding: 7px 10px; }
.btn:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

input, select {
  font: inherit; color: var(--text-primary);
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: 8px; padding: 7px 10px; width: 100%;
}
label { font-size: 0.85rem; font-weight: 600; color: var(--text-secondary); display: block; margin: 12px 0 4px; }

.alert { padding: 10px 14px; border-radius: 8px; margin: 12px 0; font-size: 0.92rem; }
.alert-error { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }
.alert-ok { background: color-mix(in srgb, var(--good-ink) 12%, transparent); color: var(--good-ink); }

/* -- connexion -------------------------------------------------------- */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: min(380px, 100%); background: var(--surface);
  border: 1px solid var(--border); border-radius: 14px; padding: 28px;
}
.login-card .btn { width: 100%; margin-top: 20px; padding: 10px; }
.login-card p { margin: 6px 0 8px; }

/* -- état de la collecte ---------------------------------------------- */
.status {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 12px; margin-bottom: 28px;
}
.stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px;
  display: flex; flex-direction: column; gap: 2px;
}
.stat-label { font-size: 0.82rem; color: var(--text-secondary); }
.stat-value { font-size: 1.6rem; font-weight: 650; }
.stat-value-sm { font-size: 1.05rem; font-weight: 600; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.stat-note { font-size: 0.8rem; color: var(--text-muted); }
.stat-note-error { color: var(--danger); }

.badge {
  display: inline-block; font-size: 0.75rem; font-weight: 650;
  padding: 2px 8px; border-radius: 999px;
  background: var(--surface-2); color: var(--text-secondary);
}
.badge-ok, .badge-collected { color: var(--good-ink); background: color-mix(in srgb, var(--good-ink) 12%, transparent); }
.badge-error, .badge-failed, .badge-unavailable { color: var(--danger); background: color-mix(in srgb, var(--danger) 12%, transparent); }
.badge-pending, .badge-running { color: var(--warn-ink); background: color-mix(in srgb, var(--warn-ink) 12%, transparent); }

/* -- diagrammes ------------------------------------------------------- */
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 14px; flex-wrap: wrap; }
.lead { color: var(--text-secondary); max-width: 70ch; margin-top: 0; }
.empty { color: var(--text-muted); padding: 40px; text-align: center; border: 1px dashed var(--border-strong); border-radius: var(--radius); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(560px, 100%), 1fr)); gap: 16px; }
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 18px 12px; min-width: 0;
}
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.card-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.card-actions .btn { padding: 4px 9px; font-size: 0.8rem; }
.explain { font-size: 0.8rem; color: var(--text-muted); margin: 4px 0 10px; min-height: 1.2em; }
.chart-box { width: 100%; min-height: 120px; }
.chart-box .vega-embed { width: 100%; display: block; }
.chart-box .vega-embed svg { max-width: 100%; }
.chart-empty, .chart-loading { color: var(--text-muted); font-size: 0.9rem; padding: 32px 0; text-align: center; margin: 0; }

/* -- éditeur ---------------------------------------------------------- */
dialog {
  width: min(1100px, calc(100vw - 32px)); max-height: calc(100vh - 32px);
  padding: 0; border: 1px solid var(--border); border-radius: 14px;
  background: var(--surface); color: var(--text-primary);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
.editor { display: flex; flex-direction: column; max-height: calc(100vh - 34px); margin: 0; }
.editor-head, .editor-foot { display: flex; justify-content: space-between; align-items: center; padding: 14px 20px; }
.editor-head { border-bottom: 1px solid var(--border); }
.editor-foot { border-top: 1px solid var(--border); justify-content: flex-end; gap: 8px; }
.editor-body { display: grid; grid-template-columns: 300px 1fr; gap: 24px; padding: 8px 20px 16px; overflow: auto; }
.editor-fields label:first-child { margin-top: 8px; }
.editor-preview { min-width: 0; }
.preview-label { font-size: 0.85rem; font-weight: 600; color: var(--text-secondary); margin: 20px 0 0; }
.hint { font-size: 0.78rem; color: var(--text-muted); margin: 4px 0 0; min-height: 1em; }
@media (max-width: 820px) {
  .editor-body { grid-template-columns: 1fr; }
  .topbar { flex-wrap: wrap; gap: 8px 16px; }
}

/* -- tableaux --------------------------------------------------------- */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.table { width: 100%; border-collapse: collapse; background: var(--surface); }
.table th, .table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--grid); vertical-align: top; }
.table th { font-size: 0.8rem; color: var(--text-secondary); font-weight: 600; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table-compact td { font-size: 0.88rem; }
.title-cell { max-width: 420px; }
.title-cell details { font-size: 0.8rem; color: var(--text-muted); }
.title-cell details p { white-space: pre-wrap; margin: 4px 0; color: var(--text-secondary); }
.table-form td { vertical-align: middle; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.row-actions form { margin: 0; }
tfoot td { border-bottom: none; }

/* -- chaînes ---------------------------------------------------------- */
.channel-cell { display: grid; gap: 3px; justify-items: start; min-width: 220px; }
.channel-name { font-weight: 600; }
.channel-id, code { font: 0.8rem/1.3 ui-monospace, "SFMono-Regular", Menlo, monospace; color: var(--text-secondary); }
.field-note { display: block; font-size: 0.78rem; color: var(--text-muted); margin-top: 3px; }
.check { width: 18px; height: 18px; accent-color: var(--accent); }
.help {
  margin-top: 24px; padding: 16px 20px; max-width: 80ch;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text-secondary); font-size: 0.92rem;
}
.help h2 { color: var(--text-primary); margin-bottom: 6px; }
.help ul { padding-left: 20px; }

/* -- infobulle Vega (style local : aucune balise <style> injectée) ---- */
#vg-tooltip-element {
  visibility: hidden; padding: 8px 10px; position: fixed; z-index: 1000;
  font: 12px/1.4 var(--font); border-radius: 8px;
  background: var(--surface); color: var(--text-primary);
  border: 1px solid var(--border-strong); box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
  max-width: 360px; pointer-events: none;
}
#vg-tooltip-element.visible { visibility: visible; }
#vg-tooltip-element h2 { margin: 0 0 6px; font-size: 13px; }
#vg-tooltip-element table { border-spacing: 0; }
#vg-tooltip-element td { padding: 1px 0; overflow: hidden; text-overflow: ellipsis; vertical-align: top; }
#vg-tooltip-element td.key { color: var(--text-secondary); max-width: 150px; text-align: right; padding-right: 8px; }
#vg-tooltip-element td.value { display: block; max-width: 240px; max-height: 6em; text-align: left; font-variant-numeric: tabular-nums; }
