/* =============================================
   VARIABLES Y RESET
   ============================================= */
:root {
    --primary-color: #3b82f6;
    --primary-hover: #2563eb;
    --secondary-color: #6b7280;
    --success-color: #10b981;
    --warning-color: #f59e0b;
    --danger-color: #ef4444;
    --purple-color: #8b5cf6;
    
    --bg-color: #f3f4f6;
    --panel-bg: #ffffff;
    --border-color: #e5e7eb;
    --text-color: #1f2937;
    --text-muted: #6b7280;
    
    --header-height: 56px;
    --panel-width: 320px;
    --transition: 0.3s ease;
    
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1);
}

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

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    font-size: 14px;
    color: var(--text-color);
    background: var(--bg-color);
    overflow: hidden;
}

/* =============================================
   LAYOUT PRINCIPAL
   ============================================= */
#app {
    display: flex;
    flex-direction: column;
    height: 100%;
    width: 100%;
}

/* =============================================
   HEADER
   ============================================= */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--header-height);
    padding: 0 16px;
    background: var(--panel-bg);
    border-bottom: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    z-index: 1000;
}

.header h1 {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-color);
}

.menu-btn, .config-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: transparent;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    color: var(--text-color);
    transition: background var(--transition);
}

.menu-btn:hover, .config-btn:hover {
    background: var(--bg-color);
}

/* =============================================
   PANEL LATERAL
   ============================================= */
.side-panel {
    position: fixed;
    top: var(--header-height);
    left: 0;
    width: var(--panel-width);
    height: calc(100% - var(--header-height));
    background: var(--panel-bg);
    border-right: 1px solid var(--border-color);
    transform: translateX(-100%);
    transition: transform var(--transition);
    z-index: 900;
    overflow: hidden;
}

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

.panel-content {
    height: 100%;
    overflow-y: auto;
    padding: 16px;
    -webkit-overflow-scrolling: touch;
}

.panel-section {
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-color);
}

.panel-section:last-child {
    border-bottom: none;
}

.panel-section h2 {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 12px;
}

/* =============================================
   OVERLAY MÓVIL
   ============================================= */
.overlay {
    position: fixed;
    top: var(--header-height);
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--transition), visibility var(--transition);
    z-index: 800;
}

.overlay.visible {
    opacity: 1;
    visibility: visible;
}

/* =============================================
   FORMULARIOS Y CONTROLES
   ============================================= */
.filter-group {
    margin-bottom: 16px;
}

.filter-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 6px;
    color: var(--text-color);
}

.filter-group select,
.filter-group input[type="text"] {
    width: 100%;
    padding: 10px 12px;
    font-size: 0.9375rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--panel-bg);
    color: var(--text-color);
    transition: border-color var(--transition), box-shadow var(--transition);
    -webkit-appearance: none;
}

.filter-group select:focus,
.filter-group input[type="text"]:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* Autocomplete List */
.autocomplete-list {
    list-style: none;
    max-height: 200px;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-top: none;
    border-radius: 0 0 8px 8px;
    background: var(--panel-bg);
    display: none;
}

.autocomplete-list.show {
    display: block;
}

.autocomplete-list li {
    padding: 10px 12px;
    cursor: pointer;
    transition: background var(--transition);
}

.autocomplete-list li:hover {
    background: var(--bg-color);
}

/* Secciones List */
.secciones-list {
    max-height: 150px;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 8px;
    margin-bottom: 8px;
    background: var(--bg-color);
}

.seccion-item {
    display: flex;
    align-items: center;
    padding: 6px 8px;
    border-radius: 4px;
    cursor: pointer;
    transition: background var(--transition);
}

.seccion-item:hover {
    background: var(--panel-bg);
}

.seccion-item input {
    margin-right: 8px;
}

/* =============================================
   BOTONES
   ============================================= */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 12px 16px;
    font-size: 0.9375rem;
    font-weight: 500;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all var(--transition);
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-hover);
}

.btn-secondary {
    background: var(--bg-color);
    color: var(--text-color);
    border: 1px solid var(--border-color);
    margin-bottom: 8px;
}

.btn-secondary:hover {
    background: var(--border-color);
}

/* =============================================
   LAYER TOGGLES
   ============================================= */
.layer-toggle {
    margin-bottom: 10px;
}

.toggle-label {
    display: flex;
    align-items: center;
    cursor: pointer;
    padding: 8px;
    border-radius: 8px;
    transition: background var(--transition);
}

.toggle-label:hover {
    background: var(--bg-color);
}

.toggle-label input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: relative;
    width: 40px;
    height: 22px;
    background: var(--border-color);
    border-radius: 11px;
    margin-right: 10px;
    transition: background var(--transition);
}

.toggle-slider::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 18px;
    height: 18px;
    background: white;
    border-radius: 50%;
    transition: transform var(--transition);
    box-shadow: var(--shadow-sm);
}

.toggle-label input:checked + .toggle-slider {
    background: var(--primary-color);
}

.toggle-label input:checked + .toggle-slider::after {
    transform: translateX(18px);
}

.layer-color {
    width: 12px;
    height: 12px;
    border-radius: 3px;
    margin-right: 8px;
}

/* =============================================
   SELECTED LAYERS
   ============================================= */
.selected-layers {
    max-height: 200px;
    overflow-y: auto;
}

.selected-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 10px;
    background: var(--bg-color);
    border-radius: 6px;
    margin-bottom: 6px;
    font-size: 0.875rem;
}

.selected-item .item-info {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    min-width: 0;
}

.selected-item .item-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.selected-item .item-actions {
    display: flex;
    gap: 4px;
}

.selected-item button {
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    transition: all var(--transition);
}

.selected-item button:hover {
    background: var(--panel-bg);
    color: var(--text-color);
}

.selected-item button.active {
    color: var(--primary-color);
}

.empty-message {
    color: var(--text-muted);
    font-size: 0.875rem;
    text-align: center;
    padding: 16px;
}

/* =============================================
   MAP STYLE BUTTONS
   ============================================= */
.map-style-buttons {
    display: flex;
    gap: 8px;
}

.style-btn {
    flex: 1;
    padding: 10px;
    font-size: 0.875rem;
    font-weight: 500;
    border: 1px solid var(--border-color);
    background: var(--panel-bg);
    color: var(--text-color);
    border-radius: 8px;
    cursor: pointer;
    transition: all var(--transition);
}

.style-btn:hover {
    background: var(--bg-color);
}

.style-btn.active {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

/* =============================================
   MAPA
   ============================================= */
.map-container {
    flex: 1;
    position: relative;
    z-index: 1;
}

#map {
    width: 100%;
    height: 100%;
}

/* Info Popup */
.info-popup {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--panel-bg);
    padding: 16px 20px;
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    max-width: 90%;
    width: 320px;
    z-index: 1000;
    transition: opacity var(--transition), transform var(--transition);
}

.info-popup.hidden {
    opacity: 0;
    transform: translateX(-50%) translateY(20px);
    pointer-events: none;
}

.close-popup {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 28px;
    height: 28px;
    border: none;
    background: var(--bg-color);
    border-radius: 50%;
    font-size: 1.25rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
}

.close-popup:hover {
    background: var(--border-color);
}

#popupContent h3 {
    font-size: 1rem;
    margin-bottom: 8px;
    color: var(--text-color);
}

#popupContent p {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-bottom: 4px;
}

#popupContent strong {
    color: var(--text-color);
}

/* =============================================
   MODAL
   ============================================= */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    padding: 20px;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: var(--panel-bg);
    padding: 24px;
    border-radius: 16px;
    width: 100%;
    max-width: 400px;
    box-shadow: var(--shadow-lg);
}

.modal-content h2 {
    font-size: 1.25rem;
    margin-bottom: 20px;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 6px;
}

.form-group input {
    width: 100%;
    padding: 12px;
    font-size: 0.9375rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.modal-actions {
    display: flex;
    gap: 10px;
}

.modal-actions .btn {
    flex: 1;
}

/* =============================================
   HIDDEN UTILITY
   ============================================= */
.hidden {
    display: none !important;
}

/* =============================================
   RESPONSIVE - TABLET
   ============================================= */
@media (min-width: 768px) {
    .menu-btn {
        display: none;
    }
    
    .side-panel {
        transform: translateX(0);
    }
    
    .map-container {
        margin-left: var(--panel-width);
    }
    
    .overlay {
        display: none;
    }
    
    .info-popup {
        left: calc(var(--panel-width) + 50%);
        transform: translateX(calc(-50% - var(--panel-width) / 2));
    }
    
    .info-popup.hidden {
        transform: translateX(calc(-50% - var(--panel-width) / 2)) translateY(20px);
    }
}

/* =============================================
   RESPONSIVE - DESKTOP
   ============================================= */
@media (min-width: 1024px) {
    :root {
        --panel-width: 360px;
    }
    
    .header h1 {
        font-size: 1.25rem;
    }
    
    .panel-content {
        padding: 20px;
    }
}

/* =============================================
   LEAFLET CUSTOMIZATION
   ============================================= */
.leaflet-control-zoom {
    border: none !important;
    box-shadow: var(--shadow-md) !important;
}

.leaflet-control-zoom a {
    width: 36px !important;
    height: 36px !important;
    line-height: 36px !important;
    font-size: 18px !important;
    border-radius: 8px !important;
    border: none !important;
    background: var(--panel-bg) !important;
    color: var(--text-color) !important;
}

.leaflet-control-zoom a:hover {
    background: var(--bg-color) !important;
}

.leaflet-control-zoom-in {
    border-radius: 8px 8px 0 0 !important;
}

.leaflet-control-zoom-out {
    border-radius: 0 0 8px 8px !important;
}

.leaflet-popup-content-wrapper {
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
}

.leaflet-popup-tip {
    box-shadow: none;
}

/* Custom marker */
.custom-marker {
    background: var(--danger-color);
    border: 3px solid white;
    border-radius: 50%;
    box-shadow: var(--shadow-md);
}

/* Touch improvements for mobile */
@media (hover: none) and (pointer: coarse) {
    .btn, .style-btn, .toggle-label, .seccion-item {
        min-height: 44px;
    }
    
    .filter-group select,
    .filter-group input[type="text"] {
        font-size: 16px; /* Prevents zoom on iOS */
    }
}