:root {
  --bg: #0c1017;
  --surface: #141a24;
  --surface-2: #1b2331;
  --line: #26303f;
  --text: #e6ecf5;
  --muted: #8b9bb4;
  --accent: #4c8dff;
  --buy: #2ecc8f;
  --accumulate: #f0b429;
  --reject: #6b7a90;
  --danger: #ff6b6b;
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 "Segoe UI", system-ui, -apple-system, sans-serif;
}

body { display: flex; flex-direction: column; }

/* ------------------------------------------------------------ topbar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 14px 22px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 12px; }

.brand .logo {
  width: 36px;
  height: 36px;
  border-radius: 9px;
  object-fit: cover;
  flex: none;
  box-shadow: 0 0 16px rgba(240, 193, 75, .28);
}

.brand h1 { margin: 0; font-size: 16px; letter-spacing: .15px; font-weight: 650; }
.brand p { margin: 0; font-size: 12px; color: var(--muted); }

/* -------------------------------------------------------- live indicator */
.live-strip {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-left: auto;
}

.switch { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); cursor: pointer; }
.switch input { accent-color: var(--accent); cursor: pointer; }

.live-status { display: flex; align-items: center; font-size: 11.5px; color: var(--muted); }

.dot {
  width: 7px; height: 7px;
  margin-right: 6px;
  border-radius: 50%;
  background: var(--reject);
  flex: none;
}

.dot.live { background: var(--buy); animation: pulse 1.8s ease-in-out infinite; }
.dot.closed { background: var(--muted); }
.dot.error { background: var(--danger); }

@keyframes pulse {
  0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(46, 204, 143, .5); }
  50% { opacity: .55; box-shadow: 0 0 0 4px rgba(46, 204, 143, 0); }
}

.chg { font-size: 11.5px; font-weight: 600; font-variant-numeric: tabular-nums; }
.chg.up { color: var(--buy); }
.chg.down { color: var(--danger); }

.live-cell { position: relative; }

.drift {
  color: var(--accumulate);
  font-style: normal;
  font-weight: 700;
  cursor: help;
}

.cost { display: flex; gap: 10px; }

.cost-item {
  min-width: 84px;
  padding: 7px 12px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  text-align: center;
}

.cost-item span {
  display: block;
  font-size: 19px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.cost-item label {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: .7px;
  color: var(--muted);
}

/* ------------------------------------------------------------ headline tape */
.headline-tape {
  display: flex;
  align-items: stretch;
  flex: none;
  height: 36px;
  background: #101820;
  border-bottom: 1px solid #2a2418;
  overflow: hidden;
}

.headline-kicker {
  flex: none;
  display: flex;
  align-items: center;
  padding: 0 14px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: .8px;
  text-transform: uppercase;
  color: #f0c14b;
  border-right: 1px solid #2a2418;
}

.headline-window {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  display: flex;
  align-items: center;
}

.headline-track {
  display: flex;
  align-items: center;
  width: max-content;
  animation: headline-scroll 90s linear infinite;
}

.headline-track:hover { animation-play-state: paused; }

.headline-item {
  display: inline-flex;
  align-items: center;
  white-space: nowrap;
  padding: 0 8px 0 18px;
  font-size: 12.5px;
  color: #e8c56a;
}

.headline-item.muted { color: #8a7340; }

.headline-item .sym {
  margin-right: 8px;
  color: #ffd56a;
  font-weight: 600;
  font-size: 11px;
}

.headline-dot {
  color: #8a7340;
  padding: 0 4px;
}

@keyframes headline-scroll {
  from { transform: translateX(0); }
  to { transform: translateX(-50%); }
}

@media (prefers-reduced-motion: reduce) {
  .headline-track { animation: none; }
}

.cost-item.accent span { color: var(--accent); }

/* ------------------------------------------------------------- filters */
.filter-bar {
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.list-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 600;
}

.icon-btn.on {
  border-color: var(--accent);
  background: rgba(76, 141, 255, .16);
}

.list-toolbar .primary {
  width: auto;
  margin-left: auto;
  padding: 8px 16px;
  flex: 0 0 auto;
}

.filter-panel {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 10px 14px;
  padding: 0 12px 12px;
}

.filter-panel[hidden] { display: none; }

.filter {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 128px;
}

.filter.compact { min-width: 92px; max-width: 110px; flex: 0 0 92px; }
.filter.sector { min-width: 200px; flex: 1 1 180px; }
.filter.horizon { min-width: 220px; flex: 0 0 auto; }
.filter.gate { min-width: 160px; flex: 1 1 160px; }
.filter.gate b { color: var(--accent); font-weight: 600; }
.filter.gate input[type="range"] { width: 100%; padding: 8px 0; }

.segment {
  display: flex;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface-2);
}

.segment button {
  flex: 1;
  margin: 0;
  padding: 8px 12px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.segment button + button { border-left: 1px solid var(--line); }

.segment button.on {
  background: rgba(76, 141, 255, .18);
  color: var(--text);
  font-weight: 600;
}

.segment button:hover:not(:disabled):not(.on) {
  border-color: transparent;
  color: var(--text);
}

.filter span {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--muted);
}

.filter-status {
  padding: 0 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.filter-status:has(#progress[hidden]):has(#error[hidden]) {
  display: none;
}

.filter-status .progress { margin: 8px 0; }
.filter-status .error { margin: 8px 0; }

/* ------------------------------------------------------------- layout */
.app-shell {
  flex: 1;
  display: flex;
  min-height: 0;
}

.workspace {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

main {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 14px;
  min-height: 0;
}

main .results { flex: 1; min-height: 0; }

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: auto;
}

.menu-btn {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  width: 40px;
  height: 40px;
  padding: 8px;
  flex: none;
}

.menu-btn span {
  display: block;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
}

.sidenav {
  flex: none;
  width: 214px;
  padding: 12px 10px;
  background: var(--surface);
  border-right: 1px solid var(--line);
  overflow: auto;
}

.sidenav-kicker {
  margin: 12px 10px 6px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .7px;
  text-transform: uppercase;
  color: var(--muted);
}

.sidenav-kicker:first-child { margin-top: 4px; }

.nav-item {
  display: block;
  width: 100%;
  margin: 0 0 4px;
  padding: 9px 12px;
  text-align: left;
  font-size: 13px;
  background: transparent;
  border-color: transparent;
}

.nav-item:hover:not(:disabled) {
  background: var(--surface-2);
  border-color: transparent;
}

.nav-item.on {
  background: rgba(76, 141, 255, .16);
  border-color: transparent;
  color: var(--text);
  font-weight: 600;
}

.nav-backdrop {
  display: none;
}

.coming-soon {
  margin: 14px;
  padding: 28px 24px;
}

.coming-soon h2 { margin: 0 0 8px; font-size: 18px; }
.coming-soon p { margin: 0 0 6px; color: var(--muted); }

/* ------------------------------------------------------------ controls */
.field-label {
  display: block;
  margin-bottom: 6px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .7px;
  color: var(--muted);
}

.field-label .value { color: var(--accent); font-weight: 600; }

textarea, input[type="number"], select {
  width: 100%;
  padding: 8px 10px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 7px;
  font: inherit;
  outline: none;
}

textarea { resize: vertical; font-family: ui-monospace, Consolas, monospace; }

textarea:focus, input:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(76, 141, 255, .16);
}

input[type="range"] { width: 100%; accent-color: var(--accent); }

.row { display: flex; align-items: flex-end; }
.row.gap { gap: 8px; }
.half { flex: 1; }
.hint { margin: 6px 0 0; font-size: 11.5px; color: var(--muted); }
.error { margin: 10px 0 0; font-size: 12px; color: var(--danger); }

button {
  padding: 8px 14px;
  border-radius: 7px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  cursor: pointer;
  transition: background .15s, border-color .15s, opacity .15s;
}

button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: .45; cursor: not-allowed; }
.ghost { flex: 1; font-size: 12.5px; }

.primary {
  width: 100%;
  padding: 11px;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
}

.primary:hover:not(:disabled) { background: #3f7ceb; }

.progress { margin-top: 12px; font-size: 11.5px; color: var(--muted); }

.progress .bar {
  height: 5px;
  margin-bottom: 6px;
  background: var(--bg);
  border-radius: 3px;
  overflow: hidden;
}

.progress .fill {
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width .2s ease;
}

/* ------------------------------------------------------------- results */
.results-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 16px;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 2;
}

.results-head h2 { margin: 0; font-size: 14px; }
.results-head select { width: auto; }

.empty { padding: 40px 24px; text-align: center; color: var(--muted); }
.empty p { margin: 0 0 6px; }

table { width: 100%; border-collapse: collapse; }

th, td {
  padding: 9px 12px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

th {
  position: sticky;
  top: 47px;
  background: var(--surface-2);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}

th:hover { color: var(--text); }
th.num, td.num { text-align: right; font-variant-numeric: tabular-nums; }

tbody tr { cursor: pointer; transition: background .12s; }
tbody tr:hover { background: var(--surface-2); }
tbody tr.selected { background: rgba(76, 141, 255, .12); }
tbody tr.selected td:first-child { box-shadow: inset 2px 0 0 var(--accent); }

.ticker { font-weight: 600; display: flex; align-items: center; gap: 8px; }

.chev {
  flex: none;
  width: 0;
  height: 0;
  border: 4px solid transparent;
  border-left-color: var(--muted);
  margin-top: 1px;
  transition: transform .15s ease;
}

tr.open .chev {
  transform: rotate(90deg);
  border-left-color: var(--accent);
}

tbody tr.expand-row {
  cursor: default;
  background: #10161f;
}

tbody tr.expand-row:hover { background: #10161f; }

tbody tr.expand-row td {
  padding: 0;
  white-space: normal;
  box-shadow: inset 2px 0 0 var(--accent);
  border-bottom: 1px solid var(--line);
}

.expand-row .detail-inner {
  padding: 14px 16px 18px;
  max-width: 920px;
}

.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .3px;
}

.badge.BUY { background: rgba(46, 204, 143, .16); color: var(--buy); }
.badge.ACCUMULATE { background: rgba(240, 180, 41, .16); color: var(--accumulate); }
.badge.REJECT { background: rgba(107, 122, 144, .18); color: var(--reject); }

.pips { display: inline-flex; gap: 3px; }

.pip {
  width: 7px; height: 7px;
  border-radius: 2px;
  background: var(--line);
}

.pip.on { background: var(--accent); }

.tag { font-size: 11.5px; color: var(--muted); }
.tag.BULLISH { color: var(--buy); }
.tag.BEARISH { color: var(--danger); }

/* -------------------------------------------------------------- detail */
.detail { padding: 0; }
.detail-inner { padding: 16px; }

.detail h3 { margin: 0 0 2px; font-size: 16px; }
.detail .sub { margin: 0 0 14px; font-size: 12px; color: var(--muted); }

.price-head {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
}

.price-head .now {
  font-size: 24px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.stale {
  margin: 0 0 12px;
  padding: 8px 10px;
  border-radius: 7px;
  border-left: 2px solid var(--danger);
  background: rgba(255, 107, 107, .1);
  font-size: 11.5px;
  color: #ffd0d0;
}

.detail .live {
  margin: 0 0 12px;
  padding: 7px 10px;
  border-radius: 7px;
  border-left: 2px solid var(--accumulate);
  background: rgba(240, 180, 41, .1);
  font-size: 11.5px;
  color: #f4dca0;
}

.detail h4 {
  margin: 18px 0 8px;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: .7px;
  color: var(--muted);
}

.verdict {
  padding: 12px;
  border-radius: 8px;
  background: var(--surface-2);
  border: 1px solid var(--line);
}

.verdict .top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.verdict p { margin: 0; font-size: 12.5px; color: #cbd6e6; }

.buy-card {
  margin: 0 0 12px;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--surface-2);
  border: 1px solid var(--line);
}

.buy-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  margin-bottom: 8px;
}

.buy-row label {
  display: block;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--muted);
}

.buy-row b {
  font-size: 16px;
  font-variant-numeric: tabular-nums;
}

.buy-card p { margin: 0; font-size: 12px; color: #cbd6e6; }

.levels { display: flex; gap: 8px; margin-top: 12px; }

.level {
  flex: 1;
  padding: 8px;
  text-align: center;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.level span {
  display: block;
  font-size: 14px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.level label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--muted);
}

.level.stop span { color: var(--danger); }
.level.target span { color: var(--buy); }

.horizon {
  margin: 8px 0 0;
  padding: 8px 10px;
  border-radius: 7px;
  border-left: 2px solid var(--accent);
  background: rgba(76, 141, 255, .1);
  font-size: 11.5px;
  color: #c7d8f5;
}

.horizon b { font-variant-numeric: tabular-nums; }

ul.notes { margin: 0; padding-left: 16px; }
ul.notes li { margin-bottom: 5px; font-size: 12.5px; color: #cbd6e6; }
ul.notes li.risk { color: #ffd0d0; }

.metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }

.metric {
  display: flex;
  justify-content: space-between;
  padding: 6px 9px;
  background: var(--surface-2);
  border-radius: 6px;
  font-size: 12px;
}

.metric b { font-variant-numeric: tabular-nums; font-weight: 600; }

.spark { width: 100%; height: 78px; display: block; }
.spark .price { fill: none; stroke: var(--accent); stroke-width: 1.6; }
.spark .ema { fill: none; stroke: var(--accumulate); stroke-width: 1.2; stroke-dasharray: 3 3; }
.spark .area { fill: rgba(76, 141, 255, .12); stroke: none; }

.legend { display: flex; gap: 14px; margin-top: 4px; font-size: 11px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 2px; margin-right: 5px; vertical-align: middle; }
.legend .p i { background: var(--accent); }
.legend .e i { background: var(--accumulate); }

@media (max-width: 980px) {
  .hide-md { display: none; }
  .menu-btn { display: flex; }
  .sidenav {
    position: fixed;
    z-index: 30;
    top: 0;
    left: 0;
    bottom: 0;
    transform: translateX(-105%);
    transition: transform .18s ease;
    box-shadow: 8px 0 24px rgba(0, 0, 0, .35);
  }
  body.nav-open .sidenav { transform: none; }
  .nav-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 25;
    background: rgba(0, 0, 0, .45);
  }
  .nav-backdrop[hidden] { display: none; }
}

@media (max-width: 760px) {
  .topbar { gap: 12px; padding: 10px 12px; }
  .brand p { display: none; }
  .live-strip { margin-left: 0; }
  .filter, .filter.sector, .filter.horizon, .filter.gate {
    min-width: 0;
    flex: 1 1 100%;
    max-width: none;
  }
  .list-toolbar .primary {
    padding: 10px 14px;
  }
  .filter-bar .primary {
    width: auto;
    margin-left: auto;
    padding: 10px 14px;
  }
  main { padding: 10px; }
  .coming-soon { margin: 10px; }
  .results-head { flex-wrap: wrap; padding: 12px; }
  th, td { padding: 10px 8px; }
  .hide-sm { display: none; }
  .buy-row { grid-template-columns: 1fr; }
  .levels { flex-wrap: wrap; }
  .level { min-width: 40%; flex: 1 1 40%; }
}
