/* =========================================================
   IAA Market Dashboard — Premium Design System v2
   ========================================================= */

/* --- Design Tokens --- */
:root {
  /* Surfaces */
  --bg:           #EFF1F7;
  --surface:      #FFFFFF;
  --surface-soft: #F7F9FC;
  --surface-tint: #FAFBFE;

  /* Text */
  --ink:          #0F172A;
  --muted:        #64748B;

  /* Borders */
  --line:         #E4E8F0;
  --line-strong:  #CDD3E0;

  /* Sidebar */
  --sidebar:      #FFFFFF;
  --sidebar-muted:#94A3B8;

  /* Primary accent — Indigo */
  --accent:        #3B5BDB;
  --accent-strong: #2F4CC0;
  --accent-soft:   #EEF2FF;

  /* Data series colors */
  --blue:       #7048E8;
  --blue-soft:  #F3F0FF;
  --amber:      #F59E0B;
  --amber-soft: #FFFBEB;
  --red:        #EF4444;
  --red-soft:   #FEF2F2;
  --violet:     #8B5CF6;
  --violet-soft:#EDE9FE;
  --cyan:       #0EA5E9;
  --cyan-soft:  #E0F2FE;
  --coral:      #F43F5E;
  --coral-soft: #FFF1F2;
  --green:      #10B981;

  --comparison-previous: #CBD5E1;

  /* Elevation */
  --shadow:       0 1px 2px rgba(15,23,42,.04);
  --shadow-raised:0 1px 3px rgba(15,23,42,.05), 0 6px 20px rgba(15,23,42,.05);
  --shadow-float: 0 4px 6px -1px rgba(15,23,42,.06), 0 10px 28px -4px rgba(15,23,42,.06);

  /* Shape */
  --radius:    10px;
  --radius-sm:  6px;
  --radius-lg: 14px;

  font-family: "Inter", ui-sans-serif, -apple-system, BlinkMacSystemFont,
    "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: var(--bg);
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  letter-spacing: 0;
}

/* --- Reset --- */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { min-height: 100%; margin: 0; background: var(--bg); }
body { min-width: 320px; font-size: 14px; overflow-x: hidden; }
button, input, select { font: inherit; }
button, select { cursor: pointer; }
button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 2px solid rgba(59,91,219,.3);
  outline-offset: 2px;
}

/* --- App Shell --- */
.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
}

/* =========================================================
   SIDEBAR
   ========================================================= */
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 20px 12px 18px;
  border-right: 1px solid var(--line);
  background: var(--sidebar);
  color: var(--ink);
  overflow-y: auto;
  overflow-x: hidden;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 2px 10px 22px;
}

.brand-logo {
  width: min(160px, 100%);
  height: auto;
  display: block;
  object-fit: contain;
  object-position: left center;
}

.brand-mark {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  flex: 0 0 auto;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent) 0%, #6C63FF 100%);
  color: #fff;
  box-shadow: 0 6px 14px rgba(59,91,219,.28);
}
.brand-mark svg { width: 18px; height: 18px; }
.brand strong { display: block; font-size: 14px; font-weight: 700; color: var(--ink); }
.brand span { display: block; margin-top: 2px; color: var(--sidebar-muted); font-size: 9px; letter-spacing: .06em; }

/* Nav */
.nav-list { display: grid; gap: 3px; }

.nav-item {
  width: 100%;
  min-height: 40px;
  display: flex;
  align-items: center;
  gap: 10px;
  position: relative;
  padding: 0 12px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #64748B;
  text-align: left;
  font-size: 13px;
  font-weight: 500;
  transition: background 160ms ease, color 160ms ease, box-shadow 160ms ease;
}
.nav-item:hover {
  background: var(--surface-soft);
  color: var(--ink);
}
.nav-item.is-active {
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-weight: 600;
  box-shadow: inset 0 0 0 1px rgba(59,91,219,.12);
}
.nav-item.is-active::before {
  content: "";
  position: absolute;
  left: 0; top: 50%;
  transform: translateY(-50%);
  width: 3px; height: 20px;
  border-radius: 0 3px 3px 0;
  background: var(--accent);
}
.nav-item:focus-visible { outline-color: rgba(59,91,219,.35); outline-offset: 1px; }
.nav-icon { width: 16px; height: 16px; flex: 0 0 16px; opacity: .7; }
.nav-item.is-active .nav-icon { opacity: 1; }

/* Sidebar footer */
.sidebar-foot {
  display: flex; align-items: center; gap: 9px;
  margin-top: auto;
  padding: 14px 10px 3px;
  border-top: 1px solid var(--line);
}
.sidebar-foot strong { display: block; font-size: 12px; font-weight: 600; color: var(--ink); }
.sidebar-foot span   { display: block; margin-top: 2px; font-size: 10px; color: var(--sidebar-muted); }
.status-dot {
  width: 8px; height: 8px; flex: 0 0 auto;
  border-radius: 50%;
  background: #10B981;
  box-shadow: 0 0 0 3px rgba(16,185,129,.15);
}

/* =========================================================
   TOPBAR
   ========================================================= */
.main-area { min-width: 0; }

.topbar {
  position: sticky; top: 0; z-index: 8;
  min-height: 68px;
  display: flex; align-items: center; justify-content: space-between; gap: 20px;
  padding: 13px 28px;
  border-bottom: 1px solid rgba(228,232,240,.8);
  background: rgba(255,255,255,.92);
  backdrop-filter: blur(18px) saturate(1.6);
  -webkit-backdrop-filter: blur(18px) saturate(1.6);
}

.eyebrow {
  margin-bottom: 3px;
  color: var(--accent);
  font-size: 9px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .1em;
}
.topbar h1 { margin: 0; font-size: 20px; font-weight: 700; color: var(--ink); }

.top-actions { display: flex; align-items: center; gap: 10px; }

.sync-state { padding-right: 14px; border-right: 1px solid var(--line); text-align: right; }
.sync-state span   { display: block; color: var(--muted); font-size: 10px; }
.sync-state strong { display: block; margin-top: 2px; font-size: 12px; font-weight: 600; }

.icon-button {
  width: 34px; height: 34px;
  display: inline-grid; place-items: center;
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  transition: border-color 140ms ease, background 140ms ease,
              box-shadow 140ms ease, transform 140ms ease;
}
.icon-button:hover {
  border-color: #A8BDEA;
  background: var(--accent-soft);
  box-shadow: 0 3px 9px rgba(59,91,219,.09);
  transform: translateY(-1px);
}
.icon-button svg { width: 16px; height: 16px; }

/* =========================================================
   CONTENT AREA + TOOLBAR
   ========================================================= */
.view-root {
  width: min(100%, 1560px);
  margin: 0 auto;
  padding: 24px 28px 52px;
}

.loading-state {
  min-height: 400px; display: grid; place-content: center;
  justify-items: center; color: var(--muted);
}
.loading-state p { margin: 14px 0 0; font-size: 13px; }
.loading-bar {
  width: 160px; height: 3px;
  position: relative; overflow: hidden; border-radius: 2px;
  background: var(--line);
}
.loading-bar::after {
  content: "";
  position: absolute; inset: 0 auto 0 0; width: 56px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  animation: loading 1.3s ease-in-out infinite;
}
@keyframes loading {
  0%   { transform: translateX(-80px); }
  100% { transform: translateX(210px); }
}

.toolbar {
  min-height: 44px; display: flex; align-items: center;
  justify-content: space-between; gap: 14px;
  margin-bottom: 16px; padding: 0 0 14px;
  border-bottom: 1px solid var(--line);
}
.toolbar-group, .section-actions, .tab-strip, .legend-row {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.field-inline { display: flex; align-items: center; gap: 8px; }
.field-inline label, .control-label {
  flex: 0 0 auto; color: var(--muted); font-size: 12px; font-weight: 500; white-space: nowrap;
}

select, .search-input {
  min-height: 34px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: var(--surface);
  color: var(--ink);
  transition: border-color 140ms ease, box-shadow 140ms ease;
}
select:hover, .search-input:hover { border-color: #A8BDEA; }
select:focus, .search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(59,91,219,.11);
  outline: 0;
}
select { min-width: 114px; padding: 0 28px 0 9px; }
.search-input { width: min(270px, 100%); padding: 0 10px; }

.segmented {
  display: inline-flex; padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #EBF0F7;
}
.segmented button, .tab-button, .text-button, .page-button {
  border: 0; border-radius: 5px; background: transparent; color: var(--muted);
}
.segmented button { min-height: 27px; padding: 0 10px; font-size: 12px; }
.segmented button.is-active {
  background: var(--surface); color: var(--ink);
  box-shadow: 0 1px 5px rgba(15,23,42,.1); font-weight: 600;
}
.tab-button { min-height: 32px; padding: 0 10px; border-radius: 6px; font-size: 13px; }
.tab-button.is-active { background: var(--accent-soft); color: var(--accent-strong); font-weight: 600; }
.text-button { min-height: 30px; padding: 0 8px; color: var(--accent-strong); border-radius: 6px; }
.text-button:hover { background: var(--accent-soft); }
.text-button.is-muted { color: var(--muted); }
.context-note { color: var(--muted); font-size: 12px; }

/* =========================================================
   KPI CARDS
   ========================================================= */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}

.kpi-card {
  position: relative;
  overflow: hidden;
  min-width: 0;
  min-height: 116px;
  padding: 16px 18px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-raised);
  transition: border-color 200ms ease, box-shadow 200ms ease, transform 200ms ease;
  animation: card-rise 480ms cubic-bezier(.22,.8,.26,1) both;
}
.kpi-card:nth-child(2) { animation-delay: 60ms; }
.kpi-card:nth-child(3) { animation-delay: 120ms; }
.kpi-card:nth-child(4) { animation-delay: 180ms; }
.kpi-card:hover {
  border-color: #CBD8EF;
  box-shadow: 0 6px 24px rgba(15,23,42,.08);
  transform: translateY(-2px);
}

/* Gradient top accent bar */
.kpi-card::before {
  content: "";
  position: absolute;
  inset: 0 auto auto 0;
  width: 100%; height: 3px;
  background: linear-gradient(90deg, var(--accent) 0%, #6C63FF 100%);
}
.kpi-card:nth-child(4n+2)::before { background: linear-gradient(90deg, var(--cyan) 0%, #0EA5E9 100%); }
.kpi-card:nth-child(4n+3)::before { background: linear-gradient(90deg, var(--violet) 0%, var(--blue) 100%); }
.kpi-card:nth-child(4n)::before   { background: linear-gradient(90deg, var(--amber) 0%, #FB923C 100%); }

.kpi-head, .kpi-foot, .section-head, .signal-head, .company-detail-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.kpi-label { color: var(--muted); font-size: 12px; }
.kpi-value {
  margin-top: 10px;
  font-size: 26px; font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  letter-spacing: -.4px;
}
.kpi-foot { margin-top: 9px; color: var(--muted); font-size: 11px; }

.trend-up   { color: #059669; }
.trend-down { color: var(--red); }
.trend-flat { color: var(--muted); }

.micro-line { width: 64px; height: 22px; flex: 0 0 64px; }
.sparkline-path {
  stroke-dasharray: 1; stroke-dashoffset: 1;
  animation: chart-draw 700ms cubic-bezier(.22,.8,.26,1) both;
}

/* =========================================================
   SECTION BANDS + HEADS
   ========================================================= */
.section-band {
  padding: 26px 0;
  border-top: 1px solid var(--line);
}
.section-band:first-of-type { border-top: 0; padding-top: 0; }

.section-head { margin-bottom: 16px; }
.section-head h2, .section-head h3, .company-detail-head h3 {
  margin: 0; font-size: 15px; font-weight: 700;
}
.section-head h2 {
  display: flex; align-items: center; gap: 9px;
}
.section-head h2::before {
  content: "";
  width: 4px; height: 14px; flex: 0 0 4px;
  border-radius: 3px;
  background: linear-gradient(180deg, var(--accent), var(--blue));
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.section-head p, .company-detail-head p { margin: 4px 0 0; color: var(--muted); font-size: 11px; }

/* Grids */
.overview-grid, .split-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.65fr) minmax(300px, 0.8fr);
  gap: 24px; align-items: start;
}
.equal-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px; align-items: start; }
.viz-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(310px, 0.78fr);
  align-items: start;
  gap: 1px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--line);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.structure-viz-grid { grid-template-columns: minmax(340px, .9fr) minmax(0, 1.2fr); }
.category-viz-grid  { grid-template-columns: minmax(340px, .85fr) minmax(0, 1.5fr); }

.viz-cell {
  min-width: 0; align-self: stretch;
  padding: 20px;
  background: var(--surface);
}
.viz-cell:first-child { padding-left: 20px; }
.viz-cell:last-child  { padding-right: 20px; }

.chart-wrap { width: 100%; min-height: 260px; position: relative; }
.chart-svg  { display: block; width: 100%; height: auto; overflow: visible; }

/* =========================================================
   CHART BASE STYLES
   ========================================================= */
.chart-grid {
  stroke: #E4E8F0; stroke-width: 1; stroke-dasharray: 3 6; opacity: 0;
  animation: chart-fade-in 500ms ease-out 80ms both;
}
.chart-axis-label { fill: #94A3B8; font-size: 9px; }
.chart-axis-title { fill: #94A3B8; font-size: 9px; font-weight: 600; }

.chart-path {
  fill: none; stroke: var(--blue); stroke-width: 2.4;
  stroke-linecap: round; stroke-linejoin: round;
  stroke-dasharray: 1; stroke-dashoffset: 1;
  animation: chart-draw 900ms cubic-bezier(.22,.8,.26,1) both;
}
.chart-area {
  fill: rgba(112,72,232,.07); opacity: 0;
  animation: chart-area-in 900ms ease-out 120ms both;
}
.chart-point {
  fill: var(--surface); stroke: var(--blue); stroke-width: 2.5;
  transform-box: fill-box; transform-origin: center;
  opacity: 0;
  animation: chart-point-in 420ms cubic-bezier(.22,.8,.26,1) calc(240ms + var(--point-index, 0) * 65ms) both;
}
.chart-point.is-selected { fill: var(--blue); stroke: var(--surface); stroke-width: 3; }

.chart-value-label {
  fill: var(--ink); font-size: 10px; font-weight: 600; opacity: 0;
  animation: chart-fade-in 360ms ease-out 520ms both;
}

/* Metric colour variants */
.chart-svg.metric-d7 .chart-path   { stroke: var(--accent); }
.chart-svg.metric-d7 .chart-area   { fill: rgba(59,91,219,.07); }
.chart-svg.metric-d7 .chart-point  { stroke: var(--accent); }
.chart-svg.metric-d7 .chart-point.is-selected { fill: var(--accent); }
.chart-svg.metric-retention .chart-path  { stroke: var(--cyan); }
.chart-svg.metric-retention .chart-area  { fill: rgba(14,165,233,.07); }
.chart-svg.metric-retention .chart-point { stroke: var(--cyan); }
.chart-svg.metric-retention .chart-point.is-selected { fill: var(--cyan); }

/* Chart colour palette */
.chart-color-0 { --chart-color: var(--accent); }
.chart-color-1 { --chart-color: var(--blue); }
.chart-color-2 { --chart-color: var(--cyan); }
.chart-color-3 { --chart-color: var(--violet); }
.chart-color-4 { --chart-color: var(--amber); }
.chart-color-5 { --chart-color: var(--green); }
.chart-color-6 { --chart-color: var(--coral); }
.chart-color-7 { --chart-color: #8292A8; }

/* Hover / interaction */
.chart-node, .chart-legend-node {
  cursor: pointer; outline: none;
  transition: opacity 160ms ease, filter 160ms ease, transform 160ms ease;
}
.chart-node:hover, .chart-node:focus-visible,
.chart-node.is-chart-linked,
.chart-legend-node:hover, .chart-legend-node:focus-visible,
.chart-legend-node.is-chart-linked {
  opacity: 1 !important;
  filter: drop-shadow(0 3px 6px rgba(59,91,219,.18));
}
.chart-point:hover, .chart-point:focus-visible,
.series-point:hover, .series-point:focus-visible,
.scatter-point:hover, .scatter-point:focus-visible { transform: scale(1.5); }
.is-chart-dimmed { opacity: .14 !important; }

/* =========================================================
   DONUT CHART
   ========================================================= */
.donut-layout {
  min-height: 240px; display: grid;
  grid-template-columns: minmax(160px, .82fr) minmax(200px, 1.18fr);
  gap: 20px; align-items: center;
}
.donut-figure { width: min(200px, 100%); aspect-ratio: 1; position: relative; margin: 0 auto; }
.donut-svg    { width: 100%; height: 100%; display: block; overflow: visible; }
.donut-track, .donut-segment { fill: none; stroke-width: 13; stroke-linecap: round; }
.donut-track  { stroke: #EDF1F7; opacity: 0; animation: chart-fade-in 420ms ease-out both; }
.donut-segment {
  stroke: var(--chart-color);
  transform: rotate(-90deg); transform-origin: 60px 60px;
  opacity: 0;
  animation: donut-segment-in 720ms cubic-bezier(.22,.8,.26,1) calc(100ms + var(--segment-index, 0) * 80ms) both;
  transition: stroke-width 180ms ease, filter 180ms ease;
}
.donut-segment:hover, .donut-segment:focus-visible, .donut-segment.is-chart-linked {
  stroke-width: 16;
  transform: rotate(-90deg) scale(1.04) !important;
  filter: drop-shadow(0 3px 5px rgba(59,91,219,.14));
}
.donut-center {
  position: absolute; inset: 50% auto auto 50%;
  width: 54%; text-align: center;
  transform: translate(-50%, -50%);
}
.donut-center strong { display: block; font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.donut-center span   { display: block; margin-top: 2px; color: var(--muted); font-size: 10px; }

.donut-legend { min-width: 0; display: grid; gap: 9px; }
.donut-legend-item {
  display: grid; grid-template-columns: 8px minmax(72px, 1fr) 48px 60px;
  gap: 8px; align-items: center; font-size: 11px; font-variant-numeric: tabular-nums;
}
.chart-swatch { width: 8px; height: 8px; border-radius: 50%; background: var(--chart-color); }
.donut-legend-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.donut-legend-item strong { text-align: right; font-weight: 650; }
.donut-legend-item small  { color: var(--muted); text-align: right; }

/* =========================================================
   COLUMN CHART
   ========================================================= */
.column-chart { min-height: 258px; }
.column-plot {
  height: 228px; position: relative; display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px; padding: 8px 6px 0 38px;
  border-bottom: 1px solid var(--line-strong);
}
.column-grid-line {
  position: absolute; right: 6px; left: 38px;
  border-top: 1px dashed var(--line);
}
.column-grid-line em {
  position: absolute; right: calc(100% + 7px); top: -7px;
  color: var(--muted); font-size: 9px; font-style: normal; white-space: nowrap;
}
.column-group {
  min-width: 0; position: relative; z-index: 1;
  display: grid; grid-template-rows: minmax(0, 1fr) 22px;
  align-items: end; text-align: center;
}
.column-bars { height: 100%; display: flex; justify-content: center; gap: 7px; align-items: flex-end; }
.column-item {
  width: min(28px, 42%); height: 100%;
  display: flex; flex-direction: column; justify-content: flex-end; align-items: center;
}
.column-value { margin-bottom: 4px; color: var(--muted); font-size: 9px; font-variant-numeric: tabular-nums; }
.column-bar {
  width: 100%; min-height: 3px; display: block;
  border-radius: 5px 5px 2px 2px;
  background: var(--comparison-previous);
  transform-origin: center bottom; transform: scaleY(0);
  animation: bar-rise 660ms cubic-bezier(.22,.8,.26,1) calc(120ms + var(--bar-index, 0) * 70ms) both;
}
.column-bar.is-current { background: linear-gradient(180deg, var(--accent) 0%, #6C63FF 100%); }
.column-bar.is-previous { background: var(--comparison-previous); }
.column-group > strong { padding-top: 6px; font-size: 10px; font-weight: 650; }
.chart-legend { display: flex; justify-content: center; gap: 16px; margin-top: 12px; color: var(--muted); font-size: 10px; }
.chart-legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend-line { width: 12px; height: 4px; display: inline-block; border-radius: 2px; background: var(--comparison-previous); }
.legend-line.is-current { background: var(--accent); }
.column-bar:hover, .column-bar:focus-visible { filter: brightness(1.08) drop-shadow(0 2px 4px rgba(59,91,219,.16)); }

/* =========================================================
   PAIRED / BAR / STACKED CHARTS
   ========================================================= */
.paired-chart { display: grid; gap: 9px; }
.paired-row {
  min-height: 30px; display: grid;
  grid-template-columns: minmax(110px, .72fr) minmax(170px, 1.8fr) 88px;
  gap: 11px; align-items: center;
}
.paired-label { min-width: 0; display: flex; align-items: center; gap: 7px; }
.paired-label span  { width: 16px; flex: 0 0 16px; color: var(--muted); font-size: 10px; text-align: right; }
.paired-label strong { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11px; font-weight: 600; }
.paired-bars, .paired-values { display: grid; gap: 3px; }
.paired-track { height: 6px; overflow: hidden; border-radius: 4px; background: #E9EEF6; }
.paired-fill {
  height: 100%; display: block; border-radius: inherit;
  background: var(--comparison-previous);
  transform-origin: left center; transform: scaleX(0);
  animation: bar-grow 660ms cubic-bezier(.22,.8,.26,1) calc(100ms + var(--bar-index, 0) * 50ms) both;
}
.paired-fill.is-current  { background: var(--accent); }
.paired-fill.is-previous { background: var(--comparison-previous); }
.paired-values { color: var(--muted); font-size: 9px; text-align: right; font-variant-numeric: tabular-nums; }
.paired-values strong { color: var(--ink); font-weight: 650; }
.paired-legend { justify-content: flex-end; margin-top: 3px; }
.paired-fill:hover, .paired-fill:focus-visible { filter: brightness(1.07) drop-shadow(0 1px 3px rgba(59,91,219,.15)); }

.bar-list { display: grid; gap: 10px; }
.bar-row {
  display: grid;
  grid-template-columns: minmax(110px, 1fr) minmax(180px, 2.8fr) 84px;
  gap: 11px; align-items: center;
}
.bar-label { min-width: 0; }
.bar-label strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; font-weight: 600; }
.bar-label span   { display: block; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: 10px; }
.bar-track, .delta-track { height: 8px; position: relative; overflow: hidden; border-radius: 5px; background: #E9EEF6; }
.bar-fill {
  height: 100%; border-radius: inherit;
  background: var(--accent);
  transform-origin: left center; transform: scaleX(0);
  animation: bar-grow 700ms cubic-bezier(.22,.8,.26,1) calc(120ms + var(--bar-index, 0) * 60ms) both;
}
.bar-fill.is-blue   { background: var(--blue); }
.bar-fill.is-amber  { background: var(--amber); }
.bar-fill.is-red    { background: var(--red); }
.bar-fill.is-violet { background: var(--violet); }
.bar-fill.is-cyan   { background: var(--cyan); }
.bar-fill.is-coral  { background: var(--coral); }
.bar-value { text-align: right; font-variant-numeric: tabular-nums; font-size: 12px; }
.bar-fill:hover, .bar-fill:focus-visible { filter: brightness(1.07) drop-shadow(0 1px 3px rgba(59,91,219,.15)); }

.stacked-bar { width: 100%; height: 16px; display: flex; overflow: hidden; border-radius: 5px; background: var(--line); }
.stack-segment {
  height: 100%; min-width: 2px;
  transform-origin: left center; transform: scaleX(0);
  animation: bar-grow 720ms cubic-bezier(.22,.8,.26,1) calc(120ms + var(--bar-index, 0) * 50ms) both;
}
.stack-segment:nth-child(6n+1) { background: var(--accent); }
.stack-segment:nth-child(6n+2) { background: var(--blue); }
.stack-segment:nth-child(6n+3) { background: var(--amber); }
.stack-segment:nth-child(6n+4) { background: var(--violet); }
.stack-segment:nth-child(6n+5) { background: #4F8A7B; }
.stack-segment:nth-child(6n)   { background: var(--coral); }

.legend-row { margin-top: 10px; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 11px; }
.legend-swatch { width: 8px; height: 8px; border-radius: 2px; background: var(--accent); }
.legend-item:nth-child(6n+2) .legend-swatch { background: var(--blue); }
.legend-item:nth-child(6n+3) .legend-swatch { background: var(--amber); }
.legend-item:nth-child(6n+4) .legend-swatch { background: var(--violet); }
.legend-item:nth-child(6n+5) .legend-swatch { background: #4F8A7B; }
.legend-item:nth-child(6n)   .legend-swatch { background: var(--coral); }

/* =========================================================
   MULTI-SERIES + SCATTER
   ========================================================= */
.multi-series-chart { min-height: 280px; }
.series-path {
  fill: none; stroke: var(--chart-color); stroke-width: 2.2;
  stroke-linecap: round; stroke-linejoin: round;
  stroke-dasharray: 1; stroke-dashoffset: 1;
  animation: chart-draw 950ms cubic-bezier(.22,.8,.26,1) calc(80ms + var(--series-index, 0) * 85ms) both;
}
.series-point {
  fill: var(--surface); stroke: var(--chart-color); stroke-width: 2;
  transform-box: fill-box; transform-origin: center; opacity: 0;
  animation: chart-point-in 420ms cubic-bezier(.22,.8,.26,1) calc(300ms + var(--point-index, 0) * 65ms) both;
}
.series-legend {
  display: flex; flex-wrap: wrap; justify-content: center;
  gap: 6px 12px; padding: 0 10px; color: var(--muted); font-size: 10px;
}
.series-legend-item {
  min-width: 0; display: inline-flex; align-items: center; gap: 6px;
  min-height: 24px; padding: 0 8px;
  border: 1px solid var(--line); border-radius: 5px;
  background: var(--surface-tint);
}
.series-legend-item span { max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.scatter-point {
  fill: var(--chart-color); fill-opacity: .76;
  stroke: var(--surface); stroke-width: 1.5;
  transform-box: fill-box; transform-origin: center; opacity: 0;
  animation: scatter-point-in 520ms cubic-bezier(.22,.8,.26,1) calc(180ms + var(--point-index, 0) * 26ms) both;
}
.scatter-point:hover { fill-opacity: 1; stroke: var(--ink); stroke-width: 2; }

/* Delta chart */
.compare-summary {
  display: grid; grid-template-columns: repeat(5, minmax(0, 1fr));
  margin-bottom: 20px;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); box-shadow: var(--shadow); overflow: hidden;
}
.compare-metric { padding: 14px; border-right: 1px solid var(--line); }
.compare-metric:last-child { border-right: 0; }
.compare-metric span   { display: block; color: var(--muted); font-size: 11px; }
.compare-metric strong { display: block; margin-top: 6px; font-size: 17px; font-weight: 700; }
.compare-metric small  { display: block; margin-top: 4px; font-size: 11px; }

.delta-row {
  display: grid;
  grid-template-columns: minmax(110px, 1fr) minmax(180px, 3fr) 82px;
  gap: 11px; align-items: center; min-height: 32px;
}
.delta-track { height: 8px; position: relative; overflow: visible; background: transparent; }
.delta-track::before {
  content: ""; position: absolute; top: 0; bottom: 0; left: 50%;
  width: 1px; background: var(--line-strong);
}
.delta-fill {
  height: 6px; position: absolute; top: 1px;
  border-radius: 3px;
  transform-origin: left center; transform: scaleX(0);
  animation: bar-grow 700ms cubic-bezier(.22,.8,.26,1) calc(120ms + var(--bar-index, 0) * 55ms) both;
}
.delta-fill.is-positive { left: 50%; background: var(--green); }
.delta-fill.is-negative { right: 50%; background: var(--red); transform-origin: right center; }
.delta-value { text-align: right; font-size: 12px; font-variant-numeric: tabular-nums; }
.delta-fill:hover, .delta-fill:focus-visible { filter: brightness(1.07) drop-shadow(0 1px 3px rgba(59,91,219,.15)); }

/* Recovery profile */
.recovery-profile { display: grid; gap: 12px; }
.recovery-product { min-width: 0; padding-bottom: 11px; border-bottom: 1px solid var(--line); }
.recovery-product:last-child { padding-bottom: 0; border-bottom: 0; }
.recovery-product-label {
  min-width: 0; display: flex; align-items: center; gap: 7px; margin-bottom: 7px;
}
.recovery-product-label strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11px; font-weight: 650; }
.recovery-stages { display: grid; gap: 4px; }
.recovery-stage { display: grid; grid-template-columns: 22px minmax(80px, 1fr) 42px; gap: 7px; align-items: center; color: var(--muted); font-size: 9px; }
.recovery-stage strong { color: var(--ink); text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.recovery-track { height: 6px; overflow: hidden; border-radius: 4px; background: #E9EEF6; }
.recovery-track i { height: 100%; display: block; border-radius: inherit; transform-origin: left center; transform: scaleX(0); animation: bar-grow 620ms cubic-bezier(.22,.8,.26,1) calc(120ms + var(--bar-index, 0) * 50ms) both; }
.recovery-track .is-blue  { background: var(--blue); }
.recovery-track .is-teal  { background: var(--accent); }
.recovery-track .is-amber { background: var(--amber); }

/* =========================================================
   TABLES
   ========================================================= */
.table-shell {
  width: 100%; overflow-x: auto;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.data-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.data-table th, .data-table td {
  height: 42px; padding: 8px 11px;
  border-bottom: 1px solid #EDF0F6;
  text-align: left; white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.data-table th {
  position: sticky; top: 0; z-index: 1;
  background: #F6F8FC; color: #75839A;
  font-size: 11px; font-weight: 600;
}
.data-table tbody tr { transition: background 100ms ease; }
.data-table tbody tr:hover { background: #F5F8FF; }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table .numeric     { text-align: right; }
.data-table .name-cell   { max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
.data-table .appid-cell  { color: var(--muted); font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; font-size: 10px; }

.sortable { display: inline-flex; align-items: center; gap: 4px; padding: 0; border: 0; background: transparent; color: inherit; font: inherit; cursor: pointer; }
.sortable.is-active { color: var(--ink); }

.pagination {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-top: 12px; color: var(--muted); font-size: 12px;
}
.page-actions { display: flex; gap: 4px; }
.page-button {
  min-width: 30px; height: 28px; padding: 0 7px;
  border: 1px solid var(--line); border-radius: 5px;
  background: var(--surface); color: var(--ink);
  font-size: 12px;
}
.page-button:disabled { cursor: not-allowed; opacity: .4; }
.page-button:not(:disabled):hover { background: var(--surface-soft); border-color: var(--line-strong); }

/* Status badges */
.signal-date, .rank-badge, .status-tag, .category-tag {
  display: inline-flex; align-items: center;
  min-height: 20px; padding: 0 7px;
  border-radius: 5px; font-size: 11px; white-space: nowrap;
}
.signal-date, .category-tag { background: var(--surface-soft); color: var(--muted); }
.rank-badge { justify-content: center; min-width: 22px; padding: 0 5px; background: var(--accent-soft); color: var(--accent-strong); font-variant-numeric: tabular-nums; }
.status-tag.is-good    { background: #EAF8F2; color: #117751; }
.status-tag.is-risk    { background: var(--red-soft); color: #9B2326; }
.status-tag.is-watch   { background: var(--amber-soft); color: #854F10; }
.status-tag.is-neutral { background: var(--violet-soft); color: #6041B5; }

/* Insight / signal / mover lists */
.insight-list, .signal-list, .mover-list, .quality-list { display: grid; gap: 0; }
.category-mover-groups { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
.subsection-title { margin: 0 0 9px; font-size: 12px; font-weight: 650; }
.empty-inline { padding: 14px 0; color: var(--muted); font-size: 12px; }
.cell-change { display: block; margin-top: 2px; font-size: 10px; font-weight: 500; }
.category-search { width: 180px; }
.category-table, .category-change-table { min-width: 1240px; }

.insight-item, .signal-item, .mover-item, .quality-item {
  padding: 12px 0; border-bottom: 1px solid var(--line);
}
.insight-item:first-child, .signal-item:first-child, .mover-item:first-child { padding-top: 0; }
.insight-item:last-child, .signal-item:last-child, .mover-item:last-child, .quality-item:last-child { border-bottom: 0; }

.insight-number {
  display: inline-grid; width: 20px; height: 20px; place-items: center;
  margin-right: 7px; border-radius: 4px;
  background: var(--accent-soft); color: var(--accent-strong);
  font-size: 11px; font-weight: 650;
}
.insight-item strong, .signal-item strong, .mover-item strong { font-weight: 600; }
.insight-item p, .signal-item p, .mover-item p, .quality-item p {
  margin: 4px 0 0; color: var(--muted); font-size: 12px; line-height: 1.6;
}
.signal-head { align-items: flex-start; }
.material-table .creative-copy { min-width: 220px; max-width: 360px; overflow: hidden; text-overflow: ellipsis; }

/* =========================================================
   RESEARCH PICKER
   ========================================================= */
.research-picker {
  margin-bottom: 22px; padding: 20px;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); box-shadow: var(--shadow-raised);
}
.research-picker .section-head { margin-bottom: 12px; }
.picker-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(280px, .65fr);
  min-height: 300px; border-top: 1px solid var(--line);
}
.picker-search-panel { min-width: 0; padding: 14px 14px 0 0; border-right: 1px solid var(--line); }
.research-search { width: 100%; margin-bottom: 10px; background: var(--surface); }
.picker-results {
  max-height: 280px; display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px; overflow-y: auto; padding-right: 8px;
}
.picker-results.is-grouped { grid-template-columns: minmax(0, 1fr); gap: 11px; }
.picker-company-group { min-width: 0; padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: #F7F9FD; }
.picker-company-head { min-height: 28px; display: flex; align-items: center; justify-content: space-between; gap: 9px; margin-bottom: 7px; }
.picker-company-head > div { min-width: 0; display: flex; align-items: baseline; gap: 7px; }
.picker-company-head strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; font-weight: 680; }
.picker-company-head span   { flex: 0 0 auto; color: var(--muted); font-size: 9px; }
.picker-company-add {
  min-height: 26px; flex: 0 0 auto; padding: 0 9px;
  border: 1px solid rgba(59,91,219,.28); border-radius: 5px;
  background: var(--accent-soft); color: var(--accent-strong);
  font-size: 10px; font-weight: 600;
}
.picker-company-add:hover { border-color: var(--accent); background: #E2EBFF; }
.picker-company-results { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }

.picker-result {
  width: 100%; min-width: 0; min-height: 66px;
  display: flex; align-items: center; justify-content: space-between; gap: 9px;
  padding: 9px 10px;
  border: 1px solid var(--line); border-radius: 7px;
  background: var(--surface-tint); color: var(--ink); text-align: left;
  transition: border-color 140ms ease, background 140ms ease, box-shadow 140ms ease;
}
.picker-result:hover { border-color: #B8C9EB; background: #F7F9FF; }
.picker-result.is-selected { border-color: rgba(59,91,219,.46); background: var(--accent-soft); box-shadow: inset 0 0 0 1px rgba(59,91,219,.06); }
.picker-result-copy { min-width: 0; }
.picker-result-copy strong, .picker-result-copy small, .picker-result-copy em { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.picker-result-copy strong { font-size: 12px; font-weight: 650; }
.picker-result-copy small  { margin-top: 3px; color: var(--muted); font-size: 10px; }
.picker-result-copy em     { margin-top: 3px; color: #8A9199; font-size: 9px; font-style: normal; }
.picker-result-action, .remove-product, .external-link {
  width: 26px; height: 26px; display: inline-grid; place-items: center; flex: 0 0 26px;
  border: 1px solid var(--line-strong); border-radius: 6px;
  background: var(--surface); color: var(--accent-strong);
  font-size: 14px; font-weight: 650; text-decoration: none;
}
.remove-product { padding: 0; border-color: transparent; background: transparent; color: var(--muted); }
.remove-product:hover, .external-link:hover { border-color: var(--line-strong); background: var(--surface-soft); color: var(--ink); }

.selected-products-panel { min-width: 0; padding: 14px 0 0 14px; }
.selected-products-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 7px; color: var(--muted); font-size: 11px; }
.selected-products-head strong { color: var(--ink); font-variant-numeric: tabular-nums; }
.selected-products { max-height: 280px; overflow-y: auto; }
.selected-product {
  min-height: 52px; display: grid;
  grid-template-columns: 8px minmax(0, 1fr) 26px;
  gap: 8px; align-items: center; border-bottom: 1px solid var(--line);
}
.selected-product:last-child { border-bottom: 0; }
.selected-product strong, .selected-product small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.selected-product strong { font-size: 12px; font-weight: 650; }
.selected-product small  { margin-top: 2px; color: var(--muted); font-size: 9px; }
.research-period-toolbar { margin-bottom: 18px; }
.research-loading { min-height: 280px; }
.empty-state.compact { min-height: 88px; }

/* =========================================================
   DIALOG + TOAST
   ========================================================= */
.scope-dialog {
  width: min(600px, calc(100vw - 28px));
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-lg);
  background: var(--surface); color: var(--ink);
  box-shadow: 0 20px 60px rgba(15,23,42,.18);
}
.scope-dialog::backdrop { background: rgba(15,23,42,.36); backdrop-filter: blur(3px); }
.dialog-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}
.dialog-head h2 { margin: 0; font-size: 18px; font-weight: 700; }
.scope-content { padding: 6px 20px 20px; }
.scope-row { display: grid; grid-template-columns: 118px minmax(0, 1fr); gap: 14px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.scope-row:last-child { border-bottom: 0; }
.scope-row dt { color: var(--muted); font-size: 12px; }
.scope-row dd { margin: 0; line-height: 1.6; }

.toast {
  position: fixed; right: 20px; bottom: 20px; z-index: 20;
  max-width: min(340px, calc(100vw - 28px));
  padding: 10px 13px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: rgba(255,255,255,.98); color: var(--ink);
  box-shadow: 0 10px 30px rgba(15,23,42,.14);
  opacity: 0; pointer-events: none;
  transform: translateY(8px);
  transition: opacity 160ms ease, transform 160ms ease;
}
.toast.is-visible { opacity: 1; transform: translateY(0); }

/* =========================================================
   TOOLTIP
   ========================================================= */
.chart-tooltip {
  position: fixed; z-index: 50;
  width: max-content; max-width: min(260px, calc(100vw - 20px));
  display: grid; gap: 3px; padding: 9px 11px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: rgba(255,255,255,.98); color: var(--ink);
  box-shadow: 0 8px 24px rgba(15,23,42,.13);
  pointer-events: none; opacity: 0;
  transform: translateY(4px) scale(.97);
  transition: opacity 110ms ease, transform 110ms ease;
}
.chart-tooltip.is-visible { opacity: 1; transform: translateY(0) scale(1); }
.chart-tooltip-title  { max-width: 240px; overflow: hidden; color: var(--muted); font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.chart-tooltip-value  { color: var(--ink); font-size: 14px; font-weight: 700; font-variant-numeric: tabular-nums; }
.chart-tooltip-detail { max-width: 240px; overflow: hidden; color: #8A95A8; font-size: 10px; line-height: 1.35; text-overflow: ellipsis; white-space: nowrap; }

/* =========================================================
   EMPTY / ERROR
   ========================================================= */
.empty-state, .error-state {
  min-height: 200px; display: grid; place-content: center;
  justify-items: center; color: var(--muted); text-align: center;
}
.error-state strong { color: var(--red); }

/* =========================================================
   COMPANY DETAIL
   ========================================================= */
.company-detail { margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--line-strong); }
.company-detail-head { margin-bottom: 13px; }

/* =========================================================
   KEYFRAME ANIMATIONS
   ========================================================= */
@keyframes chart-draw {
  from { stroke-dashoffset: 1; }
  to   { stroke-dashoffset: 0; }
}
@keyframes chart-fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes chart-area-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes chart-point-in {
  from { opacity: 0; transform: scale(.3); }
  to   { opacity: 1; transform: scale(1); }
}
@keyframes scatter-point-in {
  from { opacity: 0; transform: scale(.2); }
  to   { opacity: .76; transform: scale(1); }
}
@keyframes donut-segment-in {
  from { opacity: 0; transform: rotate(-90deg) scale(.72); }
  to   { opacity: 1; transform: rotate(-90deg) scale(1); }
}
@keyframes bar-rise {
  from { transform: scaleY(0); }
  to   { transform: scaleY(1); }
}
@keyframes bar-grow {
  from { transform: scaleX(0); }
  to   { transform: scaleX(1); }
}
@keyframes card-rise {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes content-rise {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes fade-slide-up {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* View-level stagger */
.view-root > .toolbar    { animation: content-rise 460ms cubic-bezier(.22,.8,.26,1) both; }
.view-root > .kpi-grid   { animation: content-rise 460ms cubic-bezier(.22,.8,.26,1) 55ms both; }
.view-root > .section-band:nth-of-type(1) { animation: content-rise 460ms cubic-bezier(.22,.8,.26,1) 110ms both; }
.view-root > .section-band:nth-of-type(2) { animation: content-rise 460ms cubic-bezier(.22,.8,.26,1) 165ms both; }
.view-root > .section-band:nth-of-type(3) { animation: content-rise 460ms cubic-bezier(.22,.8,.26,1) 220ms both; }
.view-root > .section-band:nth-of-type(4) { animation: content-rise 460ms cubic-bezier(.22,.8,.26,1) 275ms both; }
.view-root > .section-band:nth-of-type(5) { animation: content-rise 460ms cubic-bezier(.22,.8,.26,1) 330ms both; }
.view-root > .research-picker { animation: content-rise 460ms cubic-bezier(.22,.8,.26,1) 55ms both; }

/* Count-up number animation marker */
.kpi-value.is-counting { transition: none; }

/* =========================================================
   UTILITIES
   ========================================================= */
.nowrap       { white-space: nowrap; }
.muted        { color: var(--muted); }
.weight-medium{ font-weight: 600; }
.align-right  { text-align: right; }

/* =========================================================
   RESPONSIVE
   ========================================================= */
@media (max-width: 1320px) {
  .viz-grid, .structure-viz-grid, .category-viz-grid {
    grid-template-columns: minmax(0, 1fr);
    background: transparent;
    border: 0; box-shadow: none; gap: 12px;
  }
  .viz-cell {
    border: 1px solid var(--line); border-radius: var(--radius);
    padding: 18px;
  }
}

@media (max-width: 1120px) {
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .overview-grid, .split-grid { grid-template-columns: minmax(0, 1fr); }
  .compare-summary { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .compare-metric:nth-child(3) { border-right: 0; }
  .compare-metric:nth-child(n+4) { border-top: 1px solid var(--line); }
}

@media (max-width: 900px) {
  .app-shell { display: block; }
  .sidebar {
    position: static; width: 100%; height: auto;
    padding: 10px 12px 9px;
    border-right: 0; border-bottom: 1px solid var(--line);
  }
  .brand { padding: 1px 2px 9px; }
  .brand-logo { width: min(148px, 100%); }
  .nav-list { display: flex; gap: 4px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; overscroll-behavior-x: contain; scroll-snap-type: x proximity; }
  .nav-list::-webkit-scrollbar { display: none; }
  .nav-item { width: auto; min-width: max-content; min-height: 36px; scroll-snap-align: start; }
  .sidebar-foot { display: none; }
  .topbar { min-height: 62px; padding: 10px 16px; }
  .view-root { padding: 16px 16px 36px; }
}

@media (max-width: 700px) {
  .topbar h1 { font-size: 18px; }
  .sync-state { display: none; }
  .toolbar { align-items: flex-start; flex-direction: column; }
  .toolbar-group { width: 100%; }
  .section-head { align-items: flex-start; flex-wrap: wrap; }
  .section-head > div { min-width: 0; }
  .section-head .section-actions { width: 100%; justify-content: flex-start; }
  .context-note { max-width: 100%; line-height: 1.5; }
  .tab-strip { width: 100%; flex-wrap: nowrap; overflow-x: auto; overscroll-behavior-x: contain; scrollbar-width: none; }
  .tab-strip::-webkit-scrollbar { display: none; }
  .tab-button { flex: 0 0 auto; }
  .field-inline { min-width: 0; flex: 1 1 140px; }
  .field-inline select { min-width: 0; width: 100%; }
  .kpi-grid, .equal-grid { grid-template-columns: minmax(0, 1fr); }
  .category-mover-groups { grid-template-columns: minmax(0, 1fr); }
  .donut-layout { grid-template-columns: minmax(0, 1fr); gap: 14px; }
  .donut-figure { width: min(190px, 72vw); }
  .donut-legend { width: min(100%, 420px); margin: 0 auto; }
  .paired-row { grid-template-columns: minmax(96px, .9fr) minmax(100px, 1.4fr) 72px; gap: 8px; }
  .chart-wrap { min-height: 0; max-width: 100%; overflow-x: auto; overscroll-behavior-x: contain; scrollbar-width: thin; }
  .table-shell { max-width: 100%; -webkit-overflow-scrolling: touch; scrollbar-width: thin; }
  .compare-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .compare-metric, .compare-metric:nth-child(3) { border-right: 1px solid var(--line); border-top: 1px solid var(--line); }
  .compare-metric:nth-child(odd) { border-left: 0; }
  .compare-metric:nth-child(even) { border-right: 0; }
  .compare-metric:first-child, .compare-metric:nth-child(2) { border-top: 0; }
  .bar-row, .delta-row { grid-template-columns: minmax(90px, 1fr) minmax(100px, 2fr) 64px; gap: 8px; }
  .scope-row { grid-template-columns: minmax(0, 1fr); gap: 4px; }
  .pagination { align-items: flex-start; flex-direction: column; }
  .research-picker .section-head { align-items: flex-start; flex-direction: column; }
  .picker-grid { grid-template-columns: minmax(0, 1fr); }
  .picker-search-panel { padding-right: 0; padding-bottom: 14px; border-right: 0; border-bottom: 1px solid var(--line); }
  .selected-products-panel { padding: 14px 0 0; }
  .selected-products { max-height: 230px; }
}

@media (max-width: 460px) {
  .brand-logo { width: min(132px, 100%); }
  .nav-item { padding: 0 9px; font-size: 12px; }
  .nav-icon { width: 14px; height: 14px; flex-basis: 14px; }
  .topbar h1 { font-size: 16px; }
  .view-root { padding: 12px 12px 26px; }
  .kpi-grid { gap: 8px; margin-bottom: 18px; }
  .kpi-card { padding: 13px 13px 11px; min-height: 104px; }
  .kpi-value { font-size: 22px; }
  .section-band { padding: 20px 0; }
  .donut-legend-item { grid-template-columns: 8px minmax(68px, 1fr) 42px 52px; gap: 6px; }
  .compare-summary { grid-template-columns: minmax(0, 1fr); }
  .compare-metric, .compare-metric:nth-child(3), .compare-metric:nth-child(even) { border-right: 0; }
  .research-picker { padding: 13px; }
  .picker-results { grid-template-columns: minmax(0, 1fr); padding-right: 4px; }
  .picker-company-results { grid-template-columns: minmax(0, 1fr); }
  .series-legend { justify-content: flex-start; padding: 0; }
  .series-legend-item span { max-width: 90px; }
  .chart-wrap > .chart-svg, .chart-wrap > .multi-series-chart > .chart-svg { min-width: 460px; }
}

/* =========================================================
   PREMIUM EXTRAS
   ========================================================= */

/* Subtle body background dot-grid texture */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background-image: radial-gradient(circle, rgba(59,91,219,.05) 1px, transparent 1px);
  background-size: 28px 28px;
  pointer-events: none;
}

/* Topbar gradient accent line */
.topbar::after {
  content: "";
  position: absolute;
  bottom: -1px; left: 0; right: 0; height: 2px;
  background: linear-gradient(90deg, var(--accent) 0%, #7C3AED 40%, var(--cyan) 80%, transparent 100%);
  opacity: .22;
  pointer-events: none;
}
.topbar { position: sticky; }

/* Primary action button */
.btn-primary {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  min-height: 36px; padding: 0 16px;
  border: 0; border-radius: 8px;
  background: linear-gradient(135deg, var(--accent) 0%, #6C63FF 100%);
  color: #fff; font-size: 13px; font-weight: 600;
  box-shadow: 0 4px 12px rgba(59,91,219,.3);
  transition: filter 160ms ease, transform 160ms ease, box-shadow 160ms ease;
  cursor: pointer;
}
.btn-primary:hover {
  filter: brightness(1.07);
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(59,91,219,.35);
}
.btn-primary:active { transform: none; filter: brightness(.97); }
.btn-primary svg { width: 15px; height: 15px; }

/* Sidebar brand area — no background fill */
.brand { background: transparent; border-radius: 0; margin-bottom: 0; }

/* KPI card sparkline enhanced */
.micro-line polyline, .sparkline-path { stroke-width: 2.2; }

/* viz-cell card uniform rounded when stacked */
@media (max-width: 1320px) {
  .viz-cell { border-radius: var(--radius); }
  .viz-cell:first-child { border-radius: var(--radius); }
}

/* Smooth hover transition on nav items */
.nav-item { transition: background 140ms ease, color 140ms ease, box-shadow 140ms ease, transform 120ms ease; }
.nav-item:hover { transform: translateX(2px); }
.nav-item.is-active { transform: none; }

/* Better table header */
.data-table th { letter-spacing: .03em; }

/* Pagination button active state */
.page-button.is-active, .page-button[aria-current] {
  background: var(--accent); color: #fff; border-color: var(--accent);
}

/* Refined donut center */
.donut-center strong { letter-spacing: -.5px; }

/* Section head accent dot */
.section-head h2::before { animation: card-rise 400ms cubic-bezier(.22,.8,.26,1) 200ms both; }

/* Respect reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: .01ms !important;
  }
  .sparkline-path, .chart-path, .series-path { stroke-dashoffset: 0 !important; }
  .donut-segment { transform: rotate(-90deg) !important; }
  .column-bar, .paired-fill, .recovery-track i, .bar-fill, .stack-segment, .delta-fill { transform: none !important; }
  .sparkline-path, .chart-grid, .chart-area, .chart-path, .chart-point, .chart-value-label,
  .donut-track, .donut-segment, .column-bar, .paired-fill, .series-path, .series-point,
  .recovery-track i, .scatter-point, .bar-fill, .stack-segment, .delta-fill,
  .kpi-card, .view-root > .toolbar, .view-root > .kpi-grid, .view-root > .section-band { animation: none !important; opacity: 1 !important; }
  .chart-tooltip { transition: none; }
}
