:root {
  color-scheme: light;

  /* Shared row-rhythm scale (Stage 2C). Per-page density partials consume these instead of
     hardcoding heights: `--row-pad-y-tight` for desktop text-height rows, `--row-pad-y-compact`
     for slightly looser data rows, `--row-tap-min` as the mobile tappable floor. */
  --row-pad-y-tight: 1px;
  --row-pad-y-compact: 3px;
  --row-tap-min: 36px;

  /* Stage 5 — trends chart-design system ("Google-Trends calm"). Charts become short siblings
     across Search + Momentum; chrome (grid/axis) goes neutral and quiet while the series keep their
     semantic taxonomy colors (calm comes from lower fill opacity + neutral chrome, not recoloring). */
  --chart-height: 280px;
  --chart-height-mobile: 240px;
  --chart-stroke: 2px;
  --chart-grid: #e2e8f0;
  --chart-axis-ink: #64748b;

  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-raised: #f8fafc;
  --surface-hover: #f8fbff;
  --surface-overlay: rgba(255, 255, 255, 0.94);
  --cbsa-popover-bg: rgba(255, 255, 255, 0.84);

  --text: #172033;
  --text-strong: #0f172a;
  --text-muted: #475569;
  --text-subtle: #64748b;
  --text-on-accent: #ffffff;

  --border-subtle: #e2e8f0;
  --border-default: #d9e0e8;
  --border-strong: #cbd5e1;
  --rail: var(--border-default);

  --accent: #2563eb;
  --accent-strong: #1d4ed8;
  --accent-soft: #eff6ff;
  --tree-sel-1-bg: #1d4ed8;
  --tree-sel-1-fg: #ffffff;
  --tree-sel-2-bg: #93c5fd;
  --tree-sel-2-fg: #0f2a6b;
  --tree-sel-3-bg: #dbeafe;
  --tree-sel-3-fg: #1e3a8a;

  --success: #16a34a;
  --success-strong: #15803d;
  --success-soft: #f0fdf4;
  --success-border: #bbf7d0;

  --warning: #f59e0b;
  --warning-soft: #fef3c7;
  --warning-border: #fde68a;

  --danger: #dc2626;
  --danger-strong: #b91c1c;
  --danger-soft: #fef2f2;
  --danger-border: #fecaca;

  --info: #2563eb;
  --info-soft: #eff6ff;
  --info-border: #bfdbfe;

  --focus-ring: rgba(37, 99, 235, 0.55);

  --shadow-sm: 0 2px 6px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 24px 48px rgba(15, 23, 42, 0.12);

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-pill: 999px;
  --motion-fast: 150ms;
  --motion-med: 220ms;
  --ease-out: cubic-bezier(0.2, 0, 0, 1);
  --tap-min: 44px;

  --bar-track: #eef2f7;
  --rule: rgba(15, 23, 42, 0.36);

  --font-2xs: 10px;
  --font-xs: 11px;
  --font-sm: 12px;
  --font-md: 13px;
  --font-base: 14px;
  --font-lg: 16px;
  --font-xl: 18px;
  --font-2xl: 20px;
  --font-3xl: 24px;
  --line-tight: 1.2;
  --line-normal: 1.45;
  --line-relaxed: 1.6;
  --w-reg: 400;
  --w-med: 500;
  --w-semi: 600;
  --w-bold: 700;
  --w-heavy: 800;

  --map-cursor-hand: grab;
  --map-cursor-hand-active: grabbing;

  --font-sans: "Hanken Grotesk", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-display: "Bricolage Grotesque", var(--font-sans);

  --site-header-h: 54px;
  --mobile-header-h: calc(64px + env(safe-area-inset-top, 0px));
  --sidebar-width: 340px;

  /* Breakpoint tiers: desktop >= 941px, tablet 761-940px, mobile <= 760px. */
  font-family: var(--font-sans);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: var(--font-base);
  line-height: var(--line-normal);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

/* Shared top navigation — identical on every page so switching never shifts layout. */
.site-header {
  position: relative;
  flex: 0 0 var(--site-header-h);
  display: flex;
  align-items: stretch;
  justify-content: center;
  padding: 0 16px;
  background: var(--surface-overlay);
  border-bottom: 1px solid var(--border-default);
  backdrop-filter: saturate(140%) blur(8px);
  -webkit-backdrop-filter: saturate(140%) blur(8px);
}

.site-nav {
  display: flex;
  align-items: stretch;
  gap: clamp(8px, 3vw, 40px);
}

.site-brand {
  position: absolute;
  z-index: 2;
  top: 50%;
  left: 16px;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  height: 34px;
  padding: 3px 8px;
  overflow: hidden;
  background: #ffffff;
  border-radius: 0;
  box-shadow: none;
  line-height: 0;
  text-decoration: none;
}

.site-brand-logo {
  display: block;
  width: auto;
  height: 28px;
}

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

@media (max-width: 900px) and (min-width: 761px) {
  .site-brand {
    left: 10px;
    height: 28px;
    padding: 3px 6px;
  }

  .site-brand-logo {
    height: 18px;
  }

  .site-nav {
    gap: clamp(8px, 2vw, 16px);
  }

  .site-nav-link {
    font-size: var(--font-xs);
    letter-spacing: 0.1em;
  }
}

.site-nav-link {
  position: relative;
  display: inline-flex;
  align-items: center;
  padding: 0 2px;
  font-family: var(--font-display);
  font-size: var(--font-md);
  font-weight: var(--w-semi);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  text-decoration: none;
  color: var(--text-subtle);
  transition: color 160ms ease;
}

.site-nav-link::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 2px;
  border-radius: 2px;
  background: var(--accent);
  transform: scaleX(0);
  transform-origin: center;
  transition: transform 200ms cubic-bezier(0.4, 0, 0.2, 1);
}

.site-nav-link:hover,
.site-nav-link:focus-visible {
  color: var(--text-strong);
  outline: none;
}

.site-nav-link:hover::after,
.site-nav-link:focus-visible::after {
  transform: scaleX(0.55);
}

.site-nav-link.active {
  color: var(--text-strong);
  font-weight: var(--w-bold);
}

.site-nav-link.active::after {
  transform: scaleX(1);
}

@media (prefers-reduced-motion: reduce) {
  .site-nav-link,
  .site-nav-link::after {
    transition: none;
  }
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app {
  position: relative;
  display: grid;
  grid-template-columns: 1fr;
  width: 100%;
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
  /* Full-bleed map at all breakpoints: the sidebar becomes an off-canvas right drawer (>=761px)
     or moves into the bottom sheet (<=760px). overflow:hidden clips the off-canvas drawer so it
     never adds page-wide horizontal scroll (it is absolutely positioned within this relative box). */
  overflow: hidden;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 12px;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  border-right: 1px solid var(--border-default);
  background: var(--surface);
  padding: 12px;
}

/* Desktop/tablet (>=761px): non-blocking right drawer, scoped to the MAP page's sidebar only
   (other pages keep their in-flow sidebar). No backdrop, so the map stays interactive. Off-canvas
   by default; .is-drawer-open slides it in. Clipped by .app { overflow:hidden } so it adds no
   page-wide horizontal scroll. */
@media (min-width: 761px) {
  .app > .sidebar {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 40;
    width: min(360px, 92vw);
    transform: translateX(100%);
    transition: transform var(--motion-med) var(--ease-out);
    border-right: 0;
    border-left: 1px solid var(--border-default);
    box-shadow: var(--shadow-lg);
    overflow: auto;
  }

  .app > .sidebar.is-drawer-open {
    transform: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .app > .sidebar {
    transition: none;
  }
}

.sidebar-header,
.summary-header,
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.sidebar-header h1,
.summary-header h2 {
  margin: 0;
  font-family: var(--font-display);
  color: var(--text-strong);
  letter-spacing: -0.01em;
  line-height: var(--line-tight);
}

.sidebar-header h1 {
  font-size: var(--font-2xl);
}

.summary-header h2 {
  font-size: var(--font-xl);
}

.eyebrow {
  margin: 0 0 4px;
  font-family: var(--font-display);
  color: var(--text-subtle);
  font-size: var(--font-2xs);
  font-weight: var(--w-bold);
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.data-status {
  border: 1px solid var(--border-default);
  border-radius: 999px;
  padding: 5px 9px;
  color: var(--text-muted);
  font-size: var(--font-sm);
  white-space: nowrap;
}

.data-status.is-loading {
  border-color: var(--accent-soft);
  color: var(--accent-strong);
  background: var(--accent-soft);
}

.skeleton {
  position: relative;
  overflow: hidden;
  background: var(--bar-track);
  border-radius: 6px;
  color: transparent;
  user-select: none;
  pointer-events: none;
}

.skeleton::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    90deg,
    transparent 0%,
    var(--surface-hover) 50%,
    transparent 100%
  );
  transform: translateX(-100%);
  animation: skeleton-shimmer 1.4s ease-in-out infinite;
}

@keyframes skeleton-shimmer {
  to {
    transform: translateX(100%);
  }
}

.skeleton-stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 4px 2px;
}

.skeleton-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 2px;
}

.skeleton-checkbox {
  flex: 0 0 16px;
  height: 16px;
  border-radius: 4px;
}

.skeleton-text {
  flex: 1;
  height: 12px;
}

.skeleton-text.short {
  flex: 0 0 38%;
}

.skeleton-text.medium {
  flex: 0 0 62%;
}

.skeleton-count {
  flex: 0 0 28px;
  height: 12px;
}

.skeleton-chip {
  height: 30px;
  border-radius: 999px;
  flex: 1;
}

.skeleton-bar-row {
  display: grid;
  grid-template-columns: 110px 1fr 44px;
  gap: 10px;
  align-items: center;
  padding: 5px 0;
}

.skeleton-bar-row .skeleton-text {
  height: 11px;
}

.skeleton-bar {
  height: 18px;
  border-radius: 6px;
}

.skeleton-table {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 6px 0;
}

.skeleton-table-row {
  display: grid;
  grid-template-columns: 1.5fr repeat(5, 1fr);
  gap: 10px;
  align-items: center;
}

.skeleton-table-row .skeleton-text {
  height: 11px;
}

@keyframes map-loading-pulse {
  0%, 100% { opacity: 0.55; }
  50% { opacity: 0.85; }
}

@media (prefers-reduced-motion: reduce) {
  .skeleton::after { animation: none; }
  .map-loading::before { animation: none; opacity: 0.65; }
  *, *::before, *::after {
    transition-duration: 0.001ms !important;
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
  }
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.legend-group {
  min-height: 0;
  flex: 1;
  gap: 8px;
  padding-top: 12px;
  border-top: 1px solid var(--border-subtle);
}

/* Wave-3 item 13: the analysis-page sidebar puts the legend tree directly in .legend-group (the
   map page uses .legend-scroll). Without an explicit scroll it clipped its lower rows, so make it
   scroll on desktop and clear the floating bottom nav. Mobile relocates the sidebar into a sheet. */
@media (min-width: 761px) {
  .analysis-sidebar .legend-group {
    overflow-y: auto;
    padding-bottom: var(--bottom-nav-clearance);
  }
}

@media (min-width: 941px) {
  .trends-sidebar .legend-group > .legend-tree {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding-bottom: var(--bottom-nav-clearance);
    overscroll-behavior: contain;
  }
}

/* The Classification Legend is the focal point of the left panel. */
.legend-group > .group-title,
.legend-group > .row-title {
  font-family: var(--font-display);
  font-size: var(--font-base);
  letter-spacing: 0.005em;
  color: var(--text-strong);
}

.legend-group > .row-title > span:first-child {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.legend-group > .row-title > span:first-child::before {
  content: "";
  width: 3px;
  height: 14px;
  border-radius: 2px;
  background: var(--accent);
}

.group-title,
.row-title {
  color: var(--text-strong);
  font-size: var(--font-sm);
  font-weight: var(--w-bold);
}

.row-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.row-title-meta {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.muted {
  color: var(--text-muted);
  font-size: var(--font-sm);
  font-weight: var(--w-med);
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  overflow: hidden;
  border: 1px solid var(--border-default);
  border-radius: 8px;
  background: var(--surface-raised);
}

.segmented.wrap {
  grid-template-columns: repeat(auto-fit, minmax(72px, 1fr));
}

.segmented.two-up {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.segmented.compact {
  min-width: 156px;
}

.segmented.compact .segment {
  padding: 5px 8px;
  font-size: var(--font-xs);
}

.segment {
  border: 0;
  border-right: 1px solid var(--border-default);
  background: transparent;
  color: var(--text-muted);
  padding: 6px 7px;
  font-size: var(--font-sm);
  transition: background 150ms ease, color 150ms ease, font-weight 150ms ease;
}

.segment:last-child {
  border-right: 0;
}

.segment.active {
  background: var(--accent);
  color: var(--text-on-accent);
  font-weight: var(--w-bold);
}

.segment.is-disabled,
.segment:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.status-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

/* Status filter pills — same look as the All / Clear / Collapse All mini-action pills
   (see .mini-actions > button). One row of three separate, equal-width pills. */
.status-pill {
  min-height: 28px;
  border: 1px solid var(--border-default);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  padding: 4px 8px;
  font-size: var(--font-xs);
  font-weight: var(--w-bold);
  white-space: nowrap;
  cursor: pointer;
  transition: background 140ms ease, border-color 140ms ease, color 140ms ease;
}

.status-pill:hover,
.status-pill:focus-visible {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-strong);
}

/* Declared after :hover (equal specificity) so a selected pill stays filled on hover. */
.status-pill.is-selected {
  border-color: var(--accent-strong);
  background: var(--accent);
  color: var(--text-on-accent);
}

.status-pill:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.check-row {
  min-width: 0;
  border: 1px solid var(--border-default);
  border-radius: 8px;
  background: var(--surface);
  display: flex;
  align-items: center;
  gap: 6px;
}

.check-row input {
  flex: 0 0 16px;
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--accent);
}

.check-list {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

/* The scrollable container is .legend-scroll so the brand search can stay pinned (sticky) while
   the tree (whose innerHTML is rebuilt on every render) scrolls beneath it. */
.legend-scroll {
  flex: 1;
  min-height: 0;
  overflow: auto;
}

.legend-scroll #brand-search {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface);
}

.legend-tree {
  --legend-check-size: 14px;
  --legend-node-gap: 2px;
  --legend-row-gap: 5px;
  /* Wave-3 item 13: compact selector rows on desktop (mobile keeps 38px touch rows below). */
  --legend-row-min-h: 30px;
  --legend-row-pad-x: 6px;
  --legend-row-pad-y: 1px;
  --legend-toggle-size: 20px;
  min-height: 160px;
  padding-top: 4px;
  padding-right: 3px;
}

.legend-tree .tree-row:not(.is-selected):not(.is-partial):hover {
  background: var(--surface-hover);
}

.tree-node {
  display: flex;
  flex-direction: column;
  gap: var(--legend-node-gap);
}

.tree-node + .tree-node {
  margin-top: 3px;
}

.tree-children {
  display: flex;
  flex-direction: column;
  gap: var(--legend-node-gap);
  border-left: 2px solid var(--rail);
}

/* Progressive indent: sub-sectors at 16px under their sector, brands at 32px (16 + 16, nested). */
.tree-children.sub-sector-children {
  margin-left: 0;
  padding-left: 16px;
}

.tree-children.brand-children {
  padding-left: 16px;
}

.tree-children[hidden] {
  display: none;
}

.tree-row {
  position: relative;
  min-height: var(--legend-row-min-h);
  cursor: pointer;
}

.legend-tree .check-row {
  gap: var(--legend-row-gap);
  padding: var(--legend-row-pad-y) var(--legend-row-pad-x);
}

.legend-tree .check-row input {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: 0;
  opacity: 0;
  pointer-events: none;
}

.legend-tree .check-row:focus-within {
  border-color: var(--accent-strong);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.legend-tree .tree-toggle {
  width: var(--legend-toggle-size);
  height: var(--legend-toggle-size);
  flex: 0 0 var(--legend-toggle-size);
  border-radius: 5px;
}

.tree-toggle,
.icon-button {
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  flex: 0 0 22px;
  border: 1px solid var(--border-default);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text-strong);
  font-weight: var(--w-heavy);
  line-height: 1;
}

.tree-toggle:hover,
.icon-button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.tree-toggle-spacer {
  visibility: hidden;
}

.tree-toggle svg,
.icon-button svg,
.expander svg {
  display: block;
}

.tree-row.sector-row {
  background: var(--surface-raised);
  font-weight: var(--w-bold);
}

.tree-row.sub-sector-row {
  background: var(--surface);
}

.tree-row.brand-row {
  background: var(--surface);
}

.tree-row.sector-row.is-selected,
.tree-row.sub-sector-row.is-selected {
  border-color: var(--tree-sel-1-bg);
  background: var(--tree-sel-1-bg);
  color: var(--tree-sel-1-fg);
}

.tree-row.sector-row.is-partial,
.tree-row.sub-sector-row.is-partial {
  border-color: color-mix(in srgb, var(--tree-sel-2-bg) 78%, var(--border-default));
  background: var(--tree-sel-2-bg);
  color: var(--tree-sel-2-fg);
}

.tree-row.brand-row.is-selected {
  border-color: var(--tree-sel-1-bg);
  background: var(--tree-sel-1-bg);
  color: var(--tree-sel-1-fg);
}

.tree-row.is-selected .check-label,
.tree-row.is-selected .check-count,
.tree-row.is-partial .check-label,
.tree-row.is-partial .check-count {
  color: inherit;
}

.tree-row.is-selected .check-count,
.tree-row.is-partial .check-count {
  opacity: 0.78;
}

.tree-row.is-selected .swatch,
.tree-row.is-partial .swatch {
  border-color: rgba(255, 255, 255, 0.62);
  box-shadow: 0 0 0 1px rgba(15, 23, 42, 0.12);
}

.tree-row .check-label {
  line-height: 1.2;
  white-space: nowrap;
}

.tree-row.brand-row .check-label {
  font-size: var(--font-sm);
}

.tree-row.brand-row .brand-favicon {
  flex: 0 0 16px;
}

.empty-legend {
  border: 1px dashed var(--border-default);
  border-radius: 8px;
  color: var(--text-muted);
  font-size: var(--font-md);
  padding: 12px;
  text-align: center;
}

.check-row {
  padding: 5px 7px;
}

.check-label {
  min-width: 0;
  overflow: hidden;
  color: var(--text);
  font-size: var(--font-sm);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.check-count {
  color: var(--text-muted);
  font-size: var(--font-sm);
  font-variant-numeric: tabular-nums;
}

.tree-row .check-count {
  margin-left: auto;
  padding-left: 6px;
}

.legend-tree .check-count {
  font-size: var(--font-xs, 11px);
  line-height: 1;
}

.check-row-right {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend-tree .check-row-right {
  gap: 4px;
}

.legend-tree .check-row-right .check-count {
  margin-left: 0;
  padding-left: 0;
}

.column-split-toggle {
  display: inline-grid;
  place-items: center;
  width: 20px;
  height: 20px;
  flex: 0 0 20px;
  border: 1px solid var(--border-default);
  border-radius: 5px;
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
}

.column-split-toggle:hover,
.column-split-toggle:focus-visible,
.column-split-toggle.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.column-split-toggle svg {
  display: block;
}

.swatch {
  width: 12px;
  height: 12px;
  flex: 0 0 12px;
  border-radius: 50%;
  border: 1px solid var(--border-strong);
}

.color-swatch {
  appearance: none;
  padding: 0;
  cursor: pointer;
}

.color-swatch:hover {
  border-color: var(--text-strong);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

.brand-focus-swatch {
  transition: box-shadow 120ms ease, transform 120ms ease, border-color 120ms ease;
}

.brand-focus-swatch.is-focus-active,
.brand-focus-swatch.is-focus-locked {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  transform: scale(1.15);
}

.muted-swatch {
  background: var(--border-subtle);
  border-color: var(--border-strong);
}

.search {
  width: 100%;
  border: 1px solid var(--border-default);
  border-radius: 8px;
  background: var(--surface);
  padding: 10px 11px;
  color: var(--text);
}

.search:focus,
.search:focus-visible,
button:focus-visible,
[role="button"]:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
summary:focus-visible {
  outline: 2px solid transparent;
  outline-offset: 2px;
  box-shadow: 0 0 0 3px var(--focus-ring);
}

@media (forced-colors: active) {
  .search:focus,
  .search:focus-visible,
  button:focus-visible,
  [role="button"]:focus-visible,
  a:focus-visible,
  input:focus-visible,
  select:focus-visible,
  textarea:focus-visible,
  summary:focus-visible {
    outline: 2px solid Highlight;
    box-shadow: none;
  }
}

.taxonomy-search-control {
  position: relative;
  width: 100%;
}

.taxonomy-search-control > .search {
  padding-left: 35px;
}

.taxonomy-search-icon {
  position: absolute;
  top: 20px;
  left: 12px;
  z-index: 1;
  display: inline-flex;
  width: 15px;
  height: 15px;
  color: var(--text-muted);
  pointer-events: none;
  transform: translateY(-50%);
}

.taxonomy-search-control:focus-within .taxonomy-search-icon {
  color: var(--accent);
}

.taxonomy-search-results {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  left: 0;
  z-index: 30;
  display: flex;
  max-height: min(50vh, 360px);
  flex-direction: column;
  gap: 1px;
  overflow: auto;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface-overlay);
  box-shadow: var(--shadow-md);
  padding: 6px;
}

.taxonomy-search-results[hidden],
.taxonomy-search-results:empty {
  display: none;
}

.taxonomy-search-results.is-inline {
  position: static;
  max-height: min(42vh, 320px);
  margin-top: 6px;
}

.taxonomy-search-result {
  display: flex;
  width: 100%;
  align-items: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  padding: 6px 8px;
  text-align: left;
}

.taxonomy-search-result:hover,
.taxonomy-search-result.active {
  border-color: var(--border-default);
  background: var(--surface-hover);
}

.taxonomy-search-result-swatch {
  width: 14px;
  height: 14px;
  flex: 0 0 14px;
  border: 1px solid var(--border-default);
  border-radius: 999px;
}

/* Brand search results show the favicon (built by each page) in place of the colored dot. */
.taxonomy-search-result-icon,
.map-unit-search-result-favicon {
  display: inline-flex;
  flex: 0 0 16px;
  align-items: center;
  justify-content: center;
}

.taxonomy-search-result-icon .brand-favicon,
.map-unit-search-result-favicon .brand-favicon {
  width: 16px;
  height: 16px;
}

.taxonomy-search-result-main {
  min-width: 0;
  flex: 1 1 auto;
}

.taxonomy-search-result-label,
.taxonomy-search-result-secondary {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.taxonomy-search-result-label {
  color: var(--text);
  font-size: var(--font-sm);
  font-weight: var(--w-med);
  line-height: 1.25;
}

.taxonomy-search-result-secondary,
.taxonomy-search-result-kind,
.taxonomy-search-empty {
  color: var(--text-muted);
  font-size: var(--font-xs);
  font-weight: var(--w-med);
}

.taxonomy-search-result-kind {
  flex: 0 0 auto;
  white-space: nowrap;
}

.taxonomy-search-empty {
  padding: 8px 6px;
}

.color-popover {
  position: fixed;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--border-default);
  border-radius: 10px;
  background: var(--surface-overlay);
  box-shadow: var(--shadow-md);
  backdrop-filter: saturate(140%) blur(6px);
}

.color-popover-grid {
  display: grid;
  grid-template-columns: repeat(6, 22px);
  gap: 6px;
}

.color-popover-swatch {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  border: 1px solid var(--border-strong);
  cursor: pointer;
  padding: 0;
  transition: transform 80ms ease;
}

.color-popover-swatch:hover,
.color-popover-swatch:focus-visible {
  transform: scale(1.08);
}

.color-popover-swatch.active {
  outline: 2px solid var(--text-strong);
  outline-offset: 2px;
}

.color-popover-auto {
  border: 1px solid var(--border-default);
  border-radius: 6px;
  background: var(--surface-raised);
  color: var(--text);
  padding: 6px 10px;
  font-size: var(--font-sm);
  font-weight: var(--w-semi);
  cursor: pointer;
}

.color-popover-auto:hover {
  border-color: var(--accent);
  color: var(--accent-strong);
}

.mini-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.mini-actions.three-up {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.mini-actions.four-up {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.mini-actions.four-up button {
  padding: 4px;
  font-size: var(--font-xs);
}

.display-disclosure,
.status-disclosure {
  gap: 0;
}

.display-toggle {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 8px;
  width: 100%;
  border: 1px solid var(--border-default);
  border-radius: 9px;
  background: var(--surface);
  color: var(--text);
  padding: 8px 11px;
  text-align: left;
  transition: border-color 140ms ease, background 140ms ease, box-shadow 140ms ease;
}

.display-toggle:hover,
.display-toggle:focus-visible {
  border-color: var(--accent);
  background: var(--accent-soft);
  outline: none;
}

.display-toggle.open {
  border-color: var(--accent-strong);
  background: var(--accent-soft);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.display-toggle-label {
  color: var(--text-strong);
  font-size: var(--font-sm);
  font-weight: var(--w-bold);
  letter-spacing: 0.01em;
}

/* The verbose state string stays in the DOM for the JS/screen readers,
   but the compact button shows only the label + chevron. */
.display-toggle-meta {
  display: none;
}

.display-toggle-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  transition: transform 160ms ease;
}

.display-toggle.open .display-toggle-icon {
  color: var(--accent-strong);
}

.display-toggle-icon svg {
  display: block;
}

.display-controls {
  position: absolute;
  z-index: 30;
  top: calc(100% + 7px);
  left: 0;
  min-width: 210px;
  max-width: min(248px, 78vw);
  display: flex;
  flex-direction: column;
  gap: 9px;
  border: 1px solid var(--border-default);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow-md);
  padding: 11px;
  animation: popover-in 150ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* Right-hand control opens flush to the sidebar's right edge. */
.display-disclosure .display-controls {
  left: auto;
  right: 0;
}

.display-controls[hidden] {
  display: none;
}

/* Status is shown inline as always-visible buttons (no click-dropdown). Overrides the
   shared .display-controls popover for the Status disclosure only; Display keeps its popover. */
.status-disclosure .status-controls {
  position: static;
  z-index: auto;
  min-width: 0;
  max-width: none;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: none;
  box-shadow: none;
  animation: none;
}

.status-static-label {
  color: var(--text-strong);
  font-size: var(--font-sm);
  font-weight: var(--w-bold);
  letter-spacing: 0.01em;
  margin-bottom: 6px;
}

@keyframes popover-in {
  from {
    opacity: 0;
    transform: translateY(-6px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.display-row {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.mini-actions > button {
  min-height: 28px;
  border: 1px solid var(--border-default);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  padding: 4px 8px;
  font-size: var(--font-xs);
  font-weight: var(--w-bold);
}

.tool-button {
  min-height: 44px;
  border: 1px solid var(--border-default);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  padding: 8px 11px;
  font-weight: var(--w-bold);
}

.mini-actions > button:hover,
.mini-actions > button:focus-visible,
.tool-button:hover,
.tool-button:focus-visible {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.tool-button {
  text-decoration: none;
}

.tool-button.primary,
.tool-button.active {
  border-color: var(--accent-strong);
  background: var(--accent);
  color: var(--text-on-accent);
}

.main {
  display: grid;
  grid-template-rows: minmax(420px, 1fr) minmax(220px, 34vh);
  min-width: 0;
  height: 100%;
  min-height: 0;
}

.main.summary-expanded {
  grid-template-rows: minmax(150px, 20vh) minmax(520px, 1fr);
}

.main.summary-collapsed {
  grid-template-rows: minmax(420px, 1fr) auto;
}

.main.summary-collapsed.summary-expanded {
  grid-template-rows: minmax(420px, 1fr) auto;
}

.topbar {
  min-width: 0;
  border-bottom: 1px solid var(--border-default);
  background: var(--surface);
  padding: 12px 16px;
}

.stats {
  display: flex;
  align-items: center;
  gap: 18px;
}

.stats div {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.stat-label {
  color: var(--text-muted);
  font-size: var(--font-xs);
  font-weight: var(--w-bold);
  letter-spacing: 0;
  text-transform: uppercase;
}

.stats strong {
  color: var(--text-strong);
  font-size: var(--font-xl);
}

.toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

/* --- On-map sub-sector chip row (active/partial sub-sectors + "+ Filters") --- */
.subsector-chip-row {
  position: absolute;
  top: 12px;
  left: 56px;
  right: 206px;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

.subsector-chip-row::-webkit-scrollbar {
  display: none;
}

/* Grab-scroll feedback (toggled by brand-chips.js while dragging the marquee): grabbing cursor and
   suppressed text selection so chip labels aren't highlighted mid-drag. */
.subsector-chip-row.is-grabbing,
.subsector-chip-row.is-grabbing .subsector-chip {
  cursor: grabbing;
}
.subsector-chip-row.is-grabbing {
  user-select: none;
}

.subsector-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
  min-height: 32px;
  padding: 0 6px 0 10px;
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  background: var(--surface-overlay);
  box-shadow: var(--shadow-sm);
  color: var(--text);
  font-size: var(--font-sm);
  font-weight: var(--w-semi);
  white-space: nowrap;
}

.subsector-chip-dot {
  width: 10px;
  height: 10px;
  flex: 0 0 10px;
  border-radius: 999px;
  border: 1px solid rgba(15, 23, 42, 0.18);
  background: var(--border-strong);
}

.subsector-chip.is-partial .subsector-chip-dot {
  border-style: dashed;
  opacity: 0.72;
}

.subsector-chip-count {
  color: var(--text-muted);
  font-size: var(--font-xs);
  font-variant-numeric: tabular-nums;
}

.subsector-chip-remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--text-muted);
  padding: 0;
  cursor: pointer;
}

.subsector-chip-remove:hover,
.subsector-chip-remove:focus-visible {
  background: var(--surface-hover);
  color: var(--text-strong);
}

.subsector-chip-remove svg {
  display: block;
}

.subsector-chip.is-filters {
  padding: 0 12px;
  border-style: dashed;
  color: var(--text-muted);
  font-weight: var(--w-bold);
  cursor: pointer;
}

.subsector-chip.is-filters:hover,
.subsector-chip.is-filters:focus-visible {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.subsector-chip.is-filters:focus-visible,
.subsector-chip-remove:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 1px;
}

/* P5 motion: entry for newly-added chips + dot state/color transitions (reduced-motion gated). */
@keyframes subsector-chip-in {
  from {
    opacity: 0;
    transform: scale(0.82);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.subsector-chip.is-new {
  animation: subsector-chip-in 140ms var(--ease-out);
}

.legend-tree .swatch,
.subsector-chip-dot {
  transition: background-color 140ms var(--ease-out), border-color 140ms var(--ease-out), opacity 140ms var(--ease-out);
}

@media (prefers-reduced-motion: reduce) {
  .subsector-chip.is-new {
    animation: none;
  }

  .legend-tree .swatch,
  .subsector-chip-dot {
    transition: none;
  }
}

/* P2: Reset (ship defaults + clear saved filters) — dashed to distinguish from solid Clear. */
.mini-reset {
  width: 100%;
  min-height: 30px;
  border: 1px dashed var(--border-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text-muted);
  padding: 5px 8px;
  font-size: var(--font-xs);
  font-weight: var(--w-bold);
  cursor: pointer;
  transition: border-color 140ms ease, color 140ms ease, background 140ms ease;
}

.mini-reset:hover,
.mini-reset:focus-visible {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.brand-focus-item {
  gap: 2px;
  padding: 2px 3px 2px 5px;
}

.selection-box {
  position: absolute;
  z-index: 3;
  border: 2px solid var(--accent);
  background: var(--accent-soft);
  pointer-events: none;
}

.summary-panel {
  position: relative;
  z-index: 2;
  display: flex;
  min-height: 220px;
  min-width: 0;
  overflow: hidden;
  flex-direction: column;
  background: var(--surface);
  transition: min-height 150ms ease;
}

.summary-panel.collapsed {
  min-height: 0;
}

.summary-header {
  min-width: 0;
  border-bottom: 1px solid var(--border-default);
  padding: 12px 16px;
}

.summary-header-compact {
  justify-content: flex-end;
  padding-block: 8px;
}

.summary-panel.collapsed .summary-header {
  border-bottom: 0;
}

.summary-panel.collapsed .table-wrap {
  display: none;
}

.summary-panel.collapsed .summary-tabs {
  display: none;
}

/* Wave-3 item 2: desktop drag handle to resize the results panel (replaces the Expand/Collapse
   buttons). Mobile hides it and uses its own .sheet-grip translateY drag sheet over the panel. */
.summary-grabber {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 100%;
  height: 16px;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: ns-resize;
  touch-action: none;
}
.summary-grabber-bar {
  width: 40px;
  height: 4px;
  border-radius: var(--radius-pill);
  background: var(--border-strong);
  transition: background var(--motion-fast) var(--ease-out);
}
.summary-grabber:hover .summary-grabber-bar,
.summary-grabber:focus-visible .summary-grabber-bar {
  background: var(--accent);
}
.main.summary-resizing {
  user-select: none;
}
.main.summary-resizing .summary-panel {
  min-height: 0;
  transition: none;
}

#summary-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.summary-header > div:first-child {
  min-width: 0;
}

.summary-actions {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  flex-wrap: wrap;
  gap: 6px 10px;
  justify-content: flex-end;
  max-width: 100%;
  width: 620px;
}

.summary-header-compact .summary-actions {
  width: auto;
  margin-left: auto;
}

.summary-note {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
  font-size: var(--font-md);
  white-space: nowrap;
}

#summary-note {
  display: block;
  flex: 0 0 410px;
  margin-left: auto;
  order: 2;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 410px;
}

#download-summary,
.summary-tabs {
  order: 1;
}

.summary-note-button {
  border: 0;
  background: transparent;
  cursor: help;
  font: inherit;
  padding: 0;
  text-decoration: underline dotted;
  text-underline-offset: 3px;
}

.summary-note-button:hover,
.summary-note-button:focus-visible {
  color: var(--accent-strong);
  outline: none;
}

.summary-note-button svg {
  flex: 0 0 auto;
}

.region-help-dialog {
  width: min(680px, calc(100vw - 32px));
  max-height: min(720px, calc(100vh - 48px));
  overflow: auto;
  border: 1px solid var(--border-default);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
  padding: 0;
}

.region-help-dialog::backdrop {
  background: rgba(15, 23, 42, 0.45);
}

.region-help-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--border-default);
  padding: 14px 16px;
}

.region-help-header h2 {
  margin: 0;
  color: var(--text-strong);
  font-size: var(--font-lg);
}

.region-help-close {
  width: 28px;
  height: 28px;
  flex-basis: 28px;
}

.region-help-body {
  padding: 16px;
}

.region-help-groups {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.region-help-group {
  border: 1px solid var(--border-default);
  border-radius: 8px;
  background: var(--surface-raised);
  padding: 12px;
}

.region-help-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  color: var(--text-strong);
  font-size: var(--font-sm);
}

.region-help-states,
.region-help-footnote {
  margin: 0;
  color: var(--text-muted);
  font-size: var(--font-sm);
  line-height: 1.5;
}

.region-help-footnote {
  margin-top: 14px;
}

.summary-tabs {
  display: flex;
  flex: 0 0 auto;
  gap: 6px;
  min-width: 0;
  overflow-x: auto;
}

.summary-tab {
  border: 1px solid var(--border-default);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text-muted);
  min-height: 36px;
  padding: 6px 10px;
  font-weight: var(--w-bold);
  white-space: nowrap;
}

.summary-tab.active {
  border-color: var(--accent-strong);
  background: var(--accent);
  color: var(--text-on-accent);
}

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

#summary-content {
  min-width: 0;
}

.summary-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--font-md);
}

.summary-table th,
.summary-table td {
  border-bottom: 1px solid var(--border-default);
  padding: 9px 10px;
  text-align: left;
  vertical-align: middle;
}

.summary-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-raised);
  color: var(--text-muted);
  font-size: var(--font-xs);
  letter-spacing: 0;
  text-transform: uppercase;
}

.sort-button {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  width: 100%;
  min-width: 0;
  border: 0;
  background: transparent;
  color: inherit;
  padding: 0;
  font: inherit;
  font-weight: var(--w-heavy);
  letter-spacing: 0;
  text-align: inherit;
  text-transform: inherit;
  cursor: pointer;
}

.sort-button span:first-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sort-button.active {
  color: var(--accent-strong);
}

.sort-marker {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  min-width: 12px;
  color: var(--accent-strong);
}

.sort-marker svg {
  display: block;
}

.summary-table th:first-child .sort-button,
.matrix-table .name-col .sort-button {
  justify-content: flex-start;
  text-align: left;
}

.summary-table td:not(:first-child),
.summary-table th:not(:first-child) {
  text-align: right;
}

.summary-table tr:hover td {
  background: var(--surface-hover);
}

.summary-table .number {
  text-align: right;
  white-space: nowrap;
}

.matrix-table .per-unit-col,
.matrix-table th.per-unit-col .sort-button {
  color: var(--text-muted);
  font-style: italic;
  font-weight: var(--w-med);
}

.matrix-table .per-unit-col {
  width: 72px;
  min-width: 68px;
  max-width: 78px;
  text-align: center !important;
}

.matrix-table .pop-col {
  width: 78px;
  min-width: 78px;
  max-width: 78px;
}

.matrix-table .hh-col {
  width: 84px;
  min-width: 84px;
  max-width: 84px;
}

.matrix-table th.per-unit-col .sort-button {
  justify-content: center;
  text-align: center;
}

.matrix-table th.hh-col .sort-button {
  justify-content: center;
  text-align: center;
  text-transform: none;
}

.matrix-table th.per-unit-col .sort-button span:first-child {
  overflow: visible;
  text-overflow: clip;
}

.matrix-table th.hh-col .sort-button span:first-child {
  display: inline-block;
  overflow: visible;
  line-height: 1.05;
  text-overflow: clip;
  white-space: normal;
}

.matrix-table {
  width: max-content;
  min-width: max-content;
}

.matrix-table th,
.matrix-table td {
  padding: 6px 8px;
}

/* Stage 2C: tighten matrix BODY rows to the shared compact rhythm; headers keep their 6px so the
   brand favicons + sort buttons stay roomy. */
.matrix-table tbody td {
  padding-top: var(--row-pad-y-compact);
  padding-bottom: var(--row-pad-y-compact);
}

.selection-table {
  width: max-content;
  min-width: 100%;
}

.matrix-table th,
.matrix-table td,
.selection-table th,
.selection-table td {
  white-space: nowrap;
}

.matrix-table .brand-header,
.selection-table .color-column-header {
  width: 96px;
  min-width: 88px;
  max-width: 160px;
  overflow: hidden;
  white-space: normal;
}

.matrix-table .brand-header .sort-button,
.selection-table .color-column-header .sort-button {
  align-items: flex-start;
}

/* Wave-3 item 12: columns are marked by a bold colored bottom rule instead of a full fill, with
   readable strong-ink text; brand columns also carry the brand favicon (.matrix-col-head). */
.matrix-table .matrix-color-header {
  border-bottom: 3px solid var(--matrix-column-color);
  color: var(--text-strong);
}

.matrix-table .matrix-color-header .sort-button,
.matrix-table .matrix-color-header .sort-button.active,
.matrix-table .matrix-color-header .sort-marker {
  color: inherit;
}

.matrix-table .matrix-color-header .matrix-col-head {
  display: flex;
  align-items: flex-start;
  gap: 5px;
  min-width: 0;
}
.matrix-table .matrix-color-header .matrix-col-head .sort-button {
  min-width: 0;
}
.matrix-table .matrix-color-header .matrix-col-head .brand-favicon {
  flex: 0 0 16px;
  margin-top: 2px;
}

.matrix-table .brand-header .sort-button > span:first-child,
.selection-table .color-column-header .sort-button > span:first-child {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
  overflow-wrap: normal;
  text-overflow: ellipsis;
  white-space: normal;
  word-break: normal;
}

/* Row sorting moved to the Total row: the brand column header is now a display-only label, and each
   Total-row per-column cell is the blue sort link (with the active caret). */
.matrix-table .matrix-color-header .matrix-col-label {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  min-width: 0;
  overflow: hidden;
  color: inherit;
  text-overflow: ellipsis;
  white-space: normal;
}

.matrix-table .total-row .total-sort-cell {
  padding: 0;
}

.matrix-table .total-row .total-sort-cell .sort-button {
  width: 100%;
  justify-content: flex-end;
  gap: 3px;
  color: var(--accent);
}

.matrix-table .total-row .total-sort-cell .sort-button.active,
.matrix-table .total-row .total-sort-cell .sort-button:hover,
.matrix-table .total-row .total-sort-cell .sort-button:focus-visible {
  color: var(--accent-strong);
  text-decoration: underline;
}

.matrix-table .sticky-col {
  position: sticky;
  z-index: 2;
  background: inherit;
}

.matrix-table th.sticky-col {
  z-index: 4;
  background: var(--surface-raised);
}

.matrix-table .name-col {
  left: 0;
  width: 150px;
  min-width: 96px;
  max-width: 200px;
  overflow: hidden;
  text-align: left !important;
}

.matrix-table .name-col strong {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
  overflow-wrap: anywhere;
  white-space: normal;
}

.matrix-table tbody tr td.sticky-col {
  background: var(--surface);
}

.matrix-table tbody tr:hover td.sticky-col,
.matrix-table tbody tr:hover td {
  background: var(--surface-hover);
}

.matrix-table tbody tr.matrix-cbsa-selected td,
.matrix-table tbody tr.matrix-cbsa-selected td.sticky-col {
  background: var(--accent-soft);
}

.matrix-table .total-row td {
  background: var(--accent-soft);
  font-weight: var(--w-bold);
}

.matrix-table .total-row td.sticky-col {
  background: var(--accent-soft);
}

.empty-count {
  color: var(--text-muted);
}

.cell-button {
  min-width: 34px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--accent-strong);
  padding: 3px 6px;
  font-weight: var(--w-bold);
}

.cell-button:hover,
.cell-button.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.cell-button.active {
  border-color: var(--accent-strong);
  background: var(--accent);
  color: var(--text-on-accent);
}

.matrix-table .cell-button {
  min-width: 30px;
  padding: 2px 5px;
}

.cbsa-sort-button {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  min-width: 0;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: inherit;
  padding: 3px 5px;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.cbsa-sort-button:hover,
.cbsa-sort-button:focus-visible,
.cbsa-sort-button.active {
  border-color: var(--accent);
  background: var(--surface);
  color: var(--accent-strong);
}

.cbsa-sort-button strong {
  min-width: 0;
}

.cbsa-sort-marker {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 12px;
  color: var(--accent-strong);
}

.cbsa-main {
  --cbsa-control-row-h: 34px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  /* height parity with Units' .analysis-main so CBSA used-height matches (mobile overrides to 0) */
  padding-bottom: var(--bottom-nav-clearance);
}

.cbsa-table-wrap {
  background: var(--surface);
}

/* Wave-3 item 14: the State-grouping note moved from a permanent footnote into an info bubble
   next to the CBSA/State toggle in the sticky control row. */
.cbsa-mode-row {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}
.cbsa-info-button {
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  flex: 0 0 auto;
  padding: 0;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-subtle);
  cursor: pointer;
}
.cbsa-info-button:hover,
.cbsa-info-button[aria-expanded="true"] {
  background: var(--surface-hover);
  color: var(--accent);
}
.cbsa-info-popover {
  position: fixed;
  z-index: 80;
  max-width: min(320px, 80vw);
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface-overlay);
  box-shadow: var(--shadow-md);
  color: var(--text);
  font-size: var(--font-sm);
  line-height: 1.4;
}
.cbsa-info-popover[hidden] {
  display: none;
}

.cbsa-name-cell {
  display: flex;
  align-items: center;
  gap: 6px;
  justify-content: space-between;
  min-width: 0;
}

.cbsa-main .matrix-table .name-col {
  width: 220px;
  min-width: 220px;
  max-width: 220px;
}

.matrix-table thead .cbsa-control-row th {
  position: sticky;
  top: 0;
  z-index: 6;
  height: var(--cbsa-control-row-h);
  padding-top: 4px;
  padding-bottom: 4px;
  background: var(--surface-raised);
  color: var(--text-muted);
  vertical-align: middle;
}

.matrix-table thead .cbsa-control-row th.sticky-col {
  z-index: 8;
}

.matrix-table thead .cbsa-control-row + tr th {
  position: sticky;
  top: var(--cbsa-control-row-h);
}

.cbsa-header-mode-grid {
  display: grid;
  width: 100%;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: stretch;
}

.cbsa-header-mode {
  min-width: 0;
  border: 0;
  border-right: 1px solid var(--border-default);
  background: transparent;
  color: inherit;
  padding: 4px 5px;
  font: inherit;
  font-weight: var(--w-heavy);
  letter-spacing: 0;
  text-transform: uppercase;
  cursor: pointer;
}

.cbsa-header-mode:last-child {
  border-right: 0;
}

.cbsa-header-mode:hover,
.cbsa-header-mode:focus-visible,
.cbsa-header-mode.active {
  color: var(--accent-strong);
}

.cbsa-header-mode.active {
  background: var(--accent-soft);
}

.cbsa-control-fill {
  color: var(--text-muted);
}

.cbsa-control-download {
  text-align: right !important;
}

.cbsa-download-button {
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--text-muted);
  padding: 0;
  line-height: 1;
  cursor: pointer;
}

.cbsa-download-button:hover,
.cbsa-download-button:focus-visible {
  color: var(--accent-strong);
}

.cbsa-download-button svg {
  display: block;
}

.cbsa-name-cell .cbsa-link,
.cbsa-name-cell .state-group-toggle {
  flex: 1 1 auto;
}

.cbsa-link {
  display: block;
  min-width: 0;
  overflow: visible;
  color: var(--accent-strong);
  font-weight: var(--w-bold);
  line-height: 1.15;
  overflow-wrap: anywhere;
  text-decoration: none;
  white-space: normal;
}

.cbsa-link:hover,
.cbsa-link:focus-visible {
  text-decoration: underline;
}

.cbsa-total-column-sort {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  width: 100%;
  min-width: 34px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--accent-strong);
  padding: 2px 5px;
  font: inherit;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
  text-align: right;
  cursor: pointer;
}

.cbsa-total-column-sort strong {
  font: inherit;
  font-weight: var(--w-bold);
}

.cbsa-total-column-sort:hover,
.cbsa-total-column-sort:focus-visible,
.cbsa-total-column-sort.active {
  border-color: var(--accent);
  background: var(--surface-hover);
  color: var(--accent-strong);
}

.cbsa-total-column-sort.active {
  border-color: var(--accent-strong);
  background: var(--accent-soft);
}

.matrix-table tr.state-group-row td,
.matrix-table tr.state-group-row td.sticky-col {
  background: var(--surface-raised);
  font-weight: var(--w-bold);
}

.matrix-table tr.state-group-row:hover td,
.matrix-table tr.state-group-row:hover td.sticky-col {
  background: var(--surface-hover);
}

.state-group-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  min-width: 0;
  border: 0;
  background: transparent;
  color: inherit;
  padding: 0;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.matrix-drill-row td {
  background: var(--surface-hover);
  padding: 0;
}

.matrix-drilldown {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 16px 14px;
}

.drill-title {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  align-items: center;
  color: var(--text-muted);
  font-size: var(--font-sm);
}

.drill-title strong {
  color: var(--text-strong);
  font-size: var(--font-md);
}

.drill-close {
  margin-left: auto;
}

.drill-table-wrap {
  overflow: auto;
}

.drill-table {
  width: min(920px, 100%);
  min-width: min(720px, 100%);
  border-collapse: collapse;
  font-size: var(--font-sm);
  table-layout: fixed;
}

.matrix-drilldown .drill-table th,
.matrix-drilldown .drill-table td {
  position: static;
  z-index: auto;
  border-bottom: 1px solid var(--border-default);
  padding: 7px 8px;
  text-align: left;
  vertical-align: top;
  white-space: normal;
}

.matrix-drilldown .drill-table th {
  background: var(--surface-raised);
  color: var(--text-muted);
  font-size: var(--font-2xs);
  letter-spacing: 0;
  text-transform: uppercase;
}

.drill-table .drill-brand {
  width: 15%;
}

.drill-table .drill-unit {
  width: 18%;
}

.drill-table .drill-status {
  width: 9%;
}

.drill-table .drill-year {
  width: 9%;
  white-space: nowrap;
}

.drill-table .drill-address {
  width: 34%;
}

.drill-table .drill-franchisee {
  width: 15%;
}

.drill-table .drill-brand,
.drill-table .drill-unit,
.drill-table .drill-address,
.drill-table .drill-franchisee {
  overflow-wrap: anywhere;
}

.expander {
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border: 1px solid var(--border-default);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text-strong);
  line-height: 1;
  margin-right: 8px;
}

.expander:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.indent-1 {
  padding-left: 28px;
}

.indent-2 {
  padding-left: 52px;
}

.indent-3 {
  padding-left: 78px;
}

.unit-detail {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  color: var(--text-muted);
  font-size: var(--font-sm);
}

.unit-detail strong {
  color: var(--text);
}

.empty-cell {
  color: var(--text-muted);
  padding: 28px 16px !important;
  text-align: center !important;
}

.popup {
  min-width: 190px;
  max-width: 300px;
  padding: 8px 9px;
}

.popup h3 {
  display: flex;
  flex-wrap: wrap;
  gap: 3px 7px;
  align-items: baseline;
  margin: 0 0 5px;
  color: var(--text-strong);
  font-size: 14px;
  line-height: 1.18;
}

.popup-title-year {
  color: var(--text-strong);
  font-size: 13px;
  font-weight: var(--w-heavy);
}

.popup dl {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr);
  gap: 3px 6px;
  margin: 0;
}

.popup dt {
  color: var(--text-muted);
  font-size: var(--font-xs);
  line-height: 1.2;
}

.popup dd {
  min-width: 0;
  margin: 0;
  color: var(--text);
  font-size: var(--font-xs);
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.popup-brand-count-list {
  display: grid;
  max-height: 130px;
  overflow: auto;
  gap: 2px;
}

.popup-brand-count-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: baseline;
  gap: 7px;
}

.popup-brand-count-row span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.popup-brand-count-row strong {
  color: var(--text-strong);
  font-weight: var(--w-heavy);
}

/* Stage 3C: unit names listed beneath each brand in a grouped-bubble popup. */
.popup-brand-units {
  margin: 0 2px 4px;
  color: var(--text-subtle);
  font-size: var(--font-2xs, 10px);
  line-height: 1.3;
}

.popup-section {
  grid-column: 1;
  padding-top: 3px;
  color: var(--text-strong) !important;
  font-size: var(--font-2xs) !important;
  font-weight: var(--w-heavy);
  text-transform: uppercase;
}

.popup-section-rule {
  align-self: center;
  height: 1px;
  background: var(--border-default);
}

.review-muted {
  color: var(--text-muted) !important;
}

.popup-rating-pair {
  display: inline-flex;
  white-space: nowrap;
}

.momentum {
  display: inline-flex;
  margin-left: 4px;
  font-weight: var(--w-heavy);
}

.momentum.positive {
  color: var(--success-strong);
}

.momentum.negative {
  color: var(--danger-strong);
}

.momentum.neutral {
  color: var(--text-muted);
}

.review-badge {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--border-default);
  border-radius: 6px;
  padding: 1px 5px;
  font-size: var(--font-2xs);
  font-weight: var(--w-heavy);
}

.review-badge.positive {
  border-color: var(--success-border);
  background: var(--success-soft);
  color: var(--success-strong);
}

.review-badge.warning {
  border-color: var(--danger-border);
  background: var(--danger-soft);
  color: var(--danger-strong);
}

.review-badge.recovering {
  border-color: var(--info-border);
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.review-badge.neutral {
  color: var(--text-muted);
}

.analysis-app {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  flex: 1 1 auto;
  min-height: 0;
}

.analysis-main {
  min-width: 0;
  min-height: 0;
  overflow: auto;
  /* Wave-3 item 15: real bottom clearance so the last rows scroll clear of the fixed bottom nav
     (scroll-padding-bottom only affects anchoring, not reachable extent). */
  padding-bottom: var(--bottom-nav-clearance);
}

.analysis-panel h3 {
  margin: 0;
  font-family: var(--font-display);
  color: var(--text-strong);
  letter-spacing: -0.01em;
}

.analysis-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  padding: 14px;
}

.analysis-panel {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--border-default);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow-md);
}

.analysis-panel-wide {
  grid-column: 1 / -1;
}

.analysis-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--border-default);
  background: var(--surface-raised);
  padding: 12px 14px;
}

.analysis-panel h3 {
  font-size: var(--font-lg);
}

.analysis-chart,
.analysis-table-wrap {
  max-height: 430px;
  padding: 12px 14px 14px;
}

.analysis-chart {
  container-type: inline-size;
  overflow-x: hidden;
  overflow-y: auto;
}

.analysis-table-wrap {
  overflow: auto;
}

.rank-bars,
.mix-bars,
.review-bars {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.rank-row,
.mix-row,
.review-row {
  display: grid;
  align-items: center;
  gap: 10px;
  min-width: 0;
  /* No overflow-x:auto here: it forced overflow-y to compute to `auto`, which clipped the stacked-bar
     hover/pin popovers (they intentionally overflow the row) and spawned per-row horizontal
     scrollbars. The grid tracks below carry min-width:0 so each row shrinks to fit instead. */
}

.rank-row {
  grid-template-columns: minmax(130px, 220px) minmax(160px, 1fr) 74px 84px;
}

.rank-heading {
  color: var(--text-muted);
  font-size: var(--font-xs);
  font-weight: var(--w-heavy);
  text-transform: uppercase;
}

/* Part D1: the review chart's column headers (Rating / L6Mo Momentum). Unlike the rank-heading —
   which is hidden when its rows reflow to grid-areas on narrow containers — the review row stays a
   single line at all widths (Part D2), so this header stays VISIBLE everywhere to label both value
   columns. Same muted/uppercase treatment as the rank heading. */
.review-heading {
  color: var(--text-muted);
  font-size: var(--font-2xs);
  font-weight: var(--w-heavy);
  text-transform: uppercase;
}
.review-heading > div {
  min-width: 0;
}

.mix-row {
  grid-template-columns: minmax(130px, 190px) minmax(170px, 1fr) 56px;
}

.review-row {
  grid-template-columns: minmax(130px, 190px) minmax(190px, 1fr) minmax(190px, 1fr);
}

.rank-track,
.stacked-bar,
.review-metric {
  min-width: 0;
}

@container (max-width: 560px) {
  .rank-row {
    grid-template-columns: minmax(92px, 34%) minmax(70px, 1fr) minmax(44px, auto) minmax(54px, auto);
    grid-template-areas: "label track value outside";
    column-gap: 8px;
    row-gap: 3px;
  }

  .rank-row > .rank-label {
    grid-area: label;
  }

  .rank-row > .rank-track {
    grid-area: track;
  }

  .rank-row > .rank-value {
    grid-area: value;
  }

  .rank-row > .rank-value.outside-na-value {
    grid-area: outside;
  }

  .mix-row {
    grid-template-columns: minmax(96px, 36%) minmax(72px, 1fr) minmax(44px, auto);
    grid-template-areas: "label track total";
    column-gap: 8px;
    row-gap: 3px;
  }

  .mix-row > .mix-label {
    grid-area: label;
  }

  .mix-row > .stacked-bar {
    grid-area: track;
  }

  .mix-row > .mix-total {
    grid-area: total;
  }

  /* Part D2: keep the review row on ONE line at narrow container widths (condensed 3-col), not the
     old single-column stack. The .review-metric condense (styles.units.css) shrinks the bars/numbers
     to fit; overflow-x:auto on .review-row is the last-resort fallback. */
  .review-row {
    grid-template-columns: minmax(64px, 1.2fr) minmax(78px, 1fr) minmax(78px, 1fr);
    gap: 8px;
  }

  /* Keep the column titles ("NA Units", "Outside NA", "CBSAs", …) visible above the
     value columns on narrow widths (was display:none, leaving the number columns
     unlabeled). Map the heading's two empty cells and its two value labels onto the
     reflowed grid areas so each title sits above its number column. */
  .rank-heading > :nth-child(1) {
    grid-area: label;
  }

  .rank-heading > :nth-child(2) {
    grid-area: track;
  }

  .rank-heading > :nth-child(3) {
    grid-area: value;
  }

  .rank-heading > :nth-child(4) {
    grid-area: outside;
  }

  /* Let the titles size to their full text instead of truncating to an ellipsis. */
  .rank-heading .rank-value-label,
  .rank-heading .sort-button span:first-child {
    overflow: visible;
    text-overflow: clip;
  }
}

@container (max-width: 300px) {
  .review-metric {
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 6px;
  }
}

/* The review row (favicon · brand · rating · L6Mo) can't condense below ~340px — two value+bar
   metrics plus the brand label. Above that it shrinks to fit (no scroll); only when the chart
   container is narrower than its content (e.g. the ~307px desktop two-column charts) does it fall
   back to a contained horizontal scroll, which keeps the chart itself from overflowing. */
@container (max-width: 340px) {
  .review-row {
    overflow-x: auto;
  }
}

.rank-label,
.mix-label,
.review-brand,
.brand-cell {
  min-width: 0;
  overflow: hidden;
  color: var(--text);
  font-size: var(--font-sm);
  font-weight: 750;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand-label-content {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  max-width: 100%;
  min-width: 0;
  vertical-align: middle;
}

.rank-label .brand-label-content,
.mix-label .brand-label-content,
.review-brand .brand-label-content,
.brand-cell .brand-label-content {
  width: 100%;
}

.brand-label-text {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand-favicon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  flex: 0 0 16px;
  border-radius: 4px;
  background: var(--surface);
  box-shadow: 0 0 0 1px var(--border-subtle);
  object-fit: contain;
}

.brand-favicon-initial {
  color: #fff;
  font-size: 9px;
  font-weight: var(--w-heavy);
  line-height: 1;
  text-shadow: 0 1px 1px rgba(15, 23, 42, 0.32);
}

.rank-track,
.rating-track,
.momentum-track,
.stacked-bar {
  overflow: hidden;
  border: 1px solid var(--border-default);
  border-radius: 8px;
  background: var(--bar-track);
}

.rank-track {
  height: 18px;
}

.rank-fill {
  display: flex;
  height: 100%;
  overflow: hidden;
  border-radius: 7px;
  background: var(--accent);
}

.rank-segment {
  display: block;
  min-width: 0;
  height: 100%;
}

.unit-status-legend-item {
  cursor: default;
}

.rank-value,
.mix-total {
  color: var(--text-strong);
  font-size: var(--font-sm);
  font-weight: var(--w-heavy);
  text-align: right;
  white-space: nowrap;
}

/* Column titles for the mix charts: "NA Units" over the total column, "Pop." over the
   population-benchmark total. Small muted uppercase so it reads as a header, not data. */
.mix-header {
  align-items: end;
  min-height: 0;
  padding-bottom: 1px;
}

.mix-col-head {
  font-size: var(--font-2xs);
  font-weight: var(--w-bold);
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.mix-col-head-total {
  text-align: right;
}

.population-mix-total .mix-col-head {
  display: block;
  text-align: right;
}

/* Openings by Year: vertical stacked columns (one per year), brand-colored segments. */
.openings-wrap {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.openings-grid {
  display: flex;
  align-items: stretch;
  gap: 6px;
  height: 320px;
  padding-top: 6px;
}

.openings-col {
  display: flex;
  flex: 1 1 0;
  min-width: 0;
  flex-direction: column;
  gap: 4px;
  height: 100%;
}

.openings-stack {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column-reverse;
  min-height: 0;
  overflow: hidden;
  border-bottom: 1px solid var(--border-default);
  border-radius: 3px 3px 0 0;
}

.openings-seg {
  display: block;
  flex: 0 0 auto;
  width: 100%;
  min-height: 1px;
}

.openings-seg + .openings-seg {
  border-top: 1px solid var(--surface);
}

.openings-axis {
  flex: 0 0 auto;
  text-align: center;
  font-size: var(--font-2xs);
  color: var(--text-muted);
  white-space: nowrap;
}

.rank-value-label {
  overflow: hidden;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rank-sort-button:hover {
  color: var(--accent-strong);
}

.outside-na-value {
  color: var(--text-muted);
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 7px;
  margin-bottom: 10px;
}

.chart-legend-hint {
  color: var(--text-subtle);
  font-size: var(--font-2xs);
  font-weight: var(--w-bold);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.ui-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  display: inline-flex;
  align-items: center;
  gap: 14px;
  z-index: 9999;
  padding: 10px 16px;
  border-radius: 999px;
  border: 1px solid var(--border-default);
  background: var(--surface-overlay);
  color: var(--text);
  font-size: var(--font-md);
  font-weight: var(--w-semi);
  box-shadow: var(--shadow-md);
  backdrop-filter: saturate(140%) blur(8px);
  animation: ui-toast-rise 180ms ease-out;
}

@keyframes ui-toast-rise {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

.ui-toast-action {
  border: none;
  background: transparent;
  color: var(--accent-strong);
  font-weight: var(--w-bold);
  font-size: var(--font-sm);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  cursor: pointer;
  padding: 4px 6px;
}

.ui-toast-action:hover {
  color: var(--accent);
}

.chart-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: 1px solid var(--border-default);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 7px;
  font-size: var(--font-xs);
  font-weight: 750;
}

.chart-legend-item:hover,
.chart-legend-item:focus-visible,
.chart-legend-item.active {
  border-color: var(--accent);
  color: var(--accent-strong);
}

.chart-legend-item .sort-marker.is-hint {
  opacity: 0;
  transition: opacity 120ms ease;
  color: var(--text-subtle);
}

.chart-legend-item:hover .sort-marker.is-hint,
.chart-legend-item:focus-visible .sort-marker.is-hint {
  opacity: 1;
}

.chart-legend-item.active {
  background: var(--accent-soft);
}

.chart-legend-swatch {
  width: 10px;
  height: 10px;
  flex: 0 0 10px;
  border-radius: 50%;
}

.chart-legend-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stacked-bar {
  display: flex;
  height: 24px;
  min-width: 0;
}

.interactive-stacked-bar,
.cbsa-stacked-bar {
  position: relative;
  overflow: visible;
}

.interactive-stacked-bar .stack-segment:first-child,
.cbsa-stacked-bar .stack-segment:first-child {
  border-radius: 7px 0 0 7px;
}

.interactive-stacked-bar .stack-segment:last-child,
.cbsa-stacked-bar .stack-segment:last-child {
  border-radius: 0 7px 7px 0;
}

.population-mix-row {
  margin-bottom: 12px;
  border-bottom: 1px solid var(--border-default);
  padding-bottom: 12px;
}

.population-mix-label {
  color: var(--text-strong);
}

.population-mix-bar {
  height: 30px;
  background: var(--surface-raised);
}

.population-mix-total {
  color: var(--text-muted);
  font-size: var(--font-xs);
}

.stack-segment {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  overflow: hidden;
  color: var(--text-on-accent);
  font-size: var(--font-2xs);
  font-weight: 850;
  line-height: 1;
  text-shadow: 0 1px 1px rgba(15, 23, 42, 0.28);
  white-space: nowrap;
}

.stack-segment[role="button"] {
  cursor: pointer;
}

.interactive-stack-segment,
.cbsa-stack-segment {
  isolation: isolate;
  overflow: visible;
  position: static;
  transition: opacity 120ms ease, filter 120ms ease, box-shadow 120ms ease;
}

.interactive-stack-bars.has-stack-active .interactive-stack-segment,
.cbsa-mix-bars.has-cbsa-active .cbsa-stack-segment {
  opacity: 0.22;
  filter: grayscale(35%);
}

.interactive-stack-bars.has-stack-active .interactive-stack-segment.is-stack-active,
.interactive-stack-segment:hover,
.interactive-stack-segment:focus-visible,
.cbsa-mix-bars.has-cbsa-active .cbsa-stack-segment.is-cbsa-active,
.cbsa-stack-segment:hover,
.cbsa-stack-segment:focus-visible {
  opacity: 1;
  filter: none;
}

.interactive-stack-segment.is-stack-active,
.interactive-stack-segment:focus-visible,
.cbsa-stack-segment.is-cbsa-active,
.cbsa-stack-segment:focus-visible {
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.78), 0 0 0 1px rgba(15, 23, 42, 0.18);
}

.interactive-stack-segment:hover,
.interactive-stack-segment:focus-visible,
.interactive-stack-segment.is-stack-pinned,
.cbsa-stack-segment:hover,
.cbsa-stack-segment:focus-visible,
.cbsa-stack-segment.is-cbsa-pinned {
  z-index: 12;
}

.stack-segment-value,
.cbsa-segment-value {
  display: block;
  max-width: 100%;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stack-segment-popover,
.cbsa-segment-popover {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 8px;
  z-index: 18;
  display: none;
  width: max-content;
  max-width: min(230px, calc(100% - 16px));
  gap: 2px;
  transform: translateY(2px);
  border: 1px solid var(--border-default);
  border-radius: 8px;
  background: var(--cbsa-popover-bg);
  box-shadow: var(--shadow-md);
  color: var(--text);
  font-size: var(--font-xs);
  font-weight: var(--w-bold);
  line-height: 1.25;
  opacity: 0;
  padding: 7px 9px;
  pointer-events: none;
  text-align: left;
  text-shadow: none;
  transition: opacity 120ms ease, transform 120ms ease, visibility 120ms ease;
  visibility: hidden;
  white-space: normal;
}

.stack-segment-popover::after,
.cbsa-segment-popover::after {
  position: absolute;
  top: 100%;
  left: 12px;
  width: 8px;
  height: 8px;
  transform: translateY(-4px) rotate(45deg);
  border-right: 1px solid var(--border-default);
  border-bottom: 1px solid var(--border-default);
  background: var(--cbsa-popover-bg);
  content: "";
}

/* Units stacked-bar tooltips float to the SIDE of the segment via position:fixed (coordinates set
   in analysis.js positionStackPopover). Fixed elements don't contribute to the chart's scroll
   overflow, so the popover no longer grows the chart and toggles a scrollbar (the hover jitter).
   Scoped to .stack-segment-popover (Units); .cbsa-segment-popover keeps its in-flow placement. */
.stack-segment-popover {
  position: fixed;
  top: 0;
  left: 0;
  bottom: auto;
  z-index: 50;
}

.stack-segment-popover::after {
  display: none;
}

.interactive-stack-segment:hover .stack-segment-popover,
.interactive-stack-segment:focus-visible .stack-segment-popover,
.interactive-stack-segment.is-stack-pinned .stack-segment-popover,
.cbsa-stack-segment:hover .cbsa-segment-popover,
.cbsa-stack-segment:focus-visible .cbsa-segment-popover,
.cbsa-stack-segment.is-cbsa-pinned .cbsa-segment-popover {
  display: grid;
  transform: translateY(0);
  opacity: 1;
  visibility: visible;
}

.interactive-stack-bars .mix-row:first-child .stack-segment-popover,
.population-mix-row .stack-segment-popover,
.cbsa-mix-bars .mix-row:first-child .cbsa-segment-popover {
  top: calc(100% + 8px);
  bottom: auto;
  transform: translateY(-2px);
}

.interactive-stack-bars .mix-row:first-child .stack-segment-popover::after,
.population-mix-row .stack-segment-popover::after,
.cbsa-mix-bars .mix-row:first-child .cbsa-segment-popover::after {
  top: auto;
  bottom: 100%;
  transform: translateY(4px) rotate(45deg);
  border: 0;
  border-top: 1px solid var(--border-default);
  border-left: 1px solid var(--border-default);
}

.interactive-stack-bars .mix-row:first-child .interactive-stack-segment:hover .stack-segment-popover,
.interactive-stack-bars .mix-row:first-child .interactive-stack-segment:focus-visible .stack-segment-popover,
.interactive-stack-bars .mix-row:first-child .interactive-stack-segment.is-stack-pinned .stack-segment-popover,
.population-mix-row .interactive-stack-segment:hover .stack-segment-popover,
.population-mix-row .interactive-stack-segment:focus-visible .stack-segment-popover,
.population-mix-row .interactive-stack-segment.is-stack-pinned .stack-segment-popover,
.cbsa-mix-bars .mix-row:first-child .cbsa-stack-segment:hover .cbsa-segment-popover,
.cbsa-mix-bars .mix-row:first-child .cbsa-stack-segment:focus-visible .cbsa-segment-popover,
.cbsa-mix-bars .mix-row:first-child .cbsa-stack-segment.is-cbsa-pinned .cbsa-segment-popover {
  transform: translateY(0);
}

.stack-popover-label,
.stack-popover-meta,
.cbsa-popover-label,
.cbsa-popover-meta {
  display: block;
  overflow-wrap: anywhere;
}

.stack-popover-meta,
.cbsa-popover-meta {
  color: var(--text-muted);
  font-size: var(--font-2xs);
}

.review-metric {
  display: grid;
  grid-template-columns: 54px minmax(100px, 1fr) 54px;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.review-number,
.review-count {
  color: var(--text-muted);
  font-size: var(--font-xs);
  font-weight: var(--w-heavy);
  white-space: nowrap;
}

.review-number {
  color: var(--text-strong);
  text-align: right;
}

.rating-track,
.momentum-track {
  position: relative;
  height: 16px;
}

.rating-fill {
  display: block;
  height: 100%;
  border-radius: 7px;
  background: linear-gradient(90deg, var(--warning), var(--success));
}

.momentum-track::before {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 1px;
  background: var(--rule);
  content: "";
}

.momentum-fill {
  position: absolute;
  top: 0;
  bottom: 0;
  border-radius: 7px;
}

.momentum-fill.positive {
  background: var(--success);
}

.momentum-fill.negative {
  background: var(--danger);
}

.momentum-fill.neutral {
  background: var(--text-subtle);
}

.metric-table {
  min-width: 1180px;
}

/* Part D1: let metric-table headers wrap + show in full (no ellipsis) so every value column has a
   readable label. SCOPED to .metric-table — the global .sort-button span:first-child truncation is
   untouched (shared by CBSA / Map / Social tables). Header font shrinks to fit the now-wrapping text. */
.metric-table th {
  white-space: normal;
  font-size: var(--font-2xs);
}
.metric-table .sort-button span:first-child {
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
}

.metric-cell {
  position: relative;
  min-width: 116px;
  overflow: hidden;
}

.metric-cell-bar {
  position: absolute;
  inset: 5px auto 5px 8px;
  max-width: calc(100% - 16px);
  border-radius: 6px;
  background: var(--accent-soft);
}

.metric-cell-value {
  position: relative;
  z-index: 1;
  color: var(--text-strong);
  font-weight: 750;
}

.trends-app {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  flex: 1 1 auto;
  min-height: 0;
}

.trends-main {
  min-width: 0;
  min-height: 0;
  overflow: auto;
}

.trends-chart-section {
  padding: 14px 0;
}

.trends-panel {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--border-default);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow-md);
}

.trends-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--border-default);
  background: var(--surface-raised);
  /* Stage 5/6/7: header only as tall as its text (was 12px). */
  padding: 8px 14px;
}

.trends-panel-header h3 {
  min-width: 0;
  margin: 0;
  color: var(--text-strong);
  font-size: var(--font-lg);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Part B2: Granularity (Annual/Quarterly/Monthly) lives in the Absolute Search Interest header as a
   compact segmented group, pinned to the far right (the auto margin pushes it past the title + note).
   Visible on every viewport — the old mobile `#trends-granularity{display:none}` was removed. */
.trends-panel-header #trends-granularity.trends-granularity-header {
  margin-left: auto;
  flex: 0 0 auto;
}
.trends-panel-header #trends-granularity.trends-granularity-header .segment {
  padding: 4px 9px;
}

.trends-panel-title-with-info {
  position: relative;
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 8px;
}

.trends-chart-layout {
  --trends-chart-h: var(--chart-height);
  /* P1d: cap legends at the first 15 rows then scroll (was 10). Drives .trends-legend-rows
     (Relative-Mix), #trends-absolute-legend (Search Absolute), and the .trends-ramp-legend
     max-height (Momentum) — all read this var via inheritance. */
  --trends-legend-visible-rows: 15;
  --trends-legend-row-h: 30px;
  --trends-legend-row-gap: 2px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(220px, 22vw, 320px);
  gap: 10px;
  padding: 12px 0;
  position: relative;
}

.trends-chart-frame {
  position: relative;
  min-width: 0;
}

@media (min-width: 941px) {
  .trends-chart-frame {
    display: flex;
    min-height: var(--trends-chart-h);
  }

  .trends-chart-frame > #trends-chart {
    flex: 1 1 auto;
    height: auto;
    min-height: var(--trends-chart-h);
  }
}

/* P1c: on wide desktops, give the Search/Momentum charts more width — narrow the filter
   sidebar and shrink the Relative-Mix legend track. Scoped to trends pages (.trends-app,
   which momentum also carries via .ramps-app); the global --sidebar-width (:110) that also
   drives CBSA/Units (.analysis-app) is left untouched. #trends-absolute-chart /
   #ramps-absolute-chart share .trends-chart-layout so they widen too. */
@media (min-width: 1200px) {
  .trends-app {
    --sidebar-width: 300px;
  }
  .trends-chart-layout {
    grid-template-columns: minmax(0, 1fr) clamp(200px, 18vw, 280px);
  }
}

.trends-panel-footnote {
  padding: 0 14px 12px;
  color: var(--text-muted);
  font-size: var(--font-xs, 11px);
  line-height: 1.4;
}

.trends-panel-footnote:empty {
  display: none;
}

.trends-chart {
  height: var(--trends-chart-h);
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border-default);
  border-radius: 6px;
  background: var(--surface-raised);
  overflow: hidden;
}

/* P5: let desktop users drag the bottom edge of the two "absolute" charts to make them taller —
   Absolute Search Interest (#trends-absolute-chart) and Relative Search Since Year Founded
   (#ramps-absolute-chart). resize:vertical needs a non-visible overflow, so this overrides
   .trends-chart's overflow:hidden. Bounded so the grip can't collapse or overrun the chart; the
   ID selectors outrank the .trends-chart class. Mobile keeps the fixed height (no grip). A
   dedicated ResizeObserver (trends.js / ramps.js) re-lays the SVG so it grows, not viewBox-stretches. */
@media (min-width: 941px) {
  #trends-absolute-chart,
  #ramps-absolute-chart,
  #trends-chart,
  #ramps-chart {
    resize: vertical;
    overflow: auto;
    min-height: var(--chart-height);
    max-height: calc(var(--chart-height) * 3);
  }
  /* Default (starting) height. Relative Google Search Mix (#trends-chart) keeps its flex/--trends-chart-h
     default and only gains the grip; the other three open at 539px (mid-range of the 280–840 bounds). */
  #trends-absolute-chart,
  #ramps-absolute-chart,
  #ramps-chart {
    height: 539px;
  }
}

.trends-chart-svg {
  display: block;
  width: 100%;
  height: 100%;
  font-family: inherit;
}

.trends-granularity-buttons {
  position: absolute;
  z-index: 2;
  bottom: 7px;
  left: min(calc(100% - 52px), calc(50% + 186px));
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 2px;
  border: 1px solid var(--border-default);
  border-radius: 6px;
  background: var(--surface);
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.08);
}

.trends-granularity-buttons button {
  display: inline-grid;
  width: 22px;
  height: 20px;
  place-items: center;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--text-muted);
  font-size: 10px;
  font-weight: var(--w-heavy);
  line-height: 1;
  padding: 0;
  transition: background-color 120ms ease, color 120ms ease;
}

.trends-granularity-buttons button:hover,
.trends-granularity-buttons button:focus-visible {
  color: var(--accent-strong);
  outline: 0;
}

.trends-granularity-buttons button:focus-visible {
  box-shadow: 0 0 0 2px var(--focus-ring);
}

.trends-granularity-buttons button.active {
  background: var(--accent);
  color: var(--text-on-accent);
}

/* Stage 5: quiet, horizontal-only grid + a single subtle baseline (no heavy plot border). */
.trends-grid-line {
  stroke: var(--chart-grid);
  stroke-width: 1;
  opacity: 1;
}

.trends-axis-rule {
  stroke: var(--chart-grid);
  stroke-width: 1;
}

.trends-axis-tick {
  stroke: var(--chart-grid);
  stroke-width: 1;
}

.trends-axis-label {
  fill: var(--chart-axis-ink);
  font-size: 10px;
  font-weight: 400;
}

.trends-area {
  transition: fill-opacity 120ms ease;
}

.trends-area.is-dimmed,
.trends-area.is-locked-dim {
  fill-opacity: 0.18;
}

.trends-area.is-locked-focus {
  fill-opacity: 1;
}

/* Stage 6A: hovering a stacked band keeps it vivid and dims the others. Legend hover (.is-dimmed)
   and the drilldown lock (.is-locked-focus) keep priority. */
.trends-chart svg.has-area-hover .trends-area:not(.is-hovered):not(.is-locked-focus):not(.is-dimmed) {
  fill-opacity: 0.2;
}
.trends-chart svg.has-area-hover .trends-area.is-hovered {
  fill-opacity: 0.95;
}

.trends-ramp-line {
  fill: none;
  stroke-width: var(--chart-stroke);
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
  transition: opacity 120ms ease, stroke-width 120ms ease;
}

.trends-ramp-line.is-dimmed {
  opacity: 0.16;
}

/* Part A2: the aggregate OVERLAY line — a dashed reference curve drawn over the broken-out brand
   lines. Thinner + dashed so it reads as context, not a peer brand line. */
.trends-ramp-line.is-overlay {
  stroke-dasharray: 6 5;
  stroke-width: 2;
  opacity: 0.85;
}

.trends-ramp-line.is-focused,
.trends-ramp-line.is-pinned {
  opacity: 1;
  stroke-width: 4.6;
  filter: drop-shadow(0 1px 2px rgba(15, 23, 42, 0.28));
}

/* Overlay focus/pin keeps the dash so it stays visually distinct from brand lines. */
.trends-ramp-line.is-overlay.is-focused,
.trends-ramp-line.is-overlay.is-pinned {
  stroke-width: 3;
}

.trends-ramp-annotations {
  pointer-events: none;
}

.trends-ramp-hitbox {
  fill: transparent;
  cursor: crosshair;
  pointer-events: all;
}

.trends-ramp-hover {
  pointer-events: none;
}

.trends-ramp-hover-rule {
  stroke: var(--text-muted);
  stroke-width: 1;
  stroke-dasharray: 4 4;
  opacity: 0.45;
  vector-effect: non-scaling-stroke;
}

.trends-ramp-callout {
  pointer-events: none;
}

.trends-ramp-callout-connector {
  stroke-width: 1.2;
  opacity: 0.72;
  vector-effect: non-scaling-stroke;
}

.trends-ramp-callout-point {
  fill: var(--surface);
  stroke-width: 2.2;
  vector-effect: non-scaling-stroke;
}

.trends-ramp-callout-box {
  fill: var(--surface);
  fill-opacity: 0.72;
  stroke: var(--border-strong, var(--border-default));
  stroke-width: 1;
  filter: drop-shadow(0 2px 4px rgba(15, 23, 42, 0.14));
}

.trends-ramp-callout-box.is-dismissible {
  cursor: pointer;
  pointer-events: all;
}

.trends-ramp-callout-box.is-dismissible:hover,
.trends-ramp-callout-box.is-dismissible:focus-visible {
  fill: var(--surface-hover);
  stroke: var(--accent);
}

.trends-ramp-callout-label-rule {
  stroke-width: 2.6;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}

.trends-ramp-callout-brand-mark {
  pointer-events: none;
}

.trends-ramp-callout-brand-mark-frame {
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}

.trends-ramp-callout-brand-image {
  pointer-events: none;
}

.trends-ramp-callout-brand-initial {
  fill: #fff;
  font-size: 11px;
  font-weight: 800;
  pointer-events: none;
}

.trends-ramp-callout-primary {
  fill: var(--text-strong);
  font-size: var(--font-xs, 11px);
  font-weight: var(--w-heavy);
  pointer-events: none;
}

.trends-ramp-callout-secondary {
  fill: var(--text-muted);
  font-size: var(--font-2xs, 10px);
  font-weight: var(--w-regular);
  pointer-events: none;
}

.trends-ramp-callout-secondary.is-strong {
  fill: var(--text-strong);
  font-size: var(--font-xs, 11px);
  font-weight: var(--w-heavy);
}

.trends-ramp-hover-connector {
  stroke-width: 1.2;
  opacity: 0.72;
  vector-effect: non-scaling-stroke;
}

.trends-ramp-hover-point {
  fill: var(--surface);
  stroke-width: 2.2;
  vector-effect: non-scaling-stroke;
}

.trends-ramp-hover-box {
  fill: var(--surface);
  stroke: var(--border-strong, var(--border-default));
  stroke-width: 1;
  filter: drop-shadow(0 3px 6px rgba(15, 23, 42, 0.2));
}

.trends-ramp-hover-label-rule {
  stroke-width: 2.6;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}

.trends-ramp-hover-brand,
.trends-ramp-hover-period {
  fill: var(--text-strong);
  font-size: var(--font-xs, 11px);
}

.trends-ramp-hover-brand {
  font-weight: var(--w-heavy);
}

.trends-ramp-hover-period {
  fill: var(--text-muted);
  font-weight: 650;
}

.trends-ramp-max-connector {
  stroke-width: 1.4;
  opacity: 0.72;
  vector-effect: non-scaling-stroke;
}

.trends-ramp-max-point {
  fill: var(--surface);
  stroke-width: 2.4;
  vector-effect: non-scaling-stroke;
}

.trends-ramp-max-label-box {
  fill: var(--surface);
  stroke: var(--border-strong, var(--border-default));
  stroke-width: 1;
  filter: drop-shadow(0 2px 4px rgba(15, 23, 42, 0.18));
}

.trends-ramp-max-label-rule {
  stroke-width: 2.6;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}

.trends-ramp-max-label-text {
  fill: var(--text-strong);
  font-size: var(--font-xs, 11px);
  font-weight: var(--w-heavy);
}

.method-info {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 19px;
  height: 19px;
  flex: 0 0 19px;
  color: var(--accent-strong);
  cursor: help;
  font-family: var(--font-sans);
  letter-spacing: 0;
  text-transform: none;
}

.method-info-icon {
  display: inline-grid;
  place-items: center;
  width: 17px;
  height: 17px;
  border: 1px solid var(--accent);
  border-radius: 999px;
  font-size: var(--font-2xs, 10px);
  font-weight: var(--w-heavy);
  letter-spacing: 0;
  line-height: 1;
  text-transform: none;
}

.method-info-bubble {
  position: absolute;
  top: calc(100% + 8px);
  left: 50%;
  right: auto;
  z-index: 30;
  display: none;
  width: min(218px, calc(100vw - 48px));
  box-sizing: border-box;
  border: 1px solid var(--info-border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--font-xs, 11px);
  font-weight: var(--w-reg);
  letter-spacing: 0;
  line-height: 1.35;
  padding: 10px 11px;
  text-align: left;
  text-transform: none;
  transform: translateX(-42%);
  white-space: normal;
}

.method-info-bubble::before {
  position: absolute;
  top: -5px;
  left: 42%;
  width: 8px;
  height: 8px;
  border-top: 1px solid var(--info-border);
  border-left: 1px solid var(--info-border);
  background: var(--surface);
  content: "";
  transform: rotate(45deg);
}

/* Shown on click-toggle (`hidden` removed by the shared info-bubble helper) and, as a desktop
   convenience, transiently on hover/focus. */
.method-info-bubble:not([hidden]),
.method-info:hover .method-info-bubble,
.method-info:focus-visible .method-info-bubble,
.method-info:focus-within .method-info-bubble {
  display: grid;
  gap: 7px;
}

.method-info-line {
  display: block;
  color: inherit;
  font: inherit;
  letter-spacing: 0;
  line-height: inherit;
  text-align: left;
  text-transform: none;
}

.method-info-line strong {
  font: inherit;
}

.method-info:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 999px;
}

.top-rank-mode {
  margin-top: 0;
}

.top-range-group {
  display: grid;
  gap: 7px;
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  background: var(--surface-raised);
  padding: 8px;
}

.top-range-group-caption {
  color: var(--text-subtle);
  font-size: var(--font-2xs);
  font-weight: var(--w-bold);
  letter-spacing: 0.04em;
  line-height: 1;
  text-transform: uppercase;
}

.trends-ramp-legend {
  display: grid;
  align-content: start;
  gap: 5px;
  min-width: 0;
  overflow: auto;
  /* P1d: cap Momentum legends (#ramps-absolute-legend/#ramps-chart-legend) at 15 rows then
     scroll (was unbounded). Same formula as #trends-absolute-legend; vars inherited from
     .trends-chart-layout (search + momentum both carry it). ID cap on the search-absolute
     legend still wins where set. */
  max-height: calc(
    var(--trends-legend-visible-rows, 10) * var(--trends-legend-row-h, 30px) +
    (var(--trends-legend-visible-rows, 10) - 1) * 5px +
    18px
  );
  border: 1px solid var(--border-default);
  border-radius: 6px;
  background: var(--surface-raised);
  padding: 8px;
}

.trends-ramp-legend:empty::after {
  content: "No curves";
  color: var(--text-muted);
  font-size: var(--font-sm);
}

.trends-ramp-legend-row {
  /* Part B4: enlarged to match .trends-legend (swatch 12->14, larger swatch-left gap). Shared with
     both Momentum legends. font-size is already var(--font-sm). */
  display: grid;
  grid-template-columns: 14px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  min-height: 26px;
  border-radius: 5px;
  color: var(--text);
  cursor: pointer;
  font-size: var(--font-sm);
  padding: 2px 4px;
  transition: background-color 120ms ease, box-shadow 120ms ease, color 120ms ease;
}

.trends-ramp-legend-row.is-removable {
  grid-template-columns: 14px minmax(0, 1fr) 18px;
}

/* Part A2: overlay (aggregate) legend row — italic label + a dashed-outline swatch so it reads as a
   derived reference line, not a brand. Its remove button hides the overlay (renderer wires it). */
.trends-ramp-legend-row.is-overlay .trends-ramp-legend-label {
  font-style: italic;
}
.trends-ramp-legend-row.is-overlay .trends-ramp-legend-swatch {
  border: 1px dashed var(--text-subtle);
  background-clip: padding-box;
}

.trends-ramp-legend-row .trends-ramp-legend-remove {
  opacity: 0;
}

.trends-ramp-legend-row:hover .trends-ramp-legend-remove,
.trends-ramp-legend-row:focus-within .trends-ramp-legend-remove,
.trends-ramp-legend-remove:focus-visible {
  opacity: 1;
}

.trends-ramp-legend-row:hover,
.trends-ramp-legend-row:focus-visible,
.trends-ramp-legend-row.is-active,
.trends-ramp-legend-row.is-pinned {
  background: var(--surface-hover);
  color: var(--text-strong);
  outline: none;
}

.trends-ramp-legend-row.is-pinned {
  box-shadow: inset 0 0 0 1px var(--accent);
}

.trends-ramp-legend-swatch {
  /* Part B4: 12 -> 14 to match .trends-legend-swatch. */
  width: 14px;
  height: 14px;
  border-radius: 4px;
}

.trends-ramp-legend-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rank-label,
.mix-label,
.review-brand {
  display: flex;
  align-items: center;
  gap: 6px;
}

.analysis-chart-brand-label .brand-label-content {
  width: auto;
  flex: 1 1 auto;
}

.analysis-chart-remove {
  appearance: none;
  display: inline-flex;
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: 50%;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  opacity: 0;
  padding: 0;
  transition: opacity 120ms ease, color 120ms ease, background-color 120ms ease, border-color 120ms ease;
}

.rank-row:hover .analysis-chart-remove,
.mix-row:hover .analysis-chart-remove,
.review-row:hover .analysis-chart-remove,
.analysis-chart-remove:focus-visible {
  opacity: 1;
}

.analysis-chart-remove:hover,
.analysis-chart-remove:focus-visible {
  border-color: var(--border-default);
  background: var(--surface);
  color: var(--danger, #dc2626);
}

.trends-ramp-legend-label.has-favicon {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.trends-ramp-legend-favicon {
  display: inline-flex;
  align-items: center;
  flex: 0 0 16px;
}

.trends-ramp-legend-label-text {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.trends-overlay {
  fill: transparent;
  pointer-events: all;
  cursor: crosshair;
}

.trends-tick-hitbox {
  fill: var(--text-muted, #94a3b8);
  fill-opacity: 0;
  pointer-events: all;
  cursor: pointer;
  transition: fill-opacity 120ms ease;
}

.trends-tick-hitbox:hover {
  fill-opacity: 0.1;
}

.trends-brush-handle-hitbox {
  fill: transparent;
  pointer-events: all;
  cursor: ew-resize;
}

.trends-break-marker {
  pointer-events: none;
  opacity: 0.85;
}

.trends-brush-track {
  fill: var(--surface-overlay, #e2e8f0);
  rx: 3;
  ry: 3;
  cursor: default;
  pointer-events: all;
}

.trends-brush-selection {
  fill: var(--accent, #3b82f6);
  fill-opacity: 0.25;
  cursor: grab;
  pointer-events: all;
}

.trends-brush-selection:active {
  cursor: grabbing;
}

.trends-brush-handle {
  fill: var(--accent, #3b82f6);
  cursor: ew-resize;
  rx: 2;
  ry: 2;
  pointer-events: all;
}

.trends-brush-handle:hover {
  fill: var(--accent-strong, #2563eb);
}

.trends-brush-notch {
  stroke: var(--text-strong, #0f172a);
  stroke-width: 1.5;
  stroke-linecap: round;
  opacity: 0.72;
  pointer-events: all;
}

.trends-brush-scale-label,
.trends-brush-marker-label,
.trends-brush-range-label {
  fill: var(--text-muted, #64748b);
  font-size: 10px;
  pointer-events: none;
}

.trends-brush-range-label {
  fill: var(--text-strong, #0f172a);
  font-weight: 700;
}

.trends-brush-reset {
  cursor: pointer;
}

.trends-brush-reset-hitbox {
  fill: transparent;
  pointer-events: all;
}

.trends-brush-reset-label {
  fill: var(--accent, #2563eb);
  font-size: 10px;
  font-weight: 700;
  pointer-events: none;
  text-decoration: underline;
}

.trends-brush-reset:hover .trends-brush-reset-label,
.trends-brush-reset:focus .trends-brush-reset-label {
  fill: var(--accent-strong, #1d4ed8);
}

.trends-hover-line {
  stroke: var(--text-muted, #94a3b8);
  stroke-width: 1;
  stroke-dasharray: 3 3;
  pointer-events: none;
  opacity: 0.8;
}

.trends-hover-circle {
  fill: var(--surface, #fff);
  stroke-width: 1.5;
  pointer-events: none;
}

.trends-tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--surface);
  border: 1px solid var(--border-default);
  border-radius: 6px;
  padding: 8px 10px;
  box-shadow: var(--shadow-md);
  font-size: var(--font-xs, 11px);
  min-width: 180px;
  max-width: 280px;
  transform: translate(12px, -50%);
  z-index: 5;
  color: var(--text-default);
}

.trends-tooltip.flip-x {
  transform: translate(calc(-100% - 12px), -50%);
}

.trends-tooltip[hidden] {
  display: none;
}

.trends-area-card {
  display: flex;
  align-items: stretch;
  gap: 9px;
  min-width: 0;
}

.trends-area-card-rule {
  width: 3px;
  border-radius: 999px;
  flex: 0 0 3px;
}

.trends-area-card-body {
  display: grid;
  row-gap: 3px;
  min-width: 0;
}

.trends-area-card-title {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  color: var(--text-strong);
  font-weight: var(--w-heavy, 700);
}

.trends-area-card-title .brand-favicon {
  width: 16px;
  height: 16px;
  flex: 0 0 16px;
}

.trends-area-card-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.trends-area-card-period {
  color: var(--text-muted);
  font-size: 10px;
}

.trends-area-card-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
  color: var(--text-default);
  font-variant-numeric: tabular-nums;
}

.trends-placeholder {
  color: var(--text-muted);
  font-size: var(--font-md);
  padding: 24px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.trends-placeholder.is-loading {
  flex-direction: row;
}

.trends-placeholder-spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--border-default);
  border-top-color: var(--text-muted);
  border-radius: 50%;
  animation: trends-spin 700ms linear infinite;
}

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

.trends-placeholder.is-error {
  color: var(--text-default);
  border: 1px dashed var(--border-default);
  border-radius: 6px;
  background: var(--surface);
  padding: 18px 24px;
  max-width: 480px;
  margin: 12px auto;
}

.trends-placeholder-title {
  font-weight: 600;
  color: var(--text-strong);
  font-size: var(--font-md);
}

.trends-placeholder-detail {
  color: var(--text-muted);
  font-size: var(--font-xs, 11px);
  font-family: var(--font-mono, ui-monospace, monospace);
  word-break: break-word;
}

.trends-legend-row.is-empty-in-range {
  opacity: 0.55;
}

.trends-legend-row.is-empty-in-range .trends-legend-swatch {
  filter: grayscale(0.6);
}

.trends-legend-share.trends-legend-empty {
  color: var(--text-muted);
  font-style: italic;
  font-size: 10px;
}

.trends-toast {
  position: fixed;
  top: 70px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  border: 1px solid var(--border-default);
  border-radius: 6px;
  padding: 10px 14px;
  box-shadow: var(--shadow-md);
  font-size: var(--font-sm, 12px);
  color: var(--text-default);
  z-index: 50;
  pointer-events: none;
  white-space: nowrap;
  animation: trends-toast-in 200ms ease-out, trends-toast-out 200ms ease-in 2800ms forwards;
}

@keyframes trends-toast-in {
  from { opacity: 0; transform: translate(-50%, -8px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}

@keyframes trends-toast-out {
  from { opacity: 1; transform: translate(-50%, 0); }
  to   { opacity: 0; transform: translate(-50%, -8px); }
}

.trends-legend {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px;
  min-width: 0;
  border: 1px solid var(--border-default);
  border-radius: 6px;
  background: var(--surface-raised);
}

.trends-legend:empty::after {
  content: "Legend will appear once a chart is rendered.";
  color: var(--text-muted);
  font-size: var(--font-sm);
  padding: 12px;
  text-align: center;
}

.trends-legend-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 2px 4px 6px;
  border-bottom: 1px solid var(--border-default);
  margin-bottom: 4px;
  position: sticky;
  top: 0;
  background: var(--surface-raised);
  z-index: 1;
}

.trends-legend-header-label {
  color: var(--text-muted);
  font-size: var(--font-xs, 11px);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.trends-legend-sort {
  display: inline-flex;
  border: 1px solid var(--border-default);
  border-radius: 999px;
  overflow: hidden;
}

.trends-legend-sort button {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: var(--font-xs, 11px);
  font-weight: 500;
  padding: 2px 6px;
  white-space: nowrap;
  transition: color 120ms ease, background-color 120ms ease;
}

.trends-legend-sort button + button {
  border-left: 1px solid var(--border-default);
}

.trends-legend-sort button:hover {
  color: var(--text-strong);
  background: var(--surface);
}

.trends-legend-sort button.active {
  color: var(--text-strong);
  background: var(--surface);
}

.trends-legend-rows {
  display: flex;
  flex-direction: column;
  gap: var(--trends-legend-row-gap);
  height: calc(
    var(--trends-legend-visible-rows) * var(--trends-legend-row-h) +
    (var(--trends-legend-visible-rows) - 1) * var(--trends-legend-row-gap)
  );
  overflow-y: auto;
  padding-right: 4px;
  scrollbar-gutter: stable;
}

.trends-legend-rows::-webkit-scrollbar {
  width: 6px;
}

.trends-legend-rows::-webkit-scrollbar-thumb {
  background: var(--border-default);
  border-radius: 3px;
}

.trends-legend-row {
  position: relative;
  display: grid;
  grid-template-columns: 14px 16px minmax(0, 1fr) 44px;
  grid-template-areas: "reorder swatch label share";
  align-items: center;
  column-gap: 8px;
  flex: 0 0 var(--trends-legend-row-h);
  height: var(--trends-legend-row-h);
  padding: 3px 8px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-size: var(--font-sm);
  transition: background-color 100ms ease, border-color 100ms ease;
}

.trends-legend-reorder {
  grid-area: reorder;
  align-self: center;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.trends-legend-arrow {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 3px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  width: 14px;
  height: 11px;
  transition: color 100ms ease, background-color 100ms ease;
}

.trends-legend-arrow:hover:not(:disabled) {
  color: var(--text-strong);
  background: var(--surface);
}

.trends-legend-arrow:disabled {
  opacity: 0.25;
  cursor: not-allowed;
}

.trends-legend-row:hover {
  background: var(--surface-overlay);
  border-color: var(--border-subtle);
}

/* Brand row whose stacked area is sticky-highlighted via a legend tap. */
.trends-legend-row.is-area-pinned {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.trends-legend-swatch {
  grid-area: swatch;
  align-self: center;
  width: 14px;
  height: 14px;
  padding: 0;
  border-radius: 3px;
  border: 1px solid rgba(0, 0, 0, 0.18);
  cursor: pointer;
  transition: transform 100ms ease, border-color 100ms ease;
}

.trends-legend-swatch:hover {
  transform: scale(1.15);
  border-color: var(--text-strong);
}

.trends-legend-swatch:focus-visible {
  outline: 2px solid var(--accent-default, #2563eb);
  outline-offset: 2px;
}

.trends-legend-label {
  grid-area: label;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.25;
  color: var(--text-strong);
}

.trends-legend-label.has-favicon {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
}

.trends-legend-label.has-favicon .brand-favicon {
  flex: 0 0 16px;
}

.trends-legend-label-text {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.trends-legend-share {
  grid-area: share;
  font-variant-numeric: tabular-nums;
  text-align: right;
  width: 44px;
  color: var(--text-muted);
  font-size: var(--font-xs, 11px);
  align-self: center;
}

.trends-legend-empty {
  font-style: italic;
  opacity: 0.65;
  width: auto;
}

.trends-legend-total {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 8px;
  margin-top: 4px;
  border-top: 1px solid var(--border-default);
  color: var(--text-muted);
  font-size: var(--font-xs, 11px);
}

@keyframes trends-legend-flash {
  0%   { background: var(--accent-soft); }
  100% { background: transparent; }
}

.trends-legend-row.is-flash {
  animation: trends-legend-flash 400ms ease-out;
}

.trends-legend-total .trends-legend-share {
  align-self: center;
}

.trends-legend-actions {
  position: absolute;
  top: 50%;
  right: 56px;
  display: inline-flex;
  gap: 4px;
  align-items: center;
  justify-content: flex-end;
  padding-left: 4px;
  background: var(--surface-raised);
  opacity: 0;
  pointer-events: none;
  transform: translateY(-50%);
  transition: opacity 120ms ease;
}

.trends-legend-row:hover .trends-legend-actions,
.trends-legend-row:focus-within .trends-legend-actions {
  opacity: 1;
  pointer-events: auto;
}

.trends-legend-action:focus-visible,
.trends-legend-remove:focus-visible {
  opacity: 1;
}

.trends-legend-action,
.trends-legend-remove {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 2px;
  transition: color 120ms ease, background-color 120ms ease, border-color 120ms ease;
}

.trends-legend-action:hover,
.trends-legend-remove:hover {
  color: var(--text-strong);
  background: var(--surface);
  border-color: var(--border-default);
}

.trends-legend-remove:hover {
  color: var(--danger, #dc2626);
}

.trends-quick-pills {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 0;
}

#trends-quick-pills {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

#ramps-quick-pills,
#social-quick-pills {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.trends-quick-pills > button {
  min-width: 0;
  min-height: 28px;
  border: 1px solid var(--border-default);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-size: var(--font-xs);
  font-weight: var(--w-bold);
  padding: 4px 8px;
  transition: color 120ms ease, background-color 120ms ease, border-color 120ms ease;
}

.trends-quick-pills > button:hover,
.trends-quick-pills > button:focus-visible {
  color: var(--accent-strong);
  background: var(--accent-soft);
  border-color: var(--accent);
}

.top-count-pill {
  display: inline-flex;
  align-items: stretch;
  min-width: 0;
  min-height: 28px;
  overflow: hidden;
  border: 1px solid var(--border-default);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  transition: background-color 120ms ease, border-color 120ms ease, box-shadow 120ms ease;
}

.top-count-pill:hover {
  border-color: var(--text-muted);
  background: var(--surface-overlay);
}

.top-count-pill:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

.top-count-submit,
.top-count-input {
  min-width: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
}

.top-count-submit {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-right: 1px solid var(--border-default);
  border-radius: 0;
  padding: 4px 7px;
  font-weight: var(--w-bold);
}

.top-count-submit:hover,
.top-count-submit:focus-visible {
  color: var(--text-strong);
  background: var(--surface-hover);
}

.top-count-input {
  width: 40px;
  padding: 4px 6px;
  text-align: center;
  font-weight: var(--w-bold);
  -moz-appearance: textfield;
}

.top-count-input:focus,
.top-count-input:focus-visible {
  outline: 0;
  box-shadow: none;
}

.top-count-input::placeholder {
  color: #94a3b8;
  opacity: 1;
}

.top-count-input::-webkit-outer-spin-button,
.top-count-input::-webkit-inner-spin-button {
  margin: 0;
  appearance: none;
}

.mini-actions .top-count-pill {
  width: 100%;
}

.trends-quick-pills .top-count-pill {
  width: 100%;
  border-radius: 8px;
}

.trends-quick-pills .top-count-submit {
  padding: 4px 7px;
  color: inherit;
  font-size: inherit;
  font-weight: var(--w-bold);
}

.trends-quick-pills .top-count-input {
  width: 40px;
  padding: 4px 6px;
  color: inherit;
  font-size: inherit;
  font-weight: var(--w-bold);
}

.trends-sector-toggle {
  background: var(--surface);
  border: 1px solid var(--border-default);
  border-radius: 6px;
  color: var(--text-muted);
  cursor: pointer;
  font-size: var(--font-xs, 11px);
  font-weight: 500;
  height: 18px;
  line-height: 1;
  padding: 0 6px;
  letter-spacing: 0.02em;
  transition: color 120ms ease, background-color 120ms ease, border-color 120ms ease;
  white-space: nowrap;
}

.trends-sector-toggle:hover {
  color: var(--text-strong);
  background: var(--surface-overlay);
  border-color: var(--text-muted);
}

.trends-sector-toggle[data-action^="split"] {
  color: var(--accent);
  border-color: var(--accent-soft, var(--border-default));
}

.trends-sector-toggle[data-action^="merge"] {
  color: var(--text-muted);
}

.trends-breakout-btn {
  margin-left: auto;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  color: var(--text-muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  flex: 0 0 20px;
  padding: 0;
  transition: color 120ms ease, background-color 120ms ease, border-color 120ms ease;
}

.trends-breakout-btn:hover {
  color: var(--text-strong);
  background: var(--surface-overlay);
  border-color: var(--border-default);
}

.trends-breakout-btn[data-action="remerge"] {
  color: var(--accent-default, #2563eb);
}

.segmented.three-up {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  display: grid;
}

@media (max-width: 940px) {
  /* Map page (.app/.sidebar/.main/.legend-tree) is full-bleed with an off-canvas drawer at all
     breakpoints now, so its old stacked-sidebar rules were removed here. Keep the analysis/trends
     pages collapsing to a single column. */
  .analysis-app {
    grid-template-columns: 1fr;
  }

  .trends-app {
    grid-template-columns: 1fr;
  }

  .trends-chart-layout {
    grid-template-columns: 1fr;
  }

  .analysis-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 620px) {
  .map-color-legend {
    right: 10px;
    left: auto;
    width: min(190px, calc(100% - 98px));
    max-width: min(190px, calc(100% - 98px));
    min-width: 0;
    max-height: calc(100% - 20px);
  }

  .map-color-legend.is-collapsed {
    max-width: 28px;
  }

  .map-unit-search {
    top: 10px;
    left: 10px;
  }

  .map-unit-search-panel {
    width: min(340px, calc(100vw - 20px));
    max-height: calc(100dvh - 150px);
  }

  .map-unit-search-results {
    max-height: calc(100dvh - 230px);
  }

  .map-action-controls {
    top: auto;
    bottom: 12px;
    left: 10px;
  }

  .map-legend-title {
    display: none;
  }

  .topbar,
  .sidebar-header,
  .summary-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .stats {
    width: 100%;
    justify-content: space-between;
  }

  .toolbar-actions {
    width: 100%;
    justify-content: stretch;
  }

  .tool-button {
    flex: 1;
  }

  /* Part D2: review row stays one-line (condensed 3-col), not stacked. */
  .review-row {
    grid-template-columns: minmax(64px, 1.2fr) minmax(78px, 1fr) minmax(78px, 1fr);
    gap: 8px;
  }

  /* Keep each chart header on one line: title left (truncates), brand count right. */
  .analysis-panel-header {
    gap: 8px;
  }

  .analysis-panel-header > h3 {
    min-width: 0;
    flex: 1 1 auto;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .analysis-panel-header > .summary-note {
    min-width: 0;
    flex: 0 1 auto;
    max-width: 45%;
    overflow: hidden;
    text-align: right;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .region-help-groups {
    grid-template-columns: 1fr;
  }
}

/* --- Drill-down bar chart (clicked-legend-row -> brand breakdown) --- */
.trends-drilldown {
  border-top: 1px solid var(--border-default);
  padding: 12px 14px;
  background: var(--surface);
}

.trends-drilldown-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.trends-drilldown-title {
  margin: 0;
  font-size: var(--font-md, 14px);
  color: var(--text-strong);
}

.trends-drilldown-clear {
  background: var(--surface-raised);
  border: 1px solid var(--border-default);
  border-radius: 999px;
  padding: 3px 12px;
  font-size: var(--font-xs, 11px);
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: color 120ms ease, background-color 120ms ease, border-color 120ms ease;
}

.trends-drilldown-clear:hover {
  color: var(--text-strong);
  background: var(--surface-overlay);
  border-color: var(--text-muted);
}

.trends-drilldown-cols,
.trends-drilldown-row {
  display: grid;
  grid-template-columns: minmax(140px, 1.2fr) minmax(0, 2fr) 70px;
  gap: 10px;
  align-items: center;
  padding: 4px 8px;
}

.trends-drilldown-cols {
  font-size: var(--font-2xs, 10px);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border-subtle);
}

.trends-drilldown-rows {
  margin: 0;
  padding: 0;
  list-style: none;
}

.trends-drilldown-row {
  border-radius: 4px;
  transition: background-color 100ms ease;
}

.trends-drilldown-row:hover {
  background: var(--surface-overlay);
}

.trends-drilldown-name {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  font-size: var(--font-sm);
  color: var(--text-strong);
  overflow: hidden;
  white-space: nowrap;
}

.trends-drilldown-name-text {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.trends-drilldown-bar-cell {
  position: relative;
  height: 18px;
  background: var(--surface-raised);
  border: 1px solid var(--border-subtle);
  border-radius: 3px;
  overflow: hidden;
}

.trends-drilldown-bar {
  position: absolute;
  inset: 0 auto 0 0;
  background-color: var(--accent);
  transition: width 250ms ease;
}

.trends-drilldown-bar-label {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  font-variant-numeric: tabular-nums;
  font-size: var(--font-xs, 11px);
  color: var(--text-strong);
  mix-blend-mode: difference;
  z-index: 1;
}

.trends-drilldown-all-share {
  font-variant-numeric: tabular-nums;
  text-align: right;
  font-size: var(--font-sm);
  color: var(--text);
}

.trends-legend-row[data-kind="sector"],
.trends-legend-row[data-kind="sector-ex"],
.trends-legend-row[data-kind="subsector"],
.trends-legend-row[data-kind="subsector-ex"] {
  cursor: pointer;
}

/* --- Relative market share change tiles --- */
.trends-delta-section {
  padding: 0 14px 14px;
}

.trends-delta-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 14px;
}

.trends-delta-tile {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--border-default);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow-md);
}

/* C1: the Change-window pill row (mirrored under each tile header) drives only the change tables. */
.trends-delta-window {
  margin: 10px 14px 6px;
}

.trends-delta-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--border-default);
  background: var(--surface-raised);
  padding: 12px 14px;
}

.trends-delta-header h3 {
  flex: 1 1 220px;
  min-width: 150px;
  margin: 0;
  color: var(--text-strong);
  font-size: var(--font-md);
  line-height: 1.2;
}

.trends-delta-controls {
  flex: 0 1 430px;
  width: min(430px, 100%);
  min-width: 0;
}

.trends-delta-split-brands {
  flex: 0 0 auto;
  border: 1px solid var(--border-default);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text-muted);
  min-height: 34px;
  padding: 6px 10px;
  font-size: var(--font-xs);
  font-weight: var(--w-bold);
  white-space: nowrap;
  cursor: pointer;
  transition: background 150ms ease, border-color 150ms ease, color 150ms ease, opacity 150ms ease;
}

.trends-delta-split-brands:hover,
.trends-delta-split-brands:focus-visible {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.trends-delta-split-brands:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.trends-delta-option-row {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--border-default);
  border-radius: 8px;
  background: var(--surface);
}

.trends-delta-option,
.trends-delta-custom-form {
  min-width: 0;
}

.trends-delta-option {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 34px;
  border: 0;
  border-right: 1px solid var(--border-default);
  border-radius: 0;
  background: transparent;
  color: var(--text-muted);
  padding: 6px 4px;
  font: inherit;
  font-size: var(--font-xs);
  font-weight: var(--w-bold);
  text-align: center;
  transition: background 150ms ease, color 150ms ease, font-weight 150ms ease;
}

.trends-delta-option:hover,
.trends-delta-option:focus-visible {
  color: var(--text-strong);
  background: var(--surface-hover);
}

.trends-delta-option.active {
  background: var(--accent);
  color: var(--text-on-accent);
}

.trends-delta-custom-form {
  display: block;
}

.trends-delta-custom-input {
  border-right: 0;
  -moz-appearance: textfield;
}

.trends-delta-custom-input:focus,
.trends-delta-custom-input:focus-visible {
  outline: 0;
  box-shadow: inset 0 0 0 2px var(--focus-ring);
}

.trends-delta-custom-input::placeholder {
  color: var(--text-muted);
  opacity: 1;
}

.trends-delta-custom-input::-webkit-outer-spin-button,
.trends-delta-custom-input::-webkit-inner-spin-button {
  margin: 0;
  appearance: none;
}

.trends-delta-rows {
  display: grid;
  gap: 4px;
  margin: 0;
  padding: 10px 14px 12px;
  list-style: none;
}

.trends-delta-row {
  display: grid;
  grid-template-columns: minmax(120px, 1.1fr) minmax(0, 2fr) 72px;
  gap: 10px;
  align-items: center;
  min-height: 28px;
  padding: 4px 0;
}

.trends-delta-tile-absolute .trends-delta-row {
  grid-template-columns: minmax(120px, 1.1fr) minmax(0, 2fr) 88px;
}

.trends-delta-row.is-splittable {
  cursor: pointer;
}

.trends-delta-row.is-splittable:hover {
  background: var(--surface-overlay);
}

.trends-delta-name,
.trends-delta-label-content {
  min-width: 0;
}

.trends-delta-name {
  color: var(--text-strong);
  font-size: var(--font-sm);
  overflow: hidden;
}

.trends-delta-name .brand-label-content,
.trends-delta-label-content {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  width: 100%;
}

.trends-delta-label-text {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.trends-delta-swatch {
  width: 12px;
  height: 12px;
  flex: 0 0 12px;
  border-radius: 3px;
}

.trends-delta-bar-cell {
  position: relative;
  height: 18px;
  overflow: hidden;
  border: 1px solid var(--border-subtle);
  border-radius: 3px;
  background: var(--surface-raised);
}

.trends-delta-bar-cell::before {
  content: "";
  position: absolute;
  inset: -1px auto -1px 50%;
  width: 1px;
  background: var(--border-strong);
  transform: translateX(-0.5px);
  z-index: 1;
}

.trends-delta-fill {
  position: absolute;
  top: 0;
  bottom: 0;
  min-width: 0;
  transition: width 220ms ease;
}

.trends-delta-row.is-pos .trends-delta-fill {
  left: 50%;
  background: var(--success);
}

.trends-delta-row.is-neg .trends-delta-fill {
  right: 50%;
  background: var(--danger);
}

.trends-delta-row.is-zero .trends-delta-fill {
  left: 50%;
  background: var(--border-strong);
}

.trends-delta-value {
  color: var(--text);
  font-size: var(--font-sm);
  font-variant-numeric: tabular-nums;
  font-weight: var(--w-bold);
  text-align: right;
  white-space: nowrap;
}

.trends-delta-row.is-pos .trends-delta-value {
  color: var(--success-strong);
}

.trends-delta-row.is-neg .trends-delta-value {
  color: var(--danger-strong);
}

.trends-delta-empty {
  padding: 12px 0;
  color: var(--text-muted);
  font-size: var(--font-sm);
}

.trends-delta-footnote {
  min-height: 32px;
  border-top: 1px solid var(--border-default);
  padding: 8px 14px;
  color: var(--text-muted);
  font-size: var(--font-xs);
}

@media (max-width: 900px) {
  .trends-delta-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 620px) {
  .trends-delta-header {
    align-items: center;
  }

  .trends-delta-header h3 {
    min-width: 58px;
    font-size: var(--font-sm);
  }

  .trends-delta-split-brands {
    min-height: 32px;
    padding: 5px 7px;
    font-size: 10px;
  }

  .trends-delta-controls {
    flex-basis: 188px;
    min-width: 0;
  }

  .trends-delta-option {
    min-height: 32px;
    padding: 5px 2px;
    font-size: 10px;
  }

  .trends-delta-row {
    grid-template-columns: minmax(0, 1.15fr) minmax(76px, 1fr) 64px;
    gap: 8px;
  }

  .trends-delta-tile-absolute .trends-delta-row {
    grid-template-columns: minmax(0, 1.1fr) minmax(76px, 1fr) 74px;
  }
}

/* === Social Stats tab === */

/* Column-group band tints (applied to both header + body cells). */
:root {
  --social-ig-tint: rgba(236, 72, 153, 0.055);   /* magenta-500 @ ~5.5% */
  --social-ig-tint-strong: rgba(236, 72, 153, 0.11);
  --social-ig-rule: rgba(236, 72, 153, 0.32);
  --social-yt-tint: rgba(220, 38, 38, 0.05);     /* red-600 @ ~5% */
  --social-yt-tint-strong: rgba(220, 38, 38, 0.1);
  --social-yt-rule: rgba(220, 38, 38, 0.32);
}

.brand-logo {
  width: 32px;
  height: 32px;
  border-radius: 7px;
  object-fit: cover;
  background: var(--surface);
  flex-shrink: 0;
  box-shadow: 0 0 0 1px var(--border-subtle);
}
.brand-logo-initial {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: var(--w-semi, 600);
  font-size: 14px;
  text-shadow: 0 1px 2px rgba(0,0,0,0.4);
}

.verified-badge {
  flex-shrink: 0;
  vertical-align: -2px;
}

.ig-joined-suspect {
  font-style: italic;
  color: var(--text-muted);
}

/* ============================================================
   MOBILE
   M0 - Foundation
   ============================================================ */
html {
  -webkit-text-size-adjust: 100%;
}

button,
a,
input,
select,
label,
.segment {
  touch-action: manipulation;
}

/* M1 - Mobile navigation chrome */
.mobile-nav-toggle,
.mobile-nav-title {
  display: none;
}

.mobile-nav-toggle {
  position: absolute;
  top: 50%;
  left: max(8px, env(safe-area-inset-left));
  transform: translateY(-50%);
  z-index: 3;
  width: var(--tap-min);
  height: var(--tap-min);
}

.mobile-nav-title {
  position: relative;
  z-index: 2;
  min-width: 0;
  max-width: calc(100vw - 132px);
  color: var(--text-strong);
  font-family: var(--font-display);
  font-size: var(--font-lg);
  font-weight: var(--w-heavy);
  line-height: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* M2 - Mobile sheets */
.mobile-sheet {
  display: none;
}

.mobile-sheet-backdrop {
  position: fixed;
  inset: 0;
  border: 0;
  padding: 0;
  background: rgba(15, 23, 42, 0.38);
  opacity: 0;
  transition: opacity 180ms ease;
}

.mobile-sheet-panel {
  position: fixed;
  left: 0;
  right: 0;
  z-index: 80;
  max-height: 85dvh;
  overflow: hidden;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-default);
  box-shadow: var(--shadow-lg);
  transition: transform 220ms ease;
}

.mobile-sheet-panel.is-dragging {
  transition: none;
}

.mobile-sheet-top .mobile-sheet-panel {
  top: 0;
  border-radius: 0 0 8px 8px;
  transform: translateY(-100%);
  padding-top: env(safe-area-inset-top);
}

.mobile-sheet-bottom .mobile-sheet-panel {
  bottom: 0;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  transform: translateY(100%);
  padding-bottom: env(safe-area-inset-bottom);
}

.mobile-sheet-grip {
  display: flex;
  min-height: var(--tap-min);
  align-items: center;
  justify-content: center;
  background: var(--surface);
  cursor: grab;
  touch-action: none;
}

.mobile-sheet-panel.is-dragging .mobile-sheet-grip {
  cursor: grabbing;
}

.mobile-sheet-grip-bar {
  width: 36px;
  height: 4px;
  border-radius: var(--radius-pill);
  background: var(--border-strong);
}

.mobile-sheet-body {
  max-height: inherit;
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.mobile-menu-list {
  display: grid;
  gap: 4px;
  padding: 12px;
}

.mobile-menu-link {
  display: flex;
  align-items: center;
  min-height: 48px;
  padding: 0 14px;
  border-radius: 8px;
  color: var(--text);
  font-weight: var(--w-bold);
  text-decoration: none;
}

.mobile-menu-link:hover,
.mobile-menu-link:focus-visible {
  background: var(--surface-hover);
  color: var(--text-strong);
}

.mobile-menu-link.active {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

@media (prefers-reduced-motion: reduce) {
  .mobile-sheet-backdrop,
  .mobile-sheet-panel {
    transition: none;
  }
}

@media (max-width: 760px) {
  :root {
    --site-header-h: var(--mobile-header-h);
  }

  .site-header {
    align-items: flex-start;
    justify-content: center;
    padding: calc(8px + env(safe-area-inset-top, 0px)) calc(64px + env(safe-area-inset-right, 0px)) 8px calc(64px + env(safe-area-inset-left, 0px));
    background: transparent;
    border-bottom: 0;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }

  .site-header::before {
    content: "";
    position: absolute;
    top: calc(8px + env(safe-area-inset-top, 0px));
    right: max(12px, env(safe-area-inset-right, 0px));
    left: max(12px, env(safe-area-inset-left, 0px));
    z-index: 0;
    height: 48px;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-pill);
    background: var(--surface-overlay);
    box-shadow: var(--shadow-md);
    pointer-events: none;
    backdrop-filter: saturate(140%) blur(10px);
    -webkit-backdrop-filter: saturate(140%) blur(10px);
  }

  .site-brand,
  .site-nav {
    display: none;
  }

  .mobile-nav-toggle,
  .mobile-nav-title {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .mobile-nav-toggle {
    top: calc(8px + env(safe-area-inset-top, 0px) + 24px);
    left: max(14px, calc(env(safe-area-inset-left, 0px) + 14px));
    border-color: transparent;
    border-radius: var(--radius-pill);
    background: transparent;
    color: var(--text-strong);
  }

  .mobile-nav-title {
    height: 48px;
    line-height: 1;
    text-align: center;
  }

  .mobile-sheet {
    position: fixed;
    inset: 0;
    z-index: 70;
    display: block;
    pointer-events: none;
  }

  .mobile-sheet.is-open {
    pointer-events: auto;
  }
  .mini-actions > button,
  .mini-actions .top-count-pill,
  .status-pill,
  .trends-quick-pills > button,
  .trends-quick-pills .top-count-pill {
    min-height: 38px;
  }

  .mobile-sheet.is-open .mobile-sheet-backdrop {
    opacity: 1;
  }

  .mobile-sheet.is-open .mobile-sheet-panel {
    transform: translateY(0);
  }
}

/* Wave-3 item 9: left slide-out Account panel. The base .mobile-sheet is display:none off mobile
   and its open/transform rules live in the <=760px block above, so the left variant re-enables
   itself here for every viewport (the Account button is in the persistent top bar). */
.mobile-sheet-left {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: block;
  pointer-events: none;
}
.mobile-sheet-left.is-open {
  pointer-events: auto;
}
.mobile-sheet-left .mobile-sheet-panel {
  top: 0;
  bottom: 0;
  left: 0;
  right: auto;
  width: min(320px, 86vw);
  max-height: none;
  border-radius: 0 var(--radius-lg) var(--radius-lg) 0;
  transform: translateX(-100%);
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}
.mobile-sheet-left.is-open .mobile-sheet-backdrop {
  opacity: 1;
}
.mobile-sheet-left.is-open .mobile-sheet-panel {
  transform: translateX(0);
}

.account-sheet-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 16px;
  border-bottom: 1px solid var(--border-default);
}
.account-sheet-logo {
  width: 40px;
  height: 40px;
  border-radius: 10px;
}
.account-sheet-title {
  font-family: var(--font-display);
  font-size: var(--font-lg);
  font-weight: var(--w-heavy);
  color: var(--text-strong);
}
.account-sheet-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 14px 16px;
  border: 0;
  background: transparent;
  color: var(--text);
  font-weight: var(--w-bold);
}
.account-sheet-item:disabled {
  color: var(--text-subtle);
  cursor: default;
}

.filter-pill {
  position: fixed;
  left: 50%;
  bottom: calc(12px + env(safe-area-inset-bottom));
  z-index: 62;
  display: none;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 128px;
  min-height: 44px;
  padding: 0 16px;
  transform: translateX(-50%);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--text-strong);
  box-shadow: var(--shadow-lg);
  color: var(--text-on-accent);
  font-weight: var(--w-heavy);
}

.filter-pill-icon {
  display: inline-flex;
}

.filter-sheet .mobile-sheet-panel {
  border-bottom: 0;
  max-height: 92dvh;
}

/* Single-scroller layout: the body is a flex column that does NOT scroll (overflow
   hidden overrides the base .mobile-sheet-body's overflow:auto). The header is a fixed
   row and .filter-sheet-content is the sole scroll region. A previous grid version left
   both the body and the content as overlapping scroll containers with an indefinite
   (max-height only) height; on iOS that clamped the inner scroller's reachable extent, so
   the last rows were only reachable via rubber-band overscroll and expanding a sector grew
   the content without extending the scrollable bottom. */
.filter-sheet .mobile-sheet-body {
  display: flex;
  flex-direction: column;
  max-height: 85dvh;
  overflow: hidden;
}

.filter-sheet-header {
  position: sticky;
  top: 0;
  z-index: 2;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-default);
  background: var(--surface-overlay);
  backdrop-filter: saturate(140%) blur(8px);
  -webkit-backdrop-filter: saturate(140%) blur(8px);
  touch-action: none;
}

.filter-sheet-title {
  margin: 0;
  color: var(--text-strong);
  font-family: var(--font-display);
  font-size: var(--font-lg);
  line-height: var(--line-tight);
}

.filter-sheet-content {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.filter-sheet .sidebar {
  height: auto;
  min-height: 0;
  overflow: visible;
  border: 0;
}

.filter-sheet .legend-tree {
  max-height: none;
  overflow: visible;
}

@media (max-width: 760px) {
  .filter-pill:not([hidden]) {
    display: inline-flex;
  }

  /* Stage 3B: the Map options control now lives in the persistent topbar on mobile too. */

  /* Clear the unit-search bar on the left and the (collapsed) legend on the right. */
  .subsector-chip-row {
    left: calc(10px + env(safe-area-inset-left));
    right: calc(10px + env(safe-area-inset-right) + 38px);
  }

  body.map-mobile-chrome .subsector-chip-row {
    top: var(--mc-chips-top);
    z-index: 11;
  }
}

/* Desktop/tablet (>=761px): on the map page only (drawer regime), the "Filters · N" pill becomes a
   top-right drawer toggle and the on-map legend drops below it so they do not collide. The
   .is-drawer-toggle class is added only to the map's pill, so other pages' pills stay hidden. */
@media (min-width: 761px) {
  .filter-pill.is-drawer-toggle:not([hidden]) {
    /* The pill now lives inside the persistent .map-topbar (Wave-3 item 1); it only needs to be
       shown on desktop here — its layout comes from the .map-topbar .filter-pill rules above. */
    display: inline-flex;
  }

  .filter-pill.is-drawer-toggle[aria-expanded="true"] {
    border-color: var(--accent);
    background: var(--accent-soft);
    color: var(--accent-strong);
  }

  .map-color-legend {
    top: 62px;
  }
}

@media (max-width: 760px) {
  .app {
    height: calc(100dvh - var(--site-header-h));
    grid-template-columns: 1fr;
  }

  .main {
    height: 100%;
    min-height: 0;
    grid-template-rows: minmax(0, 1fr) auto;
  }

  .main.summary-expanded {
    grid-template-rows: minmax(0, 1fr) minmax(0, 42dvh);
  }

  .main.summary-collapsed,
  .main.summary-collapsed.summary-expanded {
    grid-template-rows: minmax(0, 1fr) auto;
  }

  .map-panel,
  .main.summary-expanded .map-panel {
    min-height: 0;
  }

  .summary-panel {
    min-height: 0;
    max-height: 42dvh;
  }

  .map-color-legend {
    top: 10px;
    right: 10px;
    left: auto;
    width: min(190px, calc(100vw - 120px));
    max-width: min(190px, calc(100vw - 120px));
    min-width: 0;
    max-height: calc(100dvh - 150px);
  }

  .map-color-legend.is-collapsed {
    max-width: 28px;
  }

  .map-action-controls {
    top: auto;
    bottom: calc(12px + env(safe-area-inset-bottom));
    left: 10px;
    display: flex;
    flex-direction: row;
    gap: 6px;
  }

  .map-action-button {
    min-height: 36px;
    height: 36px;
    padding: 0 10px;
    font-size: var(--font-xs);
  }

  .maplibregl-popup {
    max-width: min(300px, 88vw) !important;
  }

  .popup {
    min-width: 0;
    max-width: min(300px, 88vw);
  }
}

/* M3 - Table tools */
.has-scroll-shadows {
  --scroll-shadow-color: rgba(15, 23, 42, 0.22);
  background:
    linear-gradient(90deg, var(--scroll-shadow-color), transparent 18px) left / 18px 100% no-repeat,
    linear-gradient(270deg, var(--scroll-shadow-color), transparent 18px) right / 18px 100% no-repeat,
    var(--surface);
}

.has-scroll-shadows[data-shadow=""] {
  background: var(--surface);
}

.has-scroll-shadows[data-shadow="left"] {
  background:
    linear-gradient(90deg, var(--scroll-shadow-color), transparent 18px) left / 18px 100% no-repeat,
    var(--surface);
}

.has-scroll-shadows[data-shadow="right"] {
  background:
    linear-gradient(270deg, var(--scroll-shadow-color), transparent 18px) right / 18px 100% no-repeat,
    var(--surface);
}

.table-colset-mount {
  display: none;
}

.mobile-chip-row {
  display: none;
}

@media (max-width: 760px) {
  .mobile-chip-row {
    position: sticky;
    /* park below the iOS status bar in standalone PWA (env=0 elsewhere) */
    top: env(safe-area-inset-top, 0px);
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 8px;
    overflow-x: auto;
    padding: 6px 12px 8px;
    background: var(--bg);
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  .mobile-chip-row::-webkit-scrollbar {
    display: none;
  }

  .mobile-chip-row.has-scroll-shadows {
    background: var(--bg);
  }

  .mobile-chip-row[data-shadow="left"] {
    mask-image: linear-gradient(90deg, transparent 0, #000 18px, #000 100%);
  }

  .mobile-chip-row[data-shadow="right"] {
    mask-image: linear-gradient(90deg, #000 0, #000 calc(100% - 18px), transparent 100%);
  }

  .mobile-chip-row[data-shadow="both"] {
    mask-image: linear-gradient(90deg, transparent 0, #000 18px, #000 calc(100% - 18px), transparent 100%);
  }

  .mobile-chip,
  .mobile-chip-slot .segment {
    display: inline-flex;
    min-height: var(--tap-min);
    flex: 0 0 auto;
    align-items: center;
    justify-content: center;
    gap: 7px;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-pill);
    background: var(--surface);
    box-shadow: var(--shadow-sm);
    color: var(--text);
    font-size: var(--font-sm);
    font-weight: var(--w-bold);
    line-height: 1;
    padding: 0 14px;
    white-space: nowrap;
  }

  .mobile-chip.is-active,
  .mobile-chip[aria-pressed="true"],
  .mobile-chip-slot .segment.active {
    border-color: color-mix(in oklab, var(--accent) 34%, var(--border-default));
    background: var(--accent-soft);
    color: var(--accent-strong);
  }

  .mobile-chip-slot {
    display: inline-flex;
    flex: 0 0 auto;
    align-items: center;
    gap: 8px;
  }

  .mobile-chip-slot .table-colset-mount {
    display: inline-flex;
    padding: 0;
  }

  .mobile-chip-slot .table-colset-control {
    display: inline-flex;
    width: auto;
    gap: 8px;
    border: 0;
    background: transparent;
  }

  .mobile-chip-separator {
    align-self: stretch;
    width: 1px;
    min-height: 28px;
    flex: 0 0 auto;
    background: var(--border-default);
  }

  .table-colset-mount {
    display: block;
    padding: 0 0 10px;
  }

  .table-colset-control {
    display: grid;
    width: 100%;
    grid-template-columns: repeat(auto-fit, minmax(0, 1fr));
  }

  .summary-table th:first-child,
  .summary-table td:first-child,
  .social-table .col-brand {
    position: sticky;
    left: 0;
    z-index: 3;
    background: var(--surface);
  }

  .summary-table th:first-child,
  .social-table thead .social-head-row .col-brand {
    z-index: 5;
    background: var(--surface-raised);
  }

  .matrix-table .name-col {
    width: 110px;
    min-width: 110px;
  }

  .cbsa-main .matrix-table .name-col {
    width: 140px;
    min-width: 140px;
  }

  .metric-table {
    min-width: 0;
  }

  .metric-table th,
  .metric-table td {
    min-width: 104px;
  }

  .metric-table th:first-child,
  .metric-table td:first-child {
    min-width: 138px;
  }

  #zip-metrics-table[data-colset="pop"] [data-col-family]:not([data-col-family="base"]):not([data-col-family="pop"]),
  #zip-metrics-table[data-colset="density"] [data-col-family]:not([data-col-family="base"]):not([data-col-family="density"]),
  #zip-metrics-table[data-colset="hh"] [data-col-family]:not([data-col-family="base"]):not([data-col-family="hh"]),
  #zip-metrics-table[data-colset="hhDensity"] [data-col-family]:not([data-col-family="base"]):not([data-col-family="hhDensity"]) {
    display: none;
  }

  .social-table td {
    padding: 8px 10px;
  }

  .social-table .col-brand {
    min-width: 160px;
  }

  .social-table-wrap[data-colset="ig"] .social-table .group-yt,
  .social-table-wrap[data-colset="ig"] .social-table .group-tt,
  .social-table-wrap[data-colset="ig"] .social-table .group-x,
  .social-table-wrap[data-colset="ig"] .social-table .group-fb,
  .social-table-wrap[data-colset="ig"] .social-table .group-li,
  .social-table-wrap[data-colset="yt"] .social-table .group-ig,
  .social-table-wrap[data-colset="yt"] .social-table .group-tt,
  .social-table-wrap[data-colset="yt"] .social-table .group-x,
  .social-table-wrap[data-colset="yt"] .social-table .group-fb,
  .social-table-wrap[data-colset="yt"] .social-table .group-li,
  .social-table-wrap[data-colset="other"] .social-table .group-ig,
  .social-table-wrap[data-colset="other"] .social-table .group-yt {
    display: none;
  }
}

@media (max-width: 760px) and (prefers-reduced-motion: no-preference) {
  .mobile-chip:active,
  .segment:active,
  .icon-button:active,
  .filter-pill:active,
  .mobile-menu-link:active {
    transform: scale(0.97);
    transition: transform var(--motion-fast) var(--ease-out);
  }
}

/* M4 - Chart mobile tuning */
@media (min-width: 761px) and (max-width: 940px) {
  .app > .main,
  .analysis-app > .analysis-main,
  .trends-app > .trends-main {
    order: -1;
  }
}

@media (max-width: 760px) {
  .analysis-app,
  .trends-app {
    height: 100dvh;            /* Task A: header is display:none on mobile, don't subtract --site-header-h */
    grid-template-columns: 1fr;
  }

  .analysis-main,
  .trends-main {
    min-height: 0;
    overflow: auto;
    /* clear the iOS status bar in standalone PWA (env=0 elsewhere) */
    padding-top: env(safe-area-inset-top, 0px);
    /* Task A: token-driven so the PWA value (Task C) flows through */
    padding-bottom: calc(var(--bottom-nav-clearance) + env(safe-area-inset-bottom, 0px));
  }

  .trends-chart-section {
    padding: 10px 0;
  }

  .trends-panel-header,
  .trends-delta-header,
  .topbar,
  .summary-header {
    align-items: flex-start;
    flex-direction: column;
  }

  /* The delta header h3 carries a desktop `flex: 1 1 220px` so the title shares the
     row width with the Split-to-Brands button. Once the header flips to a column
     above, that 220px basis applies to the vertical axis instead — inflating the
     title to a 220px-tall band and, with justify-content: space-between, shoving the
     button to the bottom (the "fat header bar" empty space on phones). Reset the
     basis so the title sizes to its text. */
  .trends-delta-header h3 {
    flex: 0 0 auto;
  }

  .trends-panel-header h3 {
    display: -webkit-box;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: normal;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
  }

  .trends-chart-layout,
  .ramps-chart-layout {
    --trends-chart-h: var(--chart-height-mobile);   /* shared default (240) — unchanged */
    --trends-legend-row-h: 38px;
    grid-template-columns: 1fr;
    gap: 8px;
    padding: 10px 0;
  }

  /* Task D: Search only (search.html=.trends-chart-layout; momentum=.ramps-chart-layout=240). */
  .trends-chart-layout { --trends-chart-h: 360px; }              /* +50% on PWA */
  .trends-chart-layout .trends-chart { min-height: 300px; }      /* Search-scoped; global stays 200 */

  /* Task D: full-bleed the chart panel, EXCLUDING Social. */
  .trends-panel:not(.social-panel) {
    border-left: 0;
    border-right: 0;
    border-radius: 0;
  }

  .trends-chart {
    min-height: 200px;
  }

  /* Item A (goodnight): the first chart's mobile "hero" overrides were removed so it
     matches every other chart on phones (normal --chart-height-mobile panel + normal
     .trends-panel-header + subtitle). Governs both momentum.html and search.html. */

  .trends-granularity-buttons {
    right: 10px;
    bottom: 8px;
    left: auto;
  }

  .trends-legend-row,
  .trends-ramp-legend-row {
    min-height: 38px;
  }

  .trends-legend-arrow {
    width: 22px;
    height: 16px;
  }

  .trends-legend-swatch,
  .color-popover-swatch {
    width: 28px;
    height: 28px;
  }

  .trends-drilldown-cols {
    display: none;
  }

  .trends-drilldown-row {
    grid-template-columns: 1fr;
    gap: 6px;
    padding: 9px 6px;
  }

  .trends-drilldown-all-share {
    text-align: left;
  }

  .trends-delta-controls {
    flex-basis: auto;
    width: 100%;
  }

  .trends-delta-option-row {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  .trends-delta-option,
  .trends-delta-custom-input {
    min-height: 36px;
    font-size: var(--font-xs);
  }

  .trends-delta-row,
  .trends-delta-tile-absolute .trends-delta-row {
    grid-template-columns: minmax(96px, 38%) minmax(0, 1fr) auto;
    gap: 6px;
    min-height: 44px;
  }

  .trends-delta-value {
    text-align: right;
  }

  .method-info-bubble {
    left: 50%;
    max-width: min(218px, calc(100vw - 32px));
    width: min(218px, calc(100vw - 32px));
    transform: translateX(-50%);
  }

  .method-info:hover .method-info-bubble[hidden],
  .method-info:focus-visible .method-info-bubble[hidden],
  .method-info:focus-within .method-info-bubble[hidden] {
    display: none;
  }

  .method-info-bubble::before {
    left: 50%;
    transform: translateX(-50%) rotate(45deg);
  }

  /* Compact one-line layout: brand label, bar, and value(s) stay together. */
  .rank-row {
    grid-template-columns: minmax(92px, 34%) minmax(70px, 1fr) minmax(44px, auto) minmax(54px, auto);
    grid-template-areas: "label track value outside";
    column-gap: 8px;
    row-gap: 3px;
  }

  .rank-row > .rank-label {
    grid-area: label;
  }

  .rank-row > .rank-track {
    grid-area: track;
  }

  .rank-row > .rank-value {
    grid-area: value;
  }

  .rank-row > .rank-value.outside-na-value {
    grid-area: outside;
  }

  .mix-row {
    grid-template-columns: minmax(96px, 36%) minmax(72px, 1fr) minmax(44px, auto);
    grid-template-areas: "label track total";
    column-gap: 8px;
    row-gap: 3px;
  }

  .mix-row > .mix-label {
    grid-area: label;
  }

  .mix-row > .stacked-bar {
    grid-area: track;
  }

  .mix-row > .mix-total {
    grid-area: total;
  }

  /* Part D2: review row stays one-line (condensed 3-col), not stacked. */
  .review-row {
    grid-template-columns: minmax(64px, 1.2fr) minmax(78px, 1fr) minmax(78px, 1fr);
    gap: 8px;
  }

  /* Keep the column titles visible above the value columns on phones (was
     display:none). Mirror the container-query placement so the heading's empty
     label/track cells and its two value labels land on the reflowed grid areas. */
  .rank-heading > :nth-child(1) {
    grid-area: label;
  }

  .rank-heading > :nth-child(2) {
    grid-area: track;
  }

  .rank-heading > :nth-child(3) {
    grid-area: value;
  }

  .rank-heading > :nth-child(4) {
    grid-area: outside;
  }

  .rank-heading .rank-value-label,
  .rank-heading .sort-button span:first-child {
    overflow: visible;
    text-overflow: clip;
  }

  .region-help-groups {
    grid-template-columns: 1fr;
  }
}

/* M5 - Touch and accessibility polish */
@media (max-width: 760px) {
  .legend-tree {
    --legend-check-size: 18px;
    --legend-row-min-h: 38px;
    --legend-row-pad-y: 6px;
    --legend-toggle-size: 30px;
  }

  input,
  select,
  textarea {
    font-size: 16px;
  }

  .map-legend-remove,
  .analysis-chart-remove,
  .trends-ramp-legend-row .trends-ramp-legend-remove,
  .trends-legend-actions {
    opacity: 1;
    pointer-events: auto;
  }

  .map-legend-remove,
  .analysis-chart-remove,
  .trends-legend-action,
  .trends-legend-remove,
  .trends-ramp-legend-remove {
    min-width: 32px;
    min-height: 32px;
  }

  .trends-legend-row {
    grid-template-columns: 22px 28px minmax(0, 1fr) auto 44px;
    grid-template-areas: "reorder swatch label actions share";
    column-gap: 8px;
  }

  .trends-legend-actions {
    position: static;
    grid-area: actions;
    padding-left: 0;
    background: transparent;
    transform: none;
  }

  .trends-ramp-legend-row {
    grid-template-columns: 28px minmax(0, 1fr);
    padding: 4px 6px;
  }

  .trends-ramp-legend-row.is-removable {
    grid-template-columns: 28px minmax(0, 1fr) 36px;
  }
}

.cbsa-mobile-columns {
  display: none;
}

@media (max-width: 760px) {
  .cbsa-main {
    /* explicit 0 to defeat the generic .analysis-main padding-top: env(...) above (same
       element, equal specificity, later source order) — the chip row below owns the
       safe-area inset instead, so exactly one inset can ever apply above the toolbar */
    padding-top: 0;
    /* Task B: re-assert base (generic mobile .analysis-main set overflow:auto here, making
       .cbsa-main a 2nd scroller that slid the sticky header under the chip row). */
    overflow: hidden;
    padding-bottom: 0;
  }
  .cbsa-main .cbsa-table-wrap {
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;            /* Task B: sole scroller; sticky th.name-col sits below the chip row */
    padding-bottom: calc(var(--bottom-nav-clearance) + env(safe-area-inset-bottom, 0px));
  }
  .cbsa-main .mobile-chip-row {
    flex: 0 0 auto;
    /* .cbsa-main never scrolls, so the generic sticky + env() top offset (above) is
       pointless here — and standalone WebKit could stack it on the main's inset. The
       row is static and carries the safe-area inset itself, painting its --bg up to
       the physical top edge (toolbar flush at top, like Units). */
    position: static;
    padding-top: calc(6px + env(safe-area-inset-top, 0px));
  }

  .matrix-table thead .cbsa-control-row {
    display: none;
  }

  .matrix-table thead .cbsa-control-row + tr th {
    top: 0;
  }

  .matrix-table th,
  .matrix-table td {
    padding: 8px 9px;
  }

  .cbsa-total-column-sort {
    min-height: 32px;
  }

  .cbsa-total-column-sort.active {
    background: var(--accent-soft);
    border-color: color-mix(in oklab, var(--accent) 35%, var(--border-default));
    color: var(--accent-strong);
  }

  .cbsa-mobile-columns {
    display: block;
  }

  .cbsa-column-toggle-list {
    display: grid;
    gap: 8px;
  }

  .cbsa-column-toggle {
    display: flex;
    min-height: var(--tap-min);
    align-items: center;
    gap: 10px;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    background: var(--surface);
    padding: 8px 10px;
    font-weight: var(--w-med);
  }

  .cbsa-table-wrap[data-hide-pop="true"] .pop-col,
  .cbsa-table-wrap[data-hide-pop-unit="true"] .pop-unit-col,
  .cbsa-table-wrap[data-hide-hh="true"] .hh-col,
  .cbsa-table-wrap[data-hide-hh-unit="true"] .hh-unit-col {
    display: none;
  }

  .trends-chart-layout,
  .ramps-chart-layout {
    --trends-legend-row-h: 44px;
  }

  .trends-legend-row,
  .trends-ramp-legend-row {
    min-height: 44px;
  }

  .trends-legend-arrow {
    min-width: 28px;
    width: 28px;
    min-height: 24px;
    height: 24px;
  }

  .trends-legend-swatch,
  .color-popover-swatch {
    width: 32px;
    height: 32px;
  }

  .trends-legend-action,
  .trends-legend-remove,
  .trends-ramp-legend-remove,
  .analysis-chart-remove {
    position: relative;
    min-width: 40px;
    min-height: 40px;
  }

  .trends-legend-action::after,
  .trends-legend-remove::after,
  .trends-ramp-legend-remove::after,
  .analysis-chart-remove::after,
  .trends-ramp-callout-box.is-dismissible::after {
    content: "";
    position: absolute;
    inset: -2px;
  }

  .trends-delta-option,
  .trends-delta-custom-input {
    min-height: var(--tap-min);
  }

  .social-table tbody tr {
    height: 44px;
  }

  .social-table td.is-sorted-col {
    background: color-mix(in oklab, var(--accent) 8%, var(--surface));
  }

  .social-table tbody tr:hover td.is-sorted-col {
    background: color-mix(in oklab, var(--accent) 12%, var(--surface));
  }

  .analysis-grid {
    gap: 10px;
    /* Near-full-bleed panels via thin side padding instead of negative margins. The old
       margin: 0 -12px made the grid 24px wider than the viewport, so its 14px side padding
       overflowed and spawned a horizontal scrollbar in .analysis-main. */
    padding-right: 2px;
    padding-left: 2px;
  }

  .analysis-panel {
    border-right: 0;
    border-left: 0;
    border-radius: 0;
  }

  .chart-legend-item {
    min-height: var(--tap-min);
  }

  #cbsa-type-filter .segment {
    min-height: var(--tap-min);
  }

  .region-help-dialog {
    width: min(100vw, 680px);
    max-width: calc(100vw - 16px);
    max-height: calc(100dvh - 16px);
    border-radius: var(--radius-lg);
  }

  .region-help-header {
    padding: calc(12px + env(safe-area-inset-top, 0px)) 14px 12px;
  }

  .region-help-body {
    padding: 14px max(14px, env(safe-area-inset-right, 0px)) calc(14px + env(safe-area-inset-bottom, 0px)) max(14px, env(safe-area-inset-left, 0px));
  }
}

/* Task A: standalone header-band reclaim block DELETED — base 100dvh + token padding (Task C
   overrides the token on both PWA paths) make it redundant; also lets CBSA padding-bottom:0 win. */
