:root {
    --bg: #e2e8f0;
    --panel: rgba(255, 255, 255, 0.96);
    --panel-strong: #ffffff;
    --text: #0f172a;
    --muted: #475569;
    --line: rgba(15, 23, 42, 0.12);
    --primary: #0f766e;
    --primary-strong: #115e59;
    --accent: #f97316;
    --danger: #b91c1c;
    --shadow: 0 16px 40px rgba(15, 23, 42, 0.14);
    --radius: 20px;
    --radius-sm: 14px;
    --space-1: 0.5rem;
    --space-2: 0.75rem;
    --space-3: 1rem;
    --space-4: 1.25rem;
    --space-5: 1.5rem;
    --top-safe: env(safe-area-inset-top, 0px);
    --bottom-safe: env(safe-area-inset-bottom, 0px);
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    min-height: 100%;
    font-family: Inter, system-ui, sans-serif;
    color: var(--text);
    background: var(--bg);
}

body {
    overflow: hidden;
}

button,
select {
    font: inherit;
}

.hidden {
    display: none !important;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
}

.app-shell {
    height: 100dvh;
    display: flex;
    flex-direction: column;
}

.topbar {
    position: relative;
    z-index: 4;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: calc(var(--top-safe) + var(--space-2)) var(--space-3) var(--space-2);
    background: linear-gradient(180deg, rgba(255,255,255,0.95), rgba(255,255,255,0.72));
    backdrop-filter: blur(10px);
}

.brand {
    font-size: 1.25rem;
    font-weight: 800;
    letter-spacing: -0.03em;
}

.brand span {
    color: var(--primary);
}

.topbar-actions,
.action-row,
.recent-header {
    display: flex;
    gap: var(--space-2);
    align-items: center;
}

.layout {
    position: relative;
    flex: 1;
    display: grid;
    grid-template-columns: 1fr;
    min-height: 0;
}

.map-stage,
#map {
    min-height: 0;
    height: 100%;
}

#map {
    width: 100%;
    background: #cbd5e1;
}

.side-panel {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 3;
    display: grid;
    gap: var(--space-3);
    padding: 0 var(--space-3) calc(var(--bottom-safe) + var(--space-3));
    max-height: 76dvh;
    overflow: auto;
}

.panel-card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: var(--space-3);
}

.planner-card {
    margin-top: auto;
}

.planner-fields,
#waypoints-container,
.results-content,
.recent-list,
.legs-list {
    display: grid;
    gap: var(--space-2);
}

.place-field-row {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: var(--space-2);
    align-items: start;
}

.place-badge {
    width: 2rem;
    height: 2rem;
    border-radius: 999px;
    display: grid;
    place-items: center;
    background: #dcfce7;
    color: #166534;
    font-weight: 700;
}

.destination-badge {
    background: #fee2e2;
    color: #991b1b;
}

.waypoint-badge {
    background: #ffedd5;
    color: #9a3412;
}

.place-field-wrapper,
.place-input-shell {
    min-height: 3rem;
    border-radius: var(--radius-sm);
    background: var(--panel-strong);
    border: 1px solid var(--line);
}

.place-input-shell {
    display: flex;
    align-items: center;
    padding: 0 0.75rem;
}

.place-input-shell gmp-place-autocomplete {
    width: 100%;
}

.text-button,
.ghost-button,
.secondary-button,
.primary-button,
.fab,
.waypoint-control {
    border: 0;
    border-radius: 999px;
    padding: 0.8rem 1rem;
    cursor: pointer;
}

.primary-button {
    background: var(--primary);
    color: #fff;
    font-weight: 700;
}

.secondary-button {
    background: #dbeafe;
    color: #1d4ed8;
}

.ghost-button,
.text-button,
.waypoint-control {
    background: #f8fafc;
    color: var(--text);
    border: 1px solid var(--line);
}

.text-button {
    width: fit-content;
}

.fab {
    position: absolute;
    right: var(--space-3);
    bottom: calc(var(--bottom-safe) + 24rem);
    z-index: 4;
    background: var(--panel-strong);
    box-shadow: var(--shadow);
}

.status-banner {
    position: absolute;
    top: 1rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 4;
    padding: 0.75rem 1rem;
    border-radius: 999px;
    background: rgba(15, 23, 42, 0.86);
    color: #fff;
}

.inline-map-controls {
    display: grid;
    gap: 0.5rem;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: end;
}

.map-control-field {
    display: grid;
    gap: 0.35rem;
    font-size: 0.9rem;
    color: var(--muted);
}

.map-control-field select {
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #fff;
    padding: 0.7rem 0.85rem;
    color: var(--text);
}

.map-control-field input {
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #fff;
    padding: 0.7rem 0.85rem;
    color: var(--text);
    width: 100%;
}

.empty-state,
.context-note,
.recent-item-meta,
.stat-label,
.leg-item {
    color: var(--muted);
}

.warning-note {
    color: #92400e;
    background: #fffbeb;
    border-radius: var(--radius-sm);
    padding: 0.75rem;
}

.route-cards,
.stats-grid {
    display: grid;
    gap: var(--space-2);
}

.route-card,
.stat-card,
.recent-item,
.map-choice-menu {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    padding: 0.9rem;
}

.route-card-metric {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    margin-top: 0.3rem;
}

.route-card-metric svg,
.stat-icon svg {
    width: 1rem;
    height: 1rem;
    stroke: var(--primary);
    stroke-width: 1.8;
    fill: none;
    stroke-linecap: round;
    stroke-linejoin: round;
    flex: 0 0 auto;
}

.stat-card {
    display: grid;
    gap: 0.35rem;
}

.stat-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.8rem;
    height: 1.8rem;
    border-radius: 999px;
    background: #ecfeff;
}

.route-card.selected {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(15, 118, 110, 0.14);
}

.stat-card strong,
.recent-item strong,
.route-card strong {
    display: block;
    margin-bottom: 0.25rem;
}

.chart-wrap {
    min-height: 220px;
}

.recent-item-actions,
.waypoint-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.waypoint-row {
    display: grid;
    gap: 0.5rem;
}

.waypoint-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
}

.no-js,
.error-page {
    padding: 2rem;
}

@media (min-width: 1024px) {
    .layout {
        grid-template-columns: minmax(0, 1fr) 420px;
    }

    .side-panel {
        position: relative;
        max-height: none;
        padding: 0 var(--space-3) var(--space-3) 0;
        overflow: auto;
    }

    .planner-card {
        margin-top: var(--space-3);
    }

    .fab {
        bottom: 1.5rem;
        right: 1.5rem;
    }
    .inline-map-controls {
        grid-template-columns: minmax(0, 1fr) auto;
    }
}
