:root {
  color-scheme: light;
  --bg: #f5f7fa;
  --panel: #ffffff;
  --panel-hover: #eef2f6;
  --border: #d0d7de;
  --text: #1f2328;
  --muted: #59636e;
  --accent: #0969da;
  --accent-dim: rgba(9, 105, 218, 0.10);
  --buy: #1a7f37;
  --sell: #cf222e;
  --exch: #9a6700;
  --purple: #6f42c1;
  --amber: #9a3412;
  --chamber-senate: #9a3412;
  --chamber-exec: #1a7f37;
  --rank-1: #9a6700;
  --rank-2: #6e7781;
  --rank-3: #a3521e;
  --row-hover: rgba(31, 35, 40, 0.05);
  --party-D: #0969da;
  --party-R: #cf222e;
  --party-I: #59636e;
  --party-G: #1a7f37;
  --party-L: #8250df;
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px;
  --radius: 10px; --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(31,35,40,.04), 0 6px 18px rgba(31,35,40,.06);
  --topbar-h: 52px;
}

:root[data-theme='dark'] {
  color-scheme: dark;
  --bg: #0d1117;
  --panel: #161b22;
  --panel-hover: #1c2230;
  --border: #30363d;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #58a6ff;
  --accent-dim: rgba(88, 166, 255, 0.12);
  --buy: #3fb950;
  --sell: #f85149;
  --exch: #d29922;
  --purple: #a371f7;
  --amber: #ff9f6e;
  --chamber-senate: #db6d28;
  --chamber-exec: #2f9e44;
  --rank-1: #f5c518;
  --rank-2: #c0c0c0;
  --rank-3: #cd7f32;
  --row-hover: rgba(255, 255, 255, 0.02);
  --party-D: #4d8cff;
  --party-R: #ff5a5f;
  --party-I: #e6edf3;
  --party-G: #3fb950;
  --party-L: #a371f7;
  --shadow: 0 1px 0 rgba(0,0,0,.4), 0 6px 18px rgba(0,0,0,.28);
}

.num { font-variant-numeric: tabular-nums; }
.pos { color: var(--buy); }
.neg { color: var(--sell); }

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

header.topbar {
  display: flex;
  align-items: center;
  gap: 20px;
  /* The extra env() term is a no-op in ordinary browsers; on an iPhone
     home-screen web app it keeps the bar clear of the status-bar strip. */
  padding: calc(12px + env(safe-area-inset-top, 0px)) 20px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
header.topbar .brand { font-weight: 700; font-size: 16px; }
header.topbar nav { display: flex; gap: 2px; flex-wrap: wrap; align-items: center; }

/* top-level nav items: Dashboard link + dropdown group labels */
.navlink, .navgroup-label {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 6px 10px; border-radius: 6px; color: var(--muted);
  background: none; border: 0; font: inherit; line-height: 1; cursor: pointer; white-space: nowrap;
}
.navlink:hover, .navgroup-label:hover { color: var(--text); background: var(--accent-dim); text-decoration: none; }
.navlink.active, .navgroup-label.active { color: var(--text); font-weight: 600; }
.navgroup .caret { font-size: 9px; opacity: .6; }

/* dropdown */
.navgroup { position: relative; }
.navgroup-menu {
  position: absolute; top: 100%; left: 0; min-width: 188px;
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 6px; z-index: 30;
  display: none; flex-direction: column; gap: 1px;
}
.navgroup:hover .navgroup-menu, .navgroup:focus-within .navgroup-menu { display: flex; }
.navgroup-menu a { display: block; padding: 7px 10px; border-radius: 6px; color: var(--text); font-weight: 400; white-space: nowrap; }
.navgroup-menu a:hover { background: var(--accent-dim); text-decoration: none; }
.navgroup-menu a.active { color: var(--accent); font-weight: 600; }

main { padding: 20px; max-width: 1200px; margin: 0 auto; }

h1 { font-size: 20px; margin: 0 0 16px; }
h2 { font-size: 16px; margin: 24px 0 12px; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.card .big { font-size: 26px; font-weight: 700; }
.card .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }

.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; min-width: 0; overflow-wrap: break-word; }
.panel > *, .card > *, .grid-2 > *, .grid-3 > * { min-width: 0; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
/* header alignment; sort affordance only where sorting exists */
th { text-align: left; color: var(--muted); font-weight: 600; white-space: nowrap; }
.sortable th { cursor: pointer; user-select: none; }
tr:hover td { background: var(--row-hover); }

.tag { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.tag.buy { background: rgba(63,185,80,.15); color: var(--buy); }
.tag.sell { background: rgba(248,81,73,.15); color: var(--sell); }
.tag.exch { background: rgba(210,153,34,.15); color: var(--exch); }
.tag.other { background: rgba(139,148,158,.15); color: var(--muted); }
.tag.src { background: rgba(88,166,255,.12); color: var(--accent); font-weight: 500; }

.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.filters input, .filters select {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 13px;
}
.filters input { min-width: 160px; }

.party {
  display: inline-block;
  width: 18px; height: 18px; line-height: 18px;
  text-align: center; border-radius: 4px;
  font-size: 11px; font-weight: 700; vertical-align: middle;
}
.party-R { background: rgba(255,90,95,.18); color: var(--party-R); }
.party-D { background: rgba(77,140,255,.18); color: var(--party-D); }
.party-I { background: rgba(230,237,243,.16); color: var(--party-I); }
.party-G { background: rgba(63,185,80,.18); color: var(--party-G); }
.party-L { background: rgba(163,113,247,.18); color: var(--party-L); }

/* inline party-colored text (e.g. party-split counts) */
.pc-D { color: var(--party-D); }
.pc-R { color: var(--party-R); }
.pc-I { color: var(--party-I); }
.pc-G { color: var(--party-G); }

.volbar-wrap { display: flex; align-items: center; gap: 8px; min-width: 200px; }
.volbar { height: 10px; background: linear-gradient(90deg, #1f6feb, #58a6ff); border-radius: 3px; min-width: 2px; }
.volbar-label { font-variant-numeric: tabular-nums; color: var(--text); white-space: nowrap; }

/* AI insights panel */
.ai-panel { margin-bottom: 20px; border-left: 1px solid var(--accent); }
.ai-head { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.ai-title { font-weight: 700; }
.ai-windows { display: flex; gap: 4px; }
.ai-ts { margin-left: auto; font-size: 12px; }
.ai-summary p { margin: 6px 0; }
.ai-obs { margin: 10px 0 0; padding-left: 18px; }
.ai-obs li { margin: 5px 0; }
.ai-disclaimer { margin-top: 12px; font-size: 11px; opacity: .8; }
.btn-sm { background: var(--bg); border: 1px solid var(--border); color: var(--muted); border-radius: 5px; padding: 2px 8px; font-size: 12px; cursor: pointer; }
/* Long lists show a page of rows and a button that reveals the next page, so a
   phone does not turn one table into eighty screens of scrolling. */
.table-more { display: flex; justify-content: center; margin: 12px 0 4px; }
.btn-sm.active { color: var(--text); border-color: var(--accent); }
.btn.active { border-color: var(--accent); color: var(--text); }

/* signal badges */
.tag.sig { background: rgba(139,148,158,.15); color: var(--muted); margin-right: 4px; }
.tag.sig-cluster_buy { background: rgba(63,185,80,.18); color: var(--buy); }
.tag.sig-large { background: rgba(88,166,255,.18); color: var(--accent); }
.tag.sig-options { background: rgba(210,153,34,.18); color: var(--exch); }
.tag.sig-late_disclosure { background: rgba(248,81,73,.16); color: var(--sell); }
.tag.sig-anomaly { background: rgba(163,113,247,.18); color: var(--purple); }
.tag.sig-conviction { background: rgba(130,80,223,.18); color: var(--party-L); }
.lag { font-size: 11px; margin-left: 4px; }
.lag-late { color: var(--sell); font-weight: 600; }

.muted { color: var(--muted); }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.pager { display: flex; gap: 8px; align-items: center; margin-top: 14px; }
.btn {
  background: var(--bg); border: 1px solid var(--border); color: var(--text);
  padding: 6px 12px; border-radius: 6px; cursor: pointer;
}
.btn:disabled { opacity: .4; cursor: default; }
.loading { color: var(--muted); padding: 40px; text-align: center; }
.note { color: var(--muted); font-size: 12px; margin-top: 6px; }
/* Upstream messages contain URLs, host names and error strings with no spaces in
   them. Without this they push the whole page sideways on a phone. */
.note, .muted, .src, .news-list, .news-list > div { overflow-wrap: anywhere; }
.chamber-house { color: var(--purple); }
.chamber-senate { color: var(--chamber-senate); }
.chamber-executive { color: var(--chamber-exec); }

/* ============ redesign polish ============ */
.card, .panel { box-shadow: var(--shadow); transition: background .12s, box-shadow .12s, transform .12s; }
.card:hover { background: var(--panel-hover); }
.card .big { letter-spacing: -.01em; line-height: 1; }
.delta { font-size: 12px; margin-top: 6px; }
.delta.pos::before { content: "▲ "; }
.delta.neg::before { content: "▼ "; }

/* sticky table headers. The offset must be 0: the wide-table panel scrolls
   horizontally, which makes the PANEL the sticky scrollport, so a viewport
   offset (top: var(--topbar-h)) displaces the header by a row inside the panel
   instead of pinning it under the topbar. Pinned-while-scrolling headers need
   a split-header redesign, not a bigger offset. */
thead th { position: sticky; top: 0; background: var(--panel); z-index: 2; }

/* focus-visible everywhere */
a:focus-visible, .btn:focus-visible, .btn-sm:focus-visible, input:focus-visible, select:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.navlink.active, .navgroup-label.active { box-shadow: inset 0 -2px 0 var(--accent); }

/* skeleton shimmer */
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
.skel { background: linear-gradient(90deg, var(--panel), var(--panel-hover), var(--panel)); background-size: 200% 100%;
  animation: shimmer 1.4s infinite; border-radius: var(--radius-sm); display: block; height: 14px; }
.skel-row { height: 36px; margin: 0; border-bottom: 1px solid var(--border); }

/* empty state */
.empty { text-align: center; color: var(--muted); padding: 40px 16px; }
.empty .glyph { font-size: 28px; opacity: .5; display: block; margin-bottom: 8px; }

/* dashboard grids */
.grid-2 { display: grid; grid-template-columns: 1.4fr 1fr; gap: var(--s4); margin-top: var(--s5); margin-bottom: var(--s5); }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s4); margin-top: var(--s5); }
@media (max-width: 900px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }
.panel h2:first-child, .panel h3:first-child { margin-top: 0; }
.panel h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 0 0 12px; }
.panel h4 { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; margin: 16px 0 8px; }

/* conviction meter */
.conv { display: inline-flex; align-items: center; gap: 6px; }
.conv-bar { width: 46px; height: 6px; border-radius: 3px; background: var(--border); overflow: hidden; }
.conv-bar > span { display: block; height: 100%; }
.conv-high > span { background: var(--buy); } .conv-high .conv-num { color: var(--buy); }
.conv-mid > span { background: var(--exch); } .conv-mid .conv-num { color: var(--exch); }
.conv-low > span { background: var(--muted); } .conv-low .conv-num { color: var(--muted); }
.conv-num { font-variant-numeric: tabular-nums; font-weight: 600; font-size: 12px; }

/* global search palette */
.search-wrap { margin-left: auto; position: relative; }
.search-input { background: var(--bg); border: 1px solid var(--border); color: var(--text); border-radius: 999px;
  padding: 6px 12px; width: 220px; font-size: 13px; }
.search-results { position: absolute; top: 38px; right: 0; width: 320px; background: var(--panel);
  border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); z-index: 20; max-height: 60vh; overflow: auto; }
.search-results .sr-group { padding: 6px 12px; font-size: 11px; color: var(--muted); text-transform: uppercase; }
.search-results a { display: block; padding: 8px 12px; color: var(--text); }
.search-results a:hover, .search-results a.hl { background: var(--accent-dim); text-decoration: none; }

/* star toggle */
.star { background: none; border: none; cursor: pointer; color: var(--muted); font-size: 15px; padding: 0 4px; }
.star.on { color: var(--exch); }

/* ideas cards */
.idea-card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: var(--s4); box-shadow: var(--shadow); }
.idea-card .reason { color: var(--muted); font-size: 12px; margin-top: 4px; }
.disclaimer-banner { background: var(--accent-dim); border: 1px solid var(--border); border-left: 1px solid var(--accent);
  border-radius: var(--radius-sm); padding: 10px 14px; font-size: 12px; color: var(--muted); margin-bottom: var(--s4); }

/* rank medals */
.rank { display: inline-block; width: 22px; text-align: center; font-weight: 700; color: var(--muted); }
.rank-1 { color: var(--rank-1); } .rank-2 { color: var(--rank-2); } .rank-3 { color: var(--rank-3); }

/* committee chips */
.chip { display: inline-block; background: var(--bg); border: 1px solid var(--border); border-radius: 999px;
  padding: 2px 10px; font-size: 11px; color: var(--muted); margin: 2px 4px 2px 0; }
.tag.sig-cluster_sell { background: rgba(248,81,73,.18); color: var(--sell); }
.tag.sig-conflict { background: rgba(219,109,40,.20); color: var(--amber); }
.tag.sig-corp_event { background: rgba(88,166,255,.18); color: var(--accent); }
.tag.sig-legislative_context { background: rgba(77,140,255,.18); color: var(--party-D); }
.live-dot { color: var(--buy); font-size: 8px; vertical-align: middle; margin-left: 3px; animation: pulse 2s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .3; } }
.sentiment-bar { display:inline-block; height:8px; border-radius:3px; }
.news-list a { display:block; padding:6px 0; border-bottom:1px solid var(--border); }
.news-list .src { color: var(--muted); font-size: 11px; }
/* runtime config switches */
.settings-list { display: flex; flex-direction: column; gap: 12px; }
.setting-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px;
  padding-bottom: 10px; border-bottom: 1px solid var(--border); }
.setting-row:last-child { border-bottom: 0; padding-bottom: 0; }
.setting-row > label { min-width: 220px; }
.setting-note { flex: 1 1 260px; font-size: 12px; }
.watch-threshold { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; }
.watch-threshold input { width: 58px; }
.status-warn { border-color: rgba(248,81,73,.45); }
.row-active td { background: var(--accent-dim); }
.linklike { color: var(--accent); background: none; border: 0; padding: 0; font: inherit; cursor: pointer; text-align: left; }
.linklike:hover { text-decoration: underline; }
.compact-row { display: grid; grid-template-columns: minmax(120px, 1fr) auto auto; gap: 10px; align-items: baseline; padding: 5px 0; border-bottom: 1px solid var(--border); }
.metric-row { display: grid; grid-template-columns: 1fr auto auto; gap: 12px; padding: 6px 0; border-bottom: 1px solid var(--border); align-items: baseline; }
.policy-filter-panel { margin-bottom: var(--s4); }
.event-filter-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.event-filter-row select { margin-left: auto; background: var(--bg); border: 1px solid var(--border); color: var(--text); border-radius: var(--radius-sm); padding: 5px 8px; }
.policy-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.policy-row:last-child { border-bottom: 0; }
.score-card { display: grid; grid-template-columns: 130px 1fr; gap: 14px; align-items: center; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px; margin: 8px 0 14px; }
.score-card .big { font-size: 30px; font-weight: 800; }
.score-high { border-color: rgba(248,81,73,.55); }
.score-medium { border-color: rgba(210,153,34,.55); }
.score-low { border-color: rgba(88,166,255,.45); }
.research-alert { display: block; width: 100%; padding: 7px 0; border-bottom: 1px solid var(--border); }
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.62); display: flex; justify-content: center; align-items: flex-start; padding: 64px 16px 24px; z-index: 50; overflow: auto; }
.modal { width: min(920px, 100%); max-height: calc(100vh - 88px); overflow: auto; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 18px 60px rgba(0,0,0,.55); padding: 18px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; gap: 16px; border-bottom: 1px solid var(--border); padding-bottom: 10px; margin-bottom: 14px; }
.modal-head h2 { margin: 0; }
.prov-title { font-size: 16px; margin-bottom: 14px; }
.prov-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; margin: 10px 0 14px; }
.prov-field { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 10px; overflow-wrap: anywhere; }
.raw-excerpt, .recon-note pre { white-space: pre-wrap; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px; color: var(--muted); max-height: 220px; overflow: auto; }
.recon-note { border-top: 1px solid var(--border); padding-top: 10px; margin-top: 10px; }

/* ============ trade dossier + conflict score v2 ============ */
.modal-head-actions { display: flex; gap: 8px; align-items: center; }

.dossier-head { margin: 4px 0 16px; }
.dossier-line { font-size: 15px; }
.dossier-dates { font-size: 12px; margin-top: 4px; }
.dossier-disclaimer { margin-top: 24px; border-top: 1px solid var(--border); padding-top: 12px; }

/* provenance / credibility badges */
.prov-badges { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.prov-badge { display: inline-flex; align-items: center; padding: 2px 9px; border-radius: 999px;
  font-size: 11px; font-weight: 600; border: 1px solid var(--border); background: var(--bg); color: var(--muted); }
.prov-primary { border-color: rgba(63,185,80,.5); color: var(--buy); background: rgba(63,185,80,.10); }
.prov-comparison { border-color: rgba(210,153,34,.5); color: var(--exch); background: rgba(210,153,34,.10); }
.prov-context { border-color: rgba(88,166,255,.45); color: var(--accent); background: rgba(88,166,255,.10); }
.prov-link { color: var(--accent); }
.prov-link:hover { text-decoration: none; border-color: var(--accent); }
h3 .prov-badge { margin-left: 6px; vertical-align: middle; }

/* "why this is notable" callout */
.why-notable { background: var(--accent-dim); border: 1px solid var(--border); border-left: 1px solid var(--accent);
  border-radius: var(--radius-sm); padding: 12px 16px; margin: 16px 0; }
.why-notable .why-title { font-weight: 700; margin-bottom: 6px; }
.why-notable ul { margin: 0; padding-left: 18px; }
.why-notable li { margin: 4px 0; }
.why-compact { margin: 12px 0; }

/* conflict score gauge + transparent component breakdown */
.cs-head { display: flex; align-items: center; gap: 16px; }
.cs-gauge { display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-width: 78px; height: 78px; border-radius: 50%; border: 4px solid var(--border); }
.cs-num { font-size: 26px; font-weight: 800; line-height: 1; color: var(--muted); }
.cs-of { font-size: 10px; color: var(--muted); }
.cs-title { font-weight: 700; }
.cs-summary { font-size: 12px; margin-top: 4px; }
.cs-pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11px;
  text-transform: uppercase; letter-spacing: .04em; }
.cs-pill-high { background: rgba(248,81,73,.18); color: var(--sell); }
.cs-pill-medium { background: rgba(210,153,34,.18); color: var(--exch); }
.cs-pill-low { background: rgba(88,166,255,.18); color: var(--accent); }
.cs-pill-none { background: rgba(139,148,158,.15); color: var(--muted); }
.cs-high .cs-gauge { border-color: var(--sell); } .cs-high .cs-num { color: var(--sell); }
.cs-medium .cs-gauge { border-color: var(--exch); } .cs-medium .cs-num { color: var(--exch); }
.cs-low .cs-gauge { border-color: var(--accent); } .cs-low .cs-num { color: var(--accent); }

.cs-components { margin-top: 14px; display: flex; flex-direction: column; gap: 12px; }
.cs-row.off { opacity: .5; }
.cs-row-top { display: flex; justify-content: space-between; align-items: baseline; }
.cs-label { font-size: 13px; font-weight: 600; }
.cs-pts { font-size: 12px; }
.cs-bar { height: 6px; border-radius: 3px; background: var(--border); overflow: hidden; margin: 4px 0 3px; }
.cs-bar > span { display: block; height: 100%; background: var(--muted); transition: width .3s; }
.cs-high .cs-row.on .cs-bar > span { background: var(--sell); }
.cs-medium .cs-row.on .cs-bar > span { background: var(--exch); }
.cs-low .cs-row.on .cs-bar > span { background: var(--accent); }
.cs-detail { font-size: 11px; }
.cs-method { margin-top: 12px; }
.cs-flag { color: var(--sell); font-weight: 600; font-size: 13px; margin: 0 0 8px; }

/* compliance grade badge */
.grade { display: inline-block; min-width: 24px; padding: 1px 8px; border-radius: 6px; font-weight: 800;
  background: rgba(139,148,158,.15); }
.grade.pos { color: var(--buy); background: rgba(63,185,80,.16); }
.grade.neg { color: var(--sell); background: rgba(248,81,73,.16); }
.grade.muted { color: var(--exch); background: rgba(210,153,34,.16); }

/* sector-rotation heatmap */
table.heatmap td, table.heatmap th { padding: 6px 8px; font-size: 12px; }
table.heatmap td:first-child { font-weight: 600; }
table.heatmap td { transition: background .15s; }

@media (max-width: 700px) {
  header.topbar { flex-wrap: wrap; gap: 6px 10px; padding: calc(8px + env(safe-area-inset-top, 0px)) calc(12px + env(safe-area-inset-right, 0px)) 8px calc(12px + env(safe-area-inset-left, 0px)); }
  header.topbar nav {
    order: 3; width: 100%; flex-wrap: nowrap; gap: 0;
    overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch;
    /* A soft edge tells the reader the nav continues sideways without adding chrome. */
    -webkit-mask-image: linear-gradient(90deg, #000 0%, #000 90%, transparent 100%);
    mask-image: linear-gradient(90deg, #000 0%, #000 90%, transparent 100%);
  }
  header.topbar nav::-webkit-scrollbar { display: none; }
  header.topbar nav .navgroup-menu { position: static; width: 100%; box-shadow: none; border: 0; padding: 0 8px 8px; }
  header.topbar nav .navgroup.open .navgroup-menu { display: flex; }
  header.topbar .brand { font-size: 15px; }
  .navlink, .navgroup-label { padding: 8px; }
  .search-wrap { margin-left: auto; max-width: calc(100vw - 24px); }
  .search-input { width: min(190px, calc(100vw - 145px)); min-width: 110px; }
  .search-results { width: min(320px, calc(100vw - 24px)); }
  main { padding: 12px; }
  h1 { font-size: 18px; margin-bottom: 12px; }
  h2 { font-size: 15px; margin: 18px 0 8px; }
  .filters input { min-width: 0; max-width: 100%; }
}

.chart-controls { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.chart-note { color: var(--muted); font-size: 12px; line-height: 1.5; margin: -4px 0 12px; }
.trade-table { max-width: 100%; padding: 0; overflow-x: auto; }
.tag.sig { cursor: help; }

/* Dense trade tables keep their in-panel scroll, with the row identity
   anchored: the first column stays put and a divider shadow separates it
   from the scrolling content. The sticky cell must follow row hover — a
   pinned white cell on a tinted row reads as a seam. */
.trade-compact th, .trade-compact td { padding: 5px 7px; }
.trade-compact thead th:first-child, .trade-compact tbody td:first-child {
  position: sticky; left: 0; background: var(--panel); z-index: 3;
  box-shadow: 6px 0 8px -6px color-mix(in srgb, var(--text) 22%, transparent);
}
.trade-compact tbody tr:hover td:first-child { background: var(--row-hover); }
.trade-compact:not(.at-end) {
  box-shadow: inset -40px 0 28px -26px color-mix(in srgb, var(--text) 22%, transparent);
}

/* Column-visibility menu: nothing is deleted, only hidden, and the choice
   persists in the browser. The toolbar row sits above the table panel so
   the dropdown is not clipped by the panel's overflow. */
.table-toolbar { display: flex; justify-content: flex-end; margin-bottom: 6px; }
.col-menu { position: relative; }
.col-menu-btn { list-style: none; cursor: pointer; }
.col-menu-btn::-webkit-details-marker { display: none; }
.col-menu-list {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 210px; z-index: 20;
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius-sm);
  box-shadow: var(--shadow); padding: 8px; display: flex; flex-direction: column; gap: 4px;
}
.col-menu-btn::after { content: " ▾"; font-size: 10px; }
.col-menu[open] .col-menu-btn::after { content: " ▴"; }
.col-menu-item { display: flex; align-items: center; gap: 8px; padding: 5px 6px; font-size: 13px; border-radius: 6px; }
.col-menu-item:hover { background: var(--row-hover); }
.col-menu-item input { width: auto; min-height: 0; margin: 0; }

/* Source health strip on the dashboard: status, not content. */
.health-strip { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 16px; }
.health-item {
  flex: 1 1 340px; display: flex; align-items: baseline; gap: 12px;
  background: var(--panel); border: 1px solid var(--border);
  padding: 10px 14px; box-shadow: var(--shadow); border-radius: var(--radius);
}
.health-item .label { margin: 0; }
.health-item .num { font-size: 18px; font-weight: 700; }
.health-item .note { margin-left: auto; font-size: 12px; }

/* Secondary cell text, one class instead of inline repeats. */
.cell-sub { font-size: 11px; }
.live-ago { display: block; font-variant-numeric: tabular-nums; color: var(--muted); font-size: 11px; }
.snapshot-age { margin: -6px 0 14px; color: var(--muted); font-size: 13px; }
.snapshot-age strong { color: var(--text); font-variant-numeric: tabular-nums; }

/* Ticker-detail source/action cell. */
.trade-actions { display: flex; align-items: center; gap: 6px; }
/* Signal badges wrap instead of forcing the table wider. */
.trade-compact td[data-label='Signals'] { max-width: 200px; white-space: normal; }

/* tap-friendly explanations (see components/HelpTip.jsx) */
.help-tip { display: inline-block; vertical-align: middle; }
.help-tip > summary { cursor: pointer; list-style: none; display: inline-block; }
.help-tip > summary.conv { display: inline-flex; }
.help-tip > summary::-webkit-details-marker { display: none; }
.help-tip > summary::marker { content: ''; }
.help-tip > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--radius-sm); }
.help-popover { display: block; margin-top: 4px; padding: 6px 9px; background: var(--bg);
  border: 1px solid var(--border); border-radius: var(--radius-sm); color: var(--text);
  font-size: 11px; line-height: 1.45; font-weight: 400; text-transform: none; letter-spacing: normal;
  white-space: normal; width: 260px; max-width: min(280px, 68vw); text-align: left; }
/* The explanation is hidden until the disclosure is opened. Chrome hides it
   through ::details-content, but Firefox and Safari rely on the browser's own
   "display: none" rule — which the block display above would override. */
.help-tip:not([open]) > .help-popover { display: none; }
.help-q { display: inline-flex; align-items: center; justify-content: center; width: 15px; height: 15px;
  border-radius: 999px; border: 1px solid var(--border); background: var(--bg); color: var(--muted);
  font-size: 10px; font-weight: 700; line-height: 1; }
.help-tip:hover > summary .help-q, .help-tip[open] > summary .help-q { color: var(--text); border-color: var(--muted); }

/* provenance detail lists (see components/TradeProvenance.jsx) */
.detail-list { margin: 4px 0 10px; font-size: 12px; }
.detail-list > div { display: flex; gap: 8px; padding: 2px 0; border-bottom: 1px solid var(--border); }
.detail-list > div:last-child { border-bottom: 0; }
.detail-list dt { flex: 0 0 38%; color: var(--muted); }
.detail-list dd { margin: 0; flex: 1; overflow-wrap: anywhere; }
.signal-details section { margin-bottom: 10px; }

/* global search status line */
.search-message { padding: 10px 12px; color: var(--muted); font-size: 12px; }
.search-results a[aria-selected='true'] { background: var(--accent-dim); }
.btn-sm:disabled { cursor: wait; opacity: .55; }
.theme-toggle { flex-shrink: 0; }
.fatal-error { max-width: 900px; margin: 0 auto; padding: 24px; color: var(--text); }
.fatal-error p { color: var(--muted); }
.fatal-error-detail { white-space: pre-wrap; overflow-wrap: anywhere; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px; color: var(--sell); }

@media (max-width: 900px) {
  .ai-head { flex-wrap: wrap; }
  .ai-ts { width: 100%; margin-left: 0; }
  :is(.trade-table, .stack-table) { padding: 8px; overflow-x: visible; }
  :is(.trade-table, .stack-table) :is(table, tbody, tr, td) { display: block; }
  :is(.trade-table, .stack-table) thead { display: none; }
  :is(.trade-table, .stack-table) tr { padding: 10px 4px; border-bottom: 1px solid var(--border); }
  :is(.trade-table, .stack-table) tr:last-child { border-bottom: 0; }
  :is(.trade-table, .stack-table) td { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 4px 0; border: 0; text-align: left; white-space: normal; }
  :is(.trade-table, .stack-table) td::before { content: attr(data-label); flex: 0 0 82px; color: var(--muted); font-size: 11px; font-weight: 600; }
  :is(.trade-table, .stack-table) td > *:not(.star) { min-width: 0; flex: 1 1 auto; overflow-wrap: break-word; }
  :is(.trade-table, .stack-table) td:empty, :is(.trade-table, .stack-table) td:only-child:empty { display: none; }
  :is(.trade-table, .stack-table) td:only-child::before { content: none; }
  :is(.trade-table, .stack-table) td[data-label='Details'] button { width: 100%; }
  :is(.trade-table, .stack-table) td .help-tip { display: block; width: 100%; text-align: left; }
  :is(.trade-table, .stack-table) td .help-popover { max-width: none; }

  /* Any table the labeler marked becomes a stack of labelled cards. */
  table.resp-table { display: block; width: 100%; }
  table.resp-table thead { display: none; }
  table.resp-table tbody { display: block; }
  table.resp-table tr { display: block; padding: 10px 4px; border-bottom: 1px solid var(--border); }
  table.resp-table tr:last-child { border-bottom: 0; }
  table.resp-table td { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 4px 0; border: 0; text-align: left; white-space: normal; }
  table.resp-table td::before { content: attr(data-label); flex: 0 0 82px; color: var(--muted); font-size: 11px; font-weight: 600; }
  table.resp-table td:not([data-label])::before, table.resp-table td:only-child::before { content: none; }
  table.resp-table td > *:not(.star) { min-width: 0; flex: 1 1 auto; overflow-wrap: break-word; }
  table.resp-table td:empty, table.resp-table td:only-child:empty { display: none; }
  table.resp-table td .help-tip { display: block; width: 100%; text-align: left; }
  table.resp-table td .help-popover { max-width: none; }
}

.latest-mobile, .mobile-card-list { display: none; }

/* Dense trade tables get a curated phone layout: one card per trade with the
   two dates and the key comparison metrics up top, instead of the generic
   one-cell-per-row fallback. */
@media (max-width: 900px) {
  .trade-table.trade-compact > table { display: none; }
  .trade-table.trade-compact .latest-mobile { display: block; }
  .latest-item { padding: 10px 2px; border-bottom: 1px solid var(--border); }
  .latest-item:last-child { border-bottom: 0; }
  .latest-dates { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 6px; }
  .latest-date { min-width: 0; display: flex; flex-wrap: wrap; align-items: baseline; column-gap: 4px; }
  .latest-date > span:first-child { flex-basis: 100%; color: var(--muted); font-size: 12px; font-weight: 600; }
  .latest-date strong { font-size: 14px; overflow-wrap: break-word; }
  .latest-who { display: flex; flex-wrap: wrap; align-items: center; gap: 3px; font-size: 16px; line-height: 1.35; overflow-wrap: break-word; }
  .latest-member { min-width: 0; overflow-wrap: break-word; }
  .latest-sep { color: var(--muted); }
  .latest-ticker { min-width: 0; overflow-wrap: break-word; }
  .latest-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; margin-top: 6px; }
  .latest-metrics { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 8px; color: var(--muted); }
  .latest-metric { display: inline-flex; align-items: center; gap: 5px; min-width: 0; }
  .latest-metric > span:first-child { color: var(--muted); font-size: 11px; font-weight: 600; }
  .latest-actions { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 8px; }
  .mobile-card-list { display: block; }
  .options-table, .leaderboard-table, .recon-table, .status-table, .research-table,
  .quar-table, .discover-pos-table, .discover-owner-table, .committees-table { display: none; }
  .latest-item.row-active { background: var(--accent-dim); }
  .mobile-details { margin-top: 8px; color: var(--muted); }
  .mobile-details summary { cursor: pointer; color: var(--accent); min-height: 32px; }
  .mobile-details dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 10px; margin: 8px 0 0; font-size: 12px; }
  .mobile-details dt { color: var(--muted); }
  .mobile-details dd { margin: 0; overflow-wrap: break-word; }
}

@media (prefers-reduced-motion: reduce) {
  .card, .panel, .cs-bar > span { transition: none; }
  .skel { animation: none; }
}

/* ============ touch targets ============
   A fingertip needs roughly 44px to hit a control reliably, so on a touch
   device the buttons, form fields and navigation links are sized for that.
   The small inline explanation chips get the 24px minimum instead: making
   them 44px tall would break the table density they exist to preserve.
   The 16px font on the fields also stops iOS Safari from zooming in when a
   field is focused. */
@media (pointer: coarse) {
  .navlink, .navgroup-label { min-height: 44px; padding: 10px 12px; }
  .navgroup-menu a { min-height: 44px; display: flex; align-items: center; }
  .btn, .btn-sm { min-height: 44px; min-width: 44px; padding: 8px 14px; }
  input, select, textarea { min-height: 44px; font-size: 16px; }
  .search-input { min-height: 44px; }
  .star { min-width: 44px; min-height: 44px; display: inline-flex; align-items: center; justify-content: center; }
  .help-tip > summary { min-width: 24px; min-height: 24px; }
  .help-tip > summary.conv { align-items: center; }
  /* A link that looks like a chip has to be as tall as a chip; row actions are
     standalone actions, so they get the full 44px target. */
  a.tag { min-height: 24px; display: inline-flex; align-items: center; }
  .latest-actions a.tag { min-height: 44px; }
  /* News/event link rows are primary interactive content in several panels. */
  .news-list a { min-height: 44px; display: flex; align-items: center; }
}
