/* ═══════════════════════════════════════════════════════════════
   MOBILE BOTTOM SHEET — EXPERIMENT
   Replaces the full-screen sidebar drawer on phones (≤640px) with
   a draggable bottom sheet (peek / half / full) plus a fullscreen
   autocomplete that appears only while an input is focused.

   TO REVERT: delete this file + assets/js/mobile-sheet.js and the
   two include lines in header.php / footer.php (marked with
   "Mobile bottom-sheet experiment"). Nothing else was touched.

   Runtime kill switch (no code change): open the page with
   ?classic=1 to get the old drawer back.

   Every rule is gated on body.ms-active, which mobile-sheet.js
   adds only on small screens while the experiment is enabled, so
   this file is inert on desktop/tablet and when reverted.
═══════════════════════════════════════════════════════════════ */

/* Old drawer chrome goes away while the sheet is active */
body.ms-active #sidebar,
body.ms-active #sidebar-toggle,
body.ms-active #sidebar-overlay,
body.ms-active #sidebar-scroll {
	display: none !important;
}

/* The floating map search no longer needs to clear the hamburger */
body.ms-active #map-search {
	left: 12px;
}

/* Keep toasts above the peeking sheet */
body.ms-active #toast {
	bottom: calc(170px + env(safe-area-inset-bottom, 0px));
}

/* Style switcher — its bottom-left home is covered by the sheet, so
   it becomes a compact icon-only button top-left under the search bar */
body.ms-active #layers {
	top: calc(58px + env(safe-area-inset-top, 0px));
	bottom: auto;
	left: 12px;
	padding: 5px;
	border-radius: 10px;
	gap: 0;
}
body.ms-active #layers span {
	display: none;
}
body.ms-active #layers img,
body.ms-active #active-layer-preview {
	width: 30px;
	height: 30px;
	border-radius: 7px;
}
body.ms-active #layers-menu {
	top: calc(104px + env(safe-area-inset-top, 0px));
	bottom: auto;
	left: 12px;
}

/* ── The sheet itself ──
   display is gated on body.ms-active so the empty container can
   never linger on desktop after a resize back from mobile. */
#mobile-sheet {
	display: none;
	position: fixed;
	left: 0;
	right: 0;
	top: 0;
	/* vh fallback first: Safari < 15.4 doesn't know dvh and would
	   otherwise drop the declaration entirely */
	height: 100vh;
	height: 100dvh;
	z-index: 120;
	background: var(--surface);
	border-radius: var(--r-xl) var(--r-xl) 0 0;
	box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.14);
	flex-direction: column;
	/* Starts fully off-screen (hidden state); JS slides it up when the
	   user begins a directions flow from a POI popup. */
	transform: translateY(calc(100vh + 40px));
	transform: translateY(calc(100dvh + 40px));
	will-change: transform;
	touch-action: none;
}
body.ms-active #mobile-sheet {
	display: flex;
}
#mobile-sheet.ms-animate {
	transition: transform 0.32s cubic-bezier(0.32, 0.72, 0, 1);
}

/* Grab handle */
.ms-handle {
	flex: none;
	padding: 8px 0 4px;
	display: flex;
	justify-content: center;
	cursor: grab;
}
.ms-handle::before {
	content: "";
	width: 40px;
	height: 4px;
	border-radius: 2px;
	background: var(--border-strong);
}

/* Typing-mode header (back button), hidden unless typing */
.ms-typing-head {
	flex: none;
	display: none;
	align-items: center;
	gap: 10px;
	padding: 6px 14px 8px;
	border-bottom: 1px solid var(--border);
}
body.ms-typing .ms-typing-head {
	display: flex;
}
.ms-back-btn {
	width: 36px;
	height: 36px;
	border: none;
	background: none;
	border-radius: 50%;
	display: flex;
	align-items: center;
	justify-content: center;
	color: var(--mid);
	cursor: pointer;
	flex-shrink: 0;
}
.ms-back-btn:active {
	background: var(--bg);
}
.ms-back-btn svg {
	width: 20px;
	height: 20px;
}
.ms-typing-title {
	font-size: 14px;
	font-weight: 600;
	color: var(--dark);
}

/* Scrollable content — the sidebar sections get moved in here */
#ms-body {
	flex: 1;
	overflow-y: auto;
	-webkit-overflow-scrolling: touch;
	overscroll-behavior: contain;
	padding: 0 4px calc(24px + env(safe-area-inset-bottom, 0px));
	display: flex;
	flex-direction: column;
	touch-action: pan-y;
}

/* Section order inside the sheet (flex order so the DOM stays as-is):
   default   → route inputs, modes, recents
   routed    → summary + turn-by-turn jump above the inputs so the
               peek state shows ETA/distance, Google-style */
#ms-body > .section {
	order: 5;
}
#ms-body > #route-summary-section {
	order: 10;
}
#ms-body > #turn-by-turn-section {
	order: 11;
}
#ms-body > #recents-section {
	order: 12;
}
body.ms-routed #ms-body > #route-summary-section {
	order: 1;
}
body.ms-routed #ms-body > #turn-by-turn-section {
	order: 6;
}

/* ── Compact route inputs ──
   The desktop sizing is roomy; in the sheet every pixel of height
   steals map, so tighten the whole route block. */
body.ms-active #ms-body .section {
	padding: 8px 14px 10px;
}
body.ms-active #ms-body .ms-route-section > .section-label {
	display: none;
}
body.ms-active #ms-body .route-input-row {
	padding: 6px 12px;
	gap: 8px;
}
body.ms-active #ms-body .dir-action-row {
	margin-top: 8px;
}
body.ms-active #ms-body .get-dir-btn-main {
	padding: 9px 14px;
	font-size: 13px;
}
body.ms-active #ms-body .clear-btn-main {
	padding: 9px 12px;
	font-size: 12.5px;
}

/* ── Compact style menu ── */
body.ms-active #layers-menu {
	min-width: 64px;
}
body.ms-active #layers-menu .layer-option {
	padding: 6px 8px;
	gap: 3px;
}
body.ms-active #layers-menu .layer-preview {
	width: 28px;
	height: 28px;
	border-radius: 6px;
	border-width: 1.5px;
}
body.ms-active #layers-menu .layer-label {
	font-size: 10px;
}

/* Travel modes become one horizontally-scrollable chip row */
body.ms-active #ms-body .mode-chips-wrap {
	display: flex;
	flex-wrap: nowrap;
	overflow-x: auto;
	scrollbar-width: none;
	gap: 6px;
	padding-bottom: 4px;
}
body.ms-active #ms-body .mode-chips-wrap::-webkit-scrollbar {
	display: none;
}
body.ms-active #ms-body .mode-chip {
	flex: none;
	flex-direction: row;
	padding: 7px 14px;
	font-size: 12px;
}

/* ── Typing mode ──
   Sheet is pinned to the top by JS; everything except the route
   inputs + suggestions is hidden so results get the full screen. */
body.ms-typing #ms-body > .section:not(.ms-route-section),
body.ms-typing #ms-body > #route-summary-section,
body.ms-typing #ms-body > #turn-by-turn-section {
	display: none;
}
/* !important: the nav script toggles #nav-btn/#nav-panel with inline
   display, which would otherwise win over these rules */
body.ms-typing #ms-body .dir-action-row,
body.ms-typing #ms-body .route-comparison,
body.ms-typing #ms-body #nav-btn,
body.ms-typing #ms-body #nav-panel {
	display: none !important;
}
body.ms-typing #ms-body .ms-route-section .section-label {
	display: none;
}
body.ms-typing .ms-handle {
	display: none;
}

/* Recents stay visible while typing (tap = quick pick) until
   suggestions arrive, which overlay nothing — they're in-flow. */
body.ms-typing #ms-body > #recents-section {
	display: block;
}

/* Suggestions render in-flow and full-width while typing,
   instead of the absolutely-positioned desktop dropdown. */
body.ms-typing #search-results-origin.show,
body.ms-typing #search-results-dest.show {
	display: block;
	position: static;
	height: auto;
	max-height: none;
	overflow: visible;
	border: none;
	box-shadow: none;
	border-radius: 0;
	margin-top: 4px;
}
body.ms-typing .search-result {
	padding: 13px 14px;
	border-bottom: 1px solid var(--bg);
}

/* While a route is being shown, give the summary card a little
   top padding so the peek state reads cleanly under the handle */
body.ms-routed #ms-body > #route-summary-section {
	padding-top: 2px;
}

/* ── Top dock (active route) ──
   With a route on screen the origin/destination inputs and travel
   modes dock to a fixed bar at the top, replacing the map search —
   no digging through the sheet to change the trip. */
#ms-topdock {
	display: none;
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	z-index: 130;
	background: var(--surface);
	border-radius: 0 0 var(--r-xl) var(--r-xl);
	box-shadow: 0 4px 16px rgba(0, 0, 0, 0.14);
	padding: calc(8px + env(safe-area-inset-top, 0px)) 12px 8px;
}
body.ms-active.ms-docked #ms-topdock {
	display: block;
}
body.ms-active.ms-docked #map-search {
	display: none;
}
/* Push the style button + its menu below the dock */
body.ms-active.ms-docked #layers {
	top: calc(150px + env(safe-area-inset-top, 0px));
}
body.ms-active.ms-docked #layers-menu {
	top: calc(196px + env(safe-area-inset-top, 0px));
}

/* Inputs + end-route button side by side */
#ms-topdock .ms-dock-top {
	display: flex;
	align-items: center;
	gap: 8px;
}
#ms-topdock .ms-dock-inputs {
	flex: 1;
	min-width: 0;
}
#ms-topdock .ms-dock-close {
	flex: none;
	width: 34px;
	height: 34px;
	border-radius: 50%;
	border: 1.5px solid var(--border);
	background: var(--surface);
	color: var(--mid);
	display: flex;
	align-items: center;
	justify-content: center;
	cursor: pointer;
	padding: 0;
}
#ms-topdock .ms-dock-close:active {
	background: var(--bg);
}

/* Compact input rows inside the dock */
#ms-topdock .route-input-row {
	padding: 4px 10px;
	gap: 8px;
}
#ms-topdock .route-input-field {
	font-size: 16px;
	/* keep long place names from running under the floating swap button */
	padding-right: 34px;
}
#ms-topdock .swap-btn {
	right: 10px;
}
/* No per-row ✕/⌖ in the dock: editing happens by tapping the input
   (typing mode, where those buttons live), and the End-route ✕ clears
   the trip. Removing them also prevents them colliding with the
   End-route button on narrow devices. */
#ms-topdock .route-clear-btn,
#ms-topdock .route-loc-btn {
	display: none !important;
}
/* Nothing inside the card may paint past its rounded edge */
#ms-topdock .route-input-group {
	overflow: hidden;
}

/* Secondary controls (swap, per-input clear) stay quiet until the
   user interacts with the input group */
body.ms-active .route-input-group .swap-btn,
body.ms-active .route-input-group .route-clear-btn,
body.ms-active .route-input-group .route-loc-btn {
	opacity: 0.35;
	transition: opacity 0.15s ease;
}
body.ms-active .route-input-group:hover .swap-btn,
body.ms-active .route-input-group:focus-within .swap-btn,
body.ms-active .route-input-group:hover .route-clear-btn,
body.ms-active .route-input-group:focus-within .route-clear-btn,
body.ms-active .route-input-group:hover .route-loc-btn,
body.ms-active .route-input-group:focus-within .route-loc-btn {
	opacity: 1;
}

/* Zoom/compass/share control stack must clear the dock */
body.ms-active.ms-docked .maplibregl-ctrl-top-right {
	top: calc(148px + env(safe-area-inset-top, 0px));
}
#ms-topdock .ms-dock-modes .mode-chips-wrap {
	display: flex;
	flex-wrap: nowrap;
	overflow-x: auto;
	scrollbar-width: none;
	gap: 6px;
	margin-top: 8px;
}
#ms-topdock .ms-dock-modes .mode-chips-wrap::-webkit-scrollbar {
	display: none;
}
#ms-topdock .mode-chip {
	flex: none;
	flex-direction: row;
	padding: 6px 13px;
	font-size: 12px;
}

/* While docked, the sheet's leftover route/mode skeletons hide:
   the travel-mode section is empty and the action row is redundant
   (mode changes and endpoint edits re-route automatically). The
   route section stays for Start Navigation and the nav panel. */
body.ms-docked #ms-body .ms-modes-section {
	display: none;
}
body.ms-docked #ms-body .ms-route-section .dir-action-row {
	display: none;
}

/* ── Compact routed-state UI ──
   With a route active, the sheet holds a lot: comparison banner,
   summary card, alternatives, inputs, nav button, turn-by-turn.
   Tighten every block so the full state scrolls less. */
body.ms-active #ms-body .route-comparison {
	padding: 8px 12px;
	margin: 4px 14px 8px;
	border-radius: 12px;
}
body.ms-active #ms-body .comparison-footer {
	margin-top: 4px;
	padding-top: 4px;
}
body.ms-active #ms-body .route-summary-header {
	padding: 9px 12px 5px;
}
body.ms-active #ms-body .route-summary-stats {
	padding: 0 12px 8px;
}
body.ms-active #ms-body .route-tags {
	gap: 4px;
	padding: 0 12px 10px;
}
body.ms-active #ms-body .route-tag {
	padding: 3px 8px;
	font-size: 10px;
}
/* Decorative origin→destination gradient bar adds no information
   the stats above don't already give — drop it on mobile */
body.ms-active #ms-body .route-progress-bar {
	display: none;
}
body.ms-active #ms-body .alternatives-header {
	margin: 10px 0 6px;
}
body.ms-active #ms-body .alternative-card {
	padding: 7px 10px;
}
body.ms-active #ms-body #nav-btn {
	padding: 9px 14px;
	font-size: 13px;
	margin-top: 6px;
	box-shadow: none;
}
/* Turn-by-turn list: tighter rows, capped height so it scrolls
   inside its own section instead of stretching the sheet */
body.ms-active #ms-body #dir-steps {
	max-height: 40vh;
	max-height: 40dvh;
	overflow-y: auto;
	-webkit-overflow-scrolling: touch;
}
