/* ──────────────────────────────────────────────────────────────────────────
   Lattice — shared design tokens + chrome (header / nav / brand / kpi base)
   Page-specific styles (tables, badges, charts) live in each template.
   ────────────────────────────────────────────────────────────────────────── */

:root {
  /* Backgrounds — neutral near-black scale (Linear/Vercel-ish)            */
  --bg:           #0a0b0e;
  --bg2:          #11141a;
  --bg3:          #191d27;
  --border:       #232834;
  --border-dim:   #1d2230;

  /* Text                                                                   */
  --text:         #e6e9ef;
  --text-dim:     #8a93a6;
  --text-faint:   #525a6b;

  /* Accent — blue (primary) + cyan (gradient pair, in-family)              */
  --accent:       #3b82f6;
  --accent-hover: #2563eb;
  --accent-dim:   #1e3a5f;
  --accent-cyan:  #06b6d4;

  /* Semantic — finance-conventional (Bloomberg / TOS / TradingView)        */
  --strong-bull:     #10b981;
  --strong-bull-bg:  #052e1c;
  --bull:            #34d399;
  --bull-bg:         #042820;
  --bear:            #f87171;
  --bear-bg:         #2d0f0f;
  --strong-bear:     #ef4444;
  --strong-bear-bg:  #3d0909;
  --warn:            #f59e0b;
  --warn-bg:         #2d1f05;
  --neutral:         #94a3b8;
  --neutral-bg:      #1c2030;

  /* Auxiliary — only for non-bull/bear/warn signals                        */
  --cyan:         #06b6d4;
  --purple:       #a78bfa;   /* legacy, retained for source-badges          */

  /* Type — Inter for chrome, JetBrains Mono for numerics                   */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI',
               system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', 'Fira Code', Consolas,
               'Liberation Mono', monospace;

  /* Geometry                                                               */
  --radius:  8px;
  --shadow:  0 4px 24px rgba(0,0,0,0.5);
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.35);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 13px;
  font-feature-settings: 'cv11', 'ss01';
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
  /* Prevent any oversized child (e.g. .ic-bar with its 7-tile bias card)
     from dragging the body wider than the viewport. `clip` doesn't
     establish a new scroll context, so the sticky header inside body
     keeps working — unlike `hidden`, which would break it. Cards bar
     handles its own internal overflow via `overflow-x: auto`. */
  overflow-x: clip;
}

/* Numbers, code, table cells — use mono with tabular figures.
   Table headers (th) keep sans for cleaner uppercase labels. */
.mono,
code, kbd, samp,
td,
.kpi-value, .ticker, .ticker-sym, .symbol,
.price, .price-cell, .edge-num, .edge-val, .score-num, .metric-val,
.flow-type, .prem-val, .zscore-cell, .drr-label,
.tp-value, .sctr-val, .tab-badge, .sub-badge {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-feature-settings: 'tnum' 1, 'zero' 1;
}

/* ── Header ────────────────────────────────────────────────────────────── */
/* Grid: [brand] [market-toggle] [nav stretches] [refresh + date]
   4 explicit tracks so all four siblings sit on a single row regardless of
   how wide each piece grows. The market-toggle was previously a 4th child
   in a 3-track grid, which pushed the refresh-controls block onto a second
   row — that's why the chrome looked wasteful. */
header {
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  padding: 8px 22px;
  display: grid;
  grid-template-columns: auto auto 1fr auto;
  align-items: center;
  position: sticky; top: 0; z-index: 100;
  gap: 14px;
}

.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; color: inherit; }
.brand-logo {
  height: 36px; width: auto;
  display: block;
  filter: drop-shadow(0 1px 3px rgba(0,0,0,0.5));
  transition: transform 0.15s ease;
}
.brand:hover .brand-logo { transform: scale(1.03); }
/* Legacy emoji icon (kept for any pages still using the old block). */
.brand-icon {
  width: 36px; height: 36px;
  background: linear-gradient(135deg, var(--accent), var(--accent-cyan));
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.4), inset 0 1px 0 rgba(255,255,255,0.08);
}
.brand-name { font-size: 15px; font-weight: 700; letter-spacing: 0.2px; }
.brand-sub  { font-size: 11px; color: var(--text-dim); letter-spacing: 0.1px; }

/* Nav pill bar */
.nav-links {
  display: flex; gap: 2px; align-items: center;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 10px; padding: 3px;
  box-shadow: inset 0 1px 4px rgba(0,0,0,0.5);
}
.nav-link {
  display: flex; align-items: center; gap: 5px;
  font-size: 11px; font-weight: 500; color: var(--text-dim);
  text-decoration: none; padding: 5px 10px;
  border-radius: 8px; border: 1px solid transparent;
  transition: color 0.15s, background 0.15s, border-color 0.15s;
  white-space: nowrap; cursor: pointer;
  letter-spacing: 0.1px;
}
.nav-link .nav-icon { font-size: 12px; line-height: 1; opacity: 0.7; transition: opacity 0.15s; }
.nav-link:hover { color: var(--text); background: rgba(255,255,255,0.04); }
.nav-link:hover .nav-icon { opacity: 1; }
.nav-link.active {
  color: #fff; font-weight: 600;
  background: linear-gradient(135deg, var(--accent), var(--accent-cyan));
  border-color: rgba(59,130,246,0.35);
  box-shadow: 0 2px 10px rgba(59,130,246,0.35), 0 1px 2px rgba(0,0,0,0.3);
}
.nav-link.active .nav-icon { opacity: 1; }

/* Anchor links (Dashboard, Sectors) — slightly brighter base color so
   the "context" group reads as the top-down anchor of the nav. */
.nav-link.nav-anchor { color: var(--text); }

/* Subtle vertical divider between nav groups */
.nav-divider {
  display: inline-block; width: 1px; height: 16px;
  background: rgba(255,255,255,0.10);
  margin: 0 4px; align-self: center; flex-shrink: 0;
}

/* Flexible spacer — pushes the "More ⌄" item to the right of the nav */
.nav-spacer { flex: 1 1 auto; min-width: 8px; }

/* "More ⌄" dropdown */
.nav-more { position: relative; }
.nav-more .nav-more-caret { opacity: 0.6; font-size: 11px; }
.nav-dropdown {
  display: none;
  position: absolute; top: calc(100% + 6px); right: 0;
  flex-direction: column; min-width: 200px;
  padding: 6px;
  background: #131722;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.55);
  z-index: 30;
}
.nav-more.open > .nav-dropdown,
.nav-more:hover > .nav-dropdown { display: flex; }
.nav-more.open > .nav-more-trigger,
.nav-more:hover > .nav-more-trigger {
  background: rgba(255,255,255,0.04); color: var(--text);
}
.nav-dropdown-section {
  font: 600 9px "Inter", sans-serif;
  letter-spacing: 0.10em; text-transform: uppercase;
  color: var(--text-faint, #64748b);
  padding: 6px 10px 4px;
}
.nav-dropdown-link {
  display: flex; align-items: center; gap: 8px;
  color: var(--text-dim); text-decoration: none;
  padding: 6px 10px; border-radius: 5px;
  font-size: 12px;
  transition: background 0.12s, color 0.12s;
}
.nav-dropdown-link:hover { background: rgba(255,255,255,0.06); color: var(--text); }
.nav-dropdown-link.active {
  background: linear-gradient(135deg, var(--accent), var(--accent-cyan));
  color: #fff; font-weight: 600;
}

/* Market toggle (US / IN) at header-left */
.market-toggle {
  display: inline-flex; align-items: center;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 999px;
  padding: 2px;
  flex-shrink: 0;
  margin-right: 4px;
}
.market-toggle-btn {
  background: none; border: none;
  padding: 4px 10px; border-radius: 999px;
  font: 600 11px "Inter", system-ui, sans-serif; letter-spacing: 0.02em;
  color: var(--text-dim); cursor: pointer;
  display: inline-flex; align-items: center; gap: 4px;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}
.market-toggle-btn:hover:not(.active) { color: var(--text); }
.market-toggle-btn.active {
  background: linear-gradient(135deg, var(--accent), var(--accent-cyan));
  color: #fff;
  box-shadow: 0 1px 4px rgba(59,130,246,0.45);
}
.market-flag { font-size: 12px; line-height: 1; }

.header-center { display: flex; align-items: center; justify-content: center; gap: 6px; }
/* In-flow flex with two children of fixed/predictable widths: the meta
   stack sits on the left, the refresh widget anchors right. No wrapping;
   below the breakpoint the @media block stacks them. */
.header-right  { display: flex; align-items: center; gap: 14px; justify-content: flex-end; }
/* Minimalist meta: plain text, no pill chrome. Sits inside an
   .rc-meta-stack container that refresh-controls.js inserts on init —
   the stack adds the "Updated Xs ago" line beneath as a dimmed second
   line. We keep .header-meta as a single-row flex item; the column
   stacking lives on the wrapper so page-level JS can freely overwrite
   .header-meta's textContent without disturbing rc-age. */
.header-meta   {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11px; color: var(--text-dim);
  letter-spacing: 0.2px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  flex-shrink: 0;
}
.header-meta strong { color: var(--text); font-weight: 600; white-space: nowrap; }
/* Fixed-width meta stack so the layout is identical across pages
   regardless of date format ("Generated …" / "May 6 at …" / etc.). 215px
   fits "Generated YYYY-MM-DD HH:MM EDT" at the page's monospace 11px;
   shorter content right-aligns within and the widget stays anchored. */
.rc-meta-stack {
  display: inline-flex; flex-direction: column; align-items: flex-end;
  gap: 1px;
  flex-shrink: 0;
  line-height: 1.2;
  width: 215px;
}
.rc-meta-stack #rc-age {
  font-size: 10px; color: var(--text-faint); opacity: 0.85;
  font-family: var(--mono, ui-monospace, monospace);
}

/* Refresh widget sits in normal flow at the right end of header-right.
   No fixed/absolute positioning — it just anchors right via the parent's
   justify-content: flex-end. flex-shrink: 0 keeps it from being squeezed
   when header-center (nav) is wide. */
#refresh-controls {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
}

/* Breadth widget (dashboard) */
.breadth-widget { display: flex; align-items: center; gap: 8px; }
.breadth-label  { font-size: 10px; letter-spacing: 0.5px; text-transform: uppercase; color: var(--text-faint); }
.breadth-track {
  width: 120px; height: 8px;
  background: var(--bear-bg);
  border-radius: 4px; overflow: hidden;
  border: 1px solid var(--border);
}
.breadth-fill-bull { height: 100%; background: var(--strong-bull); border-radius: 4px 0 0 4px; transition: width 0.4s; }
.breadth-legend  { display: flex; gap: 10px; font-size: 10px; align-items: center; flex-wrap: wrap; }
.breadth-bull    { color: var(--strong-bull); font-weight: 700; }
.breadth-bear    { color: var(--bear); font-weight: 700; }
.breadth-neutral { color: var(--text-faint); }
.breadth-delta {
  font-size: 10px; font-weight: 700;
  padding: 1px 6px; border-radius: 4px;
  border: 1px solid transparent;
}
.breadth-delta-up   { color: var(--strong-bull); background: rgba(16,185,129,0.10); border-color: rgba(16,185,129,0.25); }
.breadth-delta-down { color: var(--bear);        background: rgba(239,68,68,0.10);  border-color: rgba(239,68,68,0.25); }
.breadth-delta-flat { color: var(--text-faint);  background: rgba(148,163,184,0.10); border-color: rgba(148,163,184,0.20); }
.breadth-aligned    { color: var(--accent-cyan); font-weight: 700; }

/* Refresh button */
.refresh-btn {
  background: var(--accent); color: #fff !important; border: none;
  padding: 6px 14px; border-radius: 6px; font-size: 11px; cursor: pointer;
  font-family: inherit; text-decoration: none; display: inline-block;
  font-weight: 500; letter-spacing: 0.1px;
  transition: background 0.15s;
}
.refresh-btn:hover { background: var(--accent-hover); }

/* Live indicator */
.live-dot {
  display: inline-block; width: 7px; height: 7px;
  background: var(--strong-bull); border-radius: 50%;
  margin-right: 5px; animation: lattice-pulse 2s infinite;
  box-shadow: 0 0 6px rgba(16,185,129,0.5);
}
@keyframes lattice-pulse { 0%,100%{opacity:1} 50%{opacity:0.3} }
@keyframes pulse         { 0%,100%{opacity:1} 50%{opacity:0.3} }

/* ── Webkit scrollbar (subtle) ─────────────────────────────────────────── */
::-webkit-scrollbar        { width: 8px; height: 8px; }
::-webkit-scrollbar-track  { background: var(--bg2); }
::-webkit-scrollbar-thumb  { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #2e3446; }

/* ── IN-market chrome suppression ───────────────────────────────────────
   /in/* pages hide US-specific chrome since the data is irrelevant:
     - #index-cards (SPY/QQQ/IWM cards, GMI, T2108, IWF, MTUM)
   The body.market-in class is set by header.js on /in/* paths. Provider
   status bar stays — it tells you if Schwab/OD/Y! APIs are healthy,
   which is useful regardless of market. */
body.market-in #index-cards { display: none !important; }
/* SPY/QQQ/IWM eyebrow pills inside provider-status are US-only too —
   they may or may not be present depending on cache state, so this hide
   is defensive. */
body.market-in .lps-idx { display: none !important; }

/* ── Header burger (hidden on desktop, shown on mobile) ───────────────── */
.header-burger {
  display: none;
  flex-direction: column; justify-content: center; gap: 4px;
  width: 36px; height: 36px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: 6px;
  cursor: pointer;
  padding: 8px;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.header-burger:hover { background: rgba(255,255,255,0.08); border-color: rgba(255,255,255,0.18); }
.header-burger .burger-line {
  height: 2px; background: var(--text); border-radius: 1px;
  width: 100%;
  transition: transform 0.2s ease, opacity 0.2s ease;
}
.header-burger.open .burger-line:nth-child(1) { transform: translateY(6px) rotate(45deg); }
.header-burger.open .burger-line:nth-child(2) { opacity: 0; }
.header-burger.open .burger-line:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }

/* Mobile slide-down menu — hidden by default; only renders on mobile.
   Belt-and-suspenders hiding (display:none, visibility:hidden, pointer-events,
   max-height) so cached CSS or unexpected overrides can't leak it onto
   desktop. The mobile media query below explicitly unsets all of these. */
.mobile-menu {
  display: none;
  visibility: hidden;
  pointer-events: none;
  position: absolute; left: 0; right: 0; top: 100%;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 8px 24px rgba(0,0,0,0.45);
  max-height: 0; overflow: hidden;
  transition: max-height 0.25s ease;
  z-index: 99;
}
.mobile-menu.open { max-height: 80vh; overflow-y: auto; }
.mobile-menu .mobile-nav {
  display: flex; flex-direction: column;
  padding: 8px;
  gap: 2px;
}
.mobile-menu .nav-link {
  width: 100%; padding: 11px 14px; font-size: 14px;
  border-radius: 6px;
  justify-content: flex-start;
}
.mobile-menu .nav-divider { display: none; }
.mobile-menu .nav-more {
  display: contents;  /* unwrap so the children render as siblings */
}
.mobile-menu .nav-more-trigger { display: none; }
.mobile-menu .nav-dropdown {
  position: static; display: flex; flex-direction: column;
  background: transparent; border: none; box-shadow: none;
  padding: 4px 0 4px 8px;
  margin-top: 4px;
}
.mobile-menu .nav-dropdown::before {
  content: "Specialized";
  font: 600 9px "Inter", sans-serif;
  letter-spacing: 0.10em; text-transform: uppercase;
  color: var(--text-faint, #64748b);
  padding: 8px 10px 4px;
}
.mobile-menu .nav-dropdown-section { display: none; }
.mobile-menu .nav-dropdown-link {
  padding: 11px 14px; font-size: 14px;
  border-radius: 6px;
}
body.mobile-menu-open { overflow: hidden; }

/* ── Tablet (768-1100px): nav stays inline but compact ─────────────────── */
@media (max-width: 1100px) {
  header {
    padding: 8px 16px;
    gap: 10px;
  }
  .nav-link { padding: 5px 8px; font-size: 11px; gap: 4px; }
  .nav-link .nav-icon { font-size: 12px; }
  .market-toggle-btn { padding: 4px 8px; font-size: 10.5px; }
  .header-meta { font-size: 11px; }
}

/* ── Mobile (≤768px): hamburger menu, hide nav + refresh from header ──── */
@media (max-width: 768px) {
  header {
    grid-template-columns: auto auto 1fr auto;
    padding: 8px 14px;
    gap: 10px;
    position: sticky;
  }
  .header-center,
  .header-right { display: none; }   /* nav + refresh move into the burger panel */
  .header-burger { display: flex; }
  .mobile-menu {
    display: block;
    visibility: visible;
    pointer-events: auto;
  }
  .brand-logo { height: 32px; }
  .market-toggle-btn { padding: 4px 9px; font-size: 11px; }
  .market-flag { font-size: 13px; }
}

/* ── Phone (≤480px): even tighter ─────────────────────────────────────── */
@media (max-width: 480px) {
  header { padding: 7px 12px; gap: 8px; }
  .brand-logo { height: 28px; }
  .market-toggle-btn { padding: 3px 7px; font-size: 10.5px; }
  .market-toggle-btn .market-flag { font-size: 12px; margin-right: 2px; }
  .header-burger { width: 32px; height: 32px; padding: 7px; }
  body { font-size: 12px; }
}
