:root {
  --bg:        #080b12;
  --bg-grad:   radial-gradient(1200px 600px at 80% -10%, #11203a 0%, transparent 55%),
               radial-gradient(900px 500px at -10% 10%, #1a1430 0%, transparent 50%),
               #080b12;
  --panel:     #0e1320;
  --panel-2:   #11182a;
  --border:    #1d2740;
  --border-2:  #2c3a5c;
  --text:      #e7edf8;
  --muted:     #8a97b1;
  --muted-2:   #5d6985;
  --up:        #16c784;
  --up-dim:    rgba(22,199,132,.14);
  --down:      #f6465d;
  --down-dim:  rgba(246,70,93,.14);
  --hold:      #f0b90b;
  --accent:    #4c8dff;
  --accent-2:  #7aa7ff;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", "JetBrains Mono", Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  background: var(--bg-grad);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

h2 { font-size: 13px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 11.5px; }
.mono  { font-family: var(--mono); }

/* ── Top bar ─────────────────────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 12px 22px;
  border-bottom: 1px solid var(--border);
  background: rgba(10,14,22,.7);
  backdrop-filter: blur(8px);
}
.brand { display: flex; align-items: baseline; gap: 9px; }
.logo { color: var(--accent); font-size: 20px; transform: translateY(2px); }
.brand-name { font-weight: 800; letter-spacing: .18em; font-size: 18px; }
.brand-sub { color: var(--muted-2); font-size: 11px; letter-spacing: .22em; text-transform: uppercase; }

.mode-badge {
  font-family: var(--mono); font-size: 11px; font-weight: 700; letter-spacing: .08em;
  padding: 4px 10px; border-radius: 6px;
  border: 1px solid var(--border); color: var(--muted); background: var(--panel);
}
.mode-badge.live {
  color: var(--up); border-color: rgba(22,199,132,.5); background: var(--up-dim);
  box-shadow: 0 0 12px rgba(22,199,132,.25);
}
.mode-badge.sim {
  color: var(--hold); border-color: rgba(240,185,11,.5); background: rgba(240,185,11,.10);
}

.market-state {
  display: flex; align-items: center; gap: 8px;
  margin-left: auto;
  font-size: 12.5px; color: var(--muted);
  font-family: var(--mono);
}
.market-state .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--up); box-shadow: 0 0 10px var(--up); }
.market-state .sep { color: var(--muted-2); }
.market-state .clock { color: var(--text); }
.market-state .utc { color: var(--muted-2); font-size: 10px; }

.conn {
  display: flex; align-items: center; gap: 7px;
  font-size: 12px; color: var(--muted);
  padding: 5px 11px; border: 1px solid var(--border); border-radius: 20px;
  background: var(--panel);
}
.conn-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted-2); transition: background .3s; }
.conn.live    .conn-dot { background: var(--up); box-shadow: 0 0 9px var(--up); }
.conn.live    #conn-text { color: var(--up); }
.conn.warn    .conn-dot { background: var(--hold); box-shadow: 0 0 9px var(--hold); }
.conn.offline .conn-dot { background: var(--down); }
.conn.offline #conn-text { color: var(--down); }

/* ── Ticker tape ─────────────────────────────────────────────────────── */
.tape {
  overflow: hidden;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(var(--panel), #0b0f1a);
  white-space: nowrap;
}
.tape-track {
  display: inline-flex;
  gap: 30px;
  padding: 8px 0;
  animation: marquee 60s linear infinite;
  will-change: transform;
}
.tape:hover .tape-track { animation-play-state: paused; }
@keyframes marquee { from { transform: translateX(0); } to { transform: translateX(-50%); } }
.tape-item { font-family: var(--mono); font-size: 12.5px; color: var(--muted); }
.tape-item b { color: var(--text); font-weight: 600; margin-right: 7px; }
.tape-item .up { color: var(--up); }
.tape-item .down { color: var(--down); }

/* ── Summary strip ───────────────────────────────────────────────────── */
.summary {
  display: flex; gap: 10px;
  padding: 14px 22px;
}
.stat {
  display: flex; flex-direction: column; gap: 3px;
  padding: 9px 16px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  min-width: 92px;
}
.stat.grow { margin-left: auto; }
.stat-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted-2); }
.stat-val { font-family: var(--mono); font-size: 20px; font-weight: 600; }
.stat-val.up { color: var(--up); }
.stat-val.down { color: var(--down); }
.stat-val.buy { color: var(--up); }
.stat-val.hold { color: var(--hold); }
.stat-val.sell { color: var(--down); }

/* ── Grid ────────────────────────────────────────────────────────────── */
.grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 16px;
  padding: 4px 22px 22px;
  flex: 1;
}
.col-main { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.col-side { min-width: 0; }

.card {
  background: linear-gradient(180deg, var(--panel) 0%, #0b101c 100%);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}

/* ── Detail chart ────────────────────────────────────────────────────── */
.detail-head {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 24px;
  align-items: center;
  padding: 18px 20px 12px;
}
.detail-sym { font-size: 26px; font-weight: 800; letter-spacing: .02em; }
.detail-name { color: var(--muted); font-size: 13px; margin-top: 2px; }
.detail-price-wrap { text-align: right; }
.detail-price { font-family: var(--mono); font-size: 30px; font-weight: 600; }
.detail-change { font-family: var(--mono); font-size: 14px; margin-top: 2px; }
.detail-change.up { color: var(--up); }
.detail-change.down { color: var(--down); }

.detail-signal { display: flex; flex-direction: column; align-items: flex-end; gap: 7px; min-width: 130px; }
.sentiment-gauge {
  width: 130px; height: 6px; border-radius: 3px;
  background: linear-gradient(90deg, var(--down), #586079 50%, var(--up));
  position: relative;
}
.sentiment-fill {
  position: absolute; top: -3px; width: 3px; height: 12px; border-radius: 2px;
  background: #fff; left: 50%; transform: translateX(-50%);
  transition: left .4s ease;
  box-shadow: 0 0 8px rgba(255,255,255,.6);
}
.sentiment-label { font-size: 10px; color: var(--muted-2); text-transform: uppercase; letter-spacing: .08em; }

.chart-wrap { position: relative; padding: 0 6px 10px; }

.range-bar { display: flex; gap: 6px; padding: 4px 12px 10px; }
.range-bar button {
  font-family: var(--mono); font-size: 11px; font-weight: 600;
  color: var(--muted); background: var(--panel); cursor: pointer;
  border: 1px solid var(--border); border-radius: 6px; padding: 4px 11px;
  transition: all .12s;
}
.range-bar button:hover { color: var(--text); border-color: var(--border-2); }
.range-bar button.active {
  color: #0a0e17; background: var(--accent); border-color: var(--accent);
  font-weight: 700; box-shadow: 0 0 10px rgba(76,141,255,.35);
}

/* news sentiment-source chip */
.sent-source {
  font-family: var(--mono); font-size: 11px; font-weight: 700; letter-spacing: .03em;
  padding: 3px 9px; border-radius: 6px; border: 1px solid var(--border);
  color: var(--muted); background: var(--panel);
}
.sent-source.ai { color: var(--up); border-color: rgba(22,199,132,.45); background: var(--up-dim); }
.sent-source.keyword { color: var(--hold); border-color: rgba(240,185,11,.55); background: rgba(240,185,11,.14); }
.sent-source.sim     { color: var(--muted-2); }

/* chart hover crosshair + tooltip */
.chart-cursor {
  position: absolute; width: 1px; background: var(--border-2);
  pointer-events: none; display: none; z-index: 2;
}
.chart-dot {
  position: absolute; width: 9px; height: 9px; border-radius: 50%;
  transform: translate(-50%, -50%); border: 2px solid var(--panel);
  box-shadow: 0 0 7px rgba(0,0,0,.6); pointer-events: none; display: none; z-index: 3;
}
.chart-tip {
  position: absolute; pointer-events: none; display: none; z-index: 4;
  background: var(--panel-2); border: 1px solid var(--border-2); border-radius: 6px;
  padding: 5px 9px; font-family: var(--mono); white-space: nowrap;
  box-shadow: 0 4px 14px rgba(0,0,0,.5);
}
.chart-tip b { display: block; font-size: 13px; color: var(--text); }
.chart-tip span { font-size: 10px; color: var(--muted); }
.chart { width: 100%; height: 220px; display: block; }
.chart-meta {
  display: flex; justify-content: space-between;
  padding: 0 14px; font-family: var(--mono); font-size: 11px; color: var(--muted-2);
}

/* ── Badges ──────────────────────────────────────────────────────────── */
.badge {
  font-family: var(--mono); font-size: 12px; font-weight: 700; letter-spacing: .06em;
  padding: 4px 12px; border-radius: 6px; text-align: center;
}
.badge.BUY  { color: var(--up);   background: var(--up-dim);   border: 1px solid rgba(22,199,132,.4); }
.badge.HOLD { color: var(--hold); background: rgba(240,185,11,.12); border: 1px solid rgba(240,185,11,.4); }
.badge.SELL { color: var(--down); background: var(--down-dim); border: 1px solid rgba(246,70,93,.4); }

/* ── Watchlist table ─────────────────────────────────────────────────── */
.table-head, .row {
  display: grid;
  grid-template-columns: 1.7fr 1fr 1.1fr 1.2fr 1.1fr 0.9fr;
  align-items: center;
  gap: 8px;
  padding: 0 18px;
}
.table-head {
  height: 34px;
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted-2);
  border-bottom: 1px solid var(--border);
}
.table-head .c-price, .table-head .c-chg { text-align: right; }
.table-head .c-sig { text-align: right; }

.table-head .sortable { cursor: pointer; transition: color .12s; }
.table-head .sortable:hover { color: var(--muted); }
.table-head .sort-asc, .table-head .sort-desc { color: var(--accent); }
.table-head .sort-asc::after  { content: ' ▲'; font-size: 8px; }
.table-head .sort-desc::after { content: ' ▼'; font-size: 8px; }
.table-body { max-height: 52vh; overflow-y: auto; }

.row {
  height: 52px;
  border-bottom: 1px solid rgba(29,39,64,.5);
  cursor: pointer;
  transition: background .15s;
}
.row:hover { background: rgba(76,141,255,.06); }
.row.selected { background: rgba(76,141,255,.10); box-shadow: inset 3px 0 0 var(--accent); }

.cell-sym { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.cell-sym .sym { font-weight: 700; font-size: 14px; }
.cell-sym .name { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.cell-price { text-align: right; font-family: var(--mono); font-size: 15px; }
.cell-chg   { text-align: right; font-family: var(--mono); font-size: 13px; }
.cell-chg.up { color: var(--up); }
.cell-chg.down { color: var(--down); }
.cell-chg .arrow { font-size: 10px; }

.cell-spark svg { width: 100%; height: 30px; display: block; }
.cell-sent { display: flex; flex-direction: column; gap: 3px; padding-right: 10px; justify-content: center; }
.sent-val { font-family: var(--mono); font-size: 12.5px; font-weight: 700; line-height: 1; }
.sent-val.pos { color: var(--up); }
.sent-val.neg { color: var(--down); }
.sent-val.neu { color: var(--muted-2); }
.sent-bar { height: 6px; border-radius: 3px; background: var(--panel-2); position: relative; overflow: hidden; }
.sent-bar::before { content: ""; position: absolute; left: 50%; top: 0; bottom: 0; width: 1px; background: var(--border-2); }
.sent-bar > span { position: absolute; top: 0; bottom: 0; }
.sent-bar > span.pos { left: 50%; background: var(--up); }
.sent-bar > span.neg { right: 50%; background: var(--down); }

.cell-sig { text-align: right; }

/* price flash */
@keyframes flashUp   { 0% { background: var(--up-dim);   } 100% { background: transparent; } }
@keyframes flashDown { 0% { background: var(--down-dim); } 100% { background: transparent; } }
.flash-up   { animation: flashUp .7s ease-out; }
.flash-down { animation: flashDown .7s ease-out; }

/* ── News feed ───────────────────────────────────────────────────────── */
.news-body { max-height: calc(52vh + 300px); overflow-y: auto; }
.news-item {
  padding: 12px 18px;
  border-bottom: 1px solid rgba(29,39,64,.5);
  display: grid; grid-template-columns: auto 1fr; gap: 11px;
}
.news-item.fresh { animation: slideIn .5s ease; }
@keyframes slideIn { from { opacity: 0; transform: translateY(-6px); background: rgba(76,141,255,.10);} to { opacity: 1; } }
.news-tag {
  font-family: var(--mono); font-size: 11px; font-weight: 700;
  padding: 3px 7px; border-radius: 5px; height: fit-content;
  background: var(--panel-2); border: 1px solid var(--border);
}
.news-tag.pos { color: var(--up); border-color: rgba(22,199,132,.4); }
.news-tag.neg { color: var(--down); border-color: rgba(246,70,93,.4); }
.news-tag.neu { color: var(--muted); }
.news-text { min-width: 0; }
.news-headline { font-size: 13px; line-height: 1.4; }
.news-meta { font-size: 11px; color: var(--muted-2); margin-top: 4px; font-family: var(--mono); }
.news-sent-dot { display:inline-block; width:7px; height:7px; border-radius:50%; margin-right:5px; vertical-align: middle; }
.news-sent-dot.pos { background: var(--up); }
.news-sent-dot.neg { background: var(--down); }
.news-sent-dot.neu { background: var(--muted-2); }

/* scrollbars */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 5px; }
::-webkit-scrollbar-track { background: transparent; }

/* ── Footer ──────────────────────────────────────────────────────────── */
.disclaimer {
  padding: 12px 22px;
  text-align: center;
  font-size: 11px;
  color: var(--muted-2);
  border-top: 1px solid var(--border);
}

@media (max-width: 980px) {
  .grid { grid-template-columns: 1fr; }
  .detail-head { grid-template-columns: 1fr 1fr; }
  .detail-signal { grid-column: 1 / -1; align-items: flex-start; flex-direction: row; }
}

/* ── AI analyst panel ───────────────────────────────────────────────────────── */
.analyst {
  margin-top: 14px;
  padding-top: 13px;
  border-top: 1px solid var(--border);
}
.analyst-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 9px;
}
.analyst-title {
  font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase;
  color: var(--accent-2);
}
.analyst-meta { font-size: 11px; color: var(--muted-2); font-family: var(--mono); }
.analyst-conf {
  display: flex; align-items: center; gap: 9px; margin-bottom: 11px;
}
.conf-gauge {
  flex: 1; height: 6px; border-radius: 4px; overflow: hidden;
  background: var(--panel-2); border: 1px solid var(--border);
}
.conf-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width .5s ease;
}
.analyst-rationale {
  margin: 0; font-size: 13px; line-height: 1.55; color: var(--text);
}
.analyst-factors {
  margin: 11px 0 0; padding: 0; list-style: none;
  display: flex; flex-wrap: wrap; gap: 6px;
}
.analyst-factors li {
  font-size: 11.5px; color: var(--muted);
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 12px; padding: 3px 10px;
}
