/* NY Voter Explorer — Stitch "Editorial macOS Sonoma" design system.
   Inter font, tonal surface layering, no-line rule, generous spacing,
   glassmorphism. Pairs with frontend/app.js; every id/class it reads
   (#question, .pin-btn, .is-stuck, .toast.show, etc.) is preserved. */

/* ── Design tokens ─────────────────────────────────────────────── */

:root {
  /* Surface hierarchy (light → dark tonal shifts define structure) */
  --bg: #f9f9fe;
  --surface: #f9f9fe;
  --surface-low: #f3f3f8;
  --surface-container: #ededf2;
  --surface-high: #e8e8ed;
  --surface-highest: #e2e2e7;
  --card: #ffffff;                          /* surface-container-lowest */
  --card-translucent: rgba(255, 255, 255, 0.72);

  /* Text */
  --fg: #1a1c1f;
  --fg-secondary: #414755;
  --muted: #717786;

  /* Primary (blue) */
  --accent: #0058bc;
  --accent-container: #0070eb;
  --accent-hover: #0064d4;
  --accent-wash: rgba(0, 88, 188, 0.08);
  --accent-ring: rgba(0, 88, 188, 0.24);
  --on-accent: #ffffff;

  /* Semantic */
  --error: #ba1a1a;
  --error-bg: rgba(186, 26, 26, 0.08);
  --ok: #30d158;
  --warn-fg: #8a5a00;
  --warn-bg: rgba(255, 159, 10, 0.08);
  --warn-border: #ff9f0a;
  --star: #f5b700;

  /* Outlines (ghost borders at 15% opacity per design system) */
  --outline: #717786;
  --outline-variant: #c1c6d7;
  --hairline: rgba(193, 198, 215, 0.15);
  --hairline-strong: rgba(193, 198, 215, 0.30);

  /* Rows / tables */
  --row-hover: rgba(0, 0, 0, 0.025);
  --row-alt: rgba(0, 0, 0, 0.015);
  --th-bg: #f3f3f8;
  --th-hover: #ededf2;

  /* SQL panel */
  --sql-bg: #1a1c1f;
  --sql-fg: #f5f5f7;

  /* Shadows (ambient, wide spread, very low opacity) */
  --shadow-card: 0 2px 8px rgba(26, 28, 31, 0.04);
  --shadow-float: 0 20px 40px rgba(26, 28, 31, 0.06);

  /* Radii — Sonoma curves */
  --radius-card: 1.25rem;   /* 20px */
  --radius-control: 0.75rem; /* 12px */
  --radius-outer: 1.75rem;  /* 28px */
  --radius-chip: 999px;

  /* Motion */
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-spring: cubic-bezier(0.32, 0.72, 0, 1);
  --dur-fast: 150ms;
  --dur-med: 220ms;

  /* Chart palette */
  --chart-1: #0058bc;
  --chart-2: #bc000a;
  --chart-3: #2a7f3a;
  --chart-4: #cc8400;
  --chart-5: #4c4aca;
  --chart-6: #169c9c;
  --chart-7: #c44a8b;
  --chart-8: #6b6b6b;

  /* Map choropleth ramp */
  --map-1: #d8e2ff;
  --map-2: #adc6ff;
  --map-3: #7aa8f0;
  --map-4: #4d8adf;
  --map-5: #0058bc;
  --map-6: #003d82;
  --map-null: #ededf2;

  /* Partisan palette — semantic political tones */
  --party-dem: #0058bc;
  --party-rep: #bc000a;
  --party-blk: #6b6b6b;
  --party-con: #9a7a00;
  --party-wor: #4c4aca;
  --party-ind: #2a7f3a;
  --party-oth: #4a6a80;

  /* Sidebar */
  --sidebar-w: 260px;
  --sidebar-bg: #ffffff;
  --sidebar-border: rgba(193, 198, 215, 0.15);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101419;
    --surface: #101419;
    --surface-low: #181c21;
    --surface-container: #1c2025;
    --surface-high: #262a30;
    --surface-highest: #31353b;
    --card: #1c2025;
    --card-translucent: rgba(28, 32, 37, 0.80);

    --fg: #e0e2ea;
    --fg-secondary: #c2c6d6;
    --muted: #8c909f;

    --accent: #adc6ff;
    --accent-container: #4d8eff;
    --accent-hover: #c2d5ff;
    --accent-wash: rgba(173, 198, 255, 0.12);
    --accent-ring: rgba(173, 198, 255, 0.28);
    --on-accent: #002e6a;

    --error: #ffb4ab;
    --error-bg: rgba(255, 180, 171, 0.12);
    --ok: #4de082;
    --warn-fg: #ffd480;
    --warn-bg: rgba(255, 159, 10, 0.14);
    --warn-border: #ff9f0a;
    --star: #ffd60a;

    --outline: #8c909f;
    --outline-variant: #424754;
    --hairline: rgba(66, 71, 84, 0.30);
    --hairline-strong: rgba(66, 71, 84, 0.50);

    --row-hover: rgba(255, 255, 255, 0.04);
    --row-alt: rgba(255, 255, 255, 0.02);
    --th-bg: #181c21;
    --th-hover: #262a30;

    --sql-bg: #0a0e13;
    --sql-fg: #e0e2ea;

    --shadow-card: 0 2px 8px rgba(0, 0, 0, 0.30);
    --shadow-float: 0 20px 40px rgba(0, 0, 0, 0.40);

    --chart-1: #adc6ff;
    --chart-2: #ff6961;
    --chart-3: #4de082;
    --chart-4: #fdba4e;
    --chart-5: #c2c1ff;
    --chart-6: #4fd1d1;
    --chart-7: #ff7ab6;
    --chart-8: #a0a0a5;

    --map-1: #0a1a30;
    --map-2: #14325a;
    --map-3: #204e8a;
    --map-4: #3070b8;
    --map-5: #5a9fe6;
    --map-6: #8cc2ff;
    --map-null: #262a30;

    --party-dem: #adc6ff;
    --party-rep: #ff6961;
    --party-blk: #a0a0a5;
    --party-con: #fdba4e;
    --party-wor: #c2c1ff;
    --party-ind: #4de082;
    --party-oth: #7fa4c0;

    --sidebar-bg: #181c21;
    --sidebar-border: rgba(66, 71, 84, 0.30);
  }
}

/* ── Reset & base ──────────────────────────────────────────────── */

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

.skip-link {
  position: absolute;
  top: -40px;
  left: 12px;
  z-index: 2000;
  padding: 8px 14px;
  background: var(--fg);
  color: var(--bg);
  font-size: 13px;
  font-weight: 500;
  border-radius: var(--radius-control);
  text-decoration: none;
  transition: top var(--dur-fast) var(--ease-out);
}
.skip-link:focus {
  top: 12px;
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 6px;
}

html, body { height: 100%; }

body {
  margin: 0;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI",
    Helvetica, Arial, sans-serif;
  font-size: 15px;
  font-feature-settings: "ss01", "cv11";
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  color: var(--fg);
  background: var(--bg);
  line-height: 1.5;
  letter-spacing: -0.006em;
}

.stats-bar, .cost-bar, .meta, thead th, tbody td,
.map-legend, .results-header, #result-count {
  font-variant-numeric: tabular-nums;
}

::selection { background: var(--accent-wash); }

/* ── App shell layout ──────────────────────────────────────────── */

.app-shell {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

.main-column {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
  position: relative;
}

/* ── Sidebar ───────────────────────────────────────────────────── */

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  padding: 24px 16px 16px;
  overflow-y: auto;
  z-index: 20;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 4px 20px;
}

.sidebar-mark {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-container));
  box-shadow: 0 4px 12px rgba(0, 88, 188, 0.20);
  flex-shrink: 0;
}
.sidebar-mark span {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.04em;
  color: #fff;
}

.sidebar-brand-text {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}
.sidebar-title {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--fg);
  white-space: nowrap;
}
.sidebar-subtitle {
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.02em;
}

.new-analysis-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 10px 16px;
  margin-bottom: 24px;
  background: linear-gradient(135deg, var(--accent), var(--accent-container));
  color: #fff;
  border: none;
  border-radius: var(--radius-control);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: filter var(--dur-fast) var(--ease-out),
              transform var(--dur-fast) var(--ease-out);
}
.new-analysis-btn:hover { filter: brightness(1.08); }
.new-analysis-btn:active { transform: scale(0.97); }
.new-analysis-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-ring);
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}

.sidebar-group-label {
  display: block;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 16px 12px 6px;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 12px;
  background: transparent;
  color: var(--fg-secondary);
  border: none;
  border-radius: var(--radius-control);
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: background var(--dur-fast) var(--ease-out),
              color var(--dur-fast) var(--ease-out);
}
.sidebar-link:hover {
  background: var(--surface-low);
  color: var(--fg);
}
.sidebar-link.is-active {
  background: var(--accent-wash);
  color: var(--accent);
}
.sidebar-link:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-ring);
}

.sidebar-icon {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  opacity: 0.7;
}
.sidebar-link.is-active .sidebar-icon { opacity: 1; }

.pill-count {
  font-size: 11px;
  padding: 1px 7px;
  border-radius: var(--radius-chip);
  background: var(--surface-container);
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  line-height: 1.4;
  margin-left: auto;
}
.sidebar-link.is-active .pill-count {
  background: var(--accent-wash);
  color: var(--accent);
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 8px;
  border-radius: var(--radius-control);
  background: var(--surface-low);
}

.sidebar-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-container));
  flex-shrink: 0;
}

.sidebar-user-info {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}
.sidebar-user-email {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--fg);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sidebar-signout {
  background: none;
  border: none;
  padding: 0;
  font-family: inherit;
  font-size: 11.5px;
  color: var(--muted);
  cursor: pointer;
  text-align: left;
  transition: color var(--dur-fast);
}
.sidebar-signout:hover { color: var(--error); }

/* Mobile sidebar overlay */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 19;
  opacity: 0;
  transition: opacity var(--dur-med) var(--ease-out);
}
.sidebar-overlay.is-visible {
  opacity: 1;
}

.sidebar-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--fg);
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-control);
  transition: background var(--dur-fast);
}
.sidebar-toggle:hover { background: var(--surface-low); }

/* ── Header ────────────────────────────────────────────────────── */

header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 32px;
  background: var(--card-translucent);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--hairline);
  flex-shrink: 0;
  z-index: 10;
}
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  header { background: var(--card); }
}

.header-title {
  display: none; /* Visible on mobile only when sidebar hidden */
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.015em;
}

.stats-bar {
  color: var(--muted);
  font-size: 13px;
}
.stats-bar strong { color: var(--fg); font-weight: 600; }

/* Cost bar (in sidebar footer) */
.cost-bar {
  color: var(--muted);
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  background: var(--surface-low);
  border-radius: var(--radius-control);
  cursor: pointer;
  user-select: none;
  transition: background var(--dur-fast) var(--ease-out),
              color var(--dur-fast) var(--ease-out);
  white-space: nowrap;
}
.cost-bar:hover {
  background: var(--surface-container);
  color: var(--fg);
}
.cost-bar:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-ring);
}
.cost-bar strong { color: var(--fg); font-weight: 600; }
.cost-bar .coin {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: linear-gradient(135deg, #f5c97a, #b8860b);
  box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.25);
  color: transparent;
  line-height: 1;
}
.cost-bar .coin-cost {
  font-variant-numeric: tabular-nums;
  color: var(--fg);
  font-weight: 500;
}
.cost-bar.is-expanded { padding: 8px 14px; }
.cost-bar.is-expanded .coin { display: none; }

/* ── Sign-in overlay ───────────────────────────────────────────── */

.signin-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(249, 249, 254, 0.72);
  backdrop-filter: saturate(180%) blur(24px);
  -webkit-backdrop-filter: saturate(180%) blur(24px);
  animation: fadeIn var(--dur-med) var(--ease-out);
}
@media (prefers-color-scheme: dark) {
  .signin-overlay { background: rgba(16, 20, 25, 0.80); }
}
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .signin-overlay { background: var(--bg); }
}

.signin-card {
  background: var(--card);
  border-radius: var(--radius-outer);
  padding: 48px 40px 36px;
  max-width: 420px;
  width: 100%;
  text-align: center;
  box-shadow: var(--shadow-float);
  animation: popIn var(--dur-med) var(--ease-spring);
}

.signin-mark {
  width: 64px;
  height: 64px;
  margin: 0 auto 18px;
  border-radius: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-container));
  box-shadow: 0 6px 20px rgba(0, 88, 188, 0.28);
}
.signin-mark-text {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.04em;
  color: #fff;
}

.signin-brand {
  margin: 0 0 8px;
  font-size: clamp(24px, 3vw, 30px);
  font-weight: 600;
  letter-spacing: -0.022em;
  color: var(--fg);
}
.signin-tagline {
  color: var(--muted);
  margin: 0 0 18px;
  font-size: 14.5px;
  line-height: 1.5;
}
.signin-freshness {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px 4px 8px;
  margin: 0 0 22px;
  border-radius: 999px;
  background: var(--accent-wash);
  color: var(--accent);
  font-size: 12px;
  font-weight: 500;
}
.signin-freshness-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 30%, transparent);
}

.signin-btn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 10px 18px;
  background: var(--card);
  color: var(--fg);
  border: 1px solid var(--hairline-strong);
  border-radius: var(--radius-control);
  text-decoration: none;
  font-weight: 500;
  font-size: 14px;
  transition: border-color var(--dur-fast) var(--ease-out),
              background var(--dur-fast) var(--ease-out);
}
.signin-btn:hover {
  background: var(--surface-low);
  border-color: var(--accent);
}
.signin-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-ring);
  border-color: var(--accent);
}
.signin-error {
  color: var(--error);
  background: var(--error-bg);
  padding: 10px 14px;
  border-radius: var(--radius-control);
  margin-top: 16px;
  font-size: 13px;
}

/* ── Main content area ─────────────────────────────────────────── */

main {
  flex: 1;
  overflow-y: auto;
  padding: 32px 40px 40px;
  max-width: 960px;
  width: 100%;
  margin: 0 auto;
}

/* ── Bottom query bar ──────────────────────────────────────────── */

.query-bar {
  flex-shrink: 0;
  z-index: 15;
  padding: 12px 40px 16px;
  background: var(--card-translucent);
  backdrop-filter: saturate(180%) blur(24px);
  -webkit-backdrop-filter: saturate(180%) blur(24px);
  border-top: 1px solid var(--hairline);
}
.query-bar .query-section {
  max-width: 960px;
  margin: 0 auto;
}
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .query-bar { background: var(--card); }
}

.query-section {
  /* Kept for JS intersection observer compatibility */
}

.query-input-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--card);
  border-radius: var(--radius-outer);
  padding: 6px 6px 6px 20px;
  box-shadow: var(--shadow-card), 0 0 0 1px var(--hairline);
  transition: box-shadow var(--dur-fast) var(--ease-out);
}
.query-input-row:focus-within {
  box-shadow: var(--shadow-card), 0 0 0 2px var(--accent);
}

.query-input-row textarea {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--fg);
  font-family: inherit;
  font-size: 15px;
  line-height: 1.45;
  resize: none;
  padding: 8px 0;
  min-height: 38px;
  max-height: 160px;
}
.query-input-row textarea::placeholder { color: var(--muted); }
.query-input-row textarea:focus { outline: none; }

.ask-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-container));
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: filter var(--dur-fast) var(--ease-out),
              transform var(--dur-fast) var(--ease-out);
}
.ask-btn:hover { filter: brightness(1.08); }
.ask-btn:active { transform: scale(0.93); }
.ask-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
  filter: none;
}
.ask-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-ring);
}

.query-section .status {
  margin-top: 8px;
  padding: 0 4px;
}
.query-section .error {
  margin-top: 8px;
}

/* Continuation pill */
.continuation-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
  background: var(--accent-wash);
  border: none;
  color: var(--fg);
  padding: 4px 4px 4px 12px;
  border-radius: var(--radius-chip);
  font-size: 12.5px;
  margin-bottom: 8px;
  animation: popIn var(--dur-med) var(--ease-spring);
}
.continuation-label {
  color: var(--accent);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 10.5px;
}
.continuation-text {
  color: var(--fg);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 50ch;
}
.continuation-x {
  background: transparent;
  color: var(--muted);
  border: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  cursor: pointer;
  line-height: 1;
  font-size: 12px;
  padding: 0;
  transition: background var(--dur-fast) var(--ease-out),
              color var(--dur-fast) var(--ease-out);
}
.continuation-x:hover { background: var(--row-hover); color: var(--fg); }

/* ── Buttons ───────────────────────────────────────────────────── */

button {
  padding: 8px 16px;
  background: linear-gradient(135deg, var(--accent), var(--accent-container));
  color: #fff;
  border: none;
  border-radius: var(--radius-control);
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  letter-spacing: -0.01em;
  transition: filter var(--dur-fast) var(--ease-out),
              transform var(--dur-fast) var(--ease-out),
              box-shadow var(--dur-fast) var(--ease-out);
}
button:hover { filter: brightness(1.06); }
button:active { transform: scale(0.98); }
button:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-ring);
}
button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
  filter: none;
}

button.small {
  background: var(--surface-low);
  color: var(--fg-secondary);
  padding: 6px 14px;
  font-size: 12.5px;
  font-weight: 500;
  border-radius: var(--radius-chip);
  filter: none;
}
button.small:hover {
  background: var(--surface-container);
  color: var(--fg);
}

.hint {
  color: var(--muted);
  font-size: 12.5px;
}

.status {
  color: var(--muted);
  font-size: 14px;
}

.error {
  padding: 10px 14px;
  border-radius: var(--radius-control);
  background: var(--error-bg);
  color: var(--error);
  font-size: 13.5px;
  white-space: pre-wrap;
}

/* ── Modal ─────────────────────────────────────────────────────── */

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.36);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  animation: fadeIn var(--dur-med) var(--ease-out);
}
@media (prefers-color-scheme: dark) {
  .modal-backdrop { background: rgba(0, 0, 0, 0.56); }
}
.modal-panel {
  position: relative;
  background: var(--card);
  border-radius: var(--radius-outer);
  box-shadow: var(--shadow-float);
  max-width: 480px;
  width: 100%;
  padding: 28px 32px 24px;
  animation: popIn var(--dur-med) var(--ease-spring);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
}
.modal-header h2 {
  font-size: 18px;
  font-weight: 600;
  margin: 0;
}
.icon-btn {
  background: var(--surface-low);
  color: var(--muted);
  border: none;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: color var(--dur-fast), background var(--dur-fast);
}
.icon-btn:hover { color: var(--fg); background: var(--surface-container); }
.icon-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-ring);
}

.shortcut-list {
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.shortcut-list > div {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 0;
}
.shortcut-list dt {
  display: flex;
  gap: 4px;
  align-items: center;
  flex-wrap: wrap;
  color: var(--fg);
  font-size: 13.5px;
}
.shortcut-list dd {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  text-align: right;
  max-width: 55%;
}

kbd {
  display: inline-block;
  padding: 2px 7px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11.5px;
  line-height: 1.4;
  color: var(--fg);
  background: var(--surface-container);
  border-radius: 6px;
  min-width: 20px;
  text-align: center;
}

/* ── Welcome grid ──────────────────────────────────────────────── */

.welcome {
  margin: 0 0 32px;
  animation: welcome-fade var(--dur-med) var(--ease-out);
}
.welcome h2 {
  font-size: clamp(28px, 4vw, 40px);
  font-weight: 700;
  letter-spacing: -0.025em;
  line-height: 1.15;
  margin: 0 0 10px;
  color: var(--fg);
}
.welcome-sub {
  margin: 0 0 28px;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.5;
}

.welcome-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 14px;
}

.welcome-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-start;
  text-align: left;
  padding: 20px 22px;
  background: var(--card);
  border: none;
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  cursor: pointer;
  font: inherit;
  color: inherit;
  transition: transform var(--dur-fast) var(--ease-out),
              box-shadow var(--dur-fast) var(--ease-out);
}
.welcome-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-float);
}
.welcome-card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.welcome-kind {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--accent-wash);
}
.welcome-q {
  font-size: 15px;
  font-weight: 500;
  color: var(--fg);
  line-height: 1.35;
}
.welcome-hint {
  font-size: 12.5px;
  color: var(--muted);
}

@keyframes welcome-fade {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  .welcome { animation: none; }
  .welcome-card { transition: none; }
  .welcome-card:hover { transform: none; }
}

/* ── Skeleton loading ──────────────────────────────────────────── */

.skeleton {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 16px;
  animation: skel-fade-in var(--dur-med) var(--ease-out);
}
.skel-card,
.skel-table {
  background: var(--card);
  border-radius: var(--radius-card);
  padding: 24px;
  box-shadow: var(--shadow-card);
}
.skel-card { display: flex; flex-direction: column; gap: 16px; }
.skel-table { padding: 18px 22px; display: flex; flex-direction: column; gap: 12px; }

.skel-line,
.skel-row {
  height: 14px;
  border-radius: 8px;
  background: linear-gradient(90deg, var(--surface-container) 0%, var(--surface-low) 50%, var(--surface-container) 100%);
  background-size: 200% 100%;
  animation: skel-shimmer 1.4s linear infinite;
}
.skel-line--lg { height: 28px; width: 45%; }
.skel-line--md { height: 14px; width: 70%; }
.skel-row { height: 18px; }
.skel-row--head { height: 14px; width: 60%; opacity: 0.75; }

@keyframes skel-shimmer {
  0%   { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}
@keyframes skel-fade-in {
  from { opacity: 0; transform: translateY(2px); }
  to   { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  .skel-line, .skel-row { animation: none; background: var(--surface-container); }
}

/* ── Results ───────────────────────────────────────────────────── */

.results {
  margin-top: 8px;
}

/* SQL box */
.sql-box {
  background: var(--card);
  border-radius: var(--radius-card);
  padding: 14px 18px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-card);
}
.sql-box summary {
  cursor: pointer;
  font-weight: 500;
  font-size: 13.5px;
  user-select: none;
  color: var(--fg-secondary);
  list-style: none;
  display: flex;
  align-items: center;
  gap: 6px;
}
.sql-box summary::-webkit-details-marker { display: none; }
.sql-box summary::before {
  content: "";
  display: inline-block;
  width: 0; height: 0;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  border-left: 5px solid currentColor;
  transition: transform var(--dur-fast) var(--ease-out);
  opacity: 0.5;
}
.sql-box[open] summary::before { transform: rotate(90deg); }

.sql-box pre {
  margin: 12px 0;
  padding: 14px 16px;
  background: var(--sql-bg);
  color: var(--sql-fg);
  border-radius: var(--radius-control);
  overflow-x: auto;
  font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  font-size: 12.5px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}
.sql-box pre code {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
  background: transparent;
  padding: 0;
  display: block;
  white-space: pre-wrap;
}

/* Prism syntax */
.sql-box .token.keyword,
.sql-box .token.operator       { color: #ff7ab2; }
.sql-box .token.function       { color: #82aaff; }
.sql-box .token.string         { color: #a5d6a7; }
.sql-box .token.number         { color: #f5c97a; }
.sql-box .token.boolean,
.sql-box .token.constant       { color: #f5c97a; }
.sql-box .token.punctuation    { color: #c0c0c5; }
.sql-box .token.comment        { color: #8e8e93; font-style: italic; }
.sql-box .token.variable       { color: #ffd480; }

/* Summary */
.summary {
  background: var(--accent-wash);
  color: var(--fg);
  padding: 16px 20px;
  border-radius: var(--radius-card);
  margin-bottom: 20px;
  font-size: 14.5px;
  line-height: 1.55;
}

/* Metric card */
.metric-card {
  background: var(--card);
  border-radius: var(--radius-card);
  padding: 40px 36px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-card);
  text-align: left;
}
.metric-value {
  font-family: "Inter", -apple-system, sans-serif;
  font-size: clamp(44px, 7vw, 72px);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.02;
  font-variant-numeric: tabular-nums;
  color: var(--fg);
}
.metric-label {
  margin-top: 12px;
  font-size: 15px;
  color: var(--muted);
  line-height: 1.45;
  max-width: 60ch;
}
.metric-sub {
  margin-top: 6px;
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-weight: 600;
}

/* Banner (truncation warning) */
.banner {
  background: var(--warn-bg);
  padding: 14px 18px;
  border-radius: var(--radius-card);
  margin-bottom: 20px;
  font-size: 13.5px;
  color: var(--warn-fg);
}
.banner strong {
  display: block;
  margin-bottom: 2px;
  font-weight: 600;
}

/* ── Chart / Map ───────────────────────────────────────────────── */

.chart-wrapper {
  background: var(--card);
  border-radius: var(--radius-card);
  padding: 16px;
  margin-bottom: 20px;
  height: 340px;
  position: relative;
  box-shadow: var(--shadow-card);
}
.chart-wrapper canvas { max-height: 100%; }

.map-wrapper {
  padding: 0;
  overflow: hidden;
  height: 420px;
}
#map { width: 100%; height: 100%; }

.map-legend {
  position: absolute;
  right: 14px;
  bottom: 14px;
  background: var(--card-translucent);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-radius: var(--radius-control);
  padding: 10px 12px;
  font-size: 11.5px;
  color: var(--fg);
  line-height: 1.55;
  box-shadow: var(--shadow-card);
}
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .map-legend { background: var(--card); }
}
.map-legend-title {
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 4px;
}
.map-legend .row { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.map-legend .sw {
  width: 14px;
  height: 10px;
  border-radius: 3px;
  flex: 0 0 14px;
}
.map-legend .sw-null {
  background-image: repeating-linear-gradient(-45deg, rgba(0,0,0,0.06) 0 2px, transparent 2px 4px);
}

/* Map layer picker — segmented control for switching district layers */
.map-layer-picker {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  display: flex;
  gap: 1px;
  background: var(--card-translucent);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-radius: var(--radius-chip);
  padding: 3px;
  box-shadow: var(--shadow-card);
}
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .map-layer-picker { background: var(--card); }
}
.map-layer-btn {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 11.5px;
  font-weight: 500;
  padding: 5px 12px;
  border-radius: var(--radius-chip);
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--dur-fast) var(--ease-out),
              color var(--dur-fast) var(--ease-out),
              box-shadow var(--dur-fast) var(--ease-out);
}
.map-layer-btn:hover {
  color: var(--fg);
  background: var(--accent-wash);
}
.map-layer-btn.is-active {
  background: var(--accent);
  color: var(--on-accent);
  box-shadow: 0 1px 4px rgba(0, 88, 188, 0.25);
}

/* Leaflet controls */
.leaflet-control-zoom {
  border: none !important;
  border-radius: var(--radius-control) !important;
  overflow: hidden;
  box-shadow: var(--shadow-card) !important;
  background: var(--card-translucent) !important;
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
}
.leaflet-control-zoom a {
  background: transparent !important;
  border: none !important;
  color: var(--fg) !important;
  width: 30px !important;
  height: 30px !important;
  line-height: 30px !important;
  font-size: 17px !important;
  font-weight: 500 !important;
  transition: background var(--dur-fast);
}
.leaflet-control-zoom a + a {
  border-top: 1px solid var(--hairline) !important;
}
.leaflet-control-zoom a:hover { background: var(--surface-low) !important; }
.leaflet-control-zoom a.leaflet-disabled { opacity: 0.4; cursor: default; }
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .leaflet-control-zoom { background: var(--card) !important; }
}

.leaflet-tooltip.county-tip {
  background: var(--fg);
  color: var(--bg);
  border: none;
  border-radius: 8px;
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 500;
  box-shadow: var(--shadow-card);
}
.leaflet-tooltip.county-tip::before { display: none; }

/* ── Results header + table ────────────────────────────────────── */

.results-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  font-size: 13.5px;
  color: var(--muted);
}
.results-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.table-wrapper {
  max-height: 560px;
  overflow: auto;
  background: var(--card);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

thead th {
  position: sticky;
  top: 0;
  background: var(--th-bg);
  padding: 12px 16px;
  text-align: left;
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  transition: background var(--dur-fast), color var(--dur-fast);
}
thead th:hover { background: var(--th-hover); color: var(--fg-secondary); }
thead th .sort-arrow {
  color: var(--accent);
  margin-left: 4px;
  font-size: 10px;
}

/* No divider lines — use spacing + hover for rows (no-line rule) */
tbody td {
  padding: 10px 16px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 320px;
  cursor: copy;
}
tbody tr:nth-child(even) { background: var(--row-alt); }
tbody tr:hover { background: var(--row-hover); }

/* Typed cells */
th.th-num, td.td-num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
th.th-bool, td.td-bool { text-align: center; }

.bool-dot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
}
.bool-true {
  background: color-mix(in srgb, var(--ok) 18%, transparent);
  color: #1c8b3d;
}
@media (prefers-color-scheme: dark) {
  .bool-true { color: #4cd96d; background: color-mix(in srgb, var(--ok) 22%, transparent); }
}
.bool-false {
  background: transparent;
  border: 1.5px solid var(--outline-variant);
  width: 10px;
  height: 10px;
}
.bool-null { color: var(--muted); font-weight: 400; }

.td-date .date-rel {
  display: inline-block;
  color: var(--fg);
}
.td-date .date-abs {
  display: inline-block;
  margin-left: 6px;
  color: var(--muted);
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
}

/* ── Floating tooltip ──────────────────────────────────────────── */

.float-tip {
  position: absolute;
  z-index: 1100;
  max-width: 260px;
  padding: 10px 12px;
  background: var(--fg);
  color: var(--bg);
  border-radius: 10px;
  font-size: 12px;
  line-height: 1.4;
  box-shadow: var(--shadow-float);
  opacity: 0;
  transform: translateY(2px);
  transition: opacity var(--dur-fast) var(--ease-out),
              transform var(--dur-fast) var(--ease-out);
  pointer-events: none;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.float-tip.show { opacity: 1; transform: translateY(0); }
.float-tip strong { font-weight: 600; word-break: break-word; }
.float-tip .tip-col {
  color: color-mix(in srgb, var(--bg) 65%, transparent);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.float-tip .tip-hint {
  color: color-mix(in srgb, var(--bg) 55%, transparent);
  font-size: 11px;
  margin-top: 2px;
}
.float-tip::after {
  content: "";
  position: absolute;
  bottom: -4px;
  left: 50%;
  width: 8px;
  height: 8px;
  background: var(--fg);
  transform: translateX(-50%) rotate(45deg);
  border-radius: 1px;
}
.float-tip.below::after { bottom: auto; top: -4px; }

@media (prefers-reduced-motion: reduce) {
  .float-tip { transition: none; }
}

/* ── Toast ─────────────────────────────────────────────────────── */

.toast {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  background: var(--fg);
  color: var(--bg);
  padding: 10px 20px;
  border-radius: var(--radius-chip);
  font-size: 13px;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur-fast) var(--ease-out),
              transform var(--dur-fast) var(--ease-out);
  z-index: 1000;
  max-width: 80vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  box-shadow: var(--shadow-float);
}
.toast.show {
  opacity: 0.96;
  transform: translateX(-50%) translateY(0);
}

/* ── Library ───────────────────────────────────────────────────── */

.library {
  margin-top: 40px;
}

.section-heading {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 600;
  margin: 0 0 12px;
}

/* Keep these rules for JS compatibility — pills are now in the sidebar,
   but any leftover .library-filters outside sidebar still works. */
.library-filters {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.library-empty {
  color: var(--muted);
  font-size: 13.5px;
  padding: 24px 20px;
  background: var(--card);
  border-radius: var(--radius-card);
  margin: 0;
  text-align: center;
}

.library-list {
  list-style: none;
  margin: 0;
  padding: 0;
  background: var(--card);
  border-radius: var(--radius-card);
  overflow: hidden;
  box-shadow: var(--shadow-card);
}

.library-list li {
  padding: 12px 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 13.5px;
  transition: background var(--dur-fast) var(--ease-out);
}
.library-list li:nth-child(even) { background: var(--row-alt); }
.library-list li:hover { background: var(--row-hover); }

.library-list .q {
  color: var(--fg);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.library-list .meta {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}
.library-list li .seg-name {
  font-weight: 600;
  margin-right: 8px;
  color: var(--fg);
}

.pin-btn {
  background: transparent;
  color: var(--muted);
  border: none;
  padding: 0 4px;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
  transition: color var(--dur-fast), transform var(--dur-fast);
  filter: none;
}
.pin-btn.pinned { color: var(--star); }
.pin-btn:hover { color: var(--accent); transform: scale(1.1); }
.pin-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-ring);
  border-radius: 4px;
}

.library-list li .delete-btn {
  background: transparent;
  color: var(--muted);
  border: none;
  padding: 0 6px;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
  transition: color var(--dur-fast);
  filter: none;
}
.library-list li .delete-btn:hover { color: var(--error); }
.library-list li .delete-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-ring);
  border-radius: 4px;
}

/* ── Admin ─────────────────────────────────────────────────────── */

.admin { margin-top: 40px; }
.admin h2 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 600;
  margin: 0 0 12px;
}

.admin-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
}
.admin-tabs button[aria-selected="true"] {
  background: linear-gradient(135deg, var(--accent), var(--accent-container));
  color: #fff;
}

.admin-panel .table-wrapper { max-height: 420px; }
.admin-panel td.err { color: var(--error); font-size: 12px; }

.admin-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 14px;
}
.admin-search {
  flex: 1 1 240px;
  min-width: 200px;
  padding: 9px 14px;
  border: none;
  border-radius: var(--radius-control);
  background: var(--surface-low);
  color: var(--fg);
  font: inherit;
  font-size: 13.5px;
  transition: box-shadow var(--dur-fast) var(--ease-out);
}
.admin-search:focus {
  outline: none;
  box-shadow: 0 0 0 2px var(--accent);
}

.admin-date-filter {
  display: flex;
  gap: 4px;
  padding: 3px;
  background: var(--surface-low);
  border-radius: 999px;
}
.admin-date-filter .pill {
  padding: 5px 14px;
  border-radius: 999px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--dur-fast), color var(--dur-fast);
  filter: none;
}
.admin-date-filter .pill:hover { color: var(--fg); }
.admin-date-filter .pill.is-active {
  background: var(--card);
  color: var(--fg);
  box-shadow: var(--shadow-card);
}

.admin-errors-only {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
  user-select: none;
}
.admin-errors-only input { accent-color: var(--accent); }

.admin-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 12px;
  gap: 10px;
  flex-wrap: wrap;
}
.admin-count {
  color: var(--muted);
  font-size: 12.5px;
}
.admin-pager {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.admin-page-label {
  min-width: 52px;
  text-align: center;
  color: var(--muted);
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
}

/* Card layout (mobile admin) */
.admin-cards {
  list-style: none;
  padding: 0;
  margin: 0;
  display: none;
  flex-direction: column;
  gap: 10px;
}
.admin-card {
  padding: 14px 16px;
  background: var(--card);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.admin-card.has-error { border-left: 3px solid var(--error); }
.admin-card .ac-row1 {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 11.5px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.admin-card .ac-user {
  max-width: 60%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.admin-card .ac-question {
  font-size: 14px;
  color: var(--fg);
  line-height: 1.35;
  word-break: break-word;
}
.admin-card .ac-meta {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  font-size: 12.5px;
  color: var(--fg);
  font-variant-numeric: tabular-nums;
}
.admin-card .ac-label {
  color: var(--muted);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-right: 2px;
}
.admin-card .ac-error {
  font-size: 12px;
  color: var(--error);
  word-break: break-word;
}

@media (max-width: 1024px) {
  .admin-queries-table { display: none; }
  .admin-cards { display: flex; }
}

/* ── Motion ────────────────────────────────────────────────────── */

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes popIn {
  from { opacity: 0; transform: scale(0.96); }
  to   { opacity: 1; transform: scale(1); }
}
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0ms !important;
  }
}

/* ── Responsive: tablet ────────────────────────────────────────── */

@media (max-width: 1024px) {
  main {
    padding: 24px 24px 120px;
  }
  .query-bar {
    padding: 12px 24px 16px;
  }
}

/* ── Responsive: mobile ────────────────────────────────────────── */

@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: -280px;
    top: 0;
    bottom: 0;
    width: 280px;
    transition: left var(--dur-med) var(--ease-out);
    z-index: 20;
    box-shadow: none;
  }
  .sidebar.is-open {
    left: 0;
    box-shadow: var(--shadow-float);
  }
  .sidebar-overlay {
    display: block;
  }
  .sidebar-toggle {
    display: flex;
  }
  .header-title {
    display: block;
  }

  header {
    padding: 12px 16px;
    gap: 10px;
  }

  main {
    padding: 16px 16px 100px;
  }

  .query-bar {
    padding: 10px 16px 14px;
  }
  .query-input-row {
    padding: 4px 4px 4px 16px;
  }
  /* 16px input text prevents iOS zoom-on-focus */
  .query-input-row textarea { font-size: 16px; }

  .welcome h2 { font-size: clamp(24px, 6vw, 32px); }
  .welcome-sub { font-size: 14.5px; }

  .chart-wrapper { height: 240px; padding: 10px; }
  .map-wrapper { height: 340px; }
  .map-layer-picker { padding: 2px; }
  .map-layer-btn { font-size: 10.5px; padding: 4px 8px; }

  .metric-card { padding: 28px 22px; }

  .results-header { flex-wrap: wrap; gap: 6px; }

  .table-wrapper { max-height: 70vh; }
  thead th { padding: 8px 12px; font-size: 10px; }
  tbody td { padding: 8px 12px; max-width: 160px; font-size: 12.5px; }

  .banner, .summary, .error { font-size: 13px; padding: 12px 14px; }

  .library-list li { font-size: 13px; padding: 10px 14px; gap: 8px; flex-wrap: wrap; }
  .library-list .meta { font-size: 11px; }

  /* Touch targets */
  button, button.small, .pin-btn, .delete-btn, .signin-btn {
    min-height: 40px;
  }
  .pin-btn, .delete-btn {
    min-width: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
}
