* {
  box-sizing: border-box;
}

:root {
  --paper: #f3f2ee;
  --surface: #ffffff;
  --surface-soft: #f7f7f4;
  --ink: #25282b;
  --muted: #73787d;
  --line: #deded8;
  --line-strong: #cecec7;
  --blue: #1769e0;
  --blue-dark: #1058c2;
  --danger: #a52a20;
  --radius: 15px;
  --shadow: 0 7px 22px rgba(24, 28, 31, .055);
  --max-width: 1040px;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  line-height: 1.42;
  -webkit-font-smoothing: antialiased;
}

button,
input {
  font: inherit;
}

button {
  min-height: 44px;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: .55;
}

/* Header */

.topbar {
  background: rgba(255, 255, 255, .96);
  border-bottom: 1px solid var(--line);
}

.header-inner {
  width: min(var(--max-width), calc(100% - 32px));
  min-height: 60px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  font-size: 1.08rem;
  font-weight: 850;
  letter-spacing: -.03em;
}

.header-actions {
  display: flex;
  gap: 7px;
}

.header-button {
  min-height: 40px;
  padding: 7px 11px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface);
  color: #34383c;
  font-size: .8rem;
  font-weight: 750;
}

.header-button:hover {
  background: var(--surface-soft);
}

/* Main desktop workspace */

.app-shell {
  width: min(var(--max-width), calc(100% - 32px));
  margin: 18px auto 30px;
}

.workspace {
  display: grid;
  grid-template-columns: 310px minmax(0, 1fr);
  gap: 14px;
  align-items: stretch;
}

.planner-card {
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.planner-heading {
  margin-bottom: 17px;
}

.eyebrow,
.panel-kicker,
.section-label {
  display: block;
  color: var(--blue);
  font-size: .62rem;
  font-weight: 850;
  letter-spacing: .13em;
}

.planner-heading h1 {
  margin: 4px 0 0;
  font-size: 1.35rem;
  line-height: 1.1;
  letter-spacing: -.035em;
}

/* Connected From -> Stops -> To stack */

.route-stack {
  position: relative;
}

.route-stack::before {
  content: "";
  position: absolute;
  left: 7px;
  top: 13px;
  bottom: 22px;
  width: 1px;
  background: var(--line-strong);
}

.route-field {
  position: relative;
  display: grid;
  grid-template-columns: 16px 1fr;
  gap: 9px;
}

.route-dot {
  position: relative;
  z-index: 1;
  width: 15px;
  height: 15px;
  margin-top: 28px;
  border: 3px solid var(--surface);
  border-radius: 50%;
  background: var(--blue);
  box-shadow: 0 0 0 1px var(--line-strong);
}

.end-dot {
  background: var(--ink);
}

.route-stops {
  position: relative;
  margin-left: 25px;
}

.route-stops .stop-row {
  position: relative;
  margin-left: 0;
}

.route-stops .stop-row::before {
  content: "";
  position: absolute;
  left: -19px;
  top: 28px;
  width: 7px;
  height: 7px;
  border: 2px solid var(--surface);
  border-radius: 50%;
  background: var(--muted);
  box-shadow: 0 0 0 1px var(--line-strong);
}

.route-stops .remove-stop {
  min-width: 42px;
}

.field {
  margin-bottom: 11px;
}

.field label {
  display: block;
  margin-bottom: 5px;
  color: #555a5e;
  font-size: .7rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .025em;
}

.field input {
  width: 100%;
  min-height: 44px;
  padding: 9px 11px;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  outline: none;
  background: var(--surface);
  color: var(--ink);
  font-size: .88rem;
}

.field input::placeholder {
  color: #999d9f;
}

.field input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(23, 105, 224, .1);
}

.stop-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 7px;
}

.remove-stop {
  align-self: end;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface);
  color: var(--muted);
  font-size: 1rem;
}

.planner-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
  margin: 1px 0 14px;
}

.secondary {
  min-height: 44px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface);
  color: #363a3e;
  font-size: .79rem;
  font-weight: 750;
}

.secondary:hover {
  background: var(--surface-soft);
}

.vehicle-block {
  padding-top: 12px;
  margin-bottom: 13px;
  border-top: 1px solid var(--line);
}

.section-label {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: .6rem;
}

.vehicle-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.compact {
  margin-bottom: 0;
}

.primary {
  width: 100%;
  min-height: 46px;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  border: 0;
  border-radius: 9px;
  background: var(--blue);
  color: #fff;
  font-size: .9rem;
  font-weight: 800;
  box-shadow: 0 3px 8px rgba(23, 105, 224, .16);
}

.primary:hover {
  background: var(--blue-dark);
}

.button-arrow {
  font-size: 1.05rem;
}

.status {
  min-height: 18px;
  margin-top: 6px;
  color: var(--muted);
  font-size: .73rem;
}

.status.error {
  color: var(--danger);
}

/* Totals are part of the planner */

.summary-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  margin-top: 11px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-soft);
}

.metric {
  min-width: 0;
  padding: 9px 6px 10px;
  text-align: center;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.metric:nth-child(2n) {
  border-right: 0;
}

.metric:nth-last-child(-n + 2) {
  border-bottom: 0;
}

.metric-label {
  display: block;
  color: var(--muted);
  font-size: .57rem;
  font-weight: 850;
  letter-spacing: .1em;
  text-transform: uppercase;
}

.metric strong {
  display: block;
  margin-top: 1px;
  color: #1f2327;
  font-size: 1.28rem;
  line-height: 1.1;
  letter-spacing: -.04em;
}

/* Map */

.map-card {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

#map,
.leaflet-container {
  width: 100%;
  height: 100%;
  min-height: 520px;
}

.leaflet-routing-container {
  display: none !important;
}

/* Bottom trip sheet */

.route-sheet {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  gap: 14px;
  margin-top: 14px;
}

.panel {
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 57px;
  padding: 11px 14px;
  border-bottom: 1px solid var(--line);
}

.panel-heading h2 {
  margin: 2px 0 0;
  font-size: .86rem;
  font-weight: 800;
  letter-spacing: -.015em;
}

#stopCount {
  color: var(--muted);
  font-size: .72rem;
}

.stop-list {
  margin: 0;
  padding: 9px 13px 12px 29px;
}

.stop-list li {
  padding: 5px 0;
  font-size: .8rem;
}

.empty {
  color: var(--muted);
  padding: 14px;
}

.instructions {
  max-height: 400px;
  overflow: auto;
}

.instruction {
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: 7px;
  padding: 9px 13px;
  border-bottom: 1px solid #ecece7;
  font-size: .81rem;
}

.instruction:last-child {
  border-bottom: 0;
}

.instruction-index {
  color: var(--blue);
  font-weight: 850;
  text-align: center;
}

.instruction-distance {
  display: block;
  margin-top: 1px;
  color: var(--muted);
  font-size: .69rem;
}

.external-links {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 12px;
}

.footer {
  padding: 11px 2px 0;
  color: var(--muted);
  font-size: .67rem;
}

/* Tablet/mobile: planner becomes top sheet, map follows */

@media (max-width: 760px) {
  .workspace {
    display: block;
  }

  .planner-card {
    margin-bottom: 12px;
  }

  .map-card {
    box-shadow: none;
  }

  #map,
  .leaflet-container {
    height: 420px;
    min-height: 420px;
  }

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

@media (max-width: 600px) {
  .header-inner,
  .app-shell {
    width: calc(100% - 24px);
  }

  .header-inner {
    min-height: 58px;
  }

  .app-shell {
    margin-top: 11px;
  }

  .planner-card {
    padding: 15px;
  }

  .external-links {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 430px) {
  .header-button {
    padding: 7px 9px;
    font-size: .75rem;
  }

  .planner-actions,
  .vehicle-row {
    grid-template-columns: 1fr;
  }

  .summary-grid {
    grid-template-columns: repeat(4, 1fr);
  }

  .metric {
    border-right: 1px solid var(--line) !important;
    border-bottom: 0 !important;
  }

  .metric:last-child {
    border-right: 0 !important;
  }

  .metric-label {
    font-size: .51rem;
  }

  .metric strong {
    font-size: 1.05rem;
  }
}

/* Printable day ticket */

@media print {
  @page {
    margin: .42in;
  }

  html,
  body {
    background: #fff;
    color: #000;
  }

  .print-hide,
  .leaflet-control-container,
  .leaflet-routing-container {
    display: none !important;
  }

  .app-shell {
    width: 100%;
    margin: 0;
  }

  .workspace {
    display: block;
  }

  .map-card {
    border: 0;
    box-shadow: none;
  }

  #map {
    height: 3.7in;
    min-height: 0;
    border: 1px solid #aaa;
    border-radius: 0;
  }

  .summary-grid {
    margin-top: 9px;
    border-color: #aaa;
    background: #fff;
  }

  .metric {
    border-color: #aaa !important;
  }

  .metric strong,
  .metric-label {
    color: #000;
  }

  .route-sheet {
    grid-template-columns: 32% 68%;
    gap: 9px;
    margin-top: 9px;
  }

  .panel {
    border-color: #aaa;
    border-radius: 0;
    box-shadow: none;
    break-inside: avoid;
  }

  .instructions {
    max-height: none;
    overflow: visible;
  }

  .footer {
    display: none !important;
  }
}
