:root {
  --bg: #07111f;
  --panel: rgba(15, 23, 42, 0.86);
  --panel-strong: rgba(15, 23, 42, 0.96);
  --border: rgba(148, 163, 184, 0.22);
  --text: #e5eefb;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --accent-2: #a78bfa;
  --green: #22c55e;
  --yellow: #f59e0b;
  --red: #ef4444;
  --black: #020617;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at top left, rgba(56, 189, 248, 0.22), transparent 32rem),
    radial-gradient(circle at bottom right, rgba(167, 139, 250, 0.18), transparent 34rem),
    var(--bg);
  color: var(--text);
}

button, input, select { font: inherit; }
button { cursor: pointer; }

.app-shell {
  min-height: 100%;
  display: grid;
  grid-template-columns: minmax(340px, 420px) 1fr;
  gap: 18px;
  padding: 18px;
}

.panel, .card {
  background: var(--panel);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
  border-radius: 24px;
}

.sidebar {
  height: calc(100vh - 36px);
  overflow-y: auto;
  padding: 18px;
}

.sidebar::-webkit-scrollbar { width: 8px; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(148, 163, 184, 0.35); border-radius: 999px; }

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 16px;
}

.brand-mark {
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  border-radius: 18px;
  color: #06111f;
  font-weight: 900;
  letter-spacing: -0.06em;
  background: linear-gradient(135deg, #38bdf8, #a78bfa 60%, #f0abfc);
}

h1, h2, h3, p { margin: 0; }
h1 { font-size: 1.42rem; letter-spacing: -0.04em; }
h2 { font-size: 1.28rem; letter-spacing: -0.035em; }
h3 { font-size: 1.02rem; letter-spacing: -0.02em; }

.eyebrow {
  color: var(--accent);
  text-transform: uppercase;
  font-size: 0.72rem;
  letter-spacing: 0.16em;
  font-weight: 800;
}

.card {
  padding: 16px;
  margin-bottom: 14px;
}

.hero-card {
  background: linear-gradient(135deg, rgba(14, 165, 233, 0.18), rgba(167, 139, 250, 0.14)), var(--panel);
}

.hero-card p:last-child {
  color: #cbd5e1;
  line-height: 1.5;
  margin-top: 9px;
}

.section-heading {
  display: grid;
  grid-template-columns: 34px 1fr;
  gap: 12px;
  align-items: start;
  margin-bottom: 14px;
}

.section-heading p, .section-title p + h3 { color: var(--muted); }
.section-heading p { margin-top: 2px; font-size: 0.88rem; }

.step {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: rgba(56, 189, 248, 0.13);
  color: #7dd3fc;
  font-weight: 900;
  border: 1px solid rgba(56, 189, 248, 0.28);
}

label {
  display: block;
  color: #cbd5e1;
  margin: 10px 0 6px;
  font-size: 0.83rem;
  font-weight: 700;
}

select, input {
  width: 100%;
  border: 1px solid rgba(148, 163, 184, 0.25);
  background: rgba(15, 23, 42, 0.86);
  color: var(--text);
  border-radius: 14px;
  padding: 10px 12px;
  outline: none;
}

select:focus, input:focus {
  border-color: rgba(56, 189, 248, 0.75);
  box-shadow: 0 0 0 4px rgba(56, 189, 248, 0.10);
}

button {
  border: 1px solid rgba(148, 163, 184, 0.22);
  background: rgba(30, 41, 59, 0.92);
  color: var(--text);
  border-radius: 14px;
  padding: 10px 12px;
  font-weight: 800;
  transition: transform 0.16s ease, border-color 0.16s ease, background 0.16s ease;
}

button:hover { transform: translateY(-1px); border-color: rgba(56, 189, 248, 0.55); }
button.primary {
  background: linear-gradient(135deg, #0284c7, #7c3aed);
  border: none;
}
button.ghost { background: transparent; }
#routeBtn { width: 100%; margin-top: 14px; }

.route-meta, .segment-info {
  margin-top: 12px;
  padding: 12px;
  border: 1px solid rgba(148, 163, 184, 0.17);
  background: rgba(2, 6, 23, 0.28);
  border-radius: 16px;
  color: #cbd5e1;
  line-height: 1.45;
  font-size: 0.9rem;
}

.scenario-card { margin-bottom: 0; }
.preset-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}
.preset-grid .preset:first-child { grid-column: span 2; }
.preset-grid .preset:last-child { grid-column: span 2; }
.preset { padding: 9px 8px; font-size: 0.86rem; }

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

.switch-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.switch {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  margin: 0;
  padding: 9px 10px;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.2);
  background: rgba(15, 23, 42, 0.6);
}

.switch input { display: none; }
.switch span {
  width: 30px;
  height: 18px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.32);
  position: relative;
}
.switch span::after {
  content: "";
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: white;
  position: absolute;
  top: 2px;
  left: 2px;
  transition: transform 0.16s ease;
}
.switch input:checked + span { background: #38bdf8; }
.switch input:checked + span::after { transform: translateX(12px); }

.button-row {
  display: grid;
  grid-template-columns: 1fr 1fr 0.7fr;
  gap: 8px;
  margin-top: 14px;
}

.main {
  min-width: 0;
  height: calc(100vh - 36px);
  display: grid;
  grid-template-rows: auto auto 1fr minmax(190px, 0.35fr);
  gap: 14px;
}

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

.status-pill {
  padding: 9px 12px;
  border-radius: 999px;
  color: #bae6fd;
  background: rgba(14, 165, 233, 0.16);
  border: 1px solid rgba(14, 165, 233, 0.3);
  font-weight: 800;
  white-space: nowrap;
}

.kpis {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 14px;
}
.kpi { padding: 14px 16px; }
.kpi span { display: block; color: var(--muted); font-weight: 700; font-size: 0.86rem; }
.kpi strong { display: block; margin-top: 6px; font-size: 1.55rem; letter-spacing: -0.05em; }

.map-wrap {
  position: relative;
  overflow: hidden;
  min-height: 360px;
}
#map { width: 100%; height: 100%; min-height: 360px; background: #0f172a; }
.leaflet-container { font: inherit; }

.map-overlay {
  position: absolute;
  z-index: 500;
  border-radius: 18px;
  border: 1px solid rgba(15, 23, 42, 0.1);
  background: rgba(255, 255, 255, 0.92);
  color: #0f172a;
  box-shadow: 0 18px 55px rgba(15, 23, 42, 0.22);
}
.legend {
  right: 16px;
  top: 16px;
  padding: 12px 14px;
  min-width: 170px;
  line-height: 1.75;
}
.legend strong { display: block; margin-bottom: 4px; }
.dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 8px;
}
.green { background: var(--green); }
.yellow { background: var(--yellow); }
.red { background: var(--red); }
.black { background: var(--black); border: 1px solid #94a3b8; }
.hint {
  left: 16px;
  bottom: 16px;
  padding: 10px 12px;
  font-weight: 800;
}

.bottom-grid {
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
.insights {
  min-height: 0;
  overflow: auto;
  padding: 16px;
}
.section-title { margin-bottom: 12px; }

.warnings-list, .explain-box { color: #dbeafe; }
.warning-item {
  padding: 12px;
  border-radius: 16px;
  border: 1px solid rgba(248, 113, 113, 0.22);
  background: rgba(127, 29, 29, 0.22);
  margin-bottom: 9px;
}
.warning-item strong { display: block; margin-bottom: 4px; }
.warning-item span { color: #fecaca; font-size: 0.9rem; }
.empty-state {
  border: 1px dashed rgba(148, 163, 184, 0.25);
  color: #cbd5e1;
  padding: 14px;
  border-radius: 16px;
}

.explain-box {
  border-radius: 16px;
  border: 1px solid rgba(148, 163, 184, 0.18);
  padding: 14px;
  background: rgba(2, 6, 23, 0.28);
  line-height: 1.55;
}
.explain-box ul { margin: 10px 0 0 18px; padding: 0; }
.explain-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 10px;
}
.explain-columns div {
  border: 1px solid rgba(148, 163, 184, 0.14);
  border-radius: 14px;
  padding: 10px;
  background: rgba(15, 23, 42, 0.34);
}
.warning-inline { color: #fbbf24; font-weight: 800; }
.score-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 56px;
  height: 32px;
  border-radius: 999px;
  color: white;
  font-weight: 900;
  margin-right: 8px;
}

.leaflet-popup-content-wrapper { border-radius: 18px; }
.leaflet-popup-content { margin: 12px 14px; line-height: 1.45; }
.popup-title { font-weight: 900; color: #0f172a; margin-bottom: 5px; }
.popup-meta { color: #475569; }

.condition-icon {
  display: grid;
  place-items: center;
  width: 32px !important;
  height: 32px !important;
  border-radius: 12px;
  background: rgba(15, 23, 42, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.55);
  box-shadow: 0 14px 30px rgba(15, 23, 42, 0.35);
  color: white;
  font-size: 17px;
}

.node-marker {
  width: 18px !important;
  height: 18px !important;
  border-radius: 999px;
  background: #38bdf8;
  border: 3px solid white;
  box-shadow: 0 8px 24px rgba(14, 165, 233, 0.45);
}

@media (max-width: 1120px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { height: auto; max-height: none; }
  .main { height: auto; min-height: 100vh; grid-template-rows: auto auto 620px auto; }
}

@media (max-width: 760px) {
  .app-shell { padding: 10px; gap: 10px; }
  .kpis, .bottom-grid, .form-grid, .explain-columns { grid-template-columns: 1fr; }
  .topbar { align-items: flex-start; flex-direction: column; }
  .button-row { grid-template-columns: 1fr; }
  .legend { left: 12px; right: 12px; top: 12px; }
  .hint { display: none; }
}
