:root {
  --bg: #eef3f8;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --ink: #0f172a;
  --muted: #5f6f83;
  --line: #d7e0ea;
  --line-strong: #bcc9d8;
  --panel-one: #0f766e;
  --panel-one-soft: #ecfdf5;
  --panel-two: #6d28d9;
  --panel-two-soft: #f5f3ff;
  --accent: #ea580c;
  --danger: #b91c1c;
  --shadow: 0 14px 40px rgba(15, 23, 42, 0.08);
  --radius: 16px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--ink);
}
button, select, input { font: inherit; }
button { cursor: pointer; }

.app-shell {
  width: min(1920px, calc(100% - 24px));
  margin: 12px auto 28px;
}

.page-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
  padding: 25px 28px 22px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: linear-gradient(135deg, #ffffff 0%, #f1f5ff 56%, #ecfdf5 100%);
  box-shadow: var(--shadow);
}

.eyebrow {
  margin: 0 0 7px;
  color: #0f766e;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .11em;
}

.header-title-block {
  padding-bottom: 2px;
}

.page-header h1 {
  margin: 0;
  max-width: 1250px;
  font-size: clamp(28px, 2.5vw, 40px);
  line-height: 1.12;
  letter-spacing: -0.03em;
}

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

.intro-card {
  position: relative;
  min-width: 0;
  padding: 15px 17px 16px;
  overflow: hidden;
  border: 1px solid rgba(188, 201, 216, .82);
  border-radius: 14px;
  background: rgba(255, 255, 255, .82);
  box-shadow: 0 5px 18px rgba(15, 23, 42, .045);
}

.intro-card::before {
  position: absolute;
  inset: 0 auto 0 0;
  width: 4px;
  content: "";
  background: var(--panel-one);
}

.intro-functions::before { background: #0e7490; }
.intro-analysis::before { background: var(--accent); }
.intro-audiences::before { background: var(--panel-two); }

.intro-card h2 {
  margin: 0 0 7px;
  color: #16324f;
  font-size: 14px;
  line-height: 1.25;
  letter-spacing: .005em;
}

.intro-card p {
  margin: 0;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.56;
}

.intro-card strong {
  color: #334155;
  font-weight: 780;
}

.data-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.data-badge {
  display: inline-flex;
  align-items: center;
  min-height: 31px;
  padding: 6px 11px;
  border: 1px solid #cbd5e1;
  border-radius: 999px;
  background: rgba(255,255,255,.9);
  color: #334155;
  font-size: 12px;
  font-weight: 720;
  box-shadow: 0 2px 8px rgba(15,23,42,.035);
}

.global-error, .fatal-message {
  margin: 14px auto;
  padding: 14px 16px;
  border: 1px solid #fecaca;
  border-radius: 12px;
  background: #fef2f2;
  color: #991b1b;
  line-height: 1.5;
}

.panel-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: start;
  gap: 14px;
  margin-top: 14px;
}

.panel-shell {
  min-width: 0;
  overflow: hidden;
  padding: 13px 14px 17px;
  border: 1px solid var(--line);
  border-top-width: 5px;
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.panel-one { border-top-color: var(--panel-one); }
.panel-two { border-top-color: var(--panel-two); }

.panel-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 3px 3px 11px;
}
.panel-heading h2 {
  margin: 0;
  font-size: 22px;
  letter-spacing: -.01em;
}
.panel-heading p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}
.panel-pill {
  flex: none;
  padding: 6px 10px;
  border-radius: 999px;
  color: white;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .06em;
}
.panel-one .panel-pill { background: var(--panel-one); }
.panel-two .panel-pill { background: var(--panel-two); }

.filter-details, .narrative-details {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
}
.filter-details > summary, .narrative-details > summary {
  padding: 12px 14px;
  color: #263449;
  font-size: 13px;
  font-weight: 780;
  cursor: pointer;
  user-select: none;
}
.filter-details[open] > summary, .narrative-details[open] > summary {
  border-bottom: 1px solid var(--line);
}
.filter-body { padding: 13px; }

.checkbox-line {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-soft);
  color: #334155;
  font-size: 12px;
  line-height: 1.4;
}
.checkbox-line input { margin-top: 2px; accent-color: var(--accent); }

.help-text {
  margin: 9px 2px 11px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.45;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
.form-field.full { grid-column: 1 / -1; }
.form-field label, .field-label {
  display: block;
  margin: 0 0 5px;
  color: #536276;
  font-size: 11px;
  font-weight: 720;
}
.form-field select {
  width: 100%;
  min-height: 38px;
  padding: 7px 30px 7px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  background: #fff;
  color: #172033;
  font-size: 12px;
  text-overflow: ellipsis;
}
.form-field select:focus, .action-button:focus-visible, .metric-option:focus-within {
  outline: 3px solid rgba(14, 116, 144, .18);
  outline-offset: 1px;
}
.form-field select:disabled { background: #f1f5f9; color: #94a3b8; }

.metric-fieldset {
  margin: 11px 0 0;
  padding: 0;
  border: 0;
}
.metric-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}
.metric-option {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  padding: 6px 9px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  color: #334155;
  font-size: 10.5px;
  line-height: 1.2;
}
.metric-option input { margin: 0; accent-color: var(--accent); }

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin: 12px 0 9px;
}
.kpi-card {
  min-height: 86px;
  padding: 10px 11px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: linear-gradient(180deg, #fff, #f8fafc);
}
.kpi-label {
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .035em;
  text-transform: uppercase;
}
.kpi-value {
  overflow: hidden;
  margin-top: 5px;
  color: var(--ink);
  font-size: 20px;
  font-weight: 790;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.kpi-note {
  margin-top: 3px;
  color: #6b7a8e;
  font-size: 9.5px;
  line-height: 1.25;
}

.analysis-note {
  margin: 5px 0 10px;
  padding: 9px 11px;
  border-left: 4px solid #94a3b8;
  border-radius: 8px;
  background: #f8fafc;
  color: #475569;
  font-size: 11px;
  line-height: 1.48;
}
.panel-one .analysis-note { border-left-color: var(--panel-one); }
.panel-two .analysis-note { border-left-color: var(--panel-two); }

.plot-card {
  position: relative;
  min-height: 440px;
  margin-top: 10px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
}
.plot-card.map-card { min-height: 505px; }
.plot-target { width: 100%; min-height: 438px; }
.map-card .plot-target { min-height: 503px; }
.plot-loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 2;
  background: rgba(255,255,255,.8);
  color: var(--muted);
  font-size: 12px;
}

.download-row {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin: 9px 0 10px;
}
.action-button {
  min-height: 35px;
  padding: 7px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  background: #fff;
  color: #263449;
  font-size: 10.5px;
  font-weight: 720;
}
.action-button:hover { background: #f8fafc; border-color: #94a3b8; }
.action-button.primary { color: #fff; border-color: transparent; }
.panel-one .action-button.primary { background: var(--panel-one); }
.panel-two .action-button.primary { background: var(--panel-two); }
.action-button[disabled] { opacity: .55; cursor: wait; }

.narrative-body { padding: 11px 12px 13px; }
.narrative-status {
  margin: 0 0 9px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.45;
}
.table-scroll {
  max-height: 520px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
}
.narrative-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 10.5px;
  line-height: 1.4;
}
.narrative-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 8px;
  border-bottom: 1px solid var(--line-strong);
  background: #f1f5f9;
  color: #334155;
  text-align: left;
  white-space: nowrap;
}
.narrative-table td {
  padding: 8px;
  border-bottom: 1px solid #e7edf4;
  vertical-align: top;
  color: #334155;
}
.narrative-table td:last-child { min-width: 360px; }
.narrative-table tr:last-child td { border-bottom: 0; }

.method-notes {
  margin-top: 14px;
  padding: 14px 17px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  color: #526176;
  font-size: 12px;
  line-height: 1.58;
}
.method-notes p { margin: 5px 0; }
.site-footer {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 3px 0;
  color: #718096;
  font-size: 10.5px;
}

.loading-screen {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: grid;
  place-items: center;
  padding: 20px;
  background: radial-gradient(circle at 20% 10%, #ecfdf5, transparent 34%), radial-gradient(circle at 80% 30%, #ede9fe, transparent 37%), #eef3f8;
}
.loading-card {
  width: min(560px, 100%);
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: rgba(255,255,255,.96);
  box-shadow: 0 20px 70px rgba(15,23,42,.13);
  text-align: center;
}
.loading-card h1 { margin: 13px 0 5px; font-size: 24px; }
.loading-card p { margin: 7px 0; color: var(--muted); font-size: 13px; line-height: 1.5; }
.loading-note { font-size: 11px !important; }
.spinner {
  width: 38px;
  height: 38px;
  margin: auto;
  border: 4px solid #dbe4ef;
  border-top-color: var(--panel-one);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
.progress-track {
  height: 8px;
  margin: 15px 0 5px;
  overflow: hidden;
  border-radius: 999px;
  background: #e2e8f0;
}
.progress-bar {
  width: 3%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--panel-one), var(--panel-two));
  transition: width .25s ease;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 1180px) {
  .panel-grid { grid-template-columns: 1fr; }
  .panel-shell { max-width: 100%; }
}
@media (max-width: 900px) {
  .dashboard-introduction { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .app-shell { width: min(100% - 12px, 1920px); margin-top: 6px; }
  .page-header { padding: 20px 18px; border-radius: 15px; }
  .intro-card { padding: 13px 14px 14px; }
  .panel-shell { padding: 11px 9px 14px; border-radius: 15px; }
  .form-grid { grid-template-columns: 1fr; }
  .form-field.full { grid-column: auto; }
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .plot-card, .plot-target { min-height: 400px; }
  .map-card, .map-card .plot-target { min-height: 445px; }
  .site-footer { flex-direction: column; }
}
@media (max-width: 430px) {
  .kpi-grid { grid-template-columns: 1fr; }
  .download-row { display: grid; grid-template-columns: 1fr 1fr; }
  .action-button.primary { grid-column: 1 / -1; }
}
