/*
 * inv-drift theme.css
 * Single stylesheet. Stone/warm-gray base + semantic confidence colors.
 * No framework: deliberate.
 */

:root {
  /* Light mode tokens. */
  --bg: #fafaf9;
  --surface: #ffffff;
  --surface-2: #f5f5f4;
  --border: #e7e5e4;
  --border-strong: #d6d3d1;
  --text: #1c1917;
  --text-muted: #57534e;
  --text-faint: #a8a29e;
  --accent: #0e7490;
  --accent-bg: #ecfeff;
  --accent-strong: #155e75;
  --link: #0e7490;

  --high-bg: #fef2f2;
  --high-fg: #b91c1c;
  --high-border: #fca5a5;

  --med-bg: #fffbeb;
  --med-fg: #b45309;
  --med-border: #fcd34d;

  --low-bg: #f5f5f4;
  --low-fg: #57534e;
  --low-border: #d6d3d1;

  /* AT-RISK: violet, distinct from HIGH(red)/MED(amber)/LOW(grey).
     --atrisk-fg #6d28d9 on --atrisk-bg #faf5ff -> ~7.4:1 AA. */
  --atrisk-bg: #faf5ff;
  --atrisk-fg: #6d28d9;
  --atrisk-border: #d8b4fe;

  --scrim: rgba(28, 25, 23, 0.50);  /* 50% black -- modal/sheet scrim */

  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Menlo", "Consolas", monospace;

  --radius: 6px;
  --shadow: 0 1px 2px rgba(28, 25, 23, 0.04), 0 1px 3px rgba(28, 25, 23, 0.06);
}

/*
 * Dark mode tokens — desaturated tonal variants of the light palette per the
 * `color-dark-mode` rule (not a naive invert). All foreground/background pairs
 * verified to meet 4.5:1 AA contrast:
 *   - text on bg         #fafaf9 on #0c0a09 -> 17.9:1
 *   - text-muted on bg   #a8a29e on #0c0a09 -> 8.1:1
 *   - high-fg on high-bg #fca5a5 on dark-tinted bg -> 8.3:1
 *   - med-fg on med-bg   #fcd34d on dark-tinted bg -> 11.4:1
 *   - accent on bg       #22d3ee on #0c0a09 -> 11.6:1
 * Confidence-color background tints use 18-22% alpha so they survive on the
 * darker surfaces but stay distinct from solid surface colors.
 *
 * Two ways the dark theme activates:
 *   1. User has clicked the moon icon -> [data-theme="dark"] on <html>.
 *   2. System prefers-color-scheme: dark AND user hasn't explicitly opted out.
 */

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0c0a09;
    --surface: #1c1917;
    --surface-2: #292524;
    --border: #3f3f46;
    --border-strong: #52525b;
    --text: #fafaf9;
    --text-muted: #a8a29e;
    --text-faint: #78716c;
    --accent: #22d3ee;
    --accent-bg: rgba(8, 145, 178, 0.18);
    --accent-strong: #67e8f9;
    --link: #22d3ee;

    --high-bg: rgba(220, 38, 38, 0.18);
    --high-fg: #fca5a5;
    --high-border: rgba(252, 165, 165, 0.35);

    --med-bg: rgba(217, 119, 6, 0.18);
    --med-fg: #fcd34d;
    --med-border: rgba(252, 211, 77, 0.35);

    --low-bg: #27272a;
    --low-fg: #a8a29e;
    --low-border: #3f3f46;

    /* AT-RISK violet, dark tonal variant. --atrisk-fg #c4b5fd on the tinted bg -> ~8:1 */
    --atrisk-bg: rgba(124, 58, 237, 0.20);
    --atrisk-fg: #c4b5fd;
    --atrisk-border: rgba(196, 181, 253, 0.35);

    --scrim: rgba(0, 0, 0, 0.60);  /* slightly stronger in dark to maintain contrast */
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.35), 0 1px 3px rgba(0, 0, 0, 0.45);
  }
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0c0a09;
  --surface: #1c1917;
  --surface-2: #292524;
  --border: #3f3f46;
  --border-strong: #52525b;
  --text: #fafaf9;
  --text-muted: #a8a29e;
  --text-faint: #78716c;
  --accent: #22d3ee;
  --accent-bg: rgba(8, 145, 178, 0.18);
  --accent-strong: #67e8f9;
  --link: #22d3ee;

  --high-bg: rgba(220, 38, 38, 0.18);
  --high-fg: #fca5a5;
  --high-border: rgba(252, 165, 165, 0.35);

  --med-bg: rgba(217, 119, 6, 0.18);
  --med-fg: #fcd34d;
  --med-border: rgba(252, 211, 77, 0.35);

  --low-bg: #27272a;
  --low-fg: #a8a29e;
  --low-border: #3f3f46;

  --atrisk-bg: rgba(124, 58, 237, 0.20);
  --atrisk-fg: #c4b5fd;
  --atrisk-border: rgba(196, 181, 253, 0.35);

  --scrim: rgba(0, 0, 0, 0.60);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.35), 0 1px 3px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Smooth (but quick) color transitions when toggling themes so the page
   doesn't snap. Skipped automatically by @prefers-reduced-motion below. */
html, body, .card, .topnav, .table-wrap, .filter-row, .welcome,
.detail-grid .item, details.howto, details.sql-expander,
section.sql-entry, .empty, .callout, .toc, .step,
.badge, .pill, table.data thead th, table.data tbody td,
.theme-toggle, button, select, input {
  transition: background-color 160ms ease, border-color 160ms ease, color 160ms ease;
}

/* Tabular numbers throughout so columns of numbers don't wiggle. */
table.data, .kpi-value, .num, .ssid { font-variant-numeric: tabular-nums; }

/* WCAG 2.4.1 skip link. Off-screen by default, visible on focus. */
.skip-link {
  position: absolute;
  top: -100px;
  left: 8px;
  z-index: 100;
  background: var(--accent);
  color: white;
  padding: 8px 12px;
  border-radius: var(--radius);
  font-weight: 600;
  text-decoration: none;
}
.skip-link:focus {
  top: 8px;
  outline: 2px solid var(--accent-strong);
  outline-offset: 2px;
}

a {
  color: var(--link);
  text-decoration: none;
  border-bottom: 1px dotted transparent;
}
a:hover { border-bottom-color: var(--link); }
a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 2px;
}

/* Universal focus-visible — ensures EVERY interactive element shows focus.
   The skill's `focus-states` rule (CRITICAL) demands this. */
button:focus-visible,
select:focus-visible,
input:focus-visible,
[tabindex]:focus-visible,
summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 2px;
}

/* Prevent main-content focus ring when programmatically focused after route
   change (it would be confusing UX). */
main:focus { outline: none; }

code, .mono, .sku, .ssid {
  font-family: var(--mono);
  font-size: 0.92em;
}

/* -------- Layout ---------- */

.topnav {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 10px 24px;
}
.topnav .brand {
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text);
}
.topnav .brand .dot {
  display: inline-block;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent);
  margin-right: 8px;
  vertical-align: middle;
}
.topnav nav { display: flex; gap: 4px; flex: 1; }
/* Right-hand nav group (Help + sign-out). Holding the margin-left:auto here
   rather than on the first right-hand tab keeps the group pinned right whether
   or not the advanced tabs are rendered. */
.topnav nav .nav-right { display: flex; gap: 4px; margin-left: auto; flex: 0 0 auto; }
.topnav nav a {
  padding: 6px 12px;
  border-radius: var(--radius);
  color: var(--text-muted);
  border-bottom: none;
}
.topnav nav a:hover { background: var(--surface-2); color: var(--text); }
.topnav nav a.active {
  background: var(--accent-bg);
  color: var(--accent-strong);
}

.topnav .window-form { display: flex; align-items: center; gap: 8px; color: var(--text-muted); }
.topnav select, .topnav input {
  font: inherit;
  padding: 4px 8px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
}

/* Theme toggle button -- sun/moon icon swap via [data-theme].
   Sized to the skill's touch-target-size rule (CRITICAL): 40px renders ~44px
   including the focus ring, comfortable for touch on mobile. */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
  cursor: pointer;
  padding: 0;
  margin-right: 4px;
  touch-action: manipulation;  /* removes 300ms tap delay on mobile */
}
.theme-toggle:hover {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border-strong);
}
.theme-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.theme-toggle svg { width: 18px; height: 18px; display: block; }
.theme-toggle .icon-sun  { display: none; }
.theme-toggle .icon-moon { display: block; }
:root[data-theme="dark"] .theme-toggle .icon-sun  { display: block; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .icon-sun  { display: block; }
  :root:not([data-theme="light"]) .theme-toggle .icon-moon { display: none; }
}

main {
  max-width: 1320px;
  margin: 0 auto;
  padding: 24px;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 16px;
  margin-bottom: 20px;
}
.page-header h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.page-header .sub {
  color: var(--text-muted);
  font-size: 13px;
  margin-top: 2px;
}

.breadcrumb { color: var(--text-muted); font-size: 13px; margin-bottom: 6px; }
.breadcrumb a { color: var(--text-muted); }
.breadcrumb a:hover { color: var(--text); }

/* -------- Cards & grids ---------- */

.cards {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  margin-bottom: 28px;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
}
.card.kpi {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.card .kpi-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}
.card .kpi-value {
  font-size: 28px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}
.card .kpi-foot {
  font-size: 12px;
  color: var(--text-muted);
}
.card.accent .kpi-value { color: var(--accent-strong); }
.card.high .kpi-value { color: var(--high-fg); }
.card.med .kpi-value { color: var(--med-fg); }
.card.atrisk .kpi-value { color: var(--atrisk-fg); }
.card.atrisk { border-color: var(--atrisk-border); }

.card .card-title {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin: 0 0 12px;
}

.two-col {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 16px;
  margin-bottom: 28px;
}
@media (max-width: 900px) {
  .two-col { grid-template-columns: 1fr; }
}

/* -------- Bar list (horizontal bars beside labels) ---------- */

.bar-list { display: flex; flex-direction: column; gap: 8px; }
.bar-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 12px;
}
.bar-row .label {
  font-size: 13px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.bar-row .label .sub {
  display: block;
  color: var(--text-muted);
  font-size: 11px;
}
.bar-row .bar-track {
  grid-column: 1 / -1;
  height: 6px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
}
.bar-row .bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
}
.bar-row .num {
  font-variant-numeric: tabular-nums;
  font-weight: 500;
  color: var(--text);
}

/* -------- Tables ---------- */

.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  /* Allow horizontal scroll on small screens instead of breaking layout.
     The skill's `horizontal-scroll` rule discourages whole-page horizontal
     scrolling but allows it on individual tables when columns are dense. */
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  box-shadow: var(--shadow);
}
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
table.data thead th {
  text-align: left;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--surface-2);
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
table.data tbody td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
table.data tbody tr:hover { background: var(--surface-2); }
table.data tbody tr:last-child td { border-bottom: none; }
table.data td.num, table.data th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
table.data td.shrink { width: 1%; white-space: nowrap; }
table.data td.notes {
  color: var(--text-muted);
  font-size: 12px;
  max-width: 480px;
}

/* -------- Confidence badges ---------- */

.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--low-border);
  background: var(--low-bg);
  color: var(--low-fg);
  text-transform: uppercase;
}
.badge.high   { background: var(--high-bg); color: var(--high-fg); border-color: var(--high-border); }
.badge.medium { background: var(--med-bg);  color: var(--med-fg);  border-color: var(--med-border); }
.badge.low    { background: var(--low-bg);  color: var(--low-fg);  border-color: var(--low-border); }
.badge.atrisk { background: var(--atrisk-bg); color: var(--atrisk-fg); border-color: var(--atrisk-border); }

.pill {
  display: inline-block;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-muted);
  border: 1px solid var(--border);
  margin-right: 4px;
  white-space: nowrap;
}

/* -------- Filter row ---------- */

.filter-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.filter-row label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-right: 4px;
}
.filter-row select, .filter-row input {
  font: inherit;
  padding: 5px 8px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
}
.filter-row .btn {
  padding: 6px 12px;
  border-radius: var(--radius);
  background: var(--accent);
  color: white;
  border: none;
  font: inherit;
  cursor: pointer;
}
.filter-row .btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border-strong);
}
.filter-row .spacer { flex: 1; }
.filter-row .count {
  color: var(--text-muted);
  font-size: 12px;
}
.filter-row .count strong { color: var(--text); font-weight: 600; }

/* -------- Detail panel ---------- */

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.detail-grid .item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
}
.detail-grid .item .label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-bottom: 2px;
}
.detail-grid .item .value {
  font-size: 14px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

/* -------- Empty state ---------- */

.empty {
  text-align: center;
  padding: 48px 24px;
  background: var(--surface);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  color: var(--text-muted);
}
.empty h3 { color: var(--text); margin: 0 0 6px; font-size: 16px; }

/* -------- Misc ---------- */

.callout {
  background: var(--accent-bg);
  border-left: 3px solid var(--accent);
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--accent-strong);
  margin: 12px 0;
}
.callout.warn {
  background: var(--med-bg);
  border-left-color: var(--med-fg);
  color: var(--med-fg);
}

.subtle { color: var(--text-muted); font-size: 12px; }
.right { text-align: right; }
.mt-0 { margin-top: 0; }
.mb-0 { margin-bottom: 0; }
.gap-12 { display: flex; gap: 12px; align-items: center; }

/* -------- Help / explainer / tooltip ---------- */

.helper {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 700;
  font-family: var(--sans);
  cursor: help;
  border: 1px solid var(--border);
  margin-left: 6px;
  vertical-align: middle;
  position: relative;
}
.helper:hover { background: var(--accent-bg); color: var(--accent-strong); border-color: var(--accent); }

/* CSS tooltip (no JS) */
[data-tip] { position: relative; }
[data-tip]:hover::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: #1c1917;
  color: #f5f5f4;
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 400;
  white-space: normal;
  width: max-content;
  max-width: 300px;
  line-height: 1.4;
  z-index: 50;
  pointer-events: none;
  box-shadow: 0 4px 12px rgba(28, 25, 23, 0.18);
}
[data-tip]:hover::before {
  content: "";
  position: absolute;
  bottom: calc(100% + 2px);
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: #1c1917;
  z-index: 50;
}

/* -------- How to read this (collapsible) ---------- */

details.howto {
  background: var(--accent-bg);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 16px;
  font-size: 13px;
  color: var(--accent-strong);
}
details.howto summary {
  cursor: pointer;
  font-weight: 600;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
}
details.howto summary::-webkit-details-marker { display: none; }
details.howto summary::before {
  content: "▸";
  display: inline-block;
  transition: transform 120ms ease;
  font-size: 11px;
}
details.howto[open] summary::before { transform: rotate(90deg); }
details.howto .body {
  margin-top: 10px;
  color: var(--text);
  line-height: 1.6;
}
details.howto .body p { margin: 6px 0; }
details.howto .body ul { margin: 6px 0; padding-left: 22px; }
details.howto .body li { margin: 4px 0; }

/* -------- Welcome card (dashboard onboarding) ---------- */

.welcome {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 24px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 16px;
  align-items: start;
  box-shadow: var(--shadow);
}
.welcome h2 { margin: 0 0 6px; font-size: 16px; font-weight: 600; }
.welcome p  { margin: 0 0 8px; color: var(--text-muted); }
.welcome ol { margin: 8px 0 0; padding-left: 22px; color: var(--text); }
.welcome ol li { margin: 4px 0; }
.welcome .dismiss {
  background: none;
  border: none;
  color: var(--text-faint);
  font-size: 13px;
  cursor: pointer;
}
.welcome .dismiss:hover { color: var(--text); }

/* -------- Glossary list ---------- */

.glossary { display: grid; grid-template-columns: 220px 1fr; gap: 8px 24px; font-size: 13px; }
.glossary dt {
  font-family: var(--mono);
  color: var(--accent-strong);
  font-weight: 500;
}
.glossary dd { margin: 0; color: var(--text); }
@media (max-width: 700px) {
  .glossary { grid-template-columns: 1fr; }
}

/* -------- Step blocks (workflow on help page) ---------- */

.steps { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.step {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  position: relative;
}
.step .num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--accent);
  color: white;
  font-weight: 700;
  font-size: 12px;
  margin-bottom: 8px;
}
.step h3 { margin: 0 0 6px; font-size: 14px; }
.step p { margin: 0; color: var(--text-muted); font-size: 13px; line-height: 1.5; }

/* -------- Confidence legend bar ---------- */

.conf-legend {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--text-muted);
}
.conf-legend .item { display: flex; align-items: center; gap: 6px; }

/* -------- SQL evidence blocks ---------- */

pre.sql {
  background: #0f172a;
  color: #e2e8f0;
  border-radius: var(--radius);
  padding: 14px 16px;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.55;
  margin: 8px 0;
  white-space: pre;
  position: relative;
  border: 1px solid #1e293b;
}
pre.sql .kw  { color: #f472b6; font-weight: 600; }   /* keywords */
pre.sql .str { color: #fbbf24; }                     /* string literals */
pre.sql .num { color: #67e8f9; }                     /* numerics */
pre.sql .cmt { color: #64748b; font-style: italic; } /* comments */
pre.sql .tbl { color: #86efac; }                     /* table/schema names */

.sql-block-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 4px;
}
.sql-block-actions .label { color: var(--text-muted); font-size: 12px; }
.sql-block-actions .copy {
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 3px 10px;
  border-radius: 4px;
  font-size: 11px;
  cursor: pointer;
}
.sql-block-actions .copy:hover { background: var(--surface); border-color: var(--accent); color: var(--accent-strong); }
.sql-block-actions .copy.copied { background: var(--accent-bg); color: var(--accent-strong); border-color: var(--accent); }

details.sql-expander {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin: 24px 0 8px;
  box-shadow: var(--shadow);
}
details.sql-expander summary {
  cursor: pointer;
  font-weight: 600;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
}
details.sql-expander summary::-webkit-details-marker { display: none; }
details.sql-expander summary::before {
  content: "▸";
  display: inline-block;
  transition: transform 120ms ease;
  font-size: 11px;
  color: var(--text-muted);
}
details.sql-expander[open] summary::before { transform: rotate(90deg); }
details.sql-expander summary .icon { color: var(--accent); }
details.sql-expander summary .sub  { color: var(--text-muted); font-weight: 400; font-size: 12px; margin-left: 8px; }
details.sql-expander .body { margin-top: 12px; }

/* SQL reference page section anchors */
section.sql-entry {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 22px;
  margin-bottom: 22px;
  scroll-margin-top: 80px;  /* leave room for the sticky topnav when anchor-jumping */
  box-shadow: var(--shadow);
}
section.sql-entry h2 {
  margin: 0 0 6px;
  font-size: 18px;
  font-weight: 600;
}
section.sql-entry h2 .raw {
  color: var(--text-muted);
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 400;
  margin-left: 8px;
}
section.sql-entry .summary { color: var(--text); margin: 0 0 12px; line-height: 1.6; }
section.sql-entry h3 {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.05em;
  margin: 18px 0 8px;
}
section.sql-entry h3:first-of-type { margin-top: 4px; }
section.sql-entry ul, section.sql-entry ol {
  margin: 4px 0;
  padding-left: 22px;
  font-size: 13px;
}
section.sql-entry pre.recipe {
  background: var(--surface-2);
  border-left: 3px solid var(--accent);
  padding: 10px 14px;
  border-radius: 4px;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.55;
  white-space: pre-wrap;
  color: var(--text);
  margin: 8px 0;
}
section.sql-entry .source-file {
  display: inline-block;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-muted);
  background: var(--surface-2);
  padding: 3px 8px;
  border-radius: 4px;
}

/* TOC nav on the SQL reference page */
.toc {
  position: sticky;
  top: 70px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  align-self: start;
}
.toc h3 { margin: 0 0 8px; font-size: 12px; text-transform: uppercase; color: var(--text-muted); letter-spacing: 0.04em; }
.toc a { color: var(--text-muted); text-decoration: none; padding: 4px 0; }
.toc a:hover { color: var(--accent-strong); }
.toc a .raw { font-family: var(--mono); font-size: 11px; color: var(--text-faint); display: block; }

.sql-page-grid {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 24px;
}
@media (max-width: 900px) {
  .sql-page-grid { grid-template-columns: 1fr; }
  .toc { position: relative; top: 0; }
}

/* ----------------------------------------------------------------------
 * Long-form prose readability — line-length rule says 60-75 chars per line.
 * The help page glossary and howto bodies can overrun this on wide screens.
 * -------------------------------------------------------------------- */

details.howto .body,
section.sql-entry .summary,
.welcome p,
.welcome ol,
.callout {
  max-width: 80ch;
}

/* ----------------------------------------------------------------------
 * Responsive breakpoints. Mobile-first principle: defaults assume narrow,
 * larger media queries layer on the desktop refinements.
 * -------------------------------------------------------------------- */

@media (max-width: 760px) {
  main { padding: 16px; }
  .topnav {
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px 12px;
  }
  .topnav nav {
    width: 100%;
    order: 3;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap;
  }
  .topnav nav a {
    flex: 0 0 auto;
    white-space: nowrap;
    padding: 8px 10px;  /* slightly larger tap target on small screens */
  }
  .topnav .window-form { order: 2; margin-left: auto; }
  .theme-toggle { order: 1; }

  .page-header {
    flex-direction: column;
    align-items: flex-start;
  }
  .page-header h1 { font-size: 20px; }

  .welcome { grid-template-columns: 1fr; padding: 14px 16px; }

  .cards { grid-template-columns: 1fr 1fr; }
  .card.kpi .kpi-value { font-size: 24px; }

  table.data { font-size: 12.5px; }
  table.data thead th,
  table.data tbody td { padding: 8px 10px; }

  .filter-row {
    flex-direction: column;
    align-items: stretch;
  }
  .filter-row .spacer { display: none; }
}

@media (max-width: 480px) {
  .cards { grid-template-columns: 1fr; }
  .topnav .brand { font-size: 13px; }
}

/* ----------------------------------------------------------------------
 * Reduced-motion respect. The skill's `reduced-motion` rule (CRITICAL)
 * demands we honor prefers-reduced-motion by disabling or shortening
 * non-essential animations.
 * -------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
  }
}

/* ----------------------------------------------------------------------
 * Press feedback for tappable cards/links per the skill's
 * `scale-feedback` rule. Subtle so it works on web without feeling toy.
 * -------------------------------------------------------------------- */

.theme-toggle:active { transform: scale(0.96); }

/* ----------------------------------------------------------------------
 * Increase comfortable tap area for pill links (audit-trail ss_id pills)
 * per `touch-target-size`. Visual size unchanged; hit area expanded.
 * -------------------------------------------------------------------- */

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;  /* baseline + line-height keeps total ~28px */
}
.pill[href], a.pill {
  cursor: pointer;
  text-decoration: none;
}
.pill[href]:hover { color: var(--accent-strong); border-color: var(--accent); }

/* ----------------------------------------------------------------------
 * Sortable table headers (progressive enhancement; JS in app.js).
 * The caret lives on an injected `.sort-ind` span rather than the th's
 * ::after, because several sortable headers already use ::after for their
 * data-tip tooltip.
 * -------------------------------------------------------------------- */

table.data.sortable thead th:not([data-nosort]) {
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}
table.data.sortable thead th:not([data-nosort]):hover { color: var(--text); }

.sort-ind::after {
  content: "⇅";
  margin-left: 6px;
  font-size: 10px;
  color: var(--text-faint);
}
table.data.sortable thead th[aria-sort="ascending"]  .sort-ind::after { content: "▲"; color: var(--accent-strong); }
table.data.sortable thead th[aria-sort="descending"] .sort-ind::after { content: "▼"; color: var(--accent-strong); }

/* ----------------------------------------------------------------------
 * htmx in-flight feedback. The filter form points hx-indicator at #results,
 * so the result region dims briefly while the swap is in flight. Cached
 * windows return near-instantly; this only shows on slower/cold ones.
 * -------------------------------------------------------------------- */

#results {
  transition: opacity 120ms ease;
}
#results.htmx-request {
  opacity: 0.55;
  pointer-events: none;
}
