/* Layout New: Professional Sidebar & Responsive System */

/* Variables */
:root {
    --sidebar-width: 64px;
    --panel-width: 320px;
    --sidebar-bg: rgba(20, 25, 30, 0.85);
    --panel-bg: rgba(31, 41, 55, 0.70);

    --accent-color: #2563eb;
    --accent-hover: #1d4ed8;
    --text-primary: #f3f4f6;
    --text-secondary: #9ca3af;
    --glass-border: 1px solid rgba(255, 255, 255, 0.1);
    --glass-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.694), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

/* Base resets & overrides */
body {
    background-color: #0f1115;
    /* Darker background for depth */
}

/* =========================================
   MAIN SIDEBAR (The thin strip)
   ========================================= */
#app-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-right: var(--glass-border);
    z-index: 2100;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 16px 0;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Logo Area */
.app-brand {
    margin-bottom: 24px;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 48px;
    height: 48px;
    border-radius: 12px;
    background: rgba(37, 99, 235, 0.1);
    color: #60a5fa;
    font-size: 20px;
    cursor: pointer;
    transition: transform 0.2s;
}

.app-brand:hover {
    transform: scale(1.05);
    background: rgba(37, 99, 235, 0.2);
}

/* Navigation Items */
.nav-items {
    display: flex;
    flex-direction: column;
    row-gap: 8px;
    width: 100%;
    align-items: center;
    flex: 1;
    /* Pushes bottom items down */
}

.nav-item {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    background: transparent;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
}

.nav-item:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-primary);
}

/* TAB STYLE ACTIVE STATE */
.nav-item.active {
    background: var(--panel-bg);
    color: var(--accent-color);
    box-shadow: none;
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
    margin-right: -1px;
    /* Overlap border */
    z-index: 2001;
    /* Above panel border */
    border-left: 3px solid var(--accent-color);
}

.nav-item svg {
    width: 22px;
    height: 22px;
}

/* Alert/Notification Badge */
.nav-badge {
    position: absolute;
    top: 2px;
    right: 2px;
    min-width: 18px;
    height: 18px;
    padding: 2px 5px;
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    border-radius: 10px;
    font-size: 10px;
    font-weight: 700;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3), 0 0 0 2px rgba(20, 25, 30, 0.85);
    animation: pulse-badge 2s infinite;
    pointer-events: none;
}

@keyframes pulse-badge {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.08);
    }
}

/* Tooltip on Hover */
.nav-item::after {
    content: attr(data-title);
    position: absolute;
    left: 54px;
    background: rgba(0, 0, 0, 0.8);
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 11px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
    transform: translateX(5px);
}

.nav-item:hover::after {
    opacity: 1;
    transform: translateX(0);
}

/* Bottom Actions in Sidebar */
.bottom-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
    align-items: center;
    padding-top: 16px;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}

/* =========================================
   PANELS (Content sliding out)
   ========================================= */
.sidebar-panel {
    position: fixed;
    top: 0;
    left: var(--sidebar-width);
    height: 100vh;
    width: var(--panel-width);
    background: var(--panel-bg);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(16px);
    border-right: var(--glass-border);
    z-index: 1000;
    transform: translateX(-105%);
    /* Hidden by default */
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    box-shadow: 10px 0 25px -5px rgba(0, 0, 0, 0.3);
    border-radius: 0 12px 12px 0;
}

/* Wider panel for reports */
.sidebar-panel-wide {
    width: 480px;
}

.sidebar-panel.open {
    transform: translateX(0);
}

.panel-header {
    padding: 6px;
    padding-left: 20px;
    padding-right: 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    /*background-color: rgb(37, 99, 235);
    background-color: rgba(20, 25, 30, 0.85);*/
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.panel-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.panel-close {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: background 0.2s;
}

.panel-close:hover {
    background: rgba(255, 255, 255, 0.1);
    color: white;
}

.panel-content {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

/* Summary Panel Specifics */
.summary-card {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 12px;
}

.summary-value {
    font-size: 24px;
    font-weight: 700;
    color: var(--accent-color);
}

.summary-label {
    font-size: 12px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* =========================================
   OVERRIDES for Existing Elements
   ========================================= */
/* Hide old headers and toggles if they exist */
#header,
#sidebar-toggles,
.sidebar-drag-handle,
#zoom-controls {
    display: none !important;
}

/* Map Controls (Legend etc) */
#map-controls {
    position: fixed;
    bottom: 0px;
    right: 0px;
    z-index: 500;
    display: flex;
    flex-direction: column;
    gap: 0px;
    align-items: flex-end;
}

/*
#legend {
    width: 100px;
    font-size: 12px;
}*/

/* =========================================
   RESPONSIVE (Mobile)
   ========================================= */
@media (max-width: 768px) {
    :root {
        --sidebar-width: 0px;
        --nav-height: 60px;
    }

    #app-sidebar {
        top: auto;
        bottom: 0;
        left: 0;
        width: 100%;
        height: var(--nav-height);
        flex-direction: row;
        padding: 0 16px;
        border-right: none;
        border-top: var(--glass-border);
        justify-content: space-around;
    }

    .app-brand {
        display: none;
    }

    .nav-items {
        flex-direction: row;
        justify-content: space-around;
        gap: 0;
    }

    .bottom-actions {
        display: flex;
        flex-direction: row;
        align-items: center;
        gap: 0;
        width: auto;
        padding-top: 0;
        border-top: none;
        margin-left: 8px;
    }

    .nav-item::after {
        display: none;
        /* No tooltips on mobile */
    }

    /* Mobile Active State Override */
    .nav-item.active {
        border-radius: 10px;
        margin-right: 0;
        border-left: none;
        border-bottom: 3px solid var(--accent-color);
        background: rgba(255, 255, 255, 0.05);
    }

    .sidebar-panel {
        left: 0;
        top: auto;
        bottom: 0;
        /* Align to bottom, height controlled via JS/CSS */
        width: 100%;
        height: 35vh;
        /* Initial height ~1/3 */
        max-height: 90vh;
        /* Bottom sheet style */
        border-right: none;
        border-top: var(--glass-border);
        border-radius: 16px 16px 0 0;
        transform: translateY(105%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), height 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        z-index: 2005;
        /* Above bottom nav */
        display: flex;
        flex-direction: column;
    }

    .sidebar-panel.open {
        transform: translateY(0);
        bottom: var(--nav-height);
        /* Sit above nav bar */
    }

    /* Remove transition when dragging to avoid lag */
    .sidebar-panel.dragging {
        transition: none;
    }

    /* Drag Handle Area */
    .panel-drag-handle {
        width: 100%;
        height: 16px;
        /* More compact */
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: ns-resize;
        flex-shrink: 0;
        touch-action: none;
        background: transparent;
        margin-top: 4px;
        /* Little spacing from top border */
    }

    /* The visual pill */
    .panel-drag-handle::after {
        content: "";
        width: 32px;
        /* Smaller width */
        height: 4px;
        /* Thinner */
        background: rgba(255, 255, 255, 0.3);
        border-radius: 10px;
    }

    /* Compact Header for Mobile */
    .panel-header {
        padding: 4px 16px;
        /* Very compact */
        border-bottom: 1px solid rgba(255, 255, 255, 0.05);
        /* Keep border but maybe lighter? */
        min-height: 40px;
        /* Reduced form 48px */
    }

    .panel-title {
        font-size: 14px;
        /* Compact font */
    }

    .panel-close {
        padding: 2px;
        /* Compact close button */
    }

    /* Adjust content area */
    .panel-content {
        padding: 12px;
        padding-bottom: 80px;
    }


    /* Adjust map controls for bottom nav */
    #map-controls {
        bottom: calc(var(--nav-height) + 0px);
        right: 0px;
        transition: bottom 0.3s;
        /* Forced z-index to be below sidebar if needed, but sidebar has 2005. 
           Controls usually 500. Legend should be BEHIND if overlapping??? 
           Actually user said "tapada pel sidebar" (covered by sidebar). 
           Sidebar z-index is 2005. Map controls z-index is 500. 
           So Sidebar covers Legend naturally. We just stop moving it up. 
        */
    }


    /* REMOVED body.panel-open #map-controls override so it stays down and gets covered */
}

/* =========================================
   CUSTOM VIEWS LIST
   ========================================= */
#views-list-container {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 25px;
}

.view-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 6px;
    padding: 2px 10px;
    transition: all 0.2s ease;
}

.view-item:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.15);
}

.view-name {
    flex: 1;
    font-size: 0.9rem;
    color: var(--text-primary);
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.view-name:hover {
    color: var(--accent-color);
}

.view-actions {
    display: flex;
    gap: 6px;
    opacity: 0.6;
    transition: opacity 0.2s;
}

.view-item:hover .view-actions {
    opacity: 1;
}

.view-action-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    font-size: 0.9rem;
    line-height: 1;
    transition: all 0.2s;
}

.view-action-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: white;
}

.view-action-btn.danger:hover {
    background: rgba(239, 68, 68, 0.2);
    color: #ef4444;
}

.view-reset-btn:hover {
    background: rgba(255, 255, 255, 0.1) !important;
    border-color: rgba(255, 255, 255, 0.2) !important;
    color: white !important;
}

/* Update Menu Items for consistency */
.zoom-menu-item {
    width: 100%;
    text-align: left;
    padding: 10px 12px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    color: var(--text-secondary);
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.zoom-menu-item:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-primary);
    transform: translateX(2px);
}

#back-view-btn:hover {
    background: rgba(37, 99, 235, 0.3) !important;
    border-color: rgba(37, 99, 235, 0.5) !important;
    color: #93c5fd !important;
}