/* Color conventions match scripts/render_eod_summary_pdf.py exactly, so the live
   dashboard and the emailed PDF read as the same product. */
:root {
  --good: #0ca30c;
  --critical: #d03b3b;
  --warning: #b8860b;
  --news: #1a56c4;
  --bidask: #7c3aed;
  --navy: #0b2545;
  --good-tint: #eef8ee;
  --critical-tint: #fcefef;
  --ink: #0b0b0b;
  --ink-secondary: #52514e;
  --ink-muted: #898781;
  --surface: #fcfcfb;
  --page-plane: #f9f9f7;
  --gridline: #e1e0d9;
  --border: rgba(11, 11, 11, 0.10);

  /* Design tokens — spacing/type/elevation/radius/motion scales, layered on top of
     the color tokens above. None of these change what any color means. */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;

  --text-xs: 11px;
  --text-sm: 13px;
  --text-md: 14px;
  --text-lg: 16px;
  --text-xl: 20px;
  --text-2xl: 28px;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;

  --shadow-sm: 0 1px 2px rgba(11, 11, 11, 0.06), 0 1px 1px rgba(11, 11, 11, 0.04);
  --shadow-md: 0 4px 12px rgba(11, 11, 11, 0.08), 0 2px 4px rgba(11, 11, 11, 0.05);
  --shadow-lg: 0 16px 40px rgba(11, 11, 11, 0.18), 0 4px 12px rgba(11, 11, 11, 0.08);

  --transition-fast: 150ms ease;
  --transition-base: 200ms ease;
}

@media (prefers-color-scheme: dark) {
  :root {
    --surface: #1c1d1b;
    --page-plane: #14150f;
    --gridline: #33342d;
    --border: rgba(255, 255, 255, 0.12);
    --ink: #f2f1ec;
    --ink-secondary: #c9c7bd;
    --ink-muted: #8f8d84;
    --good-tint: #10241a;
    --critical-tint: #2a1414;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35), 0 1px 1px rgba(0, 0, 0, 0.25);
    --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.45), 0 2px 6px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 20px 48px rgba(0, 0, 0, 0.55), 0 6px 16px rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; }

/* main/.skeleton below both set `display` unconditionally, which — per the CSS
   cascade — outranks the browser's default `[hidden] { display: none }` (an
   author-stylesheet rule always beats a user-agent rule, regardless of selector
   specificity). Without this, toggling the `hidden` attribute/property has no
   visual effect and the skeleton stays on screen forever. */
#skeleton[hidden], #app[hidden] { display: none; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--page-plane);
  font-size: var(--text-md);
  line-height: 1.5;
}

main {
  max-width: 1600px;
  margin: 0 auto;
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

h1 { font-size: var(--text-xl); margin: 0 0 4px 0; color: #fff; font-weight: 700; }
h2 { font-size: var(--text-lg); margin: 0 0 10px 0; border-bottom: 1px solid var(--gridline); padding-bottom: 6px; }
h3 { font-size: var(--text-sm); margin: 0 0 8px 0; color: var(--ink-muted); text-transform: uppercase; letter-spacing: 0.02em; }

.header {
  background: var(--navy);
  color: #fff;
  padding: var(--space-4) var(--space-5);
}
.header-row {
  max-width: 1600px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--space-4);
  flex-wrap: wrap;
}
.subtitle { color: #cfd8e3; font-size: var(--text-sm); margin: 0; }
.header-controls { display: flex; align-items: center; gap: var(--space-2); color: #cfd8e3; font-size: var(--text-sm); }
.header-controls select {
  font-size: var(--text-md);
  padding: 5px var(--space-2);
  border-radius: var(--radius-sm);
  border: none;
  transition: box-shadow var(--transition-fast);
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: var(--space-4);
  transition: box-shadow var(--transition-base);
}

.two-col { display: flex; gap: var(--space-4); flex-wrap: wrap; }
.two-col > .panel { flex: 1; min-width: 280px; }

/* Two-column dashboard body: macro/summary context on the left (scrolls with the
   page — commentary/headline text can run long), the movers table pinned on the
   right via position: sticky so it never scrolls out of view while reading the
   left side. align-items: flex-start keeps each column sized to its own content
   (not stretched to match the other) — required for the sticky column to have
   room to "stick" against, and min-width: 0 lets the wide table's own horizontal
   scroll container shrink correctly instead of forcing the flex item wider. */
.dashboard-layout {
  display: flex;
  align-items: flex-start;
  gap: var(--space-4);
}
.dashboard-sidebar {
  flex: 0 0 360px;
  min-width: 300px;
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}
.dashboard-main {
  flex: 1;
  min-width: 0;
  position: sticky;
  top: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

/* Stat-tile row — dataviz skill's stat-tile contract: label (sentence case, no
   colon) + value only (no delta/trend — a single day snapshot has no baseline to
   diff against). Values use the font's default proportional figures, not
   tabular-nums — that spacing is reserved for table/axis columns (see below). */
.stat-row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: var(--space-3);
}
.stat-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: var(--space-3) var(--space-4);
  transition: box-shadow var(--transition-base);
}
.stat-tile .stat-label {
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: var(--ink-muted);
  margin: 0 0 4px 0;
}
.stat-tile .stat-value {
  font-size: var(--text-2xl);
  font-weight: 600;
  margin: 0;
  line-height: 1.1;
}

table { width: 100%; border-collapse: collapse; }
th {
  text-align: left;
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: var(--ink-muted);
  border-bottom: 1px solid var(--gridline);
  padding: 6px 8px;
  white-space: nowrap;
}
td {
  border-bottom: 1px solid var(--gridline);
  padding: var(--space-2) var(--space-2);
  vertical-align: top;
}
tr:last-child td { border-bottom: none; }

/* Tabular alignment is reserved for columns of numbers that must line up
   vertically (table cells, breadth values) — not stand-alone stat-tile figures. */
table.breadth td.breadth-value { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }

.symbol { font-weight: 700; white-space: nowrap; }
.company { color: var(--ink-muted); font-size: 12px; display: block; }
.sector { color: var(--ink-muted); }
.num { white-space: nowrap; text-align: right; font-variant-numeric: tabular-nums; }
.pct-good { color: var(--good); font-weight: 700; }
.pct-critical { color: var(--critical); font-weight: 700; }
.corp-action-badge {
  color: var(--warning);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  display: block;
}

.legend-strip { display: flex; flex-wrap: wrap; gap: 10px 18px; font-size: 13px; }
.legend-strip .legend-item { display: flex; align-items: center; gap: 6px; }

.source-badge {
  display: inline-block;
  max-width: 100%;
  padding: 3px 8px;
  border-radius: 999px;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.01em;
  white-space: nowrap;
}
/* The movers table's Source Type column is a narrow fixed percentage width — "CORP
   ACTION" (the longest label) would otherwise refuse to wrap and visually spill
   over the neighboring cell instead of shrinking to fit. Legend/modal usages have
   room to spare, so this override is scoped to the table only. */
table.movers .source-badge { white-space: normal; text-align: center; line-height: 1.2; }
.badge-news { background: var(--news); }
.badge-bidask { background: var(--bidask); }
.badge-macro { background: var(--warning); }
.badge-corp { background: var(--good); }

.conf-high { color: var(--good); font-weight: 700; white-space: nowrap; }
.conf-medium { color: var(--warning); font-weight: 700; white-space: nowrap; }
.conf-low { color: var(--critical); font-weight: 700; white-space: nowrap; }

.filter-bar {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  flex-wrap: wrap;
  margin-bottom: var(--space-3);
  padding: var(--space-3);
  font-size: var(--text-sm);
  background: var(--page-plane);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}
.filter-bar label { display: flex; flex-direction: column; gap: 2px; color: var(--ink-muted); font-size: var(--text-xs); text-transform: uppercase; letter-spacing: 0.02em; }
.filter-bar select, .filter-bar input {
  font-size: var(--text-sm);
  padding: 5px var(--space-2);
  border-radius: var(--radius-sm);
  border: 1px solid var(--gridline);
  background: var(--surface);
  color: var(--ink);
  transition: box-shadow var(--transition-fast), border-color var(--transition-fast);
}
.filter-bar select:focus-visible, .filter-bar input:focus-visible {
  outline: none;
  border-color: var(--news);
  box-shadow: 0 0 0 3px rgba(26, 86, 196, 0.25);
}
.search-label input { min-width: 180px; }
.counter { color: var(--ink-muted); font-size: 12px; margin-left: auto; }
.clear-filters {
  font-size: var(--text-xs);
  color: var(--news);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
}

.segmented { display: flex; border: 1px solid var(--gridline); border-radius: var(--radius-sm); overflow: hidden; }
.segmented button {
  border: none;
  background: var(--surface);
  color: var(--ink);
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
  transition: background-color var(--transition-fast), color var(--transition-fast);
}
.segmented button + button { border-left: 1px solid var(--gridline); }
.segmented button.active { background: var(--navy); color: #fff; }

.table-scroll {
  overflow-x: hidden;
  overflow-y: auto;
  max-height: 70vh;
  border-radius: var(--radius-md);
  scrollbar-width: thin; /* Firefox */
  scrollbar-color: var(--gridline) transparent;
}
.table-scroll::-webkit-scrollbar { width: 8px; } /* Chrome/Safari/Edge */
.table-scroll::-webkit-scrollbar-track { background: transparent; }
.table-scroll::-webkit-scrollbar-thumb { background: var(--gridline); border-radius: 999px; }
.table-scroll::-webkit-scrollbar-thumb:hover { background: var(--ink-muted); }
/* table-layout: fixed + the <colgroup> percentages in index.html — matching
   render_eod_summary_pdf.py's already-proven fix for this exact 10-column table —
   makes the table always exactly 100% of .table-scroll's width, so cell text wraps
   instead of the table growing wider than its container and needing a horizontal
   scrollbar. Without this, auto layout lets free-text columns (Reason for Move,
   Source Detail) balloon and push the table past its container. */
table.movers { table-layout: fixed; }
table.movers th, table.movers td { overflow-wrap: break-word; word-break: break-word; }
/* .num's white-space: nowrap (below) is fine for the roomier Index Snapshot/
   Additional Movers tables, but the movers table's numeric columns are now
   percentage-width — on a narrow viewport a nowrap number could visually spill
   past its cell instead of wrapping. Scoped override, not a change to .num itself. */
table.movers td.num { white-space: normal; }
table.movers thead th {
  cursor: pointer;
  user-select: none;
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 1;
  box-shadow: 0 1px 0 var(--gridline);
  transition: color var(--transition-fast);
}
table.movers thead th:hover { color: var(--ink); }
table.movers thead th.sort-active { color: var(--ink); }
.th-label { display: inline-flex; align-items: center; gap: 4px; }
.sort-icon { width: 9px; height: 9px; flex: none; opacity: 0.3; transition: opacity var(--transition-fast), transform var(--transition-fast); }
.sort-icon.sort-icon-active { opacity: 1; }
.sort-icon.sort-icon-desc { transform: rotate(180deg); }

table.movers tbody tr {
  transition: background-color var(--transition-fast);
  cursor: pointer;
}
table.movers tbody tr:hover { background: var(--page-plane); }
table.movers tbody tr.row-gainer { border-left: 3px solid var(--good); }
table.movers tbody tr.row-loser { border-left: 3px solid var(--critical); }
table.movers td.reason, table.movers td.source-detail { color: var(--ink-secondary); font-size: 13px; }
table.movers td.col-reason { max-width: 320px; }
table.movers td.col-detail { max-width: 220px; }

.row-detail-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  margin-left: 6px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--ink-muted);
  cursor: pointer;
  vertical-align: middle;
  transition: background-color var(--transition-fast), color var(--transition-fast);
}
.row-detail-btn:hover, .row-detail-btn:focus-visible { background: var(--gridline); color: var(--ink); }

.empty { color: var(--ink-muted); font-style: italic; }
.empty-state { text-align: center; padding: var(--space-5) var(--space-3); }
.empty-state p { margin: 0 0 var(--space-2) 0; }
.methodology { font-size: 12px; color: var(--ink-muted); margin: 4px 0 24px 0; }

/* Loading skeleton — shown while the first date's data is in flight; #app stays
   hidden (see index.html) until app.js reveals it after the first real render. */
.skeleton { max-width: 1600px; margin: 0 auto; padding: var(--space-4); display: flex; flex-direction: column; gap: var(--space-4); }
.skeleton-row { display: grid; grid-template-columns: repeat(5, 1fr); gap: var(--space-3); }
.skeleton-block {
  background: linear-gradient(90deg, var(--gridline) 25%, var(--border) 37%, var(--gridline) 63%);
  background-size: 400% 100%;
  animation: skeleton-pulse 1.4s ease infinite;
  border-radius: var(--radius-md);
}
.skeleton-tile { height: 64px; }
.skeleton-panel { height: 120px; }
.skeleton-table { height: 320px; }
@keyframes skeleton-pulse {
  0% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}
@media (prefers-reduced-motion: reduce) {
  .skeleton-block { animation: none; }
}

/* Detail modal — reuses the same surface/border/radius/shadow tokens and badge
   classes as the rest of the page; no second visual system. */
.mover-modal {
  border: none;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 0;
  width: min(640px, calc(100vw - 32px));
  max-height: min(85vh, 720px);
  color: var(--ink);
  background: var(--surface);
}
.mover-modal::backdrop { background: rgba(11, 11, 11, 0.45); }
.mover-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--gridline);
}
.mover-modal-header h2 { font-size: var(--text-xl); margin: 0; border: none; padding: 0; color: var(--ink); }
.mover-modal-sector { margin: 0; color: var(--ink-muted); font-size: var(--text-xs); text-transform: uppercase; letter-spacing: 0.02em; }
.mover-modal-price { margin: 4px 0 0 0; font-size: var(--text-lg); font-weight: 600; }
.modal-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--ink-muted);
  cursor: pointer;
  flex: none;
  transition: background-color var(--transition-fast), color var(--transition-fast);
}
.modal-close:hover, .modal-close:focus-visible { background: var(--page-plane); color: var(--ink); }
.mover-modal-body { padding: var(--space-4) var(--space-5) var(--space-5); overflow-y: auto; }
.modal-section { margin-bottom: var(--space-5); }
.modal-section:last-child { margin-bottom: 0; }
.modal-section p { margin: 0; color: var(--ink-secondary); }
.modal-classification-row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); font-size: var(--text-sm); }

.source-list { display: flex; flex-direction: column; gap: var(--space-2); }
.source-card {
  border: 1px solid var(--border);
  border-left: 3px solid var(--gridline);
  border-radius: var(--radius-sm);
  padding: var(--space-2) var(--space-3);
  background: var(--page-plane);
}
.source-card.source-used { border-left-color: var(--news); }
.source-card a { color: var(--news); font-weight: 600; text-decoration: none; }
.source-card a:hover { text-decoration: underline; }
.source-meta { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; margin: 4px 0; font-size: var(--text-xs); color: var(--ink-muted); }
.source-used-pill {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--news);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
}
.source-snippet { margin: 4px 0 0 0; font-size: var(--text-sm); color: var(--ink-secondary); }

.signals-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--space-3); font-size: var(--text-sm); }
.signal-item .signal-label { font-size: var(--text-xs); color: var(--ink-muted); text-transform: uppercase; letter-spacing: 0.02em; margin: 0 0 2px 0; }
.signal-item .signal-value { margin: 0; font-variant-numeric: tabular-nums; }

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

@media (max-width: 768px) {
  .two-col { flex-direction: column; }
  .dashboard-layout { flex-direction: column; }
  .dashboard-sidebar { flex: 1 1 auto; min-width: 0; width: 100%; }
  .dashboard-main { position: static; width: 100%; }
  .stat-row { grid-template-columns: repeat(2, 1fr); }
  .header-row { flex-direction: column; align-items: stretch; }
  .filter-bar { flex-direction: column; align-items: stretch; }
  .filter-bar .search-label input { width: 100%; }
  .filter-bar .counter { margin-left: 0; }
  .signals-grid { grid-template-columns: 1fr; }
  .mover-modal { width: calc(100vw - 24px); max-height: 90vh; }
  .mover-modal-header, .mover-modal-body { padding-left: var(--space-4); padding-right: var(--space-4); }
}
