:root {
  color-scheme: light;
  --bg: #f5f7f9;
  --surface: #ffffff;
  --surface-muted: #eef3f5;
  --ink: #15212d;
  --muted: #687582;
  --line: #dce4ea;
  --blue: #246bce;
  --teal: #15847f;
  --green: #3d8b4f;
  --amber: #b87514;
  --red: #c84f49;
  --nav: #122131;
  --nav-soft: #1c3146;
  --shadow: 0 14px 36px rgba(23, 35, 48, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  letter-spacing: 0;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.login-screen {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(135deg, rgba(18, 33, 49, 0.92), rgba(21, 132, 127, 0.78)),
    var(--bg);
}

.login-card {
  width: min(420px, 100%);
  padding: 28px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 26px 70px rgba(3, 14, 25, 0.28);
}

.login-card h1 {
  margin: 22px 0 18px;
}

.login-card .primary-button {
  width: 100%;
  margin-top: 6px;
}

.login-brand span {
  color: var(--muted);
}

.login-error {
  min-height: 20px;
  margin: 12px 0 0;
  color: #b42318;
  font-size: 13px;
  font-weight: 700;
}

.shell {
  display: grid;
  grid-template-columns: 264px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 22px 18px;
  background: var(--nav);
  color: #f7fbff;
}

.brand,
.user-card {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 8px;
  background: var(--teal);
  font-weight: 800;
}

.brand strong,
.user-card strong {
  display: block;
  font-size: 15px;
}

.brand span,
.user-card span {
  display: block;
  margin-top: 3px;
  color: #a7b8c9;
  font-size: 12px;
}

.user-card > div {
  flex: 1;
  min-width: 0;
}

.user-card select {
  width: 100%;
  min-height: 32px;
  margin-top: 10px;
  border-color: rgba(255, 255, 255, 0.16);
  background: #0f2436;
  color: #ffffff;
  font-size: 12px;
}

.logout-button {
  width: 100%;
  min-height: 32px;
  margin-top: 10px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  background: #0f2436;
  color: #ffffff;
  font-size: 12px;
  font-weight: 700;
}

.logout-button:hover {
  background: #16324b;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(9, 20, 32, 0.48);
}

.modal-card {
  width: min(460px, 100%);
  display: grid;
  gap: 14px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 24px 70px rgba(3, 14, 25, 0.26);
}

.modal-card .panel-head {
  margin-bottom: 2px;
}

.modal-card .icon-button {
  width: 36px;
  min-height: 36px;
  font-size: 22px;
}

.nav {
  display: grid;
  gap: 8px;
}

.nav-item {
  width: 100%;
  min-height: 42px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: #c9d5df;
  text-align: left;
}

.nav-item:hover,
.nav-item.active {
  background: var(--nav-soft);
  color: #ffffff;
  border-color: rgba(255, 255, 255, 0.08);
}

.user-card {
  margin-top: auto;
  padding: 14px;
  border-radius: 8px;
  background: var(--nav-soft);
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 99px;
  background: #54c06a;
}

.content {
  min-width: 0;
  padding: 26px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 22px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 30px;
  line-height: 1.15;
}

h2 {
  font-size: 17px;
}

.topbar p,
.section-title p {
  margin-top: 6px;
  color: var(--muted);
}

.top-actions,
.filter-actions,
.admin-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.filter-note {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.dataset-note {
  margin: -4px 0 2px;
  padding: 10px 12px;
  border-radius: 8px;
  background: #eef5f7;
  color: #435362;
  font-size: 13px;
  line-height: 1.45;
}

.icon-button,
.primary-button,
.secondary-button,
.text-button {
  min-height: 40px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
}

.hidden {
  display: none !important;
}

.icon-button {
  width: 42px;
  font-size: 20px;
}

.primary-button,
.secondary-button {
  padding: 0 16px;
  font-weight: 700;
}

.text-button {
  min-height: 32px;
  padding: 0 10px;
  border-color: transparent;
  background: transparent;
  color: var(--blue);
  font-size: 13px;
  font-weight: 800;
}

.primary-button {
  border-color: var(--blue);
  background: var(--blue);
  color: #ffffff;
}

.secondary-button:hover,
.icon-button:hover {
  background: var(--surface-muted);
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.filters {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.filters.compact {
  grid-template-columns: repeat(3, minmax(170px, 1fr));
}

#dashboard > .filters.compact {
  position: sticky;
  top: 0;
  z-index: 20;
  box-shadow: 0 10px 24px rgba(23, 35, 48, 0.08);
}

label,
.field {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

select,
input,
textarea {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  padding: 0 11px;
}

textarea {
  min-height: 116px;
  padding: 12px;
  resize: vertical;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.metric-card,
.panel,
.table-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.metric-card {
  padding: 18px;
  min-width: 0;
}

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

.metric-card strong {
  display: block;
  margin: 10px 0 5px;
  font-size: 30px;
  line-height: 1;
}

.metric-card {
  border-top: 4px solid transparent;
}

.metric-card.risk-seasonal {
  border-top-color: #4f9b45;
}

.metric-card.risk-active {
  border-top-color: #e4ef2f;
}

.metric-card.risk-sporadic {
  border-top-color: #f28a1a;
}

.metric-card.risk-outbreak {
  border-top-color: #ed3b30;
}

.metric-card.risk-epidemic {
  border-top-color: #9a2fd2;
}

.metric-card.risk-empty {
  border-top-color: #cbd5e1;
}

.metric-card.risk-seasonal strong {
  color: #34752e;
}

.metric-card.risk-active strong {
  color: #737c10;
}

.metric-card.risk-sporadic strong {
  color: #a75e10;
}

.metric-card.risk-outbreak strong {
  color: #b72d26;
}

.metric-card.risk-epidemic strong {
  color: #7a22ad;
}

.metric-card.risk-empty strong {
  color: #64748b;
}

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

.workspace {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  gap: 18px;
}

.workspace .filters {
  grid-template-columns: 1fr;
  align-self: start;
}

.choice-panel {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
}

.choice-panel legend {
  padding: 0 4px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.toggle-line,
.checkbox-grid label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 650;
}

.toggle-line input,
.checkbox-grid input {
  width: 16px;
  min-height: 16px;
  margin: 0;
}

.checkbox-grid {
  display: grid;
  gap: 8px;
  max-height: 190px;
  overflow: auto;
  padding-right: 4px;
}

.panel,
.table-panel {
  padding: 18px;
}

.wide {
  grid-column: 1 / -1;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.panel-head span {
  color: var(--muted);
  font-size: 13px;
}

canvas {
  display: block;
  width: min(100%, 760px);
  height: auto;
  margin: 0 auto;
  border-radius: 8px;
  background: #ffffff;
}

#trendChart {
  width: min(100%, 760px);
}

#virologyTrendChart {
  width: 100%;
  max-width: none;
  height: clamp(360px, 32vw, 540px);
}

.map-card {
  display: grid;
  gap: 12px;
}

.mini-map {
  position: relative;
  min-height: 360px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7fafc;
}

.map-region {
  position: absolute;
  display: grid;
  place-items: center;
  width: var(--w);
  height: var(--h);
  left: var(--x);
  top: var(--y);
  border: 1px solid rgba(120, 30, 24, 0.35);
  color: #111111;
  font-size: 11px;
  font-weight: 800;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.7);
  clip-path: polygon(13% 20%, 50% 6%, 88% 20%, 96% 57%, 75% 88%, 28% 94%, 4% 61%);
}

.mongolia-map {
  display: block;
  width: 100%;
  height: 360px;
}

.mongolia-map path {
  stroke: rgba(95, 106, 116, 0.65);
  stroke-width: 0.8;
  vector-effect: non-scaling-stroke;
}

.mongolia-map text {
  fill: #111111;
  font-size: 14px;
  font-weight: 800;
  paint-order: stroke;
  stroke: rgba(255, 255, 255, 0.9);
  stroke-width: 3px;
  stroke-linejoin: round;
}

.map-region small {
  display: block;
  margin-top: 2px;
  font-size: 9px;
  font-weight: 700;
}

.map-c0 {
  background: #f5f5f5;
}

.map-c1 {
  background: #f7b8b8;
}

.map-c2 {
  background: #fb6e6e;
}

.map-c3 {
  background: #cf2414;
}

.mongolia-map .map-c0 {
  fill: #f5f5f5;
}

.mongolia-map .map-c1 {
  fill: #f7b8b8;
}

.mongolia-map .map-c2 {
  fill: #fb6e6e;
}

.mongolia-map .map-c3 {
  fill: #cf2414;
}

.pisa-heatmap-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.pisa-heatmap {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
  font-size: 13px;
  background: #ffffff;
}

.pisa-heatmap th,
.pisa-heatmap td {
  height: 24px;
  border: 1px solid #d7dee6;
}

.pisa-heatmap thead th {
  color: #0b2f65;
  font-weight: 800;
  text-align: center;
  background: #ffffff;
}

.pisa-heatmap tbody th {
  width: 150px;
  padding: 0 8px;
  color: #172331;
  font-weight: 650;
  text-align: left;
  white-space: nowrap;
  background: #ffffff;
}

.pisa-heatmap td {
  min-width: 28px;
}

.pisa-seasonal,
.mongolia-map .pisa-seasonal {
  fill: #8bd24f;
  background: #8bd24f;
}

.pisa-active,
.mongolia-map .pisa-active {
  fill: #ffff00;
  background: #ffff00;
}

.pisa-sporadic,
.mongolia-map .pisa-sporadic {
  fill: #ffc000;
  background: #ffc000;
}

.pisa-outbreak,
.mongolia-map .pisa-outbreak {
  fill: #ff0000;
  background: #ff0000;
}

.pisa-epidemic,
.mongolia-map .pisa-epidemic {
  fill: #7030a0;
  background: #7030a0;
}

.pisa-empty,
.mongolia-map .pisa-empty {
  fill: #d9d9d9;
  background: #d9d9d9;
}

.pisa-legend,
.virus-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  margin-top: 12px;
  color: #2e3a45;
  font-size: 12px;
}

.virus-legend:empty {
  display: none;
}

#whoSpecimensLegend {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px 12px;
  margin-top: 8px;
}

.pisa-legend.compact {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.pisa-legend span,
.virus-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.pisa-legend i,
.virus-legend i {
  width: 12px;
  height: 12px;
  border: 1px solid #9aa5b1;
}

.virus-map .mongolia-map path.virus-base {
  fill: #ffffff;
}

.virus-pie circle {
  fill: #ffffff;
  stroke: #ffffff;
  stroke-width: 3;
}

.virus-pie .virus-slice {
  stroke: #ffffff;
  stroke-width: 1.2;
  vector-effect: non-scaling-stroke;
}

.map-legend {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  font-size: 12px;
}

.map-legend span {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 24px;
}

.map-legend i {
  width: 14px;
  height: 14px;
  border: 1px solid #aab3bd;
}

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

.mapping-grid div {
  min-height: 66px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
}

.mapping-grid strong {
  display: block;
  margin-bottom: 5px;
}

.mapping-grid span {
  color: var(--muted);
  font-size: 13px;
}

.admin-summary {
  display: grid;
  gap: 6px;
  margin-bottom: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
}

.admin-summary strong {
  font-size: 18px;
}

.admin-summary span {
  color: var(--muted);
  line-height: 1.45;
}

.admin-list {
  display: grid;
  gap: 8px;
}

.admin-list.compact {
  max-height: 250px;
  overflow: auto;
  padding-right: 4px;
}

.admin-list .empty-note {
  color: var(--muted);
  font-size: 14px;
}

.admin-list-item {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
}

.admin-list-item strong {
  color: var(--ink);
}

.admin-list-item span {
  color: var(--muted);
  font-size: 13px;
  text-align: right;
}

.admin-create-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px 18px;
}

.admin-create-grid .field {
  margin-bottom: 0;
}

.wide-field {
  grid-column: 1 / -1;
}

.admin-filter-options {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  max-height: none;
}

.admin-status {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.user-form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px 18px;
}

.user-form-grid .field {
  margin-bottom: 0;
}

.row-actions {
  display: flex;
  gap: 8px;
}

.small-button {
  min-height: 32px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
}

.small-button:hover {
  background: var(--surface-muted);
}

.danger-button {
  color: #b42318;
}

.age-chart-stack {
  display: grid;
  gap: 14px;
}

.age-legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px 16px;
  color: #2e3a45;
  font-size: 12px;
}

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

.age-legend i {
  width: 10px;
  height: 10px;
  border-radius: 2px;
}

.section-title {
  margin-bottom: 18px;
}

.timeline-title {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.timeline-panel {
  display: grid;
  gap: 16px;
}

.timeline-toolbar {
  display: grid;
  grid-template-columns: 1.4fr 140px 1fr auto;
  gap: 14px;
  align-items: end;
}

.range-field {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.range-field input {
  width: 100%;
  min-height: 24px;
  padding: 0;
}

.timeline-actions {
  display: flex;
  gap: 8px;
}

.timeline-map-wrap {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7fafc;
}

.timeline-map {
  position: relative;
  min-height: 520px;
  overflow: hidden;
}

.timeline-map .mongolia-map {
  height: 520px;
}

.timeline-legend {
  max-width: 720px;
}

.map-drilldown {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 14px;
  box-shadow: none;
}

.map-drilldown span {
  color: var(--muted);
  font-size: 13px;
}

.map-empty {
  display: grid;
  min-height: 240px;
  place-items: center;
  color: var(--muted);
  font-size: 14px;
  text-align: center;
}

.table-wrap {
  overflow: auto;
  max-height: 570px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  background: #ffffff;
}

th,
td {
  padding: 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  background: #edf3f7;
  color: #4c5966;
  font-size: 12px;
}

tr:hover td {
  background: #fbfcfd;
}

.pisa-heatmap tr:hover td.pisa-seasonal,
.pisa-heatmap td.pisa-seasonal:hover {
  background: #8bd24f;
}

.pisa-heatmap tr:hover td.pisa-active,
.pisa-heatmap td.pisa-active:hover {
  background: #ffff00;
}

.pisa-heatmap tr:hover td.pisa-sporadic,
.pisa-heatmap td.pisa-sporadic:hover {
  background: #ffc000;
}

.pisa-heatmap tr:hover td.pisa-outbreak,
.pisa-heatmap td.pisa-outbreak:hover {
  background: #ff0000;
}

.pisa-heatmap tr:hover td.pisa-epidemic,
.pisa-heatmap td.pisa-epidemic:hover {
  background: #7030a0;
}

.pisa-heatmap tr:hover td.pisa-empty,
.pisa-heatmap td.pisa-empty:hover {
  background: #d9d9d9;
}

.pisa-heatmap tbody td:hover {
  position: relative;
  outline: 3px solid #111827;
  outline-offset: -3px;
  filter: saturate(1.3);
}

.mongolia-map path[class^="pisa-"]:hover {
  stroke: #111827;
  stroke-width: 2.2;
  filter: saturate(1.25);
}

.source-note {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.sql-panel textarea {
  min-height: 230px;
  font-family: Consolas, "Courier New", monospace;
  line-height: 1.5;
}

.field {
  margin-bottom: 14px;
}

.check-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.check-row label {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--ink);
}

.check-row input {
  width: 16px;
  min-height: 16px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 10px;
  border-radius: 99px;
  background: #e9eef3;
  color: #465461;
  font-size: 12px;
  font-weight: 700;
}

.pill.ok,
.pill.published {
  background: #e6f3ea;
  color: #28633c;
}

.pill.bad {
  background: #f8e7e5;
  color: #9e3934;
}

@media (max-width: 1080px) {
  .shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
  }

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

  .metrics,
  .dashboard-grid,
  .admin-grid,
  .admin-create-grid,
  .user-form-grid,
  .workspace,
  .timeline-toolbar {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .content {
    padding: 18px;
  }

  .topbar {
    display: grid;
  }

  .nav,
  .filters,
  .filters.compact,
  .mapping-grid {
    grid-template-columns: 1fr;
  }

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

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

  h1 {
    font-size: 24px;
  }
}

@media (max-width: 460px) {
  .metrics {
    grid-template-columns: 1fr;
  }
}
