/* ererson terminal — layout and components. Colours come from tokens.css. */

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

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: var(--fs-md);
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}

body { overflow: hidden; }

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0; font-weight: 600; }

.num, .mono { font-family: var(--font-num); font-variant-numeric: tabular-nums; }
.up { color: var(--up); }
.down { color: var(--down); }
.muted { color: var(--muted); }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

:focus { outline: none; }
:focus-visible { box-shadow: var(--focus); border-radius: var(--radius); }

/* ---------- App grid ---------- */

.app {
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr) auto;
  height: 100vh;
  height: 100dvh;
  min-width: 0;
}

/* Stock list view: the list takes the place of instrument, tabs and chart */
.app[data-view="list"] { grid-template-rows: auto minmax(0, 1fr) auto; }
.app[data-view="list"] .instrument,
.app[data-view="list"] .tabbar,
.app[data-view="list"] .workspace,
.app[data-view="list"] #asOf { display: none; }
#listBtn[aria-pressed="true"] { color: var(--text); background: var(--panel-2); }
.brand { cursor: pointer; }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  height: var(--tap); padding: 0 var(--s3);
  border: 1px solid var(--border-strong); border-radius: var(--radius);
  background: var(--panel); color: var(--text);
  font-size: var(--fs-sm); font-weight: 500; white-space: nowrap;
  transition: background var(--t), border-color var(--t);
}
.btn:hover { background: var(--hover); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { color: var(--text); background: var(--hover); }
.btn-accent { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-accent:hover { background: var(--accent); filter: brightness(1.08); }
.btn-danger { background: var(--down); border-color: var(--down); color: #fff; }
.btn-small { height: 28px; padding: 0 var(--s2); }

.icon-btn {
  display: inline-grid; place-items: center;
  width: var(--tap); height: var(--tap);
  border: 1px solid transparent; border-radius: var(--radius);
  background: transparent; color: var(--muted);
}
.icon-btn:hover { background: var(--hover); color: var(--text); }

.badge {
  display: inline-flex; align-items: center; gap: var(--s1);
  height: 24px; padding: 0 var(--s2);
  border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--muted); font-size: var(--fs-xs); font-family: var(--font-num);
  white-space: nowrap;
}
.badge::before {
  content: ''; width: 6px; height: 6px; border-radius: 50%; background: var(--up);
}
.badge.badge-stale, .badge-amber { color: var(--amber); border-color: var(--amber); background: var(--amber-soft); }
.badge.badge-stale::before { background: var(--amber); }
.badge-amber::before { display: none; }
.badge.badge-loading::before { background: var(--muted); }
.badge[hidden] { display: none; }

.segmented {
  display: inline-flex; padding: 2px; gap: 2px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--panel);
}
.seg {
  height: 26px; padding: 0 var(--s2);
  border: 0; border-radius: 4px; background: transparent;
  color: var(--muted); font-size: var(--fs-sm);
}
.seg[aria-pressed="true"] { background: var(--panel-2); color: var(--text); box-shadow: inset 0 0 0 1px var(--border-strong); }

/* ---------- Top bar ---------- */

.topbar {
  display: flex; align-items: center; gap: var(--s4);
  height: 48px; padding: 0 var(--s4);
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}
.brand {
  font-weight: 700; font-size: var(--fs-lg); letter-spacing: -0.01em;
  display: flex; align-items: center; gap: var(--s2);
}
.brand::before {
  content: ''; width: 10px; height: 10px; border-radius: 2px;
  background: var(--accent); transform: rotate(45deg);
}

.search { position: relative; flex: 0 1 320px; min-width: 0; }
.search input {
  width: 100%; height: var(--tap);
  padding: 0 32px 0 32px;
  border: 1px solid var(--border-strong); border-radius: var(--radius);
  background: var(--bg); color: var(--text);
  font-family: var(--font-num); font-size: var(--fs-sm); text-transform: uppercase;
}
.search input::placeholder { text-transform: none; color: var(--muted); font-family: var(--font-ui); }
.search input:focus-visible { box-shadow: var(--focus); }
.search input::-webkit-search-cancel-button { display: none; }
.search-icon { position: absolute; left: 10px; top: 50%; width: 14px; height: 14px; transform: translateY(-50%); color: var(--faint); pointer-events: none; }
.search-kbd {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  min-width: 18px; height: 18px; padding: 0 4px;
  border: 1px solid var(--border-strong); border-radius: 4px;
  color: var(--muted); font: 11px/16px var(--font-num); text-align: center;
}
.search-msg {
  position: absolute; left: 0; top: calc(100% + 6px); z-index: 40;
  display: flex; align-items: center; gap: var(--s3);
  min-width: 100%; padding: var(--s2) var(--s3);
  border-radius: var(--radius); background: var(--panel); box-shadow: var(--shadow-pop);
  font-size: var(--fs-sm); white-space: nowrap;
}
.search-msg[hidden] { display: none; }
.search-list {
  position: absolute; left: 0; top: calc(100% + 6px); z-index: 40;
  width: max(100%, 360px); padding: var(--s1);
  border-radius: var(--radius); background: var(--panel); box-shadow: var(--shadow-pop);
}
.search-list[hidden] { display: none; }
.sl-items { margin: 0; padding: 0; list-style: none; max-height: min(60vh, 440px); overflow-y: auto; }
.sl-item {
  display: grid; grid-template-columns: 64px minmax(0, 1fr) auto; align-items: center; gap: var(--s2);
  height: var(--tap); padding: 0 var(--s2); border-radius: var(--radius);
  font-size: var(--fs-sm); cursor: pointer;
}
.sl-item:hover, .sl-item.active { background: var(--hover); }
.sl-item.active { box-shadow: inset 0 0 0 1px var(--border-strong); }
.sl-sym { font-family: var(--font-num); font-weight: 600; }
.sl-name { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sl-tag { color: var(--faint); font-size: var(--fs-xs); white-space: nowrap; }
.sl-tag.current { color: var(--accent); }
.sl-more {
  display: block; width: 100%; height: 32px; margin-top: var(--s1); padding: 0 var(--s2);
  border: 0; border-top: 1px solid var(--border); border-radius: 0 0 var(--radius) var(--radius);
  background: transparent; color: var(--accent); font-size: var(--fs-sm); text-align: left;
}
.sl-more:hover, .sl-more.active { background: var(--hover); }

.topbar-right { margin-left: auto; display: flex; align-items: center; gap: var(--s2); }

/* ---------- Instrument header + stats ---------- */

.instrument {
  padding: var(--s3) var(--s4) var(--s2);
  border-bottom: 1px solid var(--border);
  min-width: 0;
}
.inst-head { display: flex; align-items: baseline; gap: var(--s3); flex-wrap: wrap; }
.inst-name { font-size: var(--fs-xl); letter-spacing: -0.01em; }
.inst-meta { display: flex; gap: var(--s2); align-items: center; color: var(--muted); font-size: var(--fs-sm); }
.inst-meta .sym {
  font-family: var(--font-num); font-weight: 600; color: var(--text);
  padding: 1px 6px; border: 1px solid var(--border-strong); border-radius: 4px;
}
.inst-meta .dot-sep::before { content: '·'; color: var(--faint); }
.inst-meta .asof-inline { display: none; font-family: var(--font-num); font-size: var(--fs-xs); }
.inst-meta .asof-inline.stale { color: var(--amber); }
.details-btn { align-self: center; margin-left: auto; }
.split-note { margin-top: var(--s1); color: var(--amber); font-size: var(--fs-sm); }
.split-note[hidden] { display: none; }
.details-btn[aria-expanded="true"] { color: var(--text); }
.details-btn[aria-expanded="true"] .caret { transform: rotate(180deg); }

.stats[hidden] { display: none; }
.stats {
  display: flex; gap: var(--s1); margin-top: var(--s2);
  overflow-x: auto; scrollbar-width: none;
}
.stats::-webkit-scrollbar { display: none; }
.stat {
  flex: 0 0 auto;
  display: flex; flex-direction: column; justify-content: center; gap: 2px;
  min-width: 96px; padding: var(--s1) var(--s3);
  border-left: 1px solid var(--border);
}
.stat:first-child { border-left: 0; padding-left: 0; }
.stat-label { color: var(--muted); font-size: var(--fs-xs); white-space: nowrap; }
.stat-value { font-family: var(--font-num); font-variant-numeric: tabular-nums; font-size: var(--fs-md); font-weight: 500; white-space: nowrap; }
.stat-value.big { font-size: var(--fs-lg); font-weight: 600; }
.stat-sub { font-family: var(--font-num); font-size: var(--fs-xs); color: var(--muted); white-space: nowrap; }
.trend-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: 1px; }
.trend-dot.ok { background: var(--up); }
.trend-dot.fail { background: var(--down); }

/* skeleton */
.sk {
  border-radius: 4px;
  background: linear-gradient(90deg, var(--skeleton) 0%, var(--skeleton-hi) 50%, var(--skeleton) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.2s linear infinite;
}
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .sk { animation: none; } }
.stat .sk { height: 10px; width: 60px; }
.stat .sk + .sk { height: 14px; width: 80px; margin-top: 4px; }
.inst-name .sk { display: inline-block; height: 18px; width: 220px; vertical-align: middle; }

/* ---------- Tab bar ---------- */

.tabbar {
  position: relative; z-index: 30;
  display: flex; align-items: center; gap: var(--s2);
  padding: var(--s2) var(--s4);
  border-bottom: 1px solid var(--border);
}
.tab-wrap { position: relative; }
.tab-wrap[hidden] { display: none; }
.tab {
  display: inline-flex; align-items: center; gap: var(--s2);
  height: var(--tap); padding: 0 var(--s3);
  border: 1px solid var(--border-strong); border-radius: var(--radius);
  background: var(--panel); font-size: var(--fs-sm); font-weight: 500;
  transition: background var(--t), border-color var(--t);
}
.tab:hover { background: var(--hover); }
.tab[aria-expanded="true"], .tab[aria-pressed="true"] {
  border-color: var(--accent); background: var(--accent-soft);
}
.tab-val { font-family: var(--font-num); color: var(--muted); font-size: var(--fs-xs); }
.tab[aria-expanded="true"] .tab-val, .tab[aria-pressed="true"] .tab-val { color: var(--text); }
.caret {
  width: 0; height: 0; border-left: 4px solid transparent; border-right: 4px solid transparent;
  border-top: 5px solid var(--muted); transition: transform var(--t);
}
.tab[aria-expanded="true"] .caret { transform: rotate(180deg); }
.tab-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }
.tab-dot[hidden] { display: none; }

.range-note {
  margin-left: auto; color: var(--amber); font-size: var(--fs-xs);
  max-width: 50%; text-align: right;
}
.range-note[hidden] { display: none; }

.dropdown {
  position: absolute; left: 0; top: calc(100% + 6px); z-index: 50;
  min-width: 220px; padding: var(--s2);
  border-radius: var(--radius); background: var(--panel); box-shadow: var(--shadow-pop);
}
.dropdown[hidden] { display: none; }
.dd-title { padding: var(--s1) var(--s2) var(--s2); color: var(--muted); font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: 0.06em; }
.dd-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s1); }
.dd-list { display: flex; flex-direction: column; gap: 2px; }
.opt {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s3);
  height: var(--tap); padding: 0 var(--s2);
  border: 1px solid transparent; border-radius: var(--radius);
  background: transparent; font-size: var(--fs-sm); text-align: left;
}
.dd-grid .opt { justify-content: center; font-family: var(--font-num); }
.opt:hover { background: var(--hover); }
.opt[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); }
.opt[aria-disabled="true"] { color: var(--faint); cursor: not-allowed; background: transparent; }
.opt kbd { font: 11px var(--font-num); color: var(--muted); }
.opt .swatch { width: 12px; height: 2px; border-radius: 1px; display: inline-block; margin-right: var(--s2); vertical-align: middle; }
.opt .check {
  width: 16px; height: 16px; border: 1px solid var(--border-strong); border-radius: 4px;
  display: inline-grid; place-items: center;
}
.opt[aria-pressed="true"] .check { background: var(--accent); border-color: var(--accent); }
.opt[aria-pressed="true"] .check::after {
  content: ''; width: 8px; height: 4px; border-left: 2px solid var(--on-accent); border-bottom: 2px solid var(--on-accent);
  transform: rotate(-45deg) translate(1px, -1px);
}
.dd-note { padding: var(--s2) var(--s2) var(--s1); color: var(--muted); font-size: var(--fs-xs); max-width: 260px; }

/* ---------- Workspace ---------- */

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  min-height: 0; min-width: 0;
}
.app[data-scan="open"] .workspace { grid-template-columns: minmax(0, 1fr) var(--scan-width); }
.app[data-fund="open"] .workspace { grid-template-columns: minmax(0, 1fr) var(--fund-width); }
.app[data-news="open"] .workspace { grid-template-columns: minmax(0, 1fr) var(--news-width); }

.chart-area { position: relative; min-width: 0; min-height: 0; background: var(--chart-bg); }
.chart { position: absolute; inset: 0; }

.overlays { position: absolute; inset: 0; pointer-events: none; z-index: 5; }
.legend {
  position: absolute; left: var(--s3);
  display: flex; flex-direction: column; gap: 2px;
  font-size: var(--fs-xs); line-height: 16px;
  max-width: calc(100% - 90px);
}
.legend-row { display: flex; flex-wrap: wrap; column-gap: var(--s3); row-gap: 0; align-items: baseline; }
.legend-row .k { color: var(--muted); margin-right: 3px; }
.legend-row .v { font-family: var(--font-num); font-variant-numeric: tabular-nums; }
.legend-row .date { font-family: var(--font-num); font-weight: 600; }
.legend-row .tag { color: var(--amber); }
.legend-title { color: var(--muted); }
.legend .sw { display: inline-block; width: 10px; height: 2px; margin-right: 5px; vertical-align: middle; border-radius: 1px; }
.legend .sw-dash { background: none; border-top: 2px dashed currentColor; height: 0; }
.legend .sw-dot { background: none; border-top: 2px dotted currentColor; height: 0; }
.legend .mk { display: inline-block; margin-right: 4px; font-size: 10px; }
.legend .mk-hollow { width: 8px; height: 8px; border: 1.5px solid var(--filtered); border-radius: 50%; vertical-align: -1px; }
.legend-markers { color: var(--muted); }

/* Signal info box (hover over a signal) */
.sig-tip {
  position: absolute; z-index: 6; min-width: 210px; max-width: 260px;
  padding: var(--s2) var(--s3);
  border-radius: var(--radius); background: var(--panel); box-shadow: var(--shadow-pop);
  font-size: var(--fs-xs); line-height: 18px; pointer-events: none;
}
.sig-tip[hidden] { display: none; }
.tip-head { display: flex; align-items: center; gap: var(--s1); margin-bottom: var(--s1); padding-bottom: var(--s1); border-bottom: 1px solid var(--border); font-weight: 600; font-size: var(--fs-sm); }
.tip-head .mk { font-size: 10px; }
.tip-date { margin-left: auto; font-family: var(--font-num); font-weight: 500; color: var(--muted); }
.tip-row { display: flex; justify-content: space-between; gap: var(--s3); }
.tip-row .k { color: var(--muted); }
.tip-row .v { font-family: var(--font-num); font-variant-numeric: tabular-nums; text-align: right; }
.tip-note { color: var(--muted); font-size: 10.5px; line-height: 14px; margin: -1px 0 3px; }

.state-layer { position: absolute; inset: 0; z-index: 8; background: var(--chart-bg); }
.state-layer[hidden] { display: none; }
.skeleton-chart { display: flex; flex-direction: column; gap: var(--s3); padding: var(--s4); }
.skeleton-chart .sk-line { height: 12px; width: 40%; }
.skeleton-chart .sk-block { flex: 3; }
.skeleton-chart .sk-short { flex: 1; }
.state-error { display: grid; place-items: center; padding: var(--s4); }
.state-card {
  display: flex; flex-direction: column; align-items: center; gap: var(--s2);
  max-width: 340px; padding: var(--s6);
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--panel);
  text-align: center;
}
.state-card svg { color: var(--amber); }
.state-card h2 { font-size: var(--fs-lg); }
.state-card p { margin: 0 0 var(--s2); color: var(--muted); font-size: var(--fs-sm); }

/* ---------- Scan panel ---------- */

.scan-panel {
  display: flex; flex-direction: column; min-height: 0; min-width: 0;
  border-left: 1px solid var(--border); background: var(--panel);
}
.scan-panel[hidden] { display: none; }
.scan-head {
  display: flex; align-items: center; gap: var(--s2);
  padding: var(--s3) var(--s3) var(--s2) var(--s4);
}
.scan-head h2 { font-size: var(--fs-lg); }
.scan-head .icon-btn { margin-left: auto; }
.scan-head .ic-close { display: none; }
.scan-strategy { padding: 0 var(--s4) var(--s3); border-bottom: 1px solid var(--border); }
.scan-strategy label { display: block; color: var(--muted); font-size: var(--fs-xs); margin-bottom: var(--s1); }
.select {
  width: 100%; height: var(--tap); padding: 0 var(--s2);
  border: 1px solid var(--border-strong); border-radius: var(--radius);
  background: var(--bg); font-size: var(--fs-sm);
}
.select:focus-visible { box-shadow: var(--focus); }
.scan-rule { margin: var(--s2) 0 0; color: var(--muted); font-size: var(--fs-xs); }

/* Strategy settings: two RSI periods, two filter switches */
.strat-settings {
  display: grid; grid-template-columns: 1fr 1fr; gap: var(--s2) var(--s3);
  margin-top: var(--s3);
}
.scan-strategy .strat-field { display: flex; align-items: center; justify-content: space-between; gap: var(--s2); margin: 0; color: var(--muted); font-size: var(--fs-xs); }
.strat-num {
  width: 56px; height: 28px; padding: 0 var(--s1) 0 var(--s2);
  border: 1px solid var(--border-strong); border-radius: var(--radius); background: var(--bg);
  font-family: var(--font-num); font-size: var(--fs-sm); text-align: right;
}
.strat-num:focus-visible { box-shadow: var(--focus); }
.scan-strategy .strat-check { display: flex; align-items: center; gap: var(--s2); margin: 0; color: var(--text); font-size: var(--fs-sm); cursor: pointer; }
.strat-check input { width: 16px; height: 16px; margin: 0; accent-color: var(--accent); cursor: pointer; }
.strat-actions { display: flex; align-items: center; gap: var(--s2); margin-top: var(--s2); min-height: 28px; }
.strat-actions > .btn-ghost { margin-left: calc(-1 * var(--s2)); }
.strat-extra { margin-left: auto; display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: center; gap: var(--s2); font-size: var(--fs-xs); color: var(--muted); }
.strat-preview { color: var(--amber); font-weight: 600; }
/* The list's signal status is being computed with newly saved settings */
.strat-progress { flex-basis: 100%; text-align: right; color: var(--amber); }
/* Further settings: entry level, episode age, filter periods, stop */
.strat-more { margin-top: var(--s2); }
.strat-more > summary { cursor: pointer; color: var(--muted); font-size: var(--fs-xs); }
.strat-more > summary:focus-visible { box-shadow: var(--focus); border-radius: var(--radius); }
.strat-more .strat-settings { margin-top: var(--s2); }
.scan-summary { display: flex; gap: var(--s3); margin-top: var(--s2); font-size: var(--fs-xs); color: var(--muted); }
.scan-summary b { font-family: var(--font-num); color: var(--text); font-weight: 600; }

.scan-body { flex: 1; min-height: 0; overflow-y: auto; padding-bottom: var(--s4); }
.scan-sec { padding: var(--s3) var(--s4) 0; }
.scan-sec + .scan-sec { border-top: 1px solid var(--border); margin-top: var(--s3); }
.sec-head { display: flex; align-items: baseline; gap: var(--s2); margin-bottom: var(--s2); }
.sec-head h3 { font-size: var(--fs-md); }
.sec-count {
  font: 600 var(--fs-xs) var(--font-num); color: var(--muted);
  padding: 0 6px; border: 1px solid var(--border-strong); border-radius: 10px;
}
.sec-hint { margin: calc(-1 * var(--s1)) 0 var(--s2); color: var(--muted); font-size: var(--fs-xs); }
.empty {
  display: flex; flex-direction: column; gap: 2px;
  padding: var(--s3); border: 1px dashed var(--border-strong); border-radius: var(--radius);
  color: var(--muted); font-size: var(--fs-sm);
}
.empty b { color: var(--text); font-weight: 500; }
.empty small { font-size: var(--fs-xs); }
.empty .btn { align-self: flex-start; margin-top: var(--s2); }

/* ---------- Fundamentals panel and dialog (Phase 2) ---------- */

.fund-panel .scan-body { padding-bottom: var(--s4); }
.fd-body { font-size: var(--fs-sm); }
.fd-dialog { max-height: 75vh; overflow-y: auto; padding: var(--s2) 0 var(--s4); }
.tab-short { display: none; }
.fd-title { padding: 0 var(--s4); font-size: var(--fs-md); }
.fd-status { padding: var(--s2) var(--s4) 0; }
.fd-status p { margin: 0 0 var(--s2); }
.fd-meta { color: var(--muted); font-size: var(--fs-xs); margin: 0; }
.fd-msg { margin: var(--s2) var(--s4); font-size: var(--fs-sm); }
.fd-msg.err { color: var(--down); }
.fd-note { margin: var(--s2) 0 0; font-size: var(--fs-xs); color: var(--muted); }
.fd-peers-needed { display: flex; align-items: center; flex-wrap: wrap; gap: var(--s2); }
.fd-peers-load { margin: 0 0 var(--s2); }
.fd-score-card { display: flex; align-items: center; gap: var(--s3); }
.fd-big { font: 600 32px/1 var(--font-num); min-width: 56px; text-align: center; }
.fd-label { display: block; color: var(--muted); font-size: var(--fs-xs); }
.fd-group { font-weight: 600; }
.fd-excl { margin: var(--s2) 0 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 2px; }
.fd-excl li { color: var(--down); font-size: var(--fs-xs); font-weight: 600; }
.fd-flag { margin: var(--s2) 0 0; padding: var(--s1) var(--s2); border-radius: var(--radius); color: var(--amber); background: var(--amber-soft); font-size: var(--fs-xs); }
.fd-tbl td, .fd-tbl th { text-align: right; }
.fd-tbl td:first-child, .fd-tbl th:first-child, .fd-tbl .fd-pname { text-align: left; }
.fd-pname { max-width: 150px; overflow: hidden; text-overflow: ellipsis; }
.fd-tbl tr[data-symbol] { cursor: pointer; }
.fd-tbl tr[data-symbol]:hover { background: var(--hover); }
.fd-sc { white-space: nowrap; }
.fd-bar { display: inline-block; width: 44px; height: 6px; margin-right: var(--s1); border-radius: 3px; background: var(--border-strong); vertical-align: middle; overflow: hidden; }
.fd-bar span { display: block; height: 100%; background: var(--accent); }
.fd-score { display: inline-block; min-width: 22px; font-family: var(--font-num); }
.fd-off { color: var(--faint); font-size: var(--fs-xs); }
.fd-dcf { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s2) var(--s3); margin-bottom: var(--s2); }
.fd-dcf b { font-family: var(--font-num); font-size: var(--fs-md); }
.fd-sens caption { caption-side: top; text-align: left; color: var(--muted); font-size: var(--fs-xs); padding: var(--s2) 0 var(--s1) var(--s2); }
.fd-sens th[scope="row"] { color: var(--muted); font-weight: 400; }
.fd-sens .fd-base { font-weight: 700; color: var(--text); background: var(--accent-soft); }
.fd-foot { padding: var(--s3) var(--s4) 0; }

/* ---------- Expanded fundamentals: financial statements (Phase 2) ---------- */

#fundExpand { margin-left: auto; gap: var(--s1); }
#fundExpand[hidden] { display: none; }
#fundExpand:not([hidden]) + .icon-btn { margin-left: 0; }
.app[data-fin="open"] .workspace,
.app[data-fund="open"][data-fin="open"] .workspace { grid-template-columns: minmax(0, 1fr); }
.app[data-fin="open"] .chart-area,
.app[data-fin="open"] #fundPanel { display: none; }
.fin-view { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--panel); }
.fin-view[hidden] { display: none; }
.fin-head { display: flex; align-items: flex-start; gap: var(--s3); padding: var(--s3) var(--s4) var(--s2); }
.fin-title { min-width: 0; }
.fin-title h2 { font-size: var(--fs-lg); }
.fin-title h2 .muted { font-weight: 400; }
.fin-meta { margin: 2px 0 0; color: var(--muted); font-size: var(--fs-xs); }
.fin-collapse { margin-left: auto; flex: none; gap: var(--s1); }
.fin-controls { display: flex; flex-wrap: wrap; gap: var(--s2); padding: 0 var(--s4) var(--s2); }
.fin-body { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.fin-note { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2); margin: var(--s2) var(--s4); color: var(--muted); font-size: var(--fs-sm); }
.fin-err { color: var(--down); }
/* The table scrolls both ways; row names and the header stay in place. */
.fin-scroll { flex: 1; min-height: 0; overflow: auto; border-top: 1px solid var(--border); }
.fin-scroll:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.fin-tbl { min-width: 100%; border-collapse: separate; border-spacing: 0; font-size: var(--fs-sm); font-variant-numeric: tabular-nums; }
.fin-tbl th, .fin-tbl td { padding: 5px var(--s3); text-align: right; white-space: nowrap; vertical-align: top; border-bottom: 1px solid var(--border); background: var(--panel); }
.fin-tbl td { font-family: var(--font-num); }
.fin-tbl thead th { position: sticky; top: 0; z-index: 2; vertical-align: bottom; background: var(--panel-2); font-weight: 600; }
.fin-tbl thead th small { display: block; color: var(--muted); font-size: var(--fs-xs); font-weight: 400; }
.fin-tbl .fin-name {
  position: sticky; left: 0; z-index: 1;
  min-width: 240px; max-width: 340px; white-space: normal; text-align: left; font-weight: 400;
  padding-left: calc(var(--s4) + 22px + var(--depth, 0) * 16px);
  border-right: 1px solid var(--border);
}
.fin-tbl thead .fin-name { z-index: 3; padding-left: var(--s4); background: var(--panel-2); }
.fin-tbl tbody tr:hover > * { background: var(--hover); }
.fin-tbl .newest { background: var(--panel-2); }
.fin-tbl thead th.newest { box-shadow: inset 0 -2px 0 var(--accent); }
.fin-tbl .fin-ttm { border-left: 1px solid var(--border-strong); }
.fin-tbl .fin-cagr { border-left: 1px solid var(--border-strong); }
.fv { display: block; }
.fg { display: block; color: var(--muted); font-size: 10px; line-height: 14px; }
.fg.up { color: var(--up); }
.fg.down { color: var(--down); }
.fin-tbl .fin-cagr .fg { display: inline; font-size: var(--fs-sm); }
.fin-span { color: var(--muted); font-size: 10px; }
.fin-group { cursor: pointer; }
.fin-group > .fin-name { font-weight: 500; }
.fin-total > .fin-name, .fin-total > td { font-weight: 600; }
.fin-sec > th { padding-top: var(--s3); color: var(--muted); font-size: var(--fs-xs); font-weight: 600; letter-spacing: 0.02em; padding-left: var(--s4); }
.fin-tog {
  width: 18px; height: 18px; margin: 0 4px 0 -22px; padding: 0; vertical-align: top;
  border: 0; border-radius: 3px; background: none; color: var(--muted); font-size: 9px; cursor: pointer;
}
.fin-tog:hover { color: var(--text); }
.fin-tog:focus-visible { box-shadow: var(--focus); }
.fin-calc { margin-left: var(--s1); padding: 0 4px; border: 1px solid var(--border-strong); border-radius: 3px; color: var(--muted); font-size: 10px; cursor: help; }

/* Rules dialog */
.ru-body { padding: var(--s3) var(--s4) var(--s4); max-height: 75vh; overflow-y: auto; }
.ru-tabs { margin-bottom: var(--s2); }
.ru-row { display: flex; flex-wrap: wrap; gap: var(--s3); }
.ru-row .lv-search { flex: none; width: 240px; max-width: 100%; height: 32px; }
.ru-h { margin: var(--s3) 0 var(--s1); font-size: var(--fs-md); }
.ru-tbl td { text-align: left; height: 32px; }
.ru-tbl td:last-child { text-align: right; }
.ru-scroll { max-height: 50vh; overflow-y: auto; }
.ru-ind th { text-align: left; position: sticky; top: 0; background: var(--panel); }
.ru-ind .select { height: 30px; width: auto; }
.ru-unmapped td:first-child { color: var(--amber); }
.ru-excl { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2); margin: var(--s1) 0; }
.ru-excl .select { width: auto; height: 30px; }
.ru-op { min-width: 56px; }
.ru-val { width: 80px; }
.ru-ccy { min-width: 40px; font-family: var(--font-num); }
.ru-newccy { width: 90px; flex: 0 0 auto; }
.ru-lab { min-width: 160px; color: var(--muted); }

/* ---------- Stock list ---------- */

.list-view { min-height: 0; overflow: auto; padding: var(--s3) var(--s4, 16px) var(--s4, 16px); }
.lv-loading { padding: var(--s4, 16px); color: var(--muted); }
.lv-bar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2) var(--s3); }
.lv-chips { display: flex; flex-wrap: wrap; gap: var(--s1); }
.chip {
  height: 28px; padding: 0 var(--s3); border: 1px solid var(--border-strong); border-radius: 999px;
  background: transparent; color: var(--muted); font-size: var(--fs-sm); cursor: pointer;
}
.chip:hover { color: var(--text); background: var(--hover); }
.chip[aria-pressed="true"] { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
.chip:focus-visible { box-shadow: var(--focus); }
.lv-search {
  flex: 1 1 240px; max-width: 360px; height: 32px; padding: 0 var(--s2);
  border: 1px solid var(--border-strong); border-radius: var(--radius); background: var(--bg); font-size: var(--fs-sm);
}
.lv-search:focus-visible { box-shadow: var(--focus); }
.lv-filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--s2) var(--s3); margin-top: var(--s3); }
.lv-filter { display: flex; flex-direction: column; gap: 2px; margin: 0; font-size: var(--fs-xs); color: var(--muted); }
.lv-filter .select { width: auto; min-width: 150px; max-width: 260px; height: 32px; }
.lv-count { margin: var(--s3) 0 var(--s2); font-size: var(--fs-xs); color: var(--muted); }
.lv-progress { color: var(--amber); }
.lv-table-wrap { overflow-x: auto; }
.lv-table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.lv-table th {
  position: sticky; top: calc(-1 * var(--s3)); z-index: 1; background: var(--bg);
  height: 32px; padding: 0 var(--s2); text-align: left; font-weight: 500; color: var(--muted); white-space: nowrap;
  border-bottom: 1px solid var(--border-strong); font-size: var(--fs-xs);
}
.lv-table td { height: 34px; padding: 0 var(--s2); border-bottom: 1px solid var(--border); white-space: nowrap; }
.lv-table .num { text-align: right; font-family: var(--font-num); }
.lv-sort { padding: 0; border: 0; background: none; color: inherit; font: inherit; cursor: pointer; }
.lv-sort:hover { color: var(--text); }
.lv-sort:focus-visible { box-shadow: var(--focus); border-radius: 2px; }
.lv-table tbody tr[data-symbol] { cursor: pointer; }
.lv-table tbody tr[data-symbol]:hover { background: var(--hover); }
.lv-table tbody tr:focus-visible { outline: none; box-shadow: inset 0 0 0 2px var(--accent); }
.lv-table tr.lv-nodata td { color: var(--faint); }
.lv-sym .sym { font: 600 var(--fs-sm) var(--font-num); }
.lv-sym small { margin-left: var(--s2); color: var(--muted); font-family: var(--font-num); font-size: var(--fs-xs); }
.lv-name { max-width: 280px; overflow: hidden; text-overflow: ellipsis; }
.lv-industry { max-width: 220px; overflow: hidden; text-overflow: ellipsis; color: var(--muted); }
.lv-idx, .lv-ex, .lv-ccy { color: var(--muted); font-size: var(--fs-xs); }
.lv-status small { margin-left: var(--s2); color: var(--muted); font-family: var(--font-num); font-size: var(--fs-xs); }
.lv-st { display: inline-block; padding: 1px 6px; border-radius: 4px; font-size: var(--fs-xs); font-weight: 600; }
.lv-st.sig { color: var(--accent); background: var(--accent-soft); }
.lv-st.watch { color: var(--amber); background: var(--amber-soft); }
.lv-data { font-family: var(--font-num); font-size: var(--fs-xs); color: var(--muted); }
.lv-data.stale { color: var(--amber); }
.lv-score { font-family: var(--font-num); }
.lv-split { display: inline-block; margin-left: 4px; padding: 0 4px; border-radius: 3px; color: var(--amber); background: var(--amber-soft);
  font-size: var(--fs-xs); font-weight: 600; white-space: nowrap; }
.lv-flag { display: inline-block; margin-left: 4px; padding: 0 4px; border-radius: 3px; color: var(--amber); background: var(--amber-soft);
  font-size: 10px; font-weight: 700; cursor: help; }

.tbl-wrap { overflow-x: auto; margin: 0 calc(-1 * var(--s2)); }
.tbl { width: 100%; border-collapse: collapse; font-size: var(--fs-xs); }
.tbl th, .tbl td { padding: 0 var(--s1); height: 28px; text-align: right; white-space: nowrap; }
.tbl th:first-child, .tbl td:first-child { padding-left: var(--s2); }
.tbl th:last-child, .tbl td:last-child { padding-right: var(--s2); }
.tbl th:first-child, .tbl td:first-child { text-align: left; }
.tbl th { color: var(--muted); font-weight: 500; border-bottom: 1px solid var(--border); height: 26px; }
.tbl td { font-family: var(--font-num); font-variant-numeric: tabular-nums; border-bottom: 1px solid var(--border); }
.tbl tbody tr { cursor: pointer; transition: background var(--t); }
.tbl tbody tr:hover { background: var(--hover); }
.tbl tbody tr:focus-visible { box-shadow: inset 0 0 0 2px var(--accent); border-radius: 0; }
.tbl tbody tr[aria-selected="true"] { background: var(--selected); }
.tbl tbody tr[aria-selected="true"] td:first-child { box-shadow: inset 2px 0 0 var(--accent); }
.tbl tfoot td { color: var(--muted); border-bottom: 0; height: 26px; }
.tbl .sym { font-weight: 600; }

details.scan-sec summary {
  display: flex; align-items: baseline; gap: var(--s2);
  list-style: none; cursor: pointer; margin-bottom: var(--s2);
  border-radius: var(--radius);
}
details.scan-sec summary::-webkit-details-marker { display: none; }
details.scan-sec summary h3 { font-size: var(--fs-md); }
details.scan-sec summary::after {
  content: ''; margin-left: auto; align-self: center;
  width: 0; height: 0; border-left: 4px solid transparent; border-right: 4px solid transparent;
  border-top: 5px solid var(--muted); transition: transform var(--t);
}
details[open].scan-sec summary::after { transform: rotate(180deg); }

.scan-foot { padding: var(--s2) var(--s4); border-top: 1px solid var(--border); color: var(--muted); font-size: var(--fs-xs); }

/* ---------- Footer ---------- */

.footer {
  display: flex; align-items: center; gap: var(--s2);
  height: 28px; padding: 0 var(--s4);
  border-top: 1px solid var(--border); background: var(--panel);
  color: var(--muted); font-size: var(--fs-xs); white-space: nowrap; overflow: hidden;
}
.footer a { color: var(--muted); }
.footer a:hover { color: var(--text); }
.footer .sep { color: var(--faint); }
.footer #sourceNote { overflow: hidden; text-overflow: ellipsis; }
.footer-keys { margin-left: auto; font-family: var(--font-num); color: var(--muted); }

/* ---------- Universe modal ---------- */

.modal {
  width: min(440px, calc(100vw - 32px));
  padding: 0; border: 0; border-radius: var(--radius);
  background: var(--panel); color: var(--text); box-shadow: var(--shadow-pop);
}
.modal::backdrop { background: rgba(0, 0, 0, 0.5); }
.modal-head { display: flex; align-items: center; gap: var(--s2); padding: var(--s3) var(--s3) var(--s3) var(--s4); border-bottom: 1px solid var(--border); }
.modal-head h2 { font-size: var(--fs-lg); }
.modal-head .icon-btn { margin-left: auto; }
.uni-add { padding: var(--s4) var(--s4) 0; }
.uni-add label { display: block; font-size: var(--fs-xs); color: var(--muted); margin-bottom: var(--s1); }
.uni-add-row { display: flex; gap: var(--s2); }
.uni-add input {
  flex: 1; min-width: 0; height: var(--tap); padding: 0 var(--s2);
  border: 1px solid var(--border-strong); border-radius: var(--radius); background: var(--bg);
  font-family: var(--font-num); text-transform: uppercase;
}
.uni-add input::placeholder { text-transform: none; font-family: var(--font-ui); color: var(--muted); }
.uni-add input[aria-invalid="true"] { border-color: var(--down); }
.uni-add input:focus-visible { box-shadow: var(--focus); }
.uni-msg { min-height: 18px; margin: var(--s1) 0 0; font-size: var(--fs-xs); color: var(--muted); }
.uni-msg.err { color: var(--down); }
.uni-count { margin: var(--s2) var(--s4) var(--s1); color: var(--muted); font-size: var(--fs-xs); }
.uni-bar { display: flex; align-items: center; gap: var(--s2); margin: var(--s2) var(--s4) var(--s1); }
.uni-bar .uni-count { margin: 0; flex: 1; }
.uni-list { list-style: none; margin: 0; padding: 0 var(--s2) var(--s3); max-height: 50vh; overflow-y: auto; }
.uni-list li {
  display: flex; align-items: center; gap: var(--s2);
  min-height: 40px; padding: 0 var(--s2); border-radius: var(--radius);
}
.uni-list li:hover { background: var(--hover); }
.uni-list .sym { font: 600 var(--fs-md) var(--font-num); min-width: 56px; }
.uni-list .meta { color: var(--muted); font-size: var(--fs-xs); flex: 1; }
.uni-list .confirm { display: flex; align-items: center; gap: var(--s2); font-size: var(--fs-xs); flex: 1; justify-content: flex-end; }

/* ---------- Mapping review modal ---------- */

.modal-wide { width: min(680px, calc(100vw - 32px)); }
.rv-body { padding: var(--s3) var(--s4) var(--s4); max-height: 75vh; overflow-y: auto; }
.rv-intro, .rv-empty { margin: 0 0 var(--s2); font-size: var(--fs-sm); color: var(--muted); }
.rv-summary { margin: 0; font-size: var(--fs-xs); }
.rv-list { list-style: none; margin: var(--s2) 0 0; padding: 0; display: grid; gap: var(--s3); }
.rv-row { border: 1px solid var(--border); border-radius: var(--radius); padding: var(--s3); }
.rv-src { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--s1) var(--s2); }
.rv-src .sym { font: 600 var(--fs-md) var(--font-num); }
.rv-meta { color: var(--muted); font-size: var(--fs-xs); }
.rv-note { margin: var(--s1) 0 0; font-size: var(--fs-xs); color: var(--amber); }
.rv-label { margin: var(--s2) 0 var(--s1); font-size: var(--fs-xs); color: var(--muted); }
.rv-cands { display: flex; flex-wrap: wrap; gap: var(--s1); }
.rv-cands .btn { height: auto; min-height: 32px; padding: var(--s1) var(--s2); text-align: left; white-space: normal; }
.rv-cand-sym { font-family: var(--font-num); font-weight: 600; }
.rv-manual { display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--s2); margin-top: var(--s2); }
.rv-manual label { display: grid; gap: 2px; font-size: var(--fs-xs); color: var(--muted); }
.rv-manual input {
  width: 120px; height: 32px; padding: 0 var(--s2);
  border: 1px solid var(--border-strong); border-radius: var(--radius); background: var(--bg); color: var(--text);
  font-family: var(--font-num); text-transform: uppercase;
}
.rv-manual input[name="mic"] { width: 72px; }
.rv-manual input:focus-visible { box-shadow: var(--focus); }
.rv-done { margin-top: var(--s4); font-size: var(--fs-xs); color: var(--muted); }
.rv-done ul { list-style: none; margin: var(--s2) 0 0; padding: 0; display: grid; gap: var(--s1); }
.rv-done .sym { font-family: var(--font-num); font-weight: 600; color: var(--text); }

/* ---------- Alerts modal ---------- */

.btn[hidden] { display: none; }
.al-body { padding: 0 var(--s4) var(--s3); }
.al-sec { padding: var(--s3) 0; }
.al-sec + .al-sec { border-top: 1px solid var(--border); }
.al-sec h3 { font-size: var(--fs-md); margin-bottom: var(--s2); }
.al-status { display: flex; align-items: baseline; margin: 0; font-size: var(--fs-sm); }
.al-status .trend-dot { flex: none; }
.al-actions { display: flex; gap: var(--s2); margin-top: var(--s3); }
.al-msg { min-height: 18px; margin: var(--s2) 0 0; font-size: var(--fs-xs); color: var(--muted); }
.al-msg.err { color: var(--down); }
.al-note { margin: 0 0 var(--s2); color: var(--muted); font-size: var(--fs-xs); }
.al-rule {
  margin: 0 0 var(--s2); padding: var(--s2) var(--s3);
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg);
  font-family: var(--font-num); font-size: var(--fs-xs); line-height: 1.6;
}
.al-meta { margin: 0 0 var(--s1); color: var(--muted); font-size: var(--fs-xs); }
.al-foot {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s2);
  padding-top: var(--s3); border-top: 1px solid var(--border);
  color: var(--muted); font-size: var(--fs-xs);
}
.al-foot .btn-ghost { margin-right: calc(-1 * var(--s2)); }

/* ---------- Login ---------- */

.login {
  position: fixed; inset: 0; z-index: 100;
  display: grid; place-items: center; padding: var(--s4);
  background: var(--bg);
}
.login[hidden] { display: none; }
.login-card {
  display: flex; flex-direction: column; gap: var(--s1);
  width: min(340px, 100%); padding: var(--s6);
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--panel);
}
.login-card .brand { margin-bottom: var(--s4); }
.login-card h1 { font-size: var(--fs-lg); margin-bottom: var(--s3); }
.login-card label { color: var(--muted); font-size: var(--fs-xs); margin-top: var(--s2); }
.login-card input {
  height: 36px; padding: 0 var(--s3);
  border: 1px solid var(--border-strong); border-radius: var(--radius); background: var(--bg);
  font-size: 16px; /* 16 px keeps phones from zooming in on focus */
}
.login-card input:focus-visible { box-shadow: var(--focus); }
.login-msg { min-height: 18px; margin: var(--s2) 0; color: var(--down); font-size: var(--fs-xs); }
.login-card .btn { height: 36px; }

/* ---------- News panel: upcoming, investor relations, market news (js/news.js) ---------- */

.nw-body { font-size: var(--fs-sm); padding: var(--s1) 0 var(--s4); }
.nw-body > .fd-title { padding: 0 var(--s4); }
.nw-sec { padding: var(--s3) var(--s4) 0; }
.nw-sec + .nw-sec { border-top: 1px solid var(--border); margin-top: var(--s3); }
.nw-sk { display: flex; flex-direction: column; gap: var(--s2); }
.nw-sk-line { height: 12px; width: 100%; }
.nw-sk-line.short { width: 60%; }
.nw-error {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s2);
  padding: var(--s2) var(--s3); border: 1px solid var(--down); border-radius: var(--radius); color: var(--text);
}
.nw-note { margin: var(--s2) 0 0; color: var(--muted); font-size: var(--fs-xs); }
.nw-foot { margin: var(--s3) 0 0; color: var(--faint); font-size: var(--fs-xs); }
.nw-foot a { color: var(--muted); }

/* Upcoming: the next results date */
.nw-card { padding: var(--s3); border: 1px solid var(--border-strong); border-radius: var(--radius); background: var(--panel-2); }
.nw-card.estimated { border-style: dashed; background: transparent; }
.nw-card-top { display: flex; align-items: center; justify-content: space-between; gap: var(--s2); }
.nw-label { color: var(--muted); font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: 0.04em; }
.nw-badge { padding: 1px 8px; border: 1px solid currentColor; border-radius: 999px; font-size: var(--fs-xs); font-weight: 600; white-space: nowrap; }
.nw-badge.company_announced { color: var(--up); }
.nw-badge.data_provider { color: var(--accent); }
.nw-badge.estimated { color: var(--amber); border-style: dashed; }
.nw-when { margin-top: var(--s2); font: 600 var(--fs-lg) var(--font-num); font-variant-numeric: tabular-nums; }
.nw-card.estimated .nw-when { color: var(--muted); }
.nw-sub { margin-top: 2px; color: var(--muted); }
.nw-est { margin-top: var(--s1); color: var(--amber); font-size: var(--fs-xs); }
.nw-ev-title, .nw-src { margin-top: var(--s1); font-size: var(--fs-xs); color: var(--muted); }
.nw-ev-title a { color: var(--text); }
.nw-actions { display: flex; flex-wrap: wrap; gap: var(--s2); margin-top: var(--s3); }
.nw-actions a.btn { text-decoration: none; display: inline-flex; align-items: center; }
.nw-hint { margin: var(--s2) 0 0; font-size: var(--fs-xs); line-height: 1.5; }
.nw-subhead { margin: var(--s3) 0 var(--s1); font-size: var(--fs-xs); color: var(--muted); font-weight: 600; }
.nw-events { margin: 0; padding: 0; list-style: none; }
.nw-events li { display: flex; gap: var(--s2); padding: 3px 0; }
.nw-date { flex: 0 0 auto; min-width: 88px; color: var(--muted); font-family: var(--font-num); font-size: var(--fs-xs); padding-top: 1px; }

/* Lists: chips, controls, day groups, rows */
.nw-controls { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2); margin-bottom: var(--s2); }
.nw-chips { display: flex; flex-wrap: wrap; gap: var(--s1); margin-bottom: var(--s2); }
.nw-controls .nw-chips { margin-bottom: 0; }
.nw-chip { height: 24px; padding: 0 var(--s2); font-size: var(--fs-xs); }
.nw-count { font-family: var(--font-num); color: var(--faint); }
.nw-chip[aria-pressed="true"] .nw-count { color: inherit; }
.nw-srcsel { width: auto; max-width: 220px; height: 28px; margin-left: auto; font-size: var(--fs-xs); }
.nw-day + .nw-day { margin-top: var(--s2); }
.nw-dayhead {
  position: sticky; top: 0; z-index: 1;
  margin: 0; padding: var(--s1) 0; background: var(--panel);
  color: var(--muted); font-size: var(--fs-xs); font-weight: 600; border-bottom: 1px solid var(--border);
}
.nw-list { margin: 0; padding: 0; list-style: none; }
.nw-row { display: flex; align-items: baseline; gap: var(--s2); padding: 6px 0; border-bottom: 1px solid var(--border); }
.nw-row:last-child { border-bottom: 0; }
.nw-time { flex: 0 0 34px; color: var(--faint); font-family: var(--font-num); font-size: var(--fs-xs); text-align: right; }
.nw-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.nw-head { color: var(--text); text-decoration: none; line-height: 1.4; overflow-wrap: anywhere; }
a.nw-head:hover { color: var(--accent); text-decoration: underline; }
a.nw-head:visited { color: var(--muted); }
a.nw-head:focus-visible { box-shadow: var(--focus); border-radius: 2px; outline: none; }
.nw-meta { display: flex; flex-wrap: wrap; gap: var(--s2); color: var(--faint); font-size: var(--fs-xs); }
.nw-also { color: var(--muted); }
.nw-flag { color: var(--amber); }
.nw-row.flagged .nw-head { color: var(--muted); }
.nw-tag {
  flex: 0 0 auto; padding: 0 6px; border: 1px solid var(--border-strong); border-radius: 999px;
  color: var(--muted); font-size: 10px; line-height: 16px; white-space: nowrap;
}
.nw-tag.tag-results { color: var(--accent); border-color: var(--accent); }
.nw-tag.tag-guidance, .nw-tag.tag-dividend, .nw-tag.tag-buyback { color: var(--up); border-color: var(--up); }
.nw-tag.tag-ma, .nw-tag.tag-management { color: var(--amber); border-color: var(--amber); }
.nw-hidden, .nw-more { margin: var(--s2) 0 0; }
.nw-hidden .btn, .nw-more .btn { margin-left: calc(-1 * var(--s2)); }

/* ---------- Tablet: scan panel overlays the chart ---------- */

@media (min-width: 768px) and (max-width: 1023px) {
  .app[data-scan="open"] .workspace { grid-template-columns: minmax(0, 1fr); }
  .workspace { position: relative; }
  .scan-panel { position: absolute; top: 0; right: 0; bottom: 0; width: var(--scan-width); z-index: 20; box-shadow: var(--shadow-pop); }
  .app[data-fund="open"] .workspace { grid-template-columns: minmax(0, 1fr); }
  .fund-panel { width: var(--fund-width); }
  .app[data-news="open"] .workspace { grid-template-columns: minmax(0, 1fr); }
  .news-panel { width: var(--news-width); }
  .footer-keys { display: none; }
}

/* ---------- Phone ---------- */

@media (max-width: 767px) {
  :root { --tap: 44px; }
  body { overflow: hidden; }
  .app {
    grid-template-rows: auto auto minmax(0, 1fr) auto;
    padding-bottom: calc(60px + env(safe-area-inset-bottom));
  }
  .topbar { height: 56px; gap: var(--s2); padding: 0 var(--s3); }
  .brand { font-size: var(--fs-md); }
  .search { flex: 1 1 auto; }
  .search-kbd { display: none; }
  .search-list { position: fixed; left: var(--s2); right: var(--s2); top: calc(56px + var(--s1)); width: auto; }
  .topbar-right .badge { display: none; }
  #universeBtn { display: none; }
  #alertsBtn { width: 44px; padding: 0; }
  #alertsBtnLabel { display: none; }
  .segmented { padding: 0; border: 0; background: transparent; }
  .seg { height: 44px; min-width: 44px; }
  .instrument { padding: var(--s2) var(--s3); }
  .inst-name { font-size: var(--fs-lg); flex: 1 1 0; min-width: 0; }
  .details-btn { order: 1; } /* on the name line; the meta line wraps below */
  .inst-meta { order: 2; flex-basis: 100%; }
  .inst-meta .asof-inline { display: inline; }
  .stats { gap: var(--s2); margin: var(--s2) calc(-1 * var(--s3)) 0; padding: 0 var(--s3); scroll-snap-type: x proximity; scroll-padding: 0 var(--s3); }
  .stat {
    border: 1px solid var(--border); border-radius: var(--radius);
    padding: var(--s1) var(--s2); min-width: 0; scroll-snap-align: start;
    background: var(--panel);
  }
  .stat:first-child { padding-left: var(--s2); border-left: 1px solid var(--border); }

  /* Tabs move to a fixed bottom bar */
  .tabbar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
    display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 0;
    height: calc(60px + env(safe-area-inset-bottom));
    padding: var(--s1) var(--s1) env(safe-area-inset-bottom);
    border-top: 1px solid var(--border); border-bottom: 0; background: var(--panel);
  }
  .tab-wrap { position: static; }
  .tab {
    width: 100%; height: 52px; flex-direction: column; justify-content: center; gap: 0;
    padding: 0 2px; border: 0; background: transparent; border-radius: var(--radius);
  }
  .tab .caret { display: none; }
  .tab-val { font-size: 10px; }
  .dropdown {
    position: fixed; left: var(--s2); right: var(--s2); top: auto;
    bottom: calc(64px + env(safe-area-inset-bottom));
    min-width: 0;
  }
  .dd-note { max-width: none; }
  .range-note {
    position: fixed; left: var(--s3); right: var(--s3); bottom: calc(66px + env(safe-area-inset-bottom));
    max-width: none; text-align: left; padding: var(--s1) var(--s2);
    background: var(--panel); border: 1px solid var(--amber); border-radius: var(--radius);
  }

  .workspace, .app[data-scan="open"] .workspace, .app[data-fund="open"] .workspace, .app[data-news="open"] .workspace { grid-template-columns: minmax(0, 1fr); }
  .fund-panel, .news-panel { width: auto; }
  .nw-row { min-height: 44px; }
  .nw-chip, .nw-srcsel { height: 36px; }
  .tab-long { display: none; }
  .tab-short { display: inline; }
  .fd-dialog { max-height: none; }
  /* Expanded fundamentals: a full-screen sheet; the table scrolls inside it */
  .fin-view { position: fixed; inset: 0; z-index: 75; padding-bottom: env(safe-area-inset-bottom); }
  .fin-head { padding: var(--s2) var(--s3); }
  .fin-controls { padding: 0 var(--s3) var(--s2); }
  .fin-collapse { height: 44px; }
  .fin-tbl .fin-name { min-width: 150px; max-width: 170px; padding-left: calc(var(--s3) + 22px + var(--depth, 0) * 10px); }
  .fin-tbl thead .fin-name, .fin-sec > th { padding-left: var(--s3); }
  .chart-area { min-height: 300px; }

  /* Scan panel becomes a full-screen sheet */
  .scan-panel {
    position: fixed; inset: 0; z-index: 70;
    border-left: 0;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .scan-head .icon-btn { width: 44px; height: 44px; }
  .scan-head .ic-collapse { display: none; }
  .scan-head .ic-close { display: block; }
  .tbl th, .tbl td { height: 44px; }

  .footer { height: auto; padding: var(--s1) var(--s3); flex-wrap: wrap; white-space: normal; row-gap: 0; }
  .footer #sourceNote, .footer .sep, .footer-keys { display: none; }

  .legend { left: var(--s2); max-width: calc(100% - 70px); }
  .uni-list li { min-height: 48px; }

  /* Stock list: ticker, name, signal and last price; the other columns are in the chart view */
  .app[data-view="list"] { padding-bottom: env(safe-area-inset-bottom); }
  #listBtn { width: 44px; padding: 0; }
  #listBtnLabel { display: none; }
  .list-view { padding: var(--s2) var(--s3) var(--s3); }
  .lv-search { max-width: none; height: 44px; flex-basis: 100%; }
  .chip { height: 36px; }
  .lv-filter { flex: 1 1 calc(50% - var(--s3)); }
  .lv-filter .select { min-width: 0; max-width: none; width: 100%; height: 44px; }
  .lv-table td { height: 48px; }
  .lv-idx, .lv-industry, .lv-ex, .lv-ccy, .lv-data, .lv-sector, .lv-score { display: none; }
  .lv-name { max-width: 150px; }
  .lv-status small { display: block; margin-left: 0; }
}
