:root {
  --ink: #1d2930;
  --muted: #66737b;
  --panel: #ffffff;
  --soft: #f4f7f8;
  --line: #d8e0e4;
  --route: #1769aa;
  --route-dark: #0f4f7f;
  --accent: #f2a331;
  --danger: #b94343;
  --ok: #21855a;
  --shadow: 0 8px 28px rgba(24, 38, 48, 0.16);
  --radius: 6px;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; }
body {
  color: var(--ink);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  background: #e7ecef;
  -webkit-tap-highlight-color: transparent;
}
button, input { font: inherit; }
button { touch-action: manipulation; }
input[type="search"]::-webkit-search-cancel-button,
input[type="search"]::-webkit-search-decoration { -webkit-appearance: none; appearance: none; }

#map { position: fixed; inset: 0; background: #dfe7ea; }
.maplibregl-ctrl-logo { display: none !important; }
.maplibregl-ctrl-attrib { font-size: 10px; opacity: 0.76; }

.panel {
  position: fixed;
  z-index: 20;
  top: 12px;
  bottom: 12px;
  left: 12px;
  width: 386px;
  max-width: calc(100vw - 24px);
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.brand { display: flex; align-items: center; gap: 10px; min-height: 40px; }
.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 4px;
  display: grid;
  place-items: center;
  color: white;
  background: var(--route-dark);
  font-size: 13px;
  font-weight: 800;
}
.brand strong { display: block; font-size: 18px; line-height: 1.1; }
.brand span { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }

.panel-section {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
}
.route-section { overflow: auto; min-height: 0; }
.field-label,
.section-title {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  margin-bottom: 8px;
}
.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--ink);
  font-size: 14px;
}

.search-box {
  height: 46px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: white;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0 8px 0 12px;
}
.search-box.floating { box-shadow: var(--shadow); }
.search-box input,
.route-row input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  font-size: 15px;
}
.search-box input::placeholder,
.route-row input::placeholder { color: #87939a; }
.icon { color: var(--route-dark); font-size: 19px; line-height: 1; }

.icon-btn,
.fab {
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
  color: var(--ink);
  background: #fff;
  cursor: pointer;
}
.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 4px;
  flex: 0 0 auto;
  font-size: 18px;
}
.icon-btn:hover,
.fab:hover,
.text-btn:hover,
.primary-btn:hover,
.secondary-btn:hover { background-color: #f7fafb; }
.icon-btn.subtle { border-color: transparent; background: transparent; color: var(--muted); }

.results,
.inline-results {
  margin-top: 10px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.results:empty,
.inline-results:empty { display: none; }
.result-item {
  width: 100%;
  min-height: 54px;
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: white;
  padding: 9px 10px;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}
.result-item:last-child { border-bottom: 0; }
.result-item:hover { background: var(--soft); }
.result-kind {
  color: var(--route-dark);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  white-space: nowrap;
}
.result-text {
  min-width: 0;
  display: grid;
  gap: 2px;
}
.result-name { font-size: 14px; font-weight: 730; line-height: 1.25; }
.result-sub {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mode-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  margin-bottom: 12px;
}
.mode-tab {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: white;
  color: var(--ink);
  cursor: pointer;
  font-weight: 700;
}
.mode-tab small {
  display: block;
  color: var(--muted);
  font-size: 10px;
  font-weight: 650;
  margin-top: 1px;
}
.mode-tab.active {
  border-color: var(--route);
  background: #eef6fb;
  color: var(--route-dark);
}

.route-inputs {
  position: relative;
  display: grid;
  gap: 8px;
  margin-bottom: 10px;
}
.route-row {
  height: 48px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: white;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0 8px 0 12px;
}
.route-dot { width: 10px; height: 10px; border-radius: 50%; flex: 0 0 auto; }
.route-dot.start { background: var(--route); }
.route-dot.end { background: var(--accent); }
.swap-btn {
  position: absolute;
  right: 47px;
  top: 42px;
  z-index: 2;
  width: 30px;
  height: 30px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: white;
  cursor: pointer;
}
.primary-btn {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--route-dark);
  border-radius: var(--radius);
  background: var(--route-dark);
  color: white;
  font-weight: 760;
  cursor: pointer;
}
.primary-btn:hover { background: #0c436d; }
.primary-btn:disabled { opacity: 0.48; cursor: not-allowed; }
.text-btn {
  border: 0;
  background: transparent;
  color: var(--route-dark);
  font-weight: 730;
  cursor: pointer;
}

.route-output { margin-top: 12px; }
.route-card,
.place-card {
  background: white;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
}
.route-metrics { display: flex; align-items: baseline; gap: 10px; }
.route-time { color: var(--route-dark); font-size: 28px; font-weight: 800; line-height: 1; }
.route-dist { color: var(--muted); font-size: 14px; }
.route-note { margin-top: 6px; color: var(--muted); font-size: 12px; line-height: 1.4; }
.steps { margin-top: 12px; display: grid; gap: 8px; }
.step {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  gap: 8px;
  align-items: start;
  color: var(--ink);
  font-size: 13px;
}
.step-num {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #eef6fb;
  color: var(--route-dark);
  font-weight: 800;
  font-size: 11px;
}
.step small { color: var(--muted); white-space: nowrap; }
.actions { display: flex; gap: 8px; margin-top: 12px; }
.secondary-btn {
  flex: 1;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  font-weight: 700;
  cursor: pointer;
}
.error-box {
  color: var(--danger);
  background: #fff6f6;
  border: 1px solid rgba(185, 67, 67, 0.26);
  border-radius: var(--radius);
  padding: 10px;
  font-size: 13px;
  line-height: 1.35;
}
.loading {
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px;
  font-size: 13px;
  background: #fff;
}
.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid #d7e0e4;
  border-top-color: var(--route);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.credits {
  margin-top: auto;
  display: grid;
  grid-template-columns: auto auto 1fr;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
}
.health { width: 9px; height: 9px; border-radius: 50%; background: #9aa8ad; }
.health.online { background: var(--ok); }
.health.offline { background: var(--danger); }
.health.checking { background: var(--accent); }

.top-search { display: none; }
.map-controls {
  position: fixed;
  z-index: 22;
  right: 12px;
  top: 84px;
  display: grid;
  gap: 8px;
}
.fab {
  width: 44px;
  height: 44px;
  border-radius: var(--radius);
  background: white;
  box-shadow: 0 4px 14px rgba(24, 38, 48, 0.16);
  font-size: 21px;
}

.pick-banner {
  position: fixed;
  z-index: 40;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: calc(100vw - 24px);
  padding: 11px 13px;
  color: white;
  background: #1d2930;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font-size: 14px;
}
.pick-banner button { border: 0; background: transparent; color: #9dd7ff; font-weight: 730; cursor: pointer; }

.sheet { display: none; }
.empty-state { display: grid; gap: 4px; color: var(--muted); line-height: 1.35; }
.empty-state strong { color: var(--ink); }
.place-title { font-size: 21px; font-weight: 800; margin-bottom: 4px; }
.place-sub { color: var(--muted); font-size: 13px; line-height: 1.35; }

.marker-pin {
  width: 30px;
  height: 30px;
  border-radius: 50% 50% 50% 4px;
  transform: rotate(-45deg);
  background: var(--accent);
  border: 3px solid white;
  box-shadow: 0 8px 18px rgba(24, 38, 48, 0.28);
}
.user-dot {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--route);
  border: 4px solid white;
  box-shadow: 0 0 0 8px rgba(23, 105, 170, 0.18), 0 8px 18px rgba(24, 38, 48, 0.24);
}
.hidden { display: none !important; }

.toast-stack {
  position: fixed;
  z-index: 80;
  right: 12px;
  bottom: 12px;
  display: grid;
  gap: 8px;
  width: min(360px, calc(100vw - 24px));
}
.toast {
  padding: 11px 13px;
  border-radius: var(--radius);
  color: white;
  background: #1d2930;
  box-shadow: var(--shadow);
  font-size: 13px;
}
.toast.error { background: var(--danger); }
.toast.ok { background: var(--ok); }

@media (max-width: 760px) {
  .panel { display: none; }
  .top-search {
    position: fixed;
    z-index: 25;
    display: block;
    top: max(12px, env(safe-area-inset-top));
    left: 12px;
    right: 12px;
  }
  .map-controls { top: auto; right: 12px; bottom: 158px; }
  .sheet {
    position: fixed;
    z-index: 30;
    left: 0;
    right: 0;
    bottom: 0;
    display: block;
    max-height: min(78vh, 620px);
    background: #fff;
    border-top: 1px solid var(--line);
    border-radius: 12px 12px 0 0;
    box-shadow: 0 -12px 34px rgba(24, 38, 48, 0.18);
    transform: translateY(calc(100% - 72px));
    transition: transform 0.22s ease;
  }
  .sheet.open { transform: translateY(0); }
  .sheet.peek { transform: translateY(calc(100% - 168px)); }
  .sheet-handle {
    width: 100%;
    height: 34px;
    border: 0;
    background: transparent;
    cursor: pointer;
  }
  .sheet-handle::before {
    content: "";
    display: block;
    width: 42px;
    height: 4px;
    margin: 12px auto 0;
    border-radius: 999px;
    background: #b8c4c8;
  }
  .sheet-content {
    max-height: calc(78vh - 34px);
    overflow: auto;
    padding: 0 14px max(18px, env(safe-area-inset-bottom));
  }
  .mobile-block { display: grid; gap: 12px; }
  .mobile-block .results,
  .mobile-block .inline-results { margin-top: 0; }
  .pick-banner { bottom: 92px; }
  .toast-stack {
    left: 12px;
    right: 12px;
    bottom: max(84px, env(safe-area-inset-bottom));
    width: auto;
  }
}
