/* ============================================================================
   PALARID UI — design overhaul layer  (v1, Pass 1)
   ----------------------------------------------------------------------------
   Loaded LAST so it cascades over the 18 legacy inline <style> blocks without
   requiring a risky rewrite of a 2.4 MB single-file app. Every rule here is
   deliberate and traceable to the design audit.

   Direction: "calm instrument panel" — one accent, no gradient text, neutral
   surfaces, strict type/space scale, chrome recedes and content leads.

   Pass 1 scope (this file):
     A. Tokens (single source of truth) + real light theme
     B. Typography scale, flat page titles, sentence-case sizing
     C. Single accent; gradient text removed
     E. Layout: kill the 62px dead band, tighten max-width + rhythm
     G. Chrome: one FAB, calmer overlays
     + Accessibility: visible focus, 44px targets, contrast-safe borders
   ============================================================================ */

/* ---------------------------------------------------------------- A. TOKENS */
:root {
  /* Surfaces — dark (default) */
  --bg:            #0B0B0F;
  --surface-1:     #131318;
  --surface-2:     #1A1A21;
  --surface-3:     #22222B;
  /* CORRECTION to the brief: #2E2E38 was specified as "3.02:1" but measures
     1.46:1 on #0B0B0F — it would have failed WCAG 1.4.11 exactly like the old
     --line did. 1.4.11 governs CONTROL boundaries, not decorative dividers, so
     the token is split rather than making every hairline glare. Measured. */
  --border:         #2E2E38;   /* 1.46:1 — decorative dividers only (exempt) */
  --border-strong:  #3D3D4A;   /* 1.84:1 — emphasis dividers */
  --border-control: #5D5D6B;   /* 3.03:1 — inputs, buttons, focusable edges  */

  /* Text */
  --text:   #F2F2F5;
  --text-2: #B4B4C0;
  --text-3: #8A8A99;

  /* Accent — ONE */
  --accent:        #8B7CF6;
  --accent-hover:  #9D90F8;
  --accent-press:  #7A69F0;
  --accent-fg:     #0B0B0F;
  --accent-subtle: rgba(139,124,246,.12);
  --accent-border: rgba(139,124,246,.32);

  /* Semantic — status only, never decoration */
  --pos:  #3DD68C;  --pos-subtle:  rgba(61,214,140,.12);
  --neg:  #F2555A;  --neg-subtle:  rgba(242,85,90,.12);
  --warn: #F0A93B;  --warn-subtle: rgba(240,169,59,.12);
  --info: #4C9AFF;  --info-subtle: rgba(76,154,255,.12);

  /* Categorical ramp for charts — colour-blind safe, never reuses pos/neg */
  --cat-1:#8B7CF6; --cat-2:#4C9AFF; --cat-3:#3DD68C;
  --cat-4:#F0A93B; --cat-5:#E86FC4; --cat-6:#54C7D9;

  /* Radius — 4 values */
  --r-sm:6px; --r-md:10px; --r-lg:14px; --r-full:999px;

  /* Space — 4px base */
  --s-1:4px;  --s-2:8px;  --s-3:12px; --s-4:16px; --s-5:20px;
  --s-6:24px; --s-8:32px; --s-10:40px; --s-12:48px; --s-16:64px; --s-20:80px;

  /* Elevation — 3 levels */
  --e-1:0 1px 2px rgba(0,0,0,.28);
  --e-2:0 4px 12px rgba(0,0,0,.32);
  --e-3:0 12px 32px rgba(0,0,0,.40);

  /* Focus */
  --focus:0 0 0 2px var(--bg), 0 0 0 4px var(--accent);

  /* Motion */
  --dur-1:120ms; --dur-2:180ms; --dur-3:260ms;
  --ease:cubic-bezier(.2,0,0,1);

  /* Layout */
  --maxw-app:1200px; --maxw-prose:68ch;
  --topbar-h:56px; --nav-h:48px;

  /* Z-index — 6 tokens. Replaces 15 arbitrary values (0…99998). */
  --z-base:0; --z-sticky:100; --z-nav:200;
  --z-overlay:300; --z-modal:400; --z-toast:500;

  /* Type scale — the complete set */
  --fs-2xs:11px; --fs-xs:12px; --fs-sm:13px; --fs-md:15px; --fs-lg:17px;
  --fs-xl:20px;  --fs-2xl:24px; --fs-3xl:30px; --fs-4xl:40px;

  /* Legacy aliases remapped onto the new system so old rules inherit the
     redesign instead of fighting it. */
  --panel:      var(--surface-1);
  --panel-2:    var(--surface-2);
  --line:       var(--border);
  --line-soft:  var(--border);
  --mute:       var(--text-3);
  --text-soft:  var(--text-2);
  --purple:     var(--accent);
  --accent-2:   var(--info);     /* demoted: informational only */
  --accent-3:   var(--warn);     /* demoted: caution only */
  --good:       var(--pos);
  --bad:        var(--neg);
  --shadow-lg:  var(--e-3);
}

/* Real light theme — surfaces/text/borders only; accent + semantics unchanged */
[data-theme="light"] {
  --bg:#FBFBFD; --surface-1:#FFFFFF; --surface-2:#F4F4F7; --surface-3:#EAEAEF;
  --border:#DCDCE4; --border-strong:#C4C4D0;
  --border-control:#8E8E9C;    /* 3.13:1 on #FBFBFD — measured */
  --text:#16161C; --text-2:#4A4A58; --text-3:#6C6C7C;
  --accent-fg:#FFFFFF;
  --e-1:0 1px 2px rgba(16,16,28,.06);
  --e-2:0 4px 12px rgba(16,16,28,.08);
  --e-3:0 12px 32px rgba(16,16,28,.12);
}

/* ------------------------------------------------------------ B. TYPOGRAPHY */
body {
  font-size: var(--fs-md);            /* raise body from 14px */
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Page titles: flat. No gradient, no shimmer, no transparent fill. */
h1.page-title, .page-title {
  font-size: var(--fs-2xl) !important;
  line-height: 1.3;
  letter-spacing: -0.015em;
  font-weight: 600 !important;
  color: var(--text) !important;
  background: none !important;
  -webkit-background-clip: border-box !important;
  background-clip: border-box !important;
  -webkit-text-fill-color: currentColor !important;
  animation: none !important;
}
/* Kill the shimmer animation outright */
@keyframes titleShimmer { from { opacity:1 } to { opacity:1 } }

/* Card titles: readable sentence case, not 11px uppercase tracking */
.card-title, .card-title b {
  font-size: var(--fs-lg);
  font-weight: 600;
  color: var(--text);
  text-transform: none;
  letter-spacing: normal;
}
/* Uppercase reserved for micro eyebrow labels only */
.eyebrow {
  font-size: var(--fs-2xs);
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--text-3);
  font-weight: 600;
}

.page-sub { font-size: var(--fs-sm); color: var(--text-2); }

/* No 800 weights anywhere */
[style*="font-weight:800"], .card-title, h1, h2, h3, h4 { font-weight: 600; }

/* Tabular numerals on every numeric surface */
.tnum, .num, .stat b, .stat-value, .stat .v, table td, table th, kbd {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}
.num { text-align: right; }

/* Prose panes clamp for readability */
.panel-pane[data-pane="privacy"]  .main-inner,
.panel-pane[data-pane="terms"]    .main-inner,
.panel-pane[data-pane="cookies"]  .main-inner,
.panel-pane[data-pane="gdpr"]     .main-inner,
.panel-pane[data-pane="about"]    .main-inner,
.panel-pane[data-pane="changelog"] .main-inner { max-width: var(--maxw-prose); }

/* ----------------------------------------------- E. LAYOUT & THE DEAD SPACE */
/* THE BUG: `.tabs` declared `position:sticky; top:62px` then re-declared
   `position:relative` later in the SAME rule. Relative won, so top:62px became
   a 62px push-down — an empty band under the header on all 524 pages. */
.tabs {
  position: sticky !important;
  top: var(--topbar-h) !important;
  z-index: 49;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  border-bottom: 1px solid var(--border);
}
@supports not (background: color-mix(in srgb, red 50%, blue)) {
  .tabs { background: var(--bg); }
}

.topbar { min-height: var(--topbar-h); }

/* Content width + gutters + rhythm */
.main { max-width: var(--maxw-app); padding: var(--s-6) var(--s-8) var(--s-16) !important; }
@media (max-width: 1024px) { .main { padding: var(--s-5) var(--s-6) var(--s-12) !important; } }
@media (max-width: 600px)  { .main { padding: var(--s-4) var(--s-4) var(--s-12) !important; } }

/* Footer sits naturally at the bottom — removes the ~250px void on short pages */
body { display: flex; flex-direction: column; min-height: 100vh; }
.main { flex: 1 0 auto; }
.footer { margin-top: var(--s-8); flex-shrink: 0; }

/* Equal-height cards in every grid row */
.g2, .g3, .g4, .g6, .grid { align-items: stretch; }
.card { display: flex; flex-direction: column; }

/* Cards: one padding value, calm surface, hover only when interactive */
.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--s-5);
  box-shadow: var(--e-1);
  transition: border-color var(--dur-2) var(--ease), box-shadow var(--dur-2) var(--ease);
}
@media (max-width: 600px) { .card { padding: var(--s-4); } }
.card:hover { transform: none; }                       /* static cards must not lift */
a.card:hover, .card[role="button"]:hover, .card.is-clickable:hover {
  border-color: var(--accent-border);
  box-shadow: var(--e-2);
}

/* ------------------------------------------------------- C. COLOUR DISCIPLINE */
/* No gradient text anywhere */
h1, h2, h3, h4, .brand-name, .page-title {
  -webkit-text-fill-color: currentColor;
  background-image: none;
}
/* Zero is neutral, not positive */
.is-zero { color: var(--text-3) !important; }

/* ----------------------------------------------------- G. CHROME & OVERLAYS */
/* One FAB. Retire the competing orbs and the bleeding glow ellipse. */
#qc-orb, .ai-explain { display: none !important; }
#cp-orb {
  width: 56px; height: 56px;
  right: var(--s-6); bottom: var(--s-6);
  background: var(--accent) !important;
  box-shadow: var(--e-2) !important;
  animation: none !important;
  filter: none !important;
}
#cp-orb::before, #cp-orb::after { display: none !important; }

/* Smart insight: quieter, never covering content on small screens */
.smart-chip { box-shadow: var(--e-2); border-color: var(--border-strong); }
@media (max-width: 700px) { .smart-chip { display: none !important; } }

/* ------------------------------------------------------------ Z-INDEX ORDER */
/* BUG FIXED: .cmdk-overlay was 70 while #cp-orb was 998 and #qc-orb 996 — the
   floating orbs rendered ON TOP of the command palette and its scrim. Leaflet
   controls (1000) also outranked #cp-drawer (999). Remapped onto 6 tokens so
   the stack is intentional and debuggable. */
.ambient-stars              { z-index: var(--z-base) !important; }
.topbar                     { z-index: var(--z-sticky) !important; }
.tabs, #cat-bar             { z-index: var(--z-nav) !important; }
#cat-panel                  { z-index: calc(var(--z-nav) - 1) !important; }
.smart-chip, #cp-orb,
.float-ai, .ai-explain      { z-index: var(--z-overlay) !important; }
#cp-drawer, .float-ai-panel { z-index: calc(var(--z-modal) - 1) !important; }
.cmdk-overlay, #cmdk,
#spot, .lb, .email-lb,
#consent-bar                { z-index: var(--z-modal) !important; }
#toast-host                 { z-index: var(--z-toast) !important; }
/* Leaflet must sit under app chrome, not over it */
.leaflet-control-container  { z-index: calc(var(--z-sticky) - 1) !important; }

/* #qc-orb jumped sides between the 680px and 760px breakpoints (left:18px vs
   right:14px!important). It is retired in favour of one FAB, but pin it in
   case a legacy path re-shows it. */
#qc-orb { left: auto !important; right: var(--s-6) !important; }

/* ------------------------------------------------------- ACCESSIBILITY GATES */
/* Visible focus everywhere (replaces the 8 `outline:none` rules) */
:where(a, button, input, select, textarea, [tabindex]):focus-visible {
  outline: none;
  box-shadow: var(--focus);
  border-radius: var(--r-sm);
}
/* Minimum tap targets */
button, .tab, .cat-btn, [role="button"] { min-height: 36px; }
@media (pointer: coarse) {
  button, .tab, .cat-btn, [role="button"] { min-height: 44px; }
}
/* Skip link */
.skip-link {
  position: absolute; left: -9999px; top: 0; z-index: 100000;
  background: var(--accent); color: var(--accent-fg);
  padding: var(--s-2) var(--s-4); border-radius: var(--r-md); font-weight: 600;
}
.skip-link:focus { left: var(--s-4); top: var(--s-4); }

/* Respect reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
    scroll-behavior: auto !important;
  }
  #ambient-stars, .smart-chip { display: none !important; }
}

/* ------------------------------------------------------------- COMPONENTS v1 */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  min-height: 40px; min-width: 120px; padding: 0 var(--s-4);
  border-radius: var(--r-md); border: 1px solid transparent;
  font: inherit; font-size: var(--fs-sm); font-weight: 600;
  cursor: pointer; transition: background var(--dur-1) var(--ease), border-color var(--dur-1) var(--ease);
}
.btn--primary { background: var(--accent); color: var(--accent-fg); }
.btn--primary:hover { background: var(--accent-hover); }
.btn--primary:active { background: var(--accent-press); }
.btn--secondary { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.btn--secondary:hover { border-color: var(--border-strong); }
.btn--ghost { background: transparent; color: var(--text-2); }
.btn--ghost:hover { background: var(--surface-2); color: var(--text); }
.btn--danger { background: var(--neg); color: #fff; }
.btn--sm { min-height: 32px; font-size: var(--fs-xs); }
.btn--lg { min-height: 48px; font-size: var(--fs-md); }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
@media (max-width: 480px) { .btn { width: 100%; } }

.field { display: flex; flex-direction: column; gap: var(--s-2); }
.field > label { font-size: var(--fs-sm); font-weight: 500; color: var(--text-2); }
.field input, .field select, .field textarea {
  min-height: 40px; padding: 10px var(--s-3);
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border-control); border-radius: var(--r-md);
  font: inherit; font-size: var(--fs-md);
}

/* WCAG 1.4.11: every control boundary must clear 3:1. Applied globally so the
   485 unlabelled legacy inputs inherit a compliant edge immediately. */
input:not([type="range"]):not([type="checkbox"]):not([type="radio"]):not([type="color"]),
select, textarea {
  border-color: var(--border-control);
}
.btn--secondary { border-color: var(--border-control); }
.field .help { font-size: var(--fs-xs); color: var(--text-3); }
.field .error { font-size: var(--fs-xs); color: var(--neg); }

.empty-state { text-align: center; padding: var(--s-10) var(--s-4); color: var(--text-3); }
.empty-state .es-title { font-size: var(--fs-md); color: var(--text-2); margin-bottom: var(--s-3); }

.skeleton {
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 37%, var(--surface-2) 63%);
  background-size: 400% 100%;
  animation: skel 1.4s ease infinite;
  border-radius: var(--r-sm); min-height: 1em;
}
@keyframes skel { 0% { background-position: 100% 50% } 100% { background-position: 0 50% } }
