* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #07070d;
  --panel: #0d0d18;
  --head: #10101e;
  --border: #1c1c2e;
  --text-primary: #e8e8f8;
  --text-secondary: #c8c8d8;
  --text-muted: #5a5a7a;
  --accent: #7c7cff;
  --good: #00e676;
  --crit: #ff4444;
  --neut: #ffd740;
  --mono: 'JetBrains Mono', monospace;
  --sans: 'Inter', sans-serif;
}

html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text-secondary);
  font-family: var(--sans);
  font-size: 13px;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 22px;
  background: var(--head);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark { width: 26px; height: 26px; flex-shrink: 0; }
.brand h1 {
  font-family: var(--mono);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 3px;
  color: var(--text-primary);
  text-transform: uppercase;
}
.brand h1 span { color: var(--accent); }

#statusbar { display: flex; align-items: center; gap: 16px; font-family: var(--mono); font-size: 11px; color: var(--text-muted); }
.about-link {
  color: var(--text-secondary);
  text-decoration: none;
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 600;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  transition: border-color .15s, color .15s;
}
.about-link:hover { border-color: var(--accent); color: var(--text-primary); }
#dot { width: 8px; height: 8px; border-radius: 50%; background: #444; }
#dot.live { background: var(--good); animation: pulse 2s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .4; } }

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 12px 22px;
  background: var(--head);
  border-bottom: 1px solid var(--border);
}
.tab-btn {
  background: var(--panel);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 9px 16px;
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 9px;
  transition: border-color .15s, color .15s;
}
.tab-btn:hover { border-color: var(--accent); color: var(--text-primary); }
.tab-btn.active {
  background: #1a1a3a;
  color: var(--text-primary);
  border-color: var(--accent);
}
.tier-badge {
  font-family: var(--mono);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 1px;
  padding: 2px 7px;
  border-radius: 8px;
}
.tier-badge.tier-paid { background: rgba(255, 215, 64, .18); color: var(--neut); border: 1px solid rgba(255, 215, 64, .3); }
.tier-badge.tier-free { background: rgba(0, 230, 118, .15); color: var(--good); border: 1px solid rgba(0, 230, 118, .3); }

/* Height is set explicitly in px by sizeContentArea() in index.html, not by
   flex-grow -- flex sizing of a replaced element (iframe) through nested
   flex containers proved unreliable across real browsers/zoom/DPI. */
.view { display: flex; flex-direction: column; overflow: auto; box-sizing: border-box; }

.kpi-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  padding: 16px 22px 0;
}
.kpi {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 16px;
}
.kpi-label {
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.kpi-val {
  font-family: var(--mono);
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
}
.kpi-val.kpi-good { color: var(--good); }
.kpi-val.kpi-crit { color: var(--crit); }

.panel {
  margin: 14px 22px 22px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: auto;
  flex: 1;
}
table { width: 100%; border-collapse: collapse; }
th {
  background: var(--head);
  color: var(--text-muted);
  padding: 9px 14px;
  text-align: left;
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 1;
}
td {
  padding: 9px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, .03);
  vertical-align: top;
  font-size: 12px;
}
tbody tr:hover td { background: rgba(124, 124, 255, .05); }
td.mono { font-family: var(--mono); font-size: 11px; }
td.muted { color: var(--text-muted); }
td.sym { color: #a0a0ff; font-weight: 700; white-space: nowrap; font-family: var(--mono); }
td.msg { color: var(--text-secondary); line-height: 1.5; max-width: 640px; }
td.empty { text-align: center; color: var(--text-muted); padding: 40px; }

.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 4px;
  font-family: var(--mono);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 1px;
}
.badge-bull { background: rgba(0, 230, 118, .15); color: var(--good); border: 1px solid rgba(0, 230, 118, .3); }
.badge-bear { background: rgba(255, 68, 68, .15); color: var(--crit); border: 1px solid rgba(255, 68, 68, .3); }
.badge-neut { background: rgba(255, 215, 64, .12); color: var(--neut); border: 1px solid rgba(255, 215, 64, .25); }

/* #embed-frame's height is set explicitly in px by JS -- see sizeContentArea()
   in index.html. No flex sizing here; it proved unreliable for a replaced
   element (iframe) nested inside body -> #embed-view -> #embed-frame. */
#embed-view { display: block; }
#embed-frame { display: block; border: none; width: 100%; }

/* 52-Week Breakout's banded grid: closest-to-breakout stocks grouped by
   urgency instead of one flat, alphabetically-ordered log. */
.band-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
  margin: 14px 22px 22px;
  overflow-y: auto;
}
.band-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.band-card.band-imminent { border-color: rgba(255, 68, 68, .4); }
.band-card.band-near     { border-color: rgba(255, 215, 64, .4); }
.band-card.band-building { border-color: rgba(124, 124, 255, .4); }
.band-card.band-watch    { border-color: var(--border); }
.band-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  background: var(--head);
  border-bottom: 1px solid var(--border);
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--text-secondary);
}
.band-count { font-family: var(--mono); font-weight: 700; color: var(--text-primary); }
.band-rows { max-height: 360px; overflow-y: auto; }
.band-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 8px 14px 8px 11px;
  border-bottom: 1px solid rgba(255, 255, 255, .03);
  border-left: 3px solid transparent;
  font-size: 12px;
}
.band-row:last-child { border-bottom: none; }
.band-row:hover { background: rgba(124, 124, 255, .05); }

/* Direction is the signal a trader scans for first -- near a 52w HIGH
   (bullish, strength) reads green, near a 52w LOW (bearish, weakness) reads
   red, on both the symbol and its own % figure, plus a left accent bar so
   the whole row registers at a glance without reading the arrow glyph.
   Reuses the same --good/--crit tokens as every other tab's bull/bear badges
   instead of inventing a one-off palette here. */
.band-row.dir-bull { border-left-color: rgba(0, 230, 118, .55); }
.band-row.dir-bear { border-left-color: rgba(255, 68, 68, .55); }
.band-row.dir-bull .b-sym { color: var(--good); }
.band-row.dir-bear .b-sym { color: var(--crit); }
.band-row .b-sym {
  font-weight: 700;
  font-family: var(--mono);
  white-space: nowrap;
}
.band-row.dir-bull .b-detail { color: var(--good); }
.band-row.dir-bear .b-detail { color: var(--crit); }
.band-row .b-detail {
  text-align: right;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
/* Volume is a separate dimension from direction (how busy, not which way) --
   kept neutral so it doesn't visually compete with the bull/bear read. */
.band-row .b-vol { color: var(--text-muted); font-weight: 400; }
.band-empty { padding: 20px; text-align: center; color: var(--text-muted); font-size: 12px; }

@media (max-width: 900px) {
  .band-grid { grid-template-columns: 1fr; }
}

/* Mobile: tabs wrap to 2+ rows and eat huge vertical space at 8 tabs, and a
   4-column KPI grid doesn't have room to breathe below ~480px -- switch tabs
   to a single horizontally-scrollable strip (thumb-swipe, standard mobile
   pattern) and KPIs to 2 columns. Embedded scanner pages (uoa_master,
   sp_pro, v6, commodity) aren't touched here -- they're each other scripts'
   own HTML and stay pixel-identical to the originals by design; only this
   shell (topbar/tabs/KPI/feed table) is addressed. */
@media (max-width: 640px) {
  #topbar { padding: 10px 14px; }
  .brand h1 { font-size: 12px; letter-spacing: 2px; }
  #statusbar { gap: 10px; }
  .about-link { padding: 5px 9px; font-size: 11px; }
  #clock { display: none; }

  .tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    padding: 10px 14px;
    -webkit-overflow-scrolling: touch;
  }
  .tab-btn { flex-shrink: 0; }

  .kpi-row { grid-template-columns: repeat(2, 1fr); padding: 12px 14px 0; }
  .panel { margin: 12px 14px 14px; }
  td.msg { max-width: 220px; }
}
