*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --earth: #2C3A2E;
  --earth-light: #3D4F40;
  --sage: #7A9B76;
  --sage-muted: #A8C4A4;
  --sand: #E8DFD0;
  --sand-light: #F5F0E8;
  --cream: #FDFBF7;
  --accent: #D4856A;
  --accent-hover: #C07050;
  --text: #1E2A20;
  --text-muted: #6B7D6D;
  --shadow: rgba(44, 58, 46, 0.12);
  --radius: 14px;
  --radius-sm: 8px;
}

html { font-size: 16px; }

body {
  font-family: 'DM Sans', sans-serif;
  background: var(--cream);
  color: var(--text);
  min-height: 100dvh;
  overflow-x: hidden;
}

/* ── Header ── */
header {
  background: var(--earth);
  color: var(--sand-light);
  padding: 1.25rem 2rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  position: relative;
  z-index: 1000;
  box-shadow: 0 4px 20px var(--shadow);
}

.logo {
  font-family: 'DM Serif Display', serif;
  font-size: 1.6rem;
  letter-spacing: 0.02em;
  color: var(--sand);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.logo svg { width: 28px; height: 28px; }

.logo-subtitle {
  font-family: 'DM Sans', sans-serif;
  font-weight: 300;
  font-size: 0.8rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--sage-muted);
  margin-left: 0.75rem;
  padding-left: 0.75rem;
  border-left: 1px solid var(--earth-light);
}

/* ── Layout ── */
.app-layout {
  display: grid;
  grid-template-columns: 400px 1fr;
  height: calc(100dvh - 62px);
}

/* ── Mobile bottom sheet handle & preview (hidden on desktop) ── */
.sidebar-handle {
  display: none;
}

.sheet-preview {
  display: none;
}

/* ── Floating plan button (hidden on desktop) ── */
.btn-plan-fab {
  display: none;
}

@media (max-width: 900px) {
  /* ── Hide header on mobile — map gets full viewport ── */
  header {
    display: none;
  }

  .app-layout {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
    height: 100dvh;
    position: relative;
  }

  .map-container {
    grid-row: 1;
    grid-column: 1;
    min-height: 0;
  }

  /* ── Bottom sheet ── */
  .sidebar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 1001;
    max-height: 85vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behaviour: contain;
    border-right: none;
    border-top: none;
    border-radius: 20px 20px 0 0;
    box-shadow: 0 -6px 32px rgba(44, 58, 46, 0.22);
    padding: 0 1.25rem 1.25rem;
    padding-bottom: calc(1.25rem + env(safe-area-inset-bottom, 0px));
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    will-change: transform;
    gap: 0.75rem;
  }

  /* Collapsed: show handle + preview bar (~72px visible) */
  .sidebar.collapsed {
    transform: translateY(calc(100% - 72px));
    overflow: hidden;
  }

  /* Half-expanded: show ~45% of viewport */
  .sidebar.half {
    transform: translateY(calc(100% - 45vh));
  }

  /* Dragging state: disable transition for real-time tracking */
  .sidebar.dragging {
    transition: none;
  }

  /* ── Handle area ── */
  .sidebar-handle {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 10px 0 6px;
    cursor: grab;
    -webkit-tap-highlight-color: transparent;
    position: sticky;
    top: 0;
    background: var(--cream);
    z-index: 2;
    margin: 0 -1.25rem;
    padding-left: 1.25rem;
    padding-right: 1.25rem;
    touch-action: none;
  }

  .sidebar-handle-bar {
    width: 36px;
    height: 4px;
    border-radius: 2px;
    background: var(--sage-muted);
    transition: background 0.2s;
    flex-shrink: 0;
  }

  .sidebar-handle:active .sidebar-handle-bar {
    background: var(--sage);
  }

  /* ── Collapsed preview row ── */
  .sheet-preview {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    width: 100%;
    padding: 8px 0 2px;
  }

  .sheet-preview-steps {
    font-family: 'DM Serif Display', serif;
    font-size: 1.05rem;
    color: var(--earth);
    font-weight: 400;
  }

  .sheet-preview-dist {
    font-size: 0.8rem;
    color: var(--sage);
    font-weight: 500;
  }

  /* ── Flatten panels on mobile — sections, not cards ── */
  .panel {
    background: transparent;
    border: none;
    box-shadow: none;
    border-radius: 0;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--sand);
  }

  .panel:last-of-type {
    border-bottom: none;
  }

  .panel-title {
    font-size: 0.95rem;
    margin-bottom: 0.75rem;
  }

  .step-badge {
    width: 20px;
    height: 20px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.6rem;
    padding: 0;
  }

  /* ── Touch-friendly targets ── */
  .preset-btn {
    padding: 0.45rem 0.85rem;
    font-size: 0.78rem;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
  }

  /* Hide inline plan button on mobile — FAB replaces it */
  .btn-plan-inline {
    display: none;
  }

  .btn-secondary {
    min-height: 44px;
    font-size: 0.85rem;
  }

  .toggle {
    width: 46px;
    height: 26px;
    min-width: 46px;
  }

  .toggle-track { border-radius: 13px; }

  .toggle-thumb {
    width: 22px;
    height: 22px;
  }

  .toggle input:checked ~ .toggle-thumb { transform: translateX(20px); }

  input[type="number"], select {
    min-height: 44px;
    font-size: 1rem;
  }

  input[type="range"] {
    height: 8px;
    margin: 0.75rem 0;
  }

  input[type="range"]::-webkit-slider-thumb {
    width: 28px;
    height: 28px;
  }

  /* ── Map hint as floating toast ── */
  .map-overlay {
    top: auto;
    bottom: 84px;
    left: 1rem;
    right: 1rem;
  }

  .map-hint {
    font-size: 0.78rem;
    padding: 0.6rem 0.85rem;
    border-radius: 12px;
    border-left: none;
    text-align: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(44, 58, 46, 0.15);
  }

  /* ── Floating action button ── */
  .btn-plan-fab {
    display: flex;
    align-items: center;
    justify-content: center;
    position: fixed;
    bottom: 84px;
    right: 1rem;
    z-index: 1002;
    width: 56px;
    height: 56px;
    border-radius: 16px;
    background: var(--accent);
    color: white;
    border: none;
    box-shadow: 0 4px 20px rgba(212, 133, 106, 0.4);
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  }

  .btn-plan-fab:hover {
    background: var(--accent-hover);
    transform: scale(1.05);
  }

  .btn-plan-fab:active {
    transform: scale(0.95);
  }

  .btn-plan-fab:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
    box-shadow: 0 2px 8px rgba(212, 133, 106, 0.2);
  }

  /* Hide FAB when route is showing or progress is active */
  .btn-plan-fab.hidden {
    display: none;
  }

  /* ── Steps display tighter on mobile ── */
  .steps-number { font-size: 2.2rem; }
  .steps-display { margin-bottom: 0.5rem; }

  /* ── Route summary on mobile ── */
  .summary-stats { gap: 0.5rem; }
  .stat { padding: 0.65rem 0.3rem; }
  .stat-value { font-size: 1.2rem; }

  .route-summary .panel {
    border-bottom: none;
    padding-top: 0.5rem;
  }

  /* ── Progress bar tighter ── */
  .progress-step {
    padding: 0.4rem 0.25rem;
  }

  /* ── Leaflet zoom controls above bottom sheet ── */
  .leaflet-control-zoom {
    margin-bottom: 84px !important;
  }

  /* ── Warning/error full-width on mobile ── */
  .warning-msg, .error-msg {
    border-radius: 10px;
  }

  /* ── Input labels slightly smaller ── */
  label {
    font-size: 0.72rem;
  }

  .input-hint {
    font-size: 0.68rem;
  }

  .toggle-label {
    font-size: 0.8rem;
  }
}

/* ── Small phones ── */
@media (max-width: 400px) {
  .sidebar {
    padding: 0 1rem 1rem;
    padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
    max-height: 88vh;
  }

  .sidebar.collapsed {
    transform: translateY(calc(100% - 68px));
  }

  .sidebar-handle {
    margin: 0 -1rem;
    padding-left: 1rem;
    padding-right: 1rem;
  }

  .sheet-preview-steps {
    font-size: 0.95rem;
  }

  .steps-presets {
    flex-wrap: wrap;
  }

  .input-row {
    grid-template-columns: 1fr;
    gap: 0.5rem;
  }

  .btn-plan-fab {
    bottom: 80px;
    right: 0.75rem;
    width: 52px;
    height: 52px;
    border-radius: 14px;
  }
}

/* ── Sidebar ── */
.sidebar {
  background: var(--cream);
  border-right: 1px solid var(--sand);
  overflow-y: auto;
  padding: 1.75rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--sage-muted); border-radius: 4px; }

/* ── Panels ── */
.panel {
  background: white;
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: 0 2px 12px var(--shadow);
  border: 1px solid var(--sand);
}

.panel-title {
  font-family: 'DM Serif Display', serif;
  font-size: 1.15rem;
  color: var(--earth);
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.panel-title .step-badge {
  background: var(--sage);
  color: white;
  font-family: 'DM Sans', sans-serif;
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  padding: 0.2rem 0.55rem;
  border-radius: 20px;
  text-transform: uppercase;
}

/* ── Form elements ── */
label {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 0.4rem;
}

input[type="number"], select {
  width: 100%;
  padding: 0.7rem 0.9rem;
  border: 1.5px solid var(--sand);
  border-radius: var(--radius-sm);
  font-family: 'DM Sans', sans-serif;
  font-size: 0.95rem;
  color: var(--text);
  background: var(--sand-light);
  transition: border-color 0.2s, box-shadow 0.2s;
  outline: none;
  -moz-appearance: textfield;
}

input[type="number"]:focus, select:focus {
  border-color: var(--sage);
  box-shadow: 0 0 0 3px rgba(122, 155, 118, 0.15);
}

input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; }

.input-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.input-group { margin-bottom: 0.85rem; }
.input-group:last-child { margin-bottom: 0; }

.input-hint {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 0.3rem;
  font-weight: 300;
}

/* ── Steps slider ── */
.steps-display {
  text-align: center;
  margin-bottom: 0.75rem;
}

.steps-number {
  font-family: 'DM Serif Display', serif;
  font-size: 2.8rem;
  color: var(--earth);
  line-height: 1;
}

.steps-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: var(--text-muted);
  font-weight: 500;
}

.steps-distance {
  font-size: 0.85rem;
  color: var(--sage);
  font-weight: 500;
  margin-top: 0.2rem;
}

input[type="range"] {
  -webkit-appearance: none;
  width: 100%;
  height: 6px;
  background: linear-gradient(to right, var(--sage), var(--accent));
  border-radius: 3px;
  outline: none;
  margin: 0.75rem 0;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 22px;
  height: 22px;
  background: white;
  border: 3px solid var(--sage);
  border-radius: 50%;
  cursor: grab;
  box-shadow: 0 2px 8px var(--shadow);
  transition: transform 0.15s;
}

input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.15); }
input[type="range"]::-webkit-slider-thumb:active { cursor: grabbing; }

.steps-presets {
  display: flex;
  gap: 0.4rem;
  justify-content: center;
  margin-top: 0.4rem;
}

.preset-btn {
  background: var(--sand-light);
  border: 1.5px solid var(--sand);
  padding: 0.3rem 0.7rem;
  border-radius: 20px;
  font-family: 'DM Sans', sans-serif;
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s;
}

.preset-btn:hover {
  background: var(--sage);
  color: white;
  border-color: var(--sage);
}

/* ── Buttons ── */
.btn-primary {
  width: 100%;
  padding: 0.85rem;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-family: 'DM Sans', sans-serif;
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  cursor: pointer;
  transition: all 0.25s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.btn-primary:hover { background: var(--accent-hover); transform: translateY(-1px); box-shadow: 0 4px 16px rgba(212, 133, 106, 0.3); }
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; transform: none; box-shadow: none; }

.btn-secondary {
  background: var(--sand-light);
  border: 1.5px solid var(--sand);
  padding: 0.55rem 1rem;
  border-radius: var(--radius-sm);
  font-family: 'DM Sans', sans-serif;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s;
}

.btn-secondary:hover { background: var(--sand); color: var(--text); }

/* ── Map ── */
#map {
  width: 100%;
  height: 100%;
  z-index: 1;
}

.map-container { position: relative; }

.map-overlay {
  position: absolute;
  top: 1rem;
  left: 1rem;
  right: 1rem;
  z-index: 999;
  pointer-events: none;
}

.map-hint {
  background: white;
  padding: 0.65rem 1rem;
  border-radius: var(--radius-sm);
  box-shadow: 0 2px 12px var(--shadow);
  font-size: 0.82rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  pointer-events: auto;
  animation: fadeSlideIn 0.4s ease;
  border-left: 3px solid var(--sage);
}

.map-hint.hidden { display: none; }

@keyframes fadeSlideIn {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ── Route summary ── */
.route-summary {
  display: none;
  animation: fadeSlideIn 0.4s ease;
}

.route-summary.visible { display: block; }

.summary-stats {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.stat {
  text-align: center;
  padding: 0.65rem 0.3rem;
  background: var(--sand-light);
  border-radius: var(--radius-sm);
}

.stat-value {
  font-family: 'DM Serif Display', serif;
  font-size: 1.3rem;
  color: var(--earth);
}

.stat-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  font-weight: 500;
}

/* ── POI list ── */
.poi-list { list-style: none; }

.poi-item {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--sand);
  animation: fadeSlideIn 0.3s ease;
}

.poi-item:last-child { border-bottom: none; }

.poi-icon {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  flex-shrink: 0;
}

.poi-icon.park { background: #E8F5E9; }
.poi-icon.viewpoint { background: #E3F2FD; }
.poi-icon.historic { background: #FFF3E0; }
.poi-icon.water { background: #E0F7FA; }
.poi-icon.art { background: #F3E5F5; }
.poi-icon.food { background: #FBE9E7; }
.poi-icon.default { background: var(--sand-light); }

.poi-name {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text);
}

.poi-type {
  font-size: 0.7rem;
  color: var(--text-muted);
}

/* ── Progress bar ── */
.progress-bar {
  display: none;
  flex-direction: column;
  gap: 0;
  padding: 0.5rem 0;
  animation: fadeSlideIn 0.3s ease;
}

.progress-bar.visible { display: flex; }

.progress-step {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.6rem 0.5rem;
  opacity: 0.35;
  transition: opacity 0.3s;
  position: relative;
}

.progress-step::before {
  content: "";
  position: absolute;
  left: 9px;
  top: 28px;
  bottom: -2px;
  width: 2px;
  background: var(--sand);
}

.progress-step:last-child::before { display: none; }

.progress-step.active {
  opacity: 1;
}

.progress-step.active .progress-dot {
  background: var(--sage);
  box-shadow: 0 0 0 4px rgba(122, 155, 118, 0.2);
}

.progress-step.active .progress-dot::after {
  content: "";
  position: absolute;
  inset: 2px;
  border: 2px solid white;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.progress-step.done { opacity: 0.7; }

.progress-step.done .progress-dot {
  background: var(--sage);
}

.progress-step.done .progress-dot::after {
  content: "";
  position: absolute;
  left: 5px;
  top: 3px;
  width: 4px;
  height: 8px;
  border: solid white;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
  animation: none;
}

.progress-step.done::before {
  background: var(--sage-muted);
}

.progress-dot {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--sand);
  flex-shrink: 0;
  position: relative;
  transition: background 0.3s, box-shadow 0.3s;
}

.progress-label {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text);
  line-height: 1.2;
}

.progress-detail {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 300;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Toggle ── */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.35rem 0;
}

.toggle-label {
  font-size: 0.82rem;
  color: var(--text);
  font-weight: 400;
}

.toggle {
  position: relative;
  width: 40px;
  height: 22px;
  cursor: pointer;
}

.toggle input { display: none; }

.toggle-track {
  position: absolute;
  inset: 0;
  background: var(--sand);
  border-radius: 11px;
  transition: background 0.25s;
}

.toggle input:checked + .toggle-track { background: var(--sage); }

.toggle-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  background: white;
  border-radius: 50%;
  box-shadow: 0 1px 4px var(--shadow);
  transition: transform 0.25s;
}

.toggle input:checked ~ .toggle-thumb { transform: translateX(18px); }

/* ── Warning ── */
.warning-msg {
  background: #FFF8E1;
  border: 1px solid #FFE082;
  color: #7B6B1A;
  padding: 0.65rem 0.85rem;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  display: none;
  animation: fadeSlideIn 0.3s ease;
}

.warning-msg.visible { display: block; }

/* ── Error ── */
.error-msg {
  background: #FFF0ED;
  border: 1px solid #FFCDC2;
  color: #9B3522;
  padding: 0.65rem 0.85rem;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  display: none;
  animation: fadeSlideIn 0.3s ease;
}

.error-msg.visible { display: block; }

/* ── Route actions ── */
.route-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.85rem;
}

.route-actions .btn-secondary { flex: 1; text-align: center; }

/* ── Leaflet overrides ── */
.leaflet-control-zoom a {
  background: white !important;
  color: var(--earth) !important;
  border-radius: var(--radius-sm) !important;
  font-family: 'DM Sans', sans-serif !important;
}

.route-arrow { background: none !important; border: none !important; }

