/* ===== Design tokens ================================================== */
:root {
  --bg: #0a0e14;
  --surface: #11161f;
  --surface-2: #161d28;
  --surface-3: #1d2633;
  --border: #222c3a;
  --border-strong: #2f3b4d;
  --text: #e6edf5;
  --text-2: #aab6c5;
  --muted: #7d8a9c;
  --accent: #5b8cff;
  --accent-soft: rgba(91, 140, 255, 0.14);
  --green: #22c55e;
  --green-soft: rgba(34, 197, 94, 0.13);
  --red: #f05252;
  --red-soft: rgba(240, 82, 82, 0.13);
  --amber: #f5a524;
  --amber-soft: rgba(245, 165, 36, 0.14);
  --ema-fast: #f5a524;
  --ema-slow: #a78bfa;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.25);
  --radius: 12px;
  --radius-sm: 8px;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #f7f9fc;
  --surface-3: #eef2f7;
  --border: #e3e8ef;
  --border-strong: #d2d9e3;
  --text: #0f1722;
  --text-2: #3b4757;
  --muted: #6a7789;
  --accent: #2f6bff;
  --accent-soft: rgba(47, 107, 255, 0.1);
  --green: #12a150;
  --green-soft: rgba(18, 161, 80, 0.1);
  --red: #e02d3c;
  --red-soft: rgba(224, 45, 60, 0.09);
  --amber: #c27803;
  --amber-soft: rgba(194, 120, 3, 0.12);
  --ema-fast: #d97706;
  --ema-slow: #7c3aed;
  --shadow: 0 1px 2px rgba(15, 23, 34, 0.05), 0 6px 20px rgba(15, 23, 34, 0.06);
  color-scheme: light;
}

/* ===== Base =========================================================== */
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 var(--sans);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.num, .mono { font-variant-numeric: tabular-nums; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.pos { color: var(--green); }
.neg { color: var(--red); }
.muted { color: var(--muted); }
.hidden { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ===== Header ========================================================== */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 20px;
  height: 56px; padding: 0 20px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; letter-spacing: -0.01em; white-space: nowrap; }
.brand-mark {
  width: 26px; height: 26px; border-radius: 7px;
  background: linear-gradient(135deg, var(--accent), #8b5cf6);
  display: grid; place-items: center; color: #fff; font-size: 13px; font-weight: 800;
}
.nav { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; }
.nav a {
  padding: 7px 12px; border-radius: 8px; color: var(--text-2); font-weight: 520; white-space: nowrap;
}
.nav a:hover { background: var(--surface-3); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.topbar .spacer { flex: 1; }
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600;
  border: 1px solid var(--border-strong); color: var(--text-2); white-space: nowrap;
}
.pill.demo { color: var(--amber); border-color: color-mix(in srgb, var(--amber) 45%, transparent); background: var(--amber-soft); }
.pill.real, .pill.zerodha { color: var(--green); border-color: color-mix(in srgb, var(--green) 45%, transparent); background: var(--green-soft); }
.pill.live { color: #fff; background: var(--red); border-color: var(--red); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.icon-btn {
  width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text-2); cursor: pointer;
}
.icon-btn:hover { color: var(--text); border-color: var(--border-strong); }

main.page { padding: 18px 20px 40px; max-width: 1680px; margin: 0 auto; }

/* ===== Cards ============================================================= */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.card-h {
  display: flex; align-items: center; gap: 10px; justify-content: space-between;
  padding: 12px 16px; border-bottom: 1px solid var(--border);
}
.card-h h2, .card-h h3 { margin: 0; font-size: 13px; font-weight: 650; letter-spacing: 0.01em; }
.card-b { padding: 14px 16px; }
.section-title { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 650; margin: 0 0 8px; }

/* ===== Buttons & inputs ===================================================== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 34px; padding: 0 14px; border-radius: 9px; font: 600 13px var(--sans);
  border: 1px solid var(--border-strong); background: var(--surface-2); color: var(--text); cursor: pointer;
}
.btn:hover { background: var(--surface-3); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn.ghost { background: transparent; }
input, select {
  height: 34px; padding: 0 10px; border-radius: 9px; font: 500 13px var(--sans);
  border: 1px solid var(--border-strong); background: var(--surface-2); color: var(--text);
}
select { padding-right: 28px; }
label.field { display: grid; gap: 5px; font-size: 12px; color: var(--muted); font-weight: 600; }
.field-err { color: var(--red); font-size: 12px; min-height: 16px; }

/* segmented control */
.seg { display: inline-flex; padding: 3px; gap: 2px; border-radius: 10px; background: var(--surface-3); border: 1px solid var(--border); }
.seg button {
  height: 28px; padding: 0 11px; border: 0; border-radius: 7px; background: transparent;
  color: var(--text-2); font: 600 12.5px var(--sans); cursor: pointer; white-space: nowrap;
}
.seg button:hover { color: var(--text); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.25); }
.seg button.win[aria-pressed="true"] { color: var(--green); }
.seg button.loss[aria-pressed="true"] { color: var(--red); }

/* ===== Filter bar ============================================================== */
.filterbar {
  position: sticky; top: 56px; z-index: 20;
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: 14px 18px;
  padding: 12px 16px; margin-bottom: 14px;
}
.filter { display: grid; gap: 5px; }
.filter > span { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 650; }
.filterbar .grow { flex: 1; }

/* ===== KPI row ===================================================================== */
.kpis { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; margin-bottom: 12px; }
.kpi { padding: 13px 16px; position: relative; overflow: hidden; }
.kpi .label { font-size: 11.5px; color: var(--muted); font-weight: 650; text-transform: uppercase; letter-spacing: .05em; }
.kpi .value { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .sub { font-size: 12px; color: var(--muted); margin-top: 2px; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi.accent::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 3px; background: var(--accent); }

.metrics-strip { display: flex; flex-wrap: wrap; gap: 6px 22px; padding: 10px 16px; margin-bottom: 12px; font-size: 12.5px; color: var(--text-2); }
.metrics-strip b { color: var(--text); font-weight: 650; font-variant-numeric: tabular-nums; }

/* mode comparison */
.compare { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-bottom: 14px; }
.cmp { padding: 12px 14px; cursor: pointer; text-align: left; font: inherit; color: inherit; transition: border-color .15s; }
.cmp:hover { border-color: var(--border-strong); }
.cmp.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset, var(--shadow); }
.cmp .t { display: flex; justify-content: space-between; align-items: baseline; font-weight: 650; }
.cmp .row { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin-top: 8px; }
.cmp .row div { font-size: 11px; color: var(--muted); }
.cmp .row b { display: block; font-size: 14px; color: var(--text); font-variant-numeric: tabular-nums; }

/* ===== Workspace ======================================================================== */
.workspace { display: grid; grid-template-columns: 450px minmax(0, 1fr); gap: 14px; align-items: start; }
.trade-list { display: flex; flex-direction: column; height: calc(100vh - 140px); min-height: 520px; position: sticky; top: 140px; }
.trade-list .card-h small { color: var(--muted); font-weight: 500; }
.tl-scroll { overflow: auto; flex: 1; outline: none; }
table.tl { width: 100%; border-collapse: collapse; font-size: 12.5px; font-variant-numeric: tabular-nums; }
table.tl th {
  position: sticky; top: 0; z-index: 1; background: var(--surface-2);
  text-align: left; font-size: 11px; color: var(--muted); font-weight: 650; text-transform: uppercase; letter-spacing: .04em;
  padding: 8px 7px; border-bottom: 1px solid var(--border);
}
table.tl td { padding: 8px 7px; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.tl th.r, table.tl td.r { text-align: right; }
table.tl tbody tr { cursor: pointer; }
table.tl tbody tr:hover { background: var(--surface-2); }
table.tl tbody tr.sel { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.dir { display: inline-flex; align-items: center; justify-content: center; width: 20px; height: 20px; border-radius: 6px; font-size: 12px; font-weight: 800; }
.dir.up { background: var(--green-soft); color: var(--green); }
.dir.down { background: var(--red-soft); color: var(--red); }
.kbd-hint { font-size: 11.5px; color: var(--muted); padding: 8px 12px; border-top: 1px solid var(--border); display: flex; gap: 10px; align-items: center; }
kbd { font: 600 11px var(--mono); padding: 1px 6px; border-radius: 5px; border: 1px solid var(--border-strong); background: var(--surface-2); color: var(--text-2); }

.detail { display: grid; gap: 14px; min-width: 0; }
.meta { display: flex; flex-wrap: wrap; gap: 0; }
.meta .m { padding: 10px 16px; border-right: 1px solid var(--border); min-width: 0; }
.meta .m:last-child { border-right: 0; }
.meta .m .k { font-size: 11px; color: var(--muted); font-weight: 650; text-transform: uppercase; letter-spacing: .05em; }
.meta .m .v { font-weight: 650; margin-top: 2px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 6px; font-size: 11.5px; font-weight: 700; }
.badge.whip { background: var(--amber-soft); color: var(--amber); }
.badge.bull { background: var(--green-soft); color: var(--green); }
.badge.bear { background: var(--red-soft); color: var(--red); }
.badge.neutral { background: var(--surface-3); color: var(--text-2); }

.chart-wrap { position: relative; }
.chart { height: 430px; }
.chart.small { height: 230px; }
.legend {
  position: absolute; left: 12px; top: 10px; z-index: 3; pointer-events: none;
  display: flex; flex-wrap: wrap; gap: 4px 14px; font: 600 12px var(--sans); color: var(--text-2);
  font-variant-numeric: tabular-nums;
}
.legend .sw { display: inline-block; width: 10px; height: 3px; border-radius: 2px; margin-right: 5px; vertical-align: middle; }
.detail-grid { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 14px; }

.costs { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.costs td { padding: 7px 0; border-bottom: 1px dashed var(--border); }
.costs td:last-child { text-align: right; font-weight: 600; }
.costs tr.total td { border-bottom: 0; border-top: 1px solid var(--border-strong); font-weight: 750; font-size: 15px; padding-top: 10px; }
.costs tr.sub td { font-weight: 650; color: var(--text); }
.costs tr.ind td:first-child { padding-left: 14px; color: var(--text-2); }

.notes { font-size: 12.5px; color: var(--text-2); }
.facts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 16px; }
.facts .k { font-size: 11px; color: var(--muted); font-weight: 650; text-transform: uppercase; letter-spacing: .05em; }
.facts .v { font-weight: 600; font-variant-numeric: tabular-nums; }

/* ===== States ======================================================================== */
.state { display: grid; place-items: center; text-align: center; padding: 48px 20px; color: var(--text-2); }
.state h3 { margin: 10px 0 4px; color: var(--text); font-size: 16px; }
.state p { margin: 0 0 14px; max-width: 460px; }
.state .ico { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; background: var(--surface-3); font-size: 20px; }
.state.error .ico { background: var(--red-soft); color: var(--red); }
.skel { position: relative; overflow: hidden; background: var(--surface-3); border-radius: 6px; }
.skel::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--text) 6%, transparent), transparent);
  animation: shimmer 1.2s infinite;
}
@keyframes shimmer { from { transform: translateX(-100%); } to { transform: translateX(100%); } }
.skel.line { height: 12px; margin: 10px 0; }
.skel.big { height: 26px; width: 60%; margin-top: 8px; }
.loading-bar { position: fixed; top: 0; left: 0; height: 2px; background: var(--accent); z-index: 100; transition: width .3s, opacity .3s; }
.spinner { width: 16px; height: 16px; border: 2px solid var(--border-strong); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed; bottom: 20px; right: 20px; z-index: 200; max-width: 420px;
  padding: 12px 16px; border-radius: 10px; background: var(--surface-3); border: 1px solid var(--border-strong);
  box-shadow: var(--shadow); font-weight: 550;
}
.toast.err { border-color: var(--red); }
.banner { padding: 10px 14px; border-radius: 10px; margin-bottom: 14px; font-weight: 550; }
.banner.warn { background: var(--amber-soft); color: var(--amber); border: 1px solid color-mix(in srgb, var(--amber) 35%, transparent); }
.banner.err { background: var(--red-soft); color: var(--red); border: 1px solid color-mix(in srgb, var(--red) 35%, transparent); }
.banner.ok { background: var(--green-soft); color: var(--green); border: 1px solid color-mix(in srgb, var(--green) 35%, transparent); }

/* progress */
.progress { height: 8px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); width: 0; transition: width .3s; }

/* generic grids */
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.stack { display: grid; gap: 14px; }
.row-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
dl.kv { display: grid; grid-template-columns: 1fr auto; gap: 8px 16px; margin: 0; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
table.data th { text-align: left; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; padding: 8px 10px; border-bottom: 1px solid var(--border); }
table.data td { padding: 8px 10px; border-bottom: 1px solid var(--border); }
.scroll-y { max-height: 380px; overflow: auto; }
details.disclosure summary { cursor: pointer; padding: 12px 16px; font-weight: 650; list-style: none; display: flex; justify-content: space-between; }
details.disclosure summary::-webkit-details-marker { display: none; }
details.disclosure[open] summary { border-bottom: 1px solid var(--border); }

dialog { border: 1px solid var(--border-strong); border-radius: 14px; background: var(--surface); color: var(--text); padding: 0; max-width: 440px; width: calc(100% - 32px); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(0, 0, 0, 0.55); }
dialog .card-b { display: grid; gap: 12px; }

/* ===== Responsive ======================================================================= */
@media (max-width: 1280px) {
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .workspace { grid-template-columns: 420px minmax(0, 1fr); }
  .detail-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 960px) {
  .workspace { grid-template-columns: minmax(0, 1fr); }
  .trade-list { position: static; height: 360px; min-height: 0; }
  .compare, .grid-3 { grid-template-columns: minmax(0, 1fr); }
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .filterbar { position: static; }
}
@media (max-width: 640px) {
  main.page { padding: 12px 16px 32px; }
  .topbar { gap: 8px 10px; padding: 8px 16px 6px; height: auto; flex-wrap: wrap; }
  .topbar .nav { order: 10; width: 100%; }
  .trade-list, .filterbar { top: auto; }
  .brand span.full { display: none; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .kpi .value { font-size: 19px; }
  .chart { height: 320px; }
  .meta .m { flex: 1 1 45%; border-right: 0; border-bottom: 1px solid var(--border); }
  .cmp .row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .seg { overflow-x: auto; max-width: 100%; }
  .filter { max-width: 100%; }
}
