/* =========================================================================
   Crypto-NVR design system — dark, data-dense, responsive (web + mobile PWA).
   Semantic tokens; 44px touch targets; tabular numerics; color never the only
   signal (PnL also uses +/− and arrows). Respects reduced-motion.
   ========================================================================= */
:root {
  --bg: #0a0d14;
  --bg-grad: radial-gradient(1200px 600px at 80% -10%, #141b2e 0%, #0a0d14 55%);
  --surface: #11151f;
  --surface-2: #151b27;
  --elevated: #1a2130;
  --border: #232b3a;
  --border-strong: #303a4d;

  --text: #e7ecf4;
  --text-dim: #98a3b7;
  --text-mute: #747f91;   /* 4.5:1 on surface — AA for normal text */

  --primary: #5b8cff;
  --primary-hover: #6f9bff;
  --primary-soft: rgba(91, 140, 255, 0.14);
  --accent: #22d3ee;

  --pos: #2bd98e;
  --pos-soft: rgba(43, 217, 142, 0.14);
  --neg: #ff5f6d;
  --neg-soft: rgba(255, 95, 109, 0.14);
  --warn: #f6c455;
  --warn-soft: rgba(246, 196, 85, 0.14);

  --r-sm: 8px; --r-md: 12px; --r-lg: 16px; --r-pill: 999px;
  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px; --sp-5: 24px; --sp-6: 32px;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
  --shadow-sm: 0 2px 10px rgba(0, 0, 0, 0.25);
  --glow: 0 0 0 1px var(--primary-soft), 0 8px 24px rgba(91, 140, 255, 0.18);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", "Roboto Mono", Menlo, monospace;
  --sidebar-w: 240px;
  --topbar-h: 60px;
  --bottomnav-h: 64px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
/* Icon SVGs must never expand to fill their container (charts use .chart svg). */
.ic { width: 20px; height: 20px; flex: none; }
.banner .ic { width: 22px; height: 22px; }
body {
  font-family: var(--font);
  background: var(--bg) var(--bg-grad) fixed;
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}
.num { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }
.mono { font-family: var(--mono); }
.pos { color: var(--pos); } .neg { color: var(--neg); } .warn { color: var(--warn); }
.dim { color: var(--text-dim); } .mute { color: var(--text-mute); }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
a { color: var(--primary); text-decoration: none; }

button, input, select { font-family: inherit; font-size: inherit; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 6px; }

/* ---------------- Layout shell ---------------- */
.shell { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100dvh; }
.sidebar {
  position: sticky; top: 0; height: 100dvh;
  background: linear-gradient(180deg, var(--surface) 0%, #0d111a 100%);
  border-right: 1px solid var(--border);
  padding: var(--sp-4) var(--sp-3);
  display: flex; flex-direction: column; gap: var(--sp-2);
}
.brand { display: flex; align-items: center; gap: 10px; padding: 8px 10px 18px; }
.brand .logo { width: 30px; height: 30px; }
.brand b { font-size: 16px; letter-spacing: -0.02em; }
.brand small { color: var(--text-mute); font-size: 11px; display: block; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 12px; border-radius: var(--r-md);
  color: var(--text-dim); cursor: pointer; border: 1px solid transparent;
  min-height: 44px; transition: background .15s, color .15s;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--primary-soft); color: var(--text); border-color: var(--primary-soft); }
.nav-item svg { width: 20px; height: 20px; flex: none; }
.nav-spacer { flex: 1; }
.main { min-width: 0; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  height: var(--topbar-h); display: flex; align-items: center; gap: var(--sp-3);
  padding: 0 var(--sp-5); background: rgba(10,13,20,0.8); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 18px; }
.topbar .spacer { flex: 1; }
.content { padding: var(--sp-5); max-width: 1200px; width: 100%; margin: 0 auto; }

/* ---------------- Chips / pills / dots ---------------- */
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px;
  border-radius: var(--r-pill); font-size: 12px; font-weight: 600;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text-dim);
}
.chip.primary { background: var(--primary-soft); color: var(--primary); border-color: transparent; }
.chip.pos { background: var(--pos-soft); color: var(--pos); border-color: transparent; }
.chip.neg { background: var(--neg-soft); color: var(--neg); border-color: transparent; }
.chip.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-mute); }
.dot.live { background: var(--pos); box-shadow: 0 0 0 4px var(--pos-soft); }
.dot.off { background: var(--neg); box-shadow: 0 0 0 4px var(--neg-soft); }

/* ---------------- Cards / grid ---------------- */
.grid { display: grid; gap: var(--sp-4); }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.card {
  background: linear-gradient(180deg, var(--surface) 0%, var(--surface-2) 100%);
  border: 1px solid var(--border); border-radius: var(--r-lg);
  padding: var(--sp-4); box-shadow: var(--shadow-sm);
}
.card.pad-lg { padding: var(--sp-5); }
.card h3 { font-size: 13px; color: var(--text-dim); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-size: 26px; font-weight: 700; margin-top: 6px; letter-spacing: -0.02em; }
.stat .sub { font-size: 12px; color: var(--text-mute); margin-top: 2px; }
.section-title { display: flex; align-items: center; gap: 10px; margin: var(--sp-5) 0 var(--sp-3); }
.section-title h2 { font-size: 16px; }

/* ---------------- Buttons ---------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 16px; border-radius: var(--r-md);
  background: var(--surface-2); color: var(--text); border: 1px solid var(--border-strong);
  cursor: pointer; font-weight: 600; transition: transform .08s, background .15s, border-color .15s;
}
.btn:hover { background: var(--elevated); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #06101f; }
.btn.primary:hover { background: var(--primary-hover); }
.btn.danger { background: var(--neg); border-color: var(--neg); color: #2a0608; }
.btn.ghost { background: transparent; }
.btn.sm { min-height: 36px; padding: 0 12px; font-size: 13px; }
.btn-row { display: flex; gap: var(--sp-2); flex-wrap: wrap; }

/* ---------------- Forms ---------------- */
.field { margin-bottom: var(--sp-4); }
.field label { display: block; font-size: 13px; color: var(--text-dim); margin-bottom: 6px; font-weight: 600; }
.field .help { font-size: 13px; color: var(--text-mute); margin-top: 6px; line-height: 1.5; }
.input, select.input {
  width: 100%; min-height: 44px; padding: 10px 12px; border-radius: var(--r-md);
  background: var(--bg); border: 1px solid var(--border-strong); color: var(--text);
}
.input:focus { border-color: var(--primary); }
.input.invalid { border-color: var(--neg); }
/* Toggle switch.
   The label carries .field label styling (display:block, 13px, dim). That block
   display used to defeat the flex row, leaving .track as an INLINE span — where
   width/height are ignored, so only its absolutely-positioned ::after knob
   rendered, floating over the label text. The specificity here must beat
   `.field label` (0,1,1), hence `.field label.toggle`. */
.toggle,
.field label.toggle {
  display: flex; align-items: center; gap: 12px;
  cursor: pointer; min-height: 44px; margin-bottom: 0;
  font-size: 15px; font-weight: 500; color: var(--text);
}
.toggle input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.toggle .track {
  flex: none;                 /* never let the flex row shrink the track away */
  display: inline-block;      /* a bare <span> is inline: width/height would not apply */
  width: 44px; height: 26px; border-radius: var(--r-pill);
  background: var(--border-strong); border: 1px solid var(--border-strong);
  position: relative; transition: background .18s ease-out, border-color .18s ease-out;
}
.toggle .track::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--text-dim);
  transition: transform .18s ease-out, background .18s ease-out;
}
.toggle input:checked + .track { background: var(--primary); border-color: var(--primary); }
.toggle input:checked + .track::after { transform: translateX(18px); background: #fff; }
/* The real input is visually hidden, so focus must be shown on the track. */
.toggle input:focus-visible + .track { outline: 2px solid var(--primary); outline-offset: 3px; }
.toggle:hover .track { border-color: var(--primary); }
/* Colour is not the only signal: the knob also moves, and state is announced. */
.toggle .state { margin-left: auto; font-size: 12px; font-weight: 600; color: var(--text-mute);
                 letter-spacing: .04em; text-transform: uppercase; }
.toggle input:checked ~ .state { color: var(--primary); }

/* Read-only settings, fixed by the venue's capabilities rather than preference. */
.field.locked .input { opacity: .55; cursor: not-allowed; }
.field .lock-note { display: inline-flex; align-items: center; gap: 5px; font-size: 12px;
                    color: var(--warn); margin-top: 6px; }

/* Numbers in inputs should align like numbers. */
.input[type="number"] { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }

/* Inline form-level error: sits with the form, announced to screen readers. */
.alert {
  display: flex; gap: 8px; align-items: flex-start; padding: 12px 14px;
  border-radius: var(--r-md); font-size: 14px; margin-top: var(--sp-4);
  background: var(--neg-soft); border: 1px solid rgba(255,95,109,.35); color: var(--text);
}
.alert::before { content: "!"; flex: none; width: 18px; height: 18px; border-radius: 50%;
  background: var(--neg); color: #0a0d14; font-weight: 700; font-size: 12px;
  display: grid; place-items: center; margin-top: 1px; }

/* Unmissable when nothing is enforcing the stop. On this venue the exchange
   holds no stop order, so "guard is down" is the single most important state
   this UI can communicate. */
.alert.danger { background: var(--neg-soft); border-color: var(--neg); }
.guard-banner {
  display: flex; gap: 12px; align-items: flex-start; padding: 14px 16px;
  border-radius: var(--r-md); margin-bottom: var(--sp-4); font-size: 14px;
  background: var(--neg-soft); border: 1px solid var(--neg);
  box-shadow: 0 0 0 1px rgba(255,95,109,.15), var(--shadow-sm);
}
.guard-banner.ok { background: var(--pos-soft); border-color: rgba(43,217,142,.35); box-shadow: none; }
.guard-banner b { display: block; margin-bottom: 2px; }
.guard-dot { width: 10px; height: 10px; border-radius: 50%; flex: none; margin-top: 5px;
             background: var(--neg); }
.guard-banner.ok .guard-dot { background: var(--pos); }
@media (prefers-reduced-motion: no-preference) {
  .guard-banner:not(.ok) .guard-dot { animation: pulse 1.8s ease-in-out infinite; }
}
@keyframes pulse { 0%,100% { opacity: 1 } 50% { opacity: .35 } }

/* ---------------- Tables ---------------- */
.table-wrap { overflow-x: auto; border-radius: var(--r-lg); border: 1px solid var(--border); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
thead th {
  text-align: left; padding: 12px 14px; color: var(--text-dim); font-weight: 600;
  font-size: 12px; text-transform: uppercase; letter-spacing: .03em;
  background: var(--surface); border-bottom: 1px solid var(--border); white-space: nowrap;
}
tbody td { padding: 12px 14px; border-bottom: 1px solid var(--border); white-space: nowrap; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }

/* ---------------- Charts ---------------- */
.chart { width: 100%; }
.chart svg { display: block; width: 100%; height: auto; }
.chart .grid-line { stroke: var(--border); stroke-width: 1; }
.chart .axis-label { fill: var(--text-mute); font-size: 10px; }
.chart-tooltip {
  position: absolute; pointer-events: none; background: var(--elevated);
  border: 1px solid var(--border-strong); border-radius: var(--r-sm);
  padding: 6px 10px; font-size: 12px; box-shadow: var(--shadow); transform: translate(-50%, -120%);
  white-space: nowrap; z-index: 5;
}

/* ---------------- Banners / events ---------------- */
.banner {
  display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: var(--r-md);
  background: var(--warn-soft); border: 1px solid rgba(246,196,85,.3); color: var(--text);
  margin-bottom: var(--sp-4); font-size: 14px;
}
.banner.demo { background: var(--primary-soft); border-color: rgba(91,140,255,.3); }
.event-row { display: flex; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.event-row:last-child { border: none; }
.event-row .when { color: var(--text-mute); font-size: 12px; min-width: 64px; }
.event-dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 6px; flex: none; background: var(--primary); }
.event-dot.warning { background: var(--warn); } .event-dot.error { background: var(--neg); }

/* ---------------- Login ---------------- */
.login-wrap { min-height: 100dvh; display: grid; place-items: center; padding: var(--sp-4); }
.login-card { width: 100%; max-width: 380px; }
.login-card .brand { justify-content: center; padding-top: 0; }

/* ---------------- Modal ---------------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: grid; place-items: center; z-index: 50; padding: var(--sp-4); }
.modal { width: 100%; max-width: 420px; animation: pop .18s ease-out; }
@keyframes pop { from { transform: scale(.96); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* ---------------- Toast ---------------- */
.toast-stack { position: fixed; bottom: calc(var(--bottomnav-h) + 16px); right: 16px; z-index: 60; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--elevated); border: 1px solid var(--border-strong); border-left: 3px solid var(--primary); padding: 12px 16px; border-radius: var(--r-md); box-shadow: var(--shadow); animation: slideIn .2s ease-out; max-width: 320px; }
.toast.error { border-left-color: var(--neg); } .toast.success { border-left-color: var(--pos); }
@keyframes slideIn { from { transform: translateX(20px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ---------------- Bottom nav (mobile) ---------------- */
.bottom-nav { display: none; }
.skeleton { background: linear-gradient(90deg, var(--surface-2) 25%, var(--elevated) 50%, var(--surface-2) 75%); background-size: 200% 100%; animation: shimmer 1.3s infinite; border-radius: var(--r-sm); }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* ---------------- Segmented control (currency toggle) ---------------- */
.segmented { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-pill); padding: 3px; gap: 2px; }
.segmented button { min-height: 34px; padding: 0 14px; border: none; background: transparent; color: var(--text-dim); border-radius: var(--r-pill); cursor: pointer; font-weight: 600; font-size: 13px; transition: background .15s, color .15s; }
.segmented button:hover { color: var(--text); }
.segmented button.active { background: var(--primary); color: #06101f; }

/* ---------------- Hero account card ---------------- */
.hero { display: flex; justify-content: space-between; gap: var(--sp-5); align-items: center; position: relative; overflow: hidden; padding: var(--sp-5); }
.hero::before { content: ""; position: absolute; top: 0; bottom: 0; left: 0; width: 4px; background: linear-gradient(180deg, var(--primary), var(--accent)); }
.hero h3 { font-size: 12px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .05em; }
.hero-main { padding-left: 6px; min-width: 0; }
.hero-value { font-size: 42px; font-weight: 750; letter-spacing: -0.03em; margin: 8px 0 12px; line-height: 1; }
.hero-sub { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; font-size: 13px; }
.hero-stats { display: grid; grid-template-columns: repeat(4, auto); gap: 30px; }
.hero-stats > div { display: flex; flex-direction: column; gap: 5px; }
.hero-stats .k { font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
.hero-stats .v { font-size: 21px; font-weight: 700; letter-spacing: -0.01em; }

/* subtle card hover lift for a more polished feel */
.card { transition: border-color .15s, transform .15s, box-shadow .15s; }
.grid .card.stat:hover, .table-wrap:hover { border-color: var(--border-strong); }

/* ---------------- Responsive ---------------- */
@media (max-width: 860px) {
  .hero { flex-direction: column; align-items: stretch; gap: var(--sp-4); }
  .hero-value { font-size: 34px; }
  .hero-stats { grid-template-columns: 1fr 1fr; gap: 18px 24px; }
  .topbar .segmented button { padding: 0 11px; }
}
@media (max-width: 1024px) { .grid.cols-4 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .content { padding: var(--sp-4); padding-bottom: calc(var(--bottomnav-h) + 24px); }
  .topbar { padding: 0 var(--sp-4); }
  .grid.cols-3, .grid.cols-2 { grid-template-columns: 1fr; }
  .grid.cols-4 { grid-template-columns: repeat(2, 1fr); }
  .bottom-nav {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
    height: calc(var(--bottomnav-h) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: rgba(13,17,26,0.96); backdrop-filter: blur(12px); border-top: 1px solid var(--border);
  }
  .bottom-nav .nav-item {
    flex: 1; flex-direction: column; gap: 3px; padding: 8px 0; border-radius: 0;
    font-size: 10.5px; min-height: 100%; justify-content: center;
  }
  .bottom-nav .nav-item.active { background: transparent; color: var(--primary); }
  .bottom-nav .nav-item span { font-weight: 600; }
}
@media (max-width: 420px) { .grid.cols-4 { grid-template-columns: 1fr 1fr; } .stat .value { font-size: 22px; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
