:root {
  --accent: #1a73e8;
  --accent-dark: #1558b0;
  --danger: #d93025;
  --bg: #fff;
  --panel-radius: 16px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.18), 0 1px 4px rgba(0, 0, 0, 0.1);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: #202124;
  overscroll-behavior: none;
}

#map {
  position: absolute;
  inset: 0;
}

/* ---------- Floating toggle (mobile, when panel closed) ---------- */
#panel-toggle {
  position: absolute;
  top: 14px;
  left: 14px;
  z-index: 11;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: var(--bg);
  box-shadow: var(--shadow);
  display: none;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: #444;
}
#panel-toggle svg {
  width: 20px;
  height: 20px;
}
#panel-toggle.hidden {
  display: none !important;
}

/* ---------- Panel ---------- */
#panel {
  position: absolute;
  top: 14px;
  left: 14px;
  width: 340px;
  max-width: calc(100vw - 28px);
  max-height: calc(100% - 28px);
  overflow-y: auto;
  background: var(--bg);
  border-radius: var(--panel-radius);
  box-shadow: var(--shadow);
  padding: 14px 16px 18px;
  z-index: 10;
  transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.2s ease;
}
#panel.collapsed {
  transform: translateX(calc(-100% - 28px));
  opacity: 0;
  pointer-events: none;
}

#panel-handle {
  display: none;
}

#panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
#panel-header h1 {
  font-size: 16px;
  font-weight: 600;
  margin: 0;
}
#panel-close {
  display: none;
  border: none;
  background: transparent;
  color: #666;
  padding: 6px;
  cursor: pointer;
  border-radius: 50%;
}
#panel-close svg {
  width: 18px;
  height: 18px;
  display: block;
}

/* ---------- Stops list ---------- */
#stops {
  list-style: none;
  margin: 0 0 8px;
  padding: 0;
  position: relative;
}

.stop {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 0;
  position: relative;
  background: var(--bg);
}
.stop.dragging {
  opacity: 0.4;
}
.stop.drag-over {
  box-shadow: inset 0 2px 0 var(--accent);
}

.stop-handle {
  cursor: grab;
  color: #bbb;
  flex: 0 0 auto;
  touch-action: none;
  padding: 4px;
  line-height: 0;
}
.stop-handle:active {
  cursor: grabbing;
}
.stop-handle svg {
  width: 14px;
  height: 20px;
  display: block;
}

.stop-dot {
  flex: 0 0 auto;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
}
.stop:first-child .stop-dot {
  background: #1a73e8;
}
.stop:last-child .stop-dot {
  border-radius: 3px;
  background: var(--danger);
}

.stop-field {
  flex: 1;
  position: relative;
  min-width: 0;
}

.stop input {
  width: 100%;
  padding: 10px 34px 10px 12px;
  border: 1px solid #e0e0e0;
  background: #f7f8f9;
  border-radius: 10px;
  font-size: 14px;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.stop input:focus {
  outline: none;
  border-color: var(--accent);
  background: #fff;
}

.stop-clear {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  border: none;
  background: transparent;
  color: #999;
  cursor: pointer;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: none;
  align-items: center;
  justify-content: center;
}
.stop-field.has-value .stop-clear {
  display: flex;
}
.stop-clear:hover {
  background: #eee;
}

.stop-remove {
  flex: 0 0 auto;
  border: none;
  background: transparent;
  color: #aaa;
  cursor: pointer;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.stop-remove:hover {
  background: #f1f3f4;
  color: var(--danger);
}
.stop-remove svg {
  width: 14px;
  height: 14px;
}

.stop-locate {
  flex: 0 0 auto;
  border: none;
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.stop-locate:hover {
  background: #eef3fe;
}
.stop-locate svg {
  width: 15px;
  height: 15px;
}
.stop-locate.loading-spin svg {
  animation: spin 0.8s linear infinite;
}

.suggestions {
  list-style: none;
  margin: 6px 0 0;
  padding: 6px;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: #fff;
  border-radius: 12px;
  box-shadow: var(--shadow);
  max-height: 240px;
  overflow-y: auto;
  z-index: 20;
  animation: pop-in 0.12s ease;
}
.suggestions.hidden {
  display: none;
}
.suggestions li {
  padding: 9px 10px;
  cursor: pointer;
  font-size: 13.5px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.suggestions li svg {
  width: 15px;
  height: 15px;
  flex: 0 0 auto;
  color: #999;
}
.suggestions li:hover,
.suggestions li.active {
  background: #eef3fe;
}

@keyframes pop-in {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- Buttons ---------- */
.text-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: none;
  background: transparent;
  color: var(--accent);
  font-size: 13.5px;
  font-weight: 500;
  padding: 8px 4px;
  cursor: pointer;
  border-radius: 8px;
}
.text-btn:hover {
  background: #eef3fe;
}

.field-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 6px;
}

.segmented {
  display: flex;
  background: #f1f3f4;
  border-radius: 10px;
  padding: 3px;
  gap: 2px;
}
.seg-btn {
  border: none;
  background: transparent;
  color: #666;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.seg-btn svg {
  width: 18px;
  height: 18px;
}
.seg-btn.active {
  background: #fff;
  color: var(--accent);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}

#route-btn {
  flex: 1;
  padding: 10px 14px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.05s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
#route-btn:hover {
  background: var(--accent-dark);
}
#route-btn:active {
  transform: scale(0.98);
}
#route-btn.loading {
  pointer-events: none;
  color: transparent;
  position: relative;
}
#route-btn.loading::after {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.5);
  border-top-color: #fff;
  animation: spin 0.7s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ---------- Route options ---------- */
#route-options {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  overflow-x: auto;
  padding-bottom: 2px;
}
#route-options.hidden {
  display: none;
}
.route-option {
  flex: 0 0 auto;
  position: relative;
  border: 1.5px solid #e0e0e0;
  background: #f7f8f9;
  border-radius: 10px;
  padding: 8px 12px;
  cursor: pointer;
  text-align: left;
  min-width: 84px;
}
.route-option.active {
  border-color: var(--accent);
  background: #eef3fe;
}
.route-option-badge {
  display: block;
  font-size: 10px;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.02em;
  margin-bottom: 2px;
}
.route-option-time {
  font-size: 14px;
  font-weight: 700;
  color: #202124;
}
.route-option-sub {
  font-size: 12px;
  color: #777;
}
.route-option-incidents {
  font-size: 11px;
  font-weight: 700;
  color: #9a6a00;
  margin-top: 2px;
  min-height: 13px;
}

/* ---------- Results ---------- */
#route-summary {
  margin: 12px 0 6px;
  font-size: 15px;
  font-weight: 700;
  padding-top: 10px;
  border-top: 1px solid #eee;
  display: flex;
  align-items: baseline;
  gap: 8px;
  animation: fade-up 0.2s ease;
}
#route-summary .sub {
  font-size: 12.5px;
  font-weight: 400;
  color: #777;
}
#route-summary.hidden {
  display: none;
}

#route-incidents {
  display: flex;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0 0 6px;
  padding: 6px 8px;
  border-radius: 8px;
  background: #fef7e0;
  color: #9a6a00;
  font-size: 12.5px;
  font-weight: 600;
}
#route-incidents svg {
  flex: 0 0 auto;
  color: #f9a825;
}
#route-incidents.hidden {
  display: none;
}

.incident-marker svg {
  width: 22px;
  height: 22px;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.35));
}
.incident-marker-alt svg {
  width: 16px;
  height: 16px;
  opacity: 0.55;
}
.incident-popup-sub {
  color: #666;
  font-size: 12px;
  margin: 2px 0 4px;
}

@keyframes fade-up {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

#route-steps {
  padding-left: 4px;
  margin: 4px 0 0;
  font-size: 13px;
  list-style: none;
}
#route-steps li {
  display: flex;
  gap: 10px;
  padding: 8px 2px;
  border-bottom: 1px solid #f2f2f2;
}
#route-steps li:last-child {
  border-bottom: none;
}
.step-icon {
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #f1f3f4;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #555;
}
.step-icon svg {
  width: 12px;
  height: 12px;
}
.step-dist {
  color: #888;
  font-size: 11.5px;
}

/* ---------- Toast ---------- */
#toast {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translate(-50%, 8px);
  background: #323232;
  color: #fff;
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 13.5px;
  box-shadow: var(--shadow);
  z-index: 30;
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s ease;
}
#toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}
#toast.hidden {
  display: none;
}

/* ---------- Start navigation ---------- */
#start-nav-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  margin-top: 10px;
  padding: 12px;
  border: none;
  border-radius: 10px;
  background: #1b8a3d;
  color: #fff;
  font-size: 14.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease;
}
#start-nav-btn:hover {
  background: #157030;
}
#start-nav-btn.hidden {
  display: none;
}

/* ---------- Navigation overlay ---------- */
#nav-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  pointer-events: none;
}
#nav-overlay.hidden {
  display: none;
}

#nav-instruction-card {
  position: absolute;
  top: 14px;
  left: 14px;
  right: 14px;
  background: #202124;
  color: #fff;
  border-radius: 14px;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: var(--shadow);
  pointer-events: auto;
}
#nav-instruction-card .step-icon {
  width: 36px;
  height: 36px;
  background: #35363a;
  color: #fff;
  flex: 0 0 auto;
}
#nav-instruction-card .step-icon svg {
  width: 20px;
  height: 20px;
}
#nav-instruction-main {
  font-size: 15px;
  font-weight: 600;
  line-height: 1.3;
}
#nav-instruction-dist {
  font-size: 13px;
  color: #aaa;
  margin-top: 2px;
}

#nav-bottom-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: #fff;
  padding: 14px 16px min(calc(14px + env(safe-area-inset-bottom)), 40px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.12);
  pointer-events: auto;
}
#nav-speed-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
  color: #202124;
}
#nav-speed-badge svg {
  width: 22px;
  height: 22px;
  flex: 0 0 auto;
  color: var(--accent);
}
#nav-speed {
  font-size: 15px;
  font-weight: 700;
  white-space: nowrap;
}
#nav-remaining-block {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
}
#nav-remaining {
  font-size: 14.5px;
  font-weight: 600;
  color: #202124;
}
#nav-arrival {
  font-size: 12px;
  color: #777;
}
#nav-exit-btn {
  flex: 0 0 auto;
  border: none;
  background: var(--danger);
  color: #fff;
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
}

#nav-recenter-btn {
  position: fixed;
  right: 14px;
  bottom: 100px;
  z-index: 41;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: none;
  background: #fff;
  color: #444;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  pointer-events: auto;
}
#nav-recenter-btn svg {
  width: 20px;
  height: 20px;
}

body.navigating #panel,
body.navigating #panel-toggle {
  display: none !important;
}

.user-puck svg {
  width: 28px;
  height: 28px;
  filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.4));
}

/* ---------- Marker styling ---------- */
.maplibregl-marker {
  cursor: grab;
}
.maplibregl-marker:active {
  cursor: grabbing;
}

/* ---------- Responsive: bottom sheet on narrow screens ---------- */
@media (max-width: 680px) {
  #panel-toggle {
    display: flex;
    width: 38px;
    height: 38px;
    top: 10px;
    left: 10px;
  }

  #panel {
    position: fixed;
    top: auto;
    bottom: var(--vv-bottom, 0px);
    left: 0;
    right: 0;
    width: 100%;
    max-width: 100%;
    max-height: 48vh;
    border-radius: 14px 14px 0 0;
    padding: 4px 10px min(calc(6px + env(safe-area-inset-bottom)), 26px);
    transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
  }
  #panel.collapsed {
    transform: translateY(100%);
    opacity: 1;
  }

  #panel-header {
    margin-bottom: 4px;
  }
  #panel-header h1 {
    font-size: 13.5px;
  }

  #route-options {
    margin-top: 6px;
  }
  .route-option {
    padding: 6px 10px;
    min-width: 72px;
  }
  .route-option-time {
    font-size: 13px;
  }
  .route-option-sub {
    font-size: 11px;
  }

  .stop {
    padding: 3px 0;
    gap: 6px;
  }
  .stop input {
    padding: 7px 30px 7px 10px;
    font-size: 13px;
    border-radius: 8px;
  }
  .stop-dot {
    width: 8px;
    height: 8px;
  }
  .stop-handle svg {
    width: 12px;
    height: 17px;
  }
  .stop-remove,
  .stop-locate {
    width: 22px;
    height: 22px;
  }

  #add-stop {
    padding: 5px 4px;
    font-size: 12.5px;
  }

  #costing-row {
    margin-top: 3px;
    gap: 6px;
  }
  .segmented {
    padding: 2px;
  }
  .seg-btn {
    width: 30px;
    height: 30px;
  }
  .seg-btn svg {
    width: 16px;
    height: 16px;
  }
  #route-btn {
    padding: 8px 12px;
    font-size: 13px;
  }

  #route-summary {
    margin: 8px 0 4px;
    padding-top: 6px;
    font-size: 13.5px;
  }
  #route-steps li {
    padding: 6px 2px;
    font-size: 12px;
  }
  .step-icon {
    width: 18px;
    height: 18px;
  }

  #panel-handle {
    display: block;
    width: 32px;
    height: 3px;
    border-radius: 2px;
    background: #ddd;
    margin: 5px auto 4px;
  }

  #panel-close {
    display: flex;
  }

  .maplibregl-ctrl-top-right {
    top: auto;
    bottom: 12px;
  }
}
