/* gscindex Terminal (Draft E: docs/superpowers/specs/terminal-draft/e-terminal.html).
   One continuous grid of panes separated by 1px rules. Square corners, no shadows.
   Mono (JetBrains Mono) for numbers, labels, tables and chrome; Inter for headlines and prose.
   Phone rules live in the "phones" section (Task 6). */

:root {
  --bg: #000000;
  --cell: #07090C;
  --grid: #1D232B;
  --text: #F2F4F7;
  --dim: #8A94A3;
  --amber: #FFB020;
  --healthy: #35D07F;
  --stable: #F5C542;
  --stressed: #FF8A3D;
  --critical: #FF4D5E;
  --hover: #0D1117;
  --track: #141A21;
  --prose: #D6DBE3;
  --mono: "JetBrains Mono", ui-monospace, Menlo, monospace;
  --sans: "Inter", system-ui, -apple-system, sans-serif;

  /* Bootstrap 5 (modal, popover, tooltip, select) in Terminal colors */
  --bs-body-bg: var(--bg);
  --bs-body-color: var(--text);
  --bs-body-font-family: var(--mono);
  --bs-body-font-size: 13px;
  --bs-border-color: var(--grid);
  --bs-border-radius: 0;
  --bs-link-color: inherit;
  --bs-link-hover-color: var(--text);
}

* { box-sizing: border-box; }
html, body { background: var(--bg); }
body {
  margin: 0;
  color: var(--text);
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
button { font: inherit; color: inherit; }
.sans { font-family: var(--sans); }
.num { font-variant-numeric: tabular-nums; }
.neg { color: var(--critical); }
.pos { color: var(--healthy); }
.dim { color: var(--dim); }
:focus-visible { outline: 1px solid var(--amber); outline-offset: 2px; }

/* ── Grid ─────────────────────────────────────────────────────────── */
.shell {
  display: grid;
  /* Side columns grow with the screen (about a quarter each on wide displays). */
  grid-template-columns: minmax(300px, 24%) minmax(0, 1fr) minmax(300px, 24%);
  grid-auto-rows: auto;
  gap: 1px;
  background: var(--grid);
  border-bottom: 1px solid var(--grid);
  min-height: 100vh;
  align-content: start;
}
.pane { background: var(--cell); padding: 14px 16px; min-width: 0; }
.wide { grid-column: 1 / 3; }
.full { grid-column: 1 / -1; }

.ttl {
  color: var(--amber);
  font-size: 12px;
  margin: 0 0 10px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
}
.ttl > span:last-child { color: var(--dim); }

/* ── Header ───────────────────────────────────────────────────────── */
.head {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 22px;
  padding: 0 16px;
  height: 44px;
  background: var(--bg);
}
.brand { font-weight: 700; letter-spacing: 0.02em; white-space: nowrap; color: inherit; text-decoration: none; }
.brand b { color: var(--amber); }

/* Segmented switches: profile (header) and trend range (readout).
   Dash 4 RadioItems: label.dash-options-list-option > span wrapper > input, then span text. */
.views, .range { display: flex; gap: 2px; margin: 0; padding: 0; }
.views .dash-options-list-option, .range .dash-options-list-option {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0;
  margin: 0;
  padding: 5px 10px;
  border: 1px solid transparent;
  color: var(--dim);
  background: none;
  cursor: pointer;
  white-space: nowrap;
  line-height: 1.2;
}
.views .dash-options-list-option:hover, .range .dash-options-list-option:hover { color: var(--text); }
.views .dash-options-list-option-wrapper, .range .dash-options-list-option-wrapper { position: static; width: 0; height: 0; }
.view-input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  margin: 0;
  cursor: pointer;
  appearance: none;
}
.views .dash-options-list-option:has(.view-input:checked),
.range .dash-options-list-option:has(.view-input:checked) { color: var(--bg); background: var(--amber); }
.dash-options-list-option:has(.view-input:focus-visible) { outline: 1px solid var(--amber); outline-offset: 2px; }
.view-option { color: inherit; }

.hr { margin-left: auto; display: flex; gap: 18px; align-items: center; color: var(--dim); }
.hr a, .hr .opt { text-decoration: none; white-space: nowrap; }
.hr a:hover, .hr .opt:hover { color: var(--text); }
.link-button { background: none; border: 0; padding: 0; cursor: pointer; color: inherit; }
.sub {
  color: var(--amber);
  background: none;
  border: 1px solid var(--amber);
  padding: 4px 10px;
  cursor: pointer;
  white-space: nowrap;
  line-height: 1.2;
}
.sub:hover { color: var(--bg); background: var(--amber); }
.updated { white-space: nowrap; }

/* Subscribe box anchored to the button */
.popover {
  --bs-popover-bg: var(--cell);
  --bs-popover-border-color: var(--grid);
  --bs-popover-border-radius: 0;
  --bs-popover-inner-border-radius: 0;
  --bs-popover-box-shadow: none;
  --bs-popover-body-color: var(--text);
  --bs-popover-body-padding-x: 14px;
  --bs-popover-body-padding-y: 14px;
  --bs-popover-max-width: 300px;
  --bs-popover-font-size: 13px;
  font-family: var(--mono);
  box-shadow: none;
}
.newsletter-popover { width: 280px; }
.newsletter-label { display: block; color: var(--amber); font-size: 12px; margin-bottom: 8px; }
.newsletter-input {
  display: block;
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--grid);
  border-radius: 0;
  padding: 6px 8px;
  font: inherit;
}
.newsletter-input:focus { outline: none; border-color: var(--amber); }
.newsletter-submit {
  display: block;
  width: 100%;
  margin-top: 8px;
  background: var(--amber);
  color: var(--bg);
  border: 0;
  padding: 6px 8px;
  font-weight: 700;
  cursor: pointer;
}
.newsletter-feedback { font-size: 12px; }
.newsletter-feedback:not(:empty) { margin-top: 8px; }

/* ── Index readout ────────────────────────────────────────────────── */
/* The readout section is re-rendered by its callback; the trend toggle sits
   outside it, so both are laid out in the cell's own single-column grid. */
.read-cell { display: grid; grid-template-columns: minmax(0, 1fr); align-content: start; }
#readout, #readout > .read { display: contents; }
.read .v { font-size: clamp(76px, 6vw, 132px); font-weight: 500; letter-spacing: -0.04em; line-height: 1; }
.read .tier { font-size: clamp(15px, 1.1vw, 20px); margin-top: 8px; font-weight: 700; }
.read .chg { margin-top: 4px; color: var(--dim); font-size: clamp(13px, 0.9vw, 16px); }
.read .spk .spark { width: 100%; height: auto; }
.read .spk { margin-top: 14px; color: var(--amber); grid-row: 5; grid-column: 1; }
.spk-label { font-size: 11px; margin-bottom: 4px; line-height: 20px; }
.spark { display: block; max-width: 100%; height: auto; }
.read-cell .range { grid-row: 5; grid-column: 1; justify-self: end; align-self: start; margin-top: 14px; z-index: 1; }
.range .dash-options-list-option { padding: 2px 6px; font-size: 11px; }
.kv {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 4px 12px;
  margin-top: 18px;
  padding-top: 12px;
  border-top: 1px solid var(--grid);
  font-size: clamp(13px, 0.85vw, 16px);
}
.kv span:nth-child(3n+2), .kv span:nth-child(3n) { text-align: right; }

/* ── Map ──────────────────────────────────────────────────────────── */
.map-pane { padding: 0; position: relative; min-height: 380px; }
.map-graph { position: absolute; inset: 0; }
.map-ttl { position: absolute; top: 14px; left: 16px; right: 16px; z-index: 1; margin: 0; pointer-events: none; }
.map-graph .js-plotly-plot, .map-graph .plot-container { width: 100%; height: 100%; }
.map-graph > div:empty { display: none; }

/* ── Markets ──────────────────────────────────────────────────────── */
.quote { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: baseline; padding: 5px 0; border-bottom: 1px solid var(--grid); }
/* The briefing scrolls inside its pane too, so the categories row is as
   tall as the category table, not the briefing text. */
.briefing-pane { position: relative; min-height: 0; }
.briefing-scroll { position: absolute; top: 44px; right: 16px; bottom: 12px; left: 16px; overflow-y: auto; scrollbar-color: var(--grid) transparent; }

/* The quote list scrolls inside its pane, so it never makes the top row
   taller than the readout and map. */
.quotes-pane { position: relative; min-height: 0; }
.quotes-scroll { position: absolute; top: 44px; right: 16px; bottom: 12px; left: 16px; overflow-y: auto; scrollbar-color: var(--grid) transparent; }
.quote-group { color: var(--amber); font-size: 11px; padding: 10px 0 2px; }
.quote-group:first-child { padding-top: 0; }
.quote > span:first-child { color: var(--dim); }
.quote b { font-weight: 500; text-align: right; }
.quote small { text-align: right; font-size: 11px; }

/* ── Tables (headlines, categories) ───────────────────────────────── */
table { width: 100%; border-collapse: collapse; }
th {
  color: var(--dim);
  font-weight: 400;
  text-align: left;
  padding: 0 10px 6px 0;
  border-bottom: 1px solid var(--grid);
  font-size: 12px;
}
td { padding: 7px 10px 7px 0; border-bottom: 1px solid var(--grid); vertical-align: top; }
tr:hover td { background: var(--hover); }
td.r, th.r { text-align: right; }
td.h { font-family: var(--sans); font-size: 14px; color: var(--text); }
td.h a { text-decoration: none; }
td.h a:hover { text-decoration: underline; }
.sev { font-weight: 700; }
.headlines td.r { white-space: nowrap; }

/* Headlines: every tracked story, about ten rows visible, filters in the title row */
.news-head { align-items: center; }
.filters { display: flex; gap: 6px; margin-left: auto; min-width: 0; }
.flt, .flt.form-select {
  height: 24px;
  font: inherit;
  font-size: 12px;
  color: var(--text);
  background-color: var(--bg);
  border: 1px solid var(--grid);
  border-radius: 0;
  padding: 2px 8px;
  min-width: 0;
  box-shadow: none;
}
.flt-search { width: 160px; display: flex; align-items: center; }
.flt-search .dash-input-element {
  width: 100%;
  height: 100%;
  background: transparent;
  border: 0;
  padding: 0;
  color: var(--text);
  font: inherit;
  outline: none;
}
.flt-search:focus-within { border-color: var(--amber); }
.flt.form-select { width: auto; padding-right: 26px; background-position: right 8px center; background-size: 10px 8px; }
.flt:focus, .flt.form-select:focus { outline: none; border-color: var(--amber); box-shadow: none; }
.flt ::placeholder, .flt::placeholder { color: var(--dim); }
.news-head .count { white-space: nowrap; }
.news-scroll { max-height: 384px; overflow-y: auto; scrollbar-color: var(--grid) transparent; }
.news-scroll th { position: sticky; top: 0; background: var(--cell); z-index: 1; }

/* Briefing */
.brief p { font-family: var(--sans); font-size: 14px; line-height: 1.5; margin: 0 0 12px; color: var(--prose); }
.report-link { color: var(--amber); text-decoration: none; font-size: 12px; }
.report-link:hover { text-decoration: underline; }

/* Categories */
.score-col { width: 28%; }
.bar { position: relative; height: 8px; background: var(--track); margin-top: 4px; }
.bar i { position: absolute; left: 0; top: 0; bottom: 0; }
.bar u { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--text); opacity: 0.5; }
.cat-name {
  background: none;
  border: 0;
  padding: 0;
  text-align: left;
  cursor: help;
  border-bottom: 1px dotted var(--dim);
  touch-action: manipulation;
}
.cat-name:hover, .cat-name:focus { border-bottom-color: var(--amber); }
.is-fallback td { opacity: 0.6; }
.fallback-tag { margin-left: 8px; font-size: 11px; color: var(--dim); border: 1px solid var(--grid); padding: 1px 5px; }
.index-row td { border-bottom: 0; }

/* Category detail tooltip */
.tooltip {
  --bs-tooltip-bg: var(--hover);
  --bs-tooltip-color: var(--text);
  --bs-tooltip-border-radius: 0;
  --bs-tooltip-max-width: 340px;
  --bs-tooltip-padding-x: 12px;
  --bs-tooltip-padding-y: 10px;
  --bs-tooltip-font-size: 12px;
  --bs-tooltip-opacity: 1;
  font-family: var(--mono);
}
.tooltip-inner { text-align: left; border: 1px solid var(--grid); }
.cat-tip .tooltip-inner > div + div { margin-top: 4px; }

/* API modal */
.term-modal .modal-content {
  background: var(--cell);
  color: var(--text);
  border: 1px solid var(--grid);
  border-radius: 0;
  box-shadow: none;
  font-family: var(--mono);
}
.term-modal .modal-header, .term-modal .modal-footer { border-color: var(--grid); }
.term-modal .modal-title { color: var(--amber); font-size: 13px; font-weight: 400; }
.term-modal .btn-close { filter: invert(1); opacity: 0.6; }
.term-modal .ttl { margin-top: 16px; }
.api-code {
  display: block;
  padding: 8px 10px;
  background: var(--bg);
  border: 1px solid var(--grid);
  color: var(--text);
  font-family: var(--mono);
  font-size: 12px;
  overflow-x: auto;
}
.term-modal ul { padding-left: 18px; margin: 0 0 12px; }
.modal-backdrop { --bs-backdrop-opacity: 0.7; }

/* ── Loading state (components/skeleton.py) ───────────────────────── */
.ph { background: var(--track); animation: ph-pulse 1.6s ease-in-out infinite; max-width: 100%; }
.sk-list .ph + .ph { margin-top: 12px; }
.sk-views { display: flex; }
.sk .ttl { opacity: 0.7; }
.sk-v { font-size: 40px; font-weight: 500; letter-spacing: -0.02em; line-height: 1; color: var(--dim); margin-top: 8px; }
.sk-msg { margin-top: 10px; min-height: 18px; }
.sk-spark { margin-top: 18px; }
.sk-kv { margin-top: 18px; padding-top: 12px; border-top: 1px solid var(--grid); display: grid; gap: 10px; }
.sk-map { position: absolute; inset: 0; background: var(--cell); }
@keyframes ph-pulse { 0%, 100% { opacity: 0.55; } 50% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .ph { animation: none; } }

/* ── Narrow desktops and tablets ──────────────────────────────────── */
@media (max-width: 1100px) {
  .briefing-scroll { position: static; max-height: none; }
  .quotes-scroll { position: static; max-height: 320px; }
  /* Two columns; briefing fills the space beside the quotes. */
  .shell { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); grid-auto-flow: row dense; }
  .wide, .full { grid-column: 1 / -1; }
  .head { flex-wrap: wrap; height: auto; min-height: 44px; padding: 8px 16px; row-gap: 8px; }
}

/* ── Phones ───────────────────────────────────────────────────────── */
/* One column in the desktop order: readout, map, quotes, headlines,
   briefing, categories. The header wraps to name + Subscribe, then the
   profile switch, then Updated / Methodology / API / CSV. Tables drop the
   low-value columns (.hide-s) instead of scrolling sideways. */
@media (max-width: 760px) {
  .shell { grid-template-columns: minmax(0, 1fr); grid-auto-flow: row; }

  .head { gap: 10px; padding: 10px 16px 12px; }
  .head > .hr { display: contents; }
  .brand { order: 1; font-size: 12px; white-space: normal; min-width: 0; flex: 1 1 0; }
  .head .sub { order: 2; margin-left: auto; padding: 7px 12px; }
  .head .hr > .ph { order: 2; margin-left: auto; }
  .views, .sk-views { order: 3; flex: 1 1 100%; }
  .views .dash-options-list-option { flex: 1 1 0; justify-content: center; padding: 7px 10px; }
  .head .updated, .head .opt { order: 4; font-size: 12px; color: var(--dim); }
  .head .updated { margin-right: auto; }

  .map-pane { min-height: 260px; }

  /* 16px inputs stop iOS from zooming the page on focus. */
  .newsletter-input, .flt-search .dash-input-element, .flt.form-select { font-size: 16px; }
  .popover { --bs-popover-max-width: calc(100vw - 32px); }
  .newsletter-popover { width: min(280px, calc(100vw - 32px)); }

  .news-head { flex-wrap: wrap; row-gap: 8px; }
  .news-head .count { margin-left: auto; }
  .filters { order: 3; flex: 1 1 100%; margin-left: 0; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 6px; }
  .flt, .flt.form-select { height: 34px; }
  .flt-search { grid-column: 1 / -1; width: auto; }
  .flt.form-select { width: 100%; }

  .hide-s { display: none; }
  td.h { overflow-wrap: anywhere; }
  .categories th, .categories td { padding-right: 8px; }
  .categories .score-col { width: 22%; }
  .tooltip { --bs-tooltip-max-width: calc(100vw - 32px); }
}
