/* ── Design Tokens ──────────────────────────────────────────── */
:root {
  /* Sidebar — dark in both themes. Its text clears 4.5:1 on it. */
  --sidebar-width: 216px;       /* drawer, and pinned sidebar with labels */
  --sidebar-rail-width: 56px;   /* pinned sidebar collapsed to icons */
  --topbar-h: 48px;
  --sidebar-gradient: #121820;  /* name kept; now a solid colour */
  --sidebar-hover-bg: rgba(255, 255, 255, 0.06);
  --sidebar-active-bg: rgba(240, 180, 60, 0.14);
  --sidebar-text: #cfd7e1;
  --sidebar-text-active: #ffffff;
  --sidebar-text-current: #f5c45e;  /* the open page: amber */
  --sidebar-text-muted: #8794a5;
  --sidebar-border: rgba(255, 255, 255, 0.08);

  /* Fonts (Direction B "Trading desk"): Plex Sans for text, Plex Sans
     Condensed for headings and labels, JetBrains Mono for figures. */
  --font-ui: 'IBM Plex Sans', 'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-head: 'IBM Plex Sans Condensed', 'IBM Plex Sans', 'Arial Narrow', 'Segoe UI', sans-serif;
  --font-num: 'JetBrains Mono', Consolas, 'Courier New', monospace;

  /* Content area */
  --bg-page: #e9edf2;
  --bg-surface: #ffffff;
  --bg-surface-2: #f3f5f8;
  --bg-hover: #edf1f6;

  /* Text — every text colour clears 4.5:1 on page, surface and hover
     backgrounds. --text-disabled is for non-essential text only. */
  --text-primary: #0f1720;
  --text-secondary: #3f4a58;
  --text-muted: #5a6573;
  --text-disabled: #9aa3ae;

  /* Borders — --border/--border-subtle are decorative dividers;
     --border-strong is for control edges (inputs), 3:1 on surfaces. */
  --border: #d6dce4;
  --border-subtle: #e6eaef;
  --border-strong: #7d8794;

  /* Accent — amber. --accent is a fill and always takes --on-accent (dark)
     text, never white; --accent-text is for amber-coloured text and links. */
  --accent: #f0b43c;
  --accent-hover: #e2a42a;
  --on-accent: #1a1300;
  --accent-text: #8a5a00;
  --accent-purple: #a855f7;
  --accent-pink: #db2777;
  --accent-light: #fdf1d6;
  --focus-ring: #a06a00;

  /* Semantic — reserved for meaning, never decoration. Text colours clear
     4.5:1; the -bg tints are backgrounds for badges, banners and rows. */
  --profit: #08784a;
  --profit-bg: rgba(8, 120, 74, 0.10);
  --loss: #c0262d;
  --loss-bg: rgba(192, 38, 45, 0.09);
  --warning-text: #a14d00;
  --warning-bg: rgba(255, 140, 40, 0.14);
  --critical: #c0262d;
  --critical-bg: rgba(192, 38, 45, 0.09);
  --info: #1a5fb4;
  --info-bg: rgba(26, 95, 180, 0.10);
  --live: #12a05c;

  /* Shadows — flat surfaces; only floating things (menus, dialogs,
     toasts) keep a shadow. */
  --shadow-xs: none;
  --shadow-sm: none;
  --shadow-md: 0 6px 20px rgba(15, 23, 32, 0.16);
  --shadow-sidebar: 4px 0 24px rgba(0, 0, 0, 0.35);

  /* Misc */
  --radius-sm: 3px;
  --radius-md: 4px;
  --radius-lg: 6px;
  --radius-xl: 8px;
  --transition: 0.18s ease;
  --sidebar-transition: 0.26s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ── Dark Theme Overrides ───────────────────────────────────── */
[data-theme="dark"] {
  --sidebar-gradient: #0b0e12;
  --bg-page: #0f1318;
  --bg-surface: #151a21;
  --bg-surface-2: #1a2028;
  --bg-hover: #202733;

  --text-primary: #dde3ea;
  --text-secondary: #a3adba;
  --text-muted: #939eae;
  --text-disabled: #5d6878;

  --border: #29313c;
  --border-subtle: #20262f;
  --border-strong: #5d6878;

  --accent-text: #f5c45e;
  --accent-light: rgba(240, 180, 60, 0.13);
  --focus-ring: #f5c45e;

  --profit: #3fcf8e;
  --profit-bg: rgba(63, 207, 142, 0.12);
  --loss: #ff6f66;
  --loss-bg: rgba(255, 111, 102, 0.12);
  --warning-text: #ff9f43;
  --warning-bg: rgba(255, 159, 67, 0.13);
  --critical: #ff6f66;
  --critical-bg: rgba(255, 111, 102, 0.12);
  --info: #6cb6ff;
  --info-bg: rgba(108, 182, 255, 0.12);

  --shadow-xs: none;
  --shadow-sm: none;
  --shadow-md: 0 6px 20px rgba(0, 0, 0, 0.5);
}

/* ── Reset ──────────────────────────────────────────────────── */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: var(--font-ui);
  background: var(--bg-page);
  color: var(--text-primary);
  overflow-x: hidden;
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background var(--transition), color var(--transition);
}

/* The reset above zeroes every margin; dialogs need auto margins to be
   centred by the browser. */
dialog { margin: auto; }

/* The hidden attribute always hides, even on elements whose class sets a
   display value (e.g. .banner is flex). Scripts toggle el.hidden. */
[hidden] { display: none !important; }

/* ── Keyboard focus ─────────────────────────────────────────── */
/* One visible focus ring for every control. Custom switches hide their
   real checkbox, so the ring goes on the visible track instead. */
:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

.do-toggle input:focus-visible + .do-toggle-slider,
.zda-toggle input:focus-visible + .zda-toggle-slider {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

/* ── Reduced motion ─────────────────────────────────────────── */
/* Stops pulses, blinks, flashes and slides for people who ask their
   system for less motion. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ── Skip link ──────────────────────────────────────────────── */
.skip-link {
  position: absolute;
  left: 12px;
  top: -48px;
  z-index: 2000;
  padding: 8px 14px;
  background: var(--accent);
  color: var(--on-accent);
  border-radius: var(--radius-md);
  font-weight: 600;
  text-decoration: none;
}

.skip-link:focus { top: 8px; }

main:focus { outline: none; }  /* target of the skip link, not a control */

/* ── Overlay (drawer mode) ──────────────────────────────────── */
.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 998;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.sidebar-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

/* ── Sidebar ────────────────────────────────────────────────── */
/* Below 1024px: an off-canvas drawer. From 1024px: pinned, either with
   labels (html[data-nav="full"]) or collapsed to icons ("rail"). */
.sidebar {
  position: fixed;
  left: 0;
  top: 0;
  height: 100vh;
  height: 100dvh;
  width: var(--sidebar-width);
  background: var(--sidebar-gradient);
  transform: translateX(-100%);
  /* Hidden (not just off-screen) while closed, so its links drop out of
     the Tab order; visibility flips only after the slide-out finishes. */
  visibility: hidden;
  transition: transform var(--sidebar-transition), box-shadow var(--sidebar-transition),
    visibility 0s linear 0.26s;
  z-index: 999;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-right: 1px solid var(--sidebar-border);
}

/* Shadow only while open: when closed, its 28px blur bled onto the left
   edge of every page. */
.sidebar.open {
  transform: translateX(0);
  box-shadow: var(--shadow-sidebar);
  visibility: visible;
  transition: transform var(--sidebar-transition), box-shadow var(--sidebar-transition),
    visibility 0s;
}

/* ── Sidebar Header ─────────────────────────────────────────── */
.sidebar-header {
  height: var(--topbar-h);
  min-height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 0 16px;
  border-bottom: 1px solid var(--sidebar-border);
  flex-shrink: 0;
}

.sidebar-brand-mark {
  width: 24px;
  height: 24px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--on-accent);
  font: 700 14px/1 var(--font-head);
}

.sidebar-brand-text {
  font: 600 16px var(--font-head);
  color: #ffffff;
  white-space: nowrap;
}

/* ── Sidebar Scroll Area ─────────────────────────────────────── */
.sidebar-scroll {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 6px 8px 16px;
  scrollbar-width: none;
}

.sidebar-scroll::-webkit-scrollbar { display: none; }

/* ── Section Labels ─────────────────────────────────────────── */
.menu-section-label {
  font: 600 12px var(--font-head);
  color: var(--sidebar-text-muted);
  padding: 12px 8px 4px;
  white-space: nowrap;
  display: block;
}

/* ── Sidebar Menu ───────────────────────────────────────────── */
.sidebar-menu { list-style: none; }

.menu-item {
  position: relative;
  margin-bottom: 1px;
}

.menu-link {
  position: relative;
  display: flex;
  align-items: center;
  padding: 6px 8px;
  color: var(--sidebar-text);
  text-decoration: none;
  border-radius: var(--radius-md);
  transition: background var(--transition), color var(--transition);
  white-space: nowrap;
  gap: 10px;
  min-height: 34px;
}

.menu-link:hover {
  background: var(--sidebar-hover-bg);
  color: var(--sidebar-text-active);
}

/* The open page: amber text and an amber bar at the sidebar's edge */
.menu-link.active {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-text-current);
  font-weight: 600;
}

.menu-link.active::before {
  content: "";
  position: absolute;
  left: -8px;
  top: 6px;
  bottom: 6px;
  width: 3px;
  border-radius: 0 2px 2px 0;
  background: var(--accent);
}

.menu-link:focus-visible {
  outline: 2px solid var(--sidebar-text-current);
  outline-offset: -2px;
}

@media (pointer: coarse) {
  .menu-link { min-height: 42px; }
}

.menu-icon {
  width: 20px;
  height: 20px;
  min-width: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.menu-icon svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.menu-text {
  font-family: var(--font-head);
  font-size: 14px;
  font-weight: 500;
  flex: 1;
}

.menu-link.active .menu-text { font-weight: 600; }

/* ── Main Content ───────────────────────────────────────────── */
.main-content {
  margin-left: 0;
  padding: 0 28px 28px;
  min-height: 100vh;
}

/* ── Top bar ────────────────────────────────────────────────────
   One sticky row: menu button, page title (the page's <h1>), the page's
   live-status slot, then the clock and theme button. Bled to the edges of
   the content area. Below 768px the status slot wraps onto its own line. */
.topbar {
  position: sticky;
  top: 0;
  z-index: 500;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  row-gap: 6px;
  column-gap: 12px;
  min-height: var(--topbar-h);
  padding: 6px 20px 6px 16px;
  margin: 0 -28px 16px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
}

.topbar-title {
  font-family: var(--font-head);
  font-size: 1.2rem;
  font-weight: 600;
  line-height: 1.3;
  color: var(--text-primary);
  white-space: nowrap;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-status {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-left: auto;
  min-width: 0;
}

.topbar-status:empty {
  display: none;
}

.topbar-tools {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.topbar-status:empty + .topbar-tools { margin-left: auto; }

/* ── Top bar buttons and clock ──────────────────────────────── */
.hamburger-btn,
.theme-toggle-btn {
  width: 34px;
  height: 34px;
  flex-shrink: 0;
  background: var(--bg-surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  transition: border-color var(--transition), color var(--transition);
}

.hamburger-btn:hover,
.theme-toggle-btn:hover { border-color: var(--border-strong); color: var(--text-primary); }

@media (pointer: coarse) {
  .hamburger-btn,
  .theme-toggle-btn { width: 40px; height: 40px; }
}

.hamburger-btn {
  flex-direction: column;
  gap: 5px;
}

.hamburger-btn span {
  width: 17px;
  height: 1.5px;
  background: currentColor;
  border-radius: 2px;
  display: block;
  transform-origin: center;
  transition: transform 0.25s ease, opacity 0.25s ease, width 0.25s ease;
}

/* Animate to an X while the drawer is open */
.hamburger-btn.is-open span:nth-child(1) { transform: translateY(6.5px) rotate(45deg); }
.hamburger-btn.is-open span:nth-child(2) { opacity: 0; width: 0; }
.hamburger-btn.is-open span:nth-child(3) { transform: translateY(-6.5px) rotate(-45deg); }

.theme-toggle-btn svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.theme-toggle-btn .icon-sun { display: none; }
[data-theme="dark"] .theme-toggle-btn .icon-sun { display: block; }
[data-theme="dark"] .theme-toggle-btn .icon-moon { display: none; }

.digital-clock {
  color: var(--accent-text);
  padding: 4px 10px;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 600;
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
  background: var(--bg-surface-2);
  border: 1px solid var(--border);
  letter-spacing: 0.04em;
  user-select: none;
  white-space: nowrap;
}

/* ── Desktop: pinned sidebar ────────────────────────────────── */
@media (min-width: 1024px) {
  .sidebar,
  .sidebar.open {
    transform: none;
    visibility: visible;
    box-shadow: none;
    transition: width var(--sidebar-transition);
  }

  .sidebar-overlay { display: none; }

  .main-content {
    margin-left: var(--sidebar-width);
    transition: margin-left var(--sidebar-transition);
  }

  /* Collapsed to icons: labels stay in the DOM for screen readers. */
  [data-nav="rail"] .sidebar { width: var(--sidebar-rail-width); }
  [data-nav="rail"] .main-content { margin-left: var(--sidebar-rail-width); }
  [data-nav="rail"] .sidebar-header { justify-content: center; padding: 0; }
  [data-nav="rail"] .sidebar-brand-text,
  [data-nav="rail"] .menu-text {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }
  [data-nav="rail"] .menu-section-label {
    font-size: 0;
    padding: 0;
    margin: 8px 6px;
    border-top: 1px solid var(--sidebar-border);
  }
  [data-nav="rail"] .sidebar-scroll { padding-left: 6px; padding-right: 6px; }
  [data-nav="rail"] .menu-link { justify-content: center; padding: 8px 0; }
  [data-nav="rail"] .menu-link.active::before { left: -6px; }
}

/* ── Content Section (card) ─────────────────────────────────── */
.content-section {
  background: var(--bg-surface);
  padding: 24px;
  border-radius: var(--radius-lg);
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
}

/* ── Custom Scrollbar ───────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-disabled); }

/* ── Small screens ──────────────────────────────────────────── */
@media (max-width: 767px) {
  .topbar-status {
    order: 3;
    flex-basis: 100%;
    margin-left: 0;
  }

  .topbar-tools { margin-left: auto; }
}

@media (max-width: 600px) {
  .main-content { padding: 0 16px 28px; }

  .topbar {
    padding: 8px 12px;
    margin: 0 -16px 12px;
  }

  .topbar-title { font-size: 1.05rem; }

  .digital-clock {
    font-size: 12.5px;
    padding: 5px 8px;
    letter-spacing: 0.02em;
  }
}
