/*
 * Citévoix back-office — token foundation
 * Identity: « Le registre municipal » (2026-07 mock).
 *   Replaces the Phase-8c warm-earth/Karla overhaul AND Sahel v2.
 *
 * Palette : ink navy ground · vermillon civique accent · near-white panels.
 * Type    : Space Grotesk (display) · Public Sans (body) · IBM Plex Mono (labels).
 * Motifs  : 12 px card radius, dotted-grid dashboard canvas, mono uppercase captions,
 *           "REGISTRE D'ACTIVITÉ" ledger with dashed hairline dividers, photo-card
 *           map markers, ink-inverted "Délai moyen" KPI card.
 *
 * Frozen invariants that survive the identity change:
 *   - The 10 token keys (red/amber/green/blue/violet/teal/slate/rose/orange/lime)
 *     stay valid; only their hex values are remapped (invariant 2).
 *   - settings.statuses[].color still drives status pins via data-color.
 *   - Back-office accent stays hardcoded — settings.accent does not drive chrome.
 *   - RTL: logical properties only; mixed mono numbers get unicode-bidi isolate.
 */

@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;600;700&family=Public+Sans:ital,wght@0,400;0,500;0,600;0,700;1,400&family=IBM+Plex+Mono:wght@400;500&display=swap');

/* ── Light (default) ─────────────────────────────────────────────────────── */
:root {
  /* Canvas + floating panel */
  --canvas:        #F6F6F8;
  --panel:         #FFFFFF;
  --panel-radius:  16px;
  --panel-shadow:  0 40px 90px -30px rgba(20, 24, 40, .18);

  /* Surfaces inside the panel. Near-white card + a slightly-off band for
     KPI strips, sub-headers, and skeletons. */
  --surface:        #FFFFFF;
  --surface-tint:   #F1F1F4;
  --surface-tint-2: #EAEBEF;
  --surface-tint-3: #F6F6F8;
  --surface-map:    #454955;

  /* Ink ladder (cool, ink-navy anchored) */
  --ink:    #2C3040;
  --ink-2:  #31354A;
  --ink-3:  #4E5266;
  --ink-4:  #7A7F8C;
  --ink-5:  #8E93A0;
  --ink-6:  #B4B7C0;

  /* Borders */
  --line:         #DEDFE4;
  --line-2:       #CACCD4;
  --line-3:       #E4E5EA;
  --line-dashed:  #CACCD4;

  /* Rail (left icon strip) — dark ink slab, vermillon accent bar on active */
  --rail-bg:           #282C3A;
  --rail-ink:          #8E93A0;
  --rail-wordmark:     #6D7280;
  --rail-hover:        rgba(255, 255, 255, .06);
  --rail-active-bg:    #3A3F4E;
  --rail-active-ink:   #FFFFFF;

  /* Accent — vermillon civique (FROZEN; not driven by settings.accent) */
  --accent:        #D14A2E;
  --accent-deep:   #B93A22;
  --accent-ink:    #FFFFFF;
  --accent-tint:   rgba(209, 74, 46, .12);

  /* Danger / destructive — a more brown-red so it doesn't blur with the accent */
  --danger:        #B23A26;
  --danger-tint:   rgba(178, 58, 38, .10);

  /* Live status / pulse (repurposes the green token — same key semantics) */
  --live:          #5A9268;
  --live-tint:     rgba(90, 146, 104, .15);

  /* Water (map) — Hérault / Mediterranean blue */
  --water:         #3F6285;

  /* Radii */
  --r-panel:  16px;
  --r-card-l: 14px;
  --r-card:   12px;
  --r-card-s: 10px;
  --r-input:  10px;
  --r-chip:   9px;
  --r-tile:   9px;
  --r-pill:   999px;

  /* 4-pt spacing scale (unchanged) */
  --s-1:  4px;
  --s-2:  8px;
  --s-3:  12px;
  --s-4:  16px;
  --s-5:  20px;
  --s-6:  24px;
  --s-7:  30px;
  --s-8:  40px;

  /* Motion */
  --ease:    cubic-bezier(.22, 1, .36, 1);
  --t-fast:  120ms;
  --t-base:  200ms;
  --t-slow:  320ms;

  /* Typography */
  --font:         'Public Sans', system-ui, -apple-system, Segoe UI, sans-serif;
  --font-display: 'Space Grotesk', 'Public Sans', system-ui, sans-serif;
  --mono:         'IBM Plex Mono', ui-monospace, Menlo, monospace;

  /* Shadows — cooler, more restrained than the warm-earth era */
  --shadow-card:        0 1px 2px rgba(20, 24, 40, .04);
  --shadow-card-hover:  0 12px 28px -14px rgba(20, 24, 40, .22);
  --shadow-floating:    0 20px 45px -18px rgba(20, 24, 40, .28);
  --shadow-marker:      0 6px 16px -4px rgba(0, 0, 0, .35);

  /* Token palette (10 frozen keys). Semantic anchors from the mock:
     amber = Non assigné · blue = Assigné · violet = En cours · green = Résolu.
     red = vermillon accent · slate = neutral labels. */
  --tok-red:    #D14A2E;
  --tok-orange: #E28749;
  --tok-amber:  #D1963A;
  --tok-lime:   #9AAE47;
  --tok-green:  #5A9268;
  --tok-teal:   #3E9EA6;
  --tok-blue:   #4B7AD1;
  --tok-violet: #7B62B4;
  --tok-rose:   #C05784;
  --tok-slate:  #7A7F8C;

  /* Tinted fills — low-saturation companions for chip backgrounds. */
  --tok-red-tint:    rgba(209,  74,  46, .12);
  --tok-orange-tint: rgba(226, 135,  73, .14);
  --tok-amber-tint:  rgba(209, 150,  58, .16);
  --tok-lime-tint:   rgba(154, 174,  71, .16);
  --tok-green-tint:  rgba( 90, 146, 104, .15);
  --tok-teal-tint:   rgba( 62, 158, 166, .14);
  --tok-blue-tint:   rgba( 75, 122, 209, .14);
  --tok-violet-tint: rgba(123,  98, 180, .14);
  --tok-rose-tint:   rgba(192,  87, 132, .14);
  --tok-slate-tint:  rgba(122, 127, 140, .14);

  /* Transitional aliases — kept ONLY while un-ported per-page CSS still
     references these names. Delete once every page in redesign_checklist.md
     is ticked off. Do NOT use these names in new code. */
  --surface-2: var(--surface-tint-2);
  --r-inner:   var(--r-input);
}

/* ── Dark variant ────────────────────────────────────────────────────────── */
:root[data-theme="dark"] {
  --canvas:        #1B1E2A;
  --panel:         #22283A;
  --panel-shadow:  0 40px 90px -30px rgba(0, 0, 0, .55);

  --surface:        #2A3145;
  --surface-tint:   #262C3E;
  --surface-tint-2: #2E3448;
  --surface-tint-3: #232939;
  --surface-map:    #1D2130;

  --ink:    #ECEDF1;
  --ink-2:  #D8DAE1;
  --ink-3:  #A9ADB9;
  --ink-4:  #8A8F9B;
  --ink-5:  #6C7180;
  --ink-6:  #4E5266;

  --line:         #3B4056;
  --line-2:       #4A4F65;
  --line-3:       #333849;
  --line-dashed:  #4A4F65;

  --rail-bg:           #14172A;
  --rail-ink:          #8E93A0;
  --rail-wordmark:     #6D7280;
  --rail-hover:        rgba(255, 255, 255, .06);
  --rail-active-bg:    #2C3145;
  --rail-active-ink:   #FFFFFF;

  /* Vermillon stays the same — it's the identity. Danger lifted for AA. */
  --accent:        #D14A2E;
  --accent-deep:   #B93A22;
  --accent-ink:    #FFFFFF;
  --accent-tint:   rgba(209, 74, 46, .22);

  --danger:        #E26550;
  --danger-tint:   rgba(226, 101, 80, .20);

  --live:          #7EB08A;
  --live-tint:     rgba(126, 176, 138, .22);

  --water:         #4C7098;

  /* Token palette — slightly lifted for AA on ink-navy surfaces */
  --tok-red:    #E26550;
  --tok-orange: #EA9560;
  --tok-amber:  #E0A85B;
  --tok-lime:   #B8C868;
  --tok-green:  #7EB08A;
  --tok-teal:   #5FB8BE;
  --tok-blue:   #7CA0E2;
  --tok-violet: #9F86D0;
  --tok-rose:   #D57BA0;
  --tok-slate:  #9A9FAA;

  --tok-red-tint:    rgba(226, 101,  80, .22);
  --tok-orange-tint: rgba(234, 149,  96, .22);
  --tok-amber-tint:  rgba(224, 168,  91, .22);
  --tok-lime-tint:   rgba(184, 200, 104, .22);
  --tok-green-tint:  rgba(126, 176, 138, .22);
  --tok-teal-tint:   rgba( 95, 184, 190, .22);
  --tok-blue-tint:   rgba(124, 160, 226, .22);
  --tok-violet-tint: rgba(159, 134, 208, .22);
  --tok-rose-tint:   rgba(213, 123, 160, .22);
  --tok-slate-tint:  rgba(154, 159, 170, .22);

  --shadow-card:        0 1px 2px rgba(0, 0, 0, .35);
  --shadow-card-hover:  0 12px 28px -14px rgba(0, 0, 0, .55);
  --shadow-floating:    0 20px 45px -18px rgba(0, 0, 0, .60);
  --shadow-marker:      0 6px 16px -4px rgba(0, 0, 0, .55);

  --surface-2: var(--surface-tint-2);
  --r-inner:   var(--r-input);
}

/* ── data-color resolvers — used for status/severity chips ──────────────── */
[data-color="red"]    { --tone: var(--tok-red);    --tone-tint: var(--tok-red-tint);    }
[data-color="orange"] { --tone: var(--tok-orange); --tone-tint: var(--tok-orange-tint); }
[data-color="amber"]  { --tone: var(--tok-amber);  --tone-tint: var(--tok-amber-tint);  }
[data-color="lime"]   { --tone: var(--tok-lime);   --tone-tint: var(--tok-lime-tint);   }
[data-color="green"]  { --tone: var(--tok-green);  --tone-tint: var(--tok-green-tint);  }
[data-color="teal"]   { --tone: var(--tok-teal);   --tone-tint: var(--tok-teal-tint);   }
[data-color="blue"]   { --tone: var(--tok-blue);   --tone-tint: var(--tok-blue-tint);   }
[data-color="violet"] { --tone: var(--tok-violet); --tone-tint: var(--tok-violet-tint); }
[data-color="rose"]   { --tone: var(--tok-rose);   --tone-tint: var(--tok-rose-tint);   }
[data-color="slate"]  { --tone: var(--tok-slate);  --tone-tint: var(--tok-slate-tint);  }

/* ── Base resets ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }
body {
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  text-size-adjust: 100%;
}

/* Display face for headings when authors reach for h1-h4 without a class */
h1, h2, h3, h4 {
  font-family: var(--font-display);
  letter-spacing: -0.02em;
  font-weight: 600;
  color: var(--ink);
}

/* ── Full-bleed app chrome (rail + topbar + content fill the viewport) ──── */
.app-canvas {
  min-height: 100vh;
  display: flex;
}
.app-shell {
  width: 100%;
  min-height: 100vh;
  background: var(--panel);
  overflow: hidden;
  display: flex;
}
.app-main {
  flex: 1;
  min-width: 0;
  background: var(--panel);
  display: flex;
  flex-direction: column;
}
.app-content {
  flex: 1;
  overflow: auto;
  width: min(1480px, calc(100% - 100px));
  margin-inline: auto;
  padding: 2px 0 8px;
  display: flex;
  flex-direction: column;
  gap: var(--s-5);
}

/* ── Core components ─────────────────────────────────────────────────────── */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-card);
  padding: var(--s-6);
  box-shadow: var(--shadow-card);
}

.create-card,
.meta-card,
.cms-table-wrap,
.table-wrap,
.staff-table,
.settings-section,
.queue-card,
.map-card {
  box-shadow: var(--shadow-card);
}

/* Filled chip — small, no border, color-aware via data-color */
.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--s-1);
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .02em;
  white-space: nowrap;
  color: var(--tone);
  background: var(--tone-tint);
}
.chip-lg {
  padding: 4px 10px;
  border-radius: 8px;
  font-size: 11px;
}

/* Bordered selectable pill (modal status/severity setters) */
.pill-select {
  display: inline-flex;
  align-items: center;
  padding: 7px 12px;
  border-radius: var(--r-chip);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  background: var(--surface);
  color: var(--ink-4);
  border: 1px solid var(--line);
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease);
}
.pill-select:hover { background: var(--surface-tint); }
.pill-select.is-active {
  background: var(--tone);
  color: #fff;
  border-color: var(--tone);
}

/* Filter pill (queue / tabs) */
.pill {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  padding: 5px 11px;
  border-radius: var(--r-pill);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  background: var(--surface-tint-2);
  color: var(--ink-3);
  border: 0;
  font-family: var(--font);
  transition: filter var(--t-fast) var(--ease), background var(--t-fast) var(--ease);
}
.pill:hover { filter: brightness(.97); }
.pill.is-active {
  background: var(--rail-bg);
  color: #fff;
  font-weight: 600;
}

/* Primary (vermillon) button */
.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  background: var(--accent);
  color: var(--accent-ink);
  border: 0;
  border-radius: var(--r-input);
  padding: 10px 20px;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--t-fast) var(--ease);
}
.btn-primary:hover { background: var(--accent-deep); }
.btn-primary:active { filter: brightness(.94); }

/* Secondary / neutral button */
.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  background: var(--surface-tint);
  color: var(--ink-3);
  border: 1px solid var(--line);
  border-radius: var(--r-input);
  padding: 10px 18px;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--t-fast) var(--ease);
}
.btn-secondary:hover { background: var(--surface-tint-2); }

/* Square icon button (☾, ✕, back arrow) */
.btn-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--r-input);
  background: var(--surface-tint);
  color: var(--ink-3);
  border: 1px solid var(--line);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-family: var(--font);
  font-size: 15px;
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.btn-icon:hover { background: var(--surface-tint-2); color: var(--ink); }
.btn-icon.is-sm { width: 34px; height: 34px; border-radius: 9px; }
.btn-icon.is-danger {
  background: var(--danger-tint);
  color: var(--danger);
  border-color: transparent;
}

/* Search field */
.search {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  background: var(--surface-tint);
  border: 1px solid var(--line);
  border-radius: var(--r-input);
  padding: 8px 14px;
  min-width: 260px;
  height: 40px;
}
.search > .icon { color: var(--ink-4); font-size: 14px; display:inline-flex; }
.search > input {
  flex: 1;
  border: 0;
  background: none;
  outline: none;
  font-family: var(--font);
  font-size: 13px;
  color: var(--ink-2);
  min-width: 0;
}
.search > input::placeholder { color: var(--ink-4); }

/* Segmented control (3-way switch like FR/EN/AR) */
.segmented {
  display: inline-flex;
  background: var(--surface-tint);
  border: 1px solid var(--line);
  border-radius: var(--r-input);
  padding: 3px;
  font-size: 12px;
  font-weight: 600;
}
.segmented > * {
  padding: 5px 10px;
  border-radius: 7px;
  color: var(--ink-4);
  cursor: pointer;
  border: 0;
  background: none;
  font-family: var(--font);
  font-size: 12px;
  font-weight: 600;
  transition: color var(--t-fast) var(--ease);
}
.segmented > .is-active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(20,24,40,.08);
}

/* Live status indicator (Dispatch "En direct" pill) */
.live-pill {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  padding: 6px 11px;
  border-radius: var(--r-chip);
  background: var(--live-tint);
  color: var(--live);
  font-size: 12px;
  font-weight: 600;
}
.live-pill::before {
  content: '';
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--live);
  box-shadow: 0 0 0 0 currentColor;
  animation: pulse 1.8s var(--ease) infinite;
}
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(90, 146, 104, .50); }
  70%  { box-shadow: 0 0 0 6px rgba(90, 146, 104, 0); }
  100% { box-shadow: 0 0 0 0 rgba(90, 146, 104, 0); }
}

/* Vermillon pulse — used on the selected marker */
@keyframes cvpulse {
  0%   { box-shadow: 0 0 0 0    rgba(209, 74, 46, .45); }
  70%  { box-shadow: 0 0 0 12px rgba(209, 74, 46, 0); }
  100% { box-shadow: 0 0 0 0    rgba(209, 74, 46, 0); }
}

/* Overline — mono uppercase caption above titles ("REGISTRE D'ACTIVITÉ") */
.overline {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: .14em;
  color: var(--ink-4);
  text-transform: uppercase;
}

/* Monospace data: coordinates, IDs, timestamps */
.mono {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
}

/* Skeleton shimmer */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--surface-tint) 0%,
    var(--surface-tint-2) 50%,
    var(--surface-tint) 100%
  );
  background-size: 200% 100%;
  animation: shimmer 1.4s linear infinite;
  border-radius: 8px;
}
@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Focus ring — vermillon at 35% */
:focus-visible {
  outline: 0;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 35%, transparent);
}

/* Scrollbars */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: var(--ink-5); }
::-webkit-scrollbar-track { background: transparent; }

/* ── Form fields (generic) ──────────────────────────────────────────────── */
input, select, textarea {
  font-family: var(--font);
  font-size: 13px;
  color: var(--ink);
  background: var(--surface-tint-3);
  border: 1px solid var(--line);
  border-radius: var(--r-input);
  padding: 9px 12px;
  width: 100%;
  transition: border-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
}
textarea { resize: vertical; min-height: 96px; line-height: 1.55; }
input::placeholder, textarea::placeholder { color: var(--ink-5); }
input:focus, select:focus, textarea:focus {
  outline: 0;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent);
}

/* ── Motion guard ───────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition-duration: 1ms !important;
  }
}
