/* Extracted from index.html so it can be served as a same-origin file.
   The API sends `Content-Security-Policy: ... 'self'`, which blocks inline <style> and
   <script> blocks outright. Keeping this content inline meant the browser silently
   discarded it: unstyled page, no event handlers, and a login form that fell back to a
   native submit. Do not move it back into the HTML. */
/* ---------------------------------------------------------------------------------------------
   Design notes, kept in the file because they are decisions rather than styling.

   The one problem this dashboard exists to solve: at 09:20 an operator needs to know whether
   anything is WRONG, and a losing strategy is not wrong — it is a strategy losing money, which is
   an expected outcome. So P&L direction and system severity use entirely separate visual channels.
   P&L is typography (tabular mono, sign, restrained tint). Severity is a solid edge bar. A
   strategy down 40,000 rupees looks calm; a strategy that stopped publishing looks alarming.

   Ground is deep slate rather than black: this is an instrument panel, not a terminal emulator.
   Status colours deliberately avoid pure red and green so they cannot be confused with P&L.
--------------------------------------------------------------------------------------------- */
:root {
  --ground:      #0E151E;
  --panel:       #141D28;
  --panel-lift:  #1A2533;
  --rule:        #24303F;
  --ink:         #E8EDF3;
  --ink-dim:     #8A9AAD;
  --ink-faint:   #556478;

  /* Severity — never used for money. */
  --ok:          #3FB8A4;
  --warn:        #E0A13A;
  --critical:    #D4574E;
  --halted:      #7B8FA8;

  /* Money — never used for severity. */
  --gain:        #6FCF97;
  --loss:        #E88B84;

  --mono: 'IBM Plex Mono', ui-monospace, monospace;
  --cond: 'IBM Plex Sans Condensed', system-ui, sans-serif;
  --sans: 'IBM Plex Sans', system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--ground);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* --- Session rail: the organising device -----------------------------------------------------
   Indian intraday hours are a hard constraint, not ambient information. Where you are in the
   session decides whether "no ticks" is a fault or simply pre-open — so the clock frames
   everything else rather than sitting in a corner. */
.rail {
  position: sticky; top: 0; z-index: 10;
  background: var(--panel);
  border-bottom: 1px solid var(--rule);
  padding: 14px 24px 10px;
}
.rail-head {
  display: flex; align-items: baseline; gap: 16px; flex-wrap: wrap;
  margin-bottom: 12px;
}
.wordmark {
  font-family: var(--cond); font-weight: 700; font-size: 15px;
  letter-spacing: .14em; text-transform: uppercase;
}
.clock {
  font-family: var(--mono); font-size: 15px; font-variant-numeric: tabular-nums;
  color: var(--ink);
}
.phase {
  font-family: var(--cond); font-size: 11px; font-weight: 600;
  letter-spacing: .12em; text-transform: uppercase; color: var(--ink-dim);
}
.conn { margin-left: auto; font-family: var(--cond); font-size: 11px;
  letter-spacing: .1em; text-transform: uppercase; color: var(--ink-faint); }
.conn[data-state="live"] { color: var(--ok); }
.conn[data-state="lost"] { color: var(--critical); }

.track { position: relative; height: 26px; }
.track-line {
  position: absolute; left: 0; right: 0; top: 7px; height: 2px;
  background: var(--rule);
}
.track-fill {
  position: absolute; left: 0; top: 7px; height: 2px;
  background: var(--ok); transition: width .6s ease;
}
.mark { position: absolute; top: 0; transform: translateX(-50%); }
.mark i {
  display: block; width: 1px; height: 16px; background: var(--rule); margin: 0 auto;
}
.mark.key i { background: var(--ink-faint); height: 20px; }
.mark span {
  display: block; font-family: var(--mono); font-size: 9.5px;
  color: var(--ink-faint); white-space: nowrap; margin-top: 2px;
}
.now {
  position: absolute; top: 2px; transform: translateX(-50%);
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--ok); box-shadow: 0 0 0 3px var(--panel);
  transition: left .6s ease;
}

/* --- Primary navigation ------------------------------------------------------------------------
   Sits below the session rail, not above it: the clock, the phase and the kill switch apply to
   every view, so they frame the tabs rather than sitting inside one. */
.mainnav {
  position: sticky; top: 0; z-index: 9;
  display: flex; gap: 2px; padding: 0 24px;
  background: var(--ground); border-bottom: 1px solid var(--rule);
}
.mainnav button {
  border: 0; border-bottom: 2px solid transparent; border-radius: 0;
  padding: 11px 16px; font-size: 11.5px; letter-spacing: .12em;
  color: var(--ink-faint); background: transparent;
}
.mainnav button:hover { color: var(--ink-dim); border-color: var(--rule); }
.mainnav button.active { color: var(--ink); border-bottom-color: var(--ok); }
.mainnav button:focus-visible { outline: 2px solid var(--ok); outline-offset: -2px; }

/* --- Layout --------------------------------------------------------------------------------- */
main { padding: 24px; max-width: 1280px; margin: 0 auto; }
.eyebrow {
  font-family: var(--cond); font-size: 11px; font-weight: 600;
  letter-spacing: .16em; text-transform: uppercase; color: var(--ink-faint);
  margin: 0 0 10px;
}
section { margin-bottom: 32px; }

/* An author rule setting `display` on these would beat the UA stylesheet's [hidden] and leave
   every view stacked on top of each other — the same trap the kill switch fell into. Both states
   are therefore stated explicitly. */
.view[hidden] { display: none; }
.view { display: block; }
.block { margin-bottom: 32px; }

/* --- Strategy cards --------------------------------------------------------------------------
   The severity bar is the signature. It is the only place solid colour appears in bulk, so the
   eye lands on a broken strategy before it reads a single word. */
.cards { display: grid; gap: 10px; }
.card {
  display: grid; grid-template-columns: 4px 1fr auto; gap: 0;
  background: var(--panel); border: 1px solid var(--rule); border-radius: 3px;
  overflow: hidden;
}
.sev { background: var(--ok); }
.card[data-sev="warn"]     .sev { background: var(--warn); }
.card[data-sev="critical"] .sev { background: var(--critical); }
.card[data-sev="halted"]   .sev { background: var(--halted); }
.card[data-sev="critical"] { border-color: color-mix(in srgb, var(--critical) 45%, var(--rule)); }

.card-body { padding: 12px 16px; min-width: 0; }
.card-top { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.sid {
  font-family: var(--mono); font-size: 13.5px; font-weight: 500;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.state {
  font-family: var(--cond); font-size: 10.5px; font-weight: 700;
  letter-spacing: .12em; text-transform: uppercase;
  padding: 1px 7px; border-radius: 2px;
  background: var(--panel-lift); color: var(--ink-dim);
}
.card[data-sev="ok"]       .state { color: var(--ok); }
.card[data-sev="warn"]     .state { color: var(--warn); }
.card[data-sev="critical"] .state { color: var(--critical); }
.mode { font-family: var(--cond); font-size: 10.5px; letter-spacing: .1em;
  text-transform: uppercase; color: var(--ink-faint); }

.err {
  font-family: var(--mono); font-size: 11.5px; color: var(--critical);
  margin-top: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* Headroom bars: what is left, not what has been used. "800 rupees of loss allowance remaining"
   is actionable; two numbers a reader has to subtract are not. */
.head { display: flex; gap: 18px; margin-top: 10px; flex-wrap: wrap; }
.gauge { min-width: 120px; flex: 1; }
.gauge label {
  display: block; font-family: var(--cond); font-size: 10px; letter-spacing: .1em;
  text-transform: uppercase; color: var(--ink-faint); margin-bottom: 4px;
}
.gauge .bar { height: 3px; background: var(--panel-lift); border-radius: 2px; overflow: hidden; }
.gauge .bar i { display: block; height: 100%; background: var(--ink-dim); transition: width .4s; }
.gauge.low  .bar i { background: var(--warn); }
.gauge.none .bar i { background: var(--critical); }
.gauge .val {
  font-family: var(--mono); font-size: 11px; font-variant-numeric: tabular-nums;
  color: var(--ink-dim); margin-top: 3px;
}

/* Money is typographic only — no fills, no bars, no solid colour. */
.pnl { padding: 12px 18px; text-align: right; border-left: 1px solid var(--rule); }
.pnl .amt {
  font-family: var(--mono); font-size: 19px; font-weight: 500;
  font-variant-numeric: tabular-nums; letter-spacing: -.01em;
}
.pnl .amt.up   { color: var(--gain); }
.pnl .amt.down { color: var(--loss); }
.pnl .sub {
  font-family: var(--mono); font-size: 10.5px; color: var(--ink-faint);
  font-variant-numeric: tabular-nums; margin-top: 2px;
}

.stale {
  font-family: var(--cond); font-size: 10px; font-weight: 700; letter-spacing: .1em;
  text-transform: uppercase; color: var(--ground); background: var(--warn);
  padding: 1px 6px; border-radius: 2px;
}

/* --- Positions ------------------------------------------------------------------------------ */
table { width: 100%; border-collapse: collapse; }
th {
  font-family: var(--cond); font-size: 10.5px; font-weight: 600; letter-spacing: .12em;
  text-transform: uppercase; color: var(--ink-faint); text-align: right;
  padding: 6px 12px; border-bottom: 1px solid var(--rule);
}
th:first-child, td:first-child { text-align: left; }
td {
  font-family: var(--mono); font-size: 12.5px; font-variant-numeric: tabular-nums;
  padding: 8px 12px; border-bottom: 1px solid var(--rule); text-align: right;
  color: var(--ink-dim);
}
td:first-child { color: var(--ink); }
td.up { color: var(--gain); } td.down { color: var(--loss); }

/* --- Equity curve ----------------------------------------------------------------------------
   Drawn as an SVG path rather than pulling in a charting library. The chart has one series and one
   job; a dependency would add more surface than it removes, and this renders identically offline.

   The zero line is emphasised over gridlines because the only threshold that matters on a session
   equity chart is whether you are up or down. */
.chart { background: var(--panel); border: 1px solid var(--rule); border-radius: 3px; padding: 16px; }
.chart svg { width: 100%; height: 180px; display: block; }
.zero { stroke: var(--ink-faint); stroke-width: 1; stroke-dasharray: 2 3; }
.curve { fill: none; stroke: var(--ok); stroke-width: 1.5; }
.curve.down { stroke: var(--loss); }
.fill-area { opacity: .10; }

.summary { display: flex; gap: 24px; flex-wrap: wrap; margin-top: 12px; }
.summary div { min-width: 88px; }
.summary label {
  display: block; font-family: var(--cond); font-size: 10px; letter-spacing: .1em;
  text-transform: uppercase; color: var(--ink-faint); margin-bottom: 2px;
}
.summary span {
  font-family: var(--mono); font-size: 14px; font-variant-numeric: tabular-nums;
}

/* --- Event feed ------------------------------------------------------------------------------
   Newest first, severity on the left edge — the same channel the strategy cards use, so a
   rejection reads as urgent and a fill does not. */
.feed { background: var(--panel); border: 1px solid var(--rule); border-radius: 3px;
  max-height: 260px; overflow-y: auto; }
.ev { display: grid; grid-template-columns: 3px 62px 1fr; border-bottom: 1px solid var(--rule); }
.ev:last-child { border-bottom: 0; }
.ev i { display: block; }
.ev.rejection i { background: var(--critical); }
.ev.fill i      { background: var(--ok); }
.ev.signal i    { background: var(--warn); }
.ev.accepted i  { background: var(--ink-faint); }
.ev time {
  font-family: var(--mono); font-size: 10.5px; color: var(--ink-faint);
  padding: 7px 0 7px 10px; font-variant-numeric: tabular-nums;
}
.ev p { margin: 0; padding: 7px 12px; font-family: var(--mono); font-size: 11.5px;
  color: var(--ink-dim); overflow: hidden; text-overflow: ellipsis; }
.ev p b { color: var(--ink); font-weight: 500; }

/* --- Empty and error states: direction, not mood -------------------------------------------- */
.note {
  border: 1px solid var(--rule); border-left: 3px solid var(--warn);
  background: var(--panel); padding: 14px 16px; border-radius: 3px;
}
.note p { margin: 0; color: var(--ink-dim); font-size: 13px; }
.note p + p { margin-top: 6px; }
.note.bad { border-left-color: var(--critical); }

button {
  font-family: var(--cond); font-size: 11px; font-weight: 600; letter-spacing: .1em;
  text-transform: uppercase; cursor: pointer;
  background: transparent; color: var(--ink-dim);
  border: 1px solid var(--rule); border-radius: 2px; padding: 5px 12px;
}
button:hover { color: var(--ink); border-color: var(--ink-faint); }
button:focus-visible { outline: 2px solid var(--ok); outline-offset: 2px; }
a:focus-visible, [tabindex]:focus-visible { outline: 2px solid var(--ok); outline-offset: 2px; }
button:disabled { opacity: .4; cursor: not-allowed; }

/* Risk-reducing and risk-increasing actions read differently on purpose: a halt or square-off is
   a plain button, matching the rest of the panel; engaging or releasing the kill switch, and
   placing an order, are the only actions with solid colour on a control. */
button.primary { background: var(--ok); color: var(--ground); border-color: var(--ok); }
button.primary:hover { color: var(--ground); filter: brightness(1.1); }
button.danger { background: transparent; color: var(--critical); border-color: color-mix(in srgb, var(--critical) 45%, var(--rule)); }
button.danger:hover { color: var(--ink); background: var(--critical); border-color: var(--critical); }
button.small { padding: 2px 8px; font-size: 10px; }

/* --- Kill switch: the single control that must never be ambiguous about its own state ---------
   [hidden] alone would be enough, but an author stylesheet rule beats the UA stylesheet's
   `[hidden] { display: none }` regardless of specificity — so display must be set explicitly for
   the hidden case too, or the control shows up armed before permissions have even loaded. */
.killswitch[hidden] { display: none; }
.killswitch { display: flex; align-items: center; gap: 8px; }
.ks-state {
  font-family: var(--cond); font-size: 10.5px; font-weight: 700; letter-spacing: .1em;
  text-transform: uppercase; padding: 2px 8px; border-radius: 2px;
  background: var(--panel-lift); color: var(--ok);
}
.killswitch[data-state="engaged"] .ks-state { background: var(--critical); color: var(--ink); }
.killswitch[data-state="engaged"] #ksToggle { color: var(--ok); border-color: var(--ok); }
.killswitch[data-state="off"] #ksToggle { color: var(--critical); border-color: color-mix(in srgb, var(--critical) 45%, var(--rule)); }

/* --- Eyebrow row: a section header with an action beside it, rather than below the content ---- */
.eyebrow-row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.eyebrow-row .eyebrow { margin: 0; }

/* --- Forms --------------------------------------------------------------------------------------
   Grid rather than stacked: the fields these ask for are short, and a Trader placing a corrective
   order during a live session should see the whole thing without scrolling. */
.grid-form {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px 16px;
  background: var(--panel); border: 1px solid var(--rule); border-radius: 3px; padding: 16px;
}
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field[hidden] { display: none; }
.field.wide { grid-column: span 2; }
.field.submit { justify-content: flex-end; }
.field.checks { grid-column: 1 / -1; flex-direction: column; gap: 7px; }

/* Two flags that make results look better than they are, so they read as warnings rather than
   preferences — someone ticking these should feel it. */
.check { display: flex; align-items: flex-start; gap: 8px; cursor: pointer; }
/* Attribute selector, not a bare `.check input`: the generic `.field input` rule below sets
   width:100%, is declared later, and carries the same specificity — so a plain selector loses and
   the checkbox stretches the full row, pushing its own label out of the form. */
.check input[type="checkbox"] {
  width: 14px; height: 14px; margin: 2px 0 0; padding: 0;
  accent-color: var(--warn); flex: none;
}
.check span { font-size: 12.5px; color: var(--ink-dim); }
.check .hint { color: var(--warn); }
.field label {
  font-family: var(--cond); font-size: 10px; font-weight: 600; letter-spacing: .1em;
  text-transform: uppercase; color: var(--ink-faint);
}
.field label .hint { text-transform: none; letter-spacing: 0; color: var(--ink-faint); font-weight: 400; }
.field input, .field select {
  font-family: var(--mono); font-size: 13px; color: var(--ink);
  background: var(--ground); border: 1px solid var(--rule); border-radius: 2px;
  padding: 7px 9px; width: 100%;
}
.field input:focus, .field select:focus {
  outline: none; border-color: var(--ok);
}
.grid-form button.primary { width: 100%; padding: 8px 12px; }
#orderResult .note, #backtestFormResult .note { margin-top: 12px; }

/* --- Backtest results ---------------------------------------------------------------------------
   The metric grid is typographic like the P&L figures elsewhere: a backtest result is money, and
   money never gets a severity colour here. */
.metrics {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 1px;
  background: var(--rule); border: 1px solid var(--rule); border-radius: 3px; overflow: hidden;
}
.metric { background: var(--panel); padding: 12px 14px; }
.metric label {
  display: block; font-family: var(--cond); font-size: 10px; letter-spacing: .1em;
  text-transform: uppercase; color: var(--ink-faint); margin-bottom: 4px;
}
.metric span {
  font-family: var(--mono); font-size: 16px; font-variant-numeric: tabular-nums; color: var(--ink);
}
.metric span.up { color: var(--gain); } .metric span.down { color: var(--loss); }

/* Caveats travel with the result rather than being printed once and lost — a run with synthetic
   chains or charges disabled must never be read as a performance estimate. */
.caveats { margin-top: 14px; display: flex; flex-direction: column; gap: 6px; }
.caveat {
  font-size: 12.5px; color: var(--ink-dim); padding: 8px 12px; border-radius: 3px;
  background: var(--panel); border-left: 3px solid var(--warn);
}
.caveat.severe { border-left-color: var(--critical); color: var(--ink); }

.run-row { cursor: pointer; }
.run-row:hover td { color: var(--ink); }
.btn-link {
  display: inline-block; font-family: var(--cond); font-size: 10px; font-weight: 600;
  letter-spacing: .1em; text-transform: uppercase; text-decoration: none;
  color: var(--ink-dim); border: 1px solid var(--rule); border-radius: 2px; padding: 2px 8px;
}
.btn-link:hover { color: var(--ink); border-color: var(--ink-faint); }

/* --- Row actions inside tables and cards -------------------------------------------------------
   Kept out of the money and severity channels entirely — actions are neither. */
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.card-actions { display: flex; gap: 6px; padding: 0 16px 12px; }

/* --- Order status pill, reusing the same visual language as strategy state -------------------- */
.pill {
  display: inline-block; font-family: var(--cond); font-size: 10px; font-weight: 700;
  letter-spacing: .1em; text-transform: uppercase; padding: 1px 7px; border-radius: 2px;
  background: var(--panel-lift); color: var(--ink-dim);
}
.pill.live { color: var(--warn); }
.pill.filled { color: var(--gain); }
.pill.rejected, .pill.cancelled { color: var(--critical); }
/* Backtest job states. Running is the only one that animates, and only to say "still going" —
   a completed run that merely lost money must look calm. */
.pill.running { color: var(--ok); }
.pill.queued { color: var(--ink-faint); }
.pill.completed { color: var(--ink); }
.pill.failed { color: var(--critical); }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
@media (max-width: 900px) {
  .grid-form { grid-template-columns: repeat(2, 1fr); }
  .field.wide { grid-column: span 2; }
}
@media (max-width: 640px) {
  main { padding: 16px; }
  .card { grid-template-columns: 3px 1fr; }
  .pnl { grid-column: 2; text-align: left; border-left: 0; border-top: 1px solid var(--rule); }
  .grid-form { grid-template-columns: 1fr; }
  .field.wide { grid-column: span 1; }
  .mainnav { padding: 0 8px; }
  .mainnav button { padding: 11px 10px; font-size: 11px; }
  /* Wide tables scroll in their own box rather than pushing the page sideways. */
  .block > div { overflow-x: auto; }
}

/* Links inside a banner. Default browser blue on a slate ground is both hard to read and clearly
   unstyled, and the enrolment prompt is the one link an operator actually needs to find. */
.note a { color: var(--ok); text-decoration: underline; text-underline-offset: 2px; }
.note a:hover { filter: brightness(1.15); }

/* Setup instructions in a banner. Monospace because the content is a command to be copied. */
.note pre {
  font-family: var(--mono); font-size: 12px; color: var(--ink);
  background: var(--ground); border: 1px solid var(--rule); border-radius: 2px;
  padding: 10px 12px; margin: 10px 0; overflow-x: auto; user-select: all;
}
.note code { font-family: var(--mono); font-size: 12px; color: var(--ink-dim); }
