:root {
  --ink: #151513;
  --muted: #6f716b;
  --paper: #f7f7f2;
  --panel: #ffffff;
  --line: #d9dbcf;
  --accent: #1f8f6a;
  --accent-dark: #116045;
  --warning: #cc5e2f;
  --road: #e8e9dd;
  --shadow: 0 22px 60px rgba(42, 53, 38, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100dvh;
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(21, 21, 19, 0.045) 1px, transparent 1px),
    linear-gradient(rgba(21, 21, 19, 0.035) 1px, transparent 1px),
    var(--paper);
  background-size: 36px 36px;
  font-family:
    ui-sans-serif,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
}

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

button {
  cursor: pointer;
}

.shell {
  width: min(1480px, calc(100% - 32px));
  margin: 0 auto;
  padding: 18px 0 28px;
}

.topbar {
  min-height: 70px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  color: white;
  background: var(--ink);
  box-shadow: inset 0 -5px 0 rgba(255, 255, 255, 0.12);
  font-weight: 850;
}

.brand strong,
.brand small {
  display: block;
}

.brand small {
  color: var(--muted);
  font-size: 0.78rem;
  margin-top: 2px;
}

.nav-pills {
  display: flex;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px;
  background: rgba(255, 255, 255, 0.72);
}

.nav-pill {
  border: 0;
  border-radius: 999px;
  padding: 9px 15px;
  color: var(--muted);
  background: transparent;
}

.nav-pill.active {
  color: white;
  background: var(--ink);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(320px, 430px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.planner-panel,
.main-stage,
.ranked-list,
.editor-card,
.view {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: var(--shadow);
}

.planner-panel {
  padding: 24px;
}

.panel-heading h1 {
  max-width: 10ch;
  margin: 8px 0 16px;
  font-size: clamp(2.7rem, 7vw, 5.9rem);
  line-height: 0.92;
  letter-spacing: 0;
}

.panel-heading p:not(.eyebrow) {
  max-width: 34rem;
  margin: 0 0 24px;
  color: var(--muted);
  line-height: 1.55;
}

.eyebrow {
  margin: 0;
  color: var(--accent-dark);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.control-grid,
.candidate-form {
  display: grid;
  gap: 13px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

select,
input[type="text"],
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: white;
}

select,
input[type="text"] {
  min-height: 46px;
  padding: 0 12px;
}

textarea {
  min-height: 540px;
  resize: vertical;
  padding: 16px;
  line-height: 1.5;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.9rem;
}

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

.range-row {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.75rem;
}

.range-row output {
  color: var(--accent-dark);
  font-weight: 900;
}

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

.primary-action,
.secondary-action,
.section-title button,
.metric-stack button {
  min-height: 42px;
  border-radius: 8px;
  font-weight: 850;
}

.primary-action,
.section-title button {
  border: 0;
  color: white;
  background: var(--accent);
  box-shadow: 0 16px 26px rgba(31, 143, 106, 0.18);
}

.primary-action.compact {
  padding: 0 14px;
}

.secondary-action,
.metric-stack button {
  border: 1px solid var(--line);
  color: var(--ink);
  background: white;
}

.agent-strip {
  display: grid;
  gap: 12px;
  margin-top: 24px;
}

.agent-strip article {
  display: grid;
  grid-template-columns: 38px 1fr;
  gap: 4px 12px;
  padding-top: 13px;
  border-top: 1px solid var(--line);
}

.agent-strip span {
  grid-row: span 2;
  color: var(--accent-dark);
  font-weight: 900;
}

.agent-strip p {
  margin: 0;
  color: var(--muted);
  font-size: 0.83rem;
  line-height: 1.42;
}

.main-stage {
  min-width: 0;
  padding: 18px;
}

.view {
  display: none;
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
}

.view.active {
  display: block;
}

.stage-toolbar,
.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.stage-toolbar h2,
.section-title h2 {
  margin: 4px 0 0;
}

.stage-toolbar h2 {
  font-size: clamp(1.7rem, 4vw, 3.2rem);
  line-height: 1;
}

.score-chip {
  width: 96px;
  height: 96px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--ink);
  color: white;
}

.score-chip span,
.score-chip small {
  display: block;
}

.score-chip span {
  align-self: end;
  font-size: 2.35rem;
  font-weight: 900;
}

.score-chip small {
  align-self: start;
  color: rgba(255, 255, 255, 0.7);
}

.map-shell {
  position: relative;
  margin: 18px 0;
}

.map-controls {
  position: absolute;
  z-index: 5;
  top: 12px;
  left: 12px;
  display: flex;
  gap: 6px;
}

.map-controls button {
  min-width: 38px;
  min-height: 34px;
  border: 1px solid rgba(21, 21, 19, 0.12);
  border-radius: 8px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.92);
  font-weight: 900;
  box-shadow: 0 10px 22px rgba(42, 53, 38, 0.1);
}

.map-status {
  position: absolute;
  z-index: 5;
  right: 12px;
  bottom: 12px;
  max-width: min(360px, calc(100% - 24px));
  border: 1px solid rgba(21, 21, 19, 0.1);
  border-radius: 8px;
  padding: 9px 11px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.92);
  font-size: 0.8rem;
  font-weight: 750;
  box-shadow: 0 12px 26px rgba(42, 53, 38, 0.12);
}

.map-canvas {
  position: relative;
  height: 460px;
  min-height: 410px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #eef0e5;
  cursor: crosshair;
}

.map-canvas:focus {
  outline: 3px solid rgba(31, 143, 106, 0.24);
  outline-offset: 3px;
}

.leaflet-container {
  font-family:
    ui-sans-serif,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
}

.leaflet-control-attribution {
  font-size: 0.66rem;
}

.geogrub-marker-wrap,
.draft-marker-wrap {
  background: transparent;
  border: 0;
}

.real-map-marker {
  position: relative;
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  border: 3px solid white;
  border-radius: 999px;
  color: white;
  background: var(--accent);
  box-shadow: 0 8px 24px rgba(17, 96, 69, 0.34);
}

.real-map-marker::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -8px;
  width: 13px;
  height: 13px;
  transform: translateX(-50%) rotate(45deg);
  border-right: 3px solid white;
  border-bottom: 3px solid white;
  background: var(--accent);
}

.real-map-marker.selected {
  background: var(--ink);
  box-shadow: 0 0 0 5px rgba(31, 143, 106, 0.24), 0 8px 24px rgba(17, 96, 69, 0.34);
}

.real-map-marker.selected::after {
  background: var(--ink);
}

.real-map-marker span,
.real-map-marker strong {
  position: relative;
  z-index: 1;
  display: block;
  line-height: 1;
}

.real-map-marker span {
  font-size: 0.72rem;
  font-weight: 950;
}

.real-map-marker strong {
  font-size: 1rem;
}

.draft-real-marker {
  position: relative;
  display: block;
  width: 30px;
  height: 30px;
  border: 3px solid white;
  border-radius: 999px;
  background: var(--warning);
  box-shadow: 0 0 0 4px rgba(204, 94, 47, 0.24), 0 12px 24px rgba(42, 53, 38, 0.2);
}

.draft-real-marker::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -8px;
  width: 10px;
  height: 10px;
  transform: translateX(-50%) rotate(45deg);
  border-right: 3px solid white;
  border-bottom: 3px solid white;
  background: var(--warning);
}

.leaflet-popup-content-wrapper {
  border-radius: 8px;
}

.leaflet-popup-content {
  min-width: 180px;
  margin: 12px;
}

.leaflet-popup-content strong,
.leaflet-popup-content small {
  display: block;
}

.leaflet-popup-content p {
  margin: 6px 0;
  color: var(--muted);
  line-height: 1.35;
}

.map-fallback {
  display: grid;
  place-items: center;
  min-height: 410px;
  padding: 24px;
  color: var(--muted);
  text-align: center;
}

.result-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(300px, 0.8fr);
  gap: 18px;
}

.ranked-list,
.editor-card {
  padding: 18px;
  box-shadow: none;
}

.section-title {
  margin-bottom: 14px;
}

.section-title h2 {
  font-size: 1.1rem;
}

.section-title button {
  padding: 0 12px;
}

.location-card {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  padding: 14px 0;
  border-top: 1px solid var(--line);
}

.location-card.selected {
  background: rgba(31, 143, 106, 0.06);
  margin-inline: -10px;
  padding-inline: 10px;
  border-radius: 8px;
}

.location-card:first-child {
  border-top: 0;
}

.rank {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: white;
  background: var(--ink);
  font-weight: 900;
}

.location-card h3 {
  margin: 0 0 5px;
  font-size: 1rem;
}

.location-card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.38;
}

.driver-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.driver-row span {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 8px;
  color: var(--muted);
  background: white;
  font-size: 0.72rem;
  font-weight: 800;
}

.metric-stack {
  display: grid;
  justify-items: end;
  gap: 5px;
}

.fit-score {
  color: var(--accent-dark);
  font-weight: 950;
  font-size: 1.35rem;
}

.risk {
  color: var(--warning);
  font-size: 0.78rem;
  font-weight: 800;
}

.metric-stack button {
  min-height: 30px;
  padding: 0 10px;
  color: var(--muted);
  font-size: 0.75rem;
}

.coordinate-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.7);
  font-size: 0.8rem;
  font-weight: 800;
}

.coordinate-row button,
.weather-card button {
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: white;
  font-weight: 850;
}

.weather-card {
  display: grid;
  gap: 8px;
  border: 1px solid rgba(31, 143, 106, 0.22);
  border-radius: 8px;
  padding: 10px;
  color: var(--accent-dark);
  background: rgba(31, 143, 106, 0.07);
  font-size: 0.82rem;
  font-weight: 800;
  line-height: 1.35;
}

.weather-card button {
  justify-self: start;
}

.weather-card button:disabled {
  cursor: wait;
  opacity: 0.65;
}

.slider-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 12px;
}

.route-list {
  display: grid;
  gap: 12px;
  margin: 18px 0 0;
  padding: 0;
  list-style: none;
}

.route-list li {
  display: grid;
  grid-template-columns: 96px 1fr;
  gap: 16px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}

.time {
  color: var(--accent-dark);
  font-weight: 950;
}

.stop strong {
  display: block;
}

.stop span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  line-height: 1.4;
}

@media (max-width: 1120px) {
  .workspace,
  .result-grid {
    grid-template-columns: 1fr;
  }

  .panel-heading h1 {
    max-width: 13ch;
  }
}

@media (max-width: 680px) {
  .shell {
    width: min(100% - 20px, 1480px);
    padding-top: 10px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .nav-pills,
  .button-row,
  .slider-grid {
    width: 100%;
    grid-template-columns: 1fr;
  }

  .nav-pills {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
  }

  .nav-pill {
    padding-inline: 6px;
  }

  .planner-panel,
  .main-stage,
  .ranked-list,
  .editor-card {
    padding: 16px;
  }

  .stage-toolbar {
    align-items: flex-start;
  }

  .score-chip {
    width: 78px;
    height: 78px;
  }

  .score-chip span {
    font-size: 1.9rem;
  }

  .map-canvas {
    min-height: 500px;
  }

  .location-card {
    grid-template-columns: 44px minmax(0, 1fr);
  }

  .metric-stack {
    grid-column: 2;
    justify-items: start;
  }

  .route-list li {
    grid-template-columns: 1fr;
  }
}
