/* The design system every page loads (moved out of base.html so a browser caches it once,
   instead of receiving it inside every page). Tokens defined here are read by
   scripts/design_audit.py. */
/* =====================================================================
   DESIGN SYSTEM — IBKR-grammar, refined typography
   ===================================================================== */
:root {
  /* Surfaces */
  --bg:           #FFFFFF;
  --bg-tint:      #FAFAF9;
  --bg-row:       #F7F7F6;
  --bg-row-hover: #F1F2F4;

  /* Ink */
  --ink:          #0F172A;
  --ink-2:        #1F2937;
  --ink-mute:     #4B5563;
  --ink-faint:    #6B7280;
  --ink-ghost:    #9CA3AF;
  --ink-thin:     #D1D5DB;

  /* Rules */
  --rule:         #E5E7EB;
  --rule-faint:   #F1F2F4;

  /* Chrome */
  --navy:         #0F2A4A;
  --navy-deep:    #081B33;

  /* P&L */
  --gain:         #15803D;
  --gain-deep:    #14532D;
  --gain-bg:      rgba(21, 128, 61, 0.08);
  --loss:         #DC2626;
  --loss-deep:    #991B1B;
  --loss-bg:      rgba(220, 38, 38, 0.08);

  /* Accent (refined banker blue, used sparingly for links/active) */
  --link:         #1D4ED8;
}

/* =====================================================================
   Reset + base
   ===================================================================== */
*, *::before, *::after { box-sizing: border-box; }
html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Newsreader', Georgia, serif;
  font-weight: 380;
  font-size: 17px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
body { min-height: 100vh; }
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }

/* =====================================================================
   Type primitives — usable from any page
   ===================================================================== */
.num {
  font-family: 'Fraunces', serif;
  font-variation-settings: "opsz" 60, "SOFT" 0, "WONK" 0;
  font-feature-settings: "tnum", "lnum";
  font-weight: 420;
  letter-spacing: -0.005em;
}
.mono {
  font-family: 'Recursive', ui-monospace, monospace;
  font-variation-settings: "MONO" 1;
  letter-spacing: 0;
}
.label {
  font-family: 'Newsreader', serif;
  font-style: italic;
  font-size: 0.78rem;
  color: var(--ink-faint);
  font-weight: 460;
  letter-spacing: 0.02em;
}

.gain { color: var(--gain) !important; }
.loss { color: var(--loss) !important; }
.muted { color: var(--ink-mute) !important; }
.dim { color: var(--ink-thin) !important; }
.faint { color: var(--ink-faint) !important; }

/* =====================================================================
   TOP CHROME — sticky dark navy bar
   ===================================================================== */
header.chrome {
  background: var(--navy);
  color: #fff;
  border-bottom: 3px solid var(--navy-deep);
  position: sticky;
  top: 0;
  z-index: 50;
}
/* On IB pages the light sub-tier provides the chrome's bottom edge, so drop
   the navy accent border (else it double-lines under the light tab bar). */
header.chrome.has-subnav { border-bottom: none; }
.chrome-inner {
  max-width: 1800px;
  margin: 0 auto;
  padding: 14px 44px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 36px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
}
.brand:hover { text-decoration: none; }
.brand .mark {
  width: 34px;
  height: 34px;
  color: #fff;
  flex-shrink: 0;
  display: block;
}
.glyph {
  font-family: 'Tiro Devanagari Hindi', serif;
  font-size: 28px;
  color: #fff;
  line-height: 1;
}
.wordmark {
  font-family: 'Fraunces', serif;
  font-variation-settings: "opsz" 48, "SOFT" 50;
  font-weight: 380;
  font-size: 22px;
  letter-spacing: 0.005em;
  color: #fff;
}
nav.primary {
  display: flex;
  gap: 28px;
  justify-content: center;
}
nav.primary a {
  font-family: 'Newsreader', serif;
  font-size: 0.95rem;
  color: rgba(255, 255, 255, 0.78);
  text-decoration: none;
  padding: 6px 0;
  border-bottom: 2px solid transparent;
  transition: color 0.18s, border-color 0.18s;
}
nav.primary a:hover { color: #fff; text-decoration: none; }
nav.primary a.active {
  color: #fff;
  border-bottom-color: #fff;
}

.user-block {
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 0.82rem;
  color: rgba(255, 255, 255, 0.78);
}
.user-block .email { font-weight: 460; color: #fff; }
.role-pill {
  font-family: 'Newsreader', serif;
  font-style: italic;
  font-size: 0.74rem;
  padding: 3px 9px;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 2px;
  letter-spacing: 0.04em;
  color: rgba(255, 255, 255, 0.92);
}
.signout {
  color: rgba(255, 255, 255, 0.6);
  text-decoration: none;
  font-style: italic;
  font-size: 0.82rem;
  transition: color 0.18s;
}
.signout:hover { color: #fff; text-decoration: none; }

/* freshness chip + popover */
details.freshness {
  position: relative;
  display: inline-block;
}
details.freshness > summary {
  list-style: none;
  cursor: pointer;
  padding: 4px 10px;
  background: rgba(255, 255, 255, 0.10);
  border-radius: 2px;
  font-size: 0.78rem;
  color: rgba(255, 255, 255, 0.92);
  letter-spacing: 0.02em;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  user-select: none;
  transition: background 0.18s;
}
details.freshness > summary::-webkit-details-marker { display: none; }
details.freshness > summary:hover { background: rgba(255, 255, 255, 0.18); }
details.freshness > summary .dot {
  display: inline-block;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: #4ade80;       /* green for healthy */
}
details.freshness.stale > summary .dot { background: #fbbf24; }     /* amber */
details.freshness.broken > summary .dot { background: #f87171; }    /* red */
details.freshness.unknown > summary .dot { background: #94a3b8; }   /* grey for "no state yet" */

details.freshness > .popover {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 320px;
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--rule);
  box-shadow: 0 8px 32px rgba(15, 23, 42, 0.18);
  padding: 18px 20px;
  border-radius: 2px;
  z-index: 60;
}
details.freshness > .popover .pop-head {
  display: flex; justify-content: space-between; align-items: baseline;
  padding-bottom: 10px; margin-bottom: 12px;
  border-bottom: 1px solid var(--rule);
}
details.freshness > .popover .pop-head .lbl {
  font-family: 'Newsreader', serif; font-style: italic; font-size: 0.88rem;
  color: var(--ink-mute);
}
details.freshness > .popover .pop-head .ts {
  font-family: 'Recursive', monospace;
  font-variation-settings: "MONO" 1;
  font-size: 0.78rem;
  color: var(--ink-faint);
}
details.freshness > .popover ul {
  list-style: none; padding: 0; margin: 0;
}
details.freshness > .popover li {
  display: grid; grid-template-columns: 1fr auto;
  gap: 12px; padding: 8px 0;
  font-size: 0.86rem;
  border-bottom: 1px solid var(--rule-faint);
}
details.freshness > .popover li:last-child { border-bottom: none; }
details.freshness > .popover li .src-name {
  font-family: 'Newsreader', serif;
  color: var(--ink);
}
details.freshness > .popover li .src-detail {
  display: block;
  font-size: 0.74rem;
  color: var(--ink-faint);
  font-style: italic;
  margin-top: 1px;
}
details.freshness > .popover li .src-status {
  font-family: 'Recursive', monospace;
  font-variation-settings: "MONO" 1;
  font-size: 0.78rem;
  text-align: right;
}
details.freshness > .popover li .src-status.ok    { color: var(--gain); }
details.freshness > .popover li .src-status.fail  { color: var(--loss); }
details.freshness > .popover li .src-status.transient { color: #b45309; }
details.freshness > .popover li .src-status.absent { color: var(--ink-faint); }

details.freshness > .popover .pop-actions {
  margin-top: 12px; padding-top: 12px;
  border-top: 1px solid var(--rule);
  display: flex; justify-content: flex-end;
}
details.freshness > .popover .pop-actions button {
  font-family: 'Newsreader', serif;
  font-size: 0.88rem;
  font-weight: 480;
  padding: 7px 18px;
  background: var(--navy);
  color: #fff;
  border: none;
  border-radius: 2px;
  cursor: pointer;
  transition: background 0.18s;
}
details.freshness > .popover .pop-actions button:hover {
  background: var(--navy-deep);
}
details.freshness > .popover .pop-actions button[disabled] {
  background: var(--ink-thin);
  cursor: not-allowed;
}

/* =====================================================================
   PAGE container
   ===================================================================== */
main.page {
  max-width: 1800px;
  margin: 0 auto;
  padding: 22px 44px 80px;
}

/* Offline-mode banner — a calm slate notice (not an error). Slim, full
   width, sits above the page content. */
.offline-banner {
  display: flex; align-items: center; gap: 9px;
  margin: 0 0 22px; padding: 9px 16px;
  border: 1px solid var(--rule); border-left: 3px solid #64748b;
  border-radius: 3px; background: #f1f5f9;
  font-family: 'Newsreader', serif; font-size: 0.9rem; color: #334155;
}
.offline-banner strong { font-style: normal; color: #1e293b; }
.offline-dot {
  width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0;
  background: #64748b;
}
/* Offline: hide every LLM/order generation control so nothing 503s on click.
   Covers brief "Generate" forms, the analyzer "run fresh" button, and its
   stale-banner CTA. New generate forms get hidden for free if they POST to
   a *…/generate endpoint. */
body[data-offline] form[action$="/generate"],
body[data-offline] #run-fresh-btn,
body[data-offline] .stale-banner-cta { display: none !important; }

.page-head {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: end;
  gap: 28px;
  padding-bottom: 12px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--rule);
  animation: fadeUp 0.7s ease both;
}
.page-head h1 {
  font-family: 'Fraunces', serif;
  font-variation-settings: "opsz" 96, "SOFT" 0, "WONK" 0;
  font-weight: 380;
  font-size: 40px;
  letter-spacing: -0.02em;
  line-height: 1;
  color: var(--ink);
  margin: 0;
}
.page-head .meta {
  text-align: right;
  font-size: 0.82rem;
  color: var(--ink-faint);
  font-style: italic;
  line-height: 1.5;
}
.page-head .meta strong {
  font-style: normal;
  font-weight: 480;
  color: var(--ink-mute);
}

/* =====================================================================
   IB Portfolio sub-tier — a contextual second level of the masthead,
   rendered INSIDE header.chrome (below nav.primary) when `ib_page` is set.
   A slim, slightly-deeper navy band so it reads as part of the chrome.
   ===================================================================== */
.subnav {
  background: var(--bg-row);
  border-bottom: 1px solid var(--rule);
}
.subnav-inner {
  max-width: 1800px;
  margin: 0 auto;
  padding: 0 44px;
  display: flex;
  align-items: stretch;
  height: 40px;
}
.subnav-up {
  display: flex;
  align-items: center;
  font-family: 'Newsreader', serif;
  font-style: italic;
  font-size: 0.82rem;
  color: var(--ink-faint);
  text-decoration: none;
  padding-right: 15px;
  transition: color 0.15s;
}
.subnav-up:hover { color: var(--navy); text-decoration: none; }
.subnav-book {
  display: flex;
  align-items: center;
  font-family: 'Recursive', monospace;
  font-variation-settings: 'MONO' 1;
  font-size: 0.68rem;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--ink-faint);
  padding: 0 16px;
  border-left: 1px solid var(--rule);
  white-space: nowrap;
  cursor: help;
}
.subnav-tabs {
  display: flex;
  align-items: stretch;
  margin-left: 6px;
}
.subnav-tabs a {
  display: flex;
  align-items: center;
  padding: 0 15px;
  font-family: 'Newsreader', serif;
  font-size: 0.9rem;
  color: var(--ink-mute);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}
.subnav-tabs a:hover { color: var(--ink); text-decoration: none; }
.subnav-tabs a.active {
  color: var(--navy);
  border-bottom-color: var(--navy);
  font-weight: 500;
}

/* =====================================================================
   SECTION bar
   ===================================================================== */
.section-bar {
  display: flex;
  justify-content: space-between;
  align-items: end;
  padding-bottom: 10px;
  margin-top: 12px;
  margin-bottom: 0;
  border-bottom: 1px solid var(--rule);
}
.section-bar h2 {
  font-family: 'Fraunces', serif;
  font-variation-settings: "opsz" 60;
  font-weight: 400;
  font-size: 22px;
  letter-spacing: -0.01em;
  margin: 0;
  color: var(--ink);
}
.section-bar .controls {
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 0.82rem;
  color: var(--ink-faint);
  font-style: italic;
}
.section-bar .controls form { display: flex; align-items: center; gap: 6px; }
.section-bar select {
  font-family: 'Newsreader', serif;
  font-style: italic;
  font-size: 0.85rem;
  padding: 4px 8px;
  border: 1px solid var(--rule);
  background: var(--bg);
  color: var(--ink);
  border-radius: 2px;
}

/* =====================================================================
   SUMMARY band — multi-cell stat strip
   ===================================================================== */
.summary {
  display: grid;
  gap: 0;
  border: 1px solid var(--rule);
  background: var(--bg);
  margin-bottom: 0;
  animation: fadeUp 0.7s 0.05s ease both;
}
.summary > .cell {
  padding: 15px 24px;
  border-right: 1px solid var(--rule);
}
.summary > .cell:last-child { border-right: none; }
.summary .label-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 12px;
}
.summary .lbl {
  font-family: 'Newsreader', serif;
  font-style: italic;
  font-size: 0.8rem;
  color: var(--ink-faint);
  letter-spacing: 0.02em;
}
.summary .ccy {
  font-family: 'Recursive', monospace;
  font-variation-settings: "MONO" 1;
  font-size: 0.66rem;
  color: var(--ink-ghost);
  letter-spacing: 0.06em;
}
.summary .v {
  font-family: 'Fraunces', serif;
  font-variation-settings: "opsz" 96, "SOFT" 0;
  font-feature-settings: "tnum", "lnum";
  font-weight: 380;
  font-size: 36px;
  line-height: 1;
  letter-spacing: -0.02em;
  color: var(--ink);
}
.summary .v.gain { color: var(--gain); }
.summary .v.loss { color: var(--loss); }
.summary .v.large { font-size: 48px; letter-spacing: -0.025em; }
.summary .pct {
  display: inline-block;
  margin-left: 10px;
  font-size: 0.86rem;
  font-style: italic;
  color: var(--ink-faint);
  font-family: 'Newsreader', serif;
  vertical-align: middle;
}
.summary .pct.gain { color: var(--gain); font-style: normal; font-weight: 500; }
.summary .pct.loss { color: var(--loss); font-style: normal; font-weight: 500; }
.summary .sub {
  display: block;
  margin-top: 6px;
  font-size: 0.78rem;
  color: var(--ink-faint);
  font-style: italic;
}

/* =====================================================================
   CARDS — bordered panels
   ===================================================================== */
.card {
  border: 1px solid var(--rule);
  background: var(--bg);
  padding: 24px 26px;
}
.card .card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 20px;
}
.card .card-head .title {
  font-family: 'Newsreader', serif;
  font-style: italic;
  font-size: 0.95rem;
  color: var(--ink-mute);
}
.card .card-head .meta {
  font-size: 0.78rem;
  color: var(--ink-faint);
  font-style: italic;
}

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 20px; }

/* =====================================================================
   LEDGER table — primary tabular layout
   ===================================================================== */
table.ledger {
  width: 100%;
  border-collapse: collapse;
  animation: fadeUp 0.7s 0.1s ease both;
}
/* Column header = the table's structural spine. Upright, uppercase, tracked
   — a "data-table" voice, deliberately NOT the italic caption voice used for
   KPI labels and sub-notes, so it reads as a header and not an annotation. */
table.ledger thead th {
  text-align: right;
  font-family: 'Newsreader', serif;
  font-style: normal;
  font-weight: 600;
  font-size: 0.64rem;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--ink-mute);
  padding: 8px 14px 7px;
  background: var(--bg-row);
  border-bottom: 1px solid var(--rule);
  vertical-align: bottom;
  white-space: nowrap;
}
table.ledger thead th:first-child { text-align: left; padding-left: 18px; }
table.ledger thead th:last-child { padding-right: 18px; }
table.ledger thead th.sortable {
  cursor: pointer;
  user-select: none;
  transition: color 0.15s;
}
table.ledger thead th.sortable:hover {
  color: var(--ink);
}
table.ledger thead th .arrow {
  display: inline-block;
  margin-left: 4px;
  color: var(--ink-thin);
  font-size: 0.7em;
  vertical-align: middle;
  transition: color 0.15s;
}
table.ledger thead th .arrow.idle { color: var(--ink-thin); }
table.ledger thead th .arrow.active { color: var(--ink); }
table.ledger thead th.sortable:hover .arrow.idle { color: var(--ink-faint); }
table.ledger tbody tr {
  transition: background-color 0.16s ease;
}
table.ledger tbody tr:hover { background: var(--bg-row-hover); }
table.ledger tbody td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--rule-faint);
  vertical-align: middle;
}
table.ledger tbody td:first-child { padding-left: 18px; }
table.ledger tbody td:last-child  { padding-right: 18px; }

table.ledger td.r { text-align: right; }
table.ledger td.num-cell {
  font-family: 'Fraunces', serif;
  font-variation-settings: "opsz" 60;
  font-feature-settings: "tnum", "lnum";
  font-weight: 400;
  font-size: 0.96rem;
  color: var(--ink);
  letter-spacing: -0.005em;
  white-space: nowrap;
}
table.ledger td.num-cell .v { display: block; line-height: 1.1; }
table.ledger td.num-cell .ccy {
  display: block;
  margin-top: 3px;
  font-family: 'Recursive', monospace;
  font-variation-settings: "MONO" 1;
  font-size: 0.62rem;
  color: var(--ink-ghost);
  letter-spacing: 0.06em;
  font-weight: 400;
}
table.ledger td.num-cell.muted .v { color: var(--ink-mute); }
table.ledger td.num-cell.faint .v { color: var(--ink-faint); }
table.ledger td.num-cell.gain .v  { color: var(--gain); }
table.ledger td.num-cell.loss .v  { color: var(--loss); }
table.ledger td.num-cell.dim .v   { color: var(--ink-thin); }

.sym-cell {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 200px;
}
.sym-name {
  font-family: 'Fraunces', serif;
  font-variation-settings: "opsz" 36;
  font-weight: 460;
  font-size: 1.05rem;
  letter-spacing: -0.005em;
  color: var(--ink);
  line-height: 1.1;
}
.sym-desc {
  font-family: 'Newsreader', serif;
  font-style: italic;
  font-size: 0.78rem;
  color: var(--ink-faint);
  line-height: 1.3;
}

/* Owner-only: symbol cells link to /analyze/{SYM}. Keep them visually
   identical to plain text so the table doesn't look like a sea of links;
   reveal interactivity on hover. */
.sym-name a.sym-link {
  color: inherit;
  text-decoration: none;
  border-bottom: 1px dotted transparent;
  transition: border-color 0.15s, color 0.15s;
}
.sym-name a.sym-link:hover {
  color: var(--navy);
  border-bottom-color: var(--ink-thin);
}

.change-pill {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 2px;
  font-size: 0.86rem;
  font-feature-settings: "tnum";
  font-family: 'Fraunces', serif;
  font-variation-settings: "opsz" 36;
}
.change-pill.gain { background: var(--gain-bg); color: var(--gain); }
.change-pill.loss { background: var(--loss-bg); color: var(--loss); }
.change-pill.dim  { color: var(--ink-thin); }

.footnote-mark {
  color: var(--ink-faint);
  font-size: 0.7rem;
  vertical-align: super;
  margin-left: 2px;
  font-family: 'Newsreader', serif;
}

/* =====================================================================
   HERO figure (used by /pnl, /xirr)
   ===================================================================== */
.hero {
  border: 1px solid var(--rule);
  padding: 40px 44px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  animation: fadeUp 0.7s 0.05s ease both;
}
.hero .lbl {
  font-family: 'Newsreader', serif;
  font-style: italic;
  font-size: 0.95rem;
  color: var(--ink-mute);
}
.hero .v {
  font-family: 'Fraunces', serif;
  font-variation-settings: "opsz" 144, "SOFT" 25, "WONK" 0;
  font-feature-settings: "tnum", "lnum";
  font-weight: 380;
  font-size: 88px;
  line-height: 0.9;
  letter-spacing: -0.035em;
  color: var(--ink);
}
.hero .v.gain { color: var(--gain); }
.hero .v.loss { color: var(--loss); }
.hero .sub {
  font-family: 'Newsreader', serif;
  font-style: italic;
  font-size: 0.92rem;
  color: var(--ink-faint);
}

/* =====================================================================
   FOOTER
   ===================================================================== */
footer.colophon {
  margin-top: 56px;
  padding-top: 18px;
  border-top: 1px solid var(--rule);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.78rem;
  color: var(--ink-faint);
  gap: 24px;
  flex-wrap: wrap;
}
footer.colophon .left { font-style: italic; }
footer.colophon .right {
  font-family: 'Recursive', monospace;
  font-variation-settings: "MONO" 1;
  font-size: 0.74rem;
  letter-spacing: 0.04em;
  color: var(--ink-ghost);
}
footer.colophon strong {
  color: var(--ink-mute);
  font-weight: 500;
  font-style: normal;
}

/* =====================================================================
   Animations
   ===================================================================== */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes pulse-dot {
  0%, 80%, 100% { opacity: 0.25; transform: scale(0.8); }
  40%           { opacity: 1.0;  transform: scale(1.0); }
}
@keyframes slideUp {
  from { opacity: 0; transform: translateY(16px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* =====================================================================
   Chat widget (floating bottom-right, owner-only)
   ===================================================================== */
#ask-btn {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  border: none;
  background: var(--navy);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(20, 30, 50, 0.22);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}
#ask-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(20, 30, 50, 0.28);
}
#ask-btn:active { transform: translateY(0); }
#ask-btn.is-open { display: none; }

#ask-panel {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 420px;
  max-width: calc(100vw - 32px);
  height: 600px;
  max-height: calc(100vh - 32px);
  background: white;
  border: 1px solid var(--ink);
  box-shadow: 0 12px 40px rgba(20, 30, 50, 0.20);
  display: none;
  flex-direction: column;
  z-index: 100;
  overflow: hidden;
}
#ask-panel.is-open {
  display: flex;
  animation: slideUp 0.22s ease both;
}

.ask-head {
  background: var(--navy);
  color: #fff;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
.ask-title { display: flex; flex-direction: column; gap: 1px; }
.ask-title-main {
  font-family: 'Fraunces', serif;
  font-variation-settings: "opsz" 48;
  font-weight: 460;
  font-size: 1.05rem;
  letter-spacing: -0.005em;
}
.ask-title-sub {
  font-family: 'Newsreader', serif;
  font-style: italic;
  font-size: 0.74rem;
  opacity: 0.7;
}
#ask-close {
  background: none;
  border: none;
  color: #fff;
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0 6px;
  line-height: 1;
  opacity: 0.7;
  transition: opacity 0.15s ease;
}
#ask-close:hover { opacity: 1.0; }

.ask-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  background: var(--bg-row);
  display: flex;
  flex-direction: column;
  gap: 12px;
  font-size: 0.92rem;
}
.ask-body::-webkit-scrollbar { width: 8px; }
.ask-body::-webkit-scrollbar-thumb { background: var(--ink-thin); border-radius: 4px; }

.ask-welcome {
  font-family: 'Newsreader', serif;
  color: var(--ink-mute);
  font-size: 0.92rem;
  line-height: 1.5;
}
.ask-examples {
  list-style: none;
  padding: 0;
  margin: 8px 0 0 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.ask-examples li {
  padding: 7px 11px;
  border: 1px solid var(--rule);
  background: white;
  border-radius: 14px;
  font-style: italic;
  font-size: 0.85rem;
  color: var(--ink);
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease;
}
.ask-examples li:hover {
  background: var(--navy);
  color: white;
  border-color: var(--navy);
}

.ask-msg {
  max-width: 90%;
  padding: 9px 13px;
  border-radius: 12px;
  line-height: 1.45;
  animation: fadeUp 0.18s ease both;
  word-wrap: break-word;
}
.ask-msg.user {
  align-self: flex-end;
  background: var(--navy);
  color: #fff;
  border-bottom-right-radius: 3px;
  font-size: 0.9rem;
}
.ask-msg.assistant {
  align-self: flex-start;
  background: white;
  color: var(--ink);
  border: 1px solid var(--rule);
  border-bottom-left-radius: 3px;
  font-size: 0.9rem;
}

/* Rendered markdown inside assistant messages */
.ask-msg.assistant p { margin: 0 0 8px; }
.ask-msg.assistant p:last-child { margin-bottom: 0; }
.ask-msg.assistant ul, .ask-msg.assistant ol { margin: 4px 0; padding-left: 18px; }
.ask-msg.assistant li { margin: 2px 0; }
.ask-msg.assistant strong { font-weight: 500; }
.ask-msg.assistant em { font-style: italic; color: var(--ink-mute); }
.ask-msg.assistant code {
  font-family: 'Recursive', ui-monospace, monospace;
  background: var(--bg-row);
  padding: 1px 4px;
  border-radius: 2px;
  font-size: 0.85em;
}
.ask-msg.assistant table {
  width: 100%;
  border-collapse: collapse;
  margin: 8px 0;
  font-size: 0.84rem;
  font-feature-settings: "tnum";
}
.ask-msg.assistant thead th {
  text-align: left;
  padding: 5px 7px;
  border-bottom: 1px solid var(--ink-thin);
  font-family: 'Newsreader', serif;
  font-style: italic;
  font-weight: 460;
  font-size: 0.78rem;
  color: var(--ink-faint);
}
.ask-msg.assistant tbody td {
  padding: 5px 7px;
  border-bottom: 1px solid var(--rule-faint);
}
.ask-msg.assistant tbody tr:last-child td { border-bottom: none; }
.ask-msg-meta {
  font-family: 'Newsreader', serif;
  font-style: italic;
  font-size: 0.72rem;
  color: var(--ink-faint);
  margin-top: 2px;
  align-self: flex-start;
}

.ask-thinking {
  align-self: flex-start;
  padding: 9px 13px;
  background: white;
  border: 1px solid var(--rule);
  border-radius: 12px;
  border-bottom-left-radius: 3px;
  display: inline-flex;
  gap: 5px;
}
.ask-thinking span {
  display: block;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--ink-mute);
  animation: pulse-dot 1.3s infinite ease-in-out;
}
.ask-thinking span:nth-child(2) { animation-delay: 0.16s; }
.ask-thinking span:nth-child(3) { animation-delay: 0.32s; }

.ask-form {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  background: white;
  border-top: 1px solid var(--rule);
  flex-shrink: 0;
}
#ask-input {
  flex: 1;
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 8px 10px;
  font-family: inherit;
  font-size: 0.9rem;
  resize: none;
  max-height: 100px;
  transition: border-color 0.15s ease;
}
#ask-input:focus {
  outline: none;
  border-color: var(--navy);
}
#ask-input:disabled {
  background: var(--bg-row);
  color: var(--ink-faint);
}
#ask-send {
  align-self: flex-end;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: var(--navy);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, opacity 0.15s ease;
}
#ask-send:hover:not(:disabled) { background: var(--navy-deep); }
#ask-send:disabled { opacity: 0.4; cursor: not-allowed; }
.ask-status {
  padding: 0 12px 8px;
  background: white;
  font-family: 'Newsreader', serif;
  font-style: italic;
  font-size: 0.72rem;
  color: var(--ink-faint);
  min-height: 0;
  flex-shrink: 0;
}
.ask-status.error { color: #B91C1C; font-style: normal; font-weight: 500; }

@media (max-width: 600px) {
  #ask-panel {
    bottom: 0;
    right: 0;
    width: 100vw;
    max-width: 100vw;
    height: 100vh;
    max-height: 100vh;
    border: none;
  }
  #ask-btn { bottom: 16px; right: 16px; }
}

/* =====================================================================
   Utility — stat-grid for in-card 2x2 figure blocks (used by /monthly,
   /trades). Desktop 2-col, mobile collapses to 1-col at 480px.
   ===================================================================== */
.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}
.stat-grid.tight { gap: 18px 24px; }

/* Hamburger button — hidden on desktop, shown on mobile via media query */
.hamburger {
  display: none;
  width: 40px;
  height: 40px;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.20);
  border-radius: 3px;
  color: #fff;
  cursor: pointer;
  padding: 0;
  font-size: 18px;
  line-height: 1;
  transition: background 0.18s;
}
.hamburger:hover { background: rgba(255, 255, 255, 0.10); }
.hamburger .bars,
.hamburger .bars::before,
.hamburger .bars::after {
  content: "";
  display: block;
  width: 18px;
  height: 1.5px;
  background: #fff;
  position: relative;
  transition: transform 0.2s, opacity 0.2s;
}
.hamburger .bars::before { position: absolute; top: -6px; left: 0; }
.hamburger .bars::after  { position: absolute; top:  6px; left: 0; }
.hamburger[aria-expanded="true"] .bars { background: transparent; }
.hamburger[aria-expanded="true"] .bars::before { transform: translateY(6px) rotate(45deg); }
.hamburger[aria-expanded="true"] .bars::after  { transform: translateY(-6px) rotate(-45deg); }

/* Mobile drawer — hidden by default, slides down when toggled. Lives
   inside the sticky header so it stays attached to the chrome. */
.mobile-drawer {
  display: none;
  background: var(--navy);
  border-top: 1px solid rgba(255, 255, 255, 0.10);
  animation: slideDown 0.2s ease-out;
}
.mobile-drawer.open { display: block; }
.mobile-drawer nav {
  display: flex;
  flex-direction: column;
  padding: 8px 0;
}
.mobile-drawer nav a {
  font-family: 'Newsreader', serif;
  font-size: 1.05rem;
  color: rgba(255, 255, 255, 0.86);
  text-decoration: none;
  padding: 14px 24px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
.mobile-drawer nav a:hover,
.mobile-drawer nav a.active {
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
  text-decoration: none;
}
.mobile-drawer .drawer-user {
  padding: 16px 24px 20px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  font-size: 0.88rem;
  color: rgba(255, 255, 255, 0.78);
  border-top: 1px solid rgba(255, 255, 255, 0.10);
}
.mobile-drawer .drawer-user .email { color: #fff; font-weight: 460; word-break: break-all; }
.mobile-drawer .drawer-user .signout {
  margin-left: auto;
  color: rgba(255, 255, 255, 0.78);
  font-style: italic;
  padding: 8px 14px;
  border: 1px solid rgba(255, 255, 255, 0.20);
  border-radius: 3px;
  text-decoration: none;
}
.mobile-drawer .drawer-user .signout:hover { color: #fff; text-decoration: none; }
@keyframes slideDown {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* =====================================================================
   Responsive — single mobile breakpoint at ≤768px.
   Target: a phone in portrait (about 400 CSS px). Desktop is untouched.
   ===================================================================== */
@media (max-width: 768px) {
  /* Chrome: brand on left, freshness chip + hamburger on right */
  .chrome-inner {
    grid-template-columns: auto 1fr auto;
    padding: 10px 14px;
    gap: 10px;
  }
  nav.primary { display: none; }
  .subnav-inner { padding: 0 14px; overflow-x: auto; }
  .subnav-up, .subnav-book { display: none; }   /* tabs only on mobile */
  .subnav-tabs { margin-left: 0; }
  .subnav-tabs a { font-size: 0.86rem; padding: 0 13px; }
  .user-block .email,
  .user-block .role-pill,
  .user-block .signout { display: none; }
  .user-block { gap: 10px; }
  .hamburger { display: inline-flex; }
  .wordmark { font-size: 18px; }
  .glyph { font-size: 23px; }
  .brand { gap: 9px; }
  .brand .mark { width: 28px; height: 28px; }

  details.freshness > summary { font-size: 0.74rem; padding: 4px 8px; }
  details.freshness > .popover {
    min-width: 0;
    width: calc(100vw - 32px);
    right: -8px;
    max-width: 360px;
  }

  /* Page chrome */
  main.page { padding: 18px 14px 52px; }
  .page-head {
    grid-template-columns: 1fr;
    gap: 8px;
    padding-bottom: 14px;
    margin-bottom: 20px;
  }
  .page-head h1 { font-size: 26px; }
  .page-head .meta { text-align: left; font-size: 0.78rem; }

  .section-bar {
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 28px;
  }
  .section-bar h2 { font-size: 19px; }
  .section-bar .controls { font-size: 0.78rem; gap: 8px; }

  /* Every page-level grid collapses to a single column */
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; gap: 14px; }
  .stat-grid { grid-template-columns: 1fr; gap: 14px; }

  /* Summary band — 4 cells stack 1-col; restore bottom borders */
  .summary { grid-template-columns: 1fr !important; }
  .summary > .cell {
    padding: 16px 18px;
    border-right: none;
    border-bottom: 1px solid var(--rule);
  }
  .summary > .cell:last-child { border-bottom: none; }
  .summary .v { font-size: 28px; }
  .summary .v.large { font-size: 34px; }
  .summary .pct { font-size: 0.82rem; margin-left: 6px; }
  .summary .sub { font-size: 0.74rem; }

  /* Hero */
  .hero { padding: 22px 18px; }
  .hero .v { font-size: 44px; line-height: 1; }
  .hero .lbl { font-size: 0.85rem; }
  .hero .sub { font-size: 0.82rem; }

  /* Cards */
  .card { padding: 16px 16px; }
  .card .card-head { margin-bottom: 14px; }
  .card .card-head .title { font-size: 0.88rem; }

  /* ================================================================
     table.ledger → vertical card stack.
     Each <td> needs data-label="..." for the row label.
     The first cell (symbol/instrument) gets class="cell-primary"
     to render as the card title (no label, larger, separated).
     ================================================================ */
  table.ledger { border: 0; animation: none; }
  table.ledger thead { display: none; }
  table.ledger tbody { display: block; }
  table.ledger tbody tr {
    display: block;
    background: var(--bg);
    border: 1px solid var(--rule);
    border-radius: 2px;
    margin-bottom: 10px;
    padding: 12px 14px;
  }
  table.ledger tbody tr:hover { background: var(--bg); }
  table.ledger tbody tr.short-row { background: rgba(180, 83, 9, 0.025); }
  table.ledger tbody td {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 16px;
    padding: 6px 0 !important;
    border-bottom: 1px solid var(--rule-faint);
    text-align: left;
    white-space: normal;
  }
  table.ledger tbody td:last-child { border-bottom: none; }
  table.ledger tbody td::before {
    content: attr(data-label);
    font-family: 'Newsreader', serif;
    font-style: italic;
    font-size: 0.78rem;
    font-weight: 460;
    letter-spacing: 0.02em;
    color: var(--ink-faint);
    flex-shrink: 0;
    text-align: left;
  }
  table.ledger tbody td:not([data-label])::before { display: none; }
  /* Primary cell — card title row */
  table.ledger tbody td.cell-primary {
    display: block;
    padding: 0 0 10px !important;
    margin-bottom: 6px;
    border-bottom: 1px solid var(--rule);
  }
  table.ledger tbody td.cell-primary::before { display: none; }
  table.ledger tbody td.cell-primary .sym-cell { min-width: 0; gap: 3px; }
  table.ledger tbody td.cell-primary .sym-name { font-size: 1.1rem; }
  table.ledger tbody td.cell-primary .sym-desc { font-size: 0.8rem; }

  /* Inline elements inside td: numbers, pills, currency tags */
  table.ledger tbody td.num-cell { white-space: normal; }
  table.ledger tbody td.num-cell .v { display: inline; line-height: inherit; }
  table.ledger tbody td.num-cell .ccy { display: inline; margin-top: 0; margin-left: 6px; }
  table.ledger tbody td .change-pill { font-size: 0.86rem; }

  /* Footer total row — its own emphasized card */
  table.ledger tfoot { display: block; }
  table.ledger tfoot tr.total-row {
    display: block;
    background: var(--bg-row);
    border: 1px solid var(--rule);
    padding: 12px 14px;
    margin-top: 4px;
  }
  table.ledger tfoot tr.total-row td {
    display: flex;
    justify-content: space-between;
    padding: 5px 0 !important;
    border: none;
    text-align: left;
  }
  table.ledger tfoot tr.total-row td:empty { display: none; }
  table.ledger tfoot tr.total-row td::before {
    content: attr(data-label);
    font-family: 'Newsreader', serif;
    font-style: italic;
    font-size: 0.78rem;
    color: var(--ink-faint);
    flex-shrink: 0;
  }
  table.ledger tfoot tr.total-row td:not([data-label])::before { display: none; }
  table.ledger tfoot tr.total-row td.cell-primary {
    display: block;
    padding: 0 0 8px !important;
    margin-bottom: 6px;
    border-bottom: 1px solid var(--rule);
  }
  table.ledger tfoot tr.total-row td.cell-primary::before { display: none; }
  table.ledger tfoot tr.total-row td.emphasized .v { font-size: 1.05rem; }

  footer.colophon {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    font-size: 0.74rem;
  }
}
