:root {
  --bg: #070b12;
  --bg-glow: radial-gradient(1200px 600px at 85% -10%, rgba(99,102,241,0.16), transparent 60%),
             radial-gradient(900px 500px at -10% 110%, rgba(34,211,238,0.10), transparent 60%);
  --sidebar: rgba(10,14,23,0.85);
  --panel: #0f1521;
  --panel-2: #131a28;
  --border: rgba(148,163,184,0.10);
  --border-strong: rgba(148,163,184,0.20);
  --text: #e6eaf2;
  --muted: #8b95a8;
  --faint: #5b6577;
  --accent: #818cf8;
  --accent-2: #22d3ee;
  --accent-grad: linear-gradient(135deg, #6366f1 0%, #22d3ee 100%);
  --up: #22c55e;
  --down: #ef4444;
  --shadow: 0 1px 0 rgba(255,255,255,0.03) inset, 0 20px 40px -24px rgba(0,0,0,0.6);
  --radius: 16px;
  --sidebar-w: 248px;
  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #f4f6fb;
  --bg-glow: radial-gradient(1200px 600px at 85% -10%, rgba(99,102,241,0.10), transparent 60%),
             radial-gradient(900px 500px at -10% 110%, rgba(34,211,238,0.08), transparent 60%);
  --sidebar: rgba(255,255,255,0.85);
  --panel: #ffffff;
  --panel-2: #f7f8fc;
  --border: rgba(15,23,42,0.08);
  --border-strong: rgba(15,23,42,0.16);
  --text: #0f172a;
  --muted: #5b6577;
  --faint: #94a3b8;
  --accent: #4f46e5;
  --accent-2: #0891b2;
  --shadow: 0 1px 2px rgba(15,23,42,0.04), 0 16px 32px -24px rgba(15,23,42,0.25);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg-glow), var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; color: inherit; }
/* Keep TradingView iframes transparent: a color-scheme mismatch makes browsers paint them opaque white. */
.tradingview-widget-container iframe { color-scheme: light; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100vh; }

.sidebar {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 8px;
  padding: 22px 14px;
  background: var(--sidebar);
  backdrop-filter: blur(16px);
  border-right: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 18px; font-size: 17px; letter-spacing: -0.02em; }
.brand-name { font-weight: 500; }
.brand-name b { font-weight: 800; margin-left: 2px; background: var(--accent-grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 9px; background: var(--accent-grad);
  box-shadow: 0 8px 20px -6px rgba(99,102,241,0.7);
  position: relative;
}
.brand-mark::after {
  content: ''; position: absolute; inset: 8px 7px 8px 7px;
  background: linear-gradient(to top right, transparent 45%, #fff 45%, #fff 58%, transparent 58%);
  border-radius: 2px;
}

.nav { display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }
.nav-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--faint); padding: 14px 12px 6px; font-weight: 600; }
.nav a {
  display: flex; align-items: center; gap: 12px;
  padding: 9px 12px; border-radius: 10px;
  color: var(--muted); font-weight: 500;
  transition: background .15s, color .15s;
}
.nav a:hover { background: var(--panel-2); color: var(--text); }
.nav a.active { background: var(--panel-2); color: var(--text); box-shadow: inset 0 0 0 1px var(--border-strong); }
.nav a.active svg { color: var(--accent); }
.sidebar-foot { margin-top: auto; padding: 12px; font-size: 12px; color: var(--faint); }
.sidebar-foot a { color: var(--accent); }

.main { min-width: 0; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px;
  padding: 14px 28px;
  background: color-mix(in srgb, var(--bg) 80%, transparent);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
}
.search {
  flex: 1; max-width: 560px;
  display: flex; align-items: center; gap: 10px;
  padding: 0 12px; height: 40px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  color: var(--muted);
  transition: border-color .15s, box-shadow .15s;
}
.search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 18%, transparent); }
.search input { flex: 1; min-width: 0; border: 0; background: none; outline: none; color: var(--text); }
.search input::placeholder { color: var(--faint); }
kbd { font: 600 11px/1 'Inter', sans-serif; padding: 4px 7px; border-radius: 6px; border: 1px solid var(--border-strong); color: var(--faint); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.clock { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 13px; white-space: nowrap; }
.icon-btn {
  width: 40px; height: 40px; display: grid; place-items: center;
  border-radius: 12px; border: 1px solid var(--border); background: var(--panel); cursor: pointer;
  color: var(--muted); transition: color .15s, border-color .15s;
}
.icon-btn:hover { color: var(--text); border-color: var(--border-strong); }

.ticker { border-bottom: 1px solid var(--border); min-height: 46px; background: color-mix(in srgb, var(--panel) 60%, transparent); }

.view { padding: 28px; display: flex; flex-direction: column; gap: 22px; animation: fade .35s ease; }
@keyframes fade { from { opacity: 0.5; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- page head ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; flex-wrap: wrap; }
.eyebrow { margin: 0 0 6px; font-size: 12px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--accent); }
.page-head h1 { margin: 0; font-size: 30px; letter-spacing: -0.03em; font-weight: 800; }
.page-head .sub { margin: 6px 0 0; color: var(--muted); max-width: 640px; }
.page-head-right { display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------- grid + cards ---------- */
.grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 18px; }
.span-12 { grid-column: span 12; } .span-8 { grid-column: span 8; } .span-7 { grid-column: span 7; }
.span-6 { grid-column: span 6; } .span-5 { grid-column: span 5; } .span-4 { grid-column: span 4; } .span-3 { grid-column: span 3; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  display: flex; flex-direction: column;
  min-width: 0;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 18px; border-bottom: 1px solid var(--border);
}
.card-head h3 { margin: 0; font-size: 14px; font-weight: 600; letter-spacing: -0.01em; }
.card-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.card-body { position: relative; min-width: 0; }
.card-body.sized { height: var(--h); }
.card-body.pad { padding: 18px; }
.card-body .tradingview-widget-container,
.card-body .tradingview-widget-container__widget { height: 100%; width: 100%; }
.card-body.sized::before {
  content: 'Loading market data…'; position: absolute; inset: 0; display: grid; place-items: center;
  color: var(--faint); font-size: 12px; z-index: 0; pointer-events: none;
}
.card-body.sized.loaded::before { content: none; }
.card-body.sized > * { position: relative; z-index: 1; }

/* ---------- chips, segmented, buttons ---------- */
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  padding: 7px 13px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--border); background: var(--panel); color: var(--muted);
  font-weight: 500; font-size: 13px; transition: all .15s; white-space: nowrap;
}
.chip:hover { color: var(--text); border-color: var(--border-strong); }
.chip.active { color: #fff; background: var(--accent-grad); border-color: transparent; box-shadow: 0 6px 18px -8px rgba(99,102,241,0.8); }

.segmented { display: inline-flex; padding: 3px; gap: 2px; border-radius: 10px; background: var(--panel-2); border: 1px solid var(--border); flex-wrap: wrap; }
.seg { border: 0; background: none; padding: 6px 12px; border-radius: 8px; cursor: pointer; color: var(--muted); font-weight: 500; font-size: 13px; }
.seg:hover { color: var(--text); }
.seg.active { background: var(--panel); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,0.2), inset 0 0 0 1px var(--border-strong); }

.btn {
  display: inline-flex; align-items: center; gap: 8px; height: 38px; padding: 0 16px;
  border-radius: 10px; border: 1px solid var(--border-strong); background: var(--panel-2);
  cursor: pointer; font-weight: 600; font-size: 13px; transition: all .15s; white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent-grad); color: #fff; border-color: transparent; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: none; border-color: var(--border); color: var(--muted); height: 32px; padding: 0 10px; }
.btn.ghost:hover { color: var(--text); }
.btn.starred { color: #f59e0b; border-color: rgba(245,158,11,0.4); }
.btn.starred svg { fill: currentColor; }

/* ---------- sessions strip ---------- */
.sessions { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 12px; }
.session {
  padding: 12px 14px; border-radius: 14px; background: var(--panel); border: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 2px; min-width: 0;
}
.session-top { display: flex; align-items: center; justify-content: space-between; gap: 4px 6px; flex-wrap: wrap; }
.session-name { font-weight: 600; white-space: nowrap; }
.session-venue { font-size: 11px; color: var(--faint); }
.session-time { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 13px; }
.badge { font-size: 10px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; padding: 3px 7px; border-radius: 999px; }
.badge.open { color: var(--up); background: color-mix(in srgb, var(--up) 14%, transparent); }
.badge.closed { color: var(--faint); background: var(--panel-2); }
.badge.open::before { content: ''; display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: currentColor; margin-right: 5px; vertical-align: 1px; animation: pulse 1.6s infinite; }
@keyframes pulse { 50% { opacity: 0.3; } }

/* ---------- forms ---------- */
.form { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; align-items: end; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12px; color: var(--muted); font-weight: 500; }
.field input, .field select {
  height: 40px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--border-strong);
  background: var(--panel-2); outline: none;
}
.field input:focus, .field select:focus { border-color: var(--accent); }
.form-error { color: var(--down); font-size: 13px; min-height: 20px; margin: 10px 0 0; }

/* ---------- stat tiles, donut ---------- */
.stats { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 0.8fr) minmax(0, 1.2fr); gap: 12px; }
.stat { padding: 14px; border-radius: 12px; background: var(--panel-2); border: 1px solid var(--border); min-width: 0; }
.stat-label { font-size: 12px; color: var(--muted); }
.stat-value { font-size: clamp(17px, 1.5vw, 22px); font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.donut-wrap { display: flex; align-items: center; gap: 22px; flex-wrap: wrap; }
.donut { width: 150px; height: 150px; }
.donut svg { width: 150px; height: 150px; transform: rotate(-90deg); }
.legend { display: flex; flex-direction: column; gap: 8px; flex: 1; min-width: 160px; }
.legend-row { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.legend-row .dot { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.legend-row .val { margin-left: auto; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---------- symbol cards (watchlist / portfolio) ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 18px; }
.tile-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; padding: 14px 16px 6px; }
.tile-title { font-weight: 700; letter-spacing: -0.01em; word-break: break-all; }
.tile-meta { font-size: 12px; color: var(--muted); }
.tile-actions { display: flex; gap: 6px; }
.tile-chart { height: 200px; }
.empty {
  padding: 48px 20px; text-align: center; color: var(--muted);
  border: 1px dashed var(--border-strong); border-radius: var(--radius);
}
.empty strong { display: block; color: var(--text); font-size: 16px; margin-bottom: 6px; }

.disclaimer { font-size: 12px; color: var(--faint); text-align: center; padding: 8px 0 4px; }
.disclaimer a { color: var(--accent); }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translate(-50%, 20px); opacity: 0;
  padding: 10px 16px; border-radius: 12px; background: var(--text); color: var(--bg);
  font-weight: 600; font-size: 13px; transition: all .25s; z-index: 50; pointer-events: none;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- chart page ---------- */
.chart-full { --h: calc(100vh - 230px); min-height: 520px; }

/* ---------- responsive ---------- */
@media (max-width: 1280px) {
  .sessions { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .span-8, .span-7, .span-6, .span-5, .span-4 { grid-column: span 12; }
  .span-3 { grid-column: span 6; }
}
@media (max-width: 900px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    min-width: 0;
    position: sticky; top: 0; z-index: 30; height: auto; flex-direction: row; align-items: center;
    padding: 10px 16px; border-right: 0; border-bottom: 1px solid var(--border);
  }
  .brand { padding: 0; }
  .brand-name { display: none; }
  .nav { flex-direction: row; overflow-x: auto; scrollbar-width: none; }
  .nav::-webkit-scrollbar { display: none; }
  .nav-label, .sidebar-foot { display: none; }
  .nav a { padding: 8px 10px; white-space: nowrap; }
  .topbar { position: static; padding: 12px 16px; }
  .clock, kbd { display: none; }
  .view { padding: 20px 16px; }
  .page-head h1 { font-size: 24px; }
  .card-body.sized { height: min(var(--h), 70vh); }
  .chart-full { --h: 70vh; min-height: 420px; }
}
@media (max-width: 560px) {
  .sessions { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .span-3 { grid-column: span 12; }
  .stats { grid-template-columns: 1fr; }
  .nav a span { display: none; }
}
