* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body, html {
    height: 100%;
    width: 100%;
    display: flex;
    flex-direction: column;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    overflow: hidden;
}

/* Barra Superior */
.navbar {
    height: 55px;
    background-color: #1e293b;
    color: #f8fafc;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 20px;
    z-index: 1001;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.brand-container {
    display: flex;
    align-items: center;
    gap: 12px;
}

.nav-logo {
    height: 35px;
    width: auto;
    object-fit: contain;
}

.logo {
    font-weight: bold;
    font-size: 1.1rem;
    letter-spacing: 0.5px;
}

/* Contenedor de Botones de Acción (Esquina Superior Derecha) */
.nav-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.nav-actions a {
    color: #cbd5e1;
    text-decoration: none;
    font-size: 0.85rem;
    background-color: #334155;
    padding: 6px 14px;
    border-radius: 4px;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 34px;
}

.nav-actions a:hover {
    color: #fff;
    background-color: #475569;
}

/* Botón de Casa Cuadrado */
.nav-actions .btn-home {
    width: 34px;
    padding: 0;
    font-size: 1.1rem;
    border: 1px solid #475569;
}

/* Contenedor Intermedio (Sidebar + Mapa) */
.main-container {
    display: flex;
    flex: 1;
    position: relative;
    width: 100%;
    overflow: hidden;
}

#map {
    flex: 1;
    height: 100%;
    z-index: 1;
    background-color: #ffffff;
}

/* ==========================================================================
   SIDEBARS FLOTANTES (IZQUIERDA Y DERECHA)
   ========================================================================== */
.sidebar-controls {
    width: 290px;
    height: calc(100% - 20px);
    position: absolute;
    top: 10px;
    left: 10px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
}

/* Panel de Leyendas (Derecha) */
.sidebar-legends {
    width: 290px;
    position: absolute;
    top: 80px; /* Margen superior para librar el Zoom y el Norte */
    right: 10px;
    z-index: 1000;
    pointer-events: none;
    /* Eliminamos el height fijo para que el contenedor dependa de su hijo */
}

/* Cajas de Control */
.control-box {
    pointer-events: auto;
    background-color: #1e293b;
    color: #f8fafc;
    border-radius: 8px;
    padding: 10px 12px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.15), 0 2px 4px -1px rgba(0, 0, 0, 0.1);
    max-height: 250px;
    overflow-y: auto;
}

/* Altura optimizada para la información de capas */
.text-box-expanded {
    max-height: 380px;
}

/* Caja de Leyendas: Límite de crecimiento dinámico recalculado */
.legend-box-full {
    display: flex;
    flex-direction: column;
    height: auto; 
    max-height: calc(100vh - 190px); /* Espaciado simétrico respecto a la barra de coordenadas inferior */
    overflow-y: auto; 
}

.control-box::-webkit-scrollbar {
    width: 6px;
}
.control-box::-webkit-scrollbar-thumb {
    background: #475569;
    border-radius: 4px;
}

/* Títulos */
.control-box h4 {
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid #334155;
    padding-bottom: 5px;
    margin-bottom: 8px;
    color: #fff;
    flex-shrink: 0; /* Previene que el título se encoja en flexbox */
}

/* Listados de Capas */
.layers-list {
    display: flex;
    flex-direction: column;
    gap: 7px;
    font-size: 0.8rem;
}

.layers-list label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    user-select: none;
}

.layers-list input[type="checkbox"],
.layers-list input[type="radio"] {
    cursor: pointer;
    accent-color: #38bdf8;
}

/* Estilo Buscador */
.search-input-container {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.search-input-container input {
    width: 100%;
    padding: 6px 10px;
    border: 1px solid #475569;
    border-radius: 4px;
    background-color: #334155;
    color: #fff;
    font-size: 0.75rem;
    outline: none;
    text-transform: uppercase;
}

.search-input-container button {
    width: 100%;
    padding: 6px;
    background-color: #38bdf8;
    color: #0f172a;
    border: none;
    border-radius: 4px;
    font-weight: bold;
    font-size: 0.75rem;
    cursor: pointer;
    transition: background 0.2s;
}

.search-input-container button:hover {
    background-color: #0ea5e9;
}

#search-error {
    font-size: 0.7rem;
    color: #f87171;
    display: none;
}

/* Sección Opacidad */
.opacity-container {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px dashed #334155;
    font-size: 0.75rem;
}

.opacity-slider-container {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 4px;
}

.opacity-slider {
    flex-grow: 1;
    -webkit-appearance: none;
    appearance: none;
    height: 4px;
    border-radius: 2px;
    background: #475569;
    outline: none;
    cursor: pointer;
}

.opacity-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #38bdf8;
    cursor: pointer;
}

#opacity-val {
    font-weight: bold;
    min-width: 30px;
    text-align: right;
    color: #38bdf8;
}

/* Acordeón de Leyendas */
.legend-panel {
    display: flex;
    flex-direction: column;
    gap: 6px;
    overflow-y: auto;
    flex-grow: 1;
}

.legend-item {
    font-size: 0.75rem;
}

.legend-header {
    background-color: #334155;
    padding: 6px 8px;
    cursor: pointer;
    border-radius: 4px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background-color 0.2s;
}

.legend-header:hover {
    background-color: #475569;
}

.legend-content {
    display: none;
    padding: 8px;
    background-color: #273549;
    border-radius: 0 0 4px 4px;
    text-align: center;
}

.legend-content img {
    max-width: 100%;
    height: auto;
    filter: drop-shadow(0px 1px 2px rgba(0,0,0,0.5));
}

/* Norte */
.north-arrow-control {
    background: transparent;
    padding: 5px;
    font-size: 24px;
    font-weight: bold;
    color: #1e293b;
    text-shadow: 0 0 4px #fff, 0 0 8px #fff;
    pointer-events: none;
}

/* Coordenadas y barra inferior */
.statusbar {
    height: 28px;
    background-color: #f1f5f9;
    border-top: 1px solid #e2e8f0;
    display: flex;
    align-items: center;
    justify-content: space-between; /* Empuja las coordenadas a la izquierda y el nuevo texto a la derecha */
    padding: 0 15px;
    font-size: 0.75rem;
    color: #475569;
    z-index: 1001;
}

/* Estilo opcional para el texto de la derecha (por si quieres darle un toque diferente, ej: cursiva) */
#footer-right-text {
    font-style: italic;
    color: #64748b; /* Un gris un poco más suave */
}

/* ==========================================================================
   CONTROL DE NORTE DINÁMICO (Diseño minimalista en blanco)
   ========================================================================== */
.north-arrow-control {
    position: absolute;
    top: 12px; /* Alineado horizontalmente con el botón de Zoom In */
    right: 50px; /* Separación perfecta a la izquierda del control de zoom */
    z-index: 1000;
    background-color: #1e293b; /* Mismo fondo oscuro que el zoom */
    color: #ffffff; /* Flecha blanca */
    width: 34px;
    height: 34px;
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 4px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: bold;
    box-shadow: 0 1px 5px rgba(0,0,0,0.4);
    pointer-events: auto;
    user-select: none;
}

/* Estilo para la "N" debajo de la flecha */
.north-arrow-control span {
    font-size: 8px;
    font-weight: 600;
    margin-top: -4px;
    color: #cbd5e1; /* Gris claro para la letra N */
}

/* ==========================================================================
   ESTILOS ADICIONALES PARA LEYENDAS INTEGRADAS (Añadir al final de tu map.css)
   ========================================================================== */

.legend-header {
    background-color: #334155;
    padding: 8px 10px;
    cursor: pointer;
    border-radius: 4px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background-color 0.2s;
    font-weight: 500;
}

.legend-header:hover {
    background-color: #475569;
}

.legend-content {
    display: none;
    padding: 10px;
    background-color: #1e293b; /* Igual al fondo de los paneles */
    border: 1px solid #334155;
    border-top: none;
    border-radius: 0 0 6px 6px;
}

/* Contenedor de Leyendas Vectorizadas */
.legend-vector-container {
    display: flex;
    flex-direction: column;
    gap: 8px;
    text-align: left;
}

/* Cada Fila de la Leyenda */
.legend-vector-item {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.78rem;
    color: #cbd5e1;
}

/* Símbolo dinámico (Caja, Línea, Círculo) */
.legend-vector-symbol {
    width: 16px;
    height: 16px;
    border-radius: 3px;
    flex-shrink: 0;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.15), 0 2px 4px rgba(0,0,0,0.3);
}

/* Variación para líneas (ej. límites) */
.legend-vector-symbol.line {
    height: 4px;
    border-radius: 1px;
}

/* Variación para círculos (puntos de interés) */
.legend-vector-symbol.circle {
    border-radius: 50%;
}

/* Texto de cada ítem */
.legend-vector-text {
    flex-grow: 1;
    line-height: 1.2;
}

/* Comentario o Nota inferior bajo la leyenda */
.legend-content img {
    max-width: 100%;
    height: auto;
    /* Eliminado cualquier filter de inversión */
    filter: drop-shadow(0px 1px 2px rgba(158, 158, 158, 0.5));
    display: inline-block;
    vertical-align: middle;
}

/* Forzamos a que la imagen del Catastro (que suele tener fondo blanco o transparente con líneas oscuras) 
   se renderice con un fondo claro para facilitar la lectura de sus líneas de parcela y texto */
.legend-item[data-layer-key="catastro"] .legend-content img {
    background-color: #ffffff;
    padding: 6px;
    border-radius: 4px;
}

/* Resto de tus estilos originales se mantienen exactamente igual */

/* Estilos específicos para el Buscador de Comercios */
#txt-comercios-search {
    text-transform: none !important;
}

/* Corrección para textos largos en leyendas: división automática en varias líneas */
.legend-header, 
.legend-content, 
.legend-footer-comment, 
.legend-vector-text {
    white-space: normal !important;
    word-break: break-word !important;
    overflow-wrap: break-word !important;
}

/* Asegurar tamaño mínimo de fuente visible en elementos de leyenda */
.legend-item {
    font-size: 12px !important;
}

.legend-header {
    font-size: 12px !important;
}

/* ==========================================================================
   ESTILOS PARA LEYENDA VECTORIAL DE TEXTO (Edición rápida y nítida)
   ========================================================================== */

/* Contenedor principal de la leyenda vectorial */
.legend-vector-container {
    display: flex;
    flex-direction: column;
    gap: 8px;
    text-align: left;
    padding: 6px;
    background-color: #1e293b;
    border-radius: 0 0 4px 4px;
}

/* Cada fila que contiene el color y su respectivo texto */
.legend-vector-item {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Cuadrito de color representativo de la simbología */
.legend-vector-symbol {
    width: 14px;
    height: 14px;
    border-radius: 3px;
    flex-shrink: 0;
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

/* Texto de la categoría con tamaño fijo garantizado >= 12px y multilínea */
.legend-vector-text {
    font-size: 12px !important;
    color: #f8fafc !important;
    line-height: 1.35 !important;
    white-space: normal !important;
    word-break: break-word !important;
    overflow-wrap: break-word !important;
}

/* Comentario inferior de la leyenda */
.legend-footer-comment {
    margin-top: 8px !important;
    font-size: 0.8rem !important;
    color: #94a3b8 !important;
    line-height: 1.35 !important;
    font-style: italic;
    white-space: normal !important;
    word-break: break-word !important;
}

/* Forzar tamaño base de los encabezados y elementos del acordeón */
.legend-item, 
.legend-header {
    font-size: 12px !important;
    white-space: normal !important;
    word-break: break-word !important;
}
/* ==========================================================================
   MODO EMBEBIDO (?embed=1)  — el visor va dentro de un <iframe> en WordPress
   La página de WordPress ya tiene su propia cabecera; ocultamos la nuestra
   para no duplicar branding y ganar altura útil de mapa.
   ========================================================================== */
.is-embed .navbar { display: none; }

/* En móvil los paneles laterales taparían el mapa por completo */
@media (max-width: 820px) {
    .sidebar-controls,
    .sidebar-legends {
        position: absolute;
        width: calc(100% - 20px);
        max-width: 320px;
        left: 10px;
        right: auto;
    }
    .sidebar-legends { top: auto; bottom: 40px; }
    .control-box { max-height: 180px; }
    .legend-box-full { max-height: 40vh; }
    .statusbar { font-size: 0.68rem; padding: 0 8px; }
    #footer-right-text { display: none; }
}

/* 100dvh evita el salto por la barra de navegación de iOS/Android */
@supports (height: 100dvh) {
    body, html { height: 100dvh; }
    .legend-box-full { max-height: calc(100dvh - 190px); }
}

/* Contraste mínimo AA para el texto secundario de la barra de estado */
#footer-right-text { color: #475569; }
