:root {
  color-scheme: light;
  --bg: #f2f1f4;
  --panel: #ffffff;
  --panel-soft: #f8f6ef;
  --ink: #211f2d;
  --muted: #666575;
  --line: #d9d5df;
  --accent: #5b4b8a;
  --accent-2: #d6a62e;
  --accent-3: #777985;
  --accent-4: #f0c94a;
  --warn: #9b6a00;
  --shadow: 0 14px 38px rgba(36, 32, 48, 0.08);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

a {
  color: inherit;
}

button,
input,
select {
  font: inherit;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(12px);
}

.header-inner {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  min-width: 300px;
}

.brand-logo {
  width: 54px;
  height: auto;
  display: block;
  flex: 0 0 auto;
}

.brand-copy {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.brand-copy span,
.eyebrow {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.brand-copy strong {
  color: var(--ink);
  font-size: 17px;
  line-height: 1.2;
}

.main-nav {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 6px;
}

.nav-link {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 0 10px;
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
  font-weight: 700;
}

.nav-link:hover,
.nav-link.active {
  border-color: #c7bdd9;
  background: #eee8f6;
  color: #403268;
}

.app-shell {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 28px 24px 52px;
}

.site-footer {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 0 24px 28px;
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  color: var(--muted);
  font-size: 13px;
}

.site-footer a {
  color: var(--accent);
  font-weight: 700;
  text-decoration: none;
}

.page-intro {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 380px);
  gap: 24px;
  align-items: end;
  margin-bottom: 22px;
}

.page-intro h1 {
  max-width: 980px;
  margin: 8px 0 12px;
  font-size: clamp(34px, 5vw, 64px);
  line-height: 0.98;
  letter-spacing: 0;
}

.page-intro p,
.panel p,
.note {
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
}

.intro-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.button,
button.button {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #c7bdd9;
  border-radius: var(--radius);
  padding: 0 12px;
  background: #fff;
  color: #403268;
  text-decoration: none;
  font-weight: 750;
  cursor: pointer;
}

.button.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.layout-grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 16px;
  align-items: start;
}

.span-12 {
  grid-column: span 12;
}

.span-8 {
  grid-column: span 8;
}

.span-7 {
  grid-column: span 7;
}

.span-6 {
  grid-column: span 6;
}

.span-5 {
  grid-column: span 5;
}

.span-4 {
  grid-column: span 4;
}

.panel,
.kpi-card,
.data-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.panel {
  padding: 18px;
}

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.panel h2,
.panel h3 {
  margin: 0;
  line-height: 1.2;
  letter-spacing: 0;
}

.panel h2 {
  font-size: 21px;
}

.panel h3 {
  font-size: 17px;
}

.panel-subtitle {
  margin-top: 5px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.4;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.kpi-card {
  min-height: 126px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 12px;
}

.kpi-card strong {
  color: var(--accent);
  font-size: clamp(24px, 3vw, 34px);
  line-height: 1;
}

.kpi-card span {
  color: var(--ink);
  font-weight: 750;
  line-height: 1.25;
}

.kpi-card small {
  color: var(--muted);
  line-height: 1.35;
}

.metric-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.data-card {
  padding: 14px;
  min-height: 96px;
}

.data-card strong {
  display: block;
  margin-bottom: 6px;
  color: var(--accent-2);
  font-size: 24px;
  line-height: 1.1;
}

.data-card span {
  display: block;
  color: var(--ink);
  font-size: 14px;
  font-weight: 750;
}

.data-card small {
  display: block;
  margin-top: 6px;
  color: var(--muted);
}

.cascade-summary-box.compact {
  border: 1px solid #d6cbe4;
  border-radius: var(--radius);
  padding: 14px;
  background: linear-gradient(135deg, #ffffff 0%, #f7f3fb 55%, #fbf6df 100%);
  display: grid;
  gap: 12px;
  margin-bottom: 12px;
}

.cascade-summary-box strong {
  display: block;
  color: var(--ink);
  font-size: 16px;
  line-height: 1.25;
}

.cascade-summary-box span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.summary-kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(96px, 1fr));
  gap: 8px;
}

.summary-kpi {
  min-height: 78px;
  border: 1px solid rgba(91, 75, 138, 0.16);
  border-radius: var(--radius);
  padding: 10px;
  background: rgba(255, 255, 255, 0.72);
}

.summary-kpi strong {
  color: var(--accent);
  font-size: 22px;
}

.summary-kpi span {
  margin-top: 4px;
  font-size: 12px;
  font-weight: 750;
}

.cascade-pathway {
  display: grid;
  gap: 10px;
}

.sankey-frame {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  overflow: hidden;
}

.cascade-sankey {
  width: 100%;
  height: auto;
  display: block;
}

.sankey-flow {
  fill: none;
  stroke-linecap: round;
  opacity: 0.78;
}

.sankey-flow.secondary {
  opacity: 0.48;
}

.sankey-label,
.sankey-node-title,
.sankey-node-value {
  fill: var(--ink);
  letter-spacing: 0;
}

.sankey-label {
  font-size: 14px;
  font-weight: 850;
}

.sankey-node-title {
  font-size: 15px;
  font-weight: 850;
}

.sankey-node-value {
  fill: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

.cascade-breakdown {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.cascade-breakdown span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.cascade-breakdown i {
  width: 9px;
  height: 9px;
  border-radius: 50%;
}

.cascade-breakdown strong {
  color: var(--ink);
}

.cascade-stage {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  background: #fff;
}

.stage-index {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--accent-3);
  color: #fff;
  font-weight: 850;
}

.stage-body {
  min-width: 0;
}

.stage-body strong {
  display: block;
  color: var(--ink);
  font-size: 14px;
  line-height: 1.25;
}

.stage-body span {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.3;
}

.stage-bar {
  height: 8px;
  margin-top: 8px;
  border-radius: 999px;
  overflow: hidden;
  background: #eeebf2;
}

.stage-bar i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--accent-3);
}

.stage-value {
  color: var(--ink);
  font-size: 18px;
  font-weight: 850;
  white-space: nowrap;
}

.cascade-stage.yellow .stage-index,
.cascade-stage.yellow .stage-bar i {
  background: var(--accent-2);
}

.cascade-stage.purple .stage-index,
.cascade-stage.purple .stage-bar i {
  background: var(--accent);
}

.cascade-stage.dark .stage-index,
.cascade-stage.dark .stage-bar i {
  background: #4e5261;
}

.province-map,
.district-map {
  min-height: 360px;
}

.district-map {
  min-height: 430px;
}

.province-map svg,
.district-map svg {
  width: 100%;
  height: auto;
  display: block;
  overflow: visible;
}

.province-shape {
  stroke: #ffffff;
  stroke-width: 0.65;
  cursor: pointer;
  transition: opacity 0.15s ease, stroke-width 0.15s ease;
}

.province-shape:hover,
.province-shape:focus {
  opacity: 0.84;
  outline: none;
  stroke: var(--ink);
  stroke-width: 1.3;
}

.province-shape.active {
  stroke: var(--ink);
  stroke-width: 2.4;
  filter: drop-shadow(0 5px 7px rgba(36, 32, 48, 0.2));
}

.district-shape {
  stroke: #ffffff;
  stroke-width: 0.35;
  cursor: pointer;
  transition: opacity 0.15s ease, stroke-width 0.15s ease;
}

.district-shape:hover,
.district-shape:focus {
  opacity: 0.86;
  outline: none;
  stroke: var(--ink);
  stroke-width: 0.9;
}

.district-shape.active {
  stroke: var(--ink);
  stroke-width: 1.8;
  filter: drop-shadow(0 5px 7px rgba(36, 32, 48, 0.22));
}

.map-legend {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 9px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.map-legend i {
  width: min(160px, 42vw);
  height: 12px;
  border-radius: 999px;
  background: linear-gradient(90deg, #eceaf0, #f0c94a, #5b4b8a);
}

.map-note {
  margin-top: 14px;
}

.category-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  justify-content: flex-end;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.category-legend span {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.category-legend i {
  width: 13px;
  height: 13px;
  border: 1px solid rgba(36, 32, 48, 0.2);
  border-radius: 3px;
}

.theme-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.theme-chips span {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 10px;
  background: #fffefa;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.chart-box {
  position: relative;
  height: 360px;
  width: 100%;
}

.chart-box.tall {
  height: 480px;
}

.chart-box.short {
  height: 280px;
}

.controls {
  display: flex;
  align-items: end;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
}

.control {
  display: grid;
  gap: 6px;
  min-width: 170px;
}

.control.grow {
  flex: 1 1 320px;
}

.controls.compact-controls {
  margin-bottom: 10px;
}

.control label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.control select,
.control input {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0 10px;
  background: #fff;
  color: var(--ink);
}

.table-wrap {
  width: 100%;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
  font-size: 14px;
}

.span-4 table {
  min-width: 360px;
}

th,
td {
  padding: 10px 12px;
  border-bottom: 1px solid #ebe8ef;
  text-align: left;
  vertical-align: top;
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  background: #faf9fb;
  color: #4e4b5c;
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  z-index: 1;
}

tr:last-child td {
  border-bottom: 0;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 0 9px;
  background: #eee8f6;
  color: #403268;
  font-size: 12px;
  font-weight: 800;
}

.status-pill.warn {
  background: #fff1dc;
  color: var(--warn);
}

.method-list {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.method-list li {
  border-left: 4px solid #c7bdd9;
  padding: 8px 0 8px 12px;
  color: var(--muted);
  line-height: 1.5;
}

.loading-state,
.error-state {
  min-height: 54vh;
  display: grid;
  align-content: center;
  gap: 8px;
}

.loading-state h1,
.error-state h1 {
  margin: 0;
  font-size: clamp(34px, 5vw, 60px);
  line-height: 1;
}

.empty-state {
  border: 1px dashed #c7bdd9;
  border-radius: var(--radius);
  padding: 22px;
  color: var(--muted);
  background: #fff;
}

@media (max-width: 1120px) {
  .page-intro {
    grid-template-columns: 1fr;
  }

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

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

  .span-8,
  .span-7,
  .span-6,
  .span-5,
  .span-4 {
    grid-column: span 12;
  }
}

@media (max-width: 760px) {
  .header-inner {
    display: block;
    padding: 12px 16px;
  }

  .brand {
    min-width: 0;
  }

  .brand-logo {
    width: 46px;
  }

  .main-nav {
    justify-content: flex-start;
    margin-top: 10px;
  }

  .app-shell {
    padding: 22px 16px 40px;
  }

  .site-footer {
    padding: 0 16px 24px;
  }

  .page-intro h1 {
    font-size: 36px;
  }

  .kpi-grid,
  .metric-strip {
    grid-template-columns: 1fr;
  }

  .chart-box,
  .chart-box.tall,
  .chart-box.short {
    height: 320px;
  }

  .cascade-stage {
    grid-template-columns: 30px minmax(0, 1fr);
  }

  .stage-index {
    width: 30px;
    height: 30px;
  }

  .stage-value {
    grid-column: 2;
    font-size: 16px;
  }

  .province-map {
    min-height: 280px;
  }

  .control {
    width: 100%;
  }
}
