
*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --paper: #fbf7ec;
  --paper-2: #f4efe2;
  --paper-3: #efe9da;
  --ink: #152033;
  --ink-soft: #334155;
  --muted: #69778c;
  --line: rgba(21, 32, 51, 0.13);
  --line-strong: rgba(21, 32, 51, 0.22);
  --coast: #244e5c;
  --risk: #b86850;
  --critical: #8f4b42;
  --gold: #d3af63;
  --green: #5b7562;
  --shadow: 0 14px 34px rgba(21, 32, 51, 0.10);
  --shadow-strong: 0 26px 64px rgba(21, 32, 51, 0.16);
  --display: "Fraunces", Georgia, serif;
  --sans: "Manrope", Inter, ui-sans-serif, system-ui, sans-serif;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 10% -4%, rgba(211, 175, 99, 0.18), transparent 34%),
    radial-gradient(circle at 92% 0%, rgba(36, 78, 92, 0.12), transparent 32%),
    linear-gradient(180deg, rgba(251,247,236,0.99), rgba(244,239,226,0.95));
  font-family: var(--sans);
  font-size: 12px;
  line-height: 1.55;
  overflow-x: hidden;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
}

.ml-shell {
  width: 100%;
  min-height: 100vh;
  padding-bottom: 18px;
}

.ml-topbar {
  position: sticky;
  top: 0;
  z-index: 80;
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: rgba(251, 247, 236, 0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(18px);
  box-shadow: 0 10px 26px rgba(21, 32, 51, 0.06);
}

.ml-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.ml-dot {
  width: 12px;
  height: 12px;
  flex: 0 0 auto;
  border-radius: 999px;
  background: var(--coast);
  box-shadow: 0 0 0 7px rgba(36, 78, 92, 0.10);
}

.ml-brand strong {
  display: block;
  color: var(--ink);
  font-family: var(--display);
  font-size: 19px;
  line-height: 1;
  font-weight: 650;
  letter-spacing: -0.04em;
}

.ml-brand span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 9px;
  font-weight: 900;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ml-tabs {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.tab-btn,
.filter-btn {
  min-height: 34px;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(251, 247, 236, 0.88);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: transform .18s ease, background .18s ease, color .18s ease, border-color .18s ease;
}

.tab-btn:hover,
.filter-btn:hover {
  transform: translateY(-1px);
  color: var(--coast);
  border-color: rgba(36, 78, 92, 0.25);
}

.tab-btn.active,
.filter-btn.active {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--paper);
  box-shadow: 0 12px 26px rgba(21, 32, 51, 0.18);
}

.command-strip {
  display: grid;
  grid-template-columns: 1.25fr repeat(3, minmax(110px, 0.85fr));
  gap: 10px;
  padding: 14px 16px 0;
}

.strip-card,
.overview-card {
  position: relative;
  overflow: hidden;
  padding: 13px 14px;
  min-height: 86px;
  border-radius: 21px;
  background:
    radial-gradient(circle at 100% 0%, rgba(211,175,99,0.13), transparent 38%),
    rgba(251, 247, 236, 0.88);
  border: 1px solid var(--line);
  box-shadow: 0 10px 26px rgba(21,32,51,0.07);
}

.strip-card::after {
  content: "";
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 0;
  height: 3px;
  border-radius: 999px 999px 0 0;
  background: linear-gradient(90deg, var(--coast), var(--risk), var(--gold));
  opacity: .55;
}

.strip-card.focus {
  background:
    radial-gradient(circle at 100% 0%, rgba(184,104,80,0.18), transparent 42%),
    rgba(251,247,236,.9);
}

.strip-card span,
.overview-card span,
.eyebrow {
  display: block;
  color: var(--muted);
  font-size: 8.5px;
  font-weight: 900;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.strip-card strong {
  display: block;
  margin-top: 6px;
  color: var(--coast);
  font-size: 29px;
  line-height: 0.95;
  letter-spacing: -0.05em;
  font-weight: 900;
}

.strip-card.big strong {
  font-family: var(--display);
  font-size: 25px;
  font-weight: 650;
  color: var(--ink);
}

.strip-card.big b {
  color: var(--coast);
  font-family: var(--sans);
  font-size: 31px;
  font-weight: 900;
}

.strip-card small {
  display: block;
  margin-top: 7px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 760;
}

.ml-content {
  padding: 12px 16px 16px;
}

.tab-page {
  display: none;
}

.tab-page.active {
  display: block;
  animation: enter .26s cubic-bezier(.22,1,.36,1) both;
}

@keyframes enter {
  from { opacity: 0; transform: translateY(7px); }
  to { opacity: 1; transform: translateY(0); }
}

.section-head {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) auto;
  align-items: end;
  gap: 14px;
  margin: 3px 0 10px;
}

.section-head h2 {
  margin: 3px 0 0;
  color: var(--ink);
  font-family: var(--display);
  font-size: clamp(24px, 3vw, 41px);
  line-height: .98;
  letter-spacing: -0.06em;
  font-weight: 650;
}

.filter-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 7px;
  justify-content: flex-end;
}

.control-panel,
.search-panel {
  display: grid;
  align-items: end;
  gap: 8px;
  padding: 10px;
  border-radius: 20px;
  background: rgba(251,247,236,.74);
  border: 1px solid var(--line);
  box-shadow: 0 10px 22px rgba(21,32,51,.06);
}

.control-panel {
  grid-template-columns: minmax(180px, 250px) minmax(160px, 230px);
}

.search-panel {
  grid-template-columns: auto minmax(190px, 300px) auto;
}

.control-panel label {
  display: grid;
  gap: 5px;
}

.control-panel span,
.search-panel label {
  color: var(--muted);
  font-size: 8.5px;
  font-weight: 900;
  letter-spacing: .16em;
  text-transform: uppercase;
}

select,
input {
  width: 100%;
  min-height: 38px;
  padding: 9px 12px;
  border-radius: 16px;
  background: rgba(251,247,236,.96);
  border: 1px solid var(--line);
  color: var(--ink);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.45);
  outline: none;
}

select:focus,
input:focus {
  border-color: rgba(36,78,92,.34);
  box-shadow: 0 0 0 3px rgba(36,78,92,.08);
}

.count-pill,
.guardrail-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 7px 11px;
  border-radius: 999px;
  background: rgba(36,78,92,.08);
  color: var(--coast);
  font-size: 10px;
  font-weight: 900;
  white-space: nowrap;
}

.insight-grid,
.timeline-snapshot,
.anomaly-summary {
  display: grid;
  gap: 9px;
  margin-bottom: 10px;
}

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

.timeline-snapshot {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

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

.insight-card,
.snapshot-card,
.anom-summary-card {
  min-height: 78px;
  padding: 13px;
  border-radius: 20px;
  background: rgba(251,247,236,.86);
  border: 1px solid var(--line);
  box-shadow: 0 9px 22px rgba(21,32,51,.06);
}

.insight-card b,
.snapshot-card b,
.anom-summary-card b {
  display: block;
  color: var(--muted);
  font-size: 8.5px;
  font-weight: 900;
  letter-spacing: .14em;
  text-transform: uppercase;
}

.insight-card strong,
.snapshot-card strong,
.anom-summary-card strong {
  display: block;
  margin-top: 6px;
  color: var(--coast);
  font-size: 24px;
  line-height: 1;
  letter-spacing: -.05em;
}

.insight-card span,
.snapshot-card span,
.anom-summary-card span {
  display: block;
  margin-top: 6px;
  color: var(--ink-soft);
  font-size: 10px;
  font-weight: 760;
}

.dashboard-grid {
  display: grid;
  gap: 12px;
}

.scoreboard-layout {
  grid-template-columns: minmax(310px, .95fr) minmax(360px, 1.05fr);
}

.timeline-layout {
  grid-template-columns: minmax(480px, 1.35fr) minmax(220px, .65fr);
}

.anomaly-layout {
  grid-template-columns: minmax(340px, .92fr) minmax(360px, 1.08fr);
}

.model-layout {
  grid-template-columns: minmax(420px, 1.2fr) minmax(260px, .8fr);
  margin-top: 12px;
}

.panel,
.metric-card,
.detail-card {
  position: relative;
  overflow: hidden;
  border-radius: 23px;
  background:
    radial-gradient(circle at 100% 0%, rgba(211,175,99,.09), transparent 36%),
    rgba(251,247,236,.90);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.panel {
  padding: 14px;
}

.panel-head {
  display: grid;
  gap: 4px;
  margin-bottom: 11px;
}

.panel-head span {
  color: var(--muted);
  font-size: 8.5px;
  font-weight: 900;
  letter-spacing: .16em;
  text-transform: uppercase;
}

.panel-head strong {
  color: var(--ink);
  font-size: 13px;
  line-height: 1.2;
  letter-spacing: -.02em;
}

.chart-box {
  position: relative;
  width: 100%;
  min-height: 270px;
  height: 36vh;
  max-height: 420px;
}

.chart-box.ranking {
  min-height: 330px;
  height: 43vh;
  max-height: 500px;
}

.timeline-chart {
  min-height: 360px;
  height: 48vh;
  max-height: 560px;
}

.anomaly-chart,
.feature-chart {
  min-height: 320px;
  height: 43vh;
  max-height: 520px;
}

.scoreboard-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
  max-height: min(53vh, 560px);
  overflow: auto;
  padding-right: 4px;
}

.score-card {
  padding: 12px;
  border-radius: 18px;
  background: rgba(244,239,226,.76);
  border: 1px solid rgba(21,32,51,.08);
  transition: transform .18s ease, background .18s ease, border-color .18s ease;
}

.score-card:hover {
  transform: translateY(-2px);
  background: rgba(251,247,236,.98);
  border-color: rgba(36,78,92,.22);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 8px;
}

.card-country {
  color: var(--ink);
  font-size: 12px;
  font-weight: 900;
  line-height: 1.1;
}

.card-code {
  margin-top: 3px;
  color: var(--muted);
  font-size: 9px;
  font-weight: 850;
  letter-spacing: .07em;
  text-transform: uppercase;
}

.label-badge {
  flex: 0 0 auto;
  padding: 5px 7px;
  border-radius: 999px;
  font-size: 8px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: .07em;
}

.label-badge.at_risk { color: var(--risk); background: rgba(184,104,80,.12); }
.label-badge.critical { color: var(--critical); background: rgba(143,75,66,.13); }
.label-badge.resilient { color: var(--green); background: rgba(91,117,98,.14); }

.cvi-bar-wrap {
  margin: 11px 0 7px;
}

.cvi-bar-track {
  height: 8px;
  border-radius: 999px;
  background: rgba(21,32,51,.07);
  overflow: hidden;
}

.cvi-bar-fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--coast), var(--gold), var(--risk));
}

.cvi-value {
  color: var(--coast);
  font-size: 22px;
  line-height: 1;
  font-weight: 900;
  letter-spacing: -.05em;
}

.card-meta {
  display: flex;
  justify-content: space-between;
  gap: 7px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 9px;
  font-weight: 780;
}

.detail-stack {
  display: grid;
  align-content: start;
  gap: 9px;
}

.detail-card {
  padding: 13px;
}

.detail-label {
  color: var(--muted);
  font-size: 8.5px;
  font-weight: 900;
  letter-spacing: .15em;
  text-transform: uppercase;
}

.detail-value {
  margin-top: 5px;
  color: var(--coast);
  font-size: 24px;
  line-height: 1;
  letter-spacing: -.05em;
  font-weight: 900;
}

.detail-value.risk { color: var(--risk); }
.detail-value.good { color: var(--green); }

.anomaly-list {
  display: grid;
  gap: 8px;
  max-height: min(54vh, 560px);
  overflow: auto;
  padding-right: 4px;
}

.anom-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  padding: 10px;
  border-radius: 17px;
  background: rgba(244,239,226,.76);
  border: 1px solid rgba(21,32,51,.08);
}

.anom-country {
  color: var(--ink);
  font-weight: 900;
  font-size: 12px;
}

.anom-year {
  margin-top: 4px;
  color: var(--ink-soft);
  font-size: 10px;
  line-height: 1.35;
}

.anom-right {
  display: grid;
  justify-items: end;
  align-content: center;
  gap: 5px;
}

.anom-tags {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  justify-content: end;
}

.anom-tag {
  padding: 4px 6px;
  border-radius: 999px;
  font-size: 8px;
  font-weight: 900;
  color: var(--paper);
  background: var(--coast);
}

.anom-tag.lof { background: var(--risk); }
.anom-tag.zsc { background: var(--gold); color: var(--ink); }

.anom-zscore {
  color: var(--muted);
  font-size: 9px;
  font-weight: 850;
}

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

.metric-card {
  padding: 15px;
}

.mc-title {
  color: var(--muted);
  font-size: 8.5px;
  font-weight: 900;
  letter-spacing: .15em;
  text-transform: uppercase;
}

.mc-model {
  margin: 5px 0 10px;
  color: var(--ink);
  font-family: var(--display);
  font-size: 21px;
  line-height: 1;
  letter-spacing: -.045em;
}

.metric-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 0;
  border-top: 1px solid rgba(21,32,51,.08);
}

.mr-key {
  color: var(--muted);
  font-size: 10px;
  font-weight: 850;
}

.mr-val {
  color: var(--coast);
  font-size: 10px;
  font-weight: 900;
}

.mr-val.good { color: var(--green); }
.mr-val.warn { color: var(--risk); }
.mr-val.bad { color: var(--critical); }

.model-note-panel {
  padding: 16px;
}

.model-rules {
  display: grid;
  gap: 10px;
}

.model-rules div {
  padding: 12px;
  border-radius: 17px;
  background: rgba(244,239,226,.72);
  border: 1px solid rgba(21,32,51,.08);
}

.model-rules b {
  display: block;
  color: var(--ink);
  font-size: 12px;
  margin-bottom: 4px;
}

.model-rules span {
  color: var(--ink-soft);
  font-size: 11px;
  line-height: 1.45;
}

::-webkit-scrollbar {
  width: 9px;
  height: 9px;
}

::-webkit-scrollbar-track {
  background: rgba(21,32,51,.045);
  border-radius: 999px;
}

::-webkit-scrollbar-thumb {
  background: rgba(36,78,92,.28);
  border: 2px solid rgba(251,247,236,.80);
  border-radius: 999px;
}

@media (max-width: 980px) {
  .ml-topbar,
  .section-head,
  .timeline-head,
  .anomaly-head {
    grid-template-columns: 1fr;
    align-items: start;
  }

  .ml-tabs,
  .filter-row {
    justify-content: start;
  }

  .command-strip,
  .insight-grid,
  .timeline-snapshot,
  .anomaly-summary,
  .model-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .scoreboard-layout,
  .timeline-layout,
  .anomaly-layout,
  .model-layout {
    grid-template-columns: 1fr;
  }

  .control-panel {
    grid-template-columns: 1fr;
  }

  .search-panel {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .command-strip,
  .insight-grid,
  .timeline-snapshot,
  .anomaly-summary,
  .model-grid,
  .scoreboard-grid {
    grid-template-columns: 1fr;
  }

  .ml-tabs {
    overflow-x: auto;
    flex-wrap: nowrap;
    justify-content: flex-start;
    padding-bottom: 3px;
  }

  .tab-btn {
    flex: 0 0 auto;
  }

  .chart-box,
  .timeline-chart,
  .anomaly-chart,
  .feature-chart {
    min-height: 280px;
    height: 360px;
  }
}
