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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    overflow: hidden;
    background: #1a1a1a;
}

#map {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: 100%;
}

.glass-panel {
    background: rgba(30, 30, 30, 0.65);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    color: #ffffff;
}

.control-btn {
    padding: 10px 16px;
    background: rgba(30, 30, 30, 0.65);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 8px;
    color: white;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 8px;
    border: none;
}

.control-btn:hover {
    background: rgba(40, 40, 40, 0.75);
    border-color: rgba(255, 255, 255, 0.25);
}

.control-btn svg {
    width: 16px;
    height: 16px;
}

#loading {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(26, 26, 26, 0.98);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    flex-direction: column;
    gap: 20px;
}

#loading.hidden {
    display: none;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(255, 255, 255, 0.1);
    border-top: 4px solid #2563eb;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

#header {
    position: fixed;
    top: 16px;
    left: 16px;
    z-index: 900;
    pointer-events: all;
}

#app-title {
    position: fixed;
    top: 10px;
    left: 10px;
    padding: 10px 16px;
}

#app-title h1 {
    font-size: 16px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

#zoom-menu-btn {
    position: fixed;
    top: 70px;
    left: 10px;
    z-index: 900;
    width: 40px;
    height: 40px;
    background: rgba(30, 30, 30, 0.85);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

#zoom-menu-btn:hover {
    background: rgba(40, 40, 40, 0.75);
}

#zoom-menu-btn svg {
    width: 20px;
    height: 20px;
    stroke: white;
}

#zoom-menu {
    position: fixed;
    top: 70px;
    left: 55px;
    z-index: 900;
    display: none;
    flex-direction: column;
    gap: 6px;
    padding: 8px;
    background: rgba(30, 30, 30, 0.65);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 8px;
}

#zoom-menu.visible {
    display: flex;
}

.zoom-menu-item {
    padding: 8px 14px;
    font-size: 12px;
    white-space: nowrap;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    color: white;
    border: none;
}

.zoom-menu-item:hover {
    background: rgba(255, 255, 255, 0.1);
}

#sidebar {
    position: fixed;
    top: 30px;
    right: -8px;
    width: 300px;
    max-height: calc(100vh - 96px);
    transform: translateX(0);
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 800;
    display: flex;
    flex-direction: column;
}

#sidebar.collapsed {
    transform: translateX(calc(100%)); 
}

#sidebar-toggle {
    position: absolute;
    left: -40px;
    top: 40px;
    width: 40px;
    height: 40px;
    background: rgba(30, 30, 30, 0.85);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px 0 0 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

#sidebar-toggle:hover {
    background: rgba(40, 40, 40, 0.9);
}

#sidebar-toggle svg {
    width: 20px;
    height: 20px;
    stroke: white;
    transition: transform 0.3s;
}

#sidebar.collapsed #sidebar-toggle svg {
    transform: rotate(180deg);
}

#sidebar-content {
    padding: 20px;
    overflow-y: auto;
    max-height: calc(100vh - 96px);
}

#sidebar-content::-webkit-scrollbar {
    width: 6px;
}

#sidebar-content::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 3px;
}

#sidebar-content::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}

.section-title {
    font-size: 13px;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.7);
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.layer-drag-handle {
    position: absolute;
    left: -20px;
    top: 12px;
    width: 16px;
    height: 100%;
    cursor: move;
    opacity: 0.3;
    transition: opacity 0.2s;
}

.layer-drag-handle::before {
    content: '⋮⋮';
    color: white;
    font-size: 14px;
    line-height: 1;
}

.layer-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

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

.layer-info {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
}

.layer-icon {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}

.layer-text {
    flex: 1;
}

.layer-label {
    font-size: 13px;
    color: #ffffff;
    font-weight: 500;
}

.layer-count {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.5);
}

.toggle-switch {
    position: relative;
    width: 44px;
    height: 24px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(255, 255, 255, 0.2);
    transition: .3s;
    border-radius: 24px;
}

.toggle-slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .3s;
    border-radius: 50%;
}

input:checked + .toggle-slider {
    background-color: #2563eb;
}

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

.layer-options {
    margin-top: 0px;
    padding-left: 16px;
    border-left: 2px solid rgba(255, 255, 255, 0.1);
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
}

.layer-options.expanded {
    max-height: 300px;
    margin-bottom: 0px;
}

.layer-options {
    padding-top: 0px; /* abans era 8px */
    padding-left: 12px; /* abans era 16px */
    padding-bottom: 4px;
}

.layer-option222 {
    padding: 4px 0; /* abans era 6px */
}

.layer-option label {
    font-size: 11px; /* abans era 12px */
}

.layer-option {
    padding: 6px 0;
}

.layer-option label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 12px;
    color: rgba(255, 255, 255, 0.7);
}

.layer-option input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: #2563eb;
}

#zoom-controls {
    position: fixed;
    bottom: 20px;
    right: 16px;
    z-index: 700;
    display: none;
    flex-direction: column;
    gap: 8px;
}

.zoom-btn {
    padding: 10px 16px;
    font-size: 12px;
    white-space: nowrap;
}

#search-container {
    margin-bottom: 16px;
}

#search-box {
    width: 100%;
    padding: 10px 12px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    color: white;
    font-size: 13px;
    outline: none;
}

#search-box:focus {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(37, 99, 235, 0.5);
}

#search-box::placeholder {
    color: rgba(255, 255, 255, 0.4);
}

#search-results {
    margin-top: 8px;
    max-height: 300px;
    overflow-y: auto;
    display: none;
}

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

.search-result-item {
    padding: 10px 12px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 6px;
    margin-bottom: 6px;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 12px;
}

.search-result-item:hover {
    background: rgba(255, 255, 255, 0.08);
}

.search-result-name {
    font-weight: 500;
    color: #ffffff;
}

.search-result-type {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.5);
    margin-top: 2px;
}

#map-controls {
    position: fixed;
    bottom: 20px;
    left: 16px;
    z-index: 700;
    display: flex;
    gap: 12px;
}

/* SELECTOR DE MAPA BASE */
.select-container {
    position: relative;
    margin-bottom: 16px;
}

.select-container select {
    width: 100%;
    padding: 10px 12px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    color: white;
    font-size: 13px;
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='white'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 16px;
    padding: 8px 32px 8px 10px;
    color: white;
}

.select-container select:hover {
    background-color: rgba(255, 255, 255, 0.08);
}

.select-container select option {
    background: #1a1a1a;
    color: white;
}


#legend {
    position: fixed;
    bottom: 10px;
    right: 10px;
    padding: 16px;
    z-index: 600;
    max-width: 200px;
}

#legend h3 {
    font-size: 12px;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.9);
    margin-bottom: 10px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
    font-size: 11px;
    color: rgba(255, 255, 255, 0.7);
}

.legend-color {
    width: 14px;
    height: 14px;
    border-radius: 50%;
}

.maplibregl-popup-content {
    padding: 12px;
    border-radius: 8px;
    background: rgba(30, 30, 30, 0.95);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: white;
}

.maplibregl-popup-close-button {
    position: absolute;
    top: 6px;
    right: 6px;
    font-size: 28px;
    color: white;
}

.popup-title {
    font-size: 14px;
    font-weight: 600;
    color: #ffffff;
    margin-right: 20px;
    margin-bottom: 10px;
    padding-bottom: 8px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.popup-stat {
    display: flex;
    justify-content: space-between;
    margin: 6px 0;
    font-size: 12px;
}

.popup-stat-label {
    color: rgba(255, 255, 255, 0.6);
    margin-right: 12px;
}

.popup-stat-value {
    color: #ffffff;
    font-weight: 500;
}

.popup-alert {
    margin-top: 10px;
    padding: 6px 10px;
    background: rgba(239, 68, 68, 0.2);
    color: #fca5a5;
    border-radius: 4px;
    font-size: 11px;
    text-align: center;
    border: 1px solid rgba(239, 68, 68, 0.3);
}





#error {
    position: fixed;
    top: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(30, 30, 30, 0.95);
    backdrop-filter: blur(10px);
    color: #fca5a5;
    padding: 12px 20px;
    border-radius: 8px;
    border: 1px solid rgba(239, 68, 68, 0.3);
    z-index: 10001;
    display: none;
    max-width: 500px;
}

#error.visible {
    display: block;
}
/*
@media (max-width: 768px) {
    #sidebar {
        width: calc(100vw - 80px);
        max-width: 320px;
        top: 70px;
        right: 12px;
    }

    #header {
        top: 12px;
        left: 12px;
    }

    #app-title h1 {
        font-size: 14px;
    }

    #zoom-menu-btn {
        top: 60px;
        left: 12px;
    }

    #zoom-menu {
        top: 60px;
        left: 60px;
    }

    #legend {
        display: none;
    }

    .control-btn span {
        display: none;
    }
}

@media (max-width: 480px) {
    #sidebar {
        width: calc(100vw - 80px);
        max-width: 280px;
        right: 12px;
    }

    #sidebar.collapsed {
        transform: translateX(calc(100% + 60px));
    }
}*/

/* LLISTA DE CAPES MÉS COMPACTA */
.layer-item-container {
    margin-top: 0px; /* abans era 12px */
    margin-bottom: 0px; /* abans era 12px */
    padding:0;
    position: relative;
}

.layer-item-container:hover .layer-drag-handle {
    opacity: 0.6;
}


.layer-item {
    padding: 4px 10px; /* abans era 12px */
}

.layer-icon {
    width: 28px; /* abans era 32px */
    height: 28px;
    font-size: 16px; /* abans era 18px */
}

.layer-label {
    font-size: 12px; /* abans era 13px */
}

.layer-count {
    font-size: 10px; /* abans era 11px */
}

.toggle-switch {
    width: 40px; /* abans era 44px */
    height: 22px; /* abans era 24px */
}

.toggle-slider:before {
    height: 16px; /* abans era 18px */
    width: 16px;
}

input:checked + .toggle-slider:before {
    transform: translateX(18px); /* abans era 20px */
}


/* GRUPS DE CAPES */
.layer-group {
    margin-bottom: 16px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    overflow: hidden;
}

.layer-group-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    background: rgba(255, 255, 255, 0.08);
    cursor: pointer;
    transition: background 0.2s;
}

.layer-group-header:hover {
    background: rgba(255, 255, 255, 0.12);
}

.layer-group-title {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    font-size: 12px;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.9);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.layer-group-toggle {
    font-size: 18px;
    transition: transform 0.3s;
    opacity: 0.6;
}

.layer-group.collapsed .layer-group-toggle {
    transform: rotate(-90deg);
}

.layer-group-actions {
    display: flex;
    gap: 6px;
}

.layer-group-btn {
    padding: 4px 8px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 4px;
    color: white;
    font-size: 10px;
    cursor: pointer;
    transition: all 0.2s;
}

.layer-group-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.layer-group-content {
    max-height: 2000px;
    overflow: hidden;
    transition: max-height 0.3s ease;
    padding: 8px;
}

.layer-group.collapsed .layer-group-content {
    max-height: 0;
    padding: 0 8px;
}

