:root {
    --sidebar-width: 30vw;
    --sidebar-max-width: 500px;
    --animation-speed: 0.5s;
}

/* 1. CSS CHUNG */
#map-container {
    display: block;
    height: calc(100vh - 75px);
    width: 100%;
    position: relative;
}

#sidebar-map {
    background: #f9f9f9;
    border-right: 1px solid #ccc;
    transition: width var(--animation-speed) ease, transform var(--animation-speed) ease-in-out;
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    z-index: 990;
    overflow: hidden;
}

#map {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    margin-left: min(var(--sidebar-width), var(--sidebar-max-width));
    transition: margin-left var(--animation-speed) ease;
}

/* ⬇️ THÊM: CSS CHO MAP LOADER BAN ĐẦU ⬇️ */
#map-loader {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #f9f9f9;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1001;
    opacity: 1;
    transition: opacity 0.5s ease;
}

#map-loader.is-hidden {
    opacity: 0;
    pointer-events: none;
}

/* ⬇️ THÊM: CSS CHO MAP RESIZE OVERLAY ⬇️ */
#map-resize-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 1);
    /* Nền tối mờ */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1002;
    /* Nằm trên map, dưới sidebar */
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    color: white;
    /* Chữ màu trắng */
}

#map-resize-overlay.is-visible {
    opacity: 1;
    pointer-events: all;
}

/* Cố định chiều rộng nội dung sidebar */
#sidebar-main-loader,
#sidebar-content-wrapper {
    width: var(--sidebar-width);
    max-width: var(--sidebar-max-width);
    height: 100%;
    display: flex;
    flex-direction: column;
}

#search-bar {
    padding: 10px;
    border-bottom: 1px solid #ddd;
    background: #f7f7f7;
}

/* 2. CSS CHO DESKTOP (Mặc định) */
#sidebar-map {
    width: var(--sidebar-width);
    max-width: var(--sidebar-max-width);
    transform: translateX(0);
}

#sidebar-toggle-btn {
    position: absolute;
    top: 50%;
    left: min(var(--sidebar-width), var(--sidebar-max-width));
    transform: translateY(-50%);
    width: 25px;
    height: 50px;
    background-color: #fff;
    border: 1px solid #ccc;
    border-left: none;
    border-radius: 0 4px 4px 0;
    cursor: pointer;
    z-index: 1003;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: left var(--animation-speed) ease;
}

#sidebar-toggle-btn:hover {
    background-color: #f9f9f9;
}

#sidebar-toggle-btn .fa-chevron-right {
    display: none;
}

#map-container.sidebar-collapsed #sidebar-map {
    width: 0;
    border-right: none;
}

#map-container.sidebar-collapsed #map {
    margin-left: 0;
}

#map-container.sidebar-collapsed #sidebar-toggle-btn {
    left: 0;
}

#map-container.sidebar-collapsed #sidebar-toggle-btn .fa-chevron-left {
    display: none;
}

#map-container.sidebar-collapsed #sidebar-toggle-btn .fa-chevron-right {
    display: block;
}

.mobile-sidebar-header {
    display: none;
}

.mobile-close-btn {
    display: none;
}

#mobile-map-sidebar-open-btn {
    display: none;
}


/* 3. CSS CHO MOBILE (max-width: 768px) */
@media (max-width: 768px) {
    #map-container {
        overflow: hidden;
    }

    #sidebar-map {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        max-width: 100%;
        height: 100%;
        z-index: 2000;
        background-color: #fff;
        transform: translateX(-100%);
    }

    #sidebar-main-loader,
    #sidebar-content-wrapper {
        width: 100%;
        max-width: 100%;
    }

    #map {
        margin-left: 0;
    }

    #sidebar-map.sidebar-visible {
        transform: translateX(0);
    }

    #sidebar-toggle-btn {
        display: none !important;
    }

    .mobile-sidebar-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 10px 15px;
        border-bottom: 1px solid #ddd;
        background: #f9f9f9;
    }

    .mobile-sidebar-title {
        font-weight: 600;
        font-size: 1.1rem;
    }

    .mobile-close-btn {
        display: block;
        font-size: 1.5rem;
        cursor: pointer;
        color: #555;
    }

    #mobile-map-sidebar-open-btn {
        display: flex;
        position: absolute;
        top: 10px;
        left: 10px;
        z-index: 1000;
        background: #fff;
        border: 1px solid #ccc;
        border-radius: 4px;
        width: 40px;
        height: 40px;
        font-size: 1.2rem;
        color: #333;
        cursor: pointer;
        align-items: center;
        justify-content: center;
        box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
    }
}

/* Chi tiết kết quả: cho phép bảng cuộn khi quá dài */
#btabs-detail {
    padding: 10px;
}

#btabs-detail .detail-table-wrapper {
    max-height: calc(100vh - 220px);
    overflow-y: auto;
}

#btabs-detail .detail-table-wrapper table {
    width: 100%;
}

/* Container chính: Đặt vị trí tương đối để căn chỉnh menu con */
.google-layers-control {
    position: relative;
    margin: 10px;
    font-family: 'Roboto', Arial, sans-serif;
    z-index: 999;
    /* Đảm bảo nổi lên trên */
}

/* Nút kích hoạt (Icon Lớp) */
.layer-trigger-btn {
    width: 40px;
    height: 40px;
    background-color: #fff;
    border-radius: 2px;
    /* Bo góc nhẹ giống Google */
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.layer-trigger-btn:hover {
    background-color: #f1f1f1;
}

/* Icon SVG bên trong nút */
.layer-icon-svg {
    width: 24px;
    height: 24px;
    fill: #565656;
}

/* Bảng chứa các lựa chọn (Ẩn mặc định) */
.layer-panel {
    position: absolute;
    bottom: 0;
    left: 45px;
    /* Cách nút chính một chút sang phải */
    background: #fff;
    padding: 10px;
    border-radius: 4px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    display: flex;
    /* Xếp ngang */
    gap: 10px;

    /* Hiệu ứng ẩn/hiện */
    opacity: 0;
    visibility: hidden;
    transform: translateX(-10px);
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}

/* Khi hover vào container cha thì hiện bảng lựa chọn */
.basemap-layers-control:hover .layer-panel {
    opacity: 1;
    visibility: visible;
    transform: translateX(0);
}

/* Mũi tên nhỏ chỉ vào nút (trang trí) */
.layer-panel::before {
    content: '';
    position: absolute;
    left: -6px;
    bottom: 12px;
    width: 0;
    height: 0;
    border-top: 6px solid transparent;
    border-bottom: 6px solid transparent;
    border-right: 6px solid #fff;
}

/* Style cho từng ô Thumbnail (giống bài trước) */
.layer-card {
    width: 60px;
    height: 60px;
    border-radius: 8px;
    /* Bo tròn nhiều hơn cho hiện đại */
    border: 2px solid #fff;
    /* Viền trắng tạo khoảng cách */
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    cursor: pointer;
    position: relative;
    overflow: hidden;
    transition: transform 0.2s, border-color 0.2s;
}

.layer-card:hover {
    transform: scale(1.05);
}

.layer-card.active {
    border: 2px solid #3367D6;
    /* Màu xanh Google */
    box-shadow: 0 0 0 2px rgba(51, 103, 214, 0.3);
}

.layer-label {
    position: absolute;
    bottom: 0;
    width: 100%;
    background: rgba(0, 0, 0, 0.6);
    color: #fff;
    font-size: 10px;
    text-align: center;
    padding: 3px 0;
}

/* Các background giả lập */
.bg-road {
    background: linear-gradient(135deg, #f5f5f5 25%, #e0e0e0 25%, #e0e0e0 50%, #f5f5f5 50%, #f5f5f5 75%, #e0e0e0 75%);
    background-size: 20px 20px;
}

.bg-satellite {
    background: linear-gradient(135deg, #2c3e50 25%, #34495e 25%, #34495e 50%, #2c3e50 50%, #2c3e50 75%, #34495e 75%);
    background-size: 20px 20px;
}

.bg-hcm {
    background: repeating-linear-gradient(45deg, #fff3e0, #fff3e0 10px, #ffe0b2 10px, #ffe0b2 20px);
}

.layer-parent-checkbox:checked+label::before {
    transform: rotate(90deg);
}

.toggle-icon {
    width: 14px;        /* giữ chỗ cố định */
    text-align: center;
    transition: transform 0.2s ease;
}

/* node không có children */
.toggle-icon.placeholder {
    visibility: hidden;
}

/* khi mở */
.tree-node.expanded .toggle-icon {
    transform: rotate(90deg);
}

.layer-count {
    font-size: 11px;
    background: #e9f2ff;
    color: #0d6efd;
    border-radius: 10px;
    padding: 1px 6px;
}

#btabs-layers {
    height: calc(100vh - 300px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* phần nút giữ nguyên size */
#btabs-layers>.mb-2 {
    flex-shrink: 0;
}

/* phần list scroll */
#layer-list-wrapper {
    flex: 1;
    overflow-y: auto;
    scroll-behavior: smooth;
}
.tab-content {
    flex: 1;
    overflow: hidden;
    display: flex;
}

.tab-pane {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}