:root {
  color-scheme: dark;
  --bg: #070a0f;
  --panel: #101720;
  --panel-2: #131c27;
  --line: #263342;
  --text: #eef4f8;
  --muted: #93a4b4;
  --blue: #5bb7ff;
  --green: #43d17d;
  --amber: #ffc35a;
  --shadow: 0 14px 40px rgba(0, 0, 0, 0.24);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top left, rgba(91, 183, 255, 0.18), transparent 34rem),
    linear-gradient(135deg, #070a0f 0%, #0a1017 52%, #0b1210 100%);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input, select { font: inherit; }

button {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #172230;
  color: var(--text);
  cursor: pointer;
}

button:hover:not(:disabled) {
  border-color: #4d6780;
  background: #1d2b3b;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.primary {
  border-color: rgba(67, 209, 125, 0.45);
  background: linear-gradient(135deg, #43d17d, #5bb7ff);
  color: #06100b;
  font-weight: 800;
}

.app-shell {
  width: min(1880px, calc(100vw - 20px));
  margin: 0 auto;
  padding: 10px 0 16px;
}

.stage, .control-section {
  border: 1px solid rgba(132, 160, 184, 0.18);
  border-radius: 8px;
  background: rgba(16, 23, 32, 0.88);
  box-shadow: var(--shadow);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 10px 14px 8px;
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--green);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-size: clamp(1.5rem, 2.4vw, 2.7rem);
  line-height: 1;
}

h2 {
  margin-bottom: 0;
  font-size: 0.98rem;
}

.top-actions, .map-toolbar, .section-title {
  display: flex;
  align-items: center;
  gap: 8px;
}

.top-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.top-actions button { padding: 0 12px; }

.visual-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 496px;
  gap: 10px;
  padding: 0 10px 10px;
}

.map-panel { min-width: 0; }

.map-toolbar {
  justify-content: space-between;
  min-height: 38px;
  padding: 4px 0;
}

.tool-group {
  display: flex;
  gap: 6px;
}

.tool { width: 68px; }

.tool.active {
  border-color: rgba(91, 183, 255, 0.8);
  background: rgba(91, 183, 255, 0.22);
}

.hint, .section-title span, .metrics span, .route-panel li { color: var(--muted); }

#mapCanvas, #chartCanvas {
  display: block;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #080d12;
}

#mapCanvas {
  aspect-ratio: 1200 / 760;
  height: auto;
  min-height: 0;
  cursor: crosshair;
}

#chartCanvas { height: 140px; }

.side-panel {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: calc(100vh - 104px);
  min-width: 0;
  overflow-y: auto;
  padding-right: 2px;
}

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

.metrics div, .insight, .chart-panel, .route-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
}

.metrics div {
  min-height: 58px;
  padding: 8px 10px;
}

.metrics span, .metrics strong { display: block; }

.metrics strong {
  margin-top: 4px;
  color: var(--green);
  font-size: 1.14rem;
  line-height: 1;
}

.insight {
  flex: 0 0 190px;
  height: 190px;
  min-height: 190px;
  padding: 12px;
  overflow-y: auto;
}

.insight p:first-child {
  margin-bottom: 6px;
  color: var(--amber);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.insight h2 {
  margin-bottom: 7px;
  font-size: 1rem;
}

.insight p:last-child {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.36;
}

.chart-panel, .route-panel {
  min-width: 0;
  padding: 9px;
}

.section-title {
  justify-content: space-between;
  margin-bottom: 7px;
}

.section-title button {
  min-height: 30px;
  padding: 0 10px;
}

#routeList {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  max-height: 92px;
  margin: 0;
  padding: 0;
  overflow: auto;
  list-style: none;
}

.route-panel li {
  border: 1px solid rgba(91, 183, 255, 0.25);
  border-radius: 999px;
  padding: 4px 8px;
  background: rgba(91, 183, 255, 0.08);
  color: var(--text);
  font-size: 0.86rem;
}

.controls {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-top: 0;
}

.control-section {
  padding: 10px;
  box-shadow: none;
}

.preset-grid, .slider-grid, .form-grid {
  display: grid;
  gap: 8px;
}

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

.slider-grid {
  grid-template-columns: 1fr;
}

label span {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 3px;
  color: var(--muted);
  font-size: 0.88rem;
}

label b { color: var(--blue); }

input[type="range"] {
  width: 100%;
  accent-color: var(--green);
}

input[type="number"], select {
  width: 100%;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0b121a;
  color: var(--text);
  padding: 0 10px;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 34px;
  padding-top: 20px;
}

.toggle input {
  width: 18px;
  height: 18px;
  accent-color: var(--green);
}

.toggle span {
  margin: 0;
  color: var(--text);
}

@media (max-width: 1180px) {
  .visual-grid, .controls { grid-template-columns: 1fr; }
  .side-panel {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    max-height: none;
    overflow: visible;
  }
}

@media (max-width: 760px) {
  .app-shell {
    width: min(100vw - 12px, 1880px);
    padding-top: 8px;
  }

  .topbar, .map-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions, .tool-group, .preset-grid, .slider-grid, .form-grid, .side-panel {
    grid-template-columns: 1fr;
  }

  .top-actions button, .tool { width: 100%; }

  #mapCanvas { aspect-ratio: 1200 / 760; }

  .insight {
    flex-basis: auto;
    height: auto;
    min-height: 180px;
  }
}
