:root {
  --ink: #14212d;
  --muted: #5f6f7f;
  --line: #d9e2e8;
  --paper: #f7fafb;
  --panel: #ffffff;
  --brand: #17324d;
  --brand-soft: #e8f0f7;
  --green: #16845b;
  --green-soft: #e8f7ef;
  --amber: #b96b12;
  --amber-soft: #fff3dd;
  --red: #bd3d33;
  --red-soft: #ffebe8;
  --blue: #2364aa;
  --blue-soft: #e8f1fb;
  --shadow: 0 18px 50px rgba(16, 35, 54, 0.12);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-width: 320px;
  background:
    linear-gradient(180deg, rgba(232, 240, 247, 0.75), rgba(247, 250, 251, 0) 360px),
    var(--paper);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

a {
  color: inherit;
  text-decoration: none;
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 14px clamp(16px, 4vw, 32px);
  border-bottom: 1px solid rgba(217, 226, 232, 0.9);
  background: rgba(247, 250, 251, 0.92);
  backdrop-filter: blur(14px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 180px;
}

.brand img {
  width: 42px;
  height: 42px;
  border-radius: 8px;
}

.brand span {
  display: grid;
  line-height: 1.1;
}

.brand strong {
  font-size: 1.08rem;
}

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

.nav-tabs {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.nav-tab {
  min-width: 88px;
  padding: 10px 12px;
  border-radius: 6px;
  color: var(--muted);
  font-weight: 700;
  text-align: center;
}

.nav-tab.active {
  background: var(--brand);
  color: #fff;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(310px, 385px) minmax(0, 1fr);
  gap: 18px;
  width: min(1500px, 100%);
  margin: 0 auto;
  padding: 18px clamp(14px, 3vw, 32px) 32px;
}

.control-panel,
.main-panel {
  min-width: 0;
}

.control-panel {
  display: grid;
  align-content: start;
  gap: 14px;
}

.panel-section,
.content-band,
.metric-card,
.recommendation-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.panel-section {
  padding: 18px;
}

.panel-section.compact {
  box-shadow: none;
}

.section-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
}

.section-heading.row {
  align-items: center;
}

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

h1 {
  max-width: 18ch;
  margin-bottom: 0;
  font-size: clamp(1.45rem, 2vw, 2rem);
  line-height: 1.02;
}

h2 {
  margin-bottom: 0;
  font-size: 1.24rem;
  line-height: 1.2;
}

h3 {
  margin-bottom: 8px;
  font-size: 1.02rem;
}

.eyebrow {
  margin-bottom: 6px;
  color: var(--blue);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.provider-pill,
.section-heading span,
.summary-list dt,
.metric-card span,
.metric-card small,
.condition-card small,
.stop-card small {
  color: var(--muted);
  font-size: 0.82rem;
}

.provider-pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 5px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--brand-soft);
  color: var(--brand);
  font-weight: 800;
  white-space: nowrap;
}

.provider-pill.live {
  background: var(--green-soft);
  color: var(--green);
}

.provider-pill.fallback {
  background: var(--amber-soft);
  color: var(--amber);
}

.inline-status {
  margin-top: 12px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
}

.planner-form,
.truck-form,
.adapter-form {
  display: grid;
  gap: 14px;
}

label,
.choice-group label {
  display: grid;
  gap: 7px;
  color: var(--ink);
  font-weight: 700;
}

label span,
legend {
  color: var(--muted);
  font-size: 0.82rem;
}

input[type="text"],
input[type="number"],
input[type="password"],
input[type="url"],
input:not([type]) {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}

input:focus-visible,
button:focus-visible,
a:focus-visible {
  outline: 3px solid rgba(35, 100, 170, 0.28);
  outline-offset: 2px;
}

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

output {
  color: var(--green);
  font-weight: 800;
}

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

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

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

.choice-group {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.choice-group label,
.filter-row label,
.switch-row {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  font-size: 0.92rem;
}

input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--green);
}

.primary-action,
.ghost-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  border-radius: 8px;
  font-weight: 800;
}

.primary-action {
  border: 0;
  background: var(--green);
  color: #fff;
}

.primary-action span {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.22);
  font-size: 1.05rem;
}

.ghost-button {
  padding: 0 12px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--brand);
}

.ghost-button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-width: 2.2;
}

.summary-list {
  display: grid;
  gap: 12px;
  margin: 0;
}

.summary-list div {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.summary-list div:last-child {
  padding-bottom: 0;
  border-bottom: 0;
}

.summary-list dd {
  margin: 0;
  font-weight: 800;
  text-align: right;
}

.main-panel {
  display: grid;
}

.view {
  display: none;
  min-width: 0;
}

.view.active {
  display: grid;
  gap: 16px;
}

.map-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.route-canvas {
  position: relative;
  min-height: 330px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(217, 226, 232, 0.65) 1px, transparent 1px),
    linear-gradient(0deg, rgba(217, 226, 232, 0.55) 1px, transparent 1px),
    #fafdff;
  background-size: 46px 46px;
  box-shadow: var(--shadow);
}

.route-map {
  display: none;
  position: relative;
  width: 100%;
  min-height: 430px;
  height: clamp(430px, 54vh, 680px);
  background: #edf4f7;
}

.route-canvas.map-ready {
  background: #edf4f7;
}

.route-canvas.map-ready .route-map {
  display: block;
}

.route-canvas.map-ready #route-svg {
  display: none;
}

.map-pin {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border: 3px solid #fff;
  border-radius: 999px;
  background: var(--green);
  color: #fff;
  box-shadow: 0 8px 20px rgba(20, 33, 45, 0.28);
  font-size: 0.76rem;
  font-weight: 900;
}

.map-pin.rest {
  background: var(--blue);
}

.map-pin.best,
.map-pin.gps {
  width: 34px;
  height: 34px;
  background: var(--brand);
}

.map-pin.weather {
  background: var(--amber);
}

.map-pin.traffic {
  background: var(--red);
}

.route-map.static-map {
  overflow: hidden;
  background: #dbe7ed;
}

.static-map-stage,
.static-map-overlay {
  position: absolute;
  inset: 0;
}

.static-map-stage {
  overflow: hidden;
}

.static-map-tile {
  position: absolute;
  width: 256px;
  height: 256px;
  user-select: none;
}

.static-map-overlay {
  pointer-events: none;
}

.static-route-line,
.static-window-line,
.static-traffic-line {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.static-route-line {
  stroke: rgba(20, 33, 45, 0.36);
  stroke-width: 13;
}

.static-window-line {
  stroke: var(--green);
  stroke-width: 11;
}

.static-traffic-line {
  stroke: var(--amber);
  stroke-width: 9;
}

.static-traffic-line.high {
  stroke: var(--red);
}

.static-map-marker {
  position: absolute;
  z-index: 4;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  padding: 0;
  transform: translate(-50%, -50%);
  border: 3px solid #fff;
  border-radius: 999px;
  background: var(--green);
  color: #fff;
  box-shadow: 0 8px 20px rgba(20, 33, 45, 0.3);
  font-size: 0.76rem;
  font-weight: 900;
  line-height: 1;
}

.static-map-marker.rest {
  background: var(--blue);
}

.static-map-marker.best,
.static-map-marker.gps {
  width: 36px;
  height: 36px;
  background: var(--brand);
}

.static-map-marker.weather {
  background: var(--amber);
}

.static-map-marker.traffic {
  background: var(--red);
}

.static-map-legend,
.static-map-popup,
.static-map-attribution {
  position: absolute;
  z-index: 5;
  border: 1px solid rgba(217, 226, 232, 0.92);
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 10px 30px rgba(20, 33, 45, 0.16);
  backdrop-filter: blur(8px);
}

.static-map-legend {
  top: 12px;
  left: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  max-width: min(560px, calc(100% - 24px));
  padding: 8px;
  border-radius: 8px;
}

.static-map-legend span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--muted);
  font-size: 0.73rem;
  font-weight: 900;
}

.static-map-legend span::before {
  content: "";
  width: 18px;
  height: 4px;
  border-radius: 999px;
  background: var(--brand);
}

.static-map-legend .legend-window::before {
  background: var(--green);
}

.static-map-legend .legend-stop::before {
  width: 10px;
  height: 10px;
  background: var(--blue);
}

.static-map-legend .legend-weather::before {
  width: 10px;
  height: 10px;
  background: var(--amber);
}

.static-map-legend .legend-traffic::before {
  background: var(--red);
}

.static-map-popup {
  right: 12px;
  bottom: 28px;
  display: grid;
  gap: 4px;
  width: min(320px, calc(100% - 24px));
  padding: 12px;
  border-radius: 8px;
}

.static-map-popup strong {
  font-size: 0.95rem;
}

.static-map-popup small {
  color: var(--muted);
  font-size: 0.78rem;
}

.static-map-attribution {
  right: 8px;
  bottom: 6px;
  padding: 2px 6px;
  border-radius: 6px;
  color: var(--muted);
  font-size: 0.68rem;
  box-shadow: none;
}

.leaflet-popup-content {
  min-width: 190px;
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

.leaflet-popup-content strong {
  display: block;
  margin-bottom: 4px;
}

.leaflet-popup-content small {
  display: block;
  color: var(--muted);
}

#route-svg {
  display: block;
  width: 100%;
  min-height: 330px;
}

.route-line {
  fill: none;
  stroke: #8ea6b8;
  stroke-linecap: round;
  stroke-width: 18;
}

.route-progress {
  fill: none;
  stroke: var(--green);
  stroke-linecap: round;
  stroke-width: 18;
}

.route-warning {
  fill: none;
  stroke: var(--amber);
  stroke-linecap: round;
  stroke-width: 20;
}

.route-bad {
  fill: none;
  stroke: var(--red);
  stroke-linecap: round;
  stroke-width: 20;
}

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

.map-subtext {
  fill: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.marker-stop {
  fill: #fff;
  stroke: var(--green);
  stroke-width: 5;
}

.marker-rest {
  fill: #fff;
  stroke: var(--blue);
  stroke-width: 5;
}

.marker-best {
  fill: var(--green);
  stroke: #fff;
  stroke-width: 5;
}

.marker-weather {
  fill: var(--amber);
  stroke: #fff;
  stroke-width: 4;
}

.range-band {
  fill: rgba(22, 132, 91, 0.11);
  stroke: rgba(22, 132, 91, 0.28);
  stroke-width: 2;
}

.insight-grid,
.condition-grid,
.gps-dashboard {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.metric-card,
.gps-card {
  display: grid;
  gap: 8px;
  padding: 16px;
  box-shadow: none;
}

.metric-card strong,
.gps-card strong {
  font-size: 1.15rem;
}

.gps-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.gps-card span,
.gps-card small {
  color: var(--muted);
  font-size: 0.82rem;
}

.gps-card-primary {
  border-left: 5px solid var(--blue);
}

.gps-actions {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.gps-next-stop {
  display: grid;
  gap: 12px;
}

.accent-green {
  border-left: 5px solid var(--green);
}

.accent-amber {
  border-left: 5px solid var(--amber);
}

.accent-red {
  border-left: 5px solid var(--red);
}

.content-band {
  padding: 18px;
}

.stop-list,
.condition-list,
.recommendation-stack {
  display: grid;
  gap: 12px;
}

.stop-card,
.condition-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.stop-card strong,
.condition-card strong {
  display: block;
  margin-bottom: 4px;
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 25px;
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--blue-soft);
  color: #194d85;
  font-size: 0.75rem;
  font-weight: 800;
}

.tag.green {
  background: var(--green-soft);
  color: var(--green);
}

.tag.amber {
  background: var(--amber-soft);
  color: var(--amber);
}

.tag.red {
  background: var(--red-soft);
  color: var(--red);
}

.availability {
  min-width: 104px;
  text-align: right;
}

.availability strong {
  color: var(--green);
}

.recommendation-card {
  display: grid;
  gap: 12px;
  padding: 18px;
  box-shadow: none;
}

.recommendation-card.best {
  border-color: rgba(22, 132, 91, 0.42);
  background: linear-gradient(135deg, var(--green-soft), #fff 54%);
}

.recommendation-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.score-badge {
  display: grid;
  place-items: center;
  min-width: 64px;
  min-height: 46px;
  border-radius: 8px;
  background: var(--brand);
  color: #fff;
  font-weight: 900;
}

.reason-list {
  display: grid;
  gap: 7px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.reason-list li {
  display: flex;
  gap: 8px;
  color: var(--muted);
}

.reason-list li::before {
  content: "";
  flex: 0 0 auto;
  width: 8px;
  height: 8px;
  margin-top: 8px;
  border-radius: 50%;
  background: var(--green);
}

.filter-row,
.adapter-grid,
.adapter-status-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.filter-row label,
.adapter-grid span,
.adapter-status {
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

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

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

.severity-low {
  border-left: 5px solid var(--green);
}

.severity-medium {
  border-left: 5px solid var(--amber);
}

.severity-high {
  border-left: 5px solid var(--red);
}

.integration-band p {
  max-width: 70ch;
  color: var(--muted);
  line-height: 1.55;
}

.adapter-grid span {
  color: var(--brand);
  font-size: 0.88rem;
  font-weight: 800;
}

.adapter-status {
  display: grid;
  gap: 2px;
  min-width: 150px;
}

.adapter-status strong {
  font-size: 0.82rem;
}

.adapter-status small {
  color: var(--muted);
  font-size: 0.75rem;
}

.adapter-status.live {
  border-color: rgba(22, 132, 91, 0.32);
  background: var(--green-soft);
}

.adapter-status.fallback {
  border-color: rgba(185, 107, 18, 0.32);
  background: var(--amber-soft);
}

.adapter-status.skipped {
  background: var(--brand-soft);
}

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

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

@media (max-width: 760px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
    gap: 12px;
  }

  .brand {
    min-width: 0;
  }

  .nav-tabs {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    overflow-x: visible;
  }

  .nav-tab {
    min-width: 0;
  }

  .workspace {
    padding-top: 12px;
  }

  .control-panel,
  .insight-grid,
  .condition-grid,
  .gps-dashboard {
    grid-template-columns: 1fr;
  }

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

  .form-grid.two,
  .form-grid.three {
    grid-template-columns: 1fr;
  }

  .map-header,
  .section-heading,
  .section-heading.row,
  .recommendation-top {
    align-items: stretch;
    flex-direction: column;
  }

  .ghost-button {
    width: 100%;
  }

  .route-canvas,
  #route-svg,
  .route-map {
    min-height: 300px;
  }

  .static-map-legend {
    top: 8px;
    left: 8px;
    max-width: calc(100% - 16px);
  }

  .static-map-popup {
    right: 8px;
    bottom: 28px;
    width: calc(100% - 16px);
  }

  .stop-card {
    grid-template-columns: 1fr;
  }

  .availability {
    text-align: left;
  }
}
