:root {
  color-scheme: light;
  --blue: #0b57d0;
  --blue-dark: #073d95;
  --blue-soft: #e8f0fe;
  --green: #137333;
  --green-soft: #e6f4ea;
  --red: #c5221f;
  --ink: #202124;
  --muted: #5f6368;
  --line: #dadce0;
  --surface: #ffffff;
  --canvas: #f1f3f4;
  --shadow: 0 4px 16px rgba(32, 33, 36, 0.16), 0 1px 3px rgba(32, 33, 36, 0.12);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { color: var(--ink); background: var(--canvas); font-size: 16px; }
button, input { font: inherit; }
button { color: inherit; }

.app-shell { min-height: 100dvh; display: grid; grid-template-columns: minmax(360px, 430px) 1fr; }
.map-wrap { grid-column: 2; grid-row: 1; position: relative; min-height: 100dvh; overflow: hidden; background: #dfe8e0; }
#map, .map-fallback { position: absolute; inset: 0; }
#map { z-index: 1; }
.map-fallback { z-index: 0; background: linear-gradient(145deg, #dce9d8, #e8ecdf 46%, #d3e6ea); }
.fallback-road { position: absolute; height: 14px; width: 140%; left: -20%; border: 4px solid #fff; background: #d4d0c8; box-shadow: 0 0 0 1px #c6c2ba; transform-origin: center; }
.road-a { top: 25%; transform: rotate(18deg); }
.road-b { top: 55%; transform: rotate(-12deg); }
.road-c { top: 72%; transform: rotate(8deg); }

.brand-pill, .data-chip, .locate-button { position: absolute; z-index: 500; background: rgba(255,255,255,.96); box-shadow: var(--shadow); }
.brand-pill { top: max(18px, env(safe-area-inset-top)); left: 18px; display: flex; align-items: center; gap: 9px; height: 44px; padding: 0 16px 0 9px; border-radius: 22px; font-weight: 700; letter-spacing: -.01em; }
.brand-mark { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50% 50% 50% 8px; transform: rotate(-45deg); color: white; background: var(--blue); font-weight: 800; }
.brand-mark::first-letter { transform: rotate(45deg); }
.data-chip { bottom: 18px; right: 18px; display: flex; align-items: center; gap: 8px; padding: 9px 12px; border: 0; border-radius: 18px; color: var(--muted); font-size: .78rem; font-weight: 650; cursor: pointer; }
.data-chip:hover { color: var(--blue); }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 3px var(--green-soft); }
.live-dot.disconnected { background: #9aa0a6; box-shadow: 0 0 0 3px #eef0f1; }
.locate-button { right: 18px; top: 18px; width: 44px; height: 44px; border: 0; border-radius: 50%; display: grid; place-items: center; cursor: pointer; }
.locate-button:hover { background: #f8fafd; }
.locate-button svg { width: 22px; fill: none; stroke: var(--blue); stroke-width: 2; }

.planner { grid-column: 1; grid-row: 1; z-index: 600; min-height: 100dvh; padding: 30px 24px 28px; background: var(--surface); box-shadow: 4px 0 18px rgba(32, 33, 36, .12); overflow-y: auto; }
.drag-handle { display: none; }
.planner-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 22px; }
.eyebrow { margin: 0 0 5px; color: var(--blue); text-transform: uppercase; letter-spacing: .1em; font-size: .72rem; font-weight: 800; }
h1 { margin: 0; max-width: 320px; font-size: clamp(1.7rem, 3vw, 2.15rem); line-height: 1.12; letter-spacing: -.045em; }
.icon-button { width: 42px; height: 42px; margin-top: 8px; border: 1px solid var(--line); border-radius: 50%; background: #fff; display: grid; place-items: center; cursor: pointer; }
.icon-button:hover { background: var(--blue-soft); border-color: transparent; }
.icon-button svg { width: 21px; fill: none; stroke: var(--blue); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.location-fields { position: relative; padding-left: 34px; border: 1px solid var(--line); border-radius: 16px; overflow: hidden; }
.location-fields label { display: block; padding: 10px 14px 9px 8px; }
.location-fields label + label { border-top: 1px solid var(--line); }
.location-fields label span { display: block; margin-bottom: 2px; color: var(--muted); font-size: .72rem; font-weight: 700; }
.location-fields input { width: 100%; padding: 2px 0; border: 0; outline: 0; background: transparent; color: var(--ink); font-size: .96rem; }
.place-field { position: relative; }
.place-suggestions { position: absolute; z-index: 700; left: -8px; right: -8px; top: calc(100% - 2px); margin: 0; padding: 6px; list-style: none; border: 1px solid var(--line); border-radius: 14px; background: #fff; box-shadow: var(--shadow); max-height: 220px; overflow: auto; }
.place-suggestions.loading::before { content: 'Searching places…'; display: block; padding: 8px 10px; color: var(--muted); font-size: .78rem; }
.place-option { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 9px 10px; border-radius: 10px; cursor: pointer; font-size: .88rem; }
.place-option[aria-selected="true"], .place-option:hover { background: var(--blue-soft); }
.place-option small { color: var(--muted); font-size: .68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; }
.route-line { position: absolute; left: 16px; top: 24px; bottom: 25px; width: 10px; display: flex; flex-direction: column; align-items: center; }
.route-line > span:nth-child(2) { flex: 1; margin: 3px 0; border-left: 2px dotted #a8abb0; }
.start-dot { width: 9px; height: 9px; border: 2px solid var(--blue); border-radius: 50%; background: #fff; }
.end-pin { width: 10px; height: 10px; border-radius: 50% 50% 50% 0; transform: rotate(-45deg); background: var(--red); }

.time-row { display: grid; grid-template-columns: auto 1fr; gap: 10px; align-items: center; margin-top: 12px; }
.time-mode { min-height: 42px; padding: 0 15px; border: 1px solid var(--line); border-radius: 21px; background: #fff; cursor: pointer; font-size: .87rem; font-weight: 650; white-space: nowrap; }
.time-mode.active { color: var(--blue); border-color: #a8c7fa; background: #f3f7fe; }
.datetime-field input { width: 100%; min-height: 42px; padding: 0 12px; border: 1px solid var(--line); border-radius: 12px; color: var(--muted); background: #fff; font-size: .82rem; }
.primary-button { grid-column: 1 / -1; min-height: 48px; border: 0; border-radius: 24px; background: var(--blue); color: #fff; display: flex; align-items: center; justify-content: center; gap: 8px; cursor: pointer; font-weight: 750; box-shadow: 0 2px 6px rgba(11, 87, 208, .28); }
.primary-button:hover { background: var(--blue-dark); }
.primary-button:disabled { background: #9aa0a6; cursor: wait; box-shadow: none; }
.primary-button svg { width: 19px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }

.status { min-height: 22px; margin: 12px 2px 2px; color: var(--muted); font-size: .82rem; }
.status.error { color: var(--red); }
.routes { display: grid; gap: 10px; }
.route-card { border: 1px solid var(--line); border-radius: 16px; background: #fff; overflow: hidden; transition: border-color .18s, box-shadow .18s; }
.route-card.selected { border-color: var(--blue); box-shadow: 0 0 0 1px var(--blue); }
.route-select { width: 100%; padding: 15px; display: grid; grid-template-columns: 18px 1fr auto; gap: 11px; align-items: start; text-align: left; border: 0; background: transparent; cursor: pointer; }
.route-radio { width: 17px; height: 17px; margin-top: 2px; border: 2px solid #80868b; border-radius: 50%; }
.selected .route-radio { border: 5px solid var(--blue); }
.route-summary { min-width: 0; display: grid; gap: 3px; }
.route-title-row { display: flex; align-items: center; gap: 7px; }
.route-name { font-size: 1rem; }
.route-badge { display: none; padding: 3px 7px; border-radius: 9px; color: var(--green); background: var(--green-soft); font-size: .65rem; font-weight: 800; text-transform: uppercase; letter-spacing: .04em; }
.route-badge:not(:empty) { display: inline; }
.route-meta { color: var(--ink); font-size: .83rem; font-weight: 650; }
.route-via { color: var(--muted); font-size: .76rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.route-price { min-width: 56px; text-align: right; }
.route-price strong { display: block; color: var(--green); font-size: 1.06rem; }
.route-price small { color: var(--muted); font-size: .67rem; font-weight: 700; }
.route-detail { display: none; margin: 0 15px 0 44px; padding: 10px 0 12px; border-top: 1px solid #eceff1; color: var(--muted); font-size: .76rem; line-height: 1.45; }
.selected .route-detail { display: block; }
.maps-button { display: none; width: calc(100% - 30px); min-height: 42px; margin: 0 15px 15px; border: 0; border-radius: 21px; color: #fff; background: var(--blue); align-items: center; justify-content: center; gap: 8px; cursor: pointer; font-size: .87rem; font-weight: 750; }
.selected .maps-button { display: flex; }
.maps-button svg { width: 19px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linejoin: round; }
.fine-print { margin: 14px 4px 0; color: #80868b; font-size: .7rem; line-height: 1.45; }
.text-button { padding: 0; border: 0; background: transparent; color: var(--blue); cursor: pointer; font-size: inherit; text-decoration: underline; text-underline-offset: 2px; }
.data-dialog { width: min(92vw, 440px); padding: 0; border: 0; border-radius: 22px; color: var(--ink); box-shadow: 0 12px 48px rgba(32,33,36,.28); }
.data-dialog::backdrop { background: rgba(32,33,36,.46); backdrop-filter: blur(2px); }
.dialog-card { padding: 24px; }
.dialog-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.dialog-head h2 { margin: 0; font-size: 1.5rem; letter-spacing: -.03em; }
.dialog-close { width: 38px; height: 38px; border: 0; border-radius: 50%; background: #f1f3f4; cursor: pointer; font-size: 1.5rem; line-height: 1; }
.dialog-copy { margin: 16px 0; color: var(--muted); font-size: .9rem; line-height: 1.5; }
.key-field { display: grid; gap: 7px; }
.key-field span { font-size: .78rem; font-weight: 750; }
.key-field input { width: 100%; min-height: 46px; padding: 0 13px; border: 1px solid var(--line); border-radius: 12px; outline: none; }
.key-field input:focus { border-color: var(--blue); box-shadow: 0 0 0 1px var(--blue); }
.privacy-note { margin: 8px 0 0; color: #80868b; font-size: .72rem; line-height: 1.45; }
.connection-status { min-height: 21px; margin: 12px 0 0; color: var(--muted); font-size: .8rem; }
.connection-status.success { color: var(--green); }
.connection-status.error { color: var(--red); }
.dialog-actions { display: grid; grid-template-columns: 1fr 1.35fr; gap: 10px; margin-top: 9px; }
.secondary-button { min-height: 44px; border: 1px solid var(--line); border-radius: 22px; background: #fff; cursor: pointer; font-weight: 700; }
.secondary-button:hover { background: #f8f9fa; }
.primary-button.compact { grid-column: auto; min-height: 44px; }
.estimate-details { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); color: var(--muted); font-size: .8rem; line-height: 1.5; }
.estimate-details summary { color: var(--ink); cursor: pointer; font-weight: 750; }
.estimate-details p { margin: 10px 0 0; }
.official-link { display: inline-block; margin-top: 16px; color: var(--blue); font-size: .82rem; font-weight: 700; text-decoration: none; }
.official-link:hover { text-decoration: underline; }
.official-links { display: flex; flex-wrap: wrap; gap: 6px 18px; }
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.leaflet-control-attribution { font-size: 9px !important; }

@media (max-width: 760px) {
  .app-shell { display: block; min-height: 100dvh; }
  .map-wrap { min-height: 52dvh; }
  .planner { position: relative; min-height: 56dvh; margin-top: -7dvh; padding: 14px 16px max(24px, env(safe-area-inset-bottom)); border-radius: 24px 24px 0 0; box-shadow: 0 -4px 18px rgba(32,33,36,.14); }
  .drag-handle { display: block; width: 40px; height: 4px; margin: 0 auto 13px; border-radius: 2px; background: #c7c9cc; }
  .planner-head { margin-bottom: 16px; }
  h1 { font-size: 1.65rem; max-width: 290px; }
  .brand-pill { top: max(12px, env(safe-area-inset-top)); left: 12px; }
  .locate-button { top: max(12px, env(safe-area-inset-top)); right: 12px; }
  .data-chip { bottom: calc(7dvh + 14px); right: 12px; }
}

@media (max-width: 390px) {
  .time-row { grid-template-columns: 1fr; }
  .time-mode { display: none; }
  .primary-button { grid-column: 1; }
}

@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; transition: none !important; } }
