/* ── Reset ───────────────────────────────────────────────────────── */
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

:root {
    --bg:        #1a1c22;
    --surface:   #22242d;
    --surface2:  #2a2d38;
    --border:    #2e3140;
    --accent:    #d4900a;
    --blue:      #3b8fff;
    --green:     #3ab870;
    --red:       #ef4444;
    --amber:     #f59e0b;
    --text:      #e5e7eb;
    --muted:     #9ca3af;
    --dim:       #5a6070;
    --sheet-radius: 20px;
}

html, body {
    height: 100%;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 16px;
}

/* ── Map — always full screen ────────────────────────────────────── */
#map {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
}

/* ── Top search bar ──────────────────────────────────────────────── */
#top-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    padding: 12px 12px 8px;
    padding-top: max(12px, env(safe-area-inset-top));
    pointer-events: none;
}
#search-pill, #search-results, .search-result, .fav-star, .search-result-content {
    pointer-events: auto;
}

#search-pill {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 0 14px;
    height: 48px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.5);
    pointer-events: all;
    cursor: text;
}

#search-pill:focus-within { border-color: var(--blue); }

#search-icon { color: var(--dim); font-size: 16px; flex-shrink: 0; }

#search-input {
    flex: 1;
    background: none;
    border: none;
    outline: none;
    color: var(--text);
    font-size: 16px;
    font-family: inherit;
}

#search-input::placeholder { color: var(--dim); }

#search-clear {
    background: none;
    border: none;
    color: var(--dim);
    font-size: 18px;
    cursor: pointer;
    display: none;
    padding: 4px;
    line-height: 1;
}

#search-clear.visible { display: block; }

/* ── Search results ──────────────────────────────────────────────── */
#search-results {
    display: none;
    flex-direction: column;
    margin-top: 6px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    overflow: hidden;
    box-shadow: 0 8px 30px rgba(0,0,0,0.5);
    max-height: 55vh;
    overflow-y: auto;
}

#search-results.visible { display: flex; }

.search-result {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 13px 16px;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    transition: background 0.15s;
}

.search-result:last-child { border-bottom: none; }
.search-result:active     { background: var(--surface2); }

.result-icon  { font-size: 18px; width: 28px; text-align: center; }
.result-info  { flex: 1; min-width: 0; }
.result-name  { font-size: 15px; color: var(--text);
                white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.result-label { font-size: 12px; color: var(--muted); margin-top: 1px;
                white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.result-type  { font-size: 11px; color: var(--dim); flex-shrink: 0; }

.search-status {
    padding: 16px;
    font-size: 14px;
    color: var(--muted);
    text-align: center;
}

/* ── Bottom bar ──────────────────────────────────────────────────── */
#bottom-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: space-around;
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding: 10px 8px;
    padding-bottom: max(10px, env(safe-area-inset-bottom));
    box-shadow: 0 -4px 20px rgba(0,0,0,0.4);
}

.bar-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    background: none;
    border: none;
    color: var(--dim);
    cursor: pointer;
    padding: 6px 16px;
    border-radius: 10px;
    transition: all 0.2s;
    min-width: 60px;
}

.bar-btn .bar-icon  { font-size: 22px; line-height: 1; }
.bar-btn .bar-label { font-size: 10px; font-weight: 600;
                      letter-spacing: 0.3px; text-transform: uppercase; }

.bar-btn:active { background: var(--surface2); }

#btn-route.active  { color: var(--accent); }
#btn-gps.active    { color: var(--green); }
#btn-layers.active { color: var(--blue); }

/* ── Sheet backdrop ──────────────────────────────────────────────── */
#sheet-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 150;
    background: rgba(0,0,0,0.4);
}

#sheet-backdrop.visible { display: block; }

/* ── Bottom sheet ────────────────────────────────────────────────── */
#bottom-sheet {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 200;
    background: var(--surface);
    border-radius: var(--sheet-radius) var(--sheet-radius) 0 0;
    padding-bottom: max(20px, env(safe-area-inset-bottom));
    box-shadow: 0 -8px 40px rgba(0,0,0,0.6);
    transform: translateY(100%);
    transition: transform 0.32s cubic-bezier(0.32,0.72,0,1);
    max-height: 85vh;
    overflow-y: auto;
}

#bottom-sheet.open { transform: translateY(0); }

.sheet-handle {
    width: 36px;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    margin: 12px auto 0;
}

.sheet-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px 10px;
}

.sheet-title { font-size: 17px; font-weight: 700; color: var(--text); }

.sheet-close {
    background: var(--surface2);
    border: none;
    color: var(--muted);
    width: 30px;
    height: 30px;
    border-radius: 50%;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sheet-body { padding: 0 16px 16px; }

/* ── Route fields ────────────────────────────────────────────────── */
.rp-field {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 0 14px;
    margin-bottom: 8px;
    transition: border-color 0.2s;
}

.rp-field:focus-within { border-color: var(--blue); }

.rp-dot { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }
.rp-dot-start { background: var(--green); }
.rp-dot-end   { background: var(--red); }

.rp-input {
    flex: 1;
    background: none;
    border: none;
    outline: none;
    color: var(--text);
    font-size: 16px;
    padding: 14px 0;
    font-family: inherit;
}

.rp-input::placeholder { color: var(--dim); }

.rp-clear {
    background: none;
    border: none;
    color: var(--dim);
    font-size: 18px;
    padding: 4px;
    cursor: pointer;
    display: none;
    line-height: 1;
}

.rp-clear.visible { display: block; }

.rp-dropdown {
    display: none;
    flex-direction: column;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
    margin-bottom: 8px;
    max-height: 35vh;
    overflow-y: auto;
}

.rp-dropdown.visible { display: flex; }

.rp-result {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
}

.rp-result:last-child { border-bottom: none; }
.rp-result:active     { background: var(--border); }

.rp-result-icon { font-size: 16px; width: 24px; text-align: center; }
.rp-result-info { flex: 1; min-width: 0; }
.rp-result-name { font-size: 14px; color: var(--text);
                  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rp-result-sub  { font-size: 12px; color: var(--muted); margin-top: 1px; }

.rp-status { padding: 14px; font-size: 14px; color: var(--muted); text-align: center; }

/* Swap button */
#btn-swap {
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--muted);
    font-size: 18px;
    width: 36px;
    height: 36px;
    cursor: pointer;
    margin: -4px 0 4px auto;
}

#btn-swap:active { background: var(--surface2); color: var(--accent); }

/* Route summary */
#route-summary {
    display: none;
    background: var(--surface2);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 10px;
}

#route-summary.visible { display: flex; }

.summary-stat { flex: 1; text-align: center; }

.summary-stat .value {
    font-size: 30px;
    font-weight: 700;
    color: var(--accent);
    line-height: 1;
}

.summary-stat .unit { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* Maneuver list */
#maneuver-list {
    display: none;
    flex-direction: column;
    margin-bottom: 10px;
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
    max-height: 28vh;
    overflow-y: auto;
}

#maneuver-list.visible { display: flex; }

.maneuver-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
}

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

.maneuver-dist {
    color: var(--muted);
    white-space: nowrap;
    min-width: 48px;
    text-align: right;
    font-size: 12px;
    padding-top: 2px;
    flex-shrink: 0;
}

.maneuver-text { color: var(--text); line-height: 1.4; }

#route-loading {
    display: none;
    text-align: center;
    padding: 14px;
    color: var(--muted);
    font-size: 14px;
}

#route-loading.visible { display: block; }

/* Sheet buttons */
.sheet-btn {
    width: 100%;
    padding: 15px;
    border-radius: 12px;
    border: none;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    margin-bottom: 8px;
    font-family: inherit;
}

.sheet-btn-primary { background: var(--accent); color: #fff; display: none; }
.sheet-btn-primary.visible { display: block; }
.sheet-btn-primary:active { opacity: 0.85; }

.sheet-btn-secondary {
    background: var(--surface2);
    color: var(--red);
    border: 1px solid var(--border);
    display: none;
}

.sheet-btn-secondary.visible { display: block; }
.sheet-btn-secondary:active { opacity: 0.85; }

/* ── Layers sheet ────────────────────────────────────────────────── */
.layer-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 15px 0;
    border-bottom: 1px solid var(--border);
}

.layer-row:last-child { border-bottom: none; }

.layer-info { display: flex; align-items: center; gap: 14px; }
.layer-icon { font-size: 22px; width: 28px; text-align: center; }
.layer-name { font-size: 15px; color: var(--text); }

/* Toggle switch */
.toggle { position: relative; width: 48px; height: 28px; flex-shrink: 0; }
.toggle input { opacity: 0; width: 0; height: 0; }

.toggle-slider {
    position: absolute;
    inset: 0;
    background: var(--border);
    border-radius: 28px;
    cursor: pointer;
    transition: background 0.2s;
}

.toggle-slider::before {
    content: '';
    position: absolute;
    width: 22px;
    height: 22px;
    left: 3px;
    top: 3px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.2s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

.toggle input:checked + .toggle-slider { background: var(--green); }
.toggle input:checked + .toggle-slider::before { transform: translateX(20px); }

/* ── GPS badge ───────────────────────────────────────────────────── */
#gps-badge {
    display: none;
    position: fixed;
    top: max(68px, calc(env(safe-area-inset-top) + 68px));
    right: 12px;
    z-index: 90;
    background: var(--surface);
    border: 1px solid var(--green);
    border-radius: 20px;
    padding: 5px 10px 5px 8px;
    font-size: 12px;
    color: var(--green);
    align-items: center;
    gap: 5px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.3);
    pointer-events: none;
}
#search-pill, #search-results, .search-result, .fav-star, .search-result-content {
    pointer-events: auto;
}

#gps-badge.visible { display: flex; }

#gps-dot-indicator {
    width: 7px;
    height: 7px;
    background: var(--green);
    border-radius: 50%;
    animation: pulse 2s infinite;
    flex-shrink: 0;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0.3; }
}

/* ── MapLibre overrides ──────────────────────────────────────────── */
.maplibregl-popup-content {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    color: var(--text);
    font-size: 14px;
    padding: 12px 14px;
    max-width: 280px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.5);
}

.maplibregl-popup-tip { border-top-color: var(--border); }

.popup-title { font-weight: 700; color: var(--accent); margin-bottom: 6px; font-size: 14px; }
.popup-row   { color: var(--muted); font-size: 13px; margin-bottom: 3px; }
.popup-row b { color: var(--text); }

/* Push MapLibre controls above bottom bar */
.maplibregl-ctrl-bottom-right { bottom: 70px !important; }
.maplibregl-ctrl-bottom-left  { bottom: 70px !important; }

body.route-mode #map { cursor: crosshair; }

/* ── Favourites ──────────────────────────────────────────────────── */
.fav-star {
    background: none;
    border: none;
    color: var(--dim);
    font-size: 16px;
    padding: 4px 6px;
    cursor: pointer;
    line-height: 1;
    flex-shrink: 0;
    transition: color 0.15s, transform 0.15s;
}

.fav-star:active  { transform: scale(1.3); }
.fav-star.starred { color: var(--accent); }

.fav-section-header {
    padding: 8px 14px 4px;
    font-size: 11px;
    font-weight: 700;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.6px;
    border-bottom: 1px solid var(--border);
}

.fav-empty {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 16px 14px;
    font-size: 13px;
    color: var(--muted);
    text-align: left;
}

.fav-empty-icon { font-size: 18px; flex-shrink: 0; }

/* star as inline span inside search result content */
.search-result-content .fav-star {
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    padding: 8px;
    font-size: 22px;
    flex-shrink: 0;
    user-select: none;
    -webkit-user-select: none;
}

/* Eliminate 300ms tap delay on iPhone for search results */
#search-results {
    touch-action: manipulation;
}
#search-results * {
    touch-action: manipulation;
}
/* ── Theme transition ────────────────────────────────────────────── */
#map, body, .bottom-sheet, #top-bar, #search-pill, #search-results,
.rp-field, .bottom-bar {
    transition: background-color 0.4s ease, color 0.3s ease, border-color 0.3s ease;
}

#icon-compass {
    display: inline-block;
    transition: transform 0.3s ease;
    font-size: 20px;
}

/* ── Dark mode refinements ───────────────────────────────────────── */
.bar-label {
    color: var(--muted);
    font-size: 10px;
}
.bottom-sheet {
    background: var(--surface);
}

/* ── Floating route card ─────────────────────────────────────────── */
#route-float-card {
    position: fixed;
    bottom: 90px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 12px 16px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
    z-index: 200;
    min-width: 280px;
    display: none;
    pointer-events: all;
}

.rfc-main {
    display: flex;
    align-items: center;
    gap: 10px;
}

.rfc-time {
    font-size: 20px;
    font-weight: 700;
    color: var(--text);
}

.rfc-km {
    font-size: 14px;
    color: var(--muted);
}

.rfc-via {
    font-size: 12px;
    color: var(--muted);
    flex: 1;
}

.rfc-start {
    background: var(--blue);
    color: white;
    border: none;
    border-radius: 20px;
    padding: 6px 14px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}

.rfc-close {
    background: none;
    border: none;
    color: var(--dim);
    font-size: 16px;
    cursor: pointer;
    padding: 4px 8px;
}

.rfc-hint {
    font-size: 11px;
    color: var(--dim);
    text-align: center;
    margin-top: 4px;
}

/* ── Route float card — updated ─────────────────────────────────── */
#route-float-card {
    position: fixed;
    bottom: 90px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 12px 16px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
    z-index: 200;
    width: min(340px, 90vw);
    display: none;
    pointer-events: all;
}

.rfc-header {
    display: flex;
    align-items: center;
    gap: 4px;
}

.rfc-nav-btn {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 50%;
    width: 36px;
    height: 36px;
    font-size: 20px;
    color: var(--text);
    cursor: pointer;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.rfc-nav-btn:disabled { opacity: 0.3; }

.rfc-content { flex: 1; text-align: center; }

.rfc-main {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.rfc-time { font-size: 22px; font-weight: 700; color: var(--text); }
.rfc-km   { font-size: 14px; color: var(--muted); }

.rfc-badge {
    font-size: 11px;
    font-weight: 700;
    padding: 3px 8px;
    border-radius: 20px;
}

.rfc-via {
    font-size: 12px;
    color: var(--muted);
    margin-top: 2px;
}

.rfc-dots {
    display: flex;
    justify-content: center;
    gap: 5px;
    margin-top: 6px;
}

.rfc-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--dim);
    display: inline-block;
}

.rfc-dot.active { background: var(--blue); }

.rfc-actions {
    display: flex;
    gap: 8px;
    margin-top: 10px;
}

.rfc-start {
    flex: 1;
    background: var(--blue);
    color: white;
    border: none;
    border-radius: 20px;
    padding: 8px 16px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    touch-action: manipulation;
}

.rfc-close {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 8px 14px;
    color: var(--muted);
    font-size: 14px;
    cursor: pointer;
    touch-action: manipulation;
}
/* ── Navigation sheet ────────────────────────────────────────────── */
#nav-sheet {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 300;
    background: rgba(15, 17, 23, 0.92);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid rgba(255,255,255,0.1);
    border-radius: 0 0 24px 24px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.5);
    padding: 16px 16px 14px;
    padding-top: max(16px, env(safe-area-inset-top));
    display: none;
    width: 100%;
}

#nav-turn {
    display: flex;
    align-items: flex-start;
    gap: 12px;
}
#nav-left {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
    width: 52px;
}
#nav-icon {
    font-size: 44px;
    line-height: 1;
    text-align: center;
}
#nav-info {
    flex: 1;
    min-width: 0;
}
#nav-dist {
    font-size: 26px;
    font-weight: 800;
    color: #ffffff;
    line-height: 1;
}
#nav-instr {
    font-size: 16px;
    font-weight: 600;
    color: rgba(255,255,255,0.95);
    white-space: normal;
    line-height: 1.3;
    margin-top: 4px;
    word-wrap: break-word;
}
#nav-next {
    font-size: 12px;
    color: rgba(255,255,255,0.45);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 3px;
    display: none;
}
#nav-stop {
    width: 100%;
    padding: 4px 6px;
    background: rgba(239,68,68,0.2);
    border: 1px solid rgba(239,68,68,0.35);
    border-radius: 6px;
    font-size: 11px;
    font-weight: 600;
    color: #fca5a5;
    cursor: pointer;
    touch-action: manipulation;
    text-align: center;
}
#nav-rerouting {
    font-size: 13px;
    color: #f59e0b;
    text-align: center;
    padding-top: 8px;
    font-weight: 700;
}

/* ── Speed badge ─────────────────────────────────────────────────── */
#speed-badge {
    position: fixed;
    bottom: 90px;
    right: 16px;
    z-index: 250;
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: 12px;
    padding: 6px 10px;
    text-align: center;
    box-shadow: 0 2px 10px rgba(0,0,0,0.2);
    display: none;
    min-width: 52px;
}

.sb-speed {
    font-size: 22px;
    font-weight: 700;
    color: var(--text);
    line-height: 1;
}

.sb-speed.sb-over {
    color: #ef4444;
}

.sb-limit {
    font-size: 11px;
    color: var(--muted);
    margin-top: 2px;
    border-top: 1px solid var(--border);
    padding-top: 2px;
}

/* ── User position dot ───────────────────────────────────────────── */
#user-dot {
    width: 22px;
    height: 22px;
}

.ud-inner {
    width: 16px;
    height: 16px;
    background: #3b8fff;
    border: 3px solid white;
    border-radius: 50%;
    box-shadow: 0 0 0 3px rgba(59,143,255,0.3);
    margin: 3px;
}

/* ── Navigation mode ─────────────────────────────────────────────── */
body.nav-active #top-bar {
    display: none !important;
}
body.nav-active .rfc-close {
    display: none !important;
}
body.nav-active #btn-clear-route {
    display: none !important;
}
body.nav-active #btn-start-nav {
    display: none !important;
}
body.nav-active #sheet-route #btn-clear-route {
    display: none !important;
}
body.nav-active #sheet-route #btn-start-nav {
    display: none !important;
}
body.nav-active #bottom-sheet {
    display: none !important;
}
