:root {
	--bg: #0f172a;
	--panel: #1f2937;
	--panel-border: rgba(255, 255, 255, 0.08);
	--text: #f3f4f6;
	--muted: #9ca3af;
	--accent: #38bdf8;
	--accent-hover: #0ea5e9;
	--danger: #f87171;
	--safe-top: env(safe-area-inset-top, 0px);
	--safe-bottom: env(safe-area-inset-bottom, 0px);
	--safe-left: env(safe-area-inset-left, 0px);
	--safe-right: env(safe-area-inset-right, 0px);
}

* {
	box-sizing: border-box;
}

[hidden] {
	display: none !important;
}

html, body {
	margin: 0;
	padding: 0;
	height: 100%;
	width: 100%;
	background: var(--bg);
	color: var(--text);
	font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
	-webkit-font-smoothing: antialiased;
	overscroll-behavior: none;
}

#map {
	position: fixed;
	inset: 0;
	width: 100%;
	height: 100%;
}

/* MapLibre control overrides — dark theme */
.maplibregl-ctrl-group {
	background: var(--panel) !important;
	border: 1px solid var(--panel-border) !important;
}
.maplibregl-ctrl-group button {
	background-color: transparent !important;
}
.maplibregl-ctrl-group button + button {
	border-top: 1px solid var(--panel-border) !important;
}
.maplibregl-ctrl-attrib {
	background: rgba(15, 23, 42, 0.7) !important;
	color: var(--muted) !important;
}
.maplibregl-ctrl-attrib a {
	color: var(--accent) !important;
}

/* Floating button — top-left, opens profile */
.floating-btn {
	position: fixed;
	top: calc(0.75rem + var(--safe-top));
	left: calc(0.75rem + var(--safe-left));
	width: 44px;
	height: 44px;
	border-radius: 8px;
	background: var(--panel);
	color: var(--text);
	border: 1px solid var(--panel-border);
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
	z-index: 10;
	transition: background 0.15s;
}
.floating-btn:hover, .floating-btn:focus-visible {
	background: #2d3748;
	outline: none;
}

/* Slide-in panel */
.panel {
	position: fixed;
	top: 0;
	left: 0;
	bottom: 0;
	width: min(380px, 100%);
	background: var(--panel);
	border-right: 1px solid var(--panel-border);
	box-shadow: 2px 0 12px rgba(0, 0, 0, 0.4);
	z-index: 20;
	transform: translateX(-100%);
	transition: transform 0.25s ease-out;
	display: flex;
	flex-direction: column;
	padding-top: var(--safe-top);
	padding-bottom: var(--safe-bottom);
	padding-left: var(--safe-left);
}
.panel.open {
	transform: translateX(0);
}
.panel[aria-hidden="true"] {
	visibility: hidden;
}
.panel.open[aria-hidden="false"] {
	visibility: visible;
}

.panel-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 1rem 1.25rem;
	border-bottom: 1px solid var(--panel-border);
}
.panel-header h2 {
	margin: 0;
	font-size: 1.125rem;
	font-weight: 600;
}

.icon-btn {
	background: transparent;
	color: var(--muted);
	border: none;
	cursor: pointer;
	width: 32px;
	height: 32px;
	border-radius: 6px;
	display: flex;
	align-items: center;
	justify-content: center;
}
.icon-btn:hover, .icon-btn:focus-visible {
	color: var(--text);
	background: rgba(255, 255, 255, 0.05);
	outline: none;
}

.panel-body {
	padding: 1.25rem;
	overflow-y: auto;
	display: flex;
	flex-direction: column;
	gap: 1rem;
}

.panel-body label {
	display: flex;
	flex-direction: column;
	gap: 0.35rem;
	font-size: 0.875rem;
	color: var(--muted);
}
.panel-body label.checkbox {
	flex-direction: row;
	align-items: center;
	gap: 0.5rem;
	color: var(--text);
	font-size: 0.9rem;
}

.panel-body input[type="number"] {
	background: var(--bg);
	color: var(--text);
	border: 1px solid var(--panel-border);
	border-radius: 6px;
	padding: 0.55rem 0.75rem;
	font-size: 1rem;
	font-family: inherit;
}
.panel-body input[type="number"]:focus {
	outline: none;
	border-color: var(--accent);
}
.panel-body input[type="checkbox"] {
	width: 18px;
	height: 18px;
	accent-color: var(--accent);
}

.hint {
	color: var(--muted);
	font-size: 0.75rem;
	line-height: 1.35;
	margin-top: 0.1rem;
	opacity: 0.85;
}

/* Search bar — top center, takes precedence over MapLibre attribution */
.search {
	position: fixed;
	top: calc(0.75rem + var(--safe-top));
	left: calc(4rem + var(--safe-left));
	right: calc(0.75rem + var(--safe-right));
	max-width: 480px;
	z-index: 10;
	display: flex;
	flex-direction: column;
}
.search-row {
	display: flex;
	align-items: center;
	background: var(--panel);
	border: 1px solid var(--panel-border);
	border-radius: 8px;
	box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
	padding: 0 0.4rem 0 0.75rem;
}
.search-row input[type="search"] {
	flex: 1;
	background: transparent;
	color: var(--text);
	border: none;
	outline: none;
	font-family: inherit;
	font-size: 1rem;
	padding: 0.65rem 0;
	min-width: 0;
}
.search-row input::placeholder {
	color: var(--muted);
}
.search-results {
	list-style: none;
	margin: 0.3rem 0 0;
	padding: 0;
	background: var(--panel);
	border: 1px solid var(--panel-border);
	border-radius: 8px;
	max-height: min(50vh, 360px);
	overflow-y: auto;
	box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}
.search-results li {
	padding: 0.6rem 0.9rem;
	cursor: pointer;
	border-bottom: 1px solid var(--panel-border);
	font-size: 0.9rem;
	line-height: 1.3;
}
.search-results li:last-child {
	border-bottom: none;
}
.search-results li:hover,
.search-results li[aria-selected="true"] {
	background: rgba(56, 189, 248, 0.08);
}
.search-results .result-name {
	color: var(--text);
	font-weight: 500;
}
.search-results .result-context {
	color: var(--muted);
	font-size: 0.8rem;
}
.search-results .result-empty {
	color: var(--muted);
	padding: 0.7rem 0.9rem;
	cursor: default;
}

.route-status {
	margin: 0.4rem 0 0;
	padding: 0.45rem 0.75rem;
	background: var(--panel);
	border: 1px solid var(--panel-border);
	border-radius: 6px;
	font-size: 0.85rem;
	color: var(--muted);
	box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}
.route-status:empty { display: none; }
.route-status.error { color: var(--danger); }
.route-status.success { color: #34d399; }

.route-actions {
	display: flex;
	gap: 0.5rem;
	margin-top: 0.4rem;
}

/* Maneuver banner — top of screen during active nav */
.maneuver {
	position: fixed;
	top: calc(0.75rem + var(--safe-top));
	left: calc(0.75rem + var(--safe-left));
	right: calc(0.75rem + var(--safe-right));
	max-width: 640px;
	margin: 0 auto;
	background: var(--panel);
	border: 1px solid var(--panel-border);
	border-radius: 12px;
	box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
	display: flex;
	align-items: center;
	gap: 0.85rem;
	padding: 0.85rem 1rem;
	z-index: 15;
}
.maneuver-distance {
	display: flex;
	align-items: baseline;
	gap: 0.25rem;
	min-width: 4.5rem;
	color: var(--accent);
}
.maneuver-distance-value {
	font-size: 1.6rem;
	font-weight: 700;
	line-height: 1;
}
.maneuver-distance-unit {
	font-size: 0.85rem;
	font-weight: 600;
	color: var(--muted);
}
.maneuver-instruction {
	flex: 1;
	font-size: 1rem;
	line-height: 1.3;
	color: var(--text);
}
.maneuver-mute {
	flex-shrink: 0;
}
.maneuver-mute[aria-pressed="true"] {
	color: var(--danger);
}
.maneuver.recalculating {
	border-color: #f59e0b;
	background: linear-gradient(90deg, var(--panel), #2d2009);
}
.maneuver.recalculating .maneuver-distance {
	visibility: hidden;
}
.maneuver.recalculating .maneuver-instruction {
	color: #fbbf24;
	font-weight: 600;
}

/* ETA HUD — bottom of screen during active nav */
.eta-hud {
	position: fixed;
	bottom: calc(0.75rem + var(--safe-bottom));
	left: calc(0.75rem + var(--safe-left));
	right: calc(0.75rem + var(--safe-right));
	max-width: 640px;
	margin: 0 auto;
	background: var(--panel);
	border: 1px solid var(--panel-border);
	border-radius: 12px;
	box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.5);
	display: flex;
	align-items: center;
	gap: 0.75rem;
	padding: 0.7rem 1rem;
	z-index: 15;
}
.eta-stat {
	flex: 1;
	display: flex;
	flex-direction: column;
	align-items: center;
	min-width: 0;
}
.eta-value {
	font-size: 1.15rem;
	font-weight: 600;
	color: var(--text);
	line-height: 1.2;
	white-space: nowrap;
}
.eta-label {
	font-size: 0.7rem;
	color: var(--muted);
	text-transform: uppercase;
	letter-spacing: 0.04em;
	margin-top: 0.15rem;
}
.btn-stop {
	background: var(--danger);
	color: #1a0606;
	border: none;
	border-radius: 8px;
	padding: 0.6rem 1rem;
	font-size: 0.95rem;
	font-weight: 600;
	font-family: inherit;
	cursor: pointer;
	flex-shrink: 0;
}
.btn-stop:hover, .btn-stop:focus-visible {
	background: #fca5a5;
	outline: none;
}

.panel-actions {
	display: flex;
	gap: 0.5rem;
	margin-top: 0.5rem;
}
.btn-primary, .btn-secondary {
	flex: 1;
	padding: 0.65rem 1rem;
	border-radius: 6px;
	font-size: 0.95rem;
	font-weight: 500;
	cursor: pointer;
	border: 1px solid transparent;
	font-family: inherit;
}
.btn-primary {
	background: var(--accent);
	color: #0f172a;
}
.btn-primary:hover, .btn-primary:focus-visible {
	background: var(--accent-hover);
	outline: none;
}
.btn-secondary {
	background: transparent;
	color: var(--muted);
	border-color: var(--panel-border);
}
.btn-secondary:hover, .btn-secondary:focus-visible {
	color: var(--text);
	background: rgba(255, 255, 255, 0.04);
	outline: none;
}

.status {
	min-height: 1.25em;
	font-size: 0.85rem;
	color: var(--muted);
	margin: 0;
}
.status.saved { color: #34d399; }
.status.error { color: var(--danger); }
