/* ==========================================================================
   Loki — design tokens, base styles and the login page.
   This file is served on the public (pre-login) path list, so it must stay
   self-contained. The dashboard additionally loads css/app.css after login.
   No external fonts (CSP: default-src 'self'); system UI stack + tabular numerals.
   ========================================================================== */

:root {
  /* layout */
  --rail-w: 76px;
  --topbar-h: 56px;
  --bottom-nav-h: 60px;   /* mobile bottom navigation; content reserves this + the safe-area inset */
  --strip-h: 34px;
  --content-max: 1560px;
  --gap: 16px;
  --pad: 20px;
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;
  --control-h: 36px;
  /* type */
  /* v30 type system. Windows 11 ships Segoe UI Variable (optical sizes, no download, CSP-safe);
     other systems fall back to their own UI font. The Display cut is for large numbers only. */
  --font: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-display: "Segoe UI Variable Display", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: "Cascadia Mono", "Cascadia Code", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  /* One whole-pixel scale (v29 rendered 16 sizes incl. 10/10.5/11.5/12.5/13.5 px). 11 px is reserved for
     UPPERCASE overlines, table headers and code tags; running text never goes below 12 px. */
  --fs-2xs: 11px;    /* uppercase overlines, table headers, PAPER/OPT/MODE tags, counters */
  --fs-xs: 12px;     /* captions, labels, navigation, hints, footers */
  --fs-sm: 13px;     /* secondary text, meta lines, small buttons, dense cells */
  --fs-md: 14px;     /* body, table cells, buttons, inputs */
  --fs-lg: 16px;     /* card titles, contract strike, premium */
  --fs-xl: 18px;     /* page title, panel headline, dialog titles, symbol */
  --fs-2xl: 20px;    /* KPI values (one size everywhere) */
  --fs-3xl: 24px;    /* large figures: ticket LTP, login brand */
  --fs-hero: 32px;   /* the single hero number of a view */
  --ls-caps: .06em;  /* tracking for every uppercase label */
  font-family: var(--font);
  color-scheme: dark;
}

/* ---------- Dark (default) ---------- */
:root, [data-theme="dark"] {
  --bg: #0a0e15;
  --bg-2: #0f1520;
  --surface: #131a27;
  --surface-2: #192234;
  --surface-3: #1f2a40;
  --border: #243046;
  --border-strong: #35476a;
  --text: #e8eef8;
  --text-2: #c2cbd9;
  --muted: #8593a8;
  --muted-2: #8290a6;   /* ≥ 4.5:1 on every dark surface it is used on (axe, 2026-10-02) */
  --accent: #4d8dff;
  --accent-2: #7fb0ff;
  --accent-soft: rgba(77, 141, 255, .14);
  --on-accent: #06101f;
  --up: #2fd07f;
  --on-up: #04140b;       /* text on a solid --up fill */
  --on-down: #0a0e15;     /* text on a solid --down fill */
  --on-warn: #1a1200;     /* text on a solid --warn fill */
  --up-soft: rgba(47, 208, 127, .14);
  --down: #ff5470;
  --down-soft: rgba(255, 84, 112, .14);
  --down-text: #ff8599;   /* danger-button text: ≥ 5.2:1 on --down-soft over every dark surface */
  --warn: #f5b942;
  --warn-soft: rgba(245, 185, 66, .14);
  --live: #7c3aed;      /* execution-mode marker: violet, so LIVE never reads as a loss (red) */
  --live-soft: rgba(124, 58, 237, .18);
  --live-text: #b9a1ff;   /* v45: LIVE as text in the top bar (≥ 7:1 on --surface) */
  --info: #5cc8ff;
  --info-soft: rgba(92, 200, 255, .14);
  /* v59: the lime-green bull logo (the brand mark's colours; 3:1+ on every dark surface) and the brand accents that echo it */
  --logo-a: #86ea4c;
  --logo-b: #3ec63a;
  --logo-c: #1c6e22;
  --logo-body: #0e3a1b;
  --logo-glow: rgba(62, 198, 58, .22);
  --brand-a: #86ea4c;
  --brand-b: #3ec63a;
  --tip-bg: #060a12;
  --tip-text: #e8eef8;
  --shadow: 0 10px 30px rgba(0, 0, 0, .45);
  --shadow-sm: 0 2px 10px rgba(0, 0, 0, .35);
  --focus: #7fb0ff;
}

/* ---------- Light ---------- */
[data-theme="light"] {
  color-scheme: light;
  --bg: #eef1f6;
  --bg-2: #f6f8fb;
  --surface: #ffffff;
  --surface-2: #f3f6fa;
  --surface-3: #e9eef6;
  --border: #dde3ec;
  --border-strong: #c5cfdd;
  --text: #0f172a;
  --text-2: #263247;
  --muted: #5b6778;
  --muted-2: #5f6b82;   /* ≥ 4.5:1 on every light surface (axe, 2026-10-02) */
  --accent: #2f6fe4;
  --accent-2: #1b4fb8;    /* text accent: ≥ 5.4:1 on every light surface incl. accent-soft (#d0dff9); white on it 7.3:1 */
  --accent-soft: rgba(47, 111, 228, .12);
  --on-accent: #ffffff;
  --up: #0b6b3d;          /* ≥ 5.6:1 on white, up-soft (#e2f1ea) and every light surface */
  --on-up: #ffffff;       /* text on a solid --up fill (TRIGGERED badge/chip, Paper Buy): 6.6:1 */
  --on-down: #ffffff;     /* white on --down #c8203f: 5.6:1 */
  --on-warn: #ffffff;     /* white on --warn #7a4a00: 7.5:1 */
  --up-soft: rgba(15, 138, 79, .12);
  --down: #c8203f;
  --down-soft: rgba(200, 32, 63, .12);
  --down-text: #a8172f;   /* ≥ 5.2:1 on --down-soft over every light surface */
  --warn: #7a4a00;        /* ≥ 5.9:1 on warn-soft (#eae4dc / #f5ece0) */
  --warn-soft: rgba(168, 100, 0, .12);
  --live: #6d28d9;
  --live-soft: rgba(109, 40, 217, .12);
  --live-text: #5b21b6;   /* v45: LIVE as text in the top bar (≥ 7:1 on white) */
  --info: #0a5f94;        /* ≥ 5.8:1 on info-soft (#e2eff6) */
  --info-soft: rgba(11, 120, 184, .12);
  /* v59: the logo's deeper greens for light surfaces (3.4:1+), its body a pale tint, no glow */
  --logo-a: #3b9330;
  --logo-b: #2a7a22;
  --logo-c: #1b5a17;
  --logo-body: #cfe6c6;
  --logo-glow: transparent;
  --brand-a: #3b9330;
  --brand-b: #2a7a22;
  --tip-bg: #111a2b;
  --tip-text: #eef2f8;
  --shadow: 0 10px 30px rgba(23, 43, 84, .12);
  --shadow-sm: 0 2px 10px rgba(23, 43, 84, .08);
  --focus: #2f6fe4;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; padding: 0; }
html { scrollbar-gutter: stable; }
[hidden] { display: none !important; }
body {
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: var(--fs-md);
  line-height: 1.5;
  font-variant-numeric: tabular-nums;   /* prices and quantities line up in every column */
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
button, input, select, textarea { font: inherit; color: inherit; }
/* v30: <b>/<strong> are a fixed 700; the UA's `bolder` turned bold text inside 600-weight UI into 900. */
b, strong { font-weight: 700; }
button { cursor: pointer; }
a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: var(--mono); font-size: .92em; }
.num, .tnum, td.num, th.num { font-variant-numeric: tabular-nums; font-feature-settings: "tnum" 1; }
.up { color: var(--up); }
.down { color: var(--down); }
.neutral { color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: var(--fs-sm); }
.xs { font-size: var(--fs-xs); }
.meta { font-size: var(--fs-sm); color: var(--muted); overflow-wrap: anywhere; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
button:focus-visible, select:focus-visible, input:focus-visible, summary:focus-visible, a:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--focus); outline-offset: 2px;
}

/* ---------- Shared form controls (login + dashboard) ---------- */
.input, .login-form input {
  width: 100%;
  min-height: var(--control-h);
  padding: 8px 12px;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  font-variant-numeric: tabular-nums;
}
.input:focus, .login-form input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input:disabled { opacity: .55; cursor: not-allowed; }
.input[aria-invalid="true"] { border-color: var(--down); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--control-h); padding: 0 14px;
  border: 1px solid var(--border); border-radius: var(--r-sm);
  background: var(--surface-2); color: var(--text);
  font-size: var(--fs-md); font-weight: 600; line-height: 1; white-space: nowrap;
  transition: background .15s ease, border-color .15s ease, transform .1s ease, opacity .15s ease;
}
.btn:hover { border-color: var(--border-strong); background: var(--surface-3); }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn-danger:disabled, .btn-primary:disabled, .btn-buy:disabled { color: var(--muted); background: var(--surface-2); border-color: var(--border); box-shadow: none; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--accent); border-color: transparent; color: var(--on-accent); }
.btn-primary .fab-ico { color: inherit; filter: grayscale(1) brightness(10); }
.btn-primary:hover { background: var(--accent-2); border-color: transparent; }
.btn-danger { color: var(--down-text); border-color: color-mix(in srgb, var(--down) 35%, transparent); background: var(--down-soft); }
.btn-danger:hover { background: rgba(255, 84, 112, .22); }
.btn-buy { background: var(--up); border-color: transparent; color: var(--on-up); }
.btn-buy:hover { filter: brightness(1.08); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-sm { min-height: 28px; padding: 0 10px; font-size: var(--fs-sm); }
.btn-block { width: 100%; }

/* ---------- Login page ---------- */
.login-page {
  width: min(100% - 40px, 420px);
  margin: 10vh auto;
  padding: 32px 28px 28px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
}
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 26px; }
/* v60 (regression LG59): the mark keeps its 44 px beside the spaced title (it shrank to ~30 px at 320 px); the
   title block wraps instead */
.login-brand .brand-mark { width: 44px; height: 44px; flex: none; }
.login-brand > div { min-width: 0; }
/* v59: the name set like the logo's wordmark - capitals, wide tracking - in the theme's text colour */
.login-brand h1 { font-family: var(--font-display); font-size: var(--fs-3xl); font-weight: 600; letter-spacing: .22em; text-transform: uppercase; line-height: 1.1; }
.login-brand .brand-sub { font-size: var(--fs-sm); color: var(--muted); }
.login-form { display: grid; gap: 16px; }
.login-form h2 { font-size: var(--fs-lg); font-weight: 700; }
.login-form .fld { display: grid; gap: 6px; font-size: var(--fs-sm); color: var(--muted); }
.login-form input { min-height: 42px; }
.login-form .btn { min-height: 42px; }
#loginError { color: var(--down); min-height: 22px; font-size: var(--fs-sm); overflow-wrap: anywhere; }
.login-note { margin-top: 18px; font-size: var(--fs-xs); color: var(--muted-2); line-height: 1.5; }

/* Brand mark (inline SVG in markup) */
.brand-mark { display: block; filter: drop-shadow(0 2px 8px var(--logo-glow)); }
