/* RadarParks Admin — thème clair/sombre par jetons */
:root {
  color-scheme: light;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f7f8fa;
  --surface-3: #eef0f3;
  --border: #e3e6ea;
  --border-strong: #cfd4db;
  --text: #111827;
  --text-2: #374151;
  --muted: #5b6472;
  --brand: #2f80ed;
  --primary: #1f6fd8;          /* fond des boutons : 4,9:1 avec le blanc */
  --primary-hover: #1a60bd;
  --primary-soft: #e8f1fd;
  --link: #1a66cc;
  --focus: #2f80ed;
  --grid: #e9ebee;
  --axis: #c9ced6;
  --good: #0a7d32;
  --good-soft: #e6f4ea;
  --bad: #c0352f;
  --bad-soft: #fdecea;
  --warn-ink: #8a5a00;
  --warn-soft: #fff4d6;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .04);
  /* séries catégorielles (palette validée, clair) */
  --series-1: #2a78d6;  /* publiées */
  --series-2: #eb6834;  /* annulées / 2e série */
  --series-3: #1baf7a;  /* prises */
  --series-4: #eda100;  /* disparues */
  --series-5: #e87ba4;
  --series-7: #6250d6;
  /* rampe séquentielle bleue */
  --seq-0: #eef0f3;
  --seq-1: #cde2fb; --seq-2: #9ec5f4; --seq-3: #6da7ec; --seq-4: #3987e5; --seq-5: #256abf; --seq-6: #184f95; --seq-7: #0d366b;
  --radius: 12px;
  --radius-sm: 8px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0f1115; --surface: #181a1f; --surface-2: #1d2026; --surface-3: #252830;
    --border: #2a2d35; --border-strong: #3a3e48;
    --text: #eef0f3; --text-2: #c9ced6; --muted: #9aa1ac;
    --brand: #5aa0f5; --primary: #1f6fd8; --primary-hover: #2a78e0; --primary-soft: #1b2a40; --link: #7db4f7; --focus: #7db4f7;
    --grid: #262930; --axis: #3a3e48;
    --good: #3fbf6a; --good-soft: #15291d; --bad: #f07470; --bad-soft: #341b1b; --warn-ink: #f2c25b; --warn-soft: #33290f;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500; --series-5: #d55181; --series-7: #9085e9;
    --seq-0: #22252c;
    --seq-1: #104281; --seq-2: #184f95; --seq-3: #1c5cab; --seq-4: #2a78d6; --seq-5: #5598e7; --seq-6: #86b6ef; --seq-7: #cde2fb;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1115; --surface: #181a1f; --surface-2: #1d2026; --surface-3: #252830;
  --border: #2a2d35; --border-strong: #3a3e48;
  --text: #eef0f3; --text-2: #c9ced6; --muted: #9aa1ac;
  --brand: #5aa0f5; --primary: #1f6fd8; --primary-hover: #2a78e0; --primary-soft: #1b2a40; --link: #7db4f7; --focus: #7db4f7;
  --grid: #262930; --axis: #3a3e48;
  --good: #3fbf6a; --good-soft: #15291d; --bad: #f07470; --bad-soft: #341b1b; --warn-ink: #f2c25b; --warn-soft: #33290f;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3);
  --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500; --series-5: #d55181; --series-7: #9085e9;
  --seq-0: #22252c;
  --seq-1: #104281; --seq-2: #184f95; --seq-3: #1c5cab; --seq-4: #2a78d6; --seq-5: #5598e7; --seq-6: #86b6ef; --seq-7: #cde2fb;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.5 var(--font); -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
[hidden] { display: none !important; }
a { color: var(--link); }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.skip-link { position: absolute; left: -9999px; top: 8px; z-index: 100; background: var(--surface); padding: 8px 12px; border-radius: 8px; }
.skip-link:focus { left: 8px; }
.sr-only { position: absolute; left: 0; top: 0; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Marque */
.brand { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; font-size: 16px; white-space: nowrap; }
.brand-sub { font-weight: 500; color: var(--muted); }
.brand-mark { width: 22px; height: 22px; border-radius: 7px; background: var(--brand); position: relative; flex: none; }
.brand-mark::after { content: "P"; position: absolute; inset: 0; display: grid; place-items: center; color: #fff; font-size: 13px; font-weight: 700; }
.brand-lg { font-size: 19px; }

/* Boutons et champs */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 36px; padding: 0 14px; border-radius: 9px; border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); cursor: pointer; font-weight: 500; white-space: nowrap; text-decoration: none;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .6; cursor: default; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-icon { width: 36px; padding: 0; }
.btn-block { width: 100%; }
.btn-sm { min-height: 30px; padding: 0 10px; font-size: 13px; }
.btn.spinning svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.field { display: grid; gap: 6px; font-weight: 500; }
.field input, .input, .select {
  min-height: 38px; padding: 0 12px; border-radius: 9px; border: 1px solid var(--border-strong);
  background: var(--surface); width: 100%;
}
.select { padding-right: 28px; width: auto; }
.input:focus, .field input:focus, .select:focus { outline: 2px solid var(--focus); outline-offset: 0; border-color: transparent; }

/* Connexion */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 28px; display: grid; gap: 16px; box-shadow: var(--shadow); }
.login-title { font-size: 20px; }
.login-hint { margin: -8px 0 0; color: var(--muted); }
.form-error { margin: 0; color: var(--bad); background: var(--bad-soft); padding: 10px 12px; border-radius: 8px; }

/* En-tête */
.topbar { position: sticky; top: 0; z-index: 20; background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar-row { display: flex; align-items: center; gap: 10px; padding: 10px 20px; flex-wrap: wrap; }
.topbar-filters { padding-top: 0; gap: 16px; }
.topbar-spacer { flex: 1; }
.updated { font-size: 13px; white-space: nowrap; }
#mock-badge { margin-left: auto; }
#mock-badge[hidden] + .updated { margin-left: auto; }

.segmented { display: inline-flex; background: var(--surface-3); border-radius: 10px; padding: 3px; gap: 2px; }
.segmented button {
  border: 0; background: transparent; padding: 5px 11px; border-radius: 8px; cursor: pointer; font-weight: 500; color: var(--text-2); white-space: nowrap; font-size: 13px;
}
.segmented button[aria-checked="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); font-weight: 600; }

.switch { position: relative; display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; font-weight: 500; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch-track { width: 36px; height: 20px; border-radius: 999px; background: var(--border-strong); position: relative; transition: background .15s; flex: none; }
.switch-track::after { content: ""; position: absolute; left: 2px; top: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.25); }
.switch input:checked + .switch-track { background: var(--primary); }
.switch input:checked + .switch-track::after { transform: translateX(16px); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--focus); outline-offset: 2px; }
.switch input:disabled + .switch-track { opacity: .5; }

/* Mise en page */
.layout { display: grid; grid-template-columns: 210px minmax(0, 1fr); min-height: calc(100vh - 100px); }
.sidenav { border-right: 1px solid var(--border); background: var(--surface); padding: 16px 10px; }
.sidenav ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; position: sticky; top: 116px; }
.sidenav a { display: block; padding: 8px 12px; border-radius: 8px; text-decoration: none; color: var(--text-2); font-weight: 500; white-space: nowrap; }
.sidenav a:hover { background: var(--surface-2); color: var(--text); }
.sidenav a[aria-current="page"] { background: var(--primary-soft); color: var(--link); font-weight: 600; }
.main { padding: 24px; min-width: 0; outline: none; }
#view { display: grid; grid-template-columns: minmax(0, 1fr); gap: 20px; transition: opacity .2s; }
#view.refreshing { opacity: .55; pointer-events: none; }

.page-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.page-head h1 { font-size: 22px; }
.page-head p { margin: 2px 0 0; color: var(--muted); }

.grid { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; }
.kpis { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; min-width: 0; }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head h2 { font-size: 15px; }
.card-head p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.card-tools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* Tuiles KPI */
.kpi { padding: 14px 16px; display: grid; gap: 4px; align-content: start; }
.kpi-label { color: var(--muted); font-size: 13px; font-weight: 500; }
.kpi-value { font-size: 26px; font-weight: 650; letter-spacing: -.02em; line-height: 1.2; }
.kpi-foot { font-size: 12.5px; color: var(--muted); display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.delta { font-weight: 600; padding: 1px 6px; border-radius: 6px; font-size: 12px; }
.delta-up { color: var(--good); background: var(--good-soft); }
.delta-down { color: var(--bad); background: var(--bad-soft); }
.delta-flat { color: var(--muted); background: var(--surface-3); }

/* Graphiques */
.chart-box { position: relative; height: 280px; }
.chart-box.sm { height: 220px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 0 0 10px; padding: 0; list-style: none; font-size: 13px; color: var(--text-2); }
.legend li { display: inline-flex; align-items: center; gap: 6px; }
.key-line { width: 14px; height: 3px; border-radius: 2px; display: inline-block; }
.key-rect { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.key-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
details.dataview { margin-top: 10px; font-size: 13px; }
details.dataview summary { cursor: pointer; color: var(--link); width: max-content; font-weight: 500; }
details.dataview .table-wrap { margin-top: 8px; max-height: 280px; }

/* Barres horizontales simples */
.hbars { display: grid; gap: 10px; margin: 0; padding: 0; list-style: none; }
.hbar { display: grid; grid-template-columns: minmax(80px, 34%) 1fr auto; gap: 10px; align-items: center; font-size: 13px; }
.hbar-label { color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar-track { height: 10px; background: var(--surface-3); border-radius: 0 4px 4px 0; position: relative; }
.hbar-fill { position: absolute; left: 0; top: 0; bottom: 0; background: var(--series-1); border-radius: 0 4px 4px 0; min-width: 2px; }
.hbar-value { font-variant-numeric: tabular-nums; white-space: nowrap; color: var(--text); font-weight: 500; }
.hbar-value small { color: var(--muted); font-weight: 400; margin-left: 4px; }

/* Barre segmentée */
.segbar { display: flex; gap: 2px; height: 28px; border-radius: 4px; overflow: hidden; margin: 6px 0 12px; }
.segbar span { display: flex; align-items: center; padding: 0 8px; color: #fff; font-size: 12px; font-weight: 600; min-width: 0; white-space: nowrap; border-radius: 4px; }
.segbar span.dark-ink { color: #0b0b0b; }

/* Heatmap */
.heatmap { display: grid; grid-template-columns: 34px repeat(24, minmax(0, 1fr)); gap: 2px; font-size: 11px; color: var(--muted); }
.heatmap .hm-cell { height: 22px; border-radius: 3px; background: var(--seq-0); cursor: default; }
.heatmap .hm-cell:hover { outline: 2px solid var(--text); outline-offset: -1px; }
.heatmap .hm-rowlabel { display: flex; align-items: center; font-weight: 500; }
.heatmap .hm-collabel { text-align: center; font-variant-numeric: tabular-nums; }
.seq-legend { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); margin-top: 10px; flex-wrap: wrap; }
.seq-legend .sw { width: 18px; height: 10px; border-radius: 2px; display: inline-block; }

/* Carte */
.map { height: 440px; border-radius: 10px; overflow: hidden; border: 1px solid var(--border); z-index: 0; background: var(--surface-3); }
.map-legend { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 10px; font-size: 12.5px; color: var(--text-2); align-items: center; }
.ring-dashed { width: 12px; height: 12px; border-radius: 50%; border: 2px dashed var(--muted); display: inline-block; }
.leaflet-container { font: 13px/1.4 var(--font); }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--surface); color: var(--text); box-shadow: 0 4px 16px rgba(0,0,0,.18); }
.leaflet-popup-content { margin: 12px 14px; }
.popup-title { font-weight: 600; margin-bottom: 4px; }
.popup-grid { display: grid; grid-template-columns: auto auto; gap: 2px 12px; }
.popup-grid dt { color: var(--muted); }
.popup-grid dd { margin: 0; font-weight: 500; text-align: right; font-variant-numeric: tabular-nums; }
.leaflet-control-attribution { background: color-mix(in srgb, var(--surface) 85%, transparent) !important; color: var(--muted); }
.leaflet-control-attribution a { color: var(--link); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(.9) contrast(.88) saturate(.6); }
}
:root[data-theme="dark"] .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(.9) contrast(.88) saturate(.6); }

/* Tableaux */
.table-tools { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.table-tools .input { max-width: 280px; }
.table-wrap { overflow: auto; border: 1px solid var(--border); border-radius: 10px; max-width: 100%; }
.table-wrap { position: relative; }
table.data { border-collapse: collapse; width: 100%; font-size: 13px; }
table.data th, table.data td { padding: 8px 12px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.data thead th { position: sticky; top: 0; background: var(--surface-2); font-weight: 600; color: var(--text-2); z-index: 1; }
table.data th.num, table.data td.num { text-align: right; }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover td { background: var(--surface-2); }
table.data tr.is-test td { color: var(--muted); }
.th-sort { background: none; border: 0; padding: 0; font-weight: 600; color: inherit; cursor: pointer; display: inline-flex; gap: 4px; align-items: center; }
.th-sort .arrow { opacity: .35; font-size: 11px; }
th[aria-sort="ascending"] .arrow, th[aria-sort="descending"] .arrow { opacity: 1; color: var(--link); }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 10px; flex-wrap: wrap; font-size: 13px; color: var(--muted); }
.pager .btns { display: flex; gap: 6px; }

.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--surface-3); color: var(--text-2); white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .8; }
.badge.plain::before { display: none; }
.badge-good { background: var(--good-soft); color: var(--good); }
.badge-bad { background: var(--bad-soft); color: var(--bad); }
.badge-warn { background: var(--warn-soft); color: var(--warn-ink); }
.badge-info { background: var(--primary-soft); color: var(--link); }

/* Fil d'événements */
.feed { list-style: none; margin: 0; padding: 0; display: grid; }
.feed li { display: grid; grid-template-columns: 12px 1fr auto; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--border); align-items: baseline; }
.feed li:last-child { border-bottom: 0; }
.feed .dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 5px; align-self: start; }
.feed .ev-label { font-weight: 600; }
.feed .ev-detail { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.feed time { color: var(--muted); font-size: 12.5px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.feed.scroll { max-height: 520px; overflow: auto; }

/* Alertes, vides, squelettes */
.alert { padding: 12px 14px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); margin-bottom: 16px; }
.alert-error { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.alert-info { background: var(--primary-soft); color: var(--text); border-color: transparent; }
.alert-warn { background: var(--warn-soft); color: var(--text); border-color: transparent; }
.alert strong { font-weight: 600; }
.empty { text-align: center; padding: 32px 16px; color: var(--muted); }
.empty strong { display: block; color: var(--text-2); margin-bottom: 4px; font-size: 14px; }
.skel { background: linear-gradient(90deg, var(--surface-3) 25%, var(--surface-2) 50%, var(--surface-3) 75%); background-size: 200% 100%; animation: shimmer 1.2s infinite; border-radius: 8px; }
@keyframes shimmer { to { background-position: -200% 0; } }
.skel-line { height: 12px; margin: 6px 0; }
.skel-num { height: 28px; width: 60%; margin-top: 6px; }
.skel-block { height: 260px; }
@media (prefers-reduced-motion: reduce) { .skel { animation: none; } .btn.spinning svg { animation: none; } }

.rules { margin: 0; padding-left: 18px; display: grid; gap: 8px; color: var(--text-2); }
.rules strong { color: var(--text); }

/* Info-bulle partagée (heatmap, barres HTML) */
.viz-tooltip {
  position: fixed; z-index: 1000; pointer-events: none; background: var(--surface); color: var(--text);
  border: 1px solid var(--border); box-shadow: 0 6px 20px rgba(0,0,0,.16); border-radius: 8px; padding: 8px 10px; font-size: 12.5px; max-width: 240px;
}
.viz-tooltip .tt-value { font-weight: 700; font-size: 14px; font-variant-numeric: tabular-nums; }
.viz-tooltip .tt-label { color: var(--muted); }

.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--text); color: var(--surface); padding: 10px 16px; border-radius: 10px; z-index: 1001; box-shadow: 0 6px 20px rgba(0,0,0,.2); max-width: calc(100vw - 32px); font-weight: 500; }
.toast.error { background: var(--bad); color: #fff; }

@media (min-width: 1101px) {
  .kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
/* Tablette */
@media (max-width: 1100px) {
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
/* Téléphone */
@media (max-width: 820px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .topbar { position: static; }
  .sidenav { position: sticky; top: 0; z-index: 15; border-right: 0; border-bottom: 1px solid var(--border); padding: 0; }
  .sidenav ul { display: flex; overflow-x: auto; gap: 4px; padding: 8px 16px; position: static; scrollbar-width: none; }
  .sidenav ul::-webkit-scrollbar { display: none; }
  .sidenav a { padding: 6px 12px; }
  .main { padding: 16px; }
  .topbar-row { padding: 8px 16px; gap: 8px; }
  .topbar-filters { padding-top: 0; gap: 10px; }
  .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); }
  .span-2 { grid-column: auto; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .kpi { padding: 12px; }
  .kpi-value { font-size: 22px; }
  .card { padding: 14px; }
  .map { height: 340px; }
  .heatmap { grid-template-columns: 30px repeat(24, minmax(0, 1fr)); gap: 1px; }
  .heatmap .hm-cell { height: 16px; border-radius: 2px; }
  .chart-box { height: 240px; }
  #logout-btn { width: 36px; padding: 0; }
  #logout-btn .btn-text { display: none; }
  .table-tools .input { max-width: none; flex: 1 1 100%; }
  .table-tools .select { flex: 1 1 150px; min-width: 0; }
}
@media (max-width: 400px) {
  .segmented button { padding: 5px 8px; }
}
