:root {
    --primary: #0ea5e9;
    --dark: #1e293b;
    --glass: rgba(255, 255, 255, 0.95);
    --border: #e2e8f0;
    --sidebar-width: 240px;
}

body, html { margin:0; padding:0; height:100%; width: 100%; font-family: 'Inter', sans-serif; overflow:hidden; }
#map { height: 100vh; width: 100vw; z-index: 1; position: absolute; top:0; left:0; }

/* --- SIDEBAR BASE --- */
.sidebar {
    position: absolute; top: 15px; bottom: 15px; width: var(--sidebar-width);
    background: var(--glass); z-index: 2000; display: flex; flex-direction: column;
    border-radius: 16px; border: 1px solid var(--border);
    transition: transform 0.4s ease; backdrop-filter: blur(10px); box-shadow: 0 10px 25px -5px rgba(0,0,0,0.1);
}
#sidebar-left { left: 15px; }
#sidebar-right { right: 15px; }
#sidebar-left.collapsed { transform: translateX(-270px); }
#sidebar-right.collapsed { transform: translateX(270px); }

.mini-title { font-size: 0.65rem !important; opacity: 0.8; }

/* --- BOTÓN FLOTANTE (FOOTER) CUANDO ESTÁ COLAPSADO --- */
.sidebar.collapsed .sidebar-footer { 
    position: absolute; 
    top: 0; 
    width: 44px; /* Cuadrado pequeño */
    height: 44px; 
    border-radius: 8px; 
    z-index: 3000; 
    border: 1px solid var(--border);
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    justify-content: center; /* Centrar icono */
}

/* Ocultar texto cuando está colapsado (para que sea solo icono) */
.sidebar.collapsed .toggle-text { display: none; }

/* Posición del botón flotante */
#sidebar-left.collapsed .sidebar-footer { right: -60px; }
#sidebar-right.collapsed .sidebar-footer { left: -60px; }

.sidebar-header { padding: 15px 20px; border-bottom: 1px solid var(--border); }
.brand h1 { font-size: 0.8rem; margin: 0; font-weight: 800; color: var(--dark); }

.sidebar-content { flex: 1; padding: 10px; overflow-y: auto; }

/* --- FOOTER EXPANDIDO --- */
.sidebar-footer {
    height: 44px; background: var(--dark); color: #fff;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; font-size: 0.7rem; border-radius: 0 0 16px 16px; font-weight: 600; gap: 8px;
}

/* --- IMPRESIÓN --- */
@media print {
    #sidebar-left, .sidebar-header, .sidebar-footer, .tool-card-sidebar, .gps-btn, button, .leaflet-control-zoom, .leaflet-control-attribution, section:not(.seccion-simbologia) { display: none !important; }
    .modo-impresion-activa #map { position: fixed !important; top: 0; left: 0; width: 100%; height: 100%; z-index: 1; }
    .modo-impresion-activa #sidebar-right { display: block !important; position: absolute !important; right: 1cm; bottom: 1cm; width: 6.5cm; background: white; border: 1px solid #000; z-index: 9999; }
    .modo-impresion-activa .sidebar-content { overflow: visible !important; background: white; }
    .modo-impresion-activa #legend-container { display: block !important; }
    .legend-dot { print-color-adjust: exact; -webkit-print-color-adjust: exact; }
}

.legend-item { display: flex; align-items: center; gap: 12px; margin-bottom: 4px; font-size: 0.75rem; font-weight: 600; color: #1e293b; }
.legend-dot { width: 12px; height: 12px; border-radius: 50%; border: 1.5px solid #fff; box-shadow: 0 1px 3px rgba(0,0,0,0.2); }
.legend-line { width: 35px; height: 5px; border-radius: 3px; border: 1px solid rgba(0,0,0,0.1); }
.legend-border { width: 30px; height: 12px; border-radius: 1px; }

.tool-card-sidebar {
    display: flex; align-items: center; gap: 10px; padding: 10px;
    background: #f8fafc; border-radius: 12px; border: 1px solid var(--border); margin: 5px 0 15px 0;
}
.tool-title { font-size: 0.7rem; font-weight: 800; color: var(--dark); display: block; }
.tool-desc { font-size: 0.65rem; color: #64748b; }

.gps-btn { width: 34px; height: 34px; border-radius: 50%; border: none; background: #fff; cursor: pointer; display: flex; align-items: center; justify-content: center; box-shadow: 0 2px 4px rgba(0,0,0,0.05); }
.gps-btn svg { width: 18px; height: 18px; fill: #64748b; }
.gps-btn.active { background: var(--primary); }
.gps-btn.active svg { fill: white; }

.menu-section { border: 1px solid var(--border); border-radius: 12px; background: white; margin-bottom: 10px; overflow: hidden; }
.section-trigger { padding: 12px 15px; cursor: pointer; display: flex; justify-content: space-between; align-items: center; font-weight: 700; font-size: 0.7rem; color: var(--dark); }
.section-content.collapsed { max-height: 0; overflow: hidden; }

.close-btn { cursor: pointer; color: #ef4444; font-size: 14px; font-weight: bold; padding: 2px 6px; border-radius: 4px; transition: background 0.2s; }
.close-btn:hover { background: #fee2e2; }

/* POPUP ESTILO */
.popup-container { font-family: 'Inter', sans-serif; min-width: 220px; padding: 5px; }
.popup-title { font-size: 13px; font-weight: 800; color: #1e293b; margin-bottom: 3px; text-transform: uppercase; line-height: 1.2; }
.popup-sub { font-size: 11px; color: #64748b; font-weight: 600; margin-bottom: 2px; }
.popup-mun { font-size: 10px; color: #94a3b8; font-style: italic; margin-bottom: 12px; border-bottom: 1px solid #f1f5f9; padding-bottom: 8px; }
.popup-btn { width: 100%; padding: 10px; background: #0ea5e9; color: white; border: none; border-radius: 8px; font-weight: 800; cursor: pointer; font-size: 11px; margin-bottom: 8px; }
.popup-nav { display: flex; gap: 6px; }
.nav-link { flex: 1; display: flex; align-items: center; justify-content: center; gap: 6px; padding: 8px; border: 1px solid #e2e8f0; border-radius: 8px; text-decoration: none; font-size: 10px; color: #475569; font-weight: 700; background: #f8fafc; }

.basemap-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 5px; }
.basemap-card { cursor: pointer; border-radius: 8px; border: 2.5px solid transparent; text-align: center; background: #fff; transition: 0.2s; overflow: hidden; }
.basemap-card img { width: 100%; height: 50px; object-fit: cover; display: block; }
.basemap-card span { font-size: 0.65rem; font-weight: 700; display: block; padding: 5px; color: #475569; }
.basemap-card.active { border-color: var(--primary); background: #f0f9ff; }
.basemap-card.active span { color: var(--primary); }

.hidden { display: none !important; }

/* --- ESTILOS BUSCADOR --- */
.search-group { position: relative; display: flex; align-items: center; }
.form-select { width: 100%; margin-bottom: 8px; padding: 6px; border-radius: 6px; border: 1px solid #cbd5e1; font-size: 0.75rem; }
.form-input { width: 100%; padding: 8px 30px 8px 8px; border-radius: 6px; border: 1px solid #cbd5e1; font-size: 0.75rem; }
#btn-clear-search { position: absolute; right: 5px; background: none; border: none; font-size: 14px; color: #94a3b8; cursor: pointer; }
#btn-clear-search:hover { color: #ef4444; }

.results-container { margin-top: 5px; background: white; border: 1px solid #e2e8f0; border-radius: 6px; max-height: 200px; overflow-y: auto; }
.result-item { padding: 8px 10px; border-bottom: 1px solid #f1f5f9; cursor: pointer; transition: 0.2s; }
.result-item:hover { background: #f8fafc; }
.res-main { display: block; font-size: 0.75rem; font-weight: 700; color: #1e293b; }
.res-sub { display: block; font-size: 0.65rem; color: #64748b; }
.form-input:disabled { background-color: #f1f5f9; color: #94a3b8; cursor: not-allowed; border-color: #e2e8f0; }

/* --- SWITCH / TOGGLE --- */
.switch { position: relative; display: inline-block; width: 30px; height: 16px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #cbd5e1; transition: .4s; }
.slider:before { position: absolute; content: ""; height: 12px; width: 12px; left: 2px; bottom: 2px; background-color: white; transition: .4s; }
input:checked + .slider { background-color: var(--primary); }
input:checked + .slider:before { transform: translateX(14px); }
.slider.round { border-radius: 16px; }
.slider.round:before { border-radius: 50%; }

/* CAPA ITEM */
.layer-item { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; border-bottom: 1px solid #f8fafc; }
.layer-label { font-size: 0.7rem; font-weight: 700; color: #475569; display: flex; align-items: center; gap: 6px; }

/* ESTILOS GIS LABEL */
.label-control-card { background: #f8fafc; border-radius: 8px; border: 1px solid var(--border); margin-bottom: 8px; overflow: hidden; }
.label-control-header { padding: 8px 10px; display: flex; justify-content: space-between; align-items: center; background: #fff; border-bottom: 1px solid #f1f5f9; }
.label-control-body { padding: 10px; display: grid; gap: 8px; }
.control-row { display: flex; align-items: center; justify-content: space-between; font-size: 0.7rem; color: #475569; font-weight: 600; }
.range-sm { width: 80px; }
.select-sm { font-size: 0.65rem; padding: 2px; border-radius: 4px; border: 1px solid #cbd5e1; }
input[type="color"] { width: 25px; height: 25px; border: none; padding: 0; background: none; cursor: pointer; }

.gis-label {
    background: transparent !important; border: none !important; box-shadow: none !important;
    font-weight: 700; text-shadow: -1px -1px 0 #fff, 1px -1px 0 #fff, -1px 1px 0 #fff, 1px 1px 0 #fff;
    white-space: nowrap; text-transform: uppercase;
}
.gis-label:before { border: none !important; }

/* --- CONTROLES LEAFLET --- */
.leaflet-bottom .leaflet-control {
    margin-bottom: 20px;
    border: none !important;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06) !important;
}

/* Transición suave para el contenedor derecho de controles */
.leaflet-right {
    transition: margin-right 0.4s ease;
    margin-right: 15px;
}

/* Cuando el panel derecho está abierto, movemos los controles */
body.panel-derecho-abierto .leaflet-right {
    margin-right: 270px !important; /* 240px ancho + 30px margen */
}

.leaflet-bar a, .custom-map-control {
    background-color: #fff !important;
    color: #475569 !important;
    border-bottom: 1px solid #f1f5f9 !important;
    width: 34px !important;
    height: 34px !important;
    line-height: 34px !important;
    font-weight: bold;
    font-size: 16px;
    transition: all 0.2s;
    display: flex !important;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.leaflet-bar a:hover, .custom-map-control:hover {
    background-color: #f8fafc !important;
    color: #0ea5e9 !important;
}

.leaflet-control-zoom a:first-child { border-top-left-radius: 8px !important; border-top-right-radius: 8px !important; }
.leaflet-control-zoom a:last-child { border-bottom-left-radius: 8px !important; border-bottom-right-radius: 8px !important; border-bottom: none !important; }

.btn-fullscreen {
    background: white;
    border-radius: 8px !important;
    margin-bottom: 10px !important;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1) !important;
}

/* --- CORRECCIÓN: OCULTAR CUADRO VACÍO DE RUTAS --- */
/* Esto oculta el contenedor por defecto que crea el plugin de routing */
.leaflet-routing-container {
    display: none !important;
    border: none !important;
    width: 0 !important;
    height: 0 !important;
}