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

html, body, #app {
    height: 100%;
    width: 100%;
}

body {
    font-family: "Segoe UI", Roboto, system-ui, sans-serif;
    color: #202124;
}

#app {
    display: flex;
    flex-direction: column;
}

/* ---- Thanh trên (quản lý) ---- */
#topbar {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 8px 16px;
    background: #1a1f28;
    color: #fff;
    z-index: 30;
}

.brand {
    font-weight: 700;
    font-size: 15px;
    white-space: nowrap;
}

#tools {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

    #tools button {
        border: 1px solid #333c4a;
        background: #262f3d;
        color: #dce3ec;
        padding: 6px 12px;
        border-radius: 6px;
        cursor: pointer;
        font-size: 13px;
    }

        #tools button:hover {
            background: #2f3a4a;
        }

        #tools button.active {
            background: #1a73e8;
            border-color: #1a73e8;
            color: #fff;
        }

        #tools button.ghost {
            background: transparent;
            border-color: #3a4657;
        }

.divider {
    width: 1px;
    height: 22px;
    background: #333c4a;
}

#hint {
    padding: 6px 16px;
    background: #eef3f8;
    color: #37475c;
    font-size: 13px;
    z-index: 20;
}

    #hint:empty {
        display: none;
    }

/* ---- Vùng bản đồ ---- */
#map-wrap {
    position: relative;
    flex: 1;
}

#map {
    position: absolute;
    inset: 0;
}

/* ---- Ô tìm kiếm nổi (góc trên trái) ---- */
#searchbox {
    position: absolute;
    top: 14px;
    left: 14px;
    z-index: 15;
    width: 360px;
    max-width: calc(100% - 28px);
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,.2);
    display: flex;
    align-items: center;
    padding: 0 12px;
}

.search-ico {
    font-size: 14px;
    opacity: .6;
}

#searchInput {
    flex: 1;
    border: 0;
    outline: 0;
    padding: 12px 10px;
    font-size: 14px;
    background: transparent;
}

#searchResults {
    position: absolute;
    top: 46px;
    left: 0;
    right: 0;
    background: #fff;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 4px 16px rgba(0,0,0,.2);
}

    #searchResults:empty {
        display: none;
    }

.sr-item {
    padding: 9px 14px;
    cursor: pointer;
    border-bottom: 1px solid #f0f0f0;
}

    .sr-item:hover {
        background: #f5f9ff;
    }

.sr-name {
    font-size: 14px;
    font-weight: 500;
}

.sr-sub {
    font-size: 12px;
    color: #70757a;
}

.sr-empty {
    padding: 12px 14px;
    font-size: 13px;
    color: #70757a;
}

/* ---- Panel chỉ đường (bên trái) ---- */
#directions {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    width: 360px;
    max-width: 88%;
    background: #fff;
    box-shadow: 2px 0 12px rgba(0,0,0,.15);
    z-index: 18;
    display: flex;
    flex-direction: column;
    transition: transform .25s ease;
}

    #directions.collapsed {
        transform: translateX(-100%);
    }

.dir-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #1a73e8;
    color: #fff;
    padding: 14px 16px;
}

.dir-title {
    font-size: 16px;
    font-weight: 600;
}

.icon-btn {
    border: 0;
    background: transparent;
    color: inherit;
    cursor: pointer;
    font-size: 16px;
    width: 30px;
    height: 30px;
    border-radius: 50%;
}

    .icon-btn:hover {
        background: rgba(255,255,255,.18);
    }

.dir-inputs {
    padding: 16px;
    border-bottom: 1px solid #eee;
}

.dir-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
    border: 1px solid #dadce0;
    border-radius: 8px;
    padding: 4px 10px;
}

    .dir-row input {
        flex: 1;
        border: 0;
        outline: 0;
        padding: 8px 4px;
        font-size: 14px;
    }

.dot-start, .dot-end {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
}

.dot-start {
    background: #1a73e8;
}

.dot-end {
    background: #ea4335;
}

.dir-row .icon-btn {
    color: #1a73e8;
}

.dir-modes {
    display: flex;
    gap: 8px;
    margin: 6px 0 14px;
}

.mode-btn {
    flex: 1;
    border: 1px solid #dadce0;
    background: #fff;
    border-radius: 8px;
    padding: 8px;
    font-size: 18px;
    cursor: pointer;
}

    .mode-btn.active {
        background: #e8f0fe;
        border-color: #1a73e8;
    }

.primary-btn {
    width: 100%;
    background: #1a73e8;
    color: #fff;
    border: 0;
    border-radius: 8px;
    padding: 12px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
}

    .primary-btn:hover {
        background: #1666cc;
    }

#dir-result {
    overflow-y: auto;
    padding: 0 16px;
}

.route-summary {
    padding: 16px 0;
    border-bottom: 1px solid #eee;
}

    .route-summary .big {
        font-size: 22px;
        font-weight: 700;
        color: #1a73e8;
    }

    .route-summary .sub {
        font-size: 13px;
        color: #5f6368;
        margin-top: 2px;
    }

.step {
    padding: 12px 0;
    border-bottom: 1px solid #f2f2f2;
    font-size: 13px;
    color: #3c4043;
}

#dirSuggest {
    background: #fff;
}

    #dirSuggest:empty {
        display: none;
    }

    #dirSuggest .sr-item {
        border: 1px solid #eee;
        border-radius: 6px;
        margin-bottom: 4px;
    }

/* ---- Nút mở chỉ đường (FAB) ---- */
.fab {
    position: absolute;
    top: 14px;
    left: 386px;
    z-index: 14;
    background: #1a73e8;
    color: #fff;
    border: 0;
    border-radius: 8px;
    padding: 11px 16px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0,0,0,.2);
}

    .fab:hover {
        background: #1666cc;
    }

/* ---- Bộ chọn kiểu bản đồ (góc dưới phải) ---- */
#layerSwitcher {
    position: absolute;
    bottom: 28px;
    right: 14px;
    z-index: 14;
    display: flex;
    gap: 8px;
    background: #fff;
    padding: 8px;
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(0,0,0,.2);
}

.layer-opt {
    border: 2px solid transparent;
    background: transparent;
    cursor: pointer;
    border-radius: 8px;
    padding: 4px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    color: #3c4043;
    width: 62px;
}

    .layer-opt.active {
        border-color: #1a73e8;
        color: #1a73e8;
        font-weight: 600;
    }

.layer-thumb {
    width: 52px;
    height: 40px;
    border-radius: 6px;
    background-size: cover;
}

.thumb-streets {
    background: linear-gradient(135deg,#e8f0e4 0%,#cfe0c8 40%,#f5f0e8 100%);
}

.thumb-sat {
    background: linear-gradient(135deg,#2c3e2f 0%,#4a5e3f 50%,#6b7a55 100%);
}

.thumb-terrain {
    background: linear-gradient(135deg,#d9c9a8 0%,#b8a878 50%,#8a9a6a 100%);
}

/* ---- Bật/tắt lớp phủ (góc dưới trái) ---- */
#overlayToggles {
    position: absolute;
    bottom: 28px;
    left: 14px;
    z-index: 14;
    background: #fff;
    padding: 10px 14px;
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(0,0,0,.2);
    font-size: 13px;
    display: flex;
    flex-direction: column;
    gap: 7px;
}

    #overlayToggles label {
        display: flex;
        align-items: center;
        gap: 7px;
        cursor: pointer;
        color: #3c4043;
    }

/* ---- Chấm vị trí hiện tại ---- */
.me-dot {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #1a73e8;
    border: 3px solid #fff;
    box-shadow: 0 0 0 rgba(26,115,232,.6);
    animation: mepulse 2s infinite;
}

@keyframes mepulse {
    0% {
        box-shadow: 0 0 0 0 rgba(26,115,232,.5);
    }

    70% {
        box-shadow: 0 0 0 14px rgba(26,115,232,0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(26,115,232,0);
    }
}

.maplibregl-popup-content {
    font-size: 13px;
    border-radius: 8px;
    padding: 12px 14px;
}

    .maplibregl-popup-content b {
        font-size: 14px;
    }


/* ---- Nút định vị nổi (góc phải, trên layer switcher) ---- */
.loc-fab {
    position: absolute;
    bottom: 150px;
    right: 14px;
    z-index: 14;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 0;
    background: #fff;
    color: #1a73e8;
    font-size: 22px;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0,0,0,.25);
    display: flex;
    align-items: center;
    justify-content: center;
}

    .loc-fab:hover {
        background: #f1f6ff;
    }

    .loc-fab.locating {
        color: #999;
    }

/* ===================== RESPONSIVE ĐIỆN THOẠI (nâng cấp) ===================== */
@media (max-width: 768px) {

    /* Thanh trên: cho cuộn ngang, khỏi tràn */
    #topbar {
        gap: 10px;
        padding: 8px 12px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    #tools {
        flex-wrap: nowrap;
    }

        #tools button {
            white-space: nowrap;
            flex-shrink: 0;
            padding: 6px 10px;
            font-size: 12px;
        }

    /* Ô tìm kiếm: gần full ngang */
    #searchbox {
        width: calc(100% - 20px);
        left: 10px;
        top: 12px;
    }

    /* Panel chỉ đường: trượt từ DƯỚI lên kiểu app (thay vì từ trái) */
    #directions {
        top: auto;
        bottom: 0;
        left: 0;
        width: 100%;
        max-width: 100%;
        height: auto;
        max-height: 72vh;
        border-radius: 16px 16px 0 0;
        box-shadow: 0 -4px 18px rgba(0,0,0,.22);
        transition: transform .25s ease;
    }
        /* Khi đóng: trượt xuống dưới (ghi đè translateX cũ cho hợp bố cục mới) */
        #directions.collapsed {
            transform: translateY(100%);
        }

    /* Nút mở chỉ đường: về góc trái, tránh đè ô tìm kiếm */
    .fab {
        left: 12px;
        top: auto;
        bottom: 24px;
    }

    /* Nút phương tiện: cao hơn cho dễ chạm */
    .mode-btn {
        padding: 10px;
    }

    /* Bộ chọn kiểu bản đồ: thu nhỏ, nâng lên tránh đè nút chỉ đường */
    #layerSwitcher {
        bottom: 20px;
        right: 10px;
        transform: scale(.9);
        transform-origin: bottom right;
    }

    /* Lớp phủ: thu nhỏ, cuộn nếu dài, nâng lên khỏi mép */
    #overlayToggles {
        bottom: 84px;
        left: 10px;
        font-size: 12px;
        padding: 8px 10px;
        gap: 5px;
        max-height: 42vh;
        overflow-y: auto;
        transform: scale(.92);
        transform-origin: bottom left;
    }

    /* Nút định vị: đưa lên trên layer switcher */
    .loc-fab {
        bottom: 96px;
        right: 10px;
    }
}

/* Điện thoại nhỏ */
@media (max-width: 400px) {
    .brand {
        display: none;
    }

    #layerSwitcher {
        transform: scale(.82);
    }

    #overlayToggles {
        transform: scale(.85);
    }
}

/* ===== Nút zoom (MapLibre ctrl) nằm TRÊN nút định vị, góc phải ===== */
/* Cần: trong app.js đặt control ở 'top-right' hoặc 'bottom-right'.
   CSS dưới ép nhóm control top-right xuống sát đáy, phía trên .loc-fab. */

/* Desktop: loc-fab ở bottom:150px, cao 44px. Đặt ctrl ngay trên nó. */
.maplibregl-ctrl-top-right {
    top: auto;
    bottom: 206px; /* 150 (loc-fab) + 44 (cao) + 12 (khoảng cách) */
    right: 14px;
}

    .maplibregl-ctrl-top-right .maplibregl-ctrl {
        margin: 0; /* bỏ margin mặc định để canh chuẩn */
    }

/* Đảm bảo cùng trục phải với loc-fab và không dính nhau */
.loc-fab {
    bottom: 150px;
    right: 14px;
}

@media (max-width: 768px) {
    /* Mobile: nâng lên 10px cho khỏi chạm layerSwitcher */
    .maplibregl-ctrl-top-right {
        bottom: 162px; /* 106 + 44 + 12 */
        right: 10px;
    }

    .loc-fab {
        bottom: 106px;
        right: 10px;
    }
    /* layer switcher đã ở bottom:20px, overlayToggles ở 84px trái - không đụng */
}

@media (max-width: 400px) {
    .maplibregl-ctrl-top-right {
        bottom: 158px;
    }

    .loc-fab {
        bottom: 106px;
    }
}
#navControls {
    position: absolute;
    top: 70px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 8px;
    z-index: 5;
}

.nav-btn {
    background: #1a73e8;
    color: #fff;
    border: 0;
    border-radius: 20px;
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0,0,0,.2);
}

    .nav-btn.sim {
        background: #7627bb;
    }

    .nav-btn.stop {
        background: #d93025;
    }

#navSpeedBox {
    position: absolute;
    bottom: 200px;
    left: 20px;
    z-index: 6;
    display: flex;
    align-items: center;
    gap: 12px;
}

.nav-cur {
    background: rgba(0,0,0,.75);
    color: #fff;
    border-radius: 12px;
    padding: 8px 16px;
    text-align: center;
    min-width: 70px;
}

    .nav-cur span {
        font-size: 28px;
        font-weight: 700;
    }

    .nav-cur small {
        display: block;
        font-size: 11px;
        opacity: .8;
    }

.nav-limit-sign {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: #fff;
    border: 5px solid #d93025;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    font-weight: 800;
    color: #000;
    box-shadow: 0 2px 8px rgba(0,0,0,.25);
}
/* Khi vượt tốc độ: ô số nhấp nháy đỏ */
#navSpeedBox.over-speed .nav-cur {
    background: #d93025;
    animation: speedFlash .6s infinite alternate;
}

@keyframes speedFlash {
    from {
        opacity: 1;
    }

    to {
        opacity: .55;
    }
}

.nav-arrow svg {
    display: block;
}