/* Tokyo Night mission-control theme for the strategy monitor.
   Tokens mirror chart-side constants in app.py — keep the two files in sync. */

:root {
  --page: #1a1b26;
  --surface: #24283b;
  --ink: #c0caf5;
  --ink-2: #a9b1d6;
  --muted: #565f89;
  --grid: #292e42;
  --border: rgba(192, 202, 245, 0.10);
  --good: #9ece6a;
  --warning: #e0af68;
  --critical: #f7768e;
  --accent: #7aa2f7;
  --cyan: #7dcfff;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
  --scrollbar-thumb: var(--surface);
  --scrollbar-thumb-hover: var(--grid);
  --scrollbar-track: var(--page);
  --font-display: "Outfit", sans-serif;
  --font-body: "IBM Plex Sans", sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, monospace;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-x: max(env(safe-area-inset-left, 0px), env(safe-area-inset-right, 0px));
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  min-height: 100vh;
  background: var(--page);
  color: var(--ink-2);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.45;
  position: relative;
  overflow-x: hidden;
}

/* Scrollbars: thin Tokyo Night styling applied globally so the sidebar nav,
   horizontal table/card scrollers, and the page body all match (both
   standard and WebKit scrollbar engines). */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
}

*::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

*::-webkit-scrollbar-track {
  background: var(--scrollbar-track);
}

*::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
}

*::-webkit-scrollbar-thumb:hover {
  background: var(--scrollbar-thumb-hover);
}

*::-webkit-scrollbar-corner {
  background: var(--scrollbar-track);
}

/* Atmosphere: a flat page field under the watermark. The corner glows and
   radar grid it used to carry were all gradients. */
.atmosphere {
  pointer-events: none;
  position: fixed;
  inset: 0;
  z-index: 0;
  background: var(--page);
}

.wrap {
  position: relative;
  z-index: 2;
  max-width: 1680px;
  margin: 0 auto;
  padding: calc(16px + var(--safe-top)) calc(18px + var(--safe-x)) calc(52px + var(--safe-bottom));
}

/* Keyboard users land here first — the sidebar's tab list sits between the top
   of the document and the view, so offer a jump past it. */
.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 60;
  padding: 10px 16px;
  background: var(--accent);
  color: #1a1b26;
  font-family: var(--font-display);
  font-weight: 700;
  text-decoration: none;
}

.skip-link:focus {
  left: 0;
}

/* --- Top bar ----------------------------------------------------------------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px 20px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-top: 1px solid rgba(192, 202, 245, 0.14);
  background: rgba(38, 43, 62, 0.84);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: 0 10px 32px rgba(0, 0, 0, 0.28), inset 0 1px 0 rgba(192, 202, 245, 0.06);
  position: sticky;
  top: 0;
  z-index: 30;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  margin-right: auto;
}

/* The rabbit, sized to the two-line brand block beside it. The art is teal on
   transparent, so it needs no blend mode to sit on the dark bar. */
.brand-mark {
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  display: block;
}

/* Hamburger — only meaningful once the sidebar becomes a drawer, so the
   desktop layout hides it entirely (see the responsive block). */
.nav-toggle {
  display: none;
  appearance: none;
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
}

.nav-toggle:hover {
  border-color: rgba(192, 202, 245, 0.25);
}

.nav-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Three bars drawn from one element: the middle is the box, the outer two are
   its pseudo-elements. */
.nav-toggle-bars,
.nav-toggle-bars::before,
.nav-toggle-bars::after {
  display: block;
  width: 18px;
  height: 2px;
  background: currentColor;
}

.nav-toggle-bars {
  position: relative;
}

.nav-toggle-bars::before,
.nav-toggle-bars::after {
  content: "";
  position: absolute;
  left: 0;
}

.nav-toggle-bars::before {
  top: -6px;
}

.nav-toggle-bars::after {
  top: 6px;
}

/* --- Shell (sidebar + view) --------------------------------------------------- */

.shell {
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.sidebar {
  position: sticky;
  /* Clears the sticky top bar (44px control + padding + the wrap's own inset). */
  top: calc(84px + var(--safe-top));
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 16px 14px;
  border: 1px solid var(--border);
  border-top: 1px solid rgba(192, 202, 245, 0.12);
  background: rgba(36, 40, 59, 0.58);
  max-height: calc(100vh - 104px - var(--safe-top));
  overflow-y: auto;
  overscroll-behavior: contain;
}

.sidebar-block {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sidebar-block .seg.mode {
  width: 100%;
}

.sidebar-block .seg.mode .seg-btn {
  flex: 1;
  padding: 0 10px;
}

.view-main {
  min-width: 0;
}

/* --- Sidebar nav (view tabs) --------------------------------------------------- */

.sidenav {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

.sidenav-eyebrow {
  margin: 0;
  padding: 0 6px;
  /* Sits above a group of tabs, so it needs air from the group before it. The
     first eyebrow in a block has nothing above it — see the reset below. */
  margin-top: 8px;
  color: var(--muted);
  font-family: var(--font-display);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.sidenav-eyebrow:first-child {
  margin-top: 0;
}

.sidenav-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.sidenav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 8px 10px;
  color: var(--ink-2);
  text-decoration: none;
  transition: background 160ms ease, color 160ms ease;
}

.sidenav-item:hover {
  background: rgba(41, 46, 66, 0.75);
  color: var(--ink);
}

.sidenav-item:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.sidenav-item.is-active {
  background: rgba(122, 162, 247, 0.14);
  color: var(--ink);
}

/* The dot carries the same "selected" signal as the tint — color is never the
   only cue, since the label also goes bright and bold. */
.sidenav-dot {
  width: 7px;
  height: 7px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--muted);
  transition: background 160ms ease, box-shadow 160ms ease;
}

.sidenav-item.is-active .sidenav-dot {
  background: var(--accent);
  box-shadow: 0 0 0 3px rgba(122, 162, 247, 0.18);
}

.sidenav-label {
  min-width: 0;
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidenav-item.is-active .sidenav-label {
  font-weight: 700;
}

/* A strategy tab with no live ledger or completed run yet (live book only —
   see build_nav_items/_live_enabled_map) — muted, inert, no hover feedback.
   The tooltip carries the reason; color alone never does. */
.sidenav-item.is-disabled {
  color: var(--muted);
  cursor: default;
}

.sidenav-item.is-disabled:hover {
  background: none;
  color: var(--muted);
}

.sidenav-item.is-disabled .sidenav-dot {
  background: var(--muted);
}

.sidenav-empty {
  margin: 0;
  padding: 0 6px;
  color: var(--muted);
  font-size: 12px;
}

.sidebar-scrim {
  display: none;
}

.brand-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.eyebrow {
  margin: 0;
  color: var(--muted);
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.topbar h1 {
  color: var(--ink);
  font-family: var(--font-display);
  font-size: clamp(1.05rem, 2.5vw, 1.28rem);
  font-weight: 700;
  letter-spacing: -0.03em;
  margin: 0;
  white-space: nowrap;
}

/* --- Sections (account overview + strategy overview) ------------------------- */

.section {
  margin-bottom: 20px;
  padding: 16px 18px 18px;
  border: 1px solid var(--border);
  border-top: 1px solid rgba(192, 202, 245, 0.12);
  background: rgba(36, 40, 59, 0.44);
  position: relative;
  overflow: hidden;
}

.section-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 14px 20px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.section-heading {
  min-width: 0;
}

.section-eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.section-title {
  margin: 0;
  color: var(--ink);
  font-family: var(--font-display);
  font-size: clamp(1.25rem, 2.6vw, 1.6rem);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.1;
}

.section-body {
  min-width: 0;
}

.refreshed {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--good);
  box-shadow: 0 0 0 0 rgba(158, 206, 106, 0.55);
  animation: pulse-live 2.2s ease-out infinite;
  flex-shrink: 0;
}

@keyframes pulse-live {
  0% {
    box-shadow: 0 0 0 0 rgba(158, 206, 106, 0.55);
  }
  70% {
    box-shadow: 0 0 0 8px rgba(158, 206, 106, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(158, 206, 106, 0);
  }
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

/* Segmented mode control — safety-critical colors when selected. */
.seg {
  display: inline-flex;
  /* Never shrink: as a column flex item on mobile, the overflow:hidden below
     drops this control's automatic minimum size to 0, so it would otherwise
     collapse under its 44px buttons and clip the PAPER/LIVE labels. */
  flex-shrink: 0;
  border: 1px solid var(--border);
  /* Clips the active button's square background to the rounded corners. */
  overflow: hidden;
  background: var(--surface);
}

.seg-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--ink-2);
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-decoration: none;
  padding: 0 16px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  user-select: none;
  transition: background 160ms ease, color 160ms ease, box-shadow 160ms ease;
}

.seg-btn + .seg-btn {
  border-left: 1px solid var(--border);
}

.seg-btn:hover {
  color: var(--ink);
  background: rgba(41, 46, 66, 0.85);
}

.seg-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  z-index: 1;
}

.seg.mode .opt-paper.is-active {
  background: var(--warning);
  color: #1a1b26;
  font-weight: 700;
  box-shadow: inset 0 0 0 1px rgba(26, 27, 38, 0.08);
}

.seg.mode .opt-live.is-active {
  background: var(--critical);
  color: #1a1b26;
  font-weight: 700;
  box-shadow: inset 0 0 0 1px rgba(26, 27, 38, 0.08);
}

/* Chart metric toggle (NAV ⇄ PnL) — a benign view switch, so it uses the accent
   rather than the mode toggle's safety colors, and sits tighter in the panel head. */
.seg.metric .seg-btn {
  min-height: 32px;
  padding: 0 14px;
  font-size: 12px;
}

.seg.metric .seg-btn.is-active {
  background: var(--accent);
  color: #1a1b26;
  font-weight: 700;
  box-shadow: inset 0 0 0 1px rgba(26, 27, 38, 0.08);
}

/* --- Strategy hero strip ----------------------------------------------------- */

.strategy-hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px 20px;
  flex-wrap: wrap;
  margin-bottom: 14px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-top: 1px solid rgba(192, 202, 245, 0.14);
  background: rgba(39, 44, 63, 0.86);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  position: relative;
  overflow: hidden;
}

.strategy-hero-main {
  min-width: 0;
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  gap: 12px 18px;
  flex-wrap: wrap;
}

.strategy-name {
  margin: 0;
  color: var(--ink);
  font-family: var(--font-display);
  font-size: clamp(1.15rem, 2.6vw, 1.5rem);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.1;
  white-space: nowrap;
}

.hero-status {
  display: flex;
  align-items: center;
  gap: 10px 14px;
  flex-wrap: wrap;
}

.hero-meta {
  color: var(--muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.hero-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border: 1px solid var(--border);
  background: rgba(26, 27, 38, 0.45);
  color: var(--ink-2);
  font-size: 12px;
}

.hero-chip--muted {
  color: var(--muted);
}

.mode-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  padding: 0 12px;
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.mode-pill--paper {
  background: rgba(224, 175, 104, 0.18);
  color: var(--warning);
  border: 1px solid rgba(224, 175, 104, 0.35);
}

.mode-pill--live {
  background: rgba(247, 118, 142, 0.16);
  color: var(--critical);
  border: 1px solid rgba(247, 118, 142, 0.35);
}

/* --- Alerts ------------------------------------------------------------------ */

/* Severity reads from the border tint and background wash, both applied evenly
   on all four sides — there is no left accent bar anywhere in this theme. */
.banner {
  border: 1px solid rgba(224, 175, 104, 0.38);
  background: rgba(224, 175, 104, 0.07);
  padding: 12px 14px;
  margin-bottom: 14px;
  color: var(--ink);
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.18);
}

.banner.critical {
  border-color: rgba(247, 118, 142, 0.45);
  background: rgba(247, 118, 142, 0.10);
}

/* --- Account overview (top section) ----------------------------------------- */

.account-overview {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Wallet hero — the Portfolio overview's equity card, standalone above the
   bento (chart + KPI tiles), mirroring the strategy view's name+status hero
   above its bento. */
.wallet {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  padding: 18px 20px;
  margin-bottom: 14px;
  border: 1px solid var(--border);
  border-top: 1px solid rgba(192, 202, 245, 0.12);
  background: rgba(36, 40, 59, 0.92);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
}

.wallet-sub {
  color: var(--muted);
  font-size: 12px;
}

.account-tables {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 14px;
  align-items: start;
}

.account-table {
  min-width: 0;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-top: 1px solid rgba(192, 202, 245, 0.12);
  background: rgba(36, 40, 59, 0.90);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.account-overview > .note {
  color: var(--muted);
}

/* --- Bento grid (strategy section) ------------------------------------------ */

.bento {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr);
  grid-auto-rows: auto;
  gap: 14px;
  align-items: stretch;
}

/* The portfolio view is the one place a .section-body trails the bento as a
   sibling (breakdown + pooled tables); match the grid's own 14px rhythm. */
.section--account .bento {
  margin-bottom: 14px;
}

/* Chart + KPIs share the first row; every other panel is a full-width band.
   Rows are auto-placed by source order, so an optional band (upcoming
   earnings, only for the earnings strategy) drops in without renumbering. */
.bento-chart {
  grid-column: 1;
  min-height: 0;
}

.bento-kpis {
  grid-column: 2;
  min-width: 0;
}

.bento-pnl,
.bento-upcoming,
.bento-journal {
  grid-column: 1 / -1;
}

.bento-strategy {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  min-width: 0;
}

/* --- KPI mosaic -------------------------------------------------------------- */

.tiles,
.kpi-mosaic {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 0;
  height: 100%;
}

.kpi-mosaic .tile--nav,
.kpi-mosaic .tile--status {
  grid-column: 1 / -1;
}

.tile {
  position: relative;
  background: rgba(39, 44, 63, 0.82);
  border: 1px solid var(--border);
  border-top: 1px solid rgba(192, 202, 245, 0.12);
  padding: 12px 14px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
  overflow: hidden;
  transition: transform 180ms ease, box-shadow 180ms ease, border-color 180ms ease;
  min-height: 88px;
}

/* Sign-tinted values anywhere (``toned_value`` spans in app.py — cash, PnL,
   deltas): green ≥ 0, red < 0. One generic rule so a new signed field needs
   no new selector. Scoped to spans: tile roots also carry data-tone, which no
   longer paints anything of its own. */
span[data-tone="good"] {
  color: var(--good);
}

span[data-tone="bad"] {
  color: var(--critical);
}

.tile:hover {
  transform: translateY(-2px);
  border-color: rgba(122, 162, 247, 0.22);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.28);
}

.tile .label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-bottom: 6px;
}

.tile .value {
  color: var(--ink);
  font-family: var(--font-display);
  font-size: clamp(1.2rem, 2.1vw, 1.5rem);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  min-height: 1.2em;
}

.tile--nav .value {
  font-size: clamp(1.45rem, 2.6vw, 1.85rem);
}

.tile .sub {
  color: var(--muted);
  font-size: 12px;
  margin-top: 6px;
}

.tile .delta-up {
  color: var(--good);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  margin-top: 6px;
}

.tile .delta-down {
  color: var(--critical);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  margin-top: 6px;
}

/* --- Panels ------------------------------------------------------------------ */

.panel {
  background: rgba(36, 40, 59, 0.90);
  border: 1px solid var(--border);
  border-top: 1px solid rgba(192, 202, 245, 0.12);
  padding: 14px 16px;
  min-width: 0;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

/* Tables need horizontal scroll; the chart panel must not clip its canvas. */
.panel:not(.panel-chart) {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.panel:hover {
  border-color: rgba(192, 202, 245, 0.16);
}

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

.panel-head h2 {
  margin: 0;
}

.panel-tag {
  color: var(--muted);
  font-family: var(--font-display);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  padding: 3px 8px;
  border: 1px solid var(--border);
  background: rgba(26, 27, 38, 0.35);
}

.panel h2,
.panel .subhead {
  color: var(--ink);
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
  margin: 0 0 12px;
}

.panel .subhead {
  margin-top: 16px;
}

.panel .note {
  color: var(--muted);
  padding: 8px 0;
  font-size: 13px;
}

.panel-chart {
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: visible;
  overflow-x: visible;
  background: rgba(36, 40, 59, 0.92);
  box-shadow:
    0 10px 32px rgba(0, 0, 0, 0.24),
    inset 0 1px 0 rgba(192, 202, 245, 0.08);
}

.nav-chart-wrap {
  position: relative;
  width: 100%;
  flex: 1 1 auto;
  min-height: 340px;
  height: clamp(340px, 42vh, 480px);
}

.nav-chart-wrap canvas,
.nav-chart {
  width: 100% !important;
  height: 100% !important;
  display: block;
}

.nav-chart-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 14px;
  pointer-events: none;
}

.nav-chart-empty[hidden] {
  display: none;
}

/* The Signals panel's allocation doughnut — a smaller, fixed-height hollow
   than the line charts so it sits as a visual anchor above the signals table. */
.allocation-chart-wrap {
  min-height: 220px;
  height: 240px;
  flex: 0 0 auto;
}

#allocation-caption {
  padding: 6px 0 2px;
  font-size: 12px;
}

/* Wallet card (the account section's equity hero) */
.wallet-label {
  color: var(--muted);
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.wallet-equity {
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: clamp(1.7rem, 3.2vw, 2.35rem);
  font-weight: 500;
  letter-spacing: -0.03em;
  line-height: 1.1;
  text-shadow: 0 0 28px rgba(122, 162, 247, 0.18);
}

.account-overview--unavailable .note {
  margin: 0;
}

/* Strategy stack */
.panel-strategy-primary,
.panel-strategy-secondary {
  min-height: 0;
}

.panel-journal {
  padding-bottom: 10px;
}

.journal {
  max-height: min(420px, 48vh);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

/* --- Strategy PnL (live) ----------------------------------------------------- */

.panel-pnl {
  background: rgba(36, 40, 59, 0.90);
}

.pnl-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.pnl-stat {
  padding: 12px 14px;
  border: 1px solid var(--border);
  background: rgba(39, 44, 63, 0.74);
}

.pnl-stat-label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-bottom: 6px;
}

.pnl-stat-value {
  color: var(--ink);
  font-family: var(--font-display);
  font-size: clamp(1.15rem, 2vw, 1.4rem);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.pnl-stat-sub {
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  margin-top: 6px;
}

/* Tone accents shared by the PnL summary (delta, unrealized). */
/* The stat *sub* lines are divs, so the generic span[data-tone] rule above
   doesn't reach them. */
.pnl-stat-sub[data-tone="good"] {
  color: var(--good);
}

.pnl-stat-sub[data-tone="bad"] {
  color: var(--critical);
}

/* Row tint by unrealized-PnL sign — subtle; the signed value still carries the
   meaning, so color is never the only signal. Hover deepens the same hue. The
   same green marks in-market rows in the Signals table (the "Signal" cell still
   carries the state in words). */
.tbl tr.pnl-up td,
.tbl tr.in-market td {
  background: rgba(158, 206, 106, 0.09);
}

.tbl tr.pnl-down td {
  background: rgba(247, 118, 142, 0.09);
}

.tbl tr.pnl-up:hover td,
.tbl tr.in-market:hover td {
  background: rgba(158, 206, 106, 0.16);
  color: var(--ink);
}

.tbl tr.pnl-down:hover td {
  background: rgba(247, 118, 142, 0.16);
  color: var(--ink);
}

/* Tables */
.tbl {
  width: 100%;
  border-collapse: collapse;
  min-width: 420px;
}

.tbl th {
  text-align: left;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 8px 12px 8px 0;
  border-bottom: 1px solid var(--grid);
  white-space: nowrap;
}

.tbl td {
  padding: 8px 12px 8px 0;
  border-bottom: 1px solid var(--grid);
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
  /* Compact tabular data reads better on one line — dates and short labels
     shouldn't wrap mid-value; the panel scrolls horizontally when narrow. */
  white-space: nowrap;
}

/* The trailing column carries the free text (positions "Leg", journal
   "Detail"): let it wrap so a long note doesn't force endless side-scroll. */
.tbl td:last-child {
  white-space: normal;
}

.tbl tr:last-child td {
  border-bottom: none;
}

.tbl tbody tr {
  transition: background 120ms ease;
}

.tbl tbody tr:hover td {
  background: rgba(122, 162, 247, 0.06);
  color: var(--ink);
}

.tbl th.num,
.tbl td.num {
  text-align: right;
  font-family: var(--font-mono);
  font-size: 12.5px;
}

.tbl--journal {
  min-width: 640px;
}

.tbl--journal th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: rgba(36, 40, 59, 0.96);
  backdrop-filter: blur(8px);
}

.tbl--journal td:first-child {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--muted);
}

/* Earnings-book rows due to exit: tinted; panel note carries the meaning. */
.tbl tr.due td {
  background: rgba(224, 175, 104, 0.12);
  color: var(--ink);
}

/* Status = dot + word, never color alone. */
.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.status .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
  box-shadow: 0 0 0 2px rgba(26, 27, 38, 0.35);
}

/* HTMX request indicator (subtle). */
.htmx-request .tiles,
.htmx-request .panel,
.htmx-request .hero {
  opacity: 0.92;
  transition: opacity 120ms ease;
}

/* Legacy equal-col classes kept harmless if any fragment still emits them. */
.cols,
.cols-2 {
  display: contents;
}

/* --- Reduced motion ---------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  .tile:hover {
    transform: none;
  }

  .live-dot {
    animation: none;
  }

  .sidebar {
    transition: none;
  }
}

/* --- Responsive -------------------------------------------------------------- */

@media (max-width: 1400px) {
  .wrap {
    max-width: 100%;
  }

  .bento {
    grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr);
  }
}

/* Below this the sidebar leaves the flow and becomes an off-canvas drawer.
   Keep in sync with isDrawerWidth() in dashboard.js. */
@media (max-width: 1000px) {
  .shell {
    display: block;
  }

  .nav-toggle {
    display: inline-flex;
  }

  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 50;
    width: min(84vw, 288px);
    max-height: none;
    padding: calc(18px + var(--safe-top)) 14px calc(18px + var(--safe-bottom));
    border-left: 0;
    background: rgba(39, 44, 63, 0.98);
    box-shadow: var(--shadow);
    transform: translateX(-102%);
    visibility: hidden;
    transition: transform 220ms ease, visibility 220ms ease;
  }

  .sidebar.is-open {
    transform: translateX(0);
    visibility: visible;
  }

  .sidebar-scrim {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 40;
    background: rgba(13, 14, 21, 0.62);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
  }

  .sidebar-scrim[hidden] {
    display: none;
  }

  /* The drawer scrolls its own list; the view behind it must not move. */
  body.nav-open {
    overflow: hidden;
  }
}

@media (max-width: 900px) {
  .topbar {
    position: static;
  }

  .section-head {
    align-items: stretch;
  }

  .bento {
    display: flex;
    flex-direction: column;
  }

  .bento-chart,
  .bento-kpis,
  .bento-pnl,
  .bento-strategy,
  .bento-upcoming,
  .bento-journal {
    grid-column: auto;
    grid-row: auto;
  }

  .bento-strategy {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .tiles,
  .kpi-mosaic {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .nav-chart-wrap {
    min-height: 300px;
    height: clamp(280px, 38vh, 400px);
  }

  /* Keep the donut smaller than the line charts on small screens — without
     this override the .nav-chart-wrap clamp above would win (equal
     specificity, later source order) and the doughnut would balloon to
     match the line charts, defeating its fixed-height anchor intent. */
  .allocation-chart-wrap {
    min-height: 200px;
    height: 240px;
  }

  .strategy-hero {
    align-items: flex-start;
  }
}

@media (max-width: 640px) {
  .wrap {
    padding-left: calc(12px + var(--safe-x));
    padding-right: calc(12px + var(--safe-x));
  }

  .topbar {
    padding: 10px 12px;
    gap: 10px;
  }

  .section {
    padding: 14px 12px 16px;
  }

  .section-head {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

  .seg {
    width: 100%;
  }

  .seg.mode {
    align-self: stretch;
  }

  /* The metric toggle stays compact in the chart's panel head — it's not a
     full-width section control like the Paper/Live toggle. */
  .seg.metric {
    width: auto;
  }

  .seg-btn {
    flex: 1;
  }

  .bento-strategy {
    display: flex;
    flex-direction: column;
  }

  .tiles,
  .kpi-mosaic {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .tile .value {
    font-size: 1.15rem;
  }

  .tile--nav .value {
    font-size: 1.35rem;
  }

  .refreshed {
    justify-content: flex-end;
  }

  .tbl {
    min-width: 360px;
  }

  .tbl--journal {
    min-width: 520px;
  }

  .strategy-hero {
    padding: 14px;
  }

  .wallet-equity {
    font-size: 1.7rem;
  }

  /* Let the journal flow with the page instead of trapping touch scroll in a
     ~320px inner region nested inside page scroll. The panel keeps the wide
     table's horizontal scroll; a static header avoids sticky-in-page jitter. */
  .journal {
    max-height: none;
    overflow: visible;
  }

  .tbl--journal th {
    position: static;
  }
}

/* --- Symbol detail (clickable tickers + modal chart) ------------------------ */

/* Ticker cells double as click targets for the detail chart. Styled as the
   plain mono ticker with a dotted underline so tables stay quiet but the
   affordance is discoverable. */
.sym-link,
.match-link {
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  color: inherit;
  cursor: pointer;
  text-decoration: underline dotted var(--muted);
  text-underline-offset: 3px;
}

.sym-link:hover,
.sym-link:focus-visible,
.match-link:hover,
.match-link:focus-visible {
  color: var(--accent);
  text-decoration-color: var(--accent);
}

.sym-link:focus-visible,
.match-link:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Panel titles that open a chart (e.g. Signals → cross-sectional momentum)
   share the sym-link affordance: dotted underline, accent on hover. */
.title-link {
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  color: inherit;
  cursor: pointer;
  text-decoration: underline dotted var(--muted);
  text-underline-offset: 4px;
}

.title-link:hover,
.title-link:focus-visible {
  color: var(--accent);
  text-decoration-color: var(--accent);
}

.title-link:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Strategy breakdown roster rows (Portfolio overview) link to that
   strategy's tab — the same dotted-underline affordance as sym-link/
   title-link, but a real <a> rather than a <button>. */
.row-link {
  color: inherit;
  text-decoration: underline dotted var(--muted);
  text-underline-offset: 3px;
}

.row-link:hover,
.row-link:focus-visible {
  color: var(--accent);
  text-decoration-color: var(--accent);
}

.row-link:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.symbol-modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 24px;
}

.symbol-modal[hidden] {
  display: none;
}

/* No backdrop-filter here on purpose — the page's fixed blur/blend layers are
   already at the edge of what the automated Browser pane tolerates. */
.symbol-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(13, 14, 22, 0.72);
}

.symbol-modal-card {
  position: relative;
  width: min(920px, 100%);
  box-shadow: var(--shadow);
}

.symbol-modal-close {
  background: none;
  border: 1px solid var(--border);
  color: var(--ink-2);
  font: inherit;
  line-height: 1;
  padding: 6px 10px;
  cursor: pointer;
}

.symbol-modal-close:hover,
.symbol-modal-close:focus-visible {
  color: var(--ink);
  border-color: var(--accent);
}

.symbol-modal-chart {
  height: clamp(280px, 46vh, 420px);
}

#symbol-modal-note {
  margin-top: 10px;
}

/* Match detail modal (tennis_reversion) — reuses .symbol-modal/-card/-close
   wholesale (see index.html) and only adds a scrollable body, since its
   content is a stack of server-rendered detail tables, not one chart. */
.match-modal-card {
  width: min(960px, 100%);
}

.match-modal-body {
  max-height: 68vh;
  overflow-y: auto;
  margin-top: 4px;
}

.match-modal-body h3 {
  margin: 16px 0 6px;
  font-size: 0.95rem;
  color: var(--ink-2);
}

.match-modal-body h3:first-child {
  margin-top: 0;
}

/* --- Strategy doc pages (offline-generated, the ?view=docs full page) -------- */
/* The hero's "Strategy details" link — a .hero-chip that's also a plain
   clickable link (a full-page navigation, not htmx — see
   partials/strategy.html), so it needs its own hover/focus state (.hero-chip
   alone is static). */
.hero-doc-link {
  color: var(--accent);
  text-decoration: none;
  cursor: pointer;
}

.hero-doc-link:hover,
.hero-doc-link:focus-visible {
  border-color: var(--accent);
  color: var(--ink);
}

.docs-toolbar {
  margin-bottom: 14px;
}

.doc-back-link {
  display: inline-block;
  color: var(--ink-2);
  text-decoration: none;
  font-size: 13px;
}

.doc-back-link:hover,
.doc-back-link:focus-visible {
  color: var(--accent);
}

/* .section (the base class every "section section--X" wrapper carries —
   see partials/strategy.html/portfolio.html for the others) sets
   `overflow: hidden` for its decorative corner treatment. A sticky-positioned
   descendant resolves against the nearest ancestor that establishes a scroll
   container — which ANY overflow value other than `visible` does, even
   `hidden`, whether or not that ancestor ever actually scrolls — so
   .section--docs's inherited `overflow: hidden` silently made .doc-toc
   "sticky" only relative to a box that never scrolls (itself, moving with
   the page) instead of relative to the real scrolling element (<body> —
   see .doc-toc below). The computed `position` still read "sticky", so this
   was easy to miss without actually scrolling the rendered page: the rail
   just sat in place like `position: static`, never visually pinning. This
   override is what makes it actually stick. */
.section--docs {
  overflow: visible;
}

/* .strategy-doc (see strategies/report.py's assemble()) is exactly two
   children in document order: the baked-in TOC nav (.doc-toc), then the
   content wrapper (.doc-page) carrying every section. flex + `order` lays
   the TOC out as a sticky rail on the right without caring which one comes
   first in the markup; `flex-wrap` isn't used here — the breakpoint below
   switches to a single column explicitly, so the TOC's sticky positioning
   never has to fight a wrap-driven reflow. */
.strategy-doc {
  display: flex;
  align-items: flex-start;
  gap: 24px;
}

.doc-page {
  order: 1;
  flex: 1 1 480px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* Sticky for real: pinned in the viewport (clearing the sticky top bar, the
   same offset formula .sidebar itself uses) so a reader scrolled deep into a
   long report can still jump sections without scrolling back up. Its own
   max-height + overflow-y keeps a long TOC (dozens of headings on these
   reports) scrolling independently of the page once it outgrows the
   viewport, rather than pushing content around or running off-screen. */
.doc-toc {
  order: 2;
  flex: 0 0 220px;
  position: sticky;
  top: calc(84px + var(--safe-top));
  max-height: calc(100vh - 104px - var(--safe-top));
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-top: 1px solid rgba(192, 202, 245, 0.12);
  background: rgba(36, 40, 59, 0.58);
}

.doc-toc-title {
  margin: 0 0 10px;
  color: var(--muted);
  font-family: var(--font-display);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.doc-toc-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.doc-toc-item a {
  display: block;
  padding: 5px 8px;
  color: var(--ink-2);
  font-size: 12.5px;
  line-height: 1.35;
  text-decoration: none;
  border-left: 2px solid transparent;
}

.doc-toc-item a:hover,
.doc-toc-item a:focus-visible {
  color: var(--ink);
  background: rgba(122, 162, 247, 0.10);
  border-left-color: var(--accent);
}

.doc-toc-item--h3 a {
  padding-left: 18px;
}

.doc-toc-item--h4 a {
  padding-left: 28px;
  font-size: 12px;
  color: var(--muted);
}

@media (max-width: 900px) {
  .strategy-doc {
    flex-direction: column;
  }

  .doc-toc {
    order: 2; /* still after the content — collapses below it, not above */
    flex-basis: auto;
    position: static;
    max-height: none;
  }
}

/* Full width of the content column — no reading-column cap. A generated
   page's prose can run long (this is an evidence page, not a blog post), and
   the doc-toc rail beside it already keeps line length in check on anything
   wider than a phone. */
.doc-prose {
  color: var(--ink-2);
  margin: 18px 0 10px;
}

.doc-prose h2,
.doc-prose h3,
.doc-prose h4,
.doc-prose h5 {
  color: var(--ink);
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0 0 10px;
}

.doc-prose h2 {
  font-size: clamp(1.15rem, 2.4vw, 1.4rem);
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.doc-prose h3 {
  font-size: 1.05rem;
  margin-top: 8px;
}

.doc-prose h4 {
  font-size: 0.95rem;
}

.doc-prose h5 {
  font-size: 0.85rem;
  color: var(--ink-2);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.doc-prose p {
  margin: 0 0 12px;
  line-height: 1.6;
}

.doc-prose ul {
  margin: 0 0 12px;
  padding-left: 20px;
  line-height: 1.6;
}

.doc-prose li {
  margin-bottom: 6px;
}

.doc-prose code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  background: rgba(122, 162, 247, 0.12);
  color: var(--cyan);
  padding: 1px 5px;
}

/* Figures and tables reuse .panel for the card treatment; these just add the
   generated page's vertical rhythm between them. fig.to_html's own output
   (see strategies/report.py's fig_html) sizes the plotly-graph-div itself —
   nothing extra needed here for the figure's render target. */
.doc-figure,
.doc-table-wrap {
  margin: 0 0 18px;
  overflow-x: auto;
}

.doc-table-title {
  margin: 0 0 10px;
  color: var(--ink);
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 600;
}

.doc-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 420px;
}

.doc-table th {
  text-align: left;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 8px 12px 8px 0;
  border-bottom: 1px solid var(--grid);
  white-space: nowrap;
}

.doc-table td {
  padding: 8px 12px 8px 0;
  border-bottom: 1px solid var(--grid);
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.doc-table tr:last-child td {
  border-bottom: none;
}

.doc-table tbody tr:hover td {
  background: rgba(122, 162, 247, 0.06);
  color: var(--ink);
}

@media (max-width: 640px) {
  .doc-prose {
    margin-top: 12px;
  }

  .doc-table {
    min-width: 0;
  }
}

/* Tennis's Live/Completed matches are wide tables — the strategy view stacks
   them full-width (see partials/strategy.html's stack_panels) instead of the
   two-column split the equity strategies' narrower panels use. Placed last so
   it outranks the equal-specificity responsive rules above at every width. */
.bento-strategy--stacked {
  display: grid;
  grid-template-columns: 1fr;
}

/* --- Tennis match modal: odds chart + position strip ------------------------- */

.match-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.match-chip {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(36, 40, 59, 0.6);
  font-size: 0.82rem;
  color: var(--muted);
}

.match-chip--good {
  color: var(--up);
  border-color: rgba(158, 206, 106, 0.35);
}

.match-chip--bad {
  color: var(--down);
  border-color: rgba(247, 118, 142, 0.35);
}

.match-chart-wrap {
  min-height: 280px;
  height: clamp(260px, 40vh, 380px);
}
