/**
 * Fineas.ai V2 — SEC Financial Intelligence Platform
 * Premium dark-first fintech UI · Linear/Bloomberg aesthetic
 *
 * Theme: TECH NOIR — near-black ink (#050608) + deep sapphire (#4f82f3)
 * Typography: Schibsted Grotesk (UI), Spline Sans Mono (numbers/data)
 * Layout: 3-column (sidebar 240px | main flex | chat 380px)
 */

/* ═══════════════════════════════════════════════════════════════
   CSS VARIABLES
   ═══════════════════════════════════════════════════════════════ */

/* ── TECH NOIR ──────────────────────────────────────────────────
   Near-black ink, hairline structure, ONE deep-sapphire accent.
   Depth comes from shadow, never glow — the data is the light.   */
:root {
  /* Backgrounds — zinc planes (matches the /filings reader design language) */
  --bg-primary: #09090b;
  --bg-secondary: #0e0e10;
  --bg-tertiary: #18181b;
  --bg-elevated: #121215;
  --bg-hover: rgba(255, 255, 255, 0.04);

  /* Text — zinc hierarchy */
  --text-primary: #f4f4f5;
  --text-secondary: #a1a1aa;
  --text-tertiary: #71717a;
  --text-muted: #52525b;

  /* Borders — hairlines are the structural language of the UI */
  --border: #27272a;
  --border-light: #1f1f23;

  /* Brand — one blue, used sparingly */
  --brand: #3b82f6;
  --brand-light: #60a5fa;
  --brand-dark: #2563eb;
  --brand-bg: rgba(59, 130, 246, 0.08);
  --brand-bg-strong: rgba(59, 130, 246, 0.16);

  /* Semantic — emerald / red / amber, desaturated on ink */
  --success: #10b981;
  --success-bg: rgba(16, 185, 129, 0.08);
  --danger: #ef4444;
  --danger-bg: rgba(239, 68, 68, 0.08);
  --warning: #f59e0b;
  --warning-bg: rgba(245, 158, 11, 0.08);
  --info: #3b82f6;
  --info-bg: rgba(59, 130, 246, 0.08);

  /* Effects — shadow for depth; glows retired */
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.45);
  --shadow: 0 6px 18px rgba(0,0,0,0.5);
  --shadow-lg: 0 18px 50px rgba(0,0,0,0.6);
  --glow: none;
  --glow-strong: none;
  --glass-bg: rgba(8, 10, 13, 0.72);
  --glass-border: rgba(165, 184, 212, 0.07);
  --inner-glow: inset 0 1px 0 rgba(255,255,255,0.025);

  /* Radius — a touch sharper */
  --radius: 8px;
  --radius-lg: 12px;
  --radius-sm: 5px;

  /* Typography — Inter (UI) / Spline Sans Mono (figures) */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'Spline Sans Mono', 'JetBrains Mono', 'Courier New', monospace;

  /* Transitions */
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --t-fast: 0.15s var(--ease);
  --t-normal: 0.25s var(--ease);
  --t-slow: 0.35s var(--ease);
}

/* Light theme */
[data-theme="light"] {
  /* Light mode keeps the noir attitude: warm-gray paper, same single
     accent family pulled deep enough for contrast on white. */
  --bg-primary: #f7f7f5;
  --bg-secondary: #ffffff;
  --bg-tertiary: #efefec;
  --bg-elevated: #ffffff;
  --bg-hover: rgba(29, 78, 216, 0.05);
  --text-primary: #14181d;
  --text-secondary: #4d565f;
  --text-tertiary: #8a929b;
  --text-muted: #c2c8ce;
  --border: rgba(20, 24, 29, 0.10);
  --border-light: rgba(20, 24, 29, 0.05);
  --brand: #1d4ed8;
  --brand-light: #3b82f6;
  --brand-dark: #1e40af;
  --brand-bg: rgba(29, 78, 216, 0.06);
  --brand-bg-strong: rgba(29, 78, 216, 0.12);
  --success-bg: rgba(22, 163, 74, 0.07);
  --danger-bg: rgba(220, 38, 38, 0.07);
  --warning-bg: rgba(217, 119, 6, 0.07);
  --info-bg: rgba(29, 78, 216, 0.06);
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
  --shadow: 0 4px 16px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.12);
  --glow: none;
}

/* ═══════════════════════════════════════════════════════════════
   RESET & BASE
   ═══════════════════════════════════════════════════════════════ */

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

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  letter-spacing: -0.011em;
  overflow: hidden;
  text-rendering: optimizeLegibility;
  font-feature-settings: 'cv02', 'cv03', 'cv04', 'cv11';
}

::selection {
  background: var(--brand);
  color: white;
}

:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

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

a { color: var(--brand-light); text-decoration: none; }
a:hover { color: var(--brand); }

/* ═══════════════════════════════════════════════════════════════
   APP SHELL — 3-column layout
   ═══════════════════════════════════════════════════════════════ */

.app {
  display: flex;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
  background: var(--bg-primary);
}

/* ═══════════════════════════════════════════════════════════════
   SIDEBAR (LEFT, 240px)
   ═══════════════════════════════════════════════════════════════ */

.sidebar {
  width: 240px;
  min-width: 240px;
  background: linear-gradient(180deg, var(--bg-secondary) 0%, rgba(17, 24, 39, 0.95) 100%);
  border-right: 1px solid var(--glass-border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  flex-shrink: 0;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  transition: width 0.25s ease, min-width 0.25s ease, opacity 0.2s ease;
}

.sidebar.collapsed {
  width: 0;
  min-width: 0;
  overflow: hidden;
  opacity: 0;
  border-right: none;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 16px 16px;
  border-bottom: 1px solid var(--border-light);
}

.brand-icon {
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, var(--brand) 0%, var(--brand-light) 100%);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  box-shadow: 0 2px 12px rgba(79, 130, 243, 0.35), 0 0 20px rgba(79, 130, 243, 0.15);
}

.brand-icon svg { width: 18px; height: 18px; }

.brand-text {
  display: flex;
  align-items: baseline;
  gap: 1px;
}

.brand-name {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.brand-sub {
  font-size: 16px;
  font-weight: 700;
  color: var(--brand);
}

/* Navigation */
.sidebar-nav {
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  border: 1px solid transparent;
  background: none;
  width: 100%;
  text-align: left;
  position: relative;
}

.nav-item svg, .nav-item i { width: 16px; height: 16px; flex-shrink: 0; opacity: 0.7; transition: opacity 0.2s ease; }

.nav-item:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  transform: translateX(2px);
}

.nav-item:hover svg, .nav-item:hover i { opacity: 1; }

.nav-item.active {
  background: var(--brand-bg);
  color: var(--brand);
  font-weight: 600;
  border-color: rgba(79, 130, 243, 0.15);
  box-shadow: inset 3px 0 0 var(--brand);
}

.nav-item.active svg, .nav-item.active i { opacity: 1; }

.nav-badge {
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 2px 5px;
  border-radius: 4px;
  background: var(--brand);
  color: white;
  margin-left: auto;
}

/* Sidebar sections */
.sidebar-section {
  padding: 8px;
  border-top: 1px solid var(--border-light);
  margin-top: 8px;
}

.section-title {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-tertiary);
  padding: 8px 12px 6px;
}

.watchlist {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.research-folders {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.research-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  color: var(--text-secondary);
  transition: background var(--t-fast), color var(--t-fast);
}

.research-item:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.research-item .research-icon {
  color: var(--brand);
  flex-shrink: 0;
  width: 14px;
  height: 14px;
}

.research-item .research-info {
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

.research-item .research-ticker {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 11px;
  color: var(--text-primary);
}

.research-item .research-name {
  font-size: 10px;
  color: var(--text-tertiary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.research-item .research-date {
  font-size: 9px;
  color: var(--text-muted);
  white-space: nowrap;
}

.research-item .research-delete {
  opacity: 0;
  padding: 2px;
  border: none;
  background: none;
  color: var(--text-muted);
  cursor: pointer;
  transition: opacity var(--t-fast), color var(--t-fast);
  flex-shrink: 0;
}

.research-item:hover .research-delete {
  opacity: 1;
}

.research-item .research-delete:hover {
  color: var(--danger);
}

.research-item .query-count {
  font-size: 9px;
  font-weight: 600;
  color: var(--brand-light);
  background: var(--brand-bg);
  padding: 1px 5px;
  border-radius: 8px;
  white-space: nowrap;
  flex-shrink: 0;
}

.research-queries {
  display: none;
  flex-direction: column;
  gap: 2px;
  padding: 2px 0 4px 22px;
}

.research-queries.expanded {
  display: flex;
  animation: fadeIn 0.2s ease forwards;
}

.research-query {
  font-size: 11px;
  color: var(--text-tertiary);
  padding: 3px 8px;
  border-radius: 4px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background var(--t-fast), color var(--t-fast);
}

.research-query:hover {
  background: var(--brand-bg);
  color: var(--text-primary);
}

.research-expand-icon {
  flex-shrink: 0;
  width: 12px;
  height: 12px;
  color: var(--text-muted);
  transition: transform 0.2s ease;
}

.research-item.expanded .research-expand-icon {
  transform: rotate(90deg);
}

.sidebar-footer {
  margin-top: auto;
  padding: 8px;
  border-top: 1px solid var(--border-light);
}

/* ═══════════════════════════════════════════════════════════════
   MAIN CONTENT AREA
   ═══════════════════════════════════════════════════════════════ */

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
  transition: all 0.3s ease;
}

/* ─── Header ─── */
.header {
  flex-shrink: 0;
  background: rgba(17, 24, 39, 0.8);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--glass-border);
  z-index: 100;
  position: relative;
}

.header-top {
  display: flex;
  align-items: center;
  position: relative;
  z-index: 101;
  gap: 16px;
  padding: 12px 20px;
}

/* Search bar */
.search-bar {
  flex: 1;
  max-width: 480px;
  position: relative;
  z-index: 999;
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(10, 15, 30, 0.6);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  padding: 0 14px;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.search-bar:focus-within {
  border-color: rgba(79, 130, 243, 0.4);
  box-shadow: 0 0 0 3px var(--brand-bg), var(--glow);
  background: rgba(10, 15, 30, 0.8);
}

.search-bar svg, .search-bar i { color: var(--text-tertiary); width: 16px; height: 16px; flex-shrink: 0; }

.search-bar input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 13px;
  padding: 10px 0;
}

.search-bar input::placeholder { color: var(--text-tertiary); }

.search-bar kbd {
  font-family: var(--font-mono);
  font-size: 10px;
  padding: 2px 6px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-tertiary);
  font-weight: 600;
}

/* Search results dropdown */
.search-results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 12px 40px rgba(0,0,0,0.6);
  z-index: 9999;
  max-height: 360px;
  overflow-y: auto;
  display: none;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.sr-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  cursor: pointer;
  transition: background var(--t-fast);
  border-bottom: 1px solid var(--border-light);
}

.sr-item:last-child { border-bottom: none; }
.sr-item:hover { background: var(--bg-hover); }

.sr-ticker {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  color: var(--brand-light);
  min-width: 56px;
}

.sr-name {
  font-size: 13px;
  color: var(--text-secondary);
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sr-exchange {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-tertiary);
  padding: 2px 6px;
  background: var(--bg-tertiary);
  border-radius: 4px;
}

/* Company pill */
.company-pill {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 14px;
  background: var(--brand-bg);
  border: 1px solid rgba(79, 130, 243, 0.15);
  border-radius: 20px;
  flex-shrink: 0;
}

.ticker-badge {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  color: var(--brand-light);
  padding: 2px 8px;
  background: var(--brand-bg-strong);
  border-radius: 4px;
}

.company-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
}

.pill-divider {
  width: 1px;
  height: 20px;
  background: var(--border);
}

.price {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

.price-change {
  display: flex;
  align-items: center;
  gap: 3px;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
}

.price-change svg, .price-change i { width: 14px; height: 14px; }
.price-change.positive, .positive { color: var(--success); }
.price-change.negative, .negative { color: var(--danger); }

.live-dot {
  width: 6px;
  height: 6px;
  background: var(--success);
  border-radius: 50%;
  animation: pulse 2s ease-in-out infinite;
}

/* Header actions */
.header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
}

.icon-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--t-fast);
  position: relative;
  padding: 0;
}

.icon-btn svg, .icon-btn i { width: 18px; height: 18px; }
.icon-btn:hover { background: var(--bg-tertiary); color: var(--text-primary); border-color: var(--border); }
.icon-btn.active { background: var(--brand-bg); color: var(--brand); border-color: rgba(79, 130, 243, 0.2); }

.icon-btn.has-badge::after {
  content: '';
  position: absolute;
  top: 7px;
  right: 7px;
  width: 7px;
  height: 7px;
  background: var(--danger);
  border-radius: 50%;
  border: 2px solid var(--bg-secondary);
}

/* ─── Header tabs ─── */
.header-tabs {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  border-top: 1px solid var(--border-light);
  overflow-x: auto;
}

.view-tabs {
  display: flex;
  gap: 0;
}

.view-tab {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 14px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--t-fast);
  white-space: nowrap;
}

.view-tab svg, .view-tab i { width: 14px; height: 14px; }
.view-tab:hover { color: var(--text-primary); background: var(--bg-hover); }

.view-tab.active {
  color: var(--brand);
  border-bottom-color: var(--brand);
  font-weight: 600;
}

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

/* Toggle group */
.toggle-group {
  display: flex;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.toggle-btn {
  padding: 6px 12px;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 11.5px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--t-fast);
}

.toggle-btn:hover { color: var(--text-primary); }

.toggle-btn.active {
  background: var(--brand);
  color: white;
}

/* Select dropdowns */
.sel {
  appearance: none;
  padding: 6px 28px 6px 10px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 11.5px;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill='%234f82f3' d='M8 11L3 6h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  background-size: 12px;
  transition: all var(--t-fast);
}

.sel:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-bg); }

/* ─── Content area ─── */
.content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 24px;
}

/* ═══════════════════════════════════════════════════════════════
   WELCOME STATE
   ═══════════════════════════════════════════════════════════════ */

.welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  text-align: center;
  animation: fadeInUp 0.5s var(--ease);
}

.welcome-icon {
  width: 72px;
  height: 72px;
  background: linear-gradient(135deg, var(--brand-bg) 0%, var(--brand-bg-strong) 100%);
  border: 1px solid rgba(79, 130, 243, 0.15);
  border-radius: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 28px;
  color: var(--brand);
  box-shadow: var(--glow-strong);
  animation: floatGlow 3s ease-in-out infinite;
}

.welcome-icon svg, .welcome-icon i { width: 32px; height: 32px; }

.welcome h2 {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 8px;
  letter-spacing: -0.02em;
}

.welcome p {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 28px;
  max-width: 400px;
}

.welcome-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-bottom: 24px;
}

.pill {
  padding: 8px 16px;
  background: rgba(17, 24, 39, 0.6);
  border: 1px solid var(--glass-border);
  border-radius: 20px;
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.pill:hover {
  background: var(--brand-bg);
  border-color: rgba(79, 130, 243, 0.25);
  color: var(--brand-light);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(79, 130, 243, 0.15), var(--glow);
}

.welcome-note {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-tertiary);
  padding: 8px 14px;
  background: var(--bg-secondary);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-light);
}

.welcome-note svg, .welcome-note i { width: 14px; height: 14px; color: var(--brand); }

.welcome-chat {
  display: flex;
  gap: 8px;
  max-width: 520px;
  margin: 24px auto 16px;
  width: 100%;
}

.welcome-chat input {
  flex: 1;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: 14px;
  color: var(--text-primary);
  font-family: var(--font-sans);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.welcome-chat input::placeholder {
  color: var(--text-tertiary);
}

.welcome-chat input:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-bg);
}

.welcome-chat .send-btn {
  padding: 12px 24px;
  font-size: 14px;
  font-weight: 600;
}

/* ═══════════════════════════════════════════════════════════════
   DASHBOARD
   ═══════════════════════════════════════════════════════════════ */

.dashboard { animation: fadeIn 0.3s var(--ease); }

/* KPI Cards */
/* Hero row: FOUR big cards. Everything else lives in the compact chip
   strip below — the old 13-tile wall read as clutter. */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 12px;
}

/* Secondary metrics: one quiet row of stat chips, click to drill */
.kpi-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 20px;
}
.stat-chip {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 8px 14px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  transition: border-color var(--t-fast), background var(--t-fast);
}
.stat-chip:hover { border-color: var(--brand); background: var(--bg-hover); }
.stat-chip .c-label { font-size: 11px; font-weight: 600; color: var(--text-tertiary);
                      text-transform: uppercase; letter-spacing: 0.5px; }
.stat-chip .c-value { font-family: var(--font-mono); font-size: 14px; font-weight: 600;
                      color: var(--text-primary); }
.stat-chip .c-delta { font-family: var(--font-mono); font-size: 11px; font-weight: 600; }
.stat-chip .c-delta.positive { color: var(--success); }
.stat-chip .c-delta.negative { color: var(--danger); }

/* Drill-down drawer: one metric, full history, provenance — opened by
   clicking any card or chip */
#kpi-drill {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
  margin-bottom: 24px;
  animation: fadeInUp 0.3s var(--ease) backwards;
}
#kpi-drill .drill-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}
#kpi-drill .drill-title { font-size: 15px; font-weight: 700; letter-spacing: -0.01em; }
#kpi-drill .drill-meta { color: var(--text-tertiary); font-size: 12px; margin-right: auto; }
#kpi-drill .drill-close {
  background: none; border: 1px solid var(--border); border-radius: 8px;
  color: var(--text-secondary); padding: 4px 10px; cursor: pointer; font-size: 12px;
}
#kpi-drill .drill-close:hover { color: var(--text-primary); border-color: var(--brand); }
#kpi-drill .drill-chart-wrap { height: 260px; }
#kpi-drill .drill-prov { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 12px;
                         font-size: 12px; color: var(--text-tertiary); }
#kpi-drill .drill-prov code { color: var(--text-secondary); background: var(--bg-tertiary);
                              padding: 1px 6px; border-radius: 5px; font-size: 11px; }

.kpi-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px;
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: var(--inner-glow);
}

.kpi-card::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: var(--radius);
  padding: 1px;
  background: linear-gradient(135deg, rgba(79, 130, 243, 0.1) 0%, transparent 50%, rgba(79, 130, 243, 0.05) 100%);
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.kpi-card::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--brand) 0%, var(--brand-light) 50%, rgba(139, 92, 246, 0.8) 100%);
  opacity: 0;
  transition: opacity 0.25s ease;
}

.kpi-card:hover {
  border-color: rgba(79, 130, 243, 0.12);
  box-shadow: var(--shadow), var(--inner-glow);
  transform: translateY(-2px);
}

.kpi-card:hover::before { opacity: 1; }
.kpi-card:hover::after { opacity: 1; }

.kpi-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.kpi-icon {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
}

.kpi-icon svg, .kpi-icon i { width: 16px; height: 16px; }

.kpi-icon.brand { background: var(--brand-bg); color: var(--brand); }
.kpi-icon.emerald { background: var(--success-bg); color: var(--success); }
.kpi-icon.blue { background: var(--info-bg); color: var(--info); }
.kpi-icon.violet { background: rgba(139, 92, 246, 0.1); color: #8b5cf6; }
.kpi-icon.amber { background: var(--warning-bg); color: var(--warning); }
.kpi-icon.rose { background: rgba(244, 63, 94, 0.1); color: #f43f5e; }

.kpi-change {
  display: flex;
  align-items: center;
  gap: 2px;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
}

.kpi-change svg, .kpi-change i { width: 14px; height: 14px; }
.kpi-change.positive { color: var(--success); }
.kpi-change.negative { color: var(--danger); }

.kpi-value {
  font-family: var(--font-mono);
  font-size: 32px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 4px;
  line-height: 1.1;
  letter-spacing: -0.03em;
  background: linear-gradient(135deg, var(--text-primary) 0%, rgba(241, 245, 249, 0.8) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.kpi-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Staggered entrance animation */
.animate-in {
  animation: fadeInUp 0.5s var(--ease) backwards;
}

.kpi-card:nth-child(1) { animation: fadeInUp 0.4s var(--ease) 0.05s backwards; }
.kpi-card:nth-child(2) { animation: fadeInUp 0.4s var(--ease) 0.1s backwards; }
.kpi-card:nth-child(3) { animation: fadeInUp 0.4s var(--ease) 0.15s backwards; }
.kpi-card:nth-child(4) { animation: fadeInUp 0.4s var(--ease) 0.2s backwards; }
.kpi-card:nth-child(5) { animation: fadeInUp 0.4s var(--ease) 0.25s backwards; }
.kpi-card:nth-child(6) { animation: fadeInUp 0.4s var(--ease) 0.3s backwards; }

/* Charts */
.charts-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 14px;
  min-width: 0;
  overflow: hidden;
}

.charts-row:has(.wide) {
  grid-template-columns: 3fr 2fr;
}

.chart-card {
  background: linear-gradient(180deg, var(--bg-secondary) 0%, rgba(17, 24, 39, 0.85) 100%);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  padding: 20px;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
  min-width: 0;
  box-shadow: var(--inner-glow), 0 2px 8px rgba(0,0,0,0.15);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.chart-card:hover {
  border-color: rgba(79, 130, 243, 0.12);
  box-shadow: var(--inner-glow), var(--shadow);
}
.chart-card.wide { /* handled by parent grid */ }

/* Constrain chart canvases */
.chart-card canvas {
  width: 100% !important;
  min-height: 280px;
  max-height: 360px;
  display: block;
}

.chart-card.wide canvas {
  min-height: 280px;
  max-height: 360px;
}

.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 14px;
  gap: 12px;
}

.card-header h3 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.card-subtitle {
  font-size: 11px;
  color: var(--text-tertiary);
  margin-top: 2px;
}

/* Chart legend */
.legend {
  display: flex;
  gap: 12px;
  flex-shrink: 0;
}

.legend-item {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}

.legend-item::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 2px;
  background: var(--color);
}

/* Segment legend */
.segment-legend {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.seg-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
}

.seg-dot {
  width: 8px;
  height: 8px;
  border-radius: 2px;
  flex-shrink: 0;
}

.seg-name {
  color: var(--text-secondary);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.seg-val {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-tertiary);
  min-width: 55px;
  text-align: right;
}

.seg-pct {
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--text-primary);
  min-width: 38px;
  text-align: right;
  font-size: 11px;
}

/* Text button */
.text-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  background: none;
  border: none;
  color: var(--brand);
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: color var(--t-fast);
  padding: 0;
}

.text-btn:hover { color: var(--brand-light); }
.text-btn svg, .text-btn i { width: 14px; height: 14px; }

/* Data tables */
.data-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
}

.data-table thead th {
  padding: 10px 14px;
  text-align: left;
  font-size: 10px;
  font-weight: 700;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-primary);
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 2;
}

.data-table thead th.right { text-align: right; }

.data-table tbody td {
  padding: 10px 14px;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border-light);
  vertical-align: middle;
  transition: background 0.15s ease;
}

.data-table tbody tr:nth-child(even) { background: rgba(148, 163, 184, 0.02); }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: rgba(79, 130, 243, 0.06); }
.data-table tbody tr:hover td { color: var(--text-primary); }

/* Statement rows */
.stmt-label { color: var(--text-secondary); font-weight: 500; }
.stmt-value { font-family: var(--font-mono); font-weight: 500; text-align: right; }
.stmt-change { font-family: var(--font-mono); font-weight: 600; text-align: right; }

/* ─── Inline statement tables (10-K Explorer → Financial Statements) ─── */
.inline-stmt-wrap {
  display: flex;
  flex-direction: column;
  gap: 24px;
  margin-bottom: 12px;
}
.inline-stmt-block {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.inline-stmt-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 14px 20px 12px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(99,102,241,0.05), transparent);
}
.inline-stmt-title {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--text-primary);
  text-transform: uppercase;
}
.inline-stmt-period {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-secondary);
  letter-spacing: 0.04em;
}
.inline-stmt-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.inline-stmt-table thead th {
  padding: 10px 16px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
  text-align: left;
  background: rgba(0,0,0,0.15);
}
.inline-stmt-table thead th.inline-stmt-num,
.inline-stmt-table thead th.inline-stmt-change { text-align: right; }
.inline-stmt-table tbody tr { transition: background 120ms ease; }
.inline-stmt-table tbody tr:nth-child(even) { background: rgba(255,255,255,0.015); }
.inline-stmt-table tbody tr:hover { background: rgba(99,102,241,0.08); }
.inline-stmt-table td { padding: 9px 16px; border: none; }
.inline-stmt-label {
  color: var(--text-secondary);
  font-weight: 500;
  letter-spacing: 0.01em;
}
.inline-stmt-num {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-weight: 500;
  text-align: right;
  color: var(--text-primary);
  white-space: nowrap;
}
.inline-stmt-num.muted { color: var(--text-secondary); font-weight: 400; }
.inline-stmt-change {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  text-align: right;
  white-space: nowrap;
  width: 90px;
}
.inline-stmt-row.is-total td {
  font-weight: 700;
  color: var(--text-primary);
}
.inline-stmt-row.is-total .inline-stmt-label { color: var(--text-primary); }
.inline-stmt-row.is-total .inline-stmt-num.muted { color: var(--text-secondary); font-weight: 500; }
.inline-stmt-row.has-divider td {
  border-top: 1px solid var(--border);
}
.inline-stmt-row.is-subtle td { opacity: 0.7; font-size: 12px; }
.inline-stmt-raw {
  margin-top: 8px;
  padding: 10px 14px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.inline-stmt-raw > summary {
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-secondary);
  user-select: none;
  list-style: none;
  padding: 4px 0;
}
.inline-stmt-raw > summary::-webkit-details-marker { display: none; }
.inline-stmt-raw > summary::before {
  content: "▸";
  display: inline-block;
  margin-right: 8px;
}
.inline-stmt-raw[open] > summary::before { content: "▾"; }
.inline-stmt-raw-body { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); }

/* Peer table */
.peer-name {
  font-weight: 600;
  color: var(--brand-light);
  font-family: var(--font-mono);
}

/* Provenance bar */
.provenance {
  margin-bottom: 16px;
  padding: 10px 14px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.prov-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.prov-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 500;
}

.prov-badge svg, .prov-badge i { width: 13px; height: 13px; }
.prov-badge.success { background: var(--success-bg); color: var(--success); }
.prov-badge.warning { background: var(--warning-bg); color: var(--warning); }
.prov-badge.neutral { background: var(--bg-tertiary); color: var(--text-secondary); }
.prov-badge.brand { background: var(--brand-bg); color: var(--brand); }

/* Source badges on KPI cards */
.source-badge { display: inline-flex; align-items: center; gap: 3px; font-size: 10px; padding: 2px 6px; border-radius: 4px; font-weight: 600; letter-spacing: 0.3px; }
.source-badge svg, .source-badge i { width: 10px; height: 10px; }
.source-sec { background: rgba(16,185,129,0.12); color: #10b981; }
.source-verified { background: rgba(99,102,241,0.12); color: #82a8f7; }
.source-web { background: rgba(245,158,11,0.12); color: #f59e0b; }
.source-unverified { background: rgba(148,163,184,0.08); color: #64748b; }
.kpi-source-badges { display: flex; gap: 4px; margin-top: 6px; flex-wrap: wrap; }

/* Web context card (Perplexity market context) */
.web-context-card {
  margin-bottom: 16px;
  padding: 14px 16px;
  background: var(--bg-secondary);
  border: 1px solid rgba(245,158,11,0.25);
  border-left: 3px solid #f59e0b;
  border-radius: var(--radius);
}
.web-context-header { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.web-context-header > svg, .web-context-header > i { width: 16px; height: 16px; color: #f59e0b; }
.web-context-disclaimer { font-size: 11px; color: #f59e0b; font-weight: 500; font-style: italic; }
.web-context-title { font-size: 14px; font-weight: 700; color: var(--text-primary); margin: 0 0 8px 0; }
.web-context-body { font-size: 13px; line-height: 1.6; color: var(--text-secondary); }
.web-context-body p { margin: 0 0 6px 0; }
.web-citations { margin-top: 10px; font-size: 11px; color: var(--text-tertiary); }
.web-citations a { color: #f59e0b; text-decoration: none; margin-right: 4px; }
.web-citations a:hover { text-decoration: underline; }

/* View panels (filings text, comps, insights) */
.view-panel {
  padding: 8px 0;
  animation: fadeIn 0.3s var(--ease);
}

/* Comparison grid */
.comparison-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 12px;
}

.comp-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.comp-ticker {
  font-family: var(--font-mono);
  font-size: 16px;
  font-weight: 700;
  color: var(--brand-light);
  margin-bottom: 8px;
}

.comp-metric {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

/* Filing text */
.filing-text {
  padding: 16px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.filing-text pre {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-secondary);
  white-space: pre-wrap;
  word-wrap: break-word;
  line-height: 1.6;
}

/* ── Company Overview Card ── */
/* Overview split: metrics left, segments right */
.overview-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.overview-left {
  overflow-y: auto;
  max-height: 450px;
}

.overview-right {
  border-left: 1px solid var(--border);
  padding-left: 20px;
}

@media (max-width: 900px) {
  .overview-split {
    grid-template-columns: 1fr;
  }
  .overview-right {
    border-left: none;
    padding-left: 0;
    border-top: 1px solid var(--border);
    padding-top: 16px;
  }
}

.company-overview {
  font-size: 13px;
  line-height: 1.6;
  overflow-y: auto;
  max-height: 450px;
}

/* 3-column compact overview */
.overview-3col {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 16px;
}

.ov-col {
  min-width: 0;
}

.ov-section-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.6px;
  color: var(--text-tertiary);
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.ov-col:not(:first-child) {
  border-left: 1px solid var(--border-light);
  padding-left: 16px;
}

@media (max-width: 900px) {
  .overview-3col {
    grid-template-columns: 1fr;
  }
  .ov-col:not(:first-child) {
    border-left: none;
    padding-left: 0;
    border-top: 1px solid var(--border-light);
    padding-top: 10px;
  }
}

.overview-section {
  margin-bottom: 14px;
}
.overview-section:last-child {
  margin-bottom: 0;
}

.overview-label {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.overview-text {
  font-size: 13px;
  color: var(--text-secondary);
  margin: 0;
  line-height: 1.5;
}
.overview-text strong {
  color: var(--text-primary);
}

.overview-metrics {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 8px;
}

.ov-metric {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 6px 8px;
  background: var(--bg-primary);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-light);
}

.ov-val {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}
.ov-val.positive { color: var(--success); }
.ov-val.negative { color: var(--danger); }

.ov-key {
  font-size: 10px;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

/* Bloomberg-style metrics grid for company overview */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  background: var(--border-light);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.metric-item {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 6px 8px;
  background: var(--bg-primary);
  border-radius: 4px;
}

.metric-item .metric-label {
  font-size: 9px;
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

.metric-item .metric-value {
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.metric-item .metric-value.positive { color: var(--success); }
.metric-item .metric-value.negative { color: var(--danger); }

/* Statement preview */
#statement-preview {
  margin-top: 12px;
}

/* ═══════════════════════════════════════════════════════════════
   CHAT PANEL (RIGHT, 380px)
   ═══════════════════════════════════════════════════════════════ */

.chat-panel {
  width: 0;
  min-width: 0;
  overflow: hidden;
  opacity: 0;
  background: linear-gradient(180deg, var(--bg-secondary) 0%, rgba(10, 15, 30, 0.98) 100%);
  border-left: 1px solid transparent;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1),
              min-width 0.3s cubic-bezier(0.4, 0, 0.2, 1),
              opacity 0.2s ease,
              border-color 0.3s ease;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.chat-panel.open {
  width: 380px;
  min-width: 380px;
  opacity: 1;
  border-left-color: var(--glass-border);
}

.chat-header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.chat-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.chat-icon {
  width: 28px;
  height: 28px;
  background: linear-gradient(135deg, var(--brand) 0%, var(--brand-light) 100%);
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
}

.chat-icon svg, .chat-icon i { width: 14px; height: 14px; }

.chat-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  display: block;
}

.chat-subtitle {
  font-size: 11px;
  color: var(--text-tertiary);
  display: block;
}

/* Messages */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.chat-welcome {
  text-align: center;
  padding: 32px 16px;
  color: var(--text-secondary);
}

.chat-welcome p { margin-bottom: 4px; font-size: 13px; }
.chat-welcome .small { font-size: 12px; color: var(--text-tertiary); }

/* Message bubbles */
.msg {
  max-width: 88%;
  animation: fadeInUp 0.2s var(--ease);
}

.msg-user {
  align-self: flex-end;
}

.msg-assistant, .msg-ai {
  align-self: flex-start;
  max-width: 100%;
}

.msg-bubble {
  padding: 11px 15px;
  border-radius: var(--radius-lg);
  font-size: 13px;
  line-height: 1.55;
  word-wrap: break-word;
  overflow-x: auto;
  max-width: 100%;
  transition: box-shadow 0.2s ease;
}

.msg-user .msg-bubble {
  background: linear-gradient(135deg, var(--brand) 0%, var(--brand-dark) 100%);
  color: white;
  border-bottom-right-radius: 4px;
  box-shadow: 0 2px 8px rgba(79, 130, 243, 0.25);
}

.msg-assistant .msg-bubble, .msg-ai .msg-bubble {
  background: rgba(30, 41, 59, 0.7);
  border: 1px solid var(--glass-border);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.msg-bubble strong { font-weight: 600; }

.msg-bubble code {
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 2px 5px;
  background: rgba(0,0,0,0.2);
  border-radius: 3px;
}

.msg-assistant .msg-bubble code, .msg-ai .msg-bubble code {
  background: var(--bg-primary);
  color: var(--brand-light);
}

/* ── Markdown content inside chat bubbles ── */
.msg-bubble h1, .msg-bubble h2, .msg-bubble h3, .msg-bubble h4 {
  margin: 12px 0 6px 0;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.3;
}
.msg-bubble h1:first-child, .msg-bubble h2:first-child,
.msg-bubble h3:first-child, .msg-bubble h4:first-child {
  margin-top: 0;
}
.msg-bubble h1 { font-size: 16px; }
.msg-bubble h2 { font-size: 14px; }
.msg-bubble h3 { font-size: 13px; color: var(--brand-light); }
.msg-bubble h4 { font-size: 12px; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.5px; }

.msg-bubble p {
  margin: 0 0 8px 0;
}
.msg-bubble p:last-child {
  margin-bottom: 0;
}

.msg-bubble ul, .msg-bubble ol {
  margin: 6px 0;
  padding-left: 20px;
}
.msg-bubble li {
  margin-bottom: 3px;
}

.msg-bubble .table-wrap {
  overflow-x: auto;
  margin: 8px -4px;
  padding: 0 4px;
}
.msg-bubble table {
  width: 100%;
  border-collapse: collapse;
  margin: 8px 0;
  font-size: 11px;
  font-family: var(--font-mono);
  table-layout: auto;
}
.msg-bubble thead th {
  text-align: left;
  padding: 5px 8px;
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  white-space: nowrap;
}
.msg-bubble tbody td {
  padding: 4px 8px;
  border-bottom: 1px solid var(--border-light);
  color: var(--text-primary);
  white-space: normal;
  word-break: break-word;
}
.msg-bubble tbody td:not(:first-child) {
  white-space: nowrap;
  text-align: right;
}
.msg-bubble tbody tr:last-child td {
  border-bottom: none;
}
.msg-bubble tbody tr:hover {
  background: var(--bg-hover);
}

.msg-bubble pre {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin: 8px 0;
  overflow-x: auto;
  font-size: 12px;
}
.msg-bubble pre code {
  background: none;
  padding: 0;
  font-size: 12px;
}

.msg-bubble blockquote {
  border-left: 3px solid var(--brand);
  margin: 8px 0;
  padding: 4px 12px;
  color: var(--text-secondary);
  font-style: italic;
}

.msg-bubble hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 10px 0;
}

/* Typing indicator */
.msg-loading .msg-bubble {
  display: flex;
  gap: 4px;
  padding: 14px 18px;
}

.typing-dot {
  width: 6px;
  height: 6px;
  background: var(--text-tertiary);
  border-radius: 50%;
  animation: typingBounce 1.4s ease-in-out infinite;
}

.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

/* Chat chips */
.chat-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 16px 8px;
}

.chip {
  padding: 6px 12px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 11.5px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--t-fast);
  white-space: nowrap;
}

.chip:hover {
  background: var(--brand-bg);
  border-color: rgba(79, 130, 243, 0.2);
  color: var(--brand);
}

.chip.highlight {
  border-color: rgba(79, 130, 243, 0.25);
  color: var(--brand);
}

/* Chat input */
.chat-input {
  display: flex;
  gap: 8px;
  padding: 14px 16px;
  border-top: 1px solid var(--glass-border);
  background: rgba(10, 15, 30, 0.4);
}

.chat-input input {
  flex: 1;
  padding: 11px 16px;
  background: rgba(10, 15, 30, 0.6);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 13px;
  outline: none;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.chat-input input::placeholder { color: var(--text-tertiary); }
.chat-input input:focus { border-color: rgba(79, 130, 243, 0.4); box-shadow: 0 0 0 3px var(--brand-bg), var(--glow); }

.send-btn {
  padding: 8px 18px;
  background: linear-gradient(135deg, var(--brand) 0%, var(--brand-dark) 100%);
  border: none;
  border-radius: var(--radius);
  color: white;
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(79, 130, 243, 0.3);
}

.send-btn:hover { background: linear-gradient(135deg, var(--brand-light) 0%, var(--brand) 100%); transform: translateY(-1px); box-shadow: 0 4px 12px rgba(79, 130, 243, 0.4); }
.send-btn:active { transform: translateY(0); box-shadow: 0 1px 4px rgba(79, 130, 243, 0.3); }

/* ═══════════════════════════════════════════════════════════════
   MODAL
   ═══════════════════════════════════════════════════════════════ */

.modal-bg {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-box {
  background: rgba(17, 24, 39, 0.9);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg), 0 0 80px rgba(0,0,0,0.3);
  max-width: 560px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  animation: fadeInUp 0.25s var(--ease);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 {
  font-size: 15px;
  font-weight: 600;
}

.modal-body {
  padding: 20px;
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.6;
}

/* ═══════════════════════════════════════════════════════════════
   10-K EXPLORER
   ═══════════════════════════════════════════════════════════════ */

.explorer-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 12px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.explorer-tab {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--t-fast);
  white-space: nowrap;
  flex-shrink: 0;
}

.explorer-tab svg, .explorer-tab i { width: 14px; height: 14px; }
.explorer-tab:hover { background: var(--bg-hover); color: var(--text-primary); border-color: rgba(99,102,241,0.15); }

.explorer-tab.active {
  background: var(--brand-bg);
  border-color: rgba(99,102,241,0.25);
  color: var(--brand);
  font-weight: 600;
}

/* Explorer layout: TOC sidebar + body */
.explorer-layout {
  display: flex;
  gap: 0;
  max-height: 600px;
  overflow: hidden;
}

.explorer-toc {
  width: 200px;
  min-width: 200px;
  flex-shrink: 0;
  overflow-y: auto;
  border-right: 1px solid var(--border);
  padding: 12px 0;
  display: none; /* shown when headings exist */
}

.toc-title {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.8px;
  color: var(--text-tertiary);
  padding: 4px 14px 8px;
}

.toc-item {
  display: block;
  padding: 5px 14px;
  font-size: 12px;
  color: var(--text-secondary);
  text-decoration: none;
  border-left: 2px solid transparent;
  transition: all 0.15s ease;
  line-height: 1.4;
}

.toc-item:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
  border-left-color: var(--brand);
}

.toc-h3 {
  padding-left: 24px;
  font-size: 11px;
  color: var(--text-tertiary);
}

.explorer-body {
  flex: 1;
  font-size: 13px;
  line-height: 1.8;
  color: var(--text-secondary);
  max-height: 600px;
  overflow-y: auto;
  padding: 4px 0;
  white-space: pre-wrap;
  word-wrap: break-word;
  font-family: var(--font-sans);
}

.explorer-body h1, .explorer-body h2, .explorer-body h3,
.explorer-body h4, .explorer-body h5 {
  color: var(--text-primary);
  margin: 16px 0 8px;
  font-weight: 600;
}

/* SEC section formatting */
.sec-heading {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
  margin: 24px 0 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
  letter-spacing: -0.01em;
}

.sec-heading:first-child {
  margin-top: 0;
}

.sec-subheading {
  font-size: 14px;
  font-weight: 600;
  color: var(--brand-light);
  margin: 20px 0 8px;
}

.sec-paragraph {
  margin: 0 0 10px;
  color: var(--text-secondary);
  font-size: 13px;
  line-height: 1.75;
}

.sec-list {
  margin: 8px 0 16px;
  padding-left: 20px;
}

.sec-list li {
  margin-bottom: 6px;
  color: var(--text-secondary);
  line-height: 1.6;
}

/* AI Summary badge */
.explorer-summary {
  padding: 4px 0;
}

.summary-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: 20px;
  background: var(--brand-bg);
  color: var(--brand-light);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.3px;
  margin-bottom: 16px;
}

.summary-badge i {
  width: 13px;
  height: 13px;
}

/* Mobile: hide TOC, full width body */
@media (max-width: 768px) {
  .explorer-toc { display: none !important; }
  .explorer-layout { flex-direction: column; }
}

/* Explorer inline AI Q&A */
.explorer-qa {
  margin-top: 16px;
  border-top: 1px solid var(--border);
  padding-top: 12px;
}

.explorer-qa-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--brand);
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.explorer-qa-header svg, .explorer-qa-header i { width: 14px; height: 14px; }

.explorer-qa-messages {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 10px;
  max-height: 300px;
  overflow-y: auto;
}

.explorer-qa-input {
  display: flex;
  gap: 8px;
}

.explorer-qa-input input {
  flex: 1;
  padding: 10px 14px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 13px;
  outline: none;
  transition: all var(--t-fast);
}

.explorer-qa-input input::placeholder { color: var(--text-tertiary); }
.explorer-qa-input input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-bg); }

/* ═══════════════════════════════════════════════════════════════
   GEOGRAPHIC MAP (Leaflet overrides)
   ═══════════════════════════════════════════════════════════════ */

#geo-map {
  border: 1px solid var(--border);
}

#geo-map .leaflet-container {
  background: var(--bg-primary) !important;
}

.leaflet-control-attribution { display: none !important; }
.leaflet-control-zoom { border: 1px solid var(--border) !important; }
.leaflet-control-zoom a {
  background: var(--bg-secondary) !important;
  color: var(--text-secondary) !important;
  border-color: var(--border) !important;
}
.leaflet-control-zoom a:hover {
  background: var(--bg-tertiary) !important;
  color: var(--text-primary) !important;
}

.geo-tooltip {
  background: var(--bg-elevated) !important;
  border: 1px solid var(--border) !important;
  border-radius: var(--radius-sm) !important;
  padding: 8px 12px !important;
  box-shadow: var(--shadow) !important;
  color: var(--text-primary) !important;
  font-family: var(--font-sans) !important;
  font-size: 12px !important;
}

.geo-tooltip .region-name {
  font-weight: 600;
  color: var(--text-primary);
}

.geo-tooltip .region-value {
  font-family: var(--font-mono);
  color: var(--brand-light);
  font-weight: 600;
}

.geo-tooltip .region-parent {
  font-size: 10px;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-top: -2px;
}

.geo-tooltip .region-pct {
  color: var(--text-tertiary);
  font-size: 11px;
}

/* ═══════════════════════════════════════════════════════════════
   LOADING & SPINNERS
   ═══════════════════════════════════════════════════════════════ */

.loading-spinner {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 48px;
  gap: 16px;
  animation: fadeIn 0.3s ease;
  gap: 16px;
}

.loading-spinner p {
  font-size: 13px;
  color: var(--text-tertiary);
  margin: 0;
}

.loading-spinner .loading-text {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.loading-spinner .loading-sub {
  font-size: 12px;
  color: var(--text-tertiary);
  animation: pulse 2s ease infinite;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--brand);
  border-right-color: var(--brand-light);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* Toast notifications */
.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 18px;
  background: rgba(26, 35, 50, 0.85);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  z-index: 1100;
  animation: fadeInUp 0.3s var(--ease);
  font-size: 13px;
  color: var(--text-primary);
}

.toast svg, .toast i { width: 16px; height: 16px; flex-shrink: 0; }
.toast-error { border-left: 3px solid var(--danger); }
.toast-error svg, .toast-error i { color: var(--danger); }

/* ═══════════════════════════════════════════════════════════════
   ANIMATIONS
   ═══════════════════════════════════════════════════════════════ */

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.fade-in {
  animation: fadeIn 0.3s ease forwards;
}

/* Chat messages fade in (complements .msg fadeInUp) */
.chat-message {
  animation: fadeIn 0.2s ease forwards;
}

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes typingBounce {
  0%, 80%, 100% { transform: translateY(0); }
  40% { transform: translateY(-6px); }
}

@keyframes floatGlow {
  0%, 100% { box-shadow: 0 0 20px rgba(79, 130, 243, 0.15), 0 0 40px rgba(79, 130, 243, 0.05); }
  50% { box-shadow: 0 0 30px rgba(79, 130, 243, 0.25), 0 0 60px rgba(79, 130, 243, 0.1); transform: translateY(-2px); }
}

@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

/* ═══════════════════════════════════════════════════════════════
   UTILITIES
   ═══════════════════════════════════════════════════════════════ */

.right { text-align: right; }
.text-center { text-align: center; }
.text-muted { color: var(--text-secondary); }
.font-mono { font-family: var(--font-mono); }
.hidden { display: none !important; }

/* ═══════════════════════════════════════════════════════════════
   RESPONSIVE
   ═══════════════════════════════════════════════════════════════ */

@media (max-width: 1200px) {
  .sidebar { width: 200px; min-width: 200px; }
  .chat-panel.open { width: 340px; min-width: 340px; }
}

@media (max-width: 1024px) {
  .sidebar { width: 56px; min-width: 56px; }
  .brand-text, .sidebar-section, .sidebar-footer, .nav-badge { display: none; }
  .sidebar-brand { padding: 16px 12px; justify-content: center; }
  .nav-item span { display: none; }
  .nav-item { justify-content: center; padding: 10px; }
  .chat-panel.open { width: 320px; min-width: 320px; }
  .company-pill { display: none; }
}

@media (max-width: 768px) {
  /* Hide sidebar on mobile */
  .sidebar { display: none; }

  /* Chat panel: full-screen overlay on mobile */
  .chat-panel {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: 1000;
    width: 0 !important;
    min-width: 0 !important;
  }
  .chat-panel.open {
    width: 100% !important;
    min-width: 100% !important;
  }
  .chat-header {
    padding-top: max(12px, env(safe-area-inset-top));
  }
  .chat-input {
    padding-bottom: max(14px, env(safe-area-inset-bottom));
  }

  /* Header: stack search + actions vertically */
  .header-top {
    flex-wrap: wrap;
    padding: 10px 12px;
    gap: 8px;
  }
  .search-bar {
    max-width: 100%;
    order: 1;
    flex-basis: 100%;
  }
  .search-bar kbd { display: none; }
  .company-pill {
    order: 2;
    flex-basis: 100%;
    justify-content: center;
    font-size: 12px;
  }
  .header-actions {
    order: 3;
    margin-left: auto;
  }

  /* Tabs: scrollable, smaller, wrap controls below */
  .header-tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding: 0 8px;
    gap: 0;
    flex-wrap: wrap;
  }
  .header-tabs::-webkit-scrollbar { display: none; }
  .view-tab {
    font-size: 12px;
    padding: 8px 10px;
    white-space: nowrap;
  }
  .view-tab i { display: none; }
  .header-controls {
    flex-basis: 100%;
    justify-content: center;
    gap: 6px;
    padding: 6px 0;
    border-top: 1px solid var(--border-light);
  }
  .header-controls .sel {
    font-size: 12px;
    padding: 6px 8px;
  }
  .header-controls .toggle-group {
    gap: 0;
  }
  .header-controls .toggle-btn {
    font-size: 11px;
    padding: 5px 10px;
  }

  /* Content: less padding */
  .content {
    padding: 12px;
  }

  /* KPI grid: 2 columns on mobile */
  .kpi-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 8px;
  }
  .kpi-card {
    padding: 12px;
  }
  .kpi-value {
    font-size: 20px !important;
  }
  .kpi-source-badges { display: none; } /* Too cramped — hide badges on mobile */

  /* Charts: single column, proper sizing */
  .charts-row {
    grid-template-columns: 1fr !important;
    gap: 12px;
  }
  .chart-card {
    padding: 14px;
  }
  .chart-card canvas {
    min-height: 200px !important;
    max-height: 260px !important;
  }

  /* Company overview metrics grid: 2 columns */
  .metrics-grid {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  /* Data tables: smaller text, scrollable */
  .data-table {
    font-size: 11px;
  }
  .data-table th, .data-table td {
    padding: 6px 8px;
  }

  /* Comps/Explorer tabs: scrollable */
  .explorer-tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    flex-wrap: nowrap;
  }
  .explorer-tabs::-webkit-scrollbar { display: none; }
  .explorer-tab {
    white-space: nowrap;
    font-size: 12px;
    padding: 8px 12px;
  }

  /* Date range bar: stack */
  .date-range-bar {
    flex-wrap: wrap;
    gap: 8px;
  }

  /* Welcome: smaller */
  .welcome h2 { font-size: 20px; }
  .welcome-pills { flex-wrap: wrap; justify-content: center; }

  /* Chat chips: smaller, scrollable */
  .chat-chips {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    flex-wrap: nowrap;
    padding: 8px 12px;
  }
  .chat-chips::-webkit-scrollbar { display: none; }
  .chip {
    white-space: nowrap;
    font-size: 11px;
    flex-shrink: 0;
  }

  /* Insights body: smaller text */
  .insights-body {
    font-size: 13px;
    line-height: 1.7;
  }
  .insights-body h1 { font-size: 18px; }
  .insights-body h2 { font-size: 15px; }

  /* Confidence grid: scroll */
  .confidence-grid {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Provenance badges: wrap */
  .provenance {
    flex-wrap: wrap;
    gap: 6px;
  }

  /* Web context card */
  .web-context-card {
    font-size: 12px;
  }

  /* Modal: full width on mobile */
  .modal-box {
    width: 95vw;
    max-height: 85vh;
  }
}

/* Small phones */
@media (max-width: 480px) {
  .kpi-grid {
    grid-template-columns: 1fr 1fr !important;
  }
  .kpi-value {
    font-size: 18px !important;
  }
  .header-top {
    padding: 8px;
  }
  .search-bar input {
    font-size: 14px; /* Prevent iOS zoom on focus */
  }
  .content {
    padding: 8px;
  }
  .chart-card canvas {
    min-height: 180px !important;
    max-height: 220px !important;
  }
  .metrics-grid {
    grid-template-columns: 1fr !important;
  }
  .welcome-icon i { width: 40px; height: 40px; }
  .welcome h2 { font-size: 18px; }
  .welcome p { font-size: 13px; }
}

/* ═══════════════════════════════════════════════════════════════
   REDUCED MOTION
   ═══════════════════════════════════════════════════════════════ */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ═══════════════════════════════════════════════════════════════
   DATE RANGE BAR
   ═══════════════════════════════════════════════════════════════ */

.date-range-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 8px 14px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.range-presets, .range-period {
  display: flex;
  gap: 2px;
  background: var(--bg-primary);
  border-radius: 6px;
  padding: 2px;
}

.range-btn {
  padding: 4px 12px;
  border: none;
  background: transparent;
  color: var(--text-tertiary);
  font-size: 12px;
  font-weight: 600;
  font-family: 'Inter', sans-serif;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s;
}

.range-btn:hover { color: var(--text-primary); background: var(--bg-hover); }
.range-btn.active { color: #fff; background: var(--brand); }

.range-custom {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-tertiary);
}

.range-custom input {
  width: 60px;
  padding: 4px 6px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-primary);
  font-size: 11px;
  font-family: 'JetBrains Mono', monospace;
}

.range-custom input:focus {
  outline: none;
  border-color: var(--brand);
}

/* ═══════════════════════════════════════════════════════════════
   CONFIDENCE SCORES & VALIDATION
   ═══════════════════════════════════════════════════════════════ */

.confidence-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 8px;
  margin-bottom: 16px;
}

.conf-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--bg-primary);
  border-radius: 8px;
  border: 1px solid var(--border-light);
}

.conf-label {
  flex: 1;
  font-size: 12px;
  color: var(--text-secondary);
  text-transform: capitalize;
}

.conf-bar-wrap {
  width: 60px;
  height: 6px;
  background: var(--bg-tertiary);
  border-radius: 3px;
  overflow: hidden;
}

.conf-bar {
  height: 100%;
  border-radius: 3px;
  transition: width 0.4s ease;
}

.conf-bar.high { background: var(--success); }
.conf-bar.medium { background: var(--warning); }
.conf-bar.low { background: var(--danger); }

.conf-pct {
  font-size: 11px;
  font-family: 'JetBrains Mono', monospace;
  font-weight: 600;
  min-width: 32px;
  text-align: right;
}

.conf-pct.high { color: var(--success); }
.conf-pct.medium { color: var(--warning); }
.conf-pct.low { color: var(--danger); }

.conf-method {
  font-size: 10px;
  color: var(--text-tertiary);
  background: var(--bg-tertiary);
  padding: 2px 6px;
  border-radius: 4px;
}

.conf-info {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--bg-tertiary);
  color: var(--text-muted);
  font-size: 9px;
  font-weight: 700;
  margin-left: 4px;
  cursor: help;
  vertical-align: middle;
}

.conf-item:hover .conf-info {
  background: var(--brand);
  color: #fff;
}

.conf-item[title] {
  cursor: help;
  position: relative;
}

.validation-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.validation-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 12px;
  line-height: 1.4;
}

.validation-item.error {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.2);
  color: #fca5a5;
}

.validation-item.warning {
  background: rgba(245, 158, 11, 0.1);
  border: 1px solid rgba(245, 158, 11, 0.2);
  color: #fcd34d;
}

.validation-item.success {
  background: rgba(16, 185, 129, 0.06);
  border: 1px solid rgba(16, 185, 129, 0.15);
  color: #6ee7b7;
}

.validation-item i, .validation-item svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

/* Multi-year chart period labels */
.chart-period-info {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-tertiary);
  margin-top: 4px;
}

.chart-period-info .ytd-badge {
  background: rgba(245, 158, 11, 0.15);
  color: #f59e0b;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 600;
}

/* Source badge on KPI cards */
.kpi-source {
  font-size: 9px;
  color: var(--text-tertiary);
  margin-top: 2px;
  font-style: italic;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ═══════════════════════════════════════════════════════════════
   TERMS OF SERVICE OVERLAY
   ═══════════════════════════════════════════════════════════════ */

.tos-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  padding: 20px;
}

.tos-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.5);
  max-width: 640px;
  width: 100%;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  animation: fadeInUp 0.4s var(--ease);
}

.tos-header {
  padding: 24px 28px 20px;
  border-bottom: 1px solid var(--border);
}

.tos-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.tos-brand-name {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
  display: block;
  line-height: 1.2;
}

.tos-brand-sub {
  font-size: 12px;
  color: var(--text-muted);
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.tos-body {
  padding: 24px 28px 28px;
  overflow-y: auto;
  flex: 1;
}

.tos-body h2 {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0 0 4px;
}

.tos-updated {
  font-size: 11px;
  color: var(--text-muted);
  margin: 0 0 20px;
}

.tos-scroll {
  max-height: 380px;
  overflow-y: auto;
  padding-right: 8px;
  margin-bottom: 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  background: var(--bg-primary);
}

.tos-scroll h3 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  margin: 18px 0 6px;
}

.tos-scroll h3:first-child {
  margin-top: 0;
}

.tos-scroll p {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.7;
  margin: 0 0 8px;
}

.tos-scroll strong {
  color: var(--text-primary);
  font-weight: 600;
}

/* Custom scrollbar for T&C */
.tos-scroll::-webkit-scrollbar { width: 5px; }
.tos-scroll::-webkit-scrollbar-track { background: transparent; }
.tos-scroll::-webkit-scrollbar-thumb {
  background: var(--text-muted);
  border-radius: 3px;
}

.tos-check {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.5;
  cursor: pointer;
  margin-bottom: 16px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color 0.2s;
}

.tos-check:has(input:checked) {
  border-color: var(--brand);
  background: rgba(79, 130, 243, 0.05);
}

.tos-check input[type="checkbox"] {
  margin-top: 2px;
  accent-color: var(--brand);
  min-width: 16px;
  min-height: 16px;
}

.tos-accept {
  width: 100%;
  padding: 12px;
  border: none;
  border-radius: var(--radius);
  background: var(--brand);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  font-family: 'Inter', sans-serif;
}

.tos-accept:hover:not(:disabled) {
  background: var(--brand-light);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(79, 130, 243, 0.4);
}

.tos-accept:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

@media (max-width: 640px) {
  .tos-card { max-height: 95vh; border-radius: 12px; }
  .tos-header { padding: 16px 20px; }
  .tos-body { padding: 16px 20px 20px; }
  .tos-scroll { max-height: 280px; }
}

/* ═══════════════════════════════════════════════════════════════
   FMP vs SEC FOOTNOTE COMPARISON
   ═══════════════════════════════════════════════════════════════ */

#data-footnote h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0 0 4px;
}

#data-footnote .card-subtitle {
  margin-bottom: 12px;
}

#data-footnote table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

#data-footnote th {
  text-align: left;
  padding: 8px 10px;
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  font-size: 10px;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
}

#data-footnote th.right { text-align: right; }

#data-footnote td {
  padding: 7px 10px;
  border-bottom: 1px solid var(--border-light);
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 12px;
}

#data-footnote td:first-child {
  font-family: var(--font-sans);
  color: var(--text-primary);
  font-weight: 500;
}

#data-footnote td.right { text-align: right; }

#data-footnote tbody tr:hover {
  background: var(--bg-hover);
}

.fn-match {
  color: var(--success) !important;
  font-weight: 600;
}

.fn-close {
  color: var(--warning) !important;
  font-weight: 600;
}

.fn-mismatch {
  color: var(--danger) !important;
  font-weight: 600;
}

.fn-note {
  font-size: 11px;
  color: var(--text-tertiary);
  margin-top: 10px;
  font-style: italic;
  line-height: 1.5;
}

/* Segment legend value styling */
.seg-val {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-tertiary);
  margin-left: 4px;
  font-weight: 500;
}

/* ═══════════════════════════════════════════════════════════════
   TOOLTIP / TITLE ATTRIBUTE STYLING
   ═══════════════════════════════════════════════════════════════ */

[title] { cursor: help; }
.kpi-card[title] { cursor: pointer; }
.source-badge[title] { cursor: help; }

/* ═══════════════════════════════════════════════════════════════
   AI INSIGHTS STYLING
   ═══════════════════════════════════════════════════════════════ */

.insights-body {
  font-size: 14px;
  line-height: 1.8;
  color: var(--text-primary);
}

.insights-body h1 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0 0 8px;
  color: var(--text-primary);
}

.insights-body h2 {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 28px 0 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
  color: var(--text-primary);
}

.insights-body h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--brand-light);
  margin: 20px 0 8px;
}

.insights-body p {
  margin: 0 0 12px;
  color: var(--text-secondary);
}

.insights-body strong {
  color: var(--text-primary);
  font-weight: 600;
}

.insights-body ul, .insights-body ol {
  margin: 8px 0 16px;
  padding-left: 20px;
}

.insights-body li {
  margin-bottom: 6px;
  color: var(--text-secondary);
}

.insights-body li strong {
  color: var(--text-primary);
}

.insights-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0;
  font-size: 13px;
  font-family: var(--font-mono);
}

.insights-body thead th {
  text-align: left;
  padding: 8px 12px;
  border-bottom: 2px solid var(--border);
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.insights-body thead th:not(:first-child) {
  text-align: right;
}

.insights-body tbody td {
  padding: 7px 12px;
  border-bottom: 1px solid var(--border-light);
}

.insights-body tbody td:not(:first-child) {
  text-align: right;
  font-family: var(--font-mono);
}

.insights-body tbody tr:hover {
  background: var(--bg-hover);
}

.insights-body blockquote {
  border-left: 3px solid var(--brand);
  padding: 8px 16px;
  margin: 12px 0;
  background: var(--brand-bg);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text-secondary);
  font-style: italic;
}

.insights-body code {
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 2px 6px;
  background: rgba(0,0,0,0.25);
  border-radius: 3px;
}

/* ═══════════════════════════════════════════════════════════════
   TECH NOIR ATMOSPHERE — film grain + vignette (dark theme only).
   Both layers are pointer-transparent and EXTREMELY quiet: the goal
   is celluloid depth, not a HUD. Light theme renders none of it.
   ═══════════════════════════════════════════════════════════════ */

html:not([data-theme="light"]) body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 9998;
  pointer-events: none;
  /* SVG feTurbulence grain, tiled — 4% opacity reads as texture, not noise */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)' opacity='0.5'/%3E%3C/svg%3E");
  opacity: 0.04;
  mix-blend-mode: overlay;
}

html:not([data-theme="light"]) body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 9997;
  pointer-events: none;
  /* Corner vignette pulls the eye to the data plane at center */
  background: radial-gradient(ellipse 120% 90% at 50% 40%, transparent 60%, rgba(0, 0, 0, 0.38) 100%);
}

/* Figures get tabular numerals — columns of numbers align like a terminal */
html:not([data-theme="light"]) .mono,
html:not([data-theme="light"]) td,
html:not([data-theme="light"]) [class*="metric"],
html:not([data-theme="light"]) [class*="price"] {
  font-variant-numeric: tabular-nums;
}

/* Streaming caret — a quiet phosphor blink while the answer writes itself */
.stream-caret {
  display: inline-block;
  width: 7px;
  height: 14px;
  margin-left: 2px;
  vertical-align: -2px;
  background: var(--brand);
  animation: caret-blink 1s steps(2) infinite;
}
@keyframes caret-blink { 50% { opacity: 0; } }

/* ═══════════════════════════════════════════════════════════════
   KPI SPARKLINES + PROVENANCE TOOLTIPS
   ═══════════════════════════════════════════════════════════════ */

/* Trend line under the value — quiet, full card width */
.kpi-spark {
  display: block;
  width: 100%;
  height: 36px;
  margin: 8px 0 4px;
}

/* Rich tooltip: hidden until card hover; sits above the card */
.kpi-card { position: relative; }
.kpi-tip {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 8px);
  transform: translateX(-50%) translateY(4px);
  min-width: 220px;
  max-width: 280px;
  padding: 10px 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--t-fast), transform var(--t-fast);
  z-index: 50;
}
.kpi-card:hover .kpi-tip {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.tip-title {
  font-size: 11px;
  color: var(--text-secondary);
  line-height: 1.45;
  margin-bottom: 8px;
}
.tip-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  font-size: 11px;
  color: var(--text-tertiary);
  padding: 2px 0;
}
.tip-row code {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--brand);
  background: var(--brand-bg);
  padding: 1px 5px;
  border-radius: 4px;
  max-width: 170px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tip-row b { color: var(--text-primary); font-weight: 600; }
.tip-conf.high { color: var(--success); }
.tip-conf.medium { color: var(--warning); }
.tip-conf.low { color: var(--danger); }

/* ═══════════════════════════════════════════════════════════════
   STATEMENTS GRID — aggregate/component delineation, tag exposure,
   compact columns, multi-period history cells
   ═══════════════════════════════════════════════════════════════ */

/* Compact columns: label hugs its numbers instead of spanning the panel */
#full-stmt-table { width: auto; min-width: 0; }
#full-stmt-table th:first-child,
#full-stmt-table td.stmt-label {
  max-width: 250px;
  width: 250px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  position: sticky;        /* label column stays put under horizontal scroll */
  left: 0;
  background: var(--bg-secondary);
  z-index: 2;
}
#full-stmt-table th.right,
#full-stmt-table td.stmt-value,
#full-stmt-table td.stmt-change {
  width: 96px;
  min-width: 84px;
  padding-left: 8px;
  padding-right: 10px;
}

/* AGGREGATES (subtotals/totals): hairline rule above + semibold — the eye
   reads the summation structure without any extra chrome */
#full-stmt-table tr.stmt-total td {
  border-top: 1px solid var(--border);
  font-weight: 600;
  color: var(--text-primary);
  background: rgba(79, 130, 243, 0.03);
}

/* COMPONENTS: indented under their aggregate with a faint left tick */
#full-stmt-table tr.stmt-component td.stmt-label {
  padding-left: 26px;
  color: var(--text-secondary);
}
#full-stmt-table tr.stmt-component td.stmt-label::before {
  content: "";
  position: absolute;
  left: 14px;
  top: 50%;
  width: 6px;
  height: 1px;
  background: var(--border);
}

/* Section dividers (e.g. FFO reconciliation) */
#full-stmt-table tr.stmt-section td {
  background: var(--brand-bg);
  padding: 8px 12px;
  font-weight: 600;
  font-style: italic;
  color: var(--text-primary);
}

/* XBRL tag chip: hidden until the row is hovered — the tagging ground truth
   at the point of reading, invisible the rest of the time */
.stmt-tag {
  display: none;
  margin-left: 8px;
  font-family: var(--font-mono);
  font-size: 9px;
  color: var(--brand);
  background: var(--brand-bg);
  padding: 1px 5px;
  border-radius: 4px;
  vertical-align: 1px;
}
#full-stmt-table tr:hover .stmt-tag { display: inline-block; }

/* Older-period history cells: slightly dimmed so the as-filed pair leads */
#full-stmt-table td.stmt-hist { color: var(--text-tertiary); }
#full-stmt-table th.th-hist { color: var(--text-muted); }

/* Derived-period legend row */
#full-stmt-table tr.stmt-legend td {
  font-size: 10px;
  color: var(--text-muted);
  border-top: 1px solid var(--border-light);
  padding: 6px 12px;
}
