/* Quant dashboard — clean dark theme. */
:root {
  --bg: #0d1117;
  --bg-card: #161b22;
  --bg-row: #1a1f27;
  --border: #2d3340;
  --fg: #d8dde6;
  --fg-muted: #7a8290;
  --accent: #58a6ff;
  --pos: #3fb950;
  --neg: #f85149;
  --warn: #d29922;
  --kill: #f85149;
  --healthy: #3fb950;
  --ready: #58a6ff;
  --breaker: #db61a2;
  --disabled: #6e7681;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 13px/1.5 -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
}
header {
  display: flex; align-items: center; gap: 24px;
  padding: 12px 24px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 700; font-size: 16px; letter-spacing: 2px; }
.brand .meta { font-weight: 400; font-size: 11px; color: var(--fg-muted); margin-left: 12px; }
nav { display: flex; gap: 2px; }
nav a {
  color: var(--fg-muted);
  text-decoration: none;
  padding: 6px 14px;
  border-radius: 4px;
  font-weight: 500;
}
nav a:hover { background: var(--bg-row); color: var(--fg); }
nav a.active { color: var(--accent); background: var(--bg-row); }
main { padding: 16px 24px; max-width: 1600px; margin: 0 auto; }

/* Cards */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 14px 16px;
}
.card h3 { margin: 0 0 8px 0; font-size: 11px; text-transform: uppercase; color: var(--fg-muted); letter-spacing: 1px; }
.value-big { font-size: 22px; font-weight: 700; letter-spacing: -0.5px; }
.card .meta { font-size: 11px; color: var(--fg-muted); margin-top: 4px; }
.card .meta.sub { font-size: 10px; opacity: 0.7; }
.card .meta a { color: var(--accent); text-decoration: none; }

/* Verdict pills */
.verdict-grid { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 8px; }
.verdict-pill, .pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}
.v-healthy { background: rgba(63,185,80,.18); color: var(--healthy); }
.v-warn    { background: rgba(210,153,34,.22); color: var(--warn); }
.v-kill_candidate { background: rgba(248,81,73,.20); color: var(--kill); }
.v-ready_flip { background: rgba(88,166,255,.18); color: var(--ready); }
.v-disabled  { background: rgba(110,118,129,.30); color: var(--disabled); }
.v-breaker_tripped { background: rgba(219,97,162,.22); color: var(--breaker); }
.v-unknown { background: rgba(110,118,129,.20); color: var(--fg-muted); }

/* Walkforward verdicts (P1 audit fix) */
.v-oos_inverted, .v-inverted { background: rgba(248,81,73,.30); color: var(--kill); font-weight: 700; }
.v-decayed { background: rgba(248,81,73,.18); color: var(--kill); }
.v-consistently_negative { background: rgba(248,81,73,.16); color: var(--kill); }
.v-uncertain { background: rgba(210,153,34,.18); color: var(--warn); }
.v-insufficient { background: rgba(110,118,129,.15); color: var(--fg-muted); }
.v-validated { background: rgba(63,185,80,.20); color: var(--healthy); font-weight: 700; }

/* Regime pills */
.v-bull { background: rgba(63,185,80,.18); color: var(--healthy); }
.v-bear { background: rgba(248,81,73,.20); color: var(--kill); }
.v-chop { background: rgba(210,153,34,.22); color: var(--warn); }
.v-accumulation { background: rgba(88,166,255,.18); color: var(--ready); }
.v-distribution { background: rgba(219,97,162,.22); color: var(--breaker); }

/* Anomaly status (re-uses existing palette but ALERT alias) */
.v-alert { background: rgba(248,81,73,.20); color: var(--kill); }
.v-ok { background: rgba(63,185,80,.18); color: var(--healthy); }

/* warn class for inline metric */
.warn { color: var(--warn); }

/* Tables */
table { width: 100%; border-collapse: collapse; font-size: 12px; }
table thead th {
  text-align: left;
  background: var(--bg-card);
  color: var(--fg-muted);
  font-weight: 600;
  font-size: 10px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  position: sticky; top: 50px;
}
table tbody td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
table tbody tr:hover { background: var(--bg-row); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.muted { color: var(--fg-muted); }
.muted.small { font-size: 11px; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.live { color: var(--pos); font-weight: 600; }
.paper { color: var(--fg-muted); }

/* Strategy table row tinting */
.row-warn td { background: rgba(210,153,34,.04); }
.row-kill_candidate td { background: rgba(248,81,73,.06); }
.row-ready_flip td { background: rgba(88,166,255,.04); }
.row-breaker_tripped td { background: rgba(219,97,162,.06); }
.row-disabled td { color: var(--fg-muted); }

.reason-row td { padding-top: 0; padding-bottom: 8px; border-bottom: 1px solid var(--border); font-size: 11px; }

/* Sections */
section { margin-bottom: 28px; }
section h2 { margin: 0 0 8px 0; font-size: 16px; }
section h3 { margin: 0 0 8px 0; font-size: 13px; font-weight: 600; color: var(--fg); text-transform: uppercase; letter-spacing: 1px; opacity: 0.8; }
section.strat-header .meta,
section.exec-header .meta { color: var(--fg-muted); font-size: 11px; }

/* Freshness table — color-code by age (>6h warn, >24h fail) */
.freshness tr.stale-warn td { color: var(--warn); }
.freshness tr.stale-fail td { color: var(--neg); }
.freshness tr.stale td { color: var(--neg); }  /* legacy */

/* Clickable strategy rows */
tr.clickable { cursor: pointer; }
tr.clickable:hover { background: var(--bg-row); }

/* Drill-down modal */
.modal {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  padding: 24px;
}
.modal.hidden { display: none; }
.modal-content {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  max-width: 900px; width: 100%;
  max-height: 85vh; overflow-y: auto;
}
.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-row);
  position: sticky; top: 0; z-index: 1;
}
.modal-header h2 { margin: 0; font-size: 15px; }
.close-btn {
  background: transparent; border: 0; color: var(--fg-muted);
  font-size: 24px; cursor: pointer; padding: 0 4px;
}
.close-btn:hover { color: var(--fg); }
.modal-body { padding: 20px; }
.modal-section { margin-bottom: 20px; }
.modal-section h4 {
  margin: 0 0 8px 0; font-size: 11px;
  text-transform: uppercase; letter-spacing: 1px;
  color: var(--fg-muted);
}
.modal-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px 20px; font-size: 12px;
}
.modal-section ul { margin: 0; padding-left: 16px; font-size: 12px; }
.modal-section li { margin-bottom: 3px; }

/* NAV chart canvas */
#nav-chart {
  width: 100%;
  max-width: 1600px;
  height: auto;
  border: 1px solid var(--border);
  border-radius: 6px;
  display: block;
}

/* Footer */
footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex; justify-content: space-between;
  color: var(--fg-muted);
  font-size: 10px;
}

/* ── Responsive ──────────────────────────────────────────────────────
 * 2026-05-22: comprehensive mobile rules. Three breakpoints:
 *   ≤1024px : tablet / small laptop — relax max-widths
 *   ≤768px  : tablet portrait — collapse nav, table scroll
 *   ≤480px  : phone — single-column cards, smaller fonts, full-screen modal
 */

/* Tables get horizontal scroll on narrow screens (don't break layout) */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

@media (max-width: 1024px) {
  main { padding: 14px 16px; max-width: 100%; }
  #nav-chart { max-width: 100%; }
}

@media (max-width: 768px) {
  body { font-size: 12px; }
  main { padding: 10px; }
  /* On mobile, sticky header eats vertical space when nav wraps.
     Allow it to scroll away. */
  header { position: static; }
  table thead th { top: 0; }
  header {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
    padding: 10px 12px;
  }
  .brand { font-size: 14px; letter-spacing: 1px; }
  .brand .meta { display: block; margin-left: 0; }
  nav {
    flex-wrap: wrap;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
    gap: 4px;
  }
  nav a {
    padding: 5px 10px;
    font-size: 11px;
  }
  .cards {
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 8px;
  }
  .card { padding: 10px 12px; }
  .value-big { font-size: 18px; }
  section { margin-bottom: 18px; }
  section h2 { font-size: 14px; }
  section h3 { font-size: 12px; }

  /* Tables: wrap parent <section> with horizontal scroll */
  section table,
  .table-wrap table { min-width: 520px; }
  section:has(> table),
  section:has(> .table-wrap) {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  table thead th { position: static; }  /* sticky breaks on touch scroll */
  table thead th, table tbody td {
    padding: 6px 8px;
    font-size: 11px;
  }

  /* Modal: near-full-screen on phone */
  .modal { padding: 8px; }
  .modal-content { max-height: 92vh; }
  .modal-header { padding: 10px 14px; }
  .modal-body { padding: 14px; }
  .modal-grid { grid-template-columns: 1fr; gap: 6px 0; }

  footer { padding: 12px; flex-wrap: wrap; gap: 4px; }
}

@media (max-width: 480px) {
  .cards { grid-template-columns: 1fr; }  /* single column */
  .brand { font-size: 13px; }
  nav a { padding: 4px 8px; font-size: 10px; }
  .verdict-pill, .pill { font-size: 9px; padding: 1px 6px; }
  /* Hide some less-critical columns on phone if marked .hide-mobile */
  .hide-mobile { display: none; }
}
