/**
 * Moderní Floating Off-Canvas Sidebar Drawer pro CB Lokátor
 * Seznam / Mapy.cz styl: táhlo/ouško na hraně panelu (Edge Tab)
 * Zajišťuje absolutně plynulý chod Leaflet mapy bez deformací a blikání dlaždic
 */

/* ==================== ZÁKLADNÍ ROZVRŽENÍ MAPY A PANELU ==================== */
/* Mapa pokrývá 100% plochy kontejneru a nikdy nemění svoji geometrii */
body.map-page .col-md-10.map-column {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    height: 100% !important;
    z-index: 1 !important;
    padding: 0 !important;
    margin: 0 !important;
    transition: none !important;
}

body.map-page #map {
    width: 100% !important;
    height: 100% !important;
    transition: none !important;
}

/* ==================== DESKTOP FLOATING DRAWER (>= 768px) ==================== */
@media (min-width: 768px) {
    body.map-page .col-md-2.sidebar-column {
        position: absolute !important;
        top: 0 !important;
        bottom: 0 !important;
        left: 0 !important;
        width: 380px !important;
        max-width: calc(100vw - 60px) !important;
        height: 100% !important;
        z-index: 1045 !important;
        background: #ffffff !important;
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.15) !important;
        transform: translateX(0);
        transition: transform 0.3s cubic-bezier(0.25, 1, 0.5, 1) !important;
        display: flex !important;
        flex-direction: column !important;
        padding: 12px 14px !important;
        overflow: visible !important; /* Důležité: umožňuje oušku vyčnívat na hraně panelu */
        pointer-events: auto;
    }

    /* Sbalený stav panelu na desktopu */
    body.sidebar-collapsed .col-md-2.sidebar-column {
        transform: translateX(-100%) !important;
        box-shadow: none !important;
        pointer-events: none !important;
    }

    /* Plynulý posun ovládacích prvků Leafletu (zoom nahoře, měřítko dole) vlevo */
    .leaflet-top.leaflet-left,
    .leaflet-bottom.leaflet-left {
        left: 395px !important;
        transition: left 0.3s cubic-bezier(0.25, 1, 0.5, 1) !important;
    }

    body.sidebar-collapsed .leaflet-top.leaflet-left,
    body.sidebar-collapsed .leaflet-bottom.leaflet-left {
        left: 34px !important;
    }
}

/* ==================== MOBILNÍ OFF-CANVAS DRAWER (< 768px) ==================== */
@media (max-width: 767.98px) {
    body.map-page .col-md-2.sidebar-column {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        bottom: 0 !important;
        width: min(88vw, 360px) !important;
        height: 100vh !important;
        height: 100dvh !important;
        background: #ffffff !important;
        z-index: 1055 !important;
        box-shadow: 4px 0 25px rgba(0, 0, 0, 0.35) !important;
        transform: translateX(-100%);
        transition: transform 0.3s cubic-bezier(0.25, 1, 0.5, 1) !important;
        display: flex !important;
        flex-direction: column !important;
        padding: 12px 14px !important;
        overflow: visible !important;
    }

    body.map-page .col-md-2.sidebar-column.sidebar-open {
        transform: translateX(0) !important;
    }

    /* Tmavý backdrop pod vysunutým panelem na mobilu */
    .sidebar-backdrop {
        position: fixed;
        top: 0;
        left: 0;
        width: 100vw;
        height: 100vh;
        height: 100dvh;
        background: rgba(0, 0, 0, 0.45);
        backdrop-filter: blur(2px);
        -webkit-backdrop-filter: blur(2px);
        z-index: 1050;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.3s ease;
    }

    .sidebar-backdrop.active {
        opacity: 1;
        pointer-events: auto;
    }

    /* Na mobilu ovládací prvky mapy */
    .leaflet-top.leaflet-left {
        left: 34px !important;
    }
}

/* ==================== SEZNAM / MAPY.CZ STYL: POST RANNÍ OUŠKO (EDGE TAB) ==================== */
.sidebar-edge-tab {
    position: absolute !important;
    left: 100% !important;
    top: 50% !important;
    transform: translateY(-50%) !important;
    width: 24px !important;
    height: 56px !important;
    background: #ffffff !important;
    border: 1px solid rgba(0, 0, 0, 0.15) !important;
    border-left: none !important;
    border-radius: 0 8px 8px 0 !important;
    box-shadow: 4px 0 12px rgba(0, 0, 0, 0.15) !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    padding: 0 !important;
    cursor: pointer !important;
    z-index: 1060 !important;
    pointer-events: auto !important; /* DŮLEŽITÉ: Klikatelné i při sbaleném panelu */
    color: #495057 !important;
    outline: none !important;
    transition: background 0.2s ease, width 0.2s ease, box-shadow 0.2s ease, color 0.2s ease !important;
}

.sidebar-edge-tab:hover {
    background: #f8f9fa !important;
    color: #0d6efd !important;
    width: 28px !important;
    box-shadow: 6px 0 16px rgba(0, 0, 0, 0.22) !important;
}

.sidebar-edge-tab i {
    font-size: 16px !important;
    line-height: 1 !important;
    transition: transform 0.2s ease !important;
}

.sidebar-edge-tab:hover i {
    transform: scale(1.15) !important;
}

@media (max-width: 767.98px) {
    .sidebar-edge-tab {
        width: 26px !important;
        height: 60px !important;
        border-radius: 0 10px 10px 0 !important;
    }
    
    .sidebar-edge-tab i {
        font-size: 18px !important;
    }
}

/* ==================== ZÁHLAVÍ PANELU A INTERNÍ OVLÁDÁNÍ ==================== */
.sidebar-header {
    flex-shrink: 0;
}

.sidebar-close-btn {
    line-height: 1;
    border-radius: 6px;
    padding: 3px 6px !important;
    transition: all 0.2s ease;
}

.sidebar-close-btn:hover {
    background-color: rgba(0, 0, 0, 0.06);
    color: #dc3545 !important;
    transform: scale(1.1);
}

/* ==================== DARK MODE PODPORA ==================== */
body.dark-mode .col-md-2.sidebar-column {
    background: #1a252f !important;
    color: #ecf0f1 !important;
    border-right: 1px solid rgba(255, 255, 255, 0.1) !important;
}

body.dark-mode .sidebar-header {
    border-color: rgba(255, 255, 255, 0.1) !important;
}

body.dark-mode .sidebar-close-btn {
    color: #adb5bd !important;
}

body.dark-mode .sidebar-close-btn:hover {
    background-color: rgba(255, 255, 255, 0.1);
    color: #ff6b6b !important;
}

body.dark-mode .sidebar-edge-tab {
    background: #1a252f !important;
    border-color: rgba(255, 255, 255, 0.2) !important;
    border-left: none !important;
    color: #ced4da !important;
    box-shadow: 4px 0 14px rgba(0, 0, 0, 0.5) !important;
}

body.dark-mode .sidebar-edge-tab:hover {
    background: #243342 !important;
    color: #4fc3f7 !important;
}
