/* Palette : instance de référence du skill dataviz (validée clair + sombre) */
.viz-root, body {
  color-scheme: light;
  --page: #f9f9f7;
  --surface-1: #fcfcfb;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
  --danger: #d03b3b;
  /* statuts = emplacements catégoriels 1 à 5, dans l'ordre fixe */
  --s-attente: #2a78d6;
  --s-entretien: #eb6834;
  --s-refus: #1baf7a;
  --s-accepte: #eda100;
  --s-abandon: #e87ba4;
  --series-1: #2a78d6;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) body,
  :root:where(:not([data-theme="light"])) .viz-root {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface-1: #1a1a19;
    --text-primary: #f0efec;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --grid: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --accent: #3987e5;
    --s-attente: #3987e5;
    --s-entretien: #d95926;
    --s-refus: #199e70;
    --s-accepte: #c98500;
    --s-abandon: #d55181;
    --series-1: #3987e5;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--page);
  color: var(--text-primary);
  -webkit-tap-highlight-color: transparent;
}
#app { min-height: 100vh; padding-bottom: calc(72px + env(safe-area-inset-bottom)); }
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--page); border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 18px; margin: 0; font-weight: 600; }
main { max-width: 760px; margin: 0 auto; padding: 16px; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr));
  background: var(--surface-1); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 0 10px; font-size: 11px; color: var(--text-muted); text-decoration: none;
}
.tabbar a span { font-size: 20px; filter: grayscale(1); opacity: .7; }
.tabbar a.active { color: var(--text-primary); font-weight: 600; }
.tabbar a.active span { filter: none; opacity: 1; }

.card {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 12px;
  padding: 16px; margin-bottom: 14px;
}
.card h2 { font-size: 15px; margin: 0 0 4px; font-weight: 600; }
.card .sub { font-size: 13px; color: var(--text-secondary); margin: 0 0 12px; }

/* Stat tiles */
.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 14px; }
@media (min-width: 640px) { .tiles { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.tile { background: var(--surface-1); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; }
.tile .label { font-size: 12px; color: var(--text-secondary); }
.tile .value { font-size: 26px; font-weight: 600; margin-top: 2px; }
.tile .hint { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* Segmented bar */
.segbar { display: flex; gap: 2px; height: 16px; }
.segbar .seg { height: 100%; min-width: 4px; cursor: pointer; }
.segbar .seg:first-child { border-radius: 4px 0 0 4px; }
.segbar .seg:last-child { border-radius: 0 4px 4px 0; }
.segbar .seg:only-child { border-radius: 4px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 12px; font-size: 13px; color: var(--text-secondary); }
.legend .item { display: inline-flex; align-items: center; gap: 6px; }
.legend b { color: var(--text-primary); font-weight: 600; }
.swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; flex: none; }

/* Chart */
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .baseline { stroke: var(--baseline); stroke-width: 1; }
.chart .tick { fill: var(--text-muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .vlabel { fill: var(--text-secondary); font-size: 11px; font-weight: 600; }
.chart .bar { fill: var(--series-1); }
.chart .bar.dim { opacity: .35; }
.chart .hit { fill: transparent; cursor: pointer; }
details.data { margin-top: 10px; font-size: 13px; color: var(--text-secondary); }
details.data table { width: 100%; border-collapse: collapse; margin-top: 6px; font-variant-numeric: tabular-nums; }
details.data td, details.data th { text-align: left; padding: 4px 0; border-bottom: 1px solid var(--grid); }

.tooltip {
  position: fixed; z-index: 20; pointer-events: none;
  background: var(--surface-1); color: var(--text-primary);
  border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px;
  font-size: 12px; box-shadow: 0 4px 16px rgba(0, 0, 0, .12); white-space: nowrap;
}
.tooltip .t-label { color: var(--text-secondary); }

/* Liste */
.filters { display: flex; gap: 8px; margin-bottom: 12px; overflow-x: auto; padding-bottom: 2px; }
.chip {
  flex: none; border: 1px solid var(--border); background: var(--surface-1); color: var(--text-secondary);
  border-radius: 999px; padding: 6px 12px; font-size: 13px; display: inline-flex; align-items: center; gap: 6px;
}
.chip.active { color: var(--text-primary); border-color: var(--text-primary); font-weight: 600; }
input, select, textarea {
  width: 100%; font: inherit; font-size: 16px; color: var(--text-primary);
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px;
}
textarea { min-height: 90px; resize: vertical; }
label.field { display: block; font-size: 13px; color: var(--text-secondary); margin-bottom: 12px; }
label.field > input, label.field > select, label.field > textarea { margin-top: 4px; }
.search { margin-bottom: 10px; }

.row {
  display: block; text-decoration: none; color: inherit;
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 12px;
  padding: 12px 14px; margin-bottom: 8px;
}
.row .top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.row .name { font-weight: 600; }
.row .date { font-size: 12px; color: var(--text-muted); white-space: nowrap; }
.row .poste { font-size: 13px; color: var(--text-secondary); margin-top: 2px; }
.row .resume { font-size: 13px; color: var(--text-secondary); margin-top: 6px; }
.status { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-secondary); margin-top: 6px; }

button {
  font: inherit; font-size: 15px; border-radius: 10px; padding: 10px 16px; cursor: pointer;
  border: 1px solid transparent; background: var(--accent); color: #fff; font-weight: 600;
}
button.ghost { background: transparent; color: var(--text-secondary); border-color: var(--border); font-weight: 400; padding: 6px 12px; font-size: 13px; }
button.danger { background: transparent; color: var(--danger); border-color: var(--danger); }
button:disabled { opacity: .5; }
.actions { display: flex; gap: 8px; justify-content: space-between; margin-top: 8px; }

.reponse { border-left: 2px solid var(--grid); padding: 2px 0 2px 12px; margin: 12px 0; }
.reponse .meta { font-size: 12px; color: var(--text-muted); }
.reponse p { margin: 6px 0; font-size: 14px; }
.reponse pre, .corps { white-space: pre-wrap; font: inherit; font-size: 13px; color: var(--text-secondary); margin: 6px 0 0; }
.when { font-weight: 600; font-size: 14px; }
.daygroup { font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; margin: 18px 0 8px; }
.empty { text-align: center; color: var(--text-muted); padding: 32px 0; }
.back { display: inline-block; margin-bottom: 12px; color: var(--text-secondary); text-decoration: none; font-size: 14px; }

.login { max-width: 360px; margin: 12vh auto 0; }
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(84px + env(safe-area-inset-bottom));
  background: var(--text-primary); color: var(--page); padding: 8px 14px; border-radius: 8px; font-size: 14px; z-index: 30;
}
.error { color: var(--danger); font-size: 14px; margin-top: 8px; }
