:root {
  --ink: #171717;
  --ink-soft: #626260;
  --paper: #f0f0ee;
  --paper-deep: #e4e4e1;
  --line: rgba(23, 23, 23, 0.13);
  --line-strong: rgba(23, 23, 23, 0.28);
  --white: #ffffff;
  --aqua: #dededb;
  --aqua-strong: #424242;
  --orange: #343434;
  --yellow: #cfcfcb;
  --shadow: 0 18px 44px rgba(23, 23, 23, 0.08);
  --display: 'Space Grotesk', 'Trebuchet MS', sans-serif;
  --body: 'DM Sans', Arial, sans-serif;
  --mono: 'SFMono-Regular', Consolas, 'Liberation Mono', monospace;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background: var(--paper);
  font-family: var(--body);
  -webkit-font-smoothing: antialiased;
}

button, input, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible {
  outline: 3px solid var(--orange);
  outline-offset: 3px;
}

[hidden] { display: none !important; }

.site-shell { overflow: hidden; }

.topbar, .tool-header, .dashboard, .footer {
  width: min(1220px, calc(100% - 64px));
  margin-inline: auto;
}

.topbar {
  min-height: 74px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: inline-flex;
  gap: 12px;
  align-items: center;
  color: var(--ink);
  font-family: var(--display);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.04em;
  text-decoration: none;
}

.topbar-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--ink-soft);
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.topbar-meta a { color: var(--ink); text-decoration: none; border-bottom: 1px solid var(--line-strong); }
.topbar-meta a:hover { border-color: var(--orange); color: var(--orange); }
.live-dot, .stamp-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--aqua-strong); box-shadow: 0 0 0 4px rgba(66, 66, 66, 0.15); }

.tool-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 30px;
  padding-block: 35px 28px;
  border-bottom: 1px solid var(--line);
}
.tool-header h1 { margin: 0; font-family: var(--display); font-size: clamp(30px, 4vw, 48px); font-weight: 600; letter-spacing: -0.075em; line-height: 1; }
.tool-description { margin: 11px 0 0; color: var(--ink-soft); font-size: 13px; }
.tool-actions { flex: 0 0 auto; text-align: right; }

.eyebrow {
  margin: 0 0 16px;
  color: var(--orange);
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.16em;
  line-height: 1.4;
  text-transform: uppercase;
}

.action-row { display: flex; align-items: center; flex-wrap: wrap; gap: 12px; }
.last-update { margin: 18px 0 0; color: var(--ink-soft); font-family: var(--mono); font-size: 10px; letter-spacing: 0.02em; }

.button {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: 2px;
  padding: 10px 15px;
  font-size: 12px;
  font-weight: 700;
  transition: transform 160ms ease, background 160ms ease, border-color 160ms ease;
}
.button:hover { transform: translateY(-2px); }
.button-primary { color: var(--white); background: var(--ink); box-shadow: 4px 4px 0 var(--orange); }
.button-primary:hover { background: #2a2a2a; }
.button-icon { font-size: 18px; font-weight: 400; line-height: 0; }
.button-quiet { color: var(--ink); border-color: var(--line-strong); background: transparent; }
.button-quiet:hover { border-color: var(--ink); background: rgba(255,255,255,0.32); }
.button-outline { min-height: 35px; padding: 7px 11px; color: var(--ink); border-color: var(--line-strong); background: transparent; font-size: 11px; }
.button-outline:hover { border-color: var(--orange); color: var(--orange); }
.button-small { min-height: 33px; padding: 7px 11px; color: var(--ink); background: var(--yellow); }

.dashboard { padding-bottom: 64px; }
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1px; background: var(--line-strong); border: 1px solid var(--line-strong); }

.analytics-section { margin-top: 48px; padding-top: 38px; border-top: 1px solid var(--line-strong); }
.analytics-heading { display: flex; align-items: end; justify-content: space-between; gap: 24px; margin-bottom: 25px; }
.analytics-heading .eyebrow { margin-bottom: 8px; }
.analytics-summary { margin: 10px 0 0; color: var(--ink-soft); font-size: 12px; }
.source-picker { min-width: 230px; display: block; }
.source-picker span { display: block; margin-bottom: 6px; color: var(--ink-soft); font-family: var(--mono); font-size: 9px; letter-spacing: 0.08em; text-transform: uppercase; }
.source-picker select { width: 100%; min-height: 39px; padding: 0 10px; color: var(--ink); border: 1px solid var(--line-strong); border-radius: 0; background: var(--white); font-size: 11px; }
.insight-kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1px; margin-bottom: 16px; background: var(--line-strong); border: 1px solid var(--line-strong); }
.insight-kpi { min-height: 116px; display: flex; flex-direction: column; justify-content: space-between; padding: 17px 18px; background: var(--white); }
.insight-kpi-dark { color: var(--white); background: var(--ink); }
.insight-kpi-label { color: var(--ink-soft); font-family: var(--mono); font-size: 9px; letter-spacing: 0.06em; text-transform: uppercase; }
.insight-kpi-dark .insight-kpi-label { color: rgba(255,255,255,0.62); }
.insight-kpi strong { font-family: var(--display); font-size: 35px; font-weight: 500; letter-spacing: -0.08em; line-height: 1; }
.insight-kpi > span:last-child { color: var(--ink-soft); font-family: var(--mono); font-size: 9px; }
.insight-kpi-dark > span:last-child { color: rgba(255,255,255,0.55); }
.insight-callout { margin-bottom: 16px; padding: 13px 16px; border-left: 3px solid var(--ink); background: var(--paper-deep); }
.insight-callout p { margin: 0; color: var(--ink); font-size: 12px; line-height: 1.45; }
.charts-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.chart-card { min-width: 0; padding: 21px 20px 16px; border: 1px solid var(--line-strong); background: var(--white); }
.chart-wide { grid-column: 1 / -1; }
.chart-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; min-height: 68px; }
.chart-heading h3 { margin: 0; font-family: var(--display); font-size: 19px; font-weight: 600; letter-spacing: -0.055em; }
.chart-heading p:not(.chart-kicker) { max-width: 580px; margin: 7px 0 0; color: var(--ink-soft); font-size: 11px; line-height: 1.4; }
.chart-kicker { margin: 0 0 7px; color: var(--ink-soft); font-family: var(--mono); font-size: 9px; letter-spacing: 0.12em; text-transform: uppercase; }
.chart-unit { flex: 0 0 auto; padding: 5px 7px; color: var(--ink-soft); border: 1px solid var(--line); font-family: var(--mono); font-size: 8px; letter-spacing: 0.04em; text-transform: uppercase; }
.chart { min-height: 220px; display: flex; align-items: center; }
.chart svg { width: 100%; height: auto; overflow: visible; }
.chart-scroll { display: block; overflow-x: auto; }
.chart-scroll svg { min-width: 820px; }
.chart-empty, .comment-empty { width: 100%; padding: 42px 15px; color: var(--ink-soft); font-family: var(--mono); font-size: 10px; text-align: center; }
.chart-grid-line { stroke: #e5e5e2; stroke-width: 1; }
.chart-axis-line { stroke: #a7a7a4; stroke-width: 1; }
.chart-track { fill: #ededeb; }
.chart-bar { fill: #171717; }
.chart-bar-soft { fill: #5a5a58; }
.chart-label { fill: #30302f; font-family: var(--body); font-size: 11px; }
.chart-axis-label, .chart-muted-value { fill: #777774; font-family: var(--mono); font-size: 9px; }
.chart-value { fill: #171717; font-family: var(--mono); font-size: 10px; font-weight: 700; }
.distribution-bar { stroke: #fff; stroke-width: 1; }
.trend-line { fill: none; stroke: #171717; stroke-width: 2.5; }
.trend-point { fill: #fff; stroke: #171717; stroke-width: 2; }
.chart-average-line { stroke: #8d8d89; stroke-dasharray: 4 4; stroke-width: 1; }
.donut-yes { stroke: #171717; stroke-width: 15; }
.donut-no { stroke: #c8c8c4; stroke-width: 15; }
.donut-value { fill: #171717; font-family: var(--display); font-size: 19px; font-weight: 600; }
.heatmap-header { fill: #555552; font-family: var(--mono); font-size: 9px; }
.heatmap-value-dark { fill: #242422; font-family: var(--mono); font-size: 10px; }
.heatmap-value-light { fill: #fff; font-family: var(--mono); font-size: 10px; }
.scatter-point { fill: #171717; opacity: 0.3; }
.comment-list { width: 100%; }
.comment-item { padding: 12px 0; border-top: 1px solid var(--line); }
.comment-item:first-child { padding-top: 0; border-top: 0; }
.comment-item p { margin: 0 0 7px; color: var(--ink); font-size: 11px; line-height: 1.45; }
.comment-item span { color: var(--ink-soft); font-family: var(--mono); font-size: 8px; text-transform: uppercase; }
.comment-empty { padding-inline: 0; text-align: left; }

.stat-card { min-height: 134px; display: flex; flex-direction: column; justify-content: space-between; padding: 20px; background: rgba(248, 248, 244, 0.45); }
.stat-card-primary { background: var(--ink); color: var(--white); }
.stat-label, .stat-note { font-family: var(--mono); font-size: 10px; letter-spacing: 0.04em; text-transform: uppercase; }
.stat-label { opacity: 0.68; }
.stat-note { opacity: 0.57; font-size: 9px; }
.stat-card strong { font-family: var(--display); font-size: 42px; font-weight: 500; letter-spacing: -0.08em; line-height: 0.9; }
.stat-card-stamp { position: relative; }
.stamp-dot { position: absolute; top: 20px; right: 20px; background: var(--orange); }

.workspace { display: grid; grid-template-columns: 250px minmax(0, 1fr); margin-top: 24px; border: 1px solid var(--line-strong); background: var(--white); box-shadow: var(--shadow); }
.field-panel { padding: 25px 20px; border-right: 1px solid var(--line); background: rgba(233, 232, 225, 0.48); }
.panel-heading, .data-panel-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 15px; }
.panel-heading .eyebrow, .data-panel-heading .eyebrow { margin-bottom: 8px; }
h2 { margin: 0; font-family: var(--display); font-size: 24px; font-weight: 600; letter-spacing: -0.06em; }
.panel-description { margin: 16px 0 24px; color: var(--ink-soft); font-size: 12px; line-height: 1.45; }
.field-list { display: grid; gap: 10px; max-height: 650px; overflow-y: auto; }
.field-item { padding: 10px 0 11px; border-top: 1px solid var(--line); }
.field-item:last-child { border-bottom: 1px solid var(--line); }
.field-reference { display: block; color: var(--orange); font-family: var(--mono); font-size: 9px; font-weight: 700; letter-spacing: 0.04em; }
.field-name { display: block; overflow: hidden; margin-top: 3px; color: var(--ink); font-size: 12px; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.field-question { display: block; margin-top: 4px; color: var(--ink-soft); font-size: 10px; line-height: 1.25; }
.field-options { display: block; margin-top: 7px; color: var(--ink-soft); font-family: var(--mono); font-size: 8px; line-height: 1.4; }
.field-meta { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 8px; color: var(--ink-soft); font-family: var(--mono); font-size: 9px; }
.field-type { color: var(--orange); text-transform: uppercase; }

.data-panel { min-width: 0; padding: 25px 25px 20px; }
.data-panel-heading { align-items: center; margin-bottom: 22px; }
.filter-bar { display: grid; grid-template-columns: minmax(180px, 1fr) 150px 150px auto; gap: 8px; align-items: end; margin-bottom: 18px; }
.search-box, .filter-control { min-width: 0; display: block; }
.search-box { position: relative; }
.search-box input, .filter-control select { width: 100%; min-height: 39px; color: var(--ink); border: 1px solid var(--line-strong); border-radius: 0; background: var(--paper); font-size: 11px; }
.search-box input { padding: 0 54px 0 32px; }
.search-box input:focus, .filter-control select:focus { border-color: var(--ink); outline: 2px solid var(--aqua-strong); outline-offset: -2px; }
.search-icon { position: absolute; z-index: 1; top: 9px; left: 11px; font-size: 21px; line-height: 1; transform: rotate(-20deg); }
kbd { position: absolute; top: 10px; right: 9px; color: var(--ink-soft); font-family: var(--mono); font-size: 9px; }
.filter-control span { display: block; margin: 0 0 5px; color: var(--ink-soft); font-family: var(--mono); font-size: 9px; text-transform: uppercase; }
.filter-control select { padding: 0 8px; }
.clear-button { min-height: 39px; padding: 0 8px; color: var(--ink-soft); border: 0; background: none; font-size: 11px; text-decoration: underline; text-underline-offset: 3px; }
.clear-button:hover { color: var(--orange); }

.error-state { display: flex; gap: 12px; align-items: center; margin-bottom: 16px; padding: 12px; border-left: 3px solid var(--orange); background: rgba(52, 52, 52, 0.1); }
.error-state strong { font-size: 12px; }
.error-state p { margin: 3px 0 0; color: var(--ink-soft); font-size: 11px; line-height: 1.4; }
.error-state .button { margin-left: auto; flex: 0 0 auto; }

.table-shell { min-width: 0; border: 1px solid var(--line); }
.table-scroll { max-height: 540px; overflow: auto; }
table { width: 100%; border-collapse: collapse; font-size: 11px; }
th, td { min-width: 130px; max-width: 250px; padding: 12px 14px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { position: sticky; z-index: 2; top: 0; color: var(--ink-soft); background: var(--paper-deep); font-family: var(--mono); font-size: 9px; font-weight: 500; letter-spacing: 0.04em; text-transform: uppercase; }
td { overflow: hidden; color: var(--ink); text-overflow: ellipsis; white-space: nowrap; }
td.cell-products { min-width: 245px; white-space: normal; line-height: 1.35; }
tbody tr:hover { background: rgba(23, 23, 23, 0.06); }
tbody tr:last-child td { border-bottom: 0; }
.sort-button { display: flex; align-items: flex-start; flex-wrap: wrap; gap: 4px 7px; width: 100%; padding: 0; color: inherit; border: 0; background: transparent; font: inherit; text-align: left; text-transform: inherit; }
.sort-button:hover { color: var(--orange); }
.sort-reference { flex-basis: 100%; color: var(--orange); font-size: 8px; letter-spacing: 0.04em; }
.sort-label { overflow: hidden; max-width: calc(100% - 22px); color: var(--ink); font-family: var(--body); font-size: 10px; font-weight: 700; letter-spacing: 0; line-height: 1.2; text-overflow: ellipsis; text-transform: none; }
.sort-arrow { margin-left: auto; color: var(--orange); font-size: 13px; line-height: 1; }
.cell-empty { color: var(--ink-soft); opacity: 0.42; }
.cell-number { font-family: var(--mono); font-size: 10px; }
caption { padding: 12px 14px; color: var(--ink-soft); border-bottom: 1px solid var(--line); font-family: var(--mono); font-size: 9px; text-align: left; text-transform: uppercase; }
.empty-state { padding: 36px 20px; color: var(--ink-soft); text-align: center; }
.empty-state strong { color: var(--ink); font-family: var(--display); font-size: 17px; }
.empty-state p { margin: 8px auto 0; font-size: 12px; }
.table-footer { min-height: 51px; display: flex; align-items: center; justify-content: space-between; gap: 15px; padding: 9px 14px; color: var(--ink-soft); font-family: var(--mono); font-size: 9px; }
.pagination-controls { display: flex; align-items: center; gap: 9px; }
.page-button { width: 27px; height: 27px; color: var(--ink); border: 1px solid var(--line-strong); background: transparent; font-size: 14px; line-height: 1; }
.page-button:hover:not(:disabled) { color: var(--white); border-color: var(--ink); background: var(--ink); }
.page-button:disabled { cursor: not-allowed; opacity: 0.3; }

.footer { display: flex; justify-content: space-between; gap: 20px; padding-block: 20px 35px; color: var(--ink-soft); border-top: 1px solid var(--line); font-family: var(--mono); font-size: 9px; letter-spacing: 0.02em; text-transform: uppercase; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

@media (max-width: 900px) {
  .tool-header { align-items: flex-start; flex-direction: column; }
  .tool-actions { text-align: left; }
  .analytics-heading { align-items: flex-start; flex-direction: column; }
  .source-picker { width: min(100%, 330px); }
  .insight-kpis { grid-template-columns: repeat(2, 1fr); }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .workspace { grid-template-columns: 190px minmax(0, 1fr); }
  .filter-bar { grid-template-columns: 1fr 1fr; }
  .search-box { grid-column: 1 / -1; }
  .clear-button { justify-self: start; }
}

@media (max-width: 650px) {
  .topbar, .tool-header, .dashboard, .footer { width: min(100% - 32px, 560px); }
  .topbar { min-height: 64px; }
  .topbar-meta { gap: 7px; font-size: 8px; }
  .topbar-meta a { display: none; }
  .tool-header { padding-block: 28px 22px; }
  .tool-header h1 { font-size: clamp(32px, 10vw, 44px); }
  .tool-description { font-size: 12px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .insight-kpis { grid-template-columns: repeat(2, 1fr); }
  .charts-grid { grid-template-columns: 1fr; }
  .chart-wide { grid-column: auto; }
  .stat-card { min-height: 115px; padding: 14px; }
  .stat-card strong { font-size: 34px; }
  .workspace { display: block; }
  .field-panel { border-right: 0; border-bottom: 1px solid var(--line); }
  .field-list { grid-template-columns: repeat(2, 1fr); max-height: 220px; gap: 0 16px; }
  .data-panel { padding: 20px 12px 12px; }
  .data-panel-heading { align-items: flex-start; }
  .data-panel-heading .button { padding-inline: 8px; font-size: 10px; }
  .filter-bar { grid-template-columns: 1fr; }
  .search-box { grid-column: auto; }
  .clear-button { justify-self: start; }
  .error-state { align-items: flex-start; flex-wrap: wrap; }
  .error-state .button { margin-left: 34px; }
  .footer { flex-direction: column; gap: 8px; }
}

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