:root {
  --paper: #F2F4F1;
  --surface: #FFFFFF;
  --surface-2: #EAEEEA;
  --ink: #16211D;
  --ink-soft: #4B5A54;
  --ink-faint: #8A968F;
  --accent: #2E6E5E;
  --accent-soft: #DCEAE4;
  --line: #D8DDD8;
  --code-bg: #EDF1EE;
  --shadow: 0 1px 2px rgba(22,33,29,0.06), 0 8px 24px rgba(22,33,29,0.05);

  --good: #2E7D46;
  --good-soft: #DCEFE1;
  --warn: #8A5A1E;
  --warn-soft: #F1E3C9;
  --bad: #9C3B2E;
  --bad-soft: #F3DCD8;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #0E1512;
    --surface: #141C18;
    --surface-2: #1A2420;
    --ink: #E8EDE9;
    --ink-soft: #A6B5AE;
    --ink-faint: #6C7A73;
    --accent: #59B79E;
    --accent-soft: #1B332C;
    --line: #263129;
    --code-bg: #101815;
    --shadow: 0 1px 2px rgba(0,0,0,0.3), 0 8px 24px rgba(0,0,0,0.35);

    --good: #5FBE7C;
    --good-soft: #17301F;
    --warn: #D9A455;
    --warn-soft: #362A15;
    --bad: #D97C6C;
    --bad-soft: #351E1A;
  }
}
:root[data-theme="dark"] {
  --paper: #0E1512;
  --surface: #141C18;
  --surface-2: #1A2420;
  --ink: #E8EDE9;
  --ink-soft: #A6B5AE;
  --ink-faint: #6C7A73;
  --accent: #59B79E;
  --accent-soft: #1B332C;
  --line: #263129;
  --code-bg: #101815;
  --shadow: 0 1px 2px rgba(0,0,0,0.3), 0 8px 24px rgba(0,0,0,0.35);

  --good: #5FBE7C;
  --good-soft: #17301F;
  --warn: #D9A455;
  --warn-soft: #362A15;
  --bad: #D97C6C;
  --bad-soft: #351E1A;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  /* The page itself must never scroll horizontally -- a wide table should
     scroll within its own .table-wrap (below), not drag the whole layout
     (sticky sidebar included) sideways with it. */
  overflow-x: hidden;
}

h1, h2, h3, .display { font-family: Georgia, "Iowan Old Style", "Palatino Linotype", serif; text-wrap: balance; }
.mono, code, .num { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.tabular { font-variant-numeric: tabular-nums; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
a:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.shell {
  display: grid;
  grid-template-columns: 236px 1fr;
  min-height: 100vh;
  transition: grid-template-columns 0.15s ease;
}
html.sidebar-collapsed .shell { grid-template-columns: 64px 1fr; }

/* ---- Sidebar ---- */
/* position:sticky + a fixed 100vh height (rather than letting the grid cell
   stretch to match main's content height) is what keeps sidebar-foot -- the
   signed-in user + sign out -- pinned in view without scrolling, no matter
   how long the page in the main column gets. align-self:start opts the
   sidebar out of the grid's default row-stretch behavior, which would
   otherwise force it to match main's height and defeat the fixed height. */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  overflow: hidden;
}
.sidebar-top { display: flex; align-items: flex-start; padding: 0 6px; }
.brand { display: flex; flex-direction: column; gap: 2px; width: 100%; }
.brand-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.brand .name { font-family: Georgia, serif; font-size: 1.05rem; letter-spacing: 0.02em; }
.brand .tagline { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--ink-faint); }
.brand .brand-mark {
  display: none; font-family: Georgia, serif; font-size: 1.15rem; font-weight: 600;
  color: var(--accent); width: 24px; height: 24px; align-items: center; justify-content: center;
}

/* Small icon-only buttons shared by the sidebar-collapse chevron (next to
   "Wealth Management") and the collapse-all-sections hamburger (next to
   "Command Center"), plus reused by the per-section accordion chevrons. */
.icon-btn {
  flex: none; width: 22px; height: 22px; border-radius: 6px; border: none;
  background: transparent; color: var(--ink-faint); display: flex; align-items: center; justify-content: center;
  cursor: pointer; padding: 0;
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn svg { width: 12px; height: 12px; transition: transform 0.15s ease; }
html.sidebar-collapsed #sidebar-collapse-btn svg { transform: rotate(180deg); }

/* Scrolls independently of the fixed-height sidebar if the nav list itself
   ever grows past the viewport -- min-height:0 is required on a flex child
   for its own overflow:auto to take effect instead of just overflowing. */
.sidebar-nav { flex: 1 1 auto; overflow-y: auto; min-height: 0; }

.service-group .label {
  font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.1em;
  color: var(--ink-faint); padding: 0 6px; margin-bottom: 8px;
}
.service-group .service-name {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 6px; font-weight: 600; color: var(--accent);
  font-size: 0.92rem; margin-bottom: 6px;
}
.service-group .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); flex: none; }

.nav-links { display: flex; flex-direction: column; gap: 1px; }
.nav-links a {
  display: flex; align-items: center; gap: 8px;
  color: var(--ink-soft);
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 0.88rem;
}
.nav-links a:hover { background: var(--surface-2); text-decoration: none; color: var(--ink); }
.nav-links a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
/* A link that's conceptually a sub-item of the one right above it (e.g.
   Prepaid under Cost) -- extra left padding in the normal (expanded)
   sidebar only; icon-only mode already visually flattens everything to a
   single indent level, so this resets there instead of compounding it. */
.nav-links a.nav-sub-link { padding-left: 24px; }
html.sidebar-collapsed .nav-links a.nav-sub-link { padding-left: 9px; }
/* Sized to roughly match the nav label's text/x-height (0.88rem), not the
   16-unit SVG viewBox each icon is drawn in -- at 16px square the icons
   read noticeably bigger than the label text next to them. */
.nav-icon { flex: none; width: 12px; height: 12px; display: inline-flex; align-items: center; justify-content: center; }
.nav-icon svg { width: 12px; height: 12px; }

.nav-subgroup { margin-bottom: 14px; }
.nav-subgroup:last-child { margin-bottom: 0; }
.nav-subgroup-label {
  display: flex; align-items: center; justify-content: space-between; width: 100%;
  font-size: 0.66rem; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--ink-faint); padding: 0 6px 6px 18px;
  background: none; border: none; cursor: pointer; font-family: inherit;
}
.nav-subgroup-label:hover { color: var(--ink-soft); }
.nav-subgroup-label .section-chevron { width: 12px; height: 12px; flex: none; transition: transform 0.15s ease; }
/* Collapsed accordion state -- hides that section's links in the normal
   (expanded-width) sidebar, but icon-only sidebar mode always shows every
   icon regardless (see the html.sidebar-collapsed override below): the
   accordion is a full-width-sidebar feature, there's nothing to collapse
   further once you're already down to icons only. */
.nav-subgroup.collapsed .nav-subgroup-label .section-chevron { transform: rotate(-90deg); }
.nav-subgroup.collapsed .nav-links { display: none; }
html.sidebar-collapsed .nav-subgroup.collapsed .nav-links { display: flex; }
.nav-links.indented {
  margin-left: 9px;
  padding-left: 10px;
  border-left: 1px solid var(--line);
}

.sidebar-version { padding: 12px 6px 0; border-top: 1px solid var(--line); font-size: 0.74rem; color: var(--ink-faint); }
.sidebar-version .version-row { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 4px; }
.sidebar-version .version-row:last-child { margin-bottom: 0; }
.sidebar-version .version-value { color: var(--ink-soft); }

.sidebar-foot { padding: 12px 6px 0; border-top: 1px solid var(--line); }
.logout-link { display: flex; align-items: center; gap: 10px; font-size: 0.8rem; color: var(--ink-faint); margin-bottom: 8px; }
.user-chip { display: flex; align-items: center; gap: 8px; font-size: 0.82rem; color: var(--ink-soft); }
.user-chip .avatar { width: 22px; height: 22px; border-radius: 50%; background: var(--surface-2); flex: none; }

/* ---- Collapsed sidebar: icons only ---- */
html.sidebar-collapsed .nav-text,
html.sidebar-collapsed .nav-subgroup-label,
html.sidebar-collapsed .service-group .label { display: none; }
html.sidebar-collapsed .brand .brand-mark { display: flex; }
html.sidebar-collapsed .sidebar-top { justify-content: center; }
html.sidebar-collapsed .brand-row { justify-content: center; }
html.sidebar-collapsed .nav-links a { justify-content: center; padding: 9px; }
html.sidebar-collapsed .nav-links.indented { margin-left: 0; padding-left: 0; border-left: none; }
html.sidebar-collapsed .logout-link { justify-content: center; margin-bottom: 10px; }
html.sidebar-collapsed .user-chip { justify-content: center; }

/* ---- Main content ---- */
.main-wrap { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 16px 40px;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
/* Left padding matches main's own 40px page margin, so the title lines up
   with the page's plain lead-in text (e.g. the "N cycle(s) on record..."
   line, which sits directly in main with no .card wrapper of its own) --
   not with the deeper indent of text inside a .card. */
.topbar-title { font-size: 1.25rem; margin: 0; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }

/* Wide enough that the app's wider tables (Agent Trade Details' 14 columns,
   in particular) fit without horizontal scrolling on a normal-size laptop
   or desktop screen, while still capping line length on an ultra-wide
   monitor. .table-wrap's overflow-x:auto (below) remains as a fallback for
   whatever doesn't fit even at this width, not the primary experience.
   min-width:0 overrides the flex item default of min-width:auto -- without
   it, main refuses to shrink narrower than an unbreakable table (th/td are
   white-space:nowrap) on a smaller window, pushing the overflow onto the
   whole page instead of staying inside .table-wrap where it can actually
   be scrolled. */
main { padding: 24px 40px 80px; max-width: 1760px; min-width: 0; }
.page-head { margin-bottom: 24px; }
.page-head h1 { font-size: 1.55rem; margin: 0 0 4px; }
.page-head .sub { color: var(--ink-soft); font-size: 0.94rem; max-width: 68ch; }

.grid { display: grid; gap: 16px; }
.grid-5 { grid-template-columns: repeat(5, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 1100px) { .grid-5 { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 900px) { .grid-5, .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr 1fr; } }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 18px 20px;
  box-shadow: var(--shadow);
}
.card h2 { font-size: 1.02rem; margin: 0 0 14px; }
.card h2 .idx { color: var(--accent); font-size: 0.8rem; margin-right: 6px; }

.stat .label { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.07em; color: var(--ink-faint); margin-bottom: 6px; }
.stat .value { font-size: 1.5rem; font-family: ui-monospace, monospace; font-variant-numeric: tabular-nums; }
.stat .value.small { font-size: 1.15rem; }

/* ---- Pills / semantic state ---- */
.pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px; border-radius: 999px; font-size: 0.78rem; font-weight: 600;
}
.pill .dot { width: 6px; height: 6px; border-radius: 50%; }
.pill.good { background: var(--good-soft); color: var(--good); }
.pill.good .dot { background: var(--good); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.warn .dot { background: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.bad .dot { background: var(--bad); }
.pill.neutral { background: var(--surface-2); color: var(--ink-soft); }
.pill.neutral .dot { background: var(--ink-faint); }

.badge { font-size: 0.74rem; padding: 2px 8px; border-radius: 5px; background: var(--surface-2); color: var(--ink-soft); }
.badge.approve { background: var(--good-soft); color: var(--good); }
.badge.reduce { background: var(--warn-soft); color: var(--warn); }
.badge.reject { background: var(--bad-soft); color: var(--bad); }
.badge.buy { background: var(--good-soft); color: var(--good); }
.badge.sell { background: var(--bad-soft); color: var(--bad); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }

/* ---- Tables ---- */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); font-size: 0.86rem; white-space: nowrap; }
th { text-transform: uppercase; letter-spacing: 0.05em; color: var(--ink-faint); font-weight: 700; }
tr:last-child td { border-bottom: none; }
tr.link-row:hover { background: var(--surface-2); cursor: pointer; }
td.wrap { white-space: normal; max-width: 420px; }
td.num, th.num { text-align: right; font-family: ui-monospace, monospace; font-variant-numeric: tabular-nums; }
.pos { color: var(--good); }
.neg { color: var(--bad); }

/* Total row on a summary table -- bold, set off with a heavier top border,
   otherwise inheriting that table's own column formatting (money/percent/
   count filters stay whatever the data rows above already use). Standard
   across every summary table in the app, not just one page's table. */
tr.total-row td { font-weight: 700; border-top: 2px solid var(--line); }

.pagination { display: flex; gap: 8px; align-items: center; margin-top: 16px; font-size: 0.85rem; color: var(--ink-soft); }
.pagination a { padding: 4px 10px; border: 1px solid var(--line); border-radius: 6px; color: var(--ink); }
.pagination a:hover { background: var(--surface-2); text-decoration: none; }
.pagination .disabled { opacity: 0.4; pointer-events: none; }

.tabs { display: flex; gap: 6px; margin-bottom: 18px; }
.tabs a {
  padding: 6px 14px; border-radius: 999px; font-size: 0.85rem;
  border: 1px solid var(--line); color: var(--ink-soft);
}
.tabs a.active { background: var(--accent); border-color: var(--accent); color: white; }
.tabs a:hover:not(.active) { background: var(--surface-2); text-decoration: none; }

.funnel-step { display: flex; align-items: center; gap: 14px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.funnel-step:last-child { border-bottom: none; }
.funnel-step .fname { flex: 0 0 180px; font-size: 0.88rem; color: var(--ink-soft); }
.funnel-step .fbar-wrap { flex: 1; background: var(--surface-2); border-radius: 4px; height: 10px; overflow: hidden; }
.funnel-step .fbar { height: 100%; background: var(--accent); }
.funnel-step .fcount { flex: 0 0 60px; text-align: right; font-family: ui-monospace, monospace; font-variant-numeric: tabular-nums; }

.reasoning-box {
  background: var(--code-bg); border-radius: 8px; padding: 14px 16px;
  font-size: 0.88rem; color: var(--ink-soft); line-height: 1.55; margin: 8px 0 0;
}

.empty-state { color: var(--ink-faint); padding: 32px 0; text-align: center; font-size: 0.92rem; }

/* ---- Ticker hover tooltip (see base.html's [data-ticker] handling) ---- */
[data-ticker] { cursor: help; border-bottom: 1px dotted var(--ink-faint); }
.ticker-tooltip {
  display: none; position: fixed; z-index: 50; max-width: 260px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 6px;
  box-shadow: var(--shadow); padding: 6px 10px; font-size: 0.8rem; color: var(--ink-soft);
  pointer-events: none;
}

/* ---- Login ---- */
.login-shell {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: var(--paper);
}
.login-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: var(--shadow); padding: 40px 36px; width: 360px; text-align: center;
}
.login-card .brand-name { font-family: Georgia, serif; font-size: 1.3rem; margin-bottom: 2px; }
.login-card .brand-sub { color: var(--ink-faint); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.1em; margin-bottom: 28px; }
.google-btn {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  background: var(--accent); color: white; padding: 11px 18px; border-radius: 8px;
  font-size: 0.92rem; font-weight: 600; border: none; width: 100%; cursor: pointer;
}
.google-btn:hover { opacity: 0.92; text-decoration: none; }
.login-note { font-size: 0.78rem; color: var(--ink-faint); margin-top: 18px; }
.login-denied { background: var(--bad-soft); color: var(--bad); border-radius: 8px; padding: 10px 14px; font-size: 0.84rem; margin-bottom: 18px; }
