/* Elite Quant M·A — web client.
 *
 * Three things this stylesheet is doing that are not obvious:
 *
 * 1. The experience tier is a `data-experience` attribute on <body>, and
 *    density is expressed as CSS variables underneath it. Switching tier is
 *    one attribute change, not a re-render, and no component needs to know
 *    which tier it is in.
 * 2. Refusals are styled as first-class content, not as errors. The scanner
 *    showing "no opportunity" is the product working; it should not look like
 *    something broke.
 * 3. Money is right-aligned and tabular everywhere. Columns of numbers that
 *    do not line up are how people misread their own balance.
 */

:root {
  color-scheme: dark;
  --bg: #0b0e14;
  --surface: #121722;
  --surface-2: #1a2030;
  --line: #232b3d;
  --text: #e6eaf2;
  --muted: #8d97ab;
  --accent: #6a7dff;
  --up: #37b26b;
  --down: #e0526b;
  --warn: #d9a02b;
  --radius: 10px;

  /* The chart reads these off the canvas rather than hard-coding colours, so
     an experience tier restyles it without chart.js knowing tiers exist.
     --ink is the strongest foreground; the watermark uses it at low alpha. */
  --ink: #e6eaf2;
  --chart-grid: rgba(141, 151, 171, .16);

  /* density, overridden per experience */
  --pad: 16px;
  --row-pad: 10px;
  --font-size: 15px;
  --table-size: 14px;
}

body[data-experience="institutional"] {
  --accent: #94a3c4;
  --pad: 12px; --row-pad: 6px; --font-size: 14px; --table-size: 12.5px;
}
body[data-experience="premium_warm"] { --accent: #6a7dff; }
body[data-experience="sanctuary_full"] {
  --accent: #2fb3a3;
  --pad: 22px; --row-pad: 15px; --font-size: 16px; --table-size: 15px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: var(--font-size)/1.5 ui-sans-serif, -apple-system, "Segoe UI", Roboto,
        "Helvetica Neue", Arial, sans-serif;
}

/* The `hidden` attribute is a browser default of `display: none`, and a
   browser default loses to any class that sets `display` itself. `.topbar`
   sets `display: flex`, so `<header hidden>` stayed on screen and a
   signed-out visitor was shown the whole navigation and a Sign out button.
   This puts the attribute back in charge, everywhere, once. */
[hidden] { display: none !important; }

/* ── chrome ─────────────────────────────────────────────────────────────── */

.honesty {
  background: color-mix(in srgb, var(--warn) 18%, var(--bg));
  border-bottom: 1px solid color-mix(in srgb, var(--warn) 45%, var(--bg));
  color: #f0dcae;
  padding: 7px 18px;
  font-size: 13px;
  text-align: center;
}

.topbar {
  display: flex; align-items: center; gap: 22px;
  padding: 0 18px; height: 58px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; }
.mark {
  display: grid; place-items: center;
  width: 30px; height: 30px; border-radius: 8px;
  background: linear-gradient(140deg, var(--accent), color-mix(in srgb, var(--accent) 40%, #000));
  color: #fff; font-size: 12px; letter-spacing: .02em;
}
.wordmark { white-space: nowrap; }
.nav { display: flex; gap: 2px; flex: 1; overflow-x: auto; }
.nav-item {
  background: none; border: 0; color: var(--muted);
  padding: 8px 12px; border-radius: 8px; cursor: pointer;
  font: inherit; white-space: nowrap;
}
.nav-item:hover { color: var(--text); background: var(--surface-2); }
.nav-item[aria-current="page"] { color: var(--text); background: var(--surface-2); }
.topbar-right { display: flex; align-items: center; gap: 10px; }

main { padding: var(--pad); max-width: 1180px; margin: 0 auto; }

/* ── primitives ─────────────────────────────────────────────────────────── */

h1 { font-size: 21px; margin: 0 0 4px; font-weight: 650; }
h2 { font-size: 15px; margin: 0 0 12px; font-weight: 600; }
.sub { color: var(--muted); font-size: 13px; margin: 0 0 var(--pad); }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--pad);
  margin-bottom: var(--pad);
}
.grid { display: grid; gap: var(--pad); }
.grid.cols-4 { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }

.stat .label { color: var(--muted); font-size: 12px; text-transform: uppercase;
               letter-spacing: .06em; }
.stat .value { font-size: 26px; font-weight: 620; font-variant-numeric: tabular-nums;
               margin-top: 4px; }
.stat .note { color: var(--muted); font-size: 12px; margin-top: 2px; }

.num { font-variant-numeric: tabular-nums; text-align: right; }
.up { color: var(--up); } .down { color: var(--down); }

.pill {
  font-size: 11.5px; padding: 3px 9px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface-2); color: var(--muted);
  white-space: nowrap;
}
.pill.live   { border-color: var(--down); color: var(--down); }
.pill.paper  { border-color: var(--accent); color: var(--accent); }
.pill.ok     { border-color: var(--up); color: var(--up); }
.pill.refused{ border-color: var(--warn); color: var(--warn); }

button.primary, button.ghost {
  font: inherit; padding: 9px 16px; border-radius: 8px; cursor: pointer;
}
button.primary { background: var(--accent); border: 0; color: #fff; font-weight: 560; }
button.primary:disabled { opacity: .5; cursor: default; }
button.ghost { background: transparent; border: 1px solid var(--line); color: var(--text); }
button.ghost:hover { background: var(--surface-2); }
button.danger { border-color: var(--down); color: var(--down); }

table { width: 100%; border-collapse: collapse; font-size: var(--table-size); }
th {
  text-align: left; color: var(--muted); font-weight: 500; font-size: 11.5px;
  text-transform: uppercase; letter-spacing: .05em;
  padding: 0 10px var(--row-pad); border-bottom: 1px solid var(--line);
}
td { padding: var(--row-pad) 10px; border-bottom: 1px solid var(--line); }
tbody tr:hover { background: var(--surface-2); }
tbody tr.clickable { cursor: pointer; }
.table-wrap { overflow-x: auto; }

.empty { color: var(--muted); padding: 26px; text-align: center; }

/* Refusals read as information, never as failure. */
.refusal { color: var(--warn); }
tr.refused td:not(.refusal) { opacity: .62; }

label.field { display: block; margin-bottom: 14px; }
label.field span { display: block; color: var(--muted); font-size: 12.5px; margin-bottom: 5px; }
input, select {
  width: 100%; padding: 10px 12px; font: inherit;
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 8px; color: var(--text);
}
input:focus, select:focus { outline: 2px solid color-mix(in srgb, var(--accent) 55%, transparent);
                            outline-offset: 1px; }

.switch { display: flex; align-items: center; gap: 12px; }
.switch input { width: auto; }

.log { list-style: none; margin: 0; padding: 0; }
.log li {
  padding: 8px 0 8px 16px; border-left: 2px solid var(--line);
  font-size: 13px; color: var(--muted);
}
.log li strong { color: var(--text); font-weight: 560; }

.auth-wrap { max-width: 380px; margin: 9vh auto; }
.auth-wrap .mark { width: 40px; height: 40px; font-size: 14px; margin-bottom: 18px; }

.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  background: var(--surface-2); border: 1px solid var(--line);
  padding: 11px 18px; border-radius: 10px; font-size: 14px; z-index: 20;
}
.toast.bad { border-color: var(--down); color: #ffd7de; }


.mono-value {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 15px; word-break: break-all; line-height: 1.5;
  margin-top: 4px;
}
.instructions {
  white-space: pre-wrap; font-family: inherit; font-size: 13.5px;
  color: var(--muted); background: var(--surface-2);
  border: 1px solid var(--line); border-radius: 8px;
  padding: 14px; margin-top: 14px; overflow-x: auto;
}

/* Sanctuary hides anything that rewards watching the screen. */
body[data-experience="sanctuary_full"] [data-hide-in="sanctuary_full"] { display: none !important; }
body[data-experience="institutional"] [data-hide-in="institutional"] { display: none !important; }

@media (max-width: 700px) {
  .topbar { height: auto; flex-wrap: wrap; padding: 10px 12px; gap: 10px; }
  /* flex-basis, not width: `.nav` has `flex: 1`, whose basis of 0 lets it
     shrink onto the first line and the nav ends up clipped beside the brand. */
  .nav { order: 3; flex: 1 0 100%; }
}


/* ── chart and markets ────────────────────────────────────────────────── */

.chart-wrap {
  position: relative;
  /* The canvas sizes itself from this element, so the height lives here and
     not on the canvas: a canvas with an intrinsic 150px default silently wins
     otherwise, and the chart draws into a letterbox. */
  height: 340px;
  margin-top: 4px;
}
.chart-wrap canvas { display: block; width: 100%; height: 100%; cursor: crosshair; }

.chart-bar {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  margin-bottom: 10px;
}
/* The select sizes to its content. `flex: 0 0 auto` alone did not do it: the
   global `input, select { width: 100% }` a hundred lines up still applied, so
   the flex item's basis was the full bar and a four-character ticker got a
   1100px dropdown. The width has to be reset explicitly. */
.chart-bar select { flex: 0 0 auto; width: auto; min-width: 150px; }
.chart-bar select, .chart-bar .tf {
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px;
  padding: 7px 10px; font: inherit; font-size: 13px;
}
.chart-bar .tf { cursor: pointer; }
.chart-bar .tf[aria-pressed="true"] {
  border-color: var(--accent); color: var(--text);
  background: color-mix(in srgb, var(--accent) 22%, var(--surface-2));
}
.chart-bar .spacer { flex: 1; }

.readout {
  display: flex; gap: 14px; flex-wrap: wrap;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12.5px; color: var(--muted); min-height: 19px;
  margin-top: 8px;
}
.readout b { color: var(--text); font-weight: 600; }

.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12.5px;
          color: var(--muted); margin-top: 8px; }
.legend i { display: inline-block; width: 18px; height: 0; vertical-align: middle;
            border-top: 2px solid currentColor; margin-right: 6px; }
.legend .entry { color: var(--accent); }
.legend .stop { color: var(--down); }
.legend .target { color: var(--up); }

/* The live indicator. It reports the transport the client actually has, not
   the one it wanted: a customer behind a proxy that strips websockets is on a
   slower path and is told so rather than left wondering. */
.live-dot {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--muted);
}
.live-dot::before {
  content: ""; width: 7px; height: 7px; border-radius: 50%;
  background: var(--muted);
}
.live-dot[data-status="live"]::before { background: var(--up); }
.live-dot[data-status="polling"]::before { background: var(--warn); }
.live-dot[data-status="offline"]::before { background: var(--down); }
/* Reduced motion is respected: a pulsing dot on a trading screen is exactly
   the kind of thing sanctuary mode exists to remove. */
@media (prefers-reduced-motion: no-preference) {
  .live-dot[data-status="live"]::before { animation: live-pulse 2.4s ease-in-out infinite; }
}
@keyframes live-pulse { 50% { opacity: .35; } }
body[data-experience="sanctuary_full"] .live-dot::before { animation: none !important; }

tr.clickable { cursor: pointer; }

@media (max-width: 700px) {
  .chart-wrap { height: 260px; }
}
