:root {
  --bg: #f4f7fb;
  --panel: #ffffff;
  --text: #0f172a;
  --muted: #475569;
  --line: #dbe4f0;
  --line-strong: #c7d5e6;
  --primary: #1d4ed8;
  --primary-soft: rgba(29, 78, 216, 0.1);
  --accent: #d97706;
  --danger: #b91c1c;
  --success: #15803d;
  --shadow: 0 18px 40px rgba(15, 23, 42, 0.08);
  --radius: 18px;
  --blue-opor: #2563eb;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
body { min-height: 100vh; }
button, select, input { font: inherit; }
button {
  border: 1px solid transparent;
  background: var(--primary);
  color: #fff;
  border-radius: 12px;
  padding: 0.72rem 1rem;
  cursor: pointer;
  transition: transform 0.16s ease, box-shadow 0.16s ease, background 0.16s ease, border-color 0.16s ease;
}
button:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 22px rgba(29, 78, 216, 0.18);
}
button.ghost {
  background: #fff;
  color: var(--text);
  border-color: var(--line);
  box-shadow: none;
}
button.ghost:hover {
  background: #f8fafc;
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.08);
}
button.active,
.segmented-control button.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
select,
input[type="number"] {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 12px;
  padding: 0.72rem 0.8rem;
  min-height: 46px;
}

.page-header {
  padding: 1.6rem clamp(1rem, 2vw, 2rem) 1rem;
  display: flex;
  gap: 1rem;
  align-items: flex-start;
  justify-content: space-between;
}
.page-header h1 {
  margin: 0;
  font-size: clamp(1.55rem, 2.1vw, 2.3rem);
  line-height: 1.12;
}
.subtitle {
  margin: 0.55rem 0 0;
  max-width: 1100px;
  color: var(--muted);
}
.header-actions {
  display: flex;
  gap: 0.7rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.language-toggle {
  min-width: 3.15rem;
  padding-inline: 0.75rem;
  font-weight: 700;
  letter-spacing: 0;
}

.layout {
  padding: 0 1rem 1.25rem;
  display: grid;
  gap: 1rem;
}
.panel,
.kpi-card {
  background: var(--panel);
  border: 1px solid rgba(148, 163, 184, 0.22);
  box-shadow: var(--shadow);
  border-radius: var(--radius);
}
.panel { padding: 1rem 1rem 1.1rem; }
.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.8rem;
  margin-bottom: 0.9rem;
}
.panel-header.compact { margin-bottom: 0.6rem; }
.panel-header h2 { margin: 0; font-size: 1.05rem; }
.panel-header p { margin: 0.3rem 0 0; color: var(--muted); line-height: 1.45; }
.panel-actions {
  display: flex;
  gap: 0.55rem;
  flex-wrap: wrap;
  align-items: center;
}
.panel-actions .compare-group {
  margin-right: 0.35rem;
}

.timeline-panel {
  padding: 1rem 1.1rem 1.15rem;
}
.timeline-readout {
  display: grid;
  grid-template-columns: repeat(3, minmax(160px, 1fr));
  gap: 0.75rem;
  margin-bottom: 0.9rem;
}
.timeline-chip {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 0.82rem 0.95rem;
  background: linear-gradient(180deg, #f8fbff 0%, #ffffff 100%);
}
.timeline-chip .label {
  color: var(--muted);
  font-size: 0.86rem;
}
.timeline-chip .value {
  margin-top: 0.28rem;
  font-weight: 700;
  font-size: 1.16rem;
}
.timeline-slider-wrap {
  padding: 0.4rem 0.15rem 0;
}
.slider-endpoints {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.84rem;
  margin-top: 0.45rem;
}

.controls-grid {
  display: grid;
  grid-template-columns: 1.2fr minmax(220px, 1fr) minmax(220px, 1fr);
  gap: 0.9rem;
  align-items: start;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 0.42rem;
}
.field span,
.inline-label,
.local-slider-label {
  color: var(--muted);
  font-size: 0.92rem;
}
.field.wide { grid-column: span 1; }
.segmented-control {
  display: inline-flex;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  background: #fff;
}
.segmented-control button {
  flex: 1 1 0;
  border: none;
  border-radius: 0;
  background: transparent;
  color: var(--text);
  padding: 0.8rem 0.9rem;
  box-shadow: none;
}
.segmented-control button + button {
  border-left: 1px solid var(--line);
}
.segmented-control button:hover {
  transform: none;
  box-shadow: none;
  background: #f8fafc;
}
.segmented-control button.active:hover {
  background: var(--primary);
}
.controls-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  margin-top: 0.95rem;
}

.toggle,
.compare-option {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--muted);
}
.toggle input,
.compare-option input {
  accent-color: var(--primary);
}
.compare-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.8rem;
  padding: 0.62rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #f8fafc;
}
.compare-group .compare-title {
  color: var(--muted);
  font-size: 0.86rem;
  margin-right: 0.15rem;
}

.error-banner {
  margin-top: 0.9rem;
  border-radius: 14px;
  padding: 0.9rem 1rem;
  background: rgba(185, 28, 28, 0.08);
  color: var(--danger);
  border: 1px solid rgba(185, 28, 28, 0.16);
}
.hidden { display: none !important; }

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(180px, 1fr));
  gap: 1rem;
}
.kpi-card { padding: 1rem 1.05rem; }
.kpi-label { color: var(--muted); font-size: 0.92rem; }
.kpi-value {
  margin-top: 0.45rem;
  font-size: clamp(1.35rem, 2vw, 2rem);
  font-weight: 700;
  letter-spacing: -0.02em;
}
.kpi-note { margin-top: 0.3rem; color: var(--muted); }

.grid-two {
  display: grid;
  grid-template-columns: minmax(0, 1.7fr) minmax(320px, 1fr);
  gap: 1rem;
}
.grid-two.equal-height > .panel { min-height: 500px; }
.side-panel { max-height: 940px; overflow: hidden; }
.map-panel { min-height: 770px; }
#map {
  width: 100%;
  height: 600px;
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid var(--line);
}
.chart { width: 100%; min-height: 390px; }

.local-controls-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(300px, 0.9fr);
  gap: 0.85rem;
  align-items: stretch;
  margin-bottom: 0.95rem;
}
.local-slider-card,
.local-side-card,
.legend-block {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fbfdff;
  padding: 0.85rem 0.95rem;
}
.local-slider-head,
.legend-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.5rem;
  margin-bottom: 0.6rem;
}
.local-slider-value {
  font-weight: 700;
  font-size: 1.1rem;
}
.local-side-stack {
  display: grid;
  gap: 0.85rem;
}
.mini-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(110px, 1fr));
  gap: 0.7rem;
}
.mini-field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.mini-field label {
  color: var(--muted);
  font-size: 0.86rem;
}
.mini-field input[type="number"] {
  min-height: 42px;
  padding: 0.58rem 0.72rem;
}
.local-note {
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.45;
}

.legend-row {
  display: grid;
  grid-template-columns: minmax(220px, 1.1fr) minmax(220px, 1fr) minmax(220px, 1fr);
  gap: 0.85rem;
  align-items: start;
  margin-bottom: 0.95rem;
}
.legend-title {
  color: var(--muted);
  font-size: 0.9rem;
}
.legend-scale {
  display: inline-block;
  width: 100%;
  height: 14px;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.28);
  margin-top: 0.55rem;
}
.gradient-traffic {
  background: linear-gradient(90deg, #dc2626 0%, #facc15 50%, #16a34a 100%);
}
.legend-labels {
  width: 100%;
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.84rem;
  margin-top: 0.42rem;
  gap: 0.45rem;
}
.legend-labels.three span:nth-child(2) {
  text-align: center;
  flex: 1 1 auto;
}
.legend-labels.three span:first-child,
.legend-labels.three span:last-child {
  min-width: 72px;
}

.size-legend-grid,
.central-type-legend {
  display: grid;
  gap: 0.45rem;
  margin-top: 0.6rem;
}
.size-legend-item,
.central-legend-item {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  color: #1e293b;
  font-size: 0.88rem;
}
.size-legend-bubble {
  display: inline-flex;
  flex: 0 0 auto;
  border-radius: 999px;
  border: 2px solid rgba(30, 41, 59, 0.22);
  background: rgba(100, 116, 139, 0.14);
}
.central-outline-demo {
  width: 18px;
  height: 18px;
  border-radius: 999px;
  border: 3px solid var(--blue-opor);
  background: rgba(37, 99, 235, 0.06);
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  color: var(--blue-opor);
  font-weight: 700;
}
.legend-emphasis {
  color: #1e293b;
}
.legend-subnote {
  margin-top: 0.48rem;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.45;
}

.selection-summary {
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #f8fbff 0%, #ffffff 100%);
  border-radius: 16px;
  padding: 1rem;
  margin-bottom: 0.9rem;
}
.selection-summary.empty-state { color: var(--muted); }
.selection-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(120px, 1fr));
  gap: 0.75rem;
  margin-top: 0.9rem;
}
.summary-kpi {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.75rem;
}
.summary-kpi .label { color: var(--muted); font-size: 0.85rem; }
.summary-kpi .value { margin-top: 0.2rem; font-weight: 700; font-size: 1.05rem; }
.meta-table {
  overflow: auto;
  max-height: 560px;
  border-radius: 16px;
  border: 1px solid var(--line);
}
.meta-table table,
.top-table table { width: 100%; border-collapse: collapse; }
.meta-table th,
.meta-table td,
.top-table th,
.top-table td {
  padding: 0.62rem 0.72rem;
  border-bottom: 1px solid #edf2f7;
  vertical-align: top;
  text-align: left;
}
.meta-table th,
.top-table th {
  width: 34%;
  background: #f8fafc;
  color: var(--muted);
  font-weight: 600;
  position: sticky;
  top: 0;
  z-index: 1;
}
.top-table {
  max-height: 460px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 16px;
}
.top-table table tbody tr { cursor: pointer; }
.top-table table tbody tr:hover { background: #f8fbff; }
.top-table .rank { color: var(--muted); width: 4rem; }

.page-footer {
  padding: 0 1rem 1.6rem;
  color: var(--muted);
  text-align: center;
}

.loading-overlay {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(241, 245, 249, 0.78);
  backdrop-filter: blur(5px);
  z-index: 2000;
}
.loading-overlay.visible { display: flex; }
.loading-card {
  background: white;
  border-radius: 20px;
  padding: 1rem 1.2rem;
  box-shadow: var(--shadow);
  display: grid;
  gap: 0.45rem;
  min-width: 320px;
}
.spinner {
  width: 34px;
  height: 34px;
  border-radius: 999px;
  border: 4px solid rgba(29, 78, 216, 0.15);
  border-top-color: var(--primary);
  animation: spin 0.85s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-title { font-weight: 700; }
.loading-subtitle { color: var(--muted); }

.ts-control,
.ts-wrapper.multi .ts-control {
  min-height: 46px;
  border-radius: 12px;
  border-color: var(--line);
  padding: 0.45rem 0.6rem;
  box-shadow: none;
}
.ts-dropdown {
  border-radius: 14px;
  border-color: var(--line);
  overflow: hidden;
}
.ts-wrapper.multi .ts-control > div {
  background: var(--primary-soft);
  color: var(--primary);
  border-radius: 999px;
}

.noUi-target {
  border: 1px solid var(--line);
  box-shadow: none;
  background: linear-gradient(180deg, #f8fbff 0%, #f1f5f9 100%);
  height: 12px;
}
.noUi-connect {
  background: linear-gradient(90deg, rgba(29, 78, 216, 0.18) 0%, rgba(29, 78, 216, 0.46) 100%);
}
.noUi-horizontal .noUi-handle {
  width: 22px;
  height: 22px;
  right: -11px;
  top: -6px;
  border-radius: 999px;
  border: 3px solid #ffffff;
  background: var(--primary);
  box-shadow: 0 6px 16px rgba(29, 78, 216, 0.22);
}
.noUi-handle::before,
.noUi-handle::after { display: none; }
.noUi-tooltip {
  border: none;
  background: #0f172a;
  color: #ffffff;
  border-radius: 10px;
  font-size: 0.8rem;
  padding: 0.32rem 0.45rem;
  bottom: 150%;
}

.popup-card {
  line-height: 1.5;
}
.popup-card .popup-emph {
  color: #1e293b;
}

#methodologyDialog {
  width: min(960px, calc(100vw - 2rem));
  max-height: calc(100vh - 2rem);
  border: none;
  border-radius: 22px;
  padding: 0;
  box-shadow: 0 24px 70px rgba(15, 23, 42, 0.22);
}
#methodologyDialog::backdrop { background: rgba(15, 23, 42, 0.4); }
.dialog-form { display: grid; max-height: calc(100vh - 2rem); }
.dialog-header {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.2rem;
  border-bottom: 1px solid var(--line);
}
.dialog-header h2 {
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
  font-size: 1.2rem;
}
.dialog-header button {
  position: relative;
  z-index: 1;
  flex: 0 0 auto;
}
.dialog-content {
  padding: 1rem 1.2rem 1.25rem;
  overflow: auto;
  color: #1e293b;
  line-height: 1.62;
}
.dialog-content p { margin: 0 0 1rem; }
.dialog-content code {
  padding: 0.15rem 0.32rem;
  border-radius: 7px;
  background: #f1f5f9;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (max-width: 1280px) {
  .controls-grid {
    grid-template-columns: 1fr 1fr;
  }
  .controls-grid .field:first-child {
    grid-column: span 2;
  }
  .legend-row,
  .local-controls-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 1180px) {
  .timeline-readout,
  .kpi-grid {
    grid-template-columns: repeat(2, minmax(160px, 1fr));
  }
  .grid-two {
    grid-template-columns: 1fr;
  }
  .map-panel { min-height: 660px; }
}

@media (max-width: 760px) {
  .page-header { flex-direction: column; }
  .header-actions { justify-content: flex-start; }
  .timeline-readout,
  .kpi-grid,
  .controls-grid,
  .selection-grid,
  .mini-fields {
    grid-template-columns: 1fr;
  }
  .controls-grid .field:first-child {
    grid-column: span 1;
  }
  .panel-actions,
  .controls-actions,
  .header-actions {
    align-items: stretch;
  }
  .compare-group {
    width: 100%;
  }
  .dialog-header {
    align-items: flex-start;
    flex-direction: column;
  }
  .dialog-header button {
    align-self: stretch;
    width: 100%;
  }
  #map { height: 520px; }
}


.controls-grid-wide {
  grid-template-columns: minmax(260px, 1.15fr) minmax(240px, 1fr) minmax(240px, 1fr);
}
.controls-hint {
  margin-top: 0.7rem;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.45;
}
.ts-wrapper.disabled .ts-control,
.ts-wrapper.locked .ts-control,
.ts-wrapper .ts-control.disabled {
  background: #f8fafc;
  color: #94a3b8;
}
.legend-details {
  margin-bottom: 0.95rem;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fbfdff;
  overflow: hidden;
}
.legend-details > summary {
  cursor: pointer;
  list-style: none;
  padding: 0.9rem 1rem;
  font-weight: 600;
  color: var(--text);
  user-select: none;
}
.legend-details > summary::-webkit-details-marker {
  display: none;
}
.legend-details[open] > summary {
  border-bottom: 1px solid var(--line);
}
.legend-details .legend-row {
  padding: 0.95rem;
  margin-bottom: 0;
}
.panel-actions-stack {
  align-items: flex-end;
  flex-direction: column;
}
.mini-export-group {
  display: inline-flex;
  gap: 0.55rem;
  flex-wrap: wrap;
}
.thematic-block {
  padding-bottom: 1.25rem;
}
.thematic-grid {
  display: grid;
  gap: 1rem;
}
.thematic-grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
.chart.compact {
  min-height: 350px;
}
.subchart-title {
  margin-bottom: 0.25rem;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 600;
}
.migration-controls-grid {
  margin-top: 1rem;
}
.strong-note {
  color: #0f172a;
  font-weight: 600;
}
@media (max-width: 1280px) {
  .controls-grid-wide {
    grid-template-columns: 1fr 1fr;
  }
  .controls-grid-wide .field:first-child {
    grid-column: span 2;
  }
}
@media (max-width: 920px) {
  .thematic-grid.two {
    grid-template-columns: 1fr;
  }
  .panel-actions-stack {
    align-items: stretch;
  }
}
