/* ============================================================
   FedInt dashboard — token-driven, dark-first, dual-theme
   ============================================================ */
:root {
  --teal: #3FD8C8;            /* brand eyebrow / accent */
  --sky: #38B6FF;
  --radius: 10px;
  --maxw: 1100px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* Dark (default) */
:root[data-theme="dark"] {
  --bg: #14161a;
  --surface: #1c2026;
  --surface-2: #232830;
  --border: #333a44;
  --ink: #eef1f5;
  --ink-dim: #aab3c0;
  --field-bg: #1a1e24;
  --accent-text: var(--teal);
  --brand: #3FD8C8;          /* brand accent for fills/borders/pipe/tabs */
  --brand-ink: #07201d;      /* text on a brand-colored fill */
  --rising: #2A9D8F;
  --falling: #6B8CA8;
  --scrubbed: #A85B8E;
  --card-shadow: none;
  --chart-bg: #0e1013;
  color-scheme: dark;
}

/* Light */
:root[data-theme="light"] {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f0f2f6;
  --border: #d7dde5;
  --ink: #1a1f26;
  --ink-dim: #5a6573;
  --field-bg: #f6f8fb;
  --accent-text: #0f7d72;   /* teal fails contrast as text on white; darkened */
  --brand: #138578;          /* darker teal for fills/borders/pipe/tabs on light */
  --brand-ink: #ffffff;      /* text on the darker brand fill */
  --rising: #218079;
  --falling: #4F6E8C;
  --scrubbed: #8E4585;
  --card-shadow: 0 1px 3px rgba(20, 30, 50, 0.08);
  --chart-bg: #ffffff;
  color-scheme: light;
}

* { box-sizing: border-box; }
/* [hidden] must beat class-level display rules (display:flex/grid/block) */
[hidden] { display: none !important; }

body {
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

/* ---------- header ---------- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1em 1.5em;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.brand { display: flex; flex-direction: column; gap: 0.15em; }
.wordmark {
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  display: inline-flex;
  align-items: center;
}
.wordmark .pipe {
  display: inline-block;
  width: 2px;
  height: 1.05em;
  margin: 0 0.18em;
  background: var(--brand);
}
.eyebrow {
  color: var(--accent-text);   /* bright teal on dark, darkened teal on light */
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.header-actions { display: flex; align-items: center; gap: 1em; }
.version { color: var(--ink-dim); font-size: 0.85rem; }

.icon-btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--ink);
  border-radius: 8px;
  width: 40px; height: 40px;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.icon-btn:hover { border-color: var(--brand); }
.icon-sun { display: none; }
.icon-moon { display: block; }
:root[data-theme="dark"] .icon-sun { display: block; }
:root[data-theme="dark"] .icon-moon { display: none; }

/* ---------- tabs ---------- */
.tabs {
  display: flex;
  gap: 0.25em;
  padding: 0 1.5em;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.tab {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--ink-dim);
  font-size: 1rem;
  font-weight: 600;
  padding: 0.85em 1.1em;
  cursor: pointer;
}
.tab:hover { color: var(--ink); }
.tab.is-active { color: var(--ink); border-bottom-color: var(--brand); }

/* ---------- main / panels ---------- */
.app-main { max-width: var(--maxw); margin: 0 auto; padding: 1.5em; }
.panel { display: none; }
.panel.is-active { display: block; }
.panel-intro { color: var(--ink-dim); max-width: 70ch; }
.muted { color: var(--ink-dim); font-weight: 400; }
code {
  background: var(--surface-2);
  padding: 0.1em 0.35em;
  border-radius: 4px;
  font-size: 0.9em;
}

.about { margin: 1em 0; }
.about summary {
  cursor: pointer;
  font-weight: 700;
  padding: 0.6em 0.8em;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.about-body {
  padding: 0.8em;
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 var(--radius) var(--radius);
}
.about-body a, .about-body a:visited { color: var(--accent-text); }

/* ---------- forms ---------- */
.grid-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25em;
  margin-top: 1em;
}
fieldset.controls {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1em;
  box-shadow: var(--card-shadow);
}
fieldset.controls.span-2 { grid-column: span 2; }
legend { font-weight: 700; padding: 0 0.4em; }
.controls label {
  display: block;
  margin: 0.75em 0 0.25em;
  font-size: 0.95rem;
  color: var(--ink-dim);
}
.controls input[type="file"],
.controls select,
.controls textarea,
.controls button {
  width: 100%;
  font-size: 1rem;
  font-family: inherit;
}
.controls input[type="file"] { color: var(--ink); }
.controls textarea, .controls select {
  background: var(--field-bg);
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5em;
}
button {
  background: var(--surface-2);
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6em 0.9em;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}
button:hover { border-color: var(--brand); }
button.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
button.primary:hover { filter: brightness(1.07); }

.button-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.75em;
  margin-bottom: 1em;
}
.display-controls { display: flex; gap: 1.5em; flex-wrap: wrap; align-items: flex-end; }
.dropdown-group { display: flex; flex-direction: column; min-width: 150px; }
.toggle-row { display: flex; align-items: center; gap: 0.5em; }
.chart-label { font-size: 0.9rem; white-space: nowrap; }
.keyword-indicator { margin-top: 0.5em; font-size: 0.9rem; color: var(--ink-dim); }

/* switch */
.switch { position: relative; display: inline-block; width: 46px; height: 24px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; inset: 0;
  background: var(--border);
  border-radius: 24px; cursor: pointer; transition: 0.3s;
}
.slider:before {
  content: ""; position: absolute;
  height: 18px; width: 18px; left: 3px; bottom: 3px;
  background: #fff; border-radius: 50%; transition: 0.3s;
}
.switch input:checked + .slider { background: var(--brand); }
.switch input:checked + .slider:before { transform: translateX(22px); }

/* ---------- scan: compact toolbar ---------- */
.inline-link { color: var(--accent-text); cursor: pointer; }
.toolbar {
  display: flex;
  gap: 1.5em;
  flex-wrap: wrap;
  align-items: flex-end;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1em 1.2em;
  margin-top: 1em;
  box-shadow: var(--card-shadow);
}
.tool-group { display: flex; flex-direction: column; gap: 0.5em; }
.tool-group.tool-actions { flex-direction: row; align-items: flex-end; margin-left: auto; }
.tool-label { font-size: 0.85rem; font-weight: 700; color: var(--ink-dim); text-transform: uppercase; letter-spacing: 0.04em; }
.tool-row { display: flex; align-items: center; gap: 0.6em; }
.file-btn {
  display: inline-block;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5em 0.9em;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.file-btn:hover { border-color: var(--brand); }
.file-btn.primary-file { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.ghost-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5em 0.85em;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
}
.ghost-btn:hover { border-color: var(--brand); }
.toolbar textarea {
  width: 100%;
  min-width: 260px;
  background: var(--field-bg);
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5em;
  font-family: inherit;
  font-size: 0.95rem;
  margin-top: 0.4em;
}
.about-body {
  margin-top: 0.8em;
  padding: 0.9em 1.1em;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.about-body a { color: var(--accent-text); }
.display-controls { margin-top: 1em; }
.scan-empty { margin-top: 1.5em; color: var(--ink-dim); padding: 2em; text-align: center; border: 1px dashed var(--border); border-radius: var(--radius); }

/* ---------- scan: results (sticky chart + output) ---------- */
.scan-results {
  display: grid;
  grid-template-columns: minmax(320px, 440px) 1fr;
  gap: 1.5em;
  margin-top: 1.5em;
  align-items: start;
}
.scan-chart { position: sticky; top: 1em; }
#chart {
  width: 100%;
  background: var(--chart-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.scan-output { min-width: 0; }
#scrollPrompt { font-weight: 700; text-align: center; margin-top: 1em; color: var(--accent-text); }
#output h2 { font-size: 1.25rem; }
#output h3 { font-size: 1.05rem; }
@media (max-width: 820px) {
  .scan-results { grid-template-columns: 1fr; }
  .scan-chart { position: static; }
  .tool-group.tool-actions { margin-left: 0; }
}
.highlight { background: var(--brand); color: var(--brand-ink); font-weight: 700; padding: 0 0.1em; border-radius: 3px; }
.suggested-alternatives { display: block; margin-bottom: 1.5em; }
.file-section, .summary, .results {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1em 1.2em;
  margin-bottom: 1.2em;
  box-shadow: var(--card-shadow);
}

/* ---------- linter ---------- */
.linter-output { margin-top: 1.5em; }
.coverage {
  margin-top: 1.5em;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1em 1.2em;
  box-shadow: var(--card-shadow);
}
.coverage-head { display: flex; justify-content: space-between; align-items: baseline; }
.coverage-count { font-weight: 700; font-size: 1.05rem; }
.coverage-bar { height: 10px; background: var(--surface-2); border-radius: 6px; margin: 0.6em 0; overflow: hidden; }
.coverage-fill { height: 100%; background: var(--brand); width: 0; transition: width 0.4s; }
.coverage-terms { font-size: 0.9rem; color: var(--ink-dim); }
.coverage-terms .used { color: var(--rising); font-weight: 600; }

.lint-hit {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--scrubbed);
  border-radius: var(--radius);
  padding: 0.9em 1.1em;
  margin-bottom: 0.9em;
  box-shadow: var(--card-shadow);
}
.lint-hit-head { display: flex; align-items: baseline; gap: 0.6em; flex-wrap: wrap; }
.lint-term { font-weight: 700; font-size: 1.1rem; }
.lint-count {
  background: var(--surface-2); color: var(--ink-dim);
  border-radius: 12px; padding: 0.1em 0.6em; font-size: 0.85rem; font-weight: 600;
}
.lint-arrow { color: var(--ink-dim); }
.pill {
  display: inline-block;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--accent-text);
  border-radius: 14px;
  padding: 0.2em 0.7em;
  margin: 0.25em 0.3em 0 0;
  font-size: 0.9rem;
  font-weight: 600;
}
.lint-evidence { margin-top: 0.5em; font-style: italic; color: var(--ink-dim); font-size: 0.95rem; }
.lint-clean { color: var(--rising); font-weight: 600; }

/* ---------- intel ---------- */
.section-title { font-size: 1.3rem; margin: 1.8em 0 0.8em; }
.section-title .eyebrow { display: block; margin-bottom: 0.2em; }

.section-desc { color: var(--ink-dim); max-width: 75ch; margin: -0.4em 0 1em; line-height: 1.55; }
.c-rising { color: var(--rising); }
.c-falling { color: var(--falling); }
.c-scrubbed { color: var(--scrubbed); }
.cluster-card h3 { display: flex; align-items: center; gap: 0.45em; }
.cluster-dot { display: inline-block; width: 11px; height: 11px; border-radius: 50%; flex: none; }

/* ---- interactive momentum explorer ---- */
.explorer { margin-bottom: 1em; }
.explorer-controls {
  display: flex; flex-wrap: wrap; gap: 1em; align-items: flex-end;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1em 1.2em; margin-bottom: 1em;
  box-shadow: var(--card-shadow);
}
.ctrl { display: flex; flex-direction: column; gap: 0.3em; }
.ctrl label { font-size: 0.8rem; font-weight: 700; color: var(--ink-dim); text-transform: uppercase; letter-spacing: 0.04em; }
.ctrl select, .ctrl input[type="text"] {
  background: var(--field-bg); color: var(--ink); border: 1px solid var(--border);
  border-radius: 8px; padding: 0.45em 0.6em; font-size: 0.95rem; font-family: inherit;
}
.ctrl-grow { flex: 1; min-width: 160px; }
.ctrl-grow input { width: 100%; }
.ctrl-actions { flex-direction: row; gap: 0.4em; }
.ghost-btn.sm { padding: 0.45em 0.7em; font-size: 0.9rem; }

.explorer-grid { display: grid; grid-template-columns: 1.4fr 1fr; gap: 1em; align-items: start; }
.explorer-chart { min-height: 360px; }
.explorer-chart canvas { height: 340px !important; }

/* Compare mode: window B picker + side-by-side charts */
.compare-bar { display: flex; align-items: center; flex-wrap: wrap; gap: 0.5em 0.75em; margin: 0 0 0.9em; }
.cmp-label { font-size: 0.88rem; color: var(--ink-dim); }
.cmp-presets { display: flex; flex-wrap: wrap; gap: 0.4em; }
.cmp-charts { display: grid; grid-template-columns: 1fr; gap: 1em; }
.cmp-charts.is-compare { grid-template-columns: 1fr 1fr; }
.cmp-charts.is-compare canvas { height: 300px !important; }
@media (max-width: 1100px) { .cmp-charts.is-compare { grid-template-columns: 1fr; } }
.cmp-row { display: flex; align-items: flex-end; flex-wrap: wrap; gap: 0.5em 0.75em; }
.cmp-legend { display: flex; flex-wrap: wrap; gap: 0.35em 1em; margin-top: 0.8em; justify-content: center; }
.cmp-leg-item { display: inline-flex; align-items: center; gap: 0.4em; font-size: 0.82rem; color: var(--ink-dim); }
.cmp-leg-swatch { width: 16px; height: 3px; border-radius: 2px; display: inline-block; }

/* Intel section sub-nav (sticky quick-jump) */
.section-nav {
  position: sticky; top: 0; z-index: 5;
  display: flex; flex-wrap: wrap; gap: 0.4em;
  padding: 0.7em 0; margin-bottom: 0.6em;
  background: var(--bg); border-bottom: 1px solid var(--border);
}
.sec-link {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 999px; padding: 0.4em 0.9em;
  font-size: 0.8rem; font-weight: 700; color: var(--ink-dim); cursor: pointer;
  text-transform: uppercase; letter-spacing: 0.05em;
  transition: color 0.12s, border-color 0.12s;
}
.sec-link:hover, .sec-link:focus-visible { color: var(--ink); border-color: var(--brand); }
/* Offset jump targets so the sticky bar doesn't cover the heading. */
.section-title[id] { scroll-margin-top: 70px; }
.explorer-table {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: auto; max-height: 400px; box-shadow: var(--card-shadow);
}
#exTable { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
#exTable thead th {
  position: sticky; top: 0; background: var(--surface-2); color: var(--ink-dim);
  text-align: left; padding: 0.55em 0.7em; font-size: 0.78rem; text-transform: uppercase;
  letter-spacing: 0.04em; border-bottom: 1px solid var(--border); user-select: none;
}
#exTable th.num, #exTable td.num { text-align: right; }
#exTable td { padding: 0.45em 0.7em; border-bottom: 1px solid var(--border); }
#exTable tr.picked { background: color-mix(in srgb, var(--brand) 10%, transparent); }
#exTable td.up { color: var(--rising); font-weight: 700; }
#exTable td.down { color: var(--scrubbed); font-weight: 700; }
.col-pick { white-space: nowrap; }
.col-pick .dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 0.4em; vertical-align: middle; border: 1px solid var(--border); }
.tag { font-size: 0.68rem; padding: 0.05em 0.4em; border-radius: 6px; text-transform: uppercase; letter-spacing: 0.03em; font-weight: 700; }
.tag.rising { background: color-mix(in srgb, var(--rising) 20%, transparent); color: var(--rising); }
.tag.falling { background: color-mix(in srgb, var(--scrubbed) 20%, transparent); color: var(--scrubbed); }
@media (max-width: 820px) { .explorer-grid { grid-template-columns: 1fr; } }

.intel-charts { display: grid; grid-template-columns: 1fr 1fr; gap: 1em; }
.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1em 1.2em;
  box-shadow: var(--card-shadow);
}
.chart-card-wide { margin-bottom: 1em; }
.chart-title { margin: 0 0 0.7em; font-size: 1rem; color: var(--ink-dim); }
.chart-note { margin: 0.6em 0 0; font-size: 0.85rem; color: var(--ink-dim); font-style: italic; }
/* maintainAspectRatio:false fills the parent — constrain it or the canvas grows unbounded. */
.chart-card canvas { width: 100% !important; height: 260px !important; }
.chart-card-wide canvas { height: 300px !important; }
@media (max-width: 820px) { .intel-charts { grid-template-columns: 1fr; } }

.era-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1em; }
.era-col {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1em;
  box-shadow: var(--card-shadow);
}
.era-col h3 { margin: 0 0 0.5em; font-size: 1.05rem; }
.era-col.rising h3 { color: var(--rising); }
.era-col.falling h3 { color: var(--falling); }
.era-col.scrubbed h3 { color: var(--scrubbed); }
.era-col ul { margin: 0; padding-left: 1.2em; }
.era-col li { margin: 0.2em 0; }

.cluster-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1em; }
.cluster-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1em;
  box-shadow: var(--card-shadow);
}
.cluster-card h3 { margin: 0 0 0.3em; font-size: 1.05rem; }
.cluster-note { color: var(--ink-dim); font-size: 0.9rem; margin: 0 0 0.6em; }

.favored-table {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--card-shadow);
}
.favored-table table { width: 100%; border-collapse: collapse; }
.favored-table th, .favored-table td {
  text-align: left; padding: 0.7em 1em; border-bottom: 1px solid var(--border); vertical-align: top;
}
.favored-table th { background: var(--surface-2); font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--ink-dim); }
.favored-table tr:last-child td { border-bottom: none; }
.favored-table .term { font-weight: 700; color: var(--accent-text); }
.favored-table .agencies { color: var(--ink-dim); font-size: 0.9rem; }

.briefs { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 1em; }
.brief-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1em 1.2em;
  box-shadow: var(--card-shadow);
}
.brief-card h3 { margin: 0 0 0.3em; }
.brief-framing { color: var(--ink-dim); font-style: italic; margin: 0 0 0.6em; }
.brief-card .label { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; font-weight: 700; }
.brief-card .label.rising { color: var(--rising); }
.brief-card .label.falling { color: var(--falling); }

/* ---------- responsive ---------- */
@media (max-width: 820px) {
  .grid-form { grid-template-columns: 1fr; }
  fieldset.controls.span-2 { grid-column: span 1; }
  .era-grid { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* ---- suggested swaps ---- */
.swap-table { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--card-shadow); margin-bottom: 1em; }
.swap-table table { width: 100%; border-collapse: collapse; }
.swap-table th, .swap-table td { text-align: left; padding: 0.7em 1em; border-bottom: 1px solid var(--border); vertical-align: top; }
.swap-table th { background: var(--surface-2); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--ink-dim); }
.swap-table tr:last-child td { border-bottom: none; }
.swap-table .swap-down { font-weight: 700; color: var(--scrubbed); white-space: nowrap; }
