* {
  box-sizing: border-box;
}

:root {
  --primary: #000078;
  --primary-bright: #1b66ff;
  --primary-mid: #003dcb;
  --primary-soft: #bed2ff;
  --secondary: #00d7f5;
  --secondary-dark: #00a9ff;
  --secondary-soft: #b3ffe6;
  --ink: #161a3a;
  --muted: #64748b;
  --card: #ffffff;
  --line: #dbe6ff;
  --page-start: #f4f8ff;
  --page-end: #eefcff;
}

html,
body {
  min-height: 100%;
  margin: 0;
}

body {
  color: var(--ink);
  font-family: "Montserrat", Arial, Helvetica, sans-serif;
  background: linear-gradient(180deg, var(--page-start), var(--page-end));
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 8px;
  font-size: 32px;
  font-weight: 600;
}

h2 {
  font-size: 24px;
  font-weight: 600;
}

h3 {
  font-size: 18px;
  font-weight: 600;
}

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

button,
a {
  cursor: pointer;
}

.site-footer {
  padding: 20px 24px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.loading-overlay {
  position: fixed;
  inset: 72px 0 0;
  z-index: 4000;
  display: grid;
  padding: 24px;
  place-items: start center;
  background: linear-gradient(180deg, rgba(244, 248, 255, 0.96), rgba(238, 252, 255, 0.96));
  transition: opacity 0.25s ease, visibility 0.25s ease;
}

.loading-overlay.hidden {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
}

.loading-panel {
  width: min(520px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  background: #ffffff;
  box-shadow: 0 10px 24px rgba(0, 0, 120, 0.12);
}

.loading-panel p {
  margin-bottom: 12px;
  color: var(--primary);
  font-weight: 600;
}

.loading-bar {
  position: relative;
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--primary-soft);
}

.loading-bar span {
  position: absolute;
  inset: 0 auto 0 0;
  width: 42%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--secondary), var(--primary-bright));
  animation: loading-slide 1.05s ease-in-out infinite;
}

@keyframes loading-slide {
  0% {
    transform: translateX(-110%);
  }

  100% {
    transform: translateX(250%);
  }
}

.top-nav {
  position: sticky;
  top: 0;
  z-index: 20;
  background: #ffffff;
  box-shadow: 0 2px 10px rgba(0, 0, 120, 0.12);
}

.nav-inner {
  display: flex;
  max-width: 1180px;
  margin: 0 auto;
  padding: 16px 24px;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

.brand,
.nav-links a {
  color: inherit;
  text-decoration: none;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
}

.brand-logo {
  display: block;
  width: auto;
  height: 42px;
  max-width: min(320px, 42vw);
  object-fit: contain;
}

.brand-icon {
  border-radius: 6px;
  padding: 4px 6px;
  color: #ffffff;
  background: var(--primary);
  font-size: 12px;
  letter-spacing: 0;
}

.nav-links {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.nav-links a {
  border-radius: 6px;
  padding: 10px 14px;
  color: var(--muted);
}

.nav-links a.active,
.nav-links a:hover {
  color: var(--primary);
  background: var(--primary-soft);
}

.page {
  min-height: calc(100vh - 72px);
  padding: 28px 24px;
}

.container {
  max-width: 1080px;
  margin: 0 auto;
}

.wide-container {
  max-width: 1320px;
  margin: 0 auto;
}

.page-header {
  margin-bottom: 24px;
  text-align: center;
}

.muted {
  color: var(--muted);
}

.card {
  border-radius: 8px;
  background: var(--card);
  box-shadow: 0 10px 24px rgba(0, 0, 120, 0.12);
}

.card-padding {
  padding: 24px;
}

.section-title {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}

.text-stack {
  display: grid;
  gap: 12px;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 24px;
}

.home-about .section-title {
  margin-bottom: 8px;
}

.home-about .button-row {
  margin-top: 14px;
}

.btn {
  display: inline-flex;
  min-height: 42px;
  border: 0;
  border-radius: 6px;
  padding: 10px 16px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: white;
  text-decoration: none;
  font-weight: 600;
}

.btn-blue {
  background: var(--primary);
}

.btn-blue:hover {
  background: var(--primary-mid);
}

.btn-green {
  color: var(--primary);
  background: var(--secondary);
}

.btn-green:hover {
  background: #57f0d1;
}

.btn-purple {
  background: var(--primary-bright);
}

.btn-purple:hover {
  background: var(--primary-mid);
}

.map-card {
  min-height: 560px;
  margin-top: 24px;
  overflow: visible;
}

.nationality-map-card .section-title {
  margin-bottom: 0;
  padding: 18px 18px 6px;
}

.nationality-map-card .section-title h2 {
  margin-bottom: 0;
}

.nationality-map-card .legend {
  border-top: 0;
  padding-top: 4px;
}

.map-area {
  position: relative;
  height: 420px;
  overflow: hidden;
  background:
    radial-gradient(circle at 55% 48%, rgba(190, 210, 255, 0.85), transparent 18%),
    linear-gradient(180deg, #eaf3ff, #f8ffff);
}

.leaflet-container {
  z-index: 0;
  font-family: "Montserrat", Arial, Helvetica, sans-serif;
}

.leaflet-pane,
.leaflet-top,
.leaflet-bottom {
  z-index: 1;
}

.leaflet-popup-content {
  margin: 14px;
}

.leaflet-popup-close-button {
  color: var(--primary) !important;
  font: 700 20px/20px Arial, Helvetica, sans-serif !important;
}

.leaflet-popup-close-button:hover {
  color: var(--primary-mid) !important;
  background: transparent !important;
}

.map-popup {
  color: var(--ink);
  font-family: "Montserrat", Arial, Helvetica, sans-serif;
}

.map-popup h3 {
  margin-bottom: 4px;
  color: var(--primary);
  font-size: 18px;
}

.popup-subtitle {
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 12px;
}

.popup-metric {
  display: flex;
  border: 1px solid var(--line);
  border-radius: 6px;
  margin-bottom: 8px;
  padding: 8px 10px;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: #f8fbff;
}

.popup-metric span {
  color: var(--muted);
  font-size: 12px;
}

.popup-metric strong {
  color: var(--primary);
}

.map-popup table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.map-popup th,
.map-popup td {
  border-bottom: 1px solid var(--line);
  padding: 6px 8px;
  text-align: right;
  white-space: nowrap;
}

.map-popup th:first-child,
.map-popup td:first-child {
  text-align: left;
}

.map-popup th {
  color: var(--primary);
  background: #eef5ff;
}

.compact-popup {
  min-width: 240px;
}

.map-error {
  display: grid;
  height: 100%;
  padding: 24px;
  place-items: center;
  color: var(--primary);
  text-align: center;
  background: #eef2ff;
}

.world-svg {
  width: 100%;
  height: 100%;
}

.land {
  fill: #e8efff;
  stroke: #9db6ff;
  stroke-width: 1;
}

.land-highlight-blue {
  fill: var(--primary-soft);
}

.land-highlight-yellow {
  fill: #b3ffe6;
}

.bubble {
  fill: var(--primary-bright);
  fill-opacity: 0.72;
  stroke: var(--primary);
  stroke-width: 2;
  transition: 0.15s ease;
}

.bubble:hover,
.bubble.selected {
  fill-opacity: 0.95;
  fill: var(--secondary);
  stroke: var(--primary);
}

.map-label {
  font-size: 12px;
  font-weight: 700;
  fill: var(--ink);
}

.legend {
  border-top: 1px solid var(--line);
  padding: 16px 16px 20px;
  background: #fbfdff;
}

.legend h3 {
  margin-bottom: 8px;
  font-size: 14px;
}

.legend-row {
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
  align-items: center;
  padding-bottom: 2px;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.dot-small,
.dot-large {
  display: inline-block;
  border-radius: 999px;
  background: var(--primary-bright);
}

.dot-small {
  width: 12px;
  height: 12px;
}

.dot-large {
  width: 24px;
  height: 24px;
}

.hint {
  margin-top: 16px;
  color: var(--muted);
  font-size: 14px;
  text-align: center;
}

.analysis-grid {
  display: grid;
  grid-template-columns: minmax(380px, 0.82fr) minmax(0, 1.18fr);
  gap: 24px;
  align-items: stretch;
}

.panel {
  min-height: calc(100vh - 72px);
  overflow: hidden;
}

.panel-header {
  border-bottom: 1px solid var(--line);
  padding: 18px;
}

.filters {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.analysis-filters {
  grid-template-columns: minmax(0, 0.95fr) minmax(0, 0.95fr) minmax(0, 0.95fr) 112px;
  gap: 12px;
  align-items: start;
}

.filter-title {
  margin-bottom: 14px;
  color: var(--primary);
  font-weight: 700;
}

.filter-column {
  display: grid;
  gap: 12px;
  align-content: start;
  min-width: 0;
}

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

.filter-control label {
  margin-bottom: 0;
  color: var(--primary);
  font-size: 13px;
}

.filter-control select[multiple] {
  width: 100%;
  height: 150px;
  min-width: 0;
  font-size: 13px;
}

.filter-help {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
}

.single-slider {
  display: grid;
  gap: 8px;
  height: 80px;
  align-content: start;
}

.dual-slider {
  position: relative;
  height: 30px;
}

.dual-slider input[type="range"] {
  position: absolute;
  inset: 0;
  width: 100%;
  margin: 0;
  background: transparent;
  pointer-events: none;
}

.dual-slider input[type="range"]::-webkit-slider-thumb {
  pointer-events: auto;
}

.dual-slider input[type="range"]::-moz-range-thumb {
  pointer-events: auto;
}

.range-caption {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 13px;
}

.range-caption strong {
  color: var(--primary);
}

.slider-row span {
  color: var(--muted);
  font-size: 12px;
}

input[type="range"] {
  accent-color: var(--primary);
}

.filter-actions {
  display: grid;
  gap: 8px;
  align-items: start;
  padding-top: 27px;
}

.filter-actions .btn {
  width: 112px;
  min-height: 44px;
  padding: 10px 12px;
}

select option {
  font-size: 13px;
}

select option:checked {
  color: #ffffff;
  background: var(--primary-mid);
}

select,
input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 10px;
  background: #ffffff;
}

.border-map-area {
  height: calc(100vh - 470px);
  min-height: 360px;
}

.selected-crossing {
  border-top: 1px solid var(--primary-soft);
  border-bottom: 1px solid var(--primary-soft);
  padding: 16px;
  background: #eef5ff;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

.stat-label {
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 14px;
}

.green-text {
  color: #009f8f;
}

.red-text {
  color: #003dcb;
}

.blue-text {
  color: var(--primary);
}

.chart-panel {
  display: grid;
  gap: 20px;
  max-height: calc(100vh - 72px);
  min-height: calc(100vh - 72px);
  overflow-y: auto;
  padding: 18px;
}

.chart-card h3 {
  margin-bottom: 10px;
}

.chart-wrap {
  position: relative;
}

canvas {
  display: block;
  width: 100%;
  height: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
}

.svg-chart {
  position: relative;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
}

.svg-chart svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
  font-family: "Montserrat", Arial, Helvetica, sans-serif;
}

.trend-line {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 3;
}

.trend-line.entries {
  stroke: #00d7f5;
}

.trend-line.exits {
  stroke: #6bfbce;
}

.trend-line.net {
  stroke: #000078;
}

.svg-axis {
  stroke: var(--line);
  stroke-width: 1;
}

.svg-axis-label {
  fill: var(--muted);
  font-size: 11px;
  font-weight: 400;
}

.svg-value {
  fill: var(--ink);
  font-size: 11px;
  font-weight: 600;
}

.svg-legend text {
  fill: var(--ink);
  font-size: 13px;
  font-weight: 400;
}

.trend-hit {
  fill: transparent;
  cursor: pointer;
}

.crossing-hit rect[fill="transparent"] {
  cursor: pointer;
}

.chart-tooltip {
  position: absolute;
  z-index: 5;
  display: none;
  min-width: 160px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  color: var(--ink);
  background: #ffffff;
  box-shadow: 0 10px 24px rgba(0, 0, 120, 0.16);
  font-size: 12px;
  pointer-events: none;
}

.chart-tooltip.visible,
.chart-tooltip.measuring {
  display: grid;
  gap: 4px;
}

.chart-tooltip.measuring {
  visibility: hidden;
}

.chart-tooltip strong {
  color: var(--primary);
}

.insights {
  border-radius: 8px;
  padding: 14px;
  background: #ecfeff;
  color: var(--primary);
}

.insights ul {
  margin: 0;
  padding-left: 20px;
}

.methodology-stack {
  display: grid;
  gap: 18px;
}

.methodology-stack ul,
.methodology-stack ol {
  margin-top: 0;
  color: var(--ink);
}

.note {
  border-radius: 8px;
  padding: 16px;
  background: #eff6ff;
  color: var(--primary);
}

.form-grid {
  display: grid;
  gap: 16px;
}

label {
  display: block;
  margin-bottom: 6px;
  font-weight: 600;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 5000;
  display: flex;
  padding: 24px;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 120, 0.52);
}

.modal {
  position: relative;
  width: min(680px, 100%);
  max-height: calc(100vh - 48px);
  overflow: auto;
  border-radius: 8px;
  padding: 24px;
  background: #ffffff;
  box-shadow: 0 24px 60px rgba(0, 0, 120, 0.28);
}

.close-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  font-size: 22px;
}

.close-btn:hover {
  background: #eef2ff;
}

.year-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 10px;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 60;
  border-radius: 8px;
  padding: 12px 16px;
  color: white;
  background: var(--primary);
  box-shadow: 0 10px 30px rgba(0, 0, 120, 0.25);
}

@media (max-width: 850px) {
  .nav-inner,
  .analysis-grid,
  .filters,
  .analysis-filters,
  .stats-grid,
  .year-row {
    grid-template-columns: 1fr;
  }

  .nav-inner {
    display: grid;
  }

  .nav-links {
    display: grid;
  }

  .analysis-grid {
    display: grid;
    grid-template-columns: 1fr;
  }

  .panel {
    min-height: auto;
  }

  .chart-panel {
    gap: 34px;
    max-height: none;
    min-height: auto;
    overflow: visible;
  }

  body {
    font-size: 14px;
  }

  .page {
    padding: 18px 12px;
  }

  .nav-inner {
    padding: 12px 14px;
    gap: 12px;
  }

  .brand,
  .nav-links a {
    font-size: 13px;
  }

  .brand-logo {
    height: 32px;
    max-width: 210px;
  }

  .nav-links a {
    padding: 8px 10px;
  }

  h1 {
    font-size: 24px;
  }

  h2 {
    font-size: 19px;
  }

  h3 {
    font-size: 15px;
  }

  p,
  li,
  label,
  select,
  input,
  textarea,
  .btn {
    font-size: 13px;
  }

  .card-padding,
  .panel-header,
  .chart-panel {
    padding: 14px;
  }

  .text-stack {
    gap: 8px;
  }

  .button-row {
    margin-top: 12px;
  }

  .map-area {
    height: 340px;
  }

  .border-map-area {
    min-height: 320px;
    height: 360px;
  }

  .map-popup {
    max-width: min(250px, calc(100vw - 96px));
    font-size: 12px;
  }

  .map-popup h3 {
    font-size: 15px;
  }

  .map-popup table {
    font-size: 10px;
  }

  .leaflet-popup-content {
    width: auto !important;
    max-width: calc(100vw - 96px);
    max-height: 58vh;
    overflow: auto;
    margin: 10px;
  }

  .leaflet-popup,
  .leaflet-popup-content-wrapper {
    max-width: calc(100vw - 48px) !important;
  }

  .leaflet-popup-close-button {
    top: 6px !important;
    right: 6px !important;
    z-index: 2;
    width: 28px !important;
    height: 28px !important;
    border-radius: 999px;
    background: #eef5ff !important;
  }

  .chart-card {
    overflow-x: visible;
    overflow-y: visible;
    padding-bottom: 0;
  }

  .chart-wrap {
    min-width: 0;
    overflow: visible;
  }

  .chart-card > canvas {
    min-width: 0;
  }

  canvas {
    width: 100%;
    max-width: none;
  }
}
