:root {
  color-scheme: light;
  --bg: #eef1ed;
  --surface: #fbfcf8;
  --panel: #ffffff;
  --ink: #18211b;
  --muted: #617066;
  --line: #d5ddd2;
  --accent: #236857;
  --accent-2: #b44d2f;
  --accent-soft: #e0eee8;
  --warn: #886014;
  --warn-bg: #fff3d4;
  --bad: #9d2f2f;
  --bad-bg: #ffe6e3;
  --good: #1f6f4a;
  --good-bg: #e4f3e7;
  --shadow: 0 20px 48px rgba(38, 48, 42, 0.1);
  --radius: 8px;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background:
    linear-gradient(135deg, rgba(35, 104, 87, 0.14), transparent 32rem),
    linear-gradient(315deg, rgba(180, 77, 47, 0.1), transparent 28rem),
    var(--bg);
  color: var(--ink);
}

button,
input {
  font: inherit;
}

button {
  min-height: 40px;
  border-radius: var(--radius);
  cursor: pointer;
}

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

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

.topbar {
  max-width: 1440px;
  margin: 0 auto 18px;
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: end;
}

.brand,
.kicker {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 850;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  max-width: 780px;
  font-size: clamp(2rem, 5vw, 4.8rem);
  line-height: 0.94;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 0;
  font-size: 1.1rem;
  line-height: 1.15;
}

.mode-pill,
.traffic-warning {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.7);
  color: var(--muted);
  font-size: 0.86rem;
}

.dot {
  width: 9px;
  height: 9px;
  display: inline-block;
  margin-right: 7px;
  border-radius: 50%;
  background: var(--accent-2);
}

.workspace {
  max-width: 1440px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(390px, 0.82fr) minmax(0, 1.18fr);
  gap: 18px;
  align-items: start;
}

.planner-panel,
.results-panel,
.map-panel,
.timeline-panel,
.summary-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.planner-panel,
.results-panel {
  padding: 18px;
}

.panel-heading,
.stop-header,
.section-title,
.summary-actions,
.action-row,
.timeline-topline,
.reorder-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.stop-header {
  margin-top: 22px;
}

.stop-header p,
.section-title p,
.empty-state p,
.form-status,
.metric span,
.timeline-item p {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

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

label {
  display: grid;
  gap: 7px;
  min-width: 0;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
  text-transform: uppercase;
}

input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 11px;
  background: var(--surface);
  color: var(--ink);
  text-transform: none;
}

input:focus,
button:focus {
  outline: 3px solid rgba(35, 104, 87, 0.2);
  outline-offset: 2px;
}

.stop-list {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.stop-row {
  display: grid;
  grid-template-columns: 32px minmax(90px, 0.8fr) minmax(130px, 1.2fr) 96px 96px;
  gap: 8px;
  align-items: end;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.stop-row label:nth-of-type(5) {
  grid-column: 2 / span 1;
}

.stop-row .icon-button {
  grid-column: 5;
  justify-self: end;
}

.stop-index,
.timeline-order {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-weight: 850;
}

.primary-button,
.ghost-button,
.icon-button,
.reorder-row button {
  border: 1px solid var(--accent);
  font-weight: 850;
}

.primary-button {
  min-width: 170px;
  background: var(--accent);
  color: #fff;
}

.ghost-button,
.icon-button,
.reorder-row button {
  background: var(--surface);
  color: var(--accent);
}

.icon-button {
  width: 40px;
  font-size: 1.1rem;
}

.action-row {
  margin-top: 16px;
}

.form-status {
  margin: 0;
  min-height: 20px;
  text-align: right;
}

.empty-state {
  min-height: 620px;
  display: grid;
  align-content: center;
  padding: 24px;
}

.empty-state h2 {
  max-width: 520px;
  font-size: clamp(1.8rem, 4vw, 3.4rem);
}

.result-content {
  display: grid;
  gap: 14px;
}

.route-health {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}

.route-health h2 {
  font-size: clamp(1.5rem, 3vw, 2.7rem);
}

.route-health.is-good {
  background: var(--good-bg);
  border-color: rgba(31, 111, 74, 0.28);
}

.route-health.is-bad {
  background: var(--bad-bg);
  border-color: rgba(157, 47, 47, 0.3);
}

.traffic-warning {
  max-width: 370px;
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.58);
  line-height: 1.45;
}

.map-timeline-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 0.86fr);
  gap: 14px;
}

.map-panel,
.timeline-panel,
.summary-panel {
  box-shadow: none;
  padding: 14px;
}

.route-map {
  margin-top: 12px;
  min-height: 420px;
  border-radius: var(--radius);
  overflow: hidden;
  background: #edf2ed;
  color: var(--accent);
}

.route-map svg {
  width: 100%;
  height: 100%;
  min-height: 420px;
  display: block;
}

.map-marker circle {
  fill: var(--accent);
  stroke: #fff;
  stroke-width: 4;
}

.map-marker text {
  fill: #fff;
  font-size: 14px;
  font-weight: 850;
  text-anchor: middle;
}

.timeline {
  max-height: 520px;
  margin: 12px 0 0;
  padding: 0;
  overflow: auto;
  display: grid;
  gap: 10px;
  list-style: none;
}

.timeline-item {
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr);
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-left-width: 5px;
  border-radius: var(--radius);
  background: var(--surface);
}

.timeline-item.is-on-time {
  border-left-color: var(--good);
}

.timeline-item.is-tight {
  border-left-color: var(--warn);
  background: var(--warn-bg);
}

.timeline-item.is-late {
  border-left-color: var(--bad);
  background: var(--bad-bg);
}

.timeline-topline span {
  flex: 0 0 auto;
  border-radius: 999px;
  padding: 4px 8px;
  background: rgba(255, 255, 255, 0.72);
  font-size: 0.78rem;
  font-weight: 850;
}

.timeline-item dl {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 12px 0;
}

.timeline-item dl div {
  min-width: 0;
}

.timeline-item dt {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 850;
  text-transform: uppercase;
}

.timeline-item dd {
  margin: 3px 0 0;
  font-weight: 750;
}

.reorder-row {
  justify-content: flex-start;
}

.reorder-row button {
  min-height: 32px;
  padding: 0 9px;
  font-size: 0.82rem;
}

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

.metric {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  background: var(--surface);
}

.metric p {
  margin: 0 0 7px;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 850;
  text-transform: uppercase;
}

.metric strong {
  display: block;
  font-size: 1.25rem;
}

.summary-actions {
  margin-top: 12px;
}

.dispatch-summary {
  margin: 12px 0 0;
  white-space: pre-wrap;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  background: #151b18;
  color: #ecf6ef;
  font-size: 0.9rem;
  line-height: 1.55;
  overflow: auto;
}

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

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

@media (max-width: 760px) {
  .app-shell {
    padding: 12px;
  }

  .topbar,
  .route-health,
  .panel-heading,
  .stop-header,
  .action-row {
    align-items: stretch;
    flex-direction: column;
  }

  .setup-grid,
  .metric-grid,
  .timeline-item dl {
    grid-template-columns: 1fr;
  }

  .stop-row {
    grid-template-columns: 32px 1fr;
  }

  .address-field,
  .stop-row .icon-button {
    grid-column: 1 / -1;
  }

  .form-status {
    text-align: left;
  }
}
