/* ==========================================================================
   MSE Clone — Material Design 3 Theme (Dark)
   Design tokens: Color system, Typography scale, Shape, Elevation, Spacing
   ========================================================================== */

/* ---- M3 Color Tokens (Dark Theme — default) ---- */
:root,
[data-theme="dark"] {
  /* Primary — Deep Blue (trust, stability, finance) */
  --md-sys-color-primary: #4D8AF0;
  --md-sys-color-on-primary: #001B3E;
  --md-sys-color-primary-container: #003A70;
  --md-sys-color-on-primary-container: #D6E3FF;
  /* Link text — lighter blue so it clears WCAG AA (>=4.5:1) on dark surfaces
     (9.2:1 on surface, 9.4:1 on background). --primary is only 5.7:1 and
     --primary-container is ~1.7:1, so it must never be used as text. */
  --md-sys-color-link: #8AB4F8;

  /* Secondary — Gold/Amber (Macedonian heritage, gains) */
  --md-sys-color-secondary: #FFD845;
  --md-sys-color-on-secondary: #3B2E00;
  --md-sys-color-secondary-container: #544300;
  --md-sys-color-on-secondary-container: #FFDF8A;

  /* Tertiary — Teal (neutral info, indices) */
  --md-sys-color-tertiary: #2EC4B6;
  --md-sys-color-on-tertiary: #003734;
  --md-sys-color-tertiary-container: #00504A;
  --md-sys-color-on-tertiary-container: #55F0E0;

  /* Error */
  --md-sys-color-error: #FFB4AB;
  --md-sys-color-on-error: #690005;
  --md-sys-color-error-container: #93000A;
  --md-sys-color-on-error-container: #FFDAD6;

  /* Surface & Background */
  --md-sys-color-surface: #0B0E14;
  --md-sys-color-on-surface: #E6E9EF;
  --md-sys-color-surface-variant: #1C2230;
  --md-sys-color-on-surface-variant: #A0A8B5;
  --md-sys-color-outline: #2A3140;
  --md-sys-color-outline-variant: #434B5C;
  --md-sys-color-background: #070A0F;
  --md-sys-color-on-background: #E6E9EF;
  --md-sys-color-surface-dim: #0B0E14;
  --md-sys-color-surface-bright: #2A3140;

  /* Surface Tones for elevation */
  --md-sys-color-surface-tone-1: #11151D;
  --md-sys-color-surface-tone-2: #151A23;
  --md-sys-color-surface-tone-3: #1A212D;

  /* Inverse */
  --md-sys-color-inverse-surface: #E6E9EF;
  --md-sys-color-inverse-on-surface: #0B0E14;
  --md-sys-color-inverse-primary: #004A9F;

  /* Semantic — Market movement (outside M3 spec, but essential here) */
  --md-sys-color-positive: #16C784;
  --md-sys-color-on-positive: #00391E;
  --md-sys-color-positive-container: #00522B;
  --md-sys-color-on-positive-container: #B8F6D8;
  --md-sys-color-negative: #EA3943;
  --md-sys-color-on-negative: #600009;
  --md-sys-color-negative-container: #8C0014;
  --md-sys-color-on-negative-container: #FFB4AB;

  /* Fixed accent colors (keep same across themes) */
  --md-sys-color-primary-fixed: #D6E3FF;
  --md-sys-color-primary-fixed-dim: #AAC7FF;
  --md-sys-color-on-primary-fixed: #001B3E;
  --md-sys-color-on-primary-fixed-variant: #003A70;
  --md-sys-color-secondary-fixed: #FFDF8A;
  --md-sys-color-secondary-fixed-dim: #FDC43F;
  --md-sys-color-on-secondary-fixed: #3B2E00;
  --md-sys-color-on-secondary-fixed-variant: #544300;
}

/* ---- M3 Color Tokens (Light Theme — financial-grade light mode) ---- */
[data-theme="light"] {
  /* Primary — brighter blue for white backgrounds. Darkened from #1A6DF5
     (4.38:1 on surface = AA fail for small text) to #1560D8 (5.4:1 surface,
     4.9:1 background) so every primary-coloured label clears AA. */
  --md-sys-color-primary: #1560D8;
  --md-sys-color-on-primary: #FFFFFF;
  --md-sys-color-primary-container: #D6E3FF;
  --md-sys-color-on-primary-container: #001B3E;
  /* Link text — darker blue; #1A6DF5 is only 4.4:1 on the light background,
     this clears AA (5.5:1 on background, 6.9:1 on surface). */
  --md-sys-color-link: #0B57D0;

  /* Secondary — dark gold keeps Macedonian heritage on light bg */
  --md-sys-color-secondary: #B8860B;
  --md-sys-color-on-secondary: #FFFFFF;
  --md-sys-color-secondary-container: #FFDF8A;
  --md-sys-color-on-secondary-container: #3B2E00;

  /* Tertiary — teal */
  --md-sys-color-tertiary: #00897B;
  --md-sys-color-on-tertiary: #FFFFFF;
  --md-sys-color-tertiary-container: #A0F2E6;
  --md-sys-color-on-tertiary-container: #00201D;

  /* Error */
  --md-sys-color-error: #BA1A1A;
  --md-sys-color-on-error: #FFFFFF;
  --md-sys-color-error-container: #FFDAD6;
  --md-sys-color-on-error-container: #410002;

  /* Surface & Background — near-white, soft gray for variant */
  --md-sys-color-surface: #F8F9FB;
  --md-sys-color-on-surface: #1A1D26;
  --md-sys-color-surface-variant: #EDEFF4;
  --md-sys-color-on-surface-variant: #464D5E;
  --md-sys-color-outline: #C4C9D6;
  --md-sys-color-outline-variant: #AFB5C5;
  --md-sys-color-background: #EDEFF4;
  --md-sys-color-on-background: #1A1D26;
  --md-sys-color-surface-dim: #D3D8E3;
  --md-sys-color-surface-bright: #F8F9FB;

  /* Surface Tones for elevation */
  --md-sys-color-surface-tone-1: #FFFFFF;
  --md-sys-color-surface-tone-2: #F2F4F9;
  --md-sys-color-surface-tone-3: #EBEDF3;

  /* Inverse */
  --md-sys-color-inverse-surface: #2E3240;
  --md-sys-color-inverse-on-surface: #EDEFF4;
  --md-sys-color-inverse-primary: #AAC7FF;

  /* Semantic — Market movement */
  --md-sys-color-positive: #0FA76C;
  --md-sys-color-on-positive: #FFFFFF;
  --md-sys-color-positive-container: #B8F0D6;
  --md-sys-color-on-positive-container: #00391E;
  --md-sys-color-negative: #DC2626;
  --md-sys-color-on-negative: #FFFFFF;
  --md-sys-color-negative-container: #FFD6D6;
  --md-sys-color-on-negative-container: #600009;

  /* Fixed accent colors (keep same across themes) */
  --md-sys-color-primary-fixed: #D6E3FF;
  --md-sys-color-primary-fixed-dim: #AAC7FF;
  --md-sys-color-on-primary-fixed: #001B3E;
  --md-sys-color-on-primary-fixed-variant: #003A70;
  --md-sys-color-secondary-fixed: #FFDF8A;
  --md-sys-color-secondary-fixed-dim: #FDC43F;
  --md-sys-color-on-secondary-fixed: #3B2E00;
  --md-sys-color-on-secondary-fixed-variant: #544300;
}

/* ---- M3 Typography Scale ---- */
:root {
  --md-typeset-display-large: 57px/64px 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --md-typeset-display-medium: 45px/52px 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --md-typeset-display-small: 36px/44px 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --md-typeset-headline-large: 32px/40px 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --md-typeset-headline-medium: 28px/36px 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --md-typeset-headline-small: 24px/32px 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --md-typeset-title-large: 22px/28px 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --md-typeset-title-medium: 16px/24px 500 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --md-typeset-title-small: 14px/20px 500 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --md-typeset-body-large: 16px/24px 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --md-typeset-body-medium: 14px/20px 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --md-typeset-body-small: 12px/16px 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --md-typeset-label-large: 14px/20px 500 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --md-typeset-label-medium: 12px/16px 500 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --md-typeset-label-small: 11px/16px 500 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;

  --md-ref-typeface-plain: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --md-ref-typeface-brand: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --md-ref-typeface-mono: 'SF Mono', 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
}

/* ---- M3 Shape Scale ---- */
:root {
  --md-shape-none: 0px;
  --md-shape-extra-small: 4px;
  --md-shape-small: 8px;
  --md-shape-medium: 12px;
  --md-shape-large: 16px;
  --md-shape-extra-large: 28px;
  --md-shape-full: 9999px;
}

/* ---- M3 Elevation (shadows) ---- */
:root {
  --md-elevation-level-0: none;
  --md-elevation-level-1: 0 1px 2px rgba(0,0,0,0.3), 0 1px 3px 1px rgba(0,0,0,0.15);
  --md-elevation-level-2: 0 1px 2px rgba(0,0,0,0.3), 0 2px 6px 2px rgba(0,0,0,0.15);
  --md-elevation-level-3: 0 4px 8px 3px rgba(0,0,0,0.15), 0 1px 3px rgba(0,0,0,0.3);
  --md-elevation-level-4: 0 6px 10px 4px rgba(0,0,0,0.15), 0 2px 3px rgba(0,0,0,0.3);
  --md-elevation-level-5: 0 8px 12px 6px rgba(0,0,0,0.15), 0 4px 4px rgba(0,0,0,0.3);
}

/* ---- M3 Motion ---- */
:root {
  --md-motion-duration-short-1: 50ms;
  --md-motion-duration-short-2: 100ms;
  --md-motion-duration-medium-1: 200ms;
  --md-motion-duration-medium-2: 400ms;
  --md-motion-duration-long-1: 500ms;
  --md-motion-duration-long-2: 600ms;
  --md-motion-easing-standard: cubic-bezier(0.2, 0, 0, 1);
  --md-motion-easing-decelerate: cubic-bezier(0.05, 0.7, 0.1, 1);
  --md-motion-easing-accelerate: cubic-bezier(0.3, 0, 0.8, 0.15);
  --md-motion-easing-emphasized: cubic-bezier(0.3, 0, 0, 1);
}

/* ---- M3 Spacing Scale ---- */
:root {
  --md-space-xxs: 4px;
  --md-space-xs: 8px;
  --md-space-sm: 12px;
  --md-space-md: 16px;
  --md-space-lg: 24px;
  --md-space-xl: 32px;
  --md-space-xxl: 48px;
}

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

body {
  font-family: var(--md-ref-typeface-plain);
  font-size: 14px;
  line-height: 20px;
  background: var(--md-sys-color-background);
  color: var(--md-sys-color-on-surface);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  /* Column flex: header (fixed) + layout (flexes) + footer (auto height,
     so the footer can wrap to multiple lines without squeezing the page). */
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

a {
  color: var(--md-sys-color-link);
  text-decoration: none;
  transition: color var(--md-motion-duration-short-2) var(--md-motion-easing-standard);
}
/* Hover keeps the same (AA-passing) colour and adds a non-colour cue, so the
   hovered link can never drop below contrast. */
a:hover {
  color: var(--md-sys-color-link);
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-thickness: 1px;
}

.hidden { display: none !important; }

/* Visually hidden but crawlable (SEO H1 etc.) */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ==========================================================================
   MATERIAL SYMBOLS ICON HELPER
   ========================================================================== */
.material-symbols-outlined {
  font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 24;
  vertical-align: middle;
  line-height: 1;
  user-select: none;
}
.icon-fill {
  font-variation-settings: 'FILL' 1, 'wght' 400, 'GRAD' 0, 'opsz' 24;
}

/* ==========================================================================
   TOPBAR — M3 App Bar
   ========================================================================== */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
  padding: 0 var(--md-space-md);
  background: var(--md-sys-color-surface);
  border-bottom: 1px solid var(--md-sys-color-outline);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--md-space-sm);
}
.brand-icon {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--md-sys-color-primary-container);
  border-radius: var(--md-shape-small);
  color: var(--md-sys-color-on-primary-container);
  flex-shrink: 0;
}
.brand-icon .material-symbols-outlined {
  font-size: 20px;
}
.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}
.brand-name {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.15px;
  color: var(--md-sys-color-on-surface);
}
.brand-sub {
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.3px;
  color: var(--md-sys-color-on-surface-variant);
  margin-top: 1px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: var(--md-space-md);
}

/* Market status chip — identical chrome to #mbiChip / #fxChip below; only the
   icon colour signals the state (green = open, muted = closed). */
.market-status {
  font-size: 12px;
  font-weight: 500;
  color: var(--md-sys-color-on-surface-variant);
  padding: 4px 12px;
  border-radius: var(--md-shape-small);
  border: 1px solid var(--md-sys-color-outline);
  background: var(--md-sys-color-surface-variant);
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  transition: all var(--md-motion-duration-short-2) var(--md-motion-easing-standard);
}
.market-status:hover {
  border-color: var(--md-sys-color-primary);
  color: var(--md-sys-color-primary);
}
.market-status .material-symbols-outlined {
  font-size: 14px;
}
.market-status.open .material-symbols-outlined {
  color: var(--md-sys-color-on-positive-container);
}
.market-status.closed .material-symbols-outlined {
  color: var(--md-sys-color-on-surface-variant);
}

/* MBI10 Index Chip — M3 Chip style */
#mbiChip {
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  color: var(--md-sys-color-on-surface-variant);
  padding: 4px 12px;
  border-radius: var(--md-shape-small);
  border: 1px solid var(--md-sys-color-outline);
  background: var(--md-sys-color-surface-variant);
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all var(--md-motion-duration-short-2) var(--md-motion-easing-standard);
  white-space: nowrap;
}
#mbiChip:hover {
  border-color: var(--md-sys-color-primary);
  color: var(--md-sys-color-primary);
}
#mbiChip .mbi-val {
  color: var(--md-sys-color-on-surface);
  font-weight: 700;
}
#mbiChip .mbi-chg {
  font-weight: 600;
}

/* NBRM FX chip — same pill style as #mbiChip. tabular-nums keeps the chip
   from jumping as values update. */
#fxChip {
  font-size: 12px;
  font-weight: 500;
  color: var(--md-sys-color-on-surface-variant);
  padding: 4px 12px;
  border-radius: var(--md-shape-small);
  border: 1px solid var(--md-sys-color-outline);
  background: var(--md-sys-color-surface-variant);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
@media (max-width: 480px) {
  #fxChip .fx-usd { display: none; } /* € only on very small screens */
}

/* Icon Button */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--md-sys-color-on-surface);
  border-radius: var(--md-shape-full);
  cursor: pointer;
  transition: background var(--md-motion-duration-short-2) var(--md-motion-easing-standard);
  flex-shrink: 0;
}
.icon-btn:hover {
  background: color-mix(in srgb, var(--md-sys-color-on-surface) 10%, transparent);
}
.icon-btn svg {
  display: block;
  width: 22px;
  height: 22px;
  color: inherit;
}
.icon-btn .material-symbols-outlined {
  font-size: 22px;
}

/* (theme icon visibility now handled by JS textContent swap) */

.lang-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 40px;
  min-width: 40px;
  padding: 0 12px;
  border: 1px solid var(--md-sys-color-outline);
  background: transparent;
  color: var(--md-sys-color-on-surface-variant);
  border-radius: var(--md-shape-full);
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
  font-family: inherit;
  letter-spacing: 0.3px;
  transition: all var(--md-motion-duration-short-2) var(--md-motion-easing-standard);
}
.lang-toggle:hover {
  border-color: var(--md-sys-color-primary);
  color: var(--md-sys-color-primary);
}

/* ==========================================================================
   LAYOUT — M3 Responsive Grid
   ========================================================================== */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--md-space-md);
  padding: var(--md-space-md) var(--md-space-md);
  max-width: 1600px;
  width: 100%;
  margin: 0 auto;
  /* Fills whatever height is left after the topbar + footer (body flex). */
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}
/* Future ad rail: add `has-ad` to <body> and the table narrows to make room.
   Nothing renders it today (no ad pipeline yet). */
.ad-rail { display: none; }
body.has-ad .layout { grid-template-columns: minmax(0, 1fr) 300px; }
body.has-ad .ad-rail {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  min-width: 0;
  overflow: hidden;
}

.main-panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

/* Shared panel header: view tabs + search + liquid toggle (both views) */
.panel-header {
  display: flex;
  align-items: center;
  gap: var(--md-space-sm);
  margin-bottom: var(--md-space-sm);
  flex-wrap: wrap;
  flex-shrink: 0;
}
.panel-header .main-tabs { margin-bottom: 0; flex-shrink: 0; }
.panel-header .search-wrapper { flex: 1; min-width: 200px; }
.panel-header .search { height: 44px; font-size: 14px; }
.panel-header .view-toggle { flex-shrink: 0; }
.panel-header #lastPoll { margin-left: auto; flex-shrink: 0; }

/* Quotes | Dividends view switcher — segmented, matches the Liquid toggle */
.main-tabs {
  display: flex;
  gap: 2px;
  padding: 3px;
  background: var(--md-sys-color-surface-variant);
  border: 1px solid var(--md-sys-color-outline);
  border-radius: var(--md-shape-small);
}
.main-tab {
  background: transparent;
  border: none;
  color: var(--md-sys-color-on-surface-variant);
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.3px;
  padding: 6px 16px;
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--md-motion-duration-short-2) var(--md-motion-easing-standard);
}
.main-tab:hover { color: var(--md-sys-color-on-surface); }
.main-tab.active {
  background: var(--md-sys-color-surface);
  color: var(--md-sys-color-primary);
  box-shadow: var(--md-elevation-level-1);
}

/* View wrappers — flex chain so .table-wrap can hug or shrink correctly */
.panel-view {
  display: flex;
  flex-direction: column;
  flex: 0 1 auto;
  min-height: 0;
}

/* ---- DIVIDENDS TABLE ---- */
.div-table th, .div-table td { padding-left: 12px; padding-right: 12px; }
.div-trend { white-space: nowrap; font-feature-settings: 'tnum' 1; color: var(--md-sys-color-on-surface-variant); font-size: 12px; }
.pay-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.3px;
  padding: 1px 6px;
  border-radius: var(--md-shape-full);
  background: var(--md-sys-color-positive-container);
  color: var(--md-sys-color-on-positive);
  vertical-align: middle;
  margin-left: 4px;
  white-space: nowrap;
}
.div-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: var(--md-space-sm);
}
.div-chip {
  display: inline-flex;
  flex-direction: column;
  gap: 2px;
  background: var(--md-sys-color-surface-variant);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-shape-small);
  padding: 8px 12px;
}
.div-chip .k {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--md-sys-color-on-surface-variant);
}
.div-chip .v {
  font-size: 14px;
  font-weight: 700;
  font-feature-settings: 'tnum' 1;
  color: var(--md-sys-color-on-surface);
}

/* Movers strip — full-width row above the table. The old right rail lived in
   the .layout grid; the strip is horizontal so the table keeps the full width. */.side-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--md-space-sm);
  padding: var(--md-space-md) var(--md-space-md) 0;
  max-width: 1600px;
  width: 100%;
  margin: 0 auto;
  flex-shrink: 0;
}

/* ==========================================================================
   TOOLBAR
   ========================================================================== */
.toolbar {
  display: flex;
  gap: var(--md-space-xs);
  align-items: center;
  margin-bottom: var(--md-space-sm);
  flex-wrap: wrap;
}

.search-wrapper {
  position: relative;
  flex: 1;
  min-width: 340px;
}
.search-wrapper .material-symbols-outlined {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 22px;
  color: var(--md-sys-color-on-surface-variant);
  pointer-events: none;
  font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 22;
}
.search-wrapper:focus-within .material-symbols-outlined {
  color: var(--md-sys-color-primary);
}

.search {
  width: 100%;
  height: 52px;
  padding: 0 18px 0 50px;
  background: var(--md-sys-color-surface-variant);
  border: 1px solid var(--md-sys-color-outline);
  color: var(--md-sys-color-on-surface);
  border-radius: var(--md-shape-extra-small);
  outline: none;
  font-size: 15px;
  font-family: inherit;
  transition: all var(--md-motion-duration-medium-1) var(--md-motion-easing-standard);
}
.search::placeholder {
  color: var(--md-sys-color-on-surface-variant);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.search:hover {
  border-color: var(--md-sys-color-on-surface-variant);
}
.search:focus {
  border-color: var(--md-sys-color-primary);
  background: var(--md-sys-color-surface);
  box-shadow: 0 0 0 1px var(--md-sys-color-primary);
}

.muted {
  color: var(--md-sys-color-on-surface-variant);
  font-size: 11px;
  white-space: nowrap;
  font-weight: 500;
}

/* Liquid / All segmented toggle (M3 segmented button) */
.view-toggle {
  display: flex;
  gap: 2px;
  padding: 3px;
  background: var(--md-sys-color-surface-variant);
  border: 1px solid var(--md-sys-color-outline);
  border-radius: var(--md-shape-small);
  flex-shrink: 0;
}
.view-toggle button {
  background: transparent;
  border: none;
  color: var(--md-sys-color-on-surface-variant);
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.3px;
  padding: 5px 14px;
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--md-motion-duration-short-2) var(--md-motion-easing-standard);
}
.view-toggle button:hover { color: var(--md-sys-color-on-surface); }
.view-toggle button.active {
  background: var(--md-sys-color-surface);
  color: var(--md-sys-color-primary);
  box-shadow: var(--md-elevation-level-1);
}

/* Note line under toolbar: liquid fallback notice / show-all-results link */
.toolbar-note {
  font-size: 12px;
  color: var(--md-sys-color-on-surface-variant);
  margin: -2px 0 8px;
}
.toolbar-note a {
  color: var(--md-sys-color-primary);
  cursor: pointer;
  text-decoration: underline;
}

/* Modal: muted line listing aggregated series (STBP etc.) */
.series-note {
  color: var(--md-sys-color-on-surface-variant);
  font-size: 11px;
  margin: -2px 0 6px;
}

/* ==========================================================================
   WATCHLIST — strip above table + star buttons
   ========================================================================== */
.watch-strip {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: var(--md-space-xs);
  min-height: 32px;
  /* Never compress under the table — the flex column shrinks the table
     (which scrolls internally) instead. */
  flex-shrink: 0;
}
.watch-strip .watch-chip { flex-shrink: 0; }
/* Desktop: single ticker-like row — scrolls horizontally when many chips */
@media (min-width: 840px) {
  .watch-strip {
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--md-sys-color-outline) transparent;
  }
  .watch-strip::-webkit-scrollbar { height: 6px; }
  .watch-strip::-webkit-scrollbar-thumb { background: var(--md-sys-color-outline); border-radius: var(--md-shape-full); }
}
.watch-toggle {
  display: none;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: var(--md-sys-color-surface-variant);
  border: 1px solid var(--md-sys-color-outline);
  border-radius: var(--md-shape-small);
  color: var(--md-sys-color-on-surface);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.watch-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.7px;
  text-transform: uppercase;
  color: var(--md-sys-color-on-surface-variant);
  flex-shrink: 0;
}
.watch-hint {
  font-size: 12px;
  color: var(--md-sys-color-on-surface-variant);
  font-style: italic;
}
.watch-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: var(--md-sys-color-surface-variant);
  border: 1px solid var(--md-sys-color-outline);
  border-radius: var(--md-shape-full);
  cursor: pointer;
  font-size: 12px;
  line-height: 1.4;
  transition: border-color var(--md-motion-duration-short-2) var(--md-motion-easing-standard);
  white-space: nowrap;
}
.watch-chip:hover { border-color: var(--md-sys-color-primary); }
.watch-chip.dim { opacity: 0.55; }
.watch-chip .wc-sym { font-weight: 700; color: var(--md-sys-color-primary); }
.watch-chip .wc-price { font-feature-settings: 'tnum' 1; color: var(--md-sys-color-on-surface); }
.watch-chip .wc-chg { font-weight: 600; font-feature-settings: 'tnum' 1; }
.watch-chip .wc-remove {
  background: transparent;
  border: none;
  color: var(--md-sys-color-on-surface-variant);
  cursor: pointer;
  font-size: 11px;
  padding: 0 0 0 2px;
  line-height: 1;
  font-family: inherit;
}
.watch-chip .wc-remove:hover { color: var(--md-sys-color-negative); }

/* Star button — hover-reveal inside the Symbol cell, always visible when
   starred. Also used in the modal header (always visible there). */
.star-btn {
  background: transparent;
  border: none;
  padding: 0 5px 0 0;
  margin: 0;
  cursor: pointer;
  line-height: 1;
  vertical-align: middle;
  opacity: 0;
  color: var(--md-sys-color-on-surface-variant);
  transition: opacity var(--md-motion-duration-short-2) var(--md-motion-easing-standard);
}
.star-btn .material-symbols-outlined { font-size: 16px; }
table.quotes tr:hover .star-btn,
.star-btn.starred,
.star-btn:focus-visible { opacity: 1; }
.star-btn:hover { color: var(--md-sys-color-secondary); }
.star-btn.starred { color: var(--md-sys-color-secondary); }
.star-btn.starred .material-symbols-outlined {
  font-variation-settings: 'FILL' 1, 'wght' 400, 'GRAD' 0, 'opsz' 20;
}
.company-head .star-btn { opacity: 1; padding: 0 2px; }
.company-head .star-btn .material-symbols-outlined { font-size: 22px; }

/* ==========================================================================
   TABLE CARD — M3 Elevated Card
   ========================================================================== */
.table-wrap {
  background: var(--md-sys-color-surface);
  border: 1px solid var(--md-sys-color-outline);
  border-radius: var(--md-shape-medium);
  /* Hug content (no grow): the Liquid view is short and must not stretch
     into empty space. flex-shrink + min-height:0 still cap it to the panel
     in the full list, where .table-scroll takes over with internal scroll. */
  flex: 0 1 auto;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.table-scroll {
  flex: 1;
  overflow: auto;
  min-height: 0;
}

table.quotes {
  width: 100%;
  min-width: 1000px;
  border-collapse: collapse;
  white-space: nowrap;
  font-size: 13px;
}

table.quotes thead {
  position: sticky;
  top: 0;
  z-index: 2;
}

table.quotes th {
  padding: 10px 12px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--md-sys-color-on-surface-variant);
  background: var(--md-sys-color-surface);
  border-bottom: 1px solid var(--md-sys-color-outline);
  user-select: none;
  white-space: nowrap;
}

table.quotes td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
  font-feature-settings: 'tnum' 1;
}

/* Coinbase-style change pills. Backgrounds come from the WCAG-tuned
   *-container tokens, so both themes clear AA without extra work. */
.chg-pill {
  display: inline-block;
  min-width: 62px;
  padding: 4px 10px;
  border-radius: var(--md-shape-full);
  font-weight: 600;
  text-align: center;
  background: var(--md-sys-color-surface-variant);
  color: var(--md-sys-color-on-surface-variant);
}
td.up .chg-pill {
  background: var(--md-sys-color-positive-container);
  color: var(--md-sys-color-on-positive-container);
}
td.down .chg-pill {
  background: var(--md-sys-color-negative-container);
  color: var(--md-sys-color-on-negative-container);
}
table.quotes td.num:has(.chg-pill) { padding-top: 6px; padding-bottom: 6px; }

table.quotes tbody tr {
  transition: background var(--md-motion-duration-short-2) var(--md-motion-easing-standard);
}
table.quotes tbody tr:last-child td {
  border-bottom: none;
}
table.quotes tbody tr:hover {
  background: var(--md-sys-color-surface-variant);
  cursor: pointer;
}

/* Sortable headers */
table.quotes th[data-sort] {
  cursor: pointer;
  transition: color var(--md-motion-duration-short-2) var(--md-motion-easing-standard);
}
table.quotes th[data-sort]:hover {
  color: var(--md-sys-color-primary);
}
table.quotes th[data-sort] .sort-icon {
  display: inline-block;
  vertical-align: middle;
  font-size: 16px;
  opacity: 0;
  margin-left: 2px;
  line-height: 1;
}
table.quotes th.sorted-asc,
table.quotes th.sorted-desc {
  color: var(--md-sys-color-primary);
}
table.quotes th.sorted-asc .sort-icon,
table.quotes th.sorted-desc .sort-icon {
  opacity: 1;
}

/* Dividends table sortable headers — same UX as the quotes table */
table.quotes th[data-divsort] {
  cursor: pointer;
  transition: color var(--md-motion-duration-short-2) var(--md-motion-easing-standard);
}
table.quotes th[data-divsort]:hover {
  color: var(--md-sys-color-primary);
}
table.quotes th[data-divsort] .sort-icon {
  display: inline-block;
  vertical-align: middle;
  font-size: 16px;
  opacity: 0;
  margin-left: 2px;
  line-height: 1;
}
table.quotes th.sorted-asc .sort-icon {
  font-variation-settings: 'FILL' 1, 'wght' 400, 'GRAD' 0, 'opsz' 20;
}
table.quotes th.sorted-desc .sort-icon {
  font-variation-settings: 'FILL' 1, 'wght' 400, 'GRAD' 0, 'opsz' 20;
}

/* Sparkline column */
table.quotes thead th.spark-th {
  width: 72px;
  text-align: center;
}

/* Rating badges (used in analysis tab) */
.badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.5px;
  padding: 2px 6px;
  border-radius: 3px;
  line-height: 1.4;
  min-width: 34px;
  text-align: center;
}
.badge-buy {
  color: var(--md-sys-color-on-positive-container);
  background: var(--md-sys-color-positive-container);
}
.badge-hold {
  color: var(--md-sys-color-on-secondary-container);
  background: var(--md-sys-color-secondary-container);
}
.badge-sell {
  color: var(--md-sys-color-on-negative-container);
  background: var(--md-sys-color-negative-container);
}

table.quotes th.num,
table.quotes td.num {
  text-align: right;
}

table.quotes thead th.spark-th {
  width: 72px;
  text-align: center;
}

.sym {
  font-weight: 600;
  color: var(--md-sys-color-primary);
  letter-spacing: 0.3px;
  font-feature-settings: 'tnum' 1, 'calt' 1;
}
/* Logo + star + ticker: flex INSIDE the cell. Styling the <td> itself as a
   flex container takes it out of the table cell layout, which made that cell's
   bottom border sit off the row baseline (visible misalignment). */
table.quotes td.sym { vertical-align: middle; }
.sym-inner {
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
table.quotes td.sym .sym-text { display: inline-block; }

.comp {
  color: var(--md-sys-color-on-surface-variant);
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 400;
}

.up {
  color: var(--md-sys-color-positive);
}
.down {
  color: var(--md-sys-color-negative);
}

/* Sparkline cell */
.spark {
  text-align: center;
}
.spark canvas {
  width: 64px !important;
  height: 24px !important;
  display: inline-block;
  vertical-align: middle;
}

/* ---- 52 WK RANGE BAR ---- */
.wk-range {
  width: 140px;
}
.wk-range-bar {
  position: relative;
  width: 120px;
  height: 4px;
  background: var(--md-sys-color-outline);
  border-radius: var(--md-shape-full);
  overflow: visible;
}
.wk-range-fill {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  border-radius: var(--md-shape-full);
  opacity: 0.6;
}
.wk-range-pointer {
  position: absolute;
  top: 50%;
  width: 10px;
  height: 10px;
  border-radius: var(--md-shape-full);
  background: var(--md-sys-color-on-surface);
  transform: translate(-50%, -50%);
  box-shadow: 0 1px 3px rgba(0,0,0,0.4);
}
.wk-range-labels {
  display: flex;
  justify-content: space-between;
  font-size: 9px;
  color: var(--md-sys-color-on-surface-variant);
  margin-top: 4px;
  font-feature-settings: 'tnum' 1;
}

/* ==========================================================================
   COMPANY LOGO (favicon + monogram fallback)
   ========================================================================== */
.co-logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 6px;
  overflow: hidden;
  background: var(--md-sys-color-surface-variant);
  flex-shrink: 0;
  vertical-align: middle;
}
.co-logo img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: 6px;
  display: block;
}
.co-logo-mono {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  color: #FFFFFF;
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 1;
  text-transform: uppercase;
}

/* ==========================================================================
   MOVERS STRIP CARDS — M3 Elevated Cards
   ========================================================================== */
.side-card {
  background: var(--md-sys-color-surface);
  border: 1px solid var(--md-sys-color-outline);
  border-radius: var(--md-shape-medium);
  overflow: hidden;
  /* Flex column so .side-items can scroll internally while the title stays
     pinned. Cards keep natural height when there's room (no grow) but shrink
     (scrolling items inside) when the sidebar is too short. */
  display: flex;
  flex-direction: column;
  flex: 0 1 auto;
  min-height: 0;
  transition: box-shadow var(--md-motion-duration-medium-1) var(--md-motion-easing-standard);
}

.side-title {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.1px;
  padding: 14px 14px 8px;
  color: var(--md-sys-color-on-surface);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.side-title .material-symbols-outlined {
  font-size: 18px;
  color: var(--md-sys-color-on-surface-variant);
}

.side-items {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--md-sys-color-outline) transparent;
}
.side-items::-webkit-scrollbar { width: 6px; }
.side-items::-webkit-scrollbar-thumb { background: var(--md-sys-color-outline); border-radius: var(--md-shape-full); }

.side-item {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 8px;
  align-items: center;
  padding: 10px 14px;
  border-top: 1px solid var(--md-sys-color-outline-variant);
  cursor: pointer;
  transition: background var(--md-motion-duration-short-2) var(--md-motion-easing-standard);
}
.side-item:hover {
  background: var(--md-sys-color-surface-variant);
}

.side-item .si-left {
  min-width: 0;
}
.side-item .si-sym {
  font-weight: 600;
  color: var(--md-sys-color-primary);
  font-size: 13px;
  letter-spacing: 0.2px;
}
.side-item .si-sym {
  display: flex;
  align-items: center;
  gap: 6px;
}
.side-item .si-name {
  color: var(--md-sys-color-on-surface-variant);
  font-size: 11px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.side-item .si-spark {
  width: 60px;
}
.side-item .si-spark canvas {
  width: 56px !important;
  height: 22px !important;
}
.side-item .si-right {
  text-align: right;
  white-space: nowrap;
}
.side-item .si-price {
  font-weight: 600;
  font-size: 13px;
  font-feature-settings: 'tnum' 1;
}
.side-item .si-chg {
  font-size: 11px;
  font-weight: 600;
}

/* ==========================================================================
   MODAL — M3 Dialog / Modal
   ========================================================================== */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 32px 16px;
  z-index: 50;
  overflow: auto;
  animation: modalFadeIn var(--md-motion-duration-medium-1) var(--md-motion-easing-decelerate);
}

@keyframes modalFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-card {
  background: var(--md-sys-color-surface);
  border: 1px solid var(--md-sys-color-outline);
  border-radius: var(--md-shape-large);
  box-shadow: var(--md-elevation-level-3);
  width: 100%;
  max-width: 860px;
  padding: 24px;
  position: relative;
  animation: modalSlideUp var(--md-motion-duration-medium-2) var(--md-motion-easing-emphasized);
  margin-top: 32px;
}

@keyframes modalSlideUp {
  from {
    opacity: 0;
    transform: translateY(20px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.close {
  position: absolute;
  right: 12px;
  top: 12px;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--md-sys-color-on-surface-variant);
  border-radius: var(--md-shape-full);
  cursor: pointer;
  transition: all var(--md-motion-duration-short-2) var(--md-motion-easing-standard);
}
.close:hover {
  background: var(--md-sys-color-surface-variant);
}
.close .material-symbols-outlined {
  font-size: 20px;
}

.company-head {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 4px;
}
.company-head h2 {
  margin: 0;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: 0;
  color: var(--md-sys-color-on-surface);
  display: flex;
  align-items: center;
  gap: 10px;
}

.company-sub {
  color: var(--md-sys-color-on-surface-variant);
  margin-bottom: 6px;
  font-size: 13px;
}

.as-of {
  color: var(--md-sys-color-on-surface-variant);
  font-size: 11px;
  margin-bottom: var(--md-space-md);
  font-style: italic;
}

/* Stats grid — M3 Data Display
   Row A (primary): price facts at a glance, with mini bars for ranges
   Row B (secondary): activity metrics, compact + dimmer */
.stat-grid {
  display: grid;
  gap: 10px;
  margin-bottom: var(--md-space-md);
}
.stat-grid-primary {
  grid-template-columns: repeat(4, 1fr);
}
.stat-grid-secondary {
  grid-template-columns: repeat(4, 1fr);
}

.stat {
  background: var(--md-sys-color-surface-variant);
  border-radius: var(--md-shape-small);
  padding: 12px 14px;
  border: 1px solid var(--md-sys-color-outline-variant);
  min-width: 0;  /* prevent grid blowout from long numbers */
}
.stat .k {
  color: var(--md-sys-color-on-surface-variant);
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.stat .v {
  font-size: 18px;
  font-weight: 700;
  margin-top: 4px;
  font-feature-settings: 'tnum' 1;
  color: var(--md-sys-color-on-surface);
  line-height: 1.15;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.stat .u {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.5px;
  color: var(--md-sys-color-on-surface-variant);
  text-transform: uppercase;
  margin-top: 1px;
}
.stat .v-sm {
  font-size: 14px;
  font-weight: 600;
  margin-top: 2px;
  font-feature-settings: 'tnum' 1;
  color: var(--md-sys-color-on-surface);
  line-height: 1.1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.stat .u-sm {
  font-size: 10px;
  font-weight: 500;
  color: var(--md-sys-color-on-surface-variant);
  margin-left: 2px;
}
.stat-grid-secondary .stat {
  padding: 10px 12px;
  background: transparent;
  border-color: transparent;
}
.stat-grid-secondary .stat .k {
  font-size: 10px;
}
.stat-grid-secondary .stat .v-sm {
  font-size: 15px;
}

/* Range-bar inside a stat cell (day range, 52w position).
   4px tall track with a 6px circle marker showing where the current
   price sits. End-labels sit just outside the track, micro-sized. */
.stat-with-bar .v {
  margin-bottom: 10px;
}
.stat-bar {
  position: relative;
  height: 4px;
  background: var(--md-sys-color-outline-variant);
  border-radius: 2px;
  margin-top: 2px;
}
.stat-bar-fill {
  position: absolute;
  top: 50%;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--md-sys-color-primary);
  transform: translate(-50%, -50%);
  border: 2px solid var(--md-sys-color-surface);
  box-shadow: 0 0 0 1px var(--md-sys-color-primary);
}
.stat-bar-end {
  position: absolute;
  top: 8px;
  font-size: 10px;
  color: var(--md-sys-color-on-surface-variant);
  font-feature-settings: 'tnum' 1;
  line-height: 1;
}
.stat-bar-low  { left: 0; }
.stat-bar-high { right: 0; text-align: right; }

/* Range buttons — M3 Segmented Button style */
.range-btns {
  display: flex;
  gap: 4px;
  margin-bottom: 10px;
  flex-wrap: wrap;
  background: var(--md-sys-color-surface-variant);
  border-radius: var(--md-shape-small);
  padding: 3px;
  width: fit-content;
  border: 1px solid var(--md-sys-color-outline);
}
.range-btns button {
  background: transparent;
  border: none;
  color: var(--md-sys-color-on-surface-variant);
  padding: 5px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  font-size: 12px;
  font-family: inherit;
  letter-spacing: 0.3px;
  transition: all var(--md-motion-duration-short-2) var(--md-motion-easing-standard);
}
.range-btns button:hover {
  color: var(--md-sys-color-on-surface);
}
.range-btns button.active {
  background: var(--md-sys-color-surface);
  color: var(--md-sys-color-primary);
  box-shadow: var(--md-elevation-level-1);
}

/* Chart area */
.chart-head {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 8px;
}
.chart-price {
  font-size: 24px;
  font-weight: 700;
  font-feature-settings: 'tnum' 1;
  color: var(--md-sys-color-on-surface);
}
.chart-chg {
  font-size: 15px;
  font-weight: 600;
}
.chart-period {
  font-size: 11px;
  color: var(--md-sys-color-on-surface-variant);
  margin-left: auto;
  align-self: center;
}

.chart-box {
  background: var(--md-sys-color-surface-variant);
  border-radius: var(--md-shape-small);
  padding: 12px;
  min-height: 360px;
  border: 1px solid var(--md-sys-color-outline-variant);
}

.chart-legend-note {
  font-size: 11px;
  color: var(--md-sys-color-on-surface-variant);
  margin-top: 6px;
  text-align: center;
}

/* ==========================================================================
   FOOTER
   ========================================================================== */
.foot {
  text-align: center;
  color: var(--md-sys-color-on-surface-variant);
  padding: 10px 14px;
  font-size: 11px;
  line-height: 1.8;
  border-top: 1px solid var(--md-sys-color-outline);
  /* Block flow (not flex) so the text wraps naturally; links never split. */
  flex-shrink: 0;
}
.foot a { white-space: nowrap; }

/* ==========================================================================
   SCROLLBAR STYLING
   ========================================================================== */
.table-scroll::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
.table-scroll::-webkit-scrollbar-track {
  background: transparent;
}
.table-scroll::-webkit-scrollbar-thumb {
  background: var(--md-sys-color-outline);
  border-radius: var(--md-shape-full);
}
.table-scroll::-webkit-scrollbar-thumb:hover {
  background: var(--md-sys-color-on-surface-variant);
}

/* ==========================================================================
   RESPONSIVE — M3 Breakpoints
   Layout adapts across Compact (<600), Medium (600-839),
   Expanded (840-1199), Large (1200-1599), Extra-large (1600+)
   ========================================================================== */

/* Large: 1200-1599px — slightly narrower sidebar */
@media (max-width: 1599px) {
  body.has-ad .layout {
    grid-template-columns: minmax(0, 1fr) 280px;
  }
}

/* Expanded: 840-1199px — still full width (no rail unless an ad is configured) */
@media (max-width: 1199px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
    max-width: none;
  }
  body.has-ad .layout {
    grid-template-columns: minmax(0, 1fr) 250px;
  }
}

/* Medium: 600-839px — single column, strip becomes a swipeable row */
@media (max-width: 839px) {
  .layout {
    grid-template-columns: 1fr;
    min-height: 0;
    padding: var(--md-space-sm);
    gap: var(--md-space-sm);
    max-width: none;
  }

  /* Horizontal scroll row with snap: three cards stay side by side and the
     row pans sideways instead of stacking (keeps the table above the fold). */
  .side-strip {
    display: flex;
    grid-template-columns: none;
    gap: var(--md-space-xs);
    padding: var(--md-space-sm) var(--md-space-sm) 0;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .side-strip::-webkit-scrollbar { display: none; }
  .side-strip .side-card {
    flex: 0 0 78%;
    min-width: 0;
    scroll-snap-align: start;
  }
  .side-card {
    min-width: 0;
  }
  .side-title {
    font-size: 13px;
    padding: 12px 12px 6px;
  }
  .side-title .material-symbols-outlined {
    font-size: 16px;
  }
  .side-item {
    padding: 8px 12px;
  }
  .side-item .si-sym {
    font-size: 12px;
  }
  .side-item .si-name {
    display: none;
  }
  .side-item .si-price {
    font-size: 12px;
  }

  .search-wrapper {
    min-width: 0;
  }
  .search {
    height: 46px;
    font-size: 14px;
  }

  .brand-sub {
    display: none;
  }

  .toolbar {
    flex-wrap: wrap;
  }
  /* Compact header: two equal segmented controls share row 1, search +
     timestamp share row 2 — same size/space for Котации|Дивиденди and
     Ликвидни|Сите. */
  .panel-header #mainTabs,
  .panel-header #viewToggle { flex: 1 1 calc(50% - 12px); }
  .panel-header #mainTabs .main-tab,
  .panel-header #viewToggle button { flex: 1; text-align: center; padding: 6px 8px; }
  .panel-header .search-wrapper { flex: 1 1 0; min-width: 0; }
  #lastPoll { width: auto; text-align: right; margin-left: auto; }

  /* Watchlist collapses to a ★ toggle bar; chips expand on tap */
  .watch-strip .watch-label { display: none; }
  .watch-strip .watch-toggle { display: inline-flex; }
  .watch-strip.collapsed .watch-chips { display: none; }

  .modal { padding: 16px 8px; }
  .modal-card { padding: 16px; }
  .stat-grid-primary,
  .stat-grid-secondary { grid-template-columns: repeat(2, 1fr); }
  .range-btns { width: 100%; }
  .range-btns button { flex: 1; text-align: center; }
  .market-status { font-size: 11px; padding: 2px 8px; }
  #mbiChip { font-size: 11px; padding: 2px 8px; }
  #fxChip { font-size: 11px; padding: 2px 8px; }
}

/* Compact: <600px — single column, swipeable strip, simplified topbar */
@media (max-width: 599px) {
  .topbar {
    height: 48px;
    padding: 0 var(--md-space-sm);
  }
  .topbar .brand-name {
    font-size: 14px;
  }
  .brand-sub {
    display: none;
  }
  .topbar-right {
    gap: 2px;
  }
  .market-status {
    display: none;
  }
  #mbiChip {
    font-size: 10px;
    padding: 2px 6px;
    max-width: 100px;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  #fxChip {
    font-size: 10px;
    padding: 2px 6px;
  }
  .icon-btn {
    width: 36px;
    height: 36px;
  }
  .icon-btn .material-symbols-outlined {
    font-size: 20px;
  }

  .layout {
    padding: var(--md-space-xs);
    gap: var(--md-space-xs);
  }

  .toolbar {
    margin-bottom: var(--md-space-xs);
  }
  .search {
    height: 40px;
    font-size: 14px;
    padding: 0 14px 0 38px;
  }
  .search-wrapper .material-symbols-outlined {
    left: 10px;
    font-size: 20px;
  }

  .side-strip .side-card {
    flex: 0 0 86%;
  }

  /* Very small screens: stack the controls full-width so labels never
     overflow — big touch targets, one control per row. */
  .panel-header { gap: var(--md-space-xs); }
  .panel-header #mainTabs,
  .panel-header #viewToggle { flex: 1 1 100%; }
  .panel-header #mainTabs .main-tab,
  .panel-header #viewToggle button { padding: 8px 6px; }
  .panel-header .search-wrapper { flex: 1 1 auto; }
  #lastPoll { margin-left: auto; }

  /* Touch-friendly table rows on compact */
  table.quotes th {
    padding: 8px 6px;
    font-size: 10px;
  }
  table.quotes td {
    padding: 10px 6px;
    font-size: 12px;
  }
  table.quotes {
    min-width: 720px;
  }

  /* Sparklines smaller */
  .spark canvas {
    width: 48px !important;
    height: 18px !important;
  }

  .side-item .si-spark canvas {
    width: 44px !important;
    height: 18px !important;
  }

  .modal {
    padding: 12px 4px;
  }
  .modal-card {
    padding: 12px;
    border-radius: var(--md-shape-medium);
  }
  .company-head h2 {
    font-size: 18px;
  }

  .foot {
    font-size: 10px;
    padding: 10px 12px;
    line-height: 1.9;
  }
}

/* Extra compact: <400px — hide sparkline column to save horizontal space */
@media (max-width: 399px) {
  table.quotes th.spark-th,
  table.quotes td.spark {
    display: none;
  }
  table.quotes {
    min-width: 580px;
  }
}

/* ==========================================================================
   FINANCIAL DATA TABS — M3 Secondary Tab Bar
   ========================================================================== */
.fin-tab-bar {
  display: flex;
  gap: 0;
  margin: var(--md-space-md) 0 0;
  border-bottom: 1px solid var(--md-sys-color-outline);
  overflow-x: auto;
  scrollbar-width: none;
}
.fin-tab-bar::-webkit-scrollbar { display: none; }

.fin-tab {
  position: relative;
  z-index: 1;
  background: transparent;
  border: none;
  color: var(--md-sys-color-on-surface-variant);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.3px;
  padding: 10px 16px;
  cursor: pointer;
  white-space: nowrap;
  transition: color var(--md-motion-duration-short-2) var(--md-motion-easing-standard);
  flex-shrink: 0;
  pointer-events: auto;
}
.fin-tab:hover {
  color: var(--md-sys-color-on-surface);
}
.fin-tab.active {
  color: var(--md-sys-color-primary);
}
.fin-tab.active::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--md-sys-color-primary);
  border-radius: 1px 1px 0 0;
}

.fin-tab-panel {
  padding-top: var(--md-space-sm);
}
/* Horizontal scroll belongs to the wide financial tables only — the chart
   must never scroll (autoSize keeps the canvas inside the container). */
#finTabData, #finTabRatios {
  overflow-x: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--md-sys-color-outline) transparent;
}
#finTabData::-webkit-scrollbar, #finTabRatios::-webkit-scrollbar { height: 6px; }
#finTabData::-webkit-scrollbar-thumb, #finTabRatios::-webkit-scrollbar-thumb { background: var(--md-sys-color-outline); border-radius: var(--md-shape-full); }
#finTabChart { overflow: hidden; }

/* ==========================================================================
   FINANCIAL TABLES
   ========================================================================== */
.fin-table {
  width: 100%;
  min-width: 560px;
  border-collapse: collapse;
  font-size: 13px;
  line-height: 1.4;
  table-layout: auto;
}
.fin-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 8px 12px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--md-sys-color-on-surface-variant);
  background: var(--md-sys-color-surface);
  border-bottom: 1px solid var(--md-sys-color-outline);
  text-align: left;
  white-space: nowrap;
  vertical-align: middle;
}
.fin-table thead th:first-child {
  min-width: 180px;
  text-align: left;
}
.fin-table thead th.num {
  text-align: right;
  min-width: 90px;
}
.fin-table tbody td {
  padding: 7px 12px;
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
  color: var(--md-sys-color-on-surface);
  vertical-align: middle;
  white-space: nowrap;
}
.fin-table tbody td.num {
  text-align: right;
  font-feature-settings: 'tnum' 1;
  white-space: nowrap;
}
.fin-table tbody td.num.muted {
  color: var(--md-sys-color-on-surface-variant);
}
.fin-table tbody td.fin-label {
  font-weight: 500;
  color: var(--md-sys-color-on-surface);
  max-width: 280px;
  min-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: left;
}
.fin-table tbody tr:last-child td {
  border-bottom: none;
}
.fin-table tbody tr:hover {
  background: var(--md-sys-color-surface-variant);
}

.fin-note {
  font-size: 11px;
  color: var(--md-sys-color-on-surface-variant);
  font-style: italic;
  margin-top: var(--md-space-xs);
  padding: 0 4px;
}

/* Compact: tighten financial tables on small screens */
@media (max-width: 839px) {
  .fin-table { min-width: 480px; }
  .fin-table thead th,
  .fin-table tbody td { padding: 6px 8px; }
}

/* ==========================================================================
   ANALYSIS TAB — Rating Cards & Signals
   ========================================================================== */
.analysis-banner {
  padding: 16px;
  border-radius: var(--md-shape-medium);
  margin-bottom: var(--md-space-sm);
  text-align: center;
  border: 1px solid var(--md-sys-color-outline);
  background: var(--md-sys-color-surface);
}
.analysis-banner.up {
  border-color: var(--md-sys-color-positive);
  background: color-mix(in srgb, var(--md-sys-color-positive) 8%, var(--md-sys-color-surface));
}
.analysis-banner.down {
  border-color: var(--md-sys-color-negative);
  background: color-mix(in srgb, var(--md-sys-color-negative) 8%, var(--md-sys-color-surface));
}
.analysis-banner.neutral {
  border-color: var(--md-sys-color-secondary);
  background: color-mix(in srgb, var(--md-sys-color-secondary) 8%, var(--md-sys-color-surface));
}
.analysis-rating {
  font-size: 24px;
  font-weight: 800;
  letter-spacing: 1px;
  margin-bottom: 4px;
}
.analysis-banner.up .analysis-rating { color: var(--md-sys-color-positive); }
.analysis-banner.down .analysis-rating { color: var(--md-sys-color-negative); }
.analysis-banner.neutral .analysis-rating { color: var(--md-sys-color-secondary); }
.analysis-pct {
  font-size: 13px;
  color: var(--md-sys-color-on-surface-variant);
  margin-bottom: 8px;
}
.analysis-bar {
  height: 6px;
  background: var(--md-sys-color-outline-variant);
  border-radius: var(--md-shape-full);
  margin: 0 auto 8px;
  max-width: 280px;
  overflow: hidden;
}
.analysis-bar-fill {
  height: 100%;
  border-radius: var(--md-shape-full);
  transition: width 0.4s ease;
}
.analysis-bar-fill.up { background: var(--md-sys-color-positive); }
.analysis-bar-fill.down { background: var(--md-sys-color-negative); }
.analysis-bar-fill.neutral { background: var(--md-sys-color-secondary); }
.analysis-score {
  font-size: 12px;
  color: var(--md-sys-color-on-surface-variant);
  font-weight: 500;
}

.analysis-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--md-space-sm);
}
@media (max-width: 839px) {
  .analysis-grid {
    grid-template-columns: 1fr;
  }
}

.analysis-card {
  background: var(--md-sys-color-surface);
  border: 1px solid var(--md-sys-color-outline);
  border-radius: var(--md-shape-medium);
  overflow: hidden;
}
.analysis-card-title {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--md-sys-color-on-surface-variant);
  padding: 12px 14px 8px;
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
}

.analysis-details {
  padding: 4px 0;
}
.analysis-detail {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px;
  font-size: 13px;
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
}
.analysis-detail:last-child {
  border-bottom: none;
}
.analysis-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.analysis-dot.up { background: var(--md-sys-color-positive); }
.analysis-dot.down { background: var(--md-sys-color-negative); }
.analysis-d-label {
  flex: 1;
  color: var(--md-sys-color-on-surface);
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 4px;
}
.analysis-tt {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--md-sys-color-on-surface-variant);
  color: var(--md-sys-color-surface);
  font-size: 9px;
  font-weight: 700;
  font-style: normal;
  cursor: help;
  flex-shrink: 0;
  line-height: 1;
  transition: background var(--md-motion-duration-short-2) var(--md-motion-easing-standard);
}
.analysis-tt:hover {
  background: var(--md-sys-color-primary);
}
.analysis-d-val {
  font-feature-settings: 'tnum' 1;
  color: var(--md-sys-color-on-surface);
  font-weight: 600;
  min-width: 60px;
  text-align: right;
}
.analysis-d-sig {
  font-size: 11px;
  font-weight: 600;
  min-width: 80px;
  text-align: right;
}
.analysis-d-sig.up { color: var(--md-sys-color-positive); }
.analysis-d-sig.down { color: var(--md-sys-color-negative); }

.analysis-verdict-text {
  padding: 14px;
  font-size: 13px;
  line-height: 1.6;
  color: var(--md-sys-color-on-surface);
}

.analysis-breakdown {
  padding: 0 14px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.analysis-b-item {
  font-size: 13px;
  color: var(--md-sys-color-on-surface);
  display: flex;
  align-items: center;
  gap: 8px;
}

.analysis-disclaimer {
  margin-top: var(--md-space-sm);
  padding: 10px 14px;
  font-size: 11px;
  color: var(--md-sys-color-on-surface-variant);
  font-style: italic;
  text-align: center;
  border-top: 1px solid var(--md-sys-color-outline-variant);
}

/* ==========================================================================
   POPOVERS (market hours) + FX LIST + FAQ ACCORDION
   ========================================================================== */
#marketStatus, #fxChip { cursor: pointer; }
#marketStatus:hover, #fxChip:hover { border-color: var(--md-sys-color-primary); }

.pop-card { max-width: 520px; }
.pop-title {
  margin: 0 0 14px;
  font-size: 17px;
  font-weight: 700;
  color: var(--md-sys-color-on-surface);
  padding-right: 36px;
}
.pop-body { display: flex; flex-direction: column; gap: 2px; }
.pop-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 16px;
  padding: 9px 0;
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
  font-size: 14px;
}
.pop-k { color: var(--md-sys-color-on-surface-variant); }
.pop-v { color: var(--md-sys-color-on-surface); font-weight: 600; text-align: right; }
.pop-open { color: var(--md-sys-color-on-positive-container); }
.pop-closed { color: var(--md-sys-color-on-surface-variant); }
.pop-note {
  margin: 14px 0 0;
  font-size: 12px;
  line-height: 1.6;
  color: var(--md-sys-color-on-surface-variant);
}
.pop-note a { color: var(--md-sys-color-link); }
.pop-foot {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--md-sys-color-outline-variant);
  font-size: 13px;
  font-weight: 600;
}
.pop-foot a { color: var(--md-sys-color-link); text-decoration: none; }
.pop-foot a:hover { text-decoration: underline; }

.fx-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  margin: 14px 0 0;
}
.fx-table th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
  color: var(--md-sys-color-on-surface-variant);
  padding: 8px 10px;
  border-bottom: 1px solid var(--md-sys-color-outline);
  position: sticky;
  top: 0;
  background: var(--md-sys-color-surface);
}
.fx-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
  color: var(--md-sys-color-on-surface);
}
.fx-table td.num, .fx-table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.fx-code {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: var(--md-shape-full);
  background: var(--md-sys-color-surface-variant);
  color: var(--md-sys-color-on-surface-variant);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
}
/* Only rendered for a currency NBRM quotes per N units (none today — every
   currency ships with unit = 1). */
.fx-unit {
  margin-left: 4px;
  font-size: 12px;
  color: var(--md-sys-color-on-surface-variant);
}
/* Keep the modal table scrollable on small screens. */
.pop-body { max-height: 60vh; overflow: auto; }

/* ---- FAQ page ---------------------------------------------------------- */
.faq-intro {
  font-size: 16px;
  line-height: 1.75;
  color: var(--md-sys-color-on-surface-variant);
  margin: 0;
}
.faq-toc {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 4px 0 8px;
}
.faq-toc a {
  font-size: 14px;
  font-weight: 600;
  padding: 7px 14px;
  border-radius: var(--md-shape-full);
  background: var(--md-sys-color-surface-variant);
  border: 1px solid var(--md-sys-color-outline-variant);
  color: var(--md-sys-color-on-surface-variant);
  text-decoration: none;
  transition: all var(--md-motion-duration-short-2) var(--md-motion-easing-standard);
}
.faq-toc a:hover {
  border-color: var(--md-sys-color-link);
  color: var(--md-sys-color-link);
  text-decoration: none;
}
.faq-sec { margin-top: 34px; scroll-margin-top: 76px; }
.faq-sec-title {
  font-size: 23px;
  line-height: 1.3;
  font-weight: 700;
  color: var(--md-sys-color-on-surface);
  margin: 0 0 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
}
.faq-item {
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-shape-large);
  margin: 0 0 10px;
  background: var(--md-sys-color-surface);
  scroll-margin-top: 76px; /* keep anchored questions clear of the sticky topbar */
  transition: border-color var(--md-motion-duration-short-2) var(--md-motion-easing-standard),
              background var(--md-motion-duration-short-2) var(--md-motion-easing-standard);
}
.faq-item:hover { border-color: var(--md-sys-color-outline); }
.faq-item[open] { background: var(--md-sys-color-surface-variant); }
.faq-item > summary {
  cursor: pointer;
  list-style: none;
  padding: 18px 20px;
  font-size: 18px;
  line-height: 1.45;
  font-weight: 600;
  color: var(--md-sys-color-on-surface);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
}
.faq-item > summary::-webkit-details-marker { display: none; }
.faq-item > summary::after {
  content: 'expand_more';
  font-family: 'Material Symbols Outlined';
  font-size: 24px;
  flex-shrink: 0;
  color: var(--md-sys-color-on-surface-variant);
  transition: transform var(--md-motion-duration-short-2) var(--md-motion-easing-standard);
}
.faq-item[open] > summary::after { transform: rotate(180deg); }
.faq-item[open] > summary { color: var(--md-sys-color-primary); }
.faq-a {
  padding: 0 20px 18px;
  /* Full width of the card: leaving a narrow max-width made answers end
     well short of the answer box and wrap at awkward spots. */
  color: var(--md-sys-color-on-surface-variant);
  animation: faqIn var(--md-motion-duration-medium-1) var(--md-motion-easing-decelerate);
}
.faq-a p {
  font-size: 17px;
  line-height: 1.8;
  margin: 0 0 12px;
  color: var(--md-sys-color-on-surface-variant);
}
.faq-a p:last-child { margin-bottom: 0; }
@keyframes faqIn {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}
@media (max-width: 599px) {
  .faq-sec-title { font-size: 20px; }
  .faq-item > summary { font-size: 16.5px; padding: 15px 16px; }
  .faq-a { padding: 0 16px 15px; }
  .faq-a p { font-size: 15.5px; }
}
