/* Viewer styles (docs/design/report-page-v1.md §3.7, §4). System fonts only; no third-party
   fonts, images, or scripts. Colours meet WCAG AA in both themes. Grade and tendency are
   always shown as text, never by colour alone; red is reserved for risk. */

:root {
  --bg: #f5f7f7;
  --surface: #ffffff;
  --surface-2: #eef3f3;
  --text: #14211f;
  --muted: #4a5a58;
  --border: #d3dddc;
  --accent: #006570; /* grade A, 6.4:1 on white */
  --accent-soft: #d9eef0;
  --secondary: #5b4a8b; /* grade B+, 7.2:1 on white */
  --secondary-soft: #e8e3f5;
  --risk: #a3221a; /* 7.0:1 on white */
  --risk-soft: #fbe5e3;
  --warn: #7a5200;
  --warn-soft: #fbefd5;
  --focus: #1b5fd6;
  /* Status tones (docs/design/status-colors.md). Text/background pairs meet WCAG AA. */
  --good: #1b6b35;
  --good-soft: #e3f4e8;
  --caution: #8a4b00;
  --caution-soft: #fdf0dc;
  --info: #1f4f99;
  --info-soft: #e4ecfb;
  --neutral: #3f4a4a;
  --neutral-soft: #eceff0;
  --missing: #555f5e;
  --missing-border: #9aa6a5;
  --radius: 10px;
  --tap: 44px;
  color-scheme: light dark;
  font-family: system-ui, -apple-system, "PingFang SC", "Hiragino Sans GB", "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1615;
    --surface: #17211f;
    --surface-2: #1f2c2a;
    --text: #e6eeec;
    --muted: #a9b8b5;
    --border: #2f403d;
    --accent: #5cc8d2;
    --accent-soft: #123a3e;
    --secondary: #bcaaf0;
    --secondary-soft: #2c2645;
    --risk: #ff8f85;
    --risk-soft: #3e1a17;
    --warn: #f0c35a;
    --warn-soft: #3a2f12;
    --focus: #8ab4ff;
    --good: #7fdc9a;
    --good-soft: #15311f;
    --caution: #ffbf66;
    --caution-soft: #3a2a10;
    --info: #9dbcff;
    --info-soft: #172a4a;
    --neutral: #c6d0ce;
    --neutral-soft: #243230;
    --missing: #a9b8b5;
    --missing-border: #4a5c59;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  overflow-x: hidden;
  padding-bottom: env(safe-area-inset-bottom);
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

button {
  min-height: var(--tap);
  min-width: var(--tap);
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
}

button:disabled {
  opacity: 0.45;
  cursor: default;
}

input,
select {
  min-height: var(--tap);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 0 10px;
  max-width: 100%;
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

h1,
h2,
h3 {
  line-height: 1.25;
  margin: 0;
}

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

.skip-link {
  position: absolute;
  left: -9999px;
}

.skip-link:focus {
  left: 12px;
  top: 12px;
  z-index: 20;
  background: var(--surface);
  padding: 8px 12px;
}

.muted {
  color: var(--muted);
}

.text-button {
  border-color: transparent;
  background: transparent;
  color: var(--accent);
  font-weight: 600;
}

/* ---- top bar ------------------------------------------------------------------------ */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: max(8px, env(safe-area-inset-top)) 12px 8px;
}

.topbar-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.brand {
  font-weight: 700;
}

.source-badge {
  font-size: 13px;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0 8px;
}

.day-button {
  margin-left: auto;
  font-weight: 600;
}

.freshness {
  margin: 4px 0 0;
  font-size: 14px;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  gap: 6px 8px;
  align-items: center;
}

.tag {
  font-size: 13px;
  border-radius: 999px;
  padding: 0 8px;
  background: var(--surface-2);
  color: var(--text);
}

.tag-latest {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.tag-history {
  background: var(--warn-soft);
  color: var(--warn);
  font-weight: 600;
}

.tag-warn {
  background: var(--warn-soft);
  color: var(--warn);
}

.pager {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 8px;
  margin-top: 8px;
}

.pager-button:first-child {
  justify-self: start;
}

.pager-button:last-child {
  justify-self: end;
}

.pager-count {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

.jump-hint {
  font-size: 13px;
  font-weight: 400;
  color: var(--muted);
}

/* ---- layout --------------------------------------------------------------------------- */

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 12px;
  padding: 12px;
  max-width: 1760px;
  margin: 0 auto;
}

/* Below 1100px the insights column dissolves into the page: the counts go to the top and
   the device panel to the end, after the stock. */
.insights {
  display: contents;
}

.insights[hidden] {
  display: none;
}

.overview {
  order: -1;
}

.session-panel {
  order: 10;
}

.sidebar {
  display: grid;
  gap: 8px;
  align-content: start;
}

.symbol-nav {
  display: none;
}

.desktop-only {
  display: none;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
}

.panel h2 {
  font-size: 14px;
  color: var(--muted);
  margin-bottom: 4px;
}

.session-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 12px;
}

.session-panel h2 {
  margin: 0;
}

.overview {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
}

.count {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 4px;
  text-align: center;
  font-size: 13px;
  color: var(--muted);
  display: grid;
}

.count-value {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 8px;
}

.search input {
  width: 100%;
}

/* iOS Safari ignores min-height on a native select, so the sort control drops the native
   appearance and draws its own arrow to match the 44 px filter button. */
.sort {
  position: relative;
}

.sort select {
  max-width: 9.5em;
  height: var(--tap);
  -webkit-appearance: none;
  appearance: none;
  padding-right: 28px;
}

.sort::after {
  content: "▾";
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  color: var(--muted);
}

.symbol-link {
  color: inherit;
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-underline-offset: 4px;
  text-decoration-color: var(--accent);
}

.filters {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  font-size: 14px;
}

.filters[hidden] {
  display: none;
}

.filters label {
  display: grid;
  gap: 4px;
}

.filters .checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: var(--tap);
}

.checkbox input {
  min-height: auto;
  width: 22px;
  height: 22px;
}

.content {
  min-width: 0;
}

/* ---- states ----------------------------------------------------------------------------- */

.state:empty {
  display: none;
}

.state {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px 16px;
  display: grid;
  gap: 12px;
}

.state-title {
  font-size: 20px;
}

.state-error .state-title {
  color: var(--risk);
}

.state-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.skeleton {
  background: var(--surface-2);
  border-radius: 6px;
  animation: pulse 1.4s ease-in-out infinite;
}

.skeleton-title {
  height: 28px;
  width: 55%;
}

.skeleton-line {
  height: 16px;
}

.skeleton-block {
  height: 160px;
}

@keyframes pulse {
  50% {
    opacity: 0.55;
  }
}

.notice {
  background: var(--warn-soft);
  color: var(--warn);
  border-radius: var(--radius);
  padding: 8px 12px;
  margin: 0 0 12px;
}

.notice[hidden] {
  display: none;
}

/* ---- stock --------------------------------------------------------------------------------- */

.stock {
  display: grid;
  gap: 10px;
  touch-action: pan-y;
  scroll-margin-top: 140px;
}

.stock[hidden] {
  display: none;
}

.summary {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  display: grid;
  gap: 8px;
}

.stock-title {
  display: flex;
  align-items: baseline;
  gap: 10px;
  font-size: 24px;
  flex-wrap: wrap;
}

.stock-title:focus {
  outline: none;
}

.stock-title .rank {
  font-size: 14px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.symbol {
  font-weight: 800;
  letter-spacing: 0.02em;
  overflow-wrap: anywhere;
}

.close {
  margin-left: auto;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.grade {
  font-size: 14px;
  font-weight: 800;
  border-radius: 6px;
  padding: 1px 8px;
  border: 1px solid currentColor;
}

.grade-a {
  color: var(--accent);
  background: var(--accent-soft);
}

.grade-b {
  color: var(--secondary);
  background: var(--secondary-soft);
}

.phase {
  margin: 0;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.chips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.chip {
  font-size: 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 10px;
  background: var(--surface-2);
}

/* ---- status tones: colour always accompanies a text label; red is risk only ---------- */

.tone {
  font-weight: 600;
}

.tone-good {
  color: var(--good);
  background: var(--good-soft);
  border-color: var(--good);
}

.tone-caution {
  color: var(--caution);
  background: var(--caution-soft);
  border-color: var(--caution);
}

.tone-info {
  color: var(--info);
  background: var(--info-soft);
  border-color: var(--info);
}

.tone-neutral {
  color: var(--neutral);
  background: var(--neutral-soft);
  border-color: var(--border);
}

.tone-missing {
  color: var(--missing);
  background: transparent;
  border: 1px dashed var(--missing-border);
  font-weight: 400;
}

.tone-risk {
  color: var(--risk);
  background: var(--risk-soft);
  border-color: var(--risk);
  font-weight: 700;
}

.grade-stripe-a {
  border-left: 5px solid var(--accent);
}

.grade-stripe-b {
  border-left: 5px solid var(--secondary);
}

.count {
  border-top-width: 3px;
}

.count-grade-a {
  border-top-color: var(--accent);
}

.count-grade-b {
  border-top-color: var(--secondary);
}

.count-good {
  border-top-color: var(--good);
}

.count-risk {
  border-top-color: var(--risk);
}

.count-info {
  border-top-color: var(--info);
}

.risk-dot {
  color: var(--risk);
}

.nav-tone {
  font-size: 13px;
  border-radius: 999px;
  padding: 0 6px;
  border: 1px solid transparent;
  margin-left: auto;
}

.nav-tone + .risk-dot {
  margin-left: 4px;
}

.levels {
  margin: 0;
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  font-variant-numeric: tabular-nums;
}

.warning {
  margin: 0;
  color: var(--risk);
  overflow-wrap: anywhere;
}

.warning .more {
  color: var(--muted);
}

.group {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.group summary {
  min-height: var(--tap);
  display: flex;
  align-items: center;
  padding: 0 14px;
  font-weight: 700;
  cursor: pointer;
}

.group > :not(summary) {
  padding: 0 14px 14px;
}

.group dl {
  margin: 0;
  display: grid;
  gap: 6px;
}

.field {
  display: grid;
  grid-template-columns: 8.5em minmax(0, 1fr);
  gap: 8px;
}

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

.field dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.warnings {
  margin: 8px 0 0;
  padding-left: 20px;
  color: var(--risk);
}

.warnings li {
  overflow-wrap: anywhere;
}

.prose {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.group h3 {
  font-size: 15px;
}

.finviz-link {
  color: var(--accent);
  font-weight: 600;
  min-height: var(--tap);
  display: inline-flex;
  align-items: center;
}

.footer {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  justify-content: center;
  padding: 12px 12px 24px;
  color: var(--muted);
  font-size: 13px;
}

/* ---- dialogs ------------------------------------------------------------------------------- */

.dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 0;
  width: min(92vw, 420px);
  max-height: 80vh;
}

.dialog::backdrop {
  background: rgb(0 0 0 / 45%);
}

.dialog-body {
  display: grid;
  gap: 12px;
  padding: 16px;
}

.dialog-body label {
  display: grid;
  gap: 4px;
}

.dialog-error {
  color: var(--risk);
  margin: 0;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.jump-list,
.day-list,
.symbol-nav {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
}

.jump-list,
.day-list {
  max-height: 45vh;
}

.jump-list button,
.day-list button,
.symbol-nav button {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: flex-start;
  color: var(--text);
  border-color: transparent;
  background: transparent;
}

.symbol-nav button[aria-current="true"],
.day-list button[aria-current="true"] {
  background: var(--accent-soft);
  border-color: var(--accent);
}

kbd {
  font-family: ui-monospace, monospace;
  font-size: 13px;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0 4px;
}

.shortcuts {
  margin: 0;
  padding-left: 18px;
  font-size: 14px;
}

/* ---- MacBook desktop: three columns, one stock in focus (§3.7) ------------------------------- */

@media (min-width: 1100px) {
  .layout {
    grid-template-columns: minmax(260px, 320px) minmax(600px, 760px) minmax(280px, 360px);
    justify-content: center;
    align-items: start;
    gap: 16px;
    padding: 16px;
  }

  .insights {
    display: grid;
    gap: 12px;
    order: 0;
    position: sticky;
    top: 132px;
  }

  .sidebar {
    position: sticky;
    top: 132px;
    max-height: calc(100vh - 148px);
    grid-template-rows: auto auto minmax(0, 1fr);
  }

  .toolbar {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .sort {
    grid-column: 1 / -1;
  }

  .sort select {
    width: 100%;
    max-width: none;
  }

  .symbol-nav {
    display: block;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 4px;
  }

  .overview {
    order: 0;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .session-panel {
    order: 0;
  }

  .desktop-only {
    display: block;
  }

  .pager {
    max-width: 760px;
    margin: 8px auto 0;
  }

  .footer {
    display: flex;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    /* biome-ignore lint/complexity/noImportantStyles: reduced motion must override every animation. */
    animation: none !important;
    /* biome-ignore lint/complexity/noImportantStyles: reduced motion must override every transition. */
    transition: none !important;
    /* biome-ignore lint/complexity/noImportantStyles: reduced motion must override smooth scrolling. */
    scroll-behavior: auto !important;
  }
}
