:root {
  --brand: #1a7f5a;
  --brand-dark: #12583e;
  --brand-light: #e6f4ee;
  --ink: #1c2321;
  --muted: #5b6b64;
  --bg: #ffffff;
  --border: #dde5e1;
  --danger: #b3261e;
  --radius: 12px;
  --shadow: 0 8px 24px rgba(20, 40, 30, 0.14);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

#map {
  position: fixed;
  inset: 0;
  z-index: 0;
  background: #dce8e2;
}

#panel {
  position: fixed;
  z-index: 10;
  top: 16px;
  left: 16px;
  width: 340px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  background: var(--bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

h1 {
  font-size: 1.3rem;
  margin: 0;
  line-height: 1.25;
}

#panel-toggle {
  flex: none;
  border: none;
  background: none;
  cursor: pointer;
  color: var(--muted);
  padding: 2px;
  border-radius: 6px;
}

#panel-toggle:hover {
  background: var(--brand-light);
  color: var(--brand-dark);
}

#panel-toggle svg {
  display: block;
  width: 20px;
  height: 20px;
  transition: transform 0.2s;
}

#panel.collapsed #panel-toggle svg {
  transform: rotate(180deg);
}

#panel.collapsed #panel-body {
  display: none;
}

#panel.collapsed {
  padding: 12px 20px;
}

.subtitle {
  margin: 4px 0 16px;
  color: var(--muted);
  font-size: 0.92rem;
}

.field {
  margin-bottom: 16px;
}

label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 6px;
}

.search-wrap {
  position: relative;
}

.search-type-toggle {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
}

.search-type-btn {
  flex: 1;
  padding: 6px 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 6px;
  font-size: 0.85rem;
  cursor: pointer;
  color: var(--muted);
}

.search-type-btn.active {
  background: var(--brand-light);
  border-color: var(--brand);
  color: var(--brand-dark);
  font-weight: 600;
}

.input-wrap {
  position: relative;
}

#address-input {
  width: 100%;
  padding: 10px 34px 10px 12px;
  font-size: 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: none;
}

#clear-address {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  border: none;
  background: none;
  padding: 4px 8px;
  font-size: 1.25rem;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
}

#clear-address:hover {
  color: var(--brand-dark);
}

#address-input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-light);
}

#suggestions {
  list-style: none;
  margin: 4px 0 0;
  padding: 4px;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  z-index: 20;
  max-height: 240px;
  overflow-y: auto;
}

#suggestions li {
  padding: 9px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.92rem;
}

#suggestions li:hover,
#suggestions li.highlighted {
  background: var(--brand-light);
}

.hint {
  margin: 6px 0 0;
  font-size: 0.78rem;
  color: var(--muted);
}

/* Feature-flagged bike/car switch: display:flex would beat the hidden
   attribute (same tie as .actions), so the explicit rule is needed. */
.mode-toggle[hidden] {
  display: none;
}

.mode-toggle {
  display: flex;
  gap: 8px;
}

.mode-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 10px 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 8px;
  font-size: 0.95rem;
  cursor: pointer;
  color: var(--ink);
}

/* stroke: currentColor, so the icon turns white on the active button */
.mode-icon {
  width: 18px;
  height: 18px;
  flex: none;
}

.mode-btn.active {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 400;
  font-size: 0.92rem;
  color: var(--ink);
  cursor: pointer;
}

.checkbox-label input {
  width: 16px;
  height: 16px;
}

.distance-label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 0.82rem;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 4px;
}

.distance-label strong {
  color: var(--brand-dark);
  font-size: 1rem;
}

#distance-slider {
  width: 100%;
  accent-color: var(--brand);
}

.presets {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}

/* lets the JS-rendered preset buttons flex directly in .presets */
#preset-buttons {
  display: contents;
}

#custom-km {
  flex: none;
  width: 62px;
  padding: 6px 4px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.85rem;
  text-align: center;
  outline: none;
  -moz-appearance: textfield;
  appearance: textfield;
}

#custom-km::-webkit-outer-spin-button,
#custom-km::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

#custom-km:focus {
  border-color: var(--brand);
}

#custom-km.custom-active {
  background: var(--brand-light);
  border-color: var(--brand);
  color: var(--brand-dark);
  font-weight: 600;
}

/* Indeterminate progress while the road polygon is being computed.
   Space stays reserved (visibility, not display) so nothing jumps. */
#calc-progress {
  margin-top: 8px;
  height: 4px;
  border-radius: 999px;
  background: var(--brand-light);
  overflow: hidden;
  visibility: hidden;
}

#calc-progress.active {
  visibility: visible;
}

.calc-progress-bar {
  width: 35%;
  height: 100%;
  border-radius: 999px;
  background: var(--brand);
  animation: calc-progress-slide 1.1s ease-in-out infinite;
  animation-play-state: paused;
}

#calc-progress.active .calc-progress-bar {
  animation-play-state: running;
}

@keyframes calc-progress-slide {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(300%); }
}

.preset-btn {
  flex: 1;
  padding: 6px 4px;
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 6px;
  font-size: 0.85rem;
  cursor: pointer;
}

.preset-btn.active {
  background: var(--brand-light);
  border-color: var(--brand);
  color: var(--brand-dark);
  font-weight: 600;
}

#status {
  min-height: 20px;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 8px;
}

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

/* Same [hidden]-vs-display:flex tie as the modal (see .modal[hidden]):
   an explicit rule is needed for the hidden attribute to win. */
.actions[hidden] {
  display: none;
}

.actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.next-step {
  margin: 0;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.btn {
  padding: 11px 14px;
  border-radius: 8px;
  font-size: 0.95rem;
  border: none;
  cursor: pointer;
  font-weight: 600;
}

.btn-primary {
  background: var(--brand);
  color: #fff;
}

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

.btn-secondary {
  background: var(--brand-light);
  color: var(--brand-dark);
}

.disclaimer {
  margin: 12px 0 0;
  font-size: 0.75rem;
  color: var(--muted);
  line-height: 1.4;
}

.version-marker[hidden] {
  display: none;
}

.version-marker {
  margin: 14px 0 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.68rem;
  letter-spacing: 0.02em;
  color: var(--muted);
  opacity: 0.6;
  text-align: right;
}

#footer-stat {
  position: fixed;
  z-index: 10;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(4px);
  padding: 8px 16px;
  font-size: 0.78rem;
  color: var(--muted);
  text-align: center;
  border-top: 1px solid var(--border);
}

.stat-source {
  opacity: 0.8;
  color: inherit;
  text-decoration: underline;
}

.stat-source:hover {
  color: var(--brand-dark);
  opacity: 1;
}

/* Modal */
.modal[hidden] {
  display: none;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(20, 30, 25, 0.45);
}

.modal-content {
  position: relative;
  background: var(--bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  width: 340px;
  max-width: calc(100vw - 32px);
}

.modal-content h2 {
  margin: 0 0 8px;
  font-size: 1.15rem;
}

.modal-content p {
  font-size: 0.92rem;
  color: var(--muted);
  margin: 0 0 16px;
}

.modal-close {
  position: absolute;
  top: 10px;
  right: 10px;
  border: none;
  background: none;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  color: var(--muted);
}

#lead-form {
  display: flex;
  gap: 8px;
}

#lead-email {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.95rem;
}

#lead-form-status {
  margin: 10px 0 0;
  font-size: 0.85rem;
  color: var(--brand-dark);
}

/* Toast */
#toast {
  position: fixed;
  z-index: 200;
  bottom: 60px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.88rem;
  box-shadow: var(--shadow);
}

.leaflet-container {
  font-family: inherit;
}

/* Mobile */
@media (max-width: 640px) {
  #panel {
    top: auto;
    bottom: 44px;
    left: 8px;
    right: 8px;
    width: auto;
    max-width: none;
    max-height: 56vh;
    padding: 16px;
  }

  /* The panel is a bottom sheet here, so it collapses downwards: the
     arrow points the opposite way of the desktop top-left panel. */
  #panel-toggle svg {
    transform: rotate(180deg);
  }

  #panel.collapsed #panel-toggle svg {
    transform: none;
  }

  #footer-stat {
    font-size: 0.7rem;
    padding: 6px 10px;
  }

  #lead-form {
    flex-direction: column;
  }
}
