/* ============================================================
   Keyword Search Tool
   Technical console: neutral charcoal, cyan signal, monospace for
   anything that is data. System fonts only, no downloads, no
   brand signature, native rendering on every platform.
   ============================================================ */

:root {
  --bg: #FFFFFF;
  --bg-raised: #F3F5F7;
  --bg-card: #FFFFFF;
  --bg-inset: #F7F9FA;
  --ink: #10141A;
  --ink-dim: #5A6472;
  --ink-faint: #646E7B;   /* AA on card and inset at 11px: 5.17 / 4.90 */
  --line: #DDE2E8;
  --line-soft: #EBEEF2;
  --accent: #0E7490;          /* cyan-700, passes AA on white */
  --accent-bright: #0891B2;
  --accent-glow: rgba(8, 145, 178, 0.16);
  --flag: #B54708;
  --ok: #15803D;
  --danger: #B42318;
  --radius: 8px;
  --radius-sm: 5px;
  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
             "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", SFMono-Regular, "JetBrains Mono",
               "Cascadia Mono", Menlo, Consolas, monospace;
  --shadow: 0 1px 2px rgba(16, 20, 26, 0.06), 0 8px 24px rgba(16, 20, 26, 0.06);
}

:root[data-theme="dark"] {
  --bg: #0E1116;
  --bg-raised: #151A21;
  --bg-card: #141920;
  --bg-inset: #10151B;
  --ink: #E8EDF3;
  --ink-dim: #98A3B2;
  --ink-faint: #939DAB;   /* AA on card and inset at 11px: 6.43 / 6.68 */
  --line: #232B35;
  --line-soft: #1B222B;
  --accent: #22D3EE;
  --accent-bright: #67E8F9;
  --accent-glow: rgba(34, 211, 238, 0.14);
  --flag: #F79009;
  --ok: #47CD89;
  --danger: #F97066;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 12px 32px rgba(0, 0, 0, 0.36);
}

* { box-sizing: border-box; }
/* The `hidden` attribute only gets display:none from the UA stylesheet, which
   any class rule outranks. Panels are switched with el.hidden, so without this
   a hidden panel that also carries a display rule stays on screen. */
[hidden] { display: none !important; }
html { scrollbar-gutter: stable; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 15.5px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

/* A faint grid behind the page. It reads as instrumentation rather than
   decoration, and at 3% it never competes with text. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background-image: linear-gradient(var(--line) 1px, transparent 1px),
                    linear-gradient(90deg, var(--line) 1px, transparent 1px);
  background-size: 44px 44px;
  opacity: 0.28;
  mask-image: radial-gradient(ellipse 85% 55% at 50% 0%, #000 20%, transparent 78%);
}
:root[data-theme="dark"] body::before { opacity: 0.5; }

h1, h2, h3, h4 { line-height: 1.2; margin: 0 0 0.4em; font-weight: 650; letter-spacing: -0.015em; }
h1 { font-size: clamp(1.6rem, 3vw, 2.1rem); }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
a { color: var(--accent); }

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

/* Micro-labels are mono and tracked out: the console idiom for a field name. */
.eyebrow, .field-label, .term-count, .terms-count, .status, .alts-label,
.term-mentions, .term-cluster, .card-index {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.11em;
  color: var(--ink-faint);
}
.eyebrow { color: var(--accent); margin: 0 0 8px; }
.num, .mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

/* ============================================================ SHELL */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  padding: 10px clamp(14px, 3vw, 32px);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(12px) saturate(140%);
  border-bottom: 1px solid var(--line);
}

.brand {
  font-family: var(--font-mono);
  font-size: 0.88rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  margin: 0;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 8px;
}
/* Status LED. A live indicator is the cheapest signal that a thing is running,
   and here it is honest: everything happens locally, so it is always on. */
.brand::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.brand .brand-dim { color: var(--ink-faint); }

.nav-links { display: flex; gap: 2px; margin-right: auto; }
.nav-link {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-dim);
  background: none;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  min-height: 40px;
  cursor: pointer;
  transition: background 130ms ease, color 130ms ease, border-color 130ms ease;
}
.nav-link:hover { background: var(--bg-raised); color: var(--ink); }
.nav-link[aria-selected="true"] {
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 45%, transparent);
  background: var(--accent-glow);
}

main { padding: clamp(20px, 3.5vw, 34px) clamp(14px, 3vw, 32px) 80px; }
.panel { max-width: 1240px; margin: 0 auto; }
.panel-head { max-width: 72ch; margin-bottom: 24px; }
.lede { color: var(--ink-dim); margin: 0; }

/* ============================================================ CONTROLS */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: var(--font-ui);
  font-weight: 550;
  font-size: 0.92rem;
  padding: 10px 18px;
  min-height: 42px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--bg-card);
  color: var(--ink);
  cursor: pointer;
  transition: border-color 130ms ease, background 130ms ease, box-shadow 130ms ease;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #04161C;
  font-weight: 650;
}
:root:not([data-theme="dark"]) .btn-primary { color: #FFFFFF; }
.btn-primary:hover:not(:disabled) { box-shadow: 0 0 0 4px var(--accent-glow); }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius-sm);
       padding: 2px; background: var(--bg-inset); }
.seg-btn {
  font-family: var(--font-mono);
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-dim);
  background: none;
  border: 0;
  border-radius: 3px;
  padding: 8px 14px;
  min-height: 38px;
  cursor: pointer;
  transition: background 130ms ease, color 130ms ease;
}
.seg-btn:hover { color: var(--ink); }
.seg-btn.is-active { background: var(--accent); color: #04161C; }
:root:not([data-theme="dark"]) .seg-btn.is-active { color: #FFFFFF; }

.field-label { display: block; margin-bottom: 7px; }

input[type="search"], input[type="text"], select, textarea {
  font-family: var(--font-ui);
  font-size: 0.94rem;
  color: var(--ink);
  background: var(--bg-inset);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  min-height: 42px;
  width: 100%;
  transition: border-color 130ms ease, box-shadow 130ms ease;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
  outline: none;
}
textarea { font-family: var(--font-mono); font-size: 0.82rem; min-height: 132px;
           resize: vertical; line-height: 1.7; }
select { cursor: pointer; }

/* The native file input was the one control still wearing the browser's own
   chrome. ::file-selector-button restyles it in place, with no hidden-input
   trick and no JavaScript, so keyboard and screen-reader behaviour stay
   exactly as the platform built them. */
input[type="file"] { font-family: var(--font-mono); font-size: 0.76rem;
                     color: var(--ink-faint); width: 100%; }
input[type="file"]::file-selector-button {
  font-family: var(--font-mono);
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink);
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 9px 14px;
  margin-right: 12px;
  cursor: pointer;
  transition: border-color 130ms ease, color 130ms ease;
}
input[type="file"]::file-selector-button:hover { border-color: var(--accent); color: var(--accent); }

:where(button, a, input, select, textarea, summary):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ============================================================ CARDS */
.card {
  position: relative;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}
/* Corner tick: a one-pixel bracket in the accent, the console's way of saying
   "this is a module" without adding a heading. */
.card::before {
  content: "";
  position: absolute;
  top: -1px; left: -1px;
  width: 14px; height: 14px;
  border-top: 2px solid var(--accent);
  border-left: 2px solid var(--accent);
  border-radius: var(--radius) 0 0 0;
  opacity: 0.55;
}

.card h2 { display: flex; align-items: baseline; gap: 9px; flex-wrap: wrap; }
.card-index { color: var(--accent); }

/* Load state for a card. Idle is a dim outline; loaded lights the accent, the
   same cyan as the header LED and the active controls, so "on" reads the same
   way everywhere. Green stays reserved for a clean scan result. */
.status-chip {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.11em;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--ink-faint);
  background: var(--bg-inset);
  transition: color 160ms ease, border-color 160ms ease, background 160ms ease;
}
.status-chip::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.55;
}
.status-chip[data-state="loaded"] {
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 50%, transparent);
  background: var(--accent-glow);
}
.status-chip[data-state="loaded"]::before {
  opacity: 1;
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.setup-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(270px, 1fr));
  gap: 14px;
  /* stretch, not start: side-by-side cards of different content lengths read as
     a broken row when one stops halfway up the other. */
  align-items: stretch;
}
/* Card 03 used to span the full width under the other two. All three sit in one
   row now, so its controls stack inside their own column instead. */
.card-actions .display-row { flex-direction: column; align-items: stretch; gap: 12px; }
.card-actions .display-group select { min-width: 0; width: 100%; }
.card-actions .seg { width: 100%; }
.card-actions .seg-btn { flex: 1; }

.action-row { display: flex; flex-wrap: wrap; gap: 9px; margin-bottom: 18px; }
.display-row { display: flex; flex-wrap: wrap; gap: 18px; align-items: flex-end; }
.display-group { display: flex; flex-direction: column; gap: 6px; }
.display-group .field-label { margin-bottom: 0; }
.display-group select { min-width: 200px; }

.hint { font-size: 0.84rem; color: var(--ink-dim); margin: 8px 0 0; }

/* ============================================================ RESULTS */
/* Chart on its own full-width row above the findings. Beside them it was a tall
   narrow column with a lot of empty space under it, and the bars had nowhere to
   grow. */
.results-layout { display: flex; flex-direction: column; gap: 16px; margin-top: 20px; }
.chart-card { padding: 16px; order: -1; }
#chart { width: 100%; max-width: 100%; }

/* Readout strip: the run's headline numbers, mono, above the findings. */
.status {
  display: none;
  align-items: center;
  gap: 10px;
  margin: 22px 0 6px;
  padding: 9px 14px;
  background: var(--bg-inset);
  border: 1px solid var(--line);
  border-left: 2px solid var(--accent);
  border-radius: var(--radius-sm);
  color: var(--ink-dim);
  font-size: 0.76rem;
}

.scan-problem, .scan-clean {
  padding: 13px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  border-left: 2px solid var(--line);
  background: var(--bg-card);
  margin-bottom: 14px;
  font-size: 0.92rem;
}
.scan-problem { border-left-color: var(--danger); }
.scan-clean { border-left-color: var(--ok); }

.file-section { margin-bottom: 24px; }
.file-section > h2 {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--ink-dim);
  padding-bottom: 7px;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.summary > ul, .results > ul { list-style: none; margin: 0; padding: 0; }
/* Each flagged term is a card. The previous markup nested three levels of <ul>
   and let indentation carry the meaning. */
.term-hit {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-left: 2px solid var(--flag);
  border-radius: var(--radius-sm);
  padding: 13px 16px;
  margin-bottom: 10px;
  transition: border-color 130ms ease;
}
.term-hit.no-alt { border-left-color: var(--line); }
.term-hit:hover { border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); }
.term-hit-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin: 0 0 4px; }
.term-name { font-family: var(--font-mono); font-weight: 600; font-size: 0.95rem; letter-spacing: -0.01em; }

.sentence {
  font-size: 0.9rem;
  color: var(--ink-dim);
  margin: 7px 0 0;
  padding-left: 11px;
  border-left: 1px solid var(--line);
}
.sentence-doc { display: inline-block; margin-left: 8px; font-family: var(--font-mono);
                font-size: 0.7rem; color: var(--ink-faint); }
.highlight {
  background: color-mix(in srgb, var(--flag) 24%, transparent);
  box-shadow: inset 0 -1px 0 var(--flag);
  border-radius: 2px;
  padding: 0 2px;
  color: var(--ink);
  font-weight: 600;
}
.alts { margin: 9px 0 0; font-size: 0.9rem; }
.alts-label { margin-right: 4px; color: var(--ink-faint); }
.alt { font-family: var(--font-mono); font-size: 0.84rem; color: var(--accent); }
.alts-none { color: var(--ink-faint); font-size: 0.84rem; margin: 9px 0 0; }

/* ============================================================ TERMS TO USE */
.terms-controls {
  display: flex; gap: 14px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 18px;
}
.terms-controls .display-group { min-width: 185px; }
.terms-count { padding-bottom: 12px; }
.terms-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 12px; }
.term-card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-left: 2px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  transition: border-color 130ms ease;
}
.term-card:hover { border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); }
.term-card h3 {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 0.95rem;
  letter-spacing: -0.01em;
  margin: 0 0 8px;
  display: flex; align-items: baseline; gap: 9px; flex-wrap: wrap;
}
.term-cluster {
  background: var(--accent-glow);
  color: var(--accent);
  border-radius: 3px;
  padding: 2px 7px;
  font-size: 0.66rem;
}
.term-mentions { white-space: nowrap; }
.term-why { margin: 0; font-size: 0.9rem; line-height: 1.5; color: var(--ink-dim); }
.terms-note { color: var(--ink-faint); font-size: 0.84rem; max-width: 74ch; margin-top: 24px; }

/* ============================================================ ABOUT */
details.about {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-card);
  padding: 2px 16px;
  margin-bottom: 18px;
}
details.about summary {
  font-family: var(--font-mono);
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--ink-dim);
  cursor: pointer;
  padding: 12px 0;
  min-height: 42px;
  display: flex;
  align-items: center;
}
details.about[open] summary { border-bottom: 1px solid var(--line); margin-bottom: 12px; }
.about-content { font-size: 0.9rem; padding-bottom: 12px; color: var(--ink-dim); }
.about-content h3 { margin-top: 16px; color: var(--ink); }
.about-content ul, .about-content ol { padding-left: 1.25em; }
.about-content li { margin-bottom: 4px; }
.about-content code { font-family: var(--font-mono); font-size: 0.84em;
  background: var(--bg-inset); border: 1px solid var(--line-soft);
  border-radius: 3px; padding: 1px 5px; }

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: 1ms !important; animation-duration: 1ms !important; }
}

/* ============================================================ PRINT
   The report opens in its own window carrying its own stylesheet, so these
   rules are for anyone who prints this page directly. */
@page { margin: 0.5in; }
@media print {
  .topbar, .setup-grid, .status, details.about { display: none !important; }
  body::before { display: none; }
  main { padding: 0; }
  .results-layout { display: block; }
  .chart-card { position: static; page-break-inside: avoid; border: 0; box-shadow: none; padding: 0; }
  .card::before { display: none; }
  #chart { max-width: 3.6in; }
  .term-hit, .term-card { page-break-inside: avoid; }
}
