:root {
  --bg: #f3f5f7;
  --panel: #ffffff;
  --panel-soft: #f8fafb;
  --ink: #17212b;
  --muted: #667085;
  --line: #d9e0e7;
  --accent: #1f5f8b;
  --accent-dark: #184b6d;
  --accent-soft: #e9f1f7;
  --positive: #b5523c;
  --negative: #2d6f9d;
  --neutral: #f7f7f5;
  --shadow: 0 10px 28px rgba(15, 23, 42, 0.10);
  --sidebar-width: 378px;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; }
body {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
}
button, input, select { font: inherit; }
button, select, input { outline: none; }

#app {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  width: 100%;
  height: 100%;
  overflow: hidden;
}

#sidebar {
  position: relative;
  z-index: 1000;
  height: 100%;
  overflow-y: auto;
  background: var(--panel);
  border-right: 1px solid var(--line);
  box-shadow: 4px 0 18px rgba(15, 23, 42, 0.05);
}
.sidebar-inner { padding: 22px 22px 28px; }
.brand { padding-bottom: 18px; border-bottom: 1px solid var(--line); }
.eyebrow, .workspace-eyebrow {
  color: var(--accent);
  font-size: 0.70rem;
  font-weight: 800;
  letter-spacing: 0.10em;
  text-transform: uppercase;
}
.brand h1 {
  margin: 7px 0 0;
  font-size: 1.38rem;
  line-height: 1.23;
  letter-spacing: -0.025em;
}
.brand .subtitle {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 0.91rem;
  line-height: 1.4;
}
.brand .description {
  margin: 12px 0 0;
  font-size: 0.83rem;
  line-height: 1.55;
}
.privacy-note {
  margin-top: 13px;
  padding: 10px 11px;
  border-radius: 8px;
  background: var(--accent-soft);
  color: #284b63;
  font-size: 0.74rem;
  line-height: 1.48;
}

.control-section {
  padding: 17px 0;
  border-bottom: 1px solid var(--line);
}
.section-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.section-title h2 {
  margin: 0;
  color: #344054;
  font-size: 0.77rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.section-title .value {
  color: var(--accent);
  font-size: 0.76rem;
  font-weight: 750;
  text-align: right;
}
.field { margin-top: 12px; }
.field:first-of-type { margin-top: 0; }
label {
  display: block;
  margin-bottom: 6px;
  color: #344054;
  font-size: 0.78rem;
  font-weight: 680;
}
select, input[type="number"] {
  width: 100%;
  min-height: 38px;
  border: 1px solid #cdd5df;
  border-radius: 8px;
  padding: 8px 10px;
  color: var(--ink);
  background: #fff;
  font-size: 0.83rem;
}
select:focus, input:focus {
  border-color: #7aa7c7;
  box-shadow: 0 0 0 3px rgba(31, 95, 139, 0.12);
}
.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.range-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
}
.range-head span {
  color: var(--accent);
  font-size: 0.77rem;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
}
input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}
.button-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 14px;
}
button {
  min-height: 37px;
  border: 1px solid #cdd5df;
  border-radius: 8px;
  padding: 8px 11px;
  color: #344054;
  background: #fff;
  font-size: 0.80rem;
  font-weight: 700;
  cursor: pointer;
}
button:hover { background: #f8fafc; border-color: #98a2b3; }
button.primary { color: #fff; background: var(--accent); border-color: var(--accent); }
button.primary:hover { background: var(--accent-dark); }
button:disabled { opacity: 0.48; cursor: not-allowed; }
.wide-button { width: 100%; }
.coverage {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.71rem;
  line-height: 1.45;
}
.footer {
  padding-top: 17px;
  color: var(--muted);
  font-size: 0.71rem;
  line-height: 1.5;
}
.footer p { margin: 0; }
.footer .links { display: flex; flex-wrap: wrap; gap: 8px 12px; margin-top: 10px; }
.footer a { color: var(--accent); text-decoration: none; }
.footer a:hover { text-decoration: underline; }
#error-box {
  display: none;
  margin-top: 12px;
  padding: 10px 11px;
  border: 1px solid #efb7b3;
  border-radius: 8px;
  color: #8a1c17;
  background: #fff1f0;
  font-size: 0.75rem;
  line-height: 1.45;
}

#workspace {
  position: relative;
  min-width: 0;
  height: 100%;
  overflow: auto;
  padding: 20px;
}
.workspace-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 15px;
}
.workspace-header h2 {
  margin: 5px 0 0;
  font-size: 1.34rem;
  letter-spacing: -0.02em;
}
.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(105px, 1fr));
  gap: 8px;
}
.summary-card {
  min-width: 110px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--panel);
}
.summary-card span {
  display: block;
  color: var(--muted);
  font-size: 0.66rem;
  letter-spacing: 0.045em;
  text-transform: uppercase;
}
.summary-card strong {
  display: block;
  margin-top: 4px;
  font-size: 0.98rem;
  font-variant-numeric: tabular-nums;
}
.workspace-grid {
  display: grid;
  grid-template-columns: minmax(480px, 1.25fr) minmax(390px, 0.85fr);
  gap: 14px;
  min-height: calc(100% - 92px);
}
.panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  box-shadow: 0 4px 16px rgba(15, 23, 42, 0.055);
  overflow: hidden;
}
.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 16px 12px;
  border-bottom: 1px solid var(--line);
}
.panel-head h3 { margin: 0; font-size: 0.95rem; }
.panel-head p { margin: 4px 0 0; color: var(--muted); font-size: 0.73rem; line-height: 1.4; }
.pill {
  flex: 0 0 auto;
  padding: 5px 8px;
  border-radius: 999px;
  color: var(--accent-dark);
  background: var(--accent-soft);
  font-size: 0.68rem;
  font-weight: 750;
}

.map-panel { display: flex; flex-direction: column; }
#map-wrap {
  position: relative;
  flex: 1;
  min-height: 565px;
  background: #f9fbfc;
}
#region-map { display: block; width: 100%; height: 100%; min-height: 565px; }
.region-shape {
  stroke: rgba(36, 50, 64, 0.58);
  stroke-width: 0.75;
  vector-effect: non-scaling-stroke;
  transition: fill 0.18s ease, stroke 0.12s ease;
  cursor: pointer;
}
.region-shape:hover { stroke: #17212b; stroke-width: 1.45; }
#map-tooltip {
  position: absolute;
  z-index: 30;
  display: none;
  min-width: 185px;
  max-width: 260px;
  padding: 9px 11px;
  border-radius: 8px;
  color: #fff;
  background: rgba(23, 33, 43, 0.94);
  box-shadow: var(--shadow);
  font-size: 0.72rem;
  line-height: 1.45;
  pointer-events: none;
}
.tooltip-title { font-weight: 800; margin-bottom: 5px; }
.tooltip-row { display: flex; justify-content: space-between; gap: 14px; }
.tooltip-row span:last-child { font-variant-numeric: tabular-nums; font-weight: 680; }
.map-legend {
  position: absolute;
  left: 18px;
  bottom: 16px;
  width: 210px;
  padding: 9px 10px;
  border: 1px solid rgba(217, 224, 231, 0.9);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.08);
  backdrop-filter: blur(5px);
}
.legend-bar {
  height: 10px;
  border: 1px solid rgba(0,0,0,0.12);
  border-radius: 3px;
  background: linear-gradient(90deg, var(--negative), var(--neutral), var(--positive));
}
.legend-labels {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.65rem;
  font-variant-numeric: tabular-nums;
}
.legend-labels span:nth-child(2) { text-align: center; }
.legend-labels span:last-child { text-align: right; }

.chart-panel { display: flex; flex-direction: column; }
.chart-wrap { flex: 1; min-height: 430px; padding: 12px 10px 4px; }
#trajectory-chart { width: 100%; height: 100%; min-height: 410px; display: block; }
.chart-legend { display: flex; gap: 10px; color: var(--muted); font-size: 0.68rem; }
.legend-item { display: inline-flex; align-items: center; gap: 5px; }
.legend-line { width: 18px; height: 2px; border-radius: 2px; }
.event-strip {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  border-top: 1px solid var(--line);
  background: var(--line);
}
.event-strip div { padding: 10px 12px; background: var(--panel-soft); }
.event-strip span { display: block; color: var(--muted); font-size: 0.63rem; text-transform: uppercase; letter-spacing: 0.04em; }
.event-strip strong { display: block; margin-top: 4px; font-size: 0.91rem; font-variant-numeric: tabular-nums; }

#loading {
  position: absolute;
  inset: 0;
  z-index: 1300;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(244, 246, 248, 0.88);
  backdrop-filter: blur(3px);
}
#loading.hidden { display: none; }
.loading-card {
  display: grid;
  justify-items: center;
  gap: 8px;
  min-width: 280px;
  padding: 22px 26px;
  border-radius: 11px;
  background: #fff;
  box-shadow: var(--shadow);
  font-size: 0.82rem;
}
.loading-card span { color: var(--muted); }
.spinner {
  width: 30px;
  height: 30px;
  border: 3px solid #d9e2ea;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

#mobile-toggle {
  display: none;
  position: fixed;
  z-index: 1400;
  top: 12px;
  left: 12px;
  box-shadow: var(--shadow);
}
#sidebar-scrim { display: none; }

@media (max-width: 1180px) {
  .workspace-header { align-items: flex-start; flex-direction: column; }
  .summary-grid { width: 100%; }
  .workspace-grid { grid-template-columns: 1fr; }
  .map-panel, .chart-panel { min-height: 590px; }
}

@media (max-width: 820px) {
  #app { display: block; }
  #sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: min(var(--sidebar-width), calc(100% - 38px));
    transform: translateX(-105%);
    transition: transform 0.22s ease;
  }
  #sidebar.open { transform: translateX(0); }
  #workspace { padding: 68px 12px 12px; }
  #mobile-toggle { display: inline-flex; }
  #sidebar-scrim {
    position: fixed;
    inset: 0;
    z-index: 900;
    background: rgba(15, 23, 42, 0.38);
  }
  #sidebar-scrim.open { display: block; }
  .summary-grid { grid-template-columns: 1fr 1fr; }
  .workspace-grid { display: block; }
  .panel { margin-bottom: 12px; }
  #map-wrap, #region-map { min-height: 490px; }
  .chart-wrap, #trajectory-chart { min-height: 360px; }
}

@media (max-width: 480px) {
  .two-col { grid-template-columns: 1fr; gap: 0; }
  .summary-card { min-width: 0; }
  .workspace-header h2 { font-size: 1.12rem; }
  #map-wrap, #region-map { min-height: 420px; }
}
