:root {
  color-scheme: light;
  --bg: #f4f6f9;
  --surface: #fefefe;
  --surface-muted: #e8ecf1;
  --surface-soft: #f8fafb;
  --text-primary: #1d262f;
  --text-secondary: #436a88;
  --text-tertiary: #748291;
  --border-subtle: #d5dbe3;
  --signal-positive: #247d78;
  --signal-info: #536fa8;
  --signal-warm: #b67920;
  --signal-danger: #c94d44;
  --cta-primary: #1b2731;
  --shadow: 0 18px 44px rgba(29, 38, 47, 0.08);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text-primary);
  font-family: Geist, Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

button {
  color: inherit;
}

a {
  color: var(--signal-positive);
  text-underline-offset: 3px;
}

.app-shell {
  width: min(1520px, calc(100% - 32px));
  margin: 0 auto;
  padding: 22px 0 44px;
  animation: workspace-in 360ms ease-out both;
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  padding: 6px 0 20px;
}

.topbar > div {
  min-width: 0;
}

.labs-link {
  display: inline-flex;
  margin-bottom: 10px;
  color: var(--signal-positive);
  font-size: 0.82rem;
  font-weight: 800;
  text-decoration: none;
  transition: color 160ms ease;
}

.labs-link::before {
  content: "<-";
  margin-right: 8px;
}

.labs-link:hover,
.labs-link:focus-visible {
  color: var(--cta-primary);
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--text-secondary);
  font-size: 0.78rem;
  font-weight: 760;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  overflow-wrap: anywhere;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  max-width: 950px;
  margin-bottom: 0;
  font-size: clamp(2.1rem, 5vw, 4.8rem);
  line-height: 0.96;
  letter-spacing: 0;
  overflow-wrap: anywhere;
}

h2 {
  margin-bottom: 4px;
  font-size: 1rem;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.status-pill,
.ghost-button {
  min-height: 38px;
  border: 1px solid var(--border-subtle);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 14px;
  white-space: nowrap;
}

.status-pill.ready {
  border-color: rgba(36, 125, 120, 0.24);
  background: rgba(36, 125, 120, 0.08);
  color: var(--signal-positive);
}

.status-pill.error {
  border-color: rgba(201, 77, 68, 0.28);
  background: rgba(201, 77, 68, 0.09);
  color: var(--signal-danger);
}

.ghost-button {
  cursor: pointer;
  transition: border-color 160ms ease, color 160ms ease, transform 160ms ease, background 160ms ease;
}

.ghost-button:hover,
.ghost-button:focus-visible {
  border-color: var(--signal-positive);
  color: var(--signal-positive);
  transform: translateY(-1px);
}

.filters,
.chart-panel,
.table-section {
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.filters {
  padding: 16px;
}

.filter-row {
  display: grid;
  gap: 12px;
}

.filter-row + .filter-row {
  margin-top: 12px;
}

.filter-row-main {
  grid-template-columns: minmax(180px, 1.15fr) minmax(140px, 0.9fr) minmax(150px, 0.85fr) repeat(5, minmax(112px, 0.7fr));
}

.filter-row-secondary {
  grid-template-columns: minmax(180px, 1.25fr) repeat(4, minmax(150px, 1fr));
}

label {
  display: grid;
  gap: 6px;
  color: var(--text-secondary);
  font-size: 0.73rem;
  font-weight: 760;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

select,
input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  background: var(--surface-soft);
  color: var(--text-primary);
  padding: 0 12px;
  outline: none;
  transition: border-color 140ms ease, box-shadow 140ms ease, background 140ms ease;
}

select[multiple] {
  min-height: 118px;
  padding: 8px 10px;
}

select:focus,
input:focus {
  border-color: var(--signal-positive);
  background: var(--surface);
  box-shadow: 0 0 0 3px rgba(36, 125, 120, 0.12);
}

.toggle-wrap {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  background: var(--surface-soft);
  color: var(--text-primary);
  padding: 0 12px;
  text-transform: none;
  letter-spacing: 0;
  font-size: 0.9rem;
  font-weight: 650;
}

.toggle-wrap input {
  width: 18px;
  min-height: 18px;
  accent-color: var(--signal-positive);
}

.filter-note {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  font-size: 0.86rem;
  line-height: 1.45;
}

.filter-note p {
  margin-bottom: 0;
}

#countryHelp {
  color: var(--text-tertiary);
  text-align: right;
}

.kpis {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 1px;
  overflow: hidden;
  margin: 14px 0;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  background: var(--border-subtle);
}

.kpi {
  min-width: 0;
  background: var(--surface);
  padding: 16px;
}

.kpi span {
  display: block;
  color: var(--text-secondary);
  font-size: 0.73rem;
  font-weight: 760;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.kpi strong {
  display: block;
  margin-top: 7px;
  font-size: clamp(1.2rem, 2vw, 2rem);
  line-height: 1.05;
  letter-spacing: 0;
  font-variant-numeric: tabular-nums;
}

.compare-lines {
  display: grid;
  gap: 4px;
  font-size: clamp(0.92rem, 1.3vw, 1.22rem);
  line-height: 1.2;
}

.compare-line {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.compare-line em {
  color: var(--text-secondary);
  font-style: normal;
  font-weight: 720;
}

.chart-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  align-items: stretch;
}

.chart-panel {
  min-width: 0;
  padding: 16px;
  animation: panel-in 300ms ease-out both;
}

.trend-panel {
  grid-column: span 2;
}

.section-heading {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 10px;
}

.section-heading p {
  margin-bottom: 0;
  color: var(--text-secondary);
  font-size: 0.86rem;
  line-height: 1.35;
}

.shade-key {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px 10px;
  margin-top: 8px;
  color: var(--text-tertiary);
  font-size: 0.74rem;
  font-weight: 680;
  line-height: 1.3;
}

.shade-key-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}

.shade-ramp {
  width: 30px;
  height: 5px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--shade-from), var(--shade-to));
}

.shade-key-note {
  color: var(--text-secondary);
  white-space: nowrap;
}

.trend-heading {
  align-items: stretch;
}

.trend-controls {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  min-width: min(360px, 48%);
}

.compare-control {
  flex: 1;
  min-width: 190px;
}

.compare-control select {
  min-height: 92px;
}

.compact-button {
  min-height: 42px;
  border-radius: var(--radius);
}

.compact-control {
  min-width: 150px;
}

.chart-box {
  position: relative;
  height: 278px;
  min-height: 278px;
}

.chart-box-large {
  height: 380px;
  min-height: 380px;
}

.table-section {
  margin-top: 14px;
  padding: 16px;
}

.table-heading {
  align-items: flex-end;
}

.table-controls {
  display: grid;
  grid-template-columns: minmax(145px, 0.8fr) minmax(88px, 0.45fr) minmax(180px, 1fr);
  gap: 10px;
  width: min(610px, 58%);
}

.table-wrap {
  position: relative;
  overflow-x: auto;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
}

table {
  width: 100%;
  min-width: 980px;
  border-collapse: collapse;
  background: var(--surface);
  font-size: 0.9rem;
}

th,
td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-subtle);
  text-align: left;
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-muted);
  color: var(--text-secondary);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
  user-select: none;
}

td {
  color: var(--text-primary);
}

td.numeric,
th.numeric {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.segment-name {
  max-width: 380px;
  font-weight: 720;
  overflow-wrap: anywhere;
}

.segment-meta {
  display: block;
  margin-top: 3px;
  color: var(--text-tertiary);
  font-size: 0.76rem;
  font-weight: 620;
}

.empty-state {
  padding: 18px;
  color: var(--text-secondary);
  background: var(--surface-soft);
}

.methodology {
  display: grid;
  grid-template-columns: minmax(240px, 0.8fr) minmax(0, 1.5fr);
  gap: 28px;
  margin-top: 24px;
  padding: 24px 0 6px;
  border-top: 1px solid var(--border-subtle);
}

.methodology h2 {
  max-width: 460px;
  font-size: clamp(1.35rem, 2.1vw, 2.1rem);
  line-height: 1.05;
}

.methodology-copy {
  color: var(--text-primary);
  font-size: 0.98rem;
  line-height: 1.65;
}

.methodology-copy p {
  margin-bottom: 12px;
}

.source-brand {
  color: var(--text-secondary);
}

code {
  border: 1px solid var(--border-subtle);
  border-radius: 5px;
  background: var(--surface-muted);
  padding: 1px 5px;
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.86em;
}

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

@keyframes panel-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 1180px) {
  .filter-row-main,
  .filter-row-secondary {
    grid-template-columns: repeat(4, minmax(150px, 1fr));
  }

  .country-picker {
    grid-column: span 2;
  }

  .wide-control {
    grid-column: span 2;
  }

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

  .trend-panel {
    grid-column: span 2;
  }

  .table-controls {
    width: 100%;
  }
}

@media (max-width: 820px) {
  .app-shell {
    width: min(100% - 20px, 760px);
    padding-top: 14px;
  }

  .topbar {
    display: grid;
    gap: 14px;
  }

  .topbar-actions {
    justify-content: flex-start;
  }

  main {
    display: flex;
    flex-direction: column;
  }

  .kpis {
    order: -1;
    margin: 0 0 14px;
  }

  .filter-row-main,
  .filter-row-secondary,
  .chart-grid,
  .methodology {
    grid-template-columns: 1fr;
  }

  .country-picker,
  .wide-control,
  .trend-panel {
    grid-column: auto;
  }

  select[multiple] {
    min-height: 96px;
  }

  .filter-note,
  .section-heading,
  .trend-heading,
  .table-heading,
  .trend-controls {
    display: grid;
    width: 100%;
    min-width: 0;
  }

  #countryHelp {
    text-align: left;
  }

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

  .chart-box,
  .chart-box-large {
    height: 300px;
    min-height: 300px;
  }

  .table-controls {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .app-shell {
    width: min(100% - 16px, 360px);
    margin-right: 8px;
    margin-left: 8px;
  }

  h1 {
    font-size: clamp(2rem, 11vw, 2.75rem);
  }

  .status-pill,
  .ghost-button {
    width: 100%;
  }

  .topbar-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .filters,
  .chart-panel,
  .table-section {
    padding: 12px;
  }

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

  .chart-box,
  .chart-box-large {
    height: 284px;
    min-height: 284px;
  }
}
