/* ── Reset & Variables ── */
:root {
  --bg:        #080c18;
  --bg2:       #0d1224;
  --card:      #111827;
  --card-border: rgba(255,255,255,0.07);
  --text:      #e2e8f0;
  --muted:     #8892a4;
  --green:     #22d3a0;
  --green-dim: rgba(34,211,160,0.12);
  --red:       #f87171;
  --red-dim:   rgba(248,113,113,0.12);
  --yellow:    #fbbf24;
  --blue:      #60a5fa;
  --accent:    #6366f1;
  --accent-dim: rgba(99,102,241,0.15);
  --radius:    14px;
  --radius-sm: 8px;
}

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

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 15px;
  line-height: 1.5;
}

/* ── Header ── */
header {
  background: var(--bg2);
  border-bottom: 1px solid var(--card-border);
  padding: 1rem 1.5rem;
  position: sticky;
  top: 0;
  z-index: 10;
}
.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.header-left {
  display: flex;
  align-items: center;
  gap: .75rem;
}
.header-icon {
  font-size: 1.4rem;
  color: var(--green);
  line-height: 1;
}
.header-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: -.01em;
}
.header-sub {
  font-size: .8rem;
  color: var(--muted);
}
.header-right {
  display: flex;
  align-items: center;
  gap: .75rem;
  flex-shrink: 0;
}
.badge {
  font-size: .75rem;
  font-weight: 700;
  padding: .25rem .65rem;
  border-radius: 20px;
  background: var(--accent-dim);
  color: #a5b4fc;
  border: 1px solid rgba(99,102,241,.35);
  text-transform: uppercase;
  letter-spacing: .04em;
}
.updated-at {
  font-size: .78rem;
  color: var(--muted);
}

/* ── Main Layout ── */
main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

/* ── KPI Grid ── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
}
@media (max-width: 900px) { .kpi-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 500px) { .kpi-grid { grid-template-columns: 1fr; } }

.kpi-card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 1.1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: .2rem;
}
.kpi-label {
  font-size: .78rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .06em;
}
.kpi-value {
  font-size: 1.6rem;
  font-weight: 800;
  letter-spacing: -.02em;
  color: #fff;
}
.kpi-sub {
  font-size: .82rem;
  color: var(--muted);
}

/* ── Cards ── */
.card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 1.25rem;
}
.card-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.card-title {
  font-size: 1rem;
  font-weight: 700;
  color: #fff;
}
.card-sub {
  font-size: .82rem;
  color: var(--muted);
}

/* ── Chart ── */
.chart-card {}
.chart-legend {
  display: flex;
  align-items: center;
  gap: .5rem;
  font-size: .8rem;
  color: var(--muted);
}
.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}
.legend-dot.green  { background: var(--green); }
.legend-dot.yellow { background: var(--yellow); }

.chart-wrap {
  position: relative;
  height: 260px;
}

/* ── Tables ── */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
table {
  width: 100%;
  border-collapse: collapse;
}
th, td {
  padding: .6rem .75rem;
  text-align: right;
  white-space: nowrap;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  font-size: .85rem;
}
th:first-child, td:first-child { text-align: left; }
th {
  color: var(--muted);
  font-weight: 600;
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  background: rgba(255,255,255,0.02);
}
tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: rgba(255,255,255,0.03); }

.ticker-cell {
  font-weight: 700;
  font-size: .9rem;
  color: #fff;
  display: flex;
  align-items: center;
  gap: .4rem;
}
.ticker-link {
  color: #fff;
  text-decoration: none;
  font-weight: 700;
}
.ticker-link:hover { color: var(--green); text-decoration: underline; }
.tv-link {
  color: var(--muted);
  font-size: .65rem;
  text-decoration: none;
  opacity: .6;
  transition: opacity .15s;
}
.tv-link:hover { opacity: 1; color: var(--yellow); }
.score-badge {
  font-size: .7rem;
  font-weight: 700;
  padding: .15rem .4rem;
  border-radius: 6px;
  background: var(--accent-dim);
  color: #a5b4fc;
  border: 1px solid rgba(99,102,241,.3);
}
.alloc-bar-wrap {
  display: flex;
  align-items: center;
  gap: .5rem;
  justify-content: flex-end;
}
.alloc-bar-bg {
  width: 60px;
  height: 6px;
  border-radius: 3px;
  background: rgba(255,255,255,0.08);
  overflow: hidden;
}
.alloc-bar-fill {
  height: 100%;
  border-radius: 3px;
  background: var(--accent);
}
.reason-cell {
  max-width: 280px;
  white-space: normal;
  color: var(--muted);
  font-size: .8rem;
  text-align: left;
}
.loading-price {
  color: var(--muted);
  font-style: italic;
  font-size: .8rem;
}
.live-badge {
  font-size: .65rem;
  font-weight: 700;
  padding: .1rem .35rem;
  border-radius: 4px;
  background: rgba(34,211,160,0.15);
  color: var(--green);
  border: 1px solid rgba(34,211,160,0.3);
  vertical-align: middle;
  margin-left: .3rem;
}
.closed-badge {
  font-size: .65rem;
  font-weight: 700;
  padding: .1rem .35rem;
  border-radius: 4px;
  background: rgba(255,255,255,0.07);
  color: var(--muted);
  border: 1px solid rgba(255,255,255,0.1);
  vertical-align: middle;
  margin-left: .3rem;
}
.stop-badge {
  font-size: .65rem;
  font-weight: 700;
  padding: .1rem .35rem;
  border-radius: 4px;
  background: rgba(251,146,60,0.15);
  color: #fb923c;
  border: 1px solid rgba(251,146,60,0.3);
  vertical-align: middle;
  margin-left: .3rem;
}

/* ── Colors ── */
.up   { color: var(--green); }
.down { color: var(--red);   }
.neutral { color: var(--muted); }

.kpi-value.up   { color: var(--green); }
.kpi-value.down { color: var(--red);   }

/* ── Loading / empty states ── */
td.empty {
  text-align: center;
  color: var(--muted);
  padding: 2rem;
}

/* ── Local file notice ── */
.notice {
  background: #1a2040;
  border: 1px dashed rgba(99,102,241,.5);
  color: #c7d0f0;
  border-radius: var(--radius);
  padding: .85rem 1.1rem;
  font-size: .88rem;
  line-height: 1.6;
}
.notice code {
  font-family: ui-monospace, monospace;
  font-size: .85em;
  color: #a5b4fc;
}
.notice.hidden { display: none; }
.local-btn {
  cursor: pointer;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: .4rem .85rem;
  font-size: .85rem;
  font-weight: 600;
}

/* ── Footer ── */
footer {
  text-align: center;
  padding: 1.5rem;
  font-size: .82rem;
  color: var(--muted);
  border-top: 1px solid var(--card-border);
  margin-top: 1rem;
}

/* ── Stats Bar ── */
.stats-bar {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: .85rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-around;
  gap: 1rem;
  flex-wrap: wrap;
}
.stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .15rem;
}
.stat-label {
  font-size: .72rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .06em;
}
.stat-value {
  font-size: 1.1rem;
  font-weight: 800;
  letter-spacing: -.02em;
  color: #fff;
}
.stat-divider {
  width: 1px;
  height: 32px;
  background: var(--card-border);
  flex-shrink: 0;
}
@media (max-width: 600px) {
  .stats-bar { justify-content: flex-start; gap: 1.25rem; }
  .stat-divider { display: none; }
}

/* ── Score badge colours ── */
.score-badge.score-high { background: rgba(34,211,160,0.15); color: var(--green); border-color: rgba(34,211,160,0.35); }
.score-badge.score-mid  { background: rgba(251,191,36,0.12);  color: var(--yellow); border-color: rgba(251,191,36,0.3); }
.score-badge.score-low  { background: rgba(251,146,60,0.12);  color: #fb923c; border-color: rgba(251,146,60,0.3); }

/* ── P&L bar inside return cell ── */
.ret-cell-wrap {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
}
.pnl-bar-bg {
  width: 60px;
  height: 3px;
  border-radius: 2px;
  background: rgba(255,255,255,0.06);
  overflow: hidden;
}
.pnl-bar {
  height: 100%;
  border-radius: 2px;
  transition: width .4s ease;
}

/* ── Clickable history rows ── */
#historyTable tbody tr { cursor: pointer; }
#historyTable tbody tr.active-session td { background: rgba(99,102,241,0.1); }

/* ── View Today button ── */
.view-today-btn {
  font-size: .75rem;
  font-weight: 600;
  padding: .2rem .6rem;
  border-radius: var(--radius-sm);
  background: var(--accent-dim);
  color: #a5b4fc;
  border: 1px solid rgba(99,102,241,.35);
  cursor: pointer;
}
.view-today-btn:hover { background: rgba(99,102,241,.3); }
.view-today-btn.hidden { display: none; }

/* ── Refresh countdown ── */
.refresh-countdown {
  font-size: .75rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* ── Runner-ups section ─────────────────────────────────────────────────────── */

.runner-ups-section {
  margin-top: 1.5rem;
  border-top: 1px solid var(--border, rgba(255,255,255,0.08));
  padding-top: 1.25rem;
}

.runner-ups-section.hidden { display: none; }

.runner-ups-header {
  display: flex;
  align-items: center;
  gap: .75rem;
  flex-wrap: wrap;
  margin-bottom: .9rem;
}

.not-picked-badge {
  display: inline-block;
  background: rgba(248, 113, 113, 0.15);
  color: var(--red);
  border: 1px solid rgba(248, 113, 113, 0.4);
  border-radius: 4px;
  font-size: .7rem;
  font-weight: 700;
  letter-spacing: .07em;
  padding: .2rem .5rem;
  text-transform: uppercase;
}

.runner-ups-title {
  font-size: .9rem;
  font-weight: 600;
  color: var(--muted);
}

.runner-ups-sub {
  font-size: .78rem;
  color: var(--muted);
  opacity: .7;
}

#runnerUpsTable thead th {
  color: var(--muted);
  opacity: .75;
  font-size: .72rem;
}

#runnerUpsTable tbody tr td {
  opacity: .8;
}

#runnerUpsTable tbody tr:hover td {
  opacity: 1;
  background: rgba(248, 113, 113, 0.04);
}
