/*
 * Trading platform dashboard — dark by default.
 *
 * Colour roles come from the validated reference palette. The dark steps are the ones that were
 * validated against the dark chart surface (#1a1a19), not an inversion of the light ones, so making
 * dark the default changes nothing about their correctness.
 *
 * The equity line uses categorical slot 1 (blue); P&L uses the diverging blue<->red pair.
 * Green/red for profit and loss was rejected on measurement: the pair sits at ΔE 4.1 under
 * deuteranopia, far below the ΔE 8 floor, so the two most important colours on a trading dashboard
 * would be the two a red-green colourblind reader cannot tell apart. blue<->red is warm/cool and
 * clears every check in both modes (worst CVD ΔE 19.2 dark / 21.6 light).
 *
 * Chart chrome stays deliberately recessive: hairline solid gridlines, 2px strokes, thin marks. The
 * "modern" here is in surface layering, type rhythm and spacing — not in making the data louder.
 */

/* ──────────────────────────────────────────────────────────────────────────────
 * The hidden attribute only works because the UA stylesheet says [hidden]{display:none}, and ANY
 * author-level display declaration outranks it. `.login{display:grid}` silently beat
 * `loginView.hidden = true`, so after signing in the login panel kept its 100vh and the app
 * rendered underneath it. Declared once, with !important, so no component can reintroduce that.
 * ────────────────────────────────────────────────────────────────────────────── */
[hidden] {
  display: none !important;
}

:root {
  color-scheme: dark;

  /* Layered surfaces give depth without shadows doing the work. */
  --page:           #0d0d0d;   /* app background */
  --surface-1:      #1a1a19;   /* cards and chart surface — the validated dark surface */
  --surface-2:      #232322;   /* inputs, hover states */
  --surface-3:      #2c2c2a;   /* popovers, tooltips */

  --text-primary:   #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted:     #898781;

  --gridline:       #2c2c2a;
  --baseline:       #383835;
  --border:         rgba(255, 255, 255, 0.09);
  --border-strong:  rgba(255, 255, 255, 0.16);

  --series-1:       #3987e5;   /* equity line, positive P&L */
  --series-neg:     #e66767;   /* negative P&L */
  --delta-good:     #0ca30c;
  --delta-bad:      #d03b3b;
  --warning:        #fab219;

  --radius-lg:      16px;
  --radius:         12px;
  --radius-sm:      8px;

  --shadow-1:       0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-2:       0 8px 28px rgba(0, 0, 0, 0.45);

  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
}

/* Light is opt-in via the toggle. Same palette, the light-surface steps. */
:root[data-theme="light"] {
  color-scheme: light;

  --page:           #f4f4f1;
  --surface-1:      #fcfcfb;
  --surface-2:      #f0efec;
  --surface-3:      #ffffff;

  --text-primary:   #0b0b0b;
  --text-secondary: #52514e;
  --text-muted:     #898781;

  --gridline:       #e1e0d9;
  --baseline:       #c3c2b7;
  --border:         rgba(11, 11, 11, 0.10);
  --border-strong:  rgba(11, 11, 11, 0.18);

  --series-1:       #2a78d6;
  --series-neg:     #e34948;
  --delta-good:     #006300;
  --delta-bad:      #d03b3b;

  --shadow-1:       0 1px 2px rgba(11, 11, 11, 0.06);
  --shadow-2:       0 8px 28px rgba(11, 11, 11, 0.12);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  color: var(--text-primary);
  background: var(--page);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* A single very soft glow behind the header, for depth. Fixed and non-interactive so it never
   shifts layout or intercepts a click. */
body::before {
  content: "";
  position: fixed;
  inset: -20% 0 auto 0;
  height: 420px;
  background: radial-gradient(60% 100% at 50% 0%,
              color-mix(in oklab, var(--series-1), transparent 88%), transparent 70%);
  pointer-events: none;
  z-index: 0;
}

/* ── Login ─────────────────────────────────────────────────────────────────── */

.login {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px 28px;
  display: grid;
  gap: 18px;
  box-shadow: var(--shadow-2);
  /* A 1px accent along the top edge — an accent, not a saturated block. */
  background-image: linear-gradient(var(--series-1), var(--series-1));
  background-size: 100% 2px;
  background-repeat: no-repeat;
  background-position: top;
}

.login-title {
  margin: 0;
  font-size: 22px;
  font-weight: 650;
  letter-spacing: -0.02em;
}

.login-sub { margin: -8px 0 0; color: var(--text-secondary); font-size: 13px; }

.field { display: grid; gap: 7px; font-size: 12px; font-weight: 500; color: var(--text-secondary); }

.field input {
  font: inherit;
  font-size: 15px;
  font-weight: 400;
  padding: 11px 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-primary);
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}

.field input:hover { border-color: var(--border-strong); }

.field input:focus {
  outline: none;
  border-color: var(--series-1);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--series-1), transparent 78%);
}

.error {
  margin: 0;
  color: var(--delta-bad);
  font-size: 13px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  background: color-mix(in oklab, var(--surface-1), var(--delta-bad) 12%);
  border: 1px solid color-mix(in oklab, var(--border), var(--delta-bad) 30%);
}

/* ── Buttons ───────────────────────────────────────────────────────────────── */

.btn {
  font: inherit;
  font-size: 13px;
  font-weight: 550;
  padding: 9px 15px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-primary);
  cursor: pointer;
  min-height: 38px;
  white-space: nowrap;
  transition: background 0.15s var(--ease), border-color 0.15s var(--ease),
              transform 0.08s var(--ease);
}

.btn:hover { background: var(--surface-3); border-color: var(--border-strong); }
.btn:active { transform: translateY(1px); }

.btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--series-1), transparent 70%);
}

.btn-primary {
  background: var(--series-1);
  border-color: transparent;
  color: #fff;
  font-weight: 600;
  min-height: 42px;
}

.btn-primary:hover { background: color-mix(in oklab, var(--series-1), #fff 12%); }

.btn-danger { background: transparent; border-color: color-mix(in oklab, var(--delta-bad), transparent 45%); color: var(--delta-bad); }
.btn-danger:hover { background: color-mix(in oklab, var(--surface-1), var(--delta-bad) 14%); border-color: var(--delta-bad); }

.btn-ghost { background: transparent; }
.btn-ghost:hover { background: var(--surface-2); }

.btn-small { padding: 6px 11px; font-size: 12px; min-height: 30px; }

/* ── Top bar ───────────────────────────────────────────────────────────────── */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  padding: 13px 24px;
  background: color-mix(in oklab, var(--page), transparent 25%);
  backdrop-filter: saturate(160%) blur(12px);
  -webkit-backdrop-filter: saturate(160%) blur(12px);
  border-bottom: 1px solid var(--border);
}

.topbar-left, .topbar-right { display: flex; gap: 10px; align-items: center; }

.brand {
  font-weight: 650;
  font-size: 15px;
  letter-spacing: -0.01em;
  display: inline-flex;
  align-items: center;
  gap: 9px;
}

/* Small solid dot as a mark, rather than a large coloured surface. */
.brand::before {
  content: "";
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--series-1);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--series-1), transparent 82%);
}

.env-badge {
  font-size: 10.5px;
  font-weight: 650;
  letter-spacing: 0.06em;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  color: var(--text-secondary);
  background: var(--surface-1);
}

/* Real money is a different kind of state, and should not look like testnet. */
.env-badge.is-live {
  color: var(--delta-bad);
  border-color: color-mix(in oklab, var(--delta-bad), transparent 40%);
  background: color-mix(in oklab, var(--surface-1), var(--delta-bad) 10%);
}

.banner {
  position: relative;
  z-index: 1;
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  padding: 12px 24px;
  font-size: 13.5px;
}

.banner-halted {
  background: color-mix(in oklab, var(--surface-1), var(--warning) 16%);
  border-bottom: 1px solid color-mix(in oklab, var(--border), var(--warning) 40%);
  color: var(--text-primary);
}

/* ── Filters and tabs ──────────────────────────────────────────────────────── */

.filters {
  position: relative;
  z-index: 1;
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 0;
  flex-wrap: wrap;
  max-width: 1280px;
  margin: 0 auto;
}

/* One segmented control, one row, above everything it scopes. */
.range-group {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.range {
  font: inherit;
  font-size: 12px;
  font-weight: 550;
  padding: 6px 14px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  min-height: 30px;
  transition: background 0.15s var(--ease), color 0.15s var(--ease);
}

.range:hover { color: var(--text-primary); background: var(--surface-2); }
.range.is-active { background: var(--series-1); color: #fff; }

.refresh-note { font-size: 12px; color: var(--text-muted); font-variant-numeric: tabular-nums; }

.tabs {
  position: relative;
  z-index: 1;
  display: flex;
  gap: 2px;
  padding: 16px 24px 0;
  max-width: 1280px;
  margin: 0 auto;
  border-bottom: 1px solid var(--border);
}

.tab {
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  padding: 11px 16px;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 8px 8px 0 0;
  position: relative;
  transition: color 0.15s var(--ease), background 0.15s var(--ease);
}

.tab:hover { color: var(--text-secondary); background: var(--surface-1); }
.tab.is-active { color: var(--text-primary); font-weight: 600; }

/* Underline drawn as a pseudo-element so it sits on the container's border line. */
.tab.is-active::after {
  content: "";
  position: absolute;
  inset: auto 12px -1px 12px;
  height: 2px;
  border-radius: 2px 2px 0 0;
  background: var(--series-1);
}

/* ── Layout ────────────────────────────────────────────────────────────────── */

.content {
  position: relative;
  z-index: 1;
  padding: 22px 24px 40px;
  display: grid;
  gap: 18px;
  max-width: 1280px;
  margin: 0 auto;
}

.panel { display: none; gap: 18px; }
.panel.is-active { display: grid; }

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 22px;
  box-shadow: var(--shadow-1);
}

.card-head {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.card-title {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--text-secondary);
  text-transform: uppercase;
}

.hint { font-size: 12px; color: var(--text-muted); font-weight: 400; text-transform: none; }

.grid-2 { display: grid; gap: 18px; grid-template-columns: 1fr; }
@media (min-width: 900px) { .grid-2 { grid-template-columns: 1fr 1fr; } }

.empty-state p { color: var(--text-secondary); font-size: 14px; max-width: 62ch; }

.empty-state code {
  font-size: 12px;
  padding: 2px 6px;
  border-radius: 5px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
}

/* ── Stat tiles ────────────────────────────────────────────────────────────── */

.tiles { display: grid; gap: 14px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 820px) { .tiles { grid-template-columns: repeat(4, minmax(0, 1fr)); } }

.tile {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow-1);
  transition: border-color 0.18s var(--ease), transform 0.18s var(--ease);
}

.tile:hover { border-color: var(--border-strong); transform: translateY(-1px); }

.tile-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-muted);
  display: flex;
  gap: 7px;
  align-items: center;
}

/* Proportional figures on a large standalone number — tabular digits read loose at this size. */
.tile-value {
  font-size: 27px;
  font-weight: 650;
  line-height: 1.15;
  margin-top: 8px;
  letter-spacing: -0.025em;
}

.tile-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 5px;
  overflow-wrap: anywhere;
}

/* An arrow glyph beside the number, so sign never rests on colour alone. */
.delta-up { color: var(--delta-good); }
.delta-down { color: var(--delta-bad); }

.tile-value.is-unknown {
  color: var(--text-muted);
  font-size: 17px;
  font-weight: 500;
  letter-spacing: 0;
}

/* ── Charts ────────────────────────────────────────────────────────────────── */

/* Height is not fixed, so the x-axis band can never be cropped into a nested scrollbar. */
.chart-holder { position: relative; }
.chart-holder svg { display: block; width: 100%; height: auto; overflow: visible; }

.grid-line { stroke: var(--gridline); stroke-width: 1; }   /* solid hairline, never dashed */
.axis-line { stroke: var(--baseline); stroke-width: 1; }
.axis-label { fill: var(--text-muted); font-size: 10px; font-variant-numeric: tabular-nums; }

.equity-line { fill: none; stroke: var(--series-1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.equity-area { fill: var(--series-1); opacity: 0.10; }

.end-dot { fill: var(--series-1); stroke: var(--surface-1); stroke-width: 2; }
.end-label { fill: var(--text-primary); font-size: 11px; font-weight: 650; }

.bar-pos { fill: var(--series-1); }
.bar-neg { fill: var(--series-neg); }
.bar-hit { fill: transparent; cursor: pointer; }

.crosshair { stroke: var(--text-muted); stroke-width: 1; pointer-events: none; }

.chart-empty {
  margin: 0;
  padding: 34px 8px;
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

.tooltip, .help-pop {
  position: fixed;
  z-index: 60;
  background: var(--surface-3);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 12px;
  color: var(--text-primary);
  box-shadow: var(--shadow-2);
  pointer-events: none;
  max-width: 270px;
}

.help-pop { pointer-events: auto; max-width: 330px; font-size: 12.5px; line-height: 1.5; padding: 14px 16px; }
.help-pop h4 { margin: 0 0 8px; font-size: 12.5px; font-weight: 650; }
.help-pop p { margin: 0 0 8px; color: var(--text-secondary); }
.help-pop p:last-child { margin-bottom: 0; }
.help-pop .risk { color: var(--delta-bad); }

.tip-label { color: var(--text-muted); font-size: 11px; }
.tip-value { font-weight: 650; font-variant-numeric: tabular-nums; margin: 2px 0; }

/* ── Tables ────────────────────────────────────────────────────────────────── */

.table-wrap, .table-view { overflow-x: auto; margin: 0 -6px; padding: 0 6px; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }

th {
  text-align: left;
  font-weight: 600;
  font-size: 10.5px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
  white-space: nowrap;
}

tbody tr { transition: background 0.12s var(--ease); }
tbody tr:hover td { background: var(--surface-2); }

td.num { text-align: right; font-variant-numeric: tabular-nums; color: var(--text-primary); }
td.strong { color: var(--text-primary); font-weight: 550; }
tbody tr:last-child td { border-bottom: 0; }

.empty-row { color: var(--text-muted); font-style: italic; }

/* ── Feeds ─────────────────────────────────────────────────────────────────── */

.feed {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 2px;
  max-height: 340px;
  overflow-y: auto;
  scrollbar-width: thin;
}

.feed li {
  display: grid;
  gap: 3px;
  font-size: 13px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  transition: background 0.12s var(--ease);
}

.feed li:hover { background: var(--surface-2); }

.feed .when {
  font-size: 10.5px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}

.feed .msg { color: var(--text-secondary); overflow-wrap: anywhere; line-height: 1.45; }
.feed .lvl-ERROR .msg { color: var(--delta-bad); }
.feed .lvl-WARN .msg { color: var(--text-primary); }

/* Left rule to mark severity, so level is not carried by colour alone. */
.feed .lvl-ERROR { border-left: 2px solid var(--delta-bad); border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.feed .lvl-WARN { border-left: 2px solid var(--warning); border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }

/* Info affordance next to every editable setting (blueprint section 12). */
.info-btn {
  width: 17px;
  height: 17px;
  min-height: 0;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--border-strong);
  background: transparent;
  color: var(--text-muted);
  font-size: 10.5px;
  font-weight: 650;
  line-height: 1;
  cursor: pointer;
  flex: 0 0 auto;
  transition: color 0.15s var(--ease), border-color 0.15s var(--ease), background 0.15s var(--ease);
}

.info-btn:hover { color: var(--text-primary); border-color: var(--series-1); background: color-mix(in oklab, var(--series-1), transparent 85%); }

.switch { display: inline-flex; gap: 8px; align-items: center; margin: 2px 0; }

.pill {
  font-size: 10.5px;
  font-weight: 650;
  letter-spacing: 0.05em;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  color: var(--text-muted);
  white-space: nowrap;
}

.pill.on {
  color: var(--delta-good);
  border-color: color-mix(in oklab, var(--delta-good), transparent 50%);
  background: color-mix(in oklab, var(--surface-1), var(--delta-good) 10%);
}

.pill.off { color: var(--text-muted); }

/* ── Bottom nav (small screens) ────────────────────────────────────────────── */

.bottom-nav { display: none; }

@media (max-width: 720px) {
  .tabs { display: none; }
  .content { padding: 16px 14px 88px; gap: 14px; }
  .card { padding: 16px; border-radius: var(--radius); }
  .topbar { padding: 11px 14px; }
  .filters { padding: 16px 14px 0; }
  .banner { padding: 11px 14px; }
  .tiles { gap: 10px; }
  .tile { padding: 13px 14px; }
  .tile-value { font-size: 21px; }
  .grid-2 { gap: 14px; }

  /* Compact the header controls rather than hiding any of them — sign-out and the kill switch
     both have to stay reachable on a phone. */
  .topbar-right { gap: 7px; }
  .topbar-right .btn { padding: 8px 11px; font-size: 12px; }

  .bottom-nav {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    position: fixed;
    inset: auto 0 0 0;
    z-index: 30;
    background: color-mix(in oklab, var(--page), transparent 12%);
    backdrop-filter: saturate(160%) blur(14px);
    -webkit-backdrop-filter: saturate(160%) blur(14px);
    border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom);
  }

  .bnav {
    font: inherit;
    font-size: 12px;
    font-weight: 550;
    padding: 14px 4px;
    border: 0;
    border-top: 2px solid transparent;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    min-height: 52px;
  }

  .bnav.is-active { color: var(--series-1); border-top-color: var(--series-1); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
  .tile:hover { transform: none; }
}
