/* =========================================
   1. VARIABLES & RESET (Fallback)
   ========================================= */
:root {
    /* Estos valores son sobreescritos por PHP si hay configuración guardada */
    
    /* Mapa */
    --s-map-null: #d9d9d9;
    
    /* Tabla - Fondos */
    --s-th-bg: #F8FAFC; 
    --s-tr-odd: #ffffff;
    --s-tr-even: #f9f9f9;
    --s-total-bg: #e8f4fd;
    
    /* Tabla - Textos */
    --s-th-text: #0F172A; 
    --s-tr-odd-txt: #475569; 
    --s-tr-even-txt: #475569;
    --s-total-txt: #0F172A;
    
    /* Bordes */
    --s-border: 1px solid #ddd;
}

/* =========================================
   2. ESTRUCTURA DE PÁGINA (Layout)
   ========================================= */
.siarhe-viz-wrapper {
    margin: 20px 0;
    position: relative;
    max-width: 100%;
}

.siarhe-header {
    margin-bottom: 25px;
    border-bottom: 1px solid #eee;
    padding-bottom: 15px;
}

.siarhe-title {
    color: #0A66C2; 
    margin: 0 0 10px 0;
    display: flex;
    align-items: center;
    gap: 10px;
}

.siarhe-meta {
    margin: 0;
}

.siarhe-section-map,
.siarhe-section-table {
    background: #fff;
    padding: 20px;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    margin-bottom: 30px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
    position: relative;
}

/* =========================================
   3. MAPA INTERACTIVO (Contenedor Base)
   ========================================= */

.siarhe-map-container {
    position: relative;
    width: 100%;
    padding-bottom: 56.25%; 
    height: 0;
    background-color: #F8FAFC; 
    border: 1px solid #ccc;
    border-radius: 4px;
    overflow: hidden;
}

.siarhe-map-container svg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

/* Estados / Polígonos */
path.siarhe-feature {
    fill: var(--s-map-null); 
    stroke: #ffffff;
    transition: fill 0.4s ease, stroke 0.2s ease;
    cursor: pointer;
    vector-effect: non-scaling-stroke;
}

path.siarhe-feature:hover {
    stroke: #0F172A; 
    filter: brightness(0.95);
    z-index: 10;
}

.siarhe-map-footer {
    margin-top: 10px;
    font-size: 12px;
    text-align: center;
}

/* =========================================
   4. TOOLTIP (Versión Adaptada a Identidad)
   ========================================= */
.siarhe-tooltip {
    position: absolute;
    padding: 10px 14px; 
    background: #0F172A; 
    color: #F8FAFC; 
    border-radius: 6px;
    pointer-events: none; 
    z-index: 10000;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    display: none;
    min-width: 200px;
    max-width: 300px;
    font-family: 'Roboto', sans-serif; 
    font-size: 13px; 
    line-height: 1.4;
    white-space: normal;
}

.siarhe-tooltip strong {
    font-family: 'Space Grotesk', sans-serif; 
    font-size: 14px;
    font-weight: 500;
    color: #06B6D4; 
}

/* =========================================
   5. TABLA DE DATOS
   ========================================= */
.siarhe-table-container {
    margin-top: 20px;
    overflow-x: auto; 
    border-radius: 5px;
    border: var(--s-border);
}

table.siarhe-data-table {
    width: 100%;
    border-collapse: collapse;
    font-family: 'Roboto', sans-serif;
    font-size: 14px;
    min-width: 600px;
}

table.siarhe-data-table th {
    background-color: var(--s-th-bg);
    color: var(--s-th-text);
    padding: 12px 10px;
    text-align: left;
    font-weight: 700;
    font-family: 'IBM Plex Sans', sans-serif; 
    border-bottom: var(--s-border);
    white-space: nowrap;
    cursor: pointer; 
    user-select: none;
    transition: background-color 0.2s ease;
}

table.siarhe-data-table th:hover {
    filter: brightness(0.95);
}

table.siarhe-data-table td {
    padding: 10px;
    border-bottom: var(--s-border);
}

table.siarhe-data-table tr:nth-child(odd) {
    background-color: var(--s-tr-odd);
    color: var(--s-tr-odd-txt);
}
table.siarhe-data-table tr:nth-child(odd) td { color: var(--s-tr-odd-txt); }

table.siarhe-data-table tr:nth-child(even) {
    background-color: var(--s-tr-even);
    color: var(--s-tr-even-txt);
}
table.siarhe-data-table tr:nth-child(even) td { color: var(--s-tr-even-txt); }

table.siarhe-data-table tr:not(.siarhe-row-total):hover td {
    background-color: rgba(6, 182, 212, 0.05); 
    cursor: default;
}

table.siarhe-data-table tbody tr.siarhe-row-total,
table.siarhe-data-table tbody tr.siarhe-row-total td {
    background-color: var(--s-total-bg);
    color: var(--s-total-txt);
    font-weight: 700;
    border-top: 2px solid #A5B4C3;
}

/* =========================================
   6. LOADER / SPINNER
   ========================================= */
.siarhe-loading-overlay {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(248, 250, 252, 0.95); 
    padding: 20px 30px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 500;
    color: #0F172A;
    z-index: 100;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.spinner {
    width: 30px;
    height: 30px;
    border: 4px solid #F8FAFC;
    border-top: 4px solid #0A66C2; 
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* =========================================
   7. BOTONES INFERIORES
   ========================================= */
.siarhe-actions {
    margin-top: 15px;
    display: flex;
    align-items: center;
    gap: 15px;
    flex-wrap: wrap;
}

.siarhe-map-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center; 
    gap: 15px;
    margin-top: 20px;
}

.btn-siarhe {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 16px;
    border-radius: 4px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: background 0.2s, transform 0.1s;
    font-size: 13px;
    text-decoration: none;
}

.btn-siarhe:active { transform: translateY(1px); }

.btn-download-map {
    background-color: #f0f0f1;
    color: #1d2327;
    border: 1px solid #c3c4c7;
}
.btn-download-map:hover { 
    background-color: #e0e0e0;
    color: #1d2327;
}

.btn-primary {
    background-color: #0A66C2; 
    color: #F8FAFC;
}
.btn-primary:hover { 
    background-color: #084C94; 
    color: #F8FAFC;
}

/* =========================================
   8. FOOTER Y ENLACES LEGALES
   ========================================= */
.siarhe-footer {
    font-family: 'Roboto', sans-serif;
    font-size: 13px;
    border-top: 1px solid #eee;
    padding-top: 20px;
    margin-top: 40px;
}

.siarhe-footer-grid {
    display: grid;
    grid-template-columns: 1fr; 
    gap: 20px;
}

.siarhe-ref-col strong {
    color: #0A66C2;
    display: block;
    margin-bottom: 5px;
    font-size: 14px;
}

.siarhe-disclaimer {
    margin-top: 15px;
    font-style: italic;
}

.siarhe-legal-disclaimer {
    margin-top: 20px;
    border-top: 1px dashed #ccc;
    padding-top: 15px;
    line-height: 1.5;
}

.siarhe-viz-wrapper .siarhe-legal-disclaimer a,
.siarhe-viz-wrapper .siarhe-footer a {
    font-family: inherit; 
    font-size: inherit;
    color: #0A66C2; 
    text-decoration: underline;
    font-weight: 400;
    transition: color 0.2s ease;
}

.siarhe-viz-wrapper .siarhe-legal-disclaimer a:hover,
.siarhe-viz-wrapper .siarhe-footer a:hover {
    color: #063A73; 
}

/* =========================================
   9. RESPONSIVE QUERIES
   ========================================= */
@media (min-width: 768px) {
    .siarhe-footer-grid {
        grid-template-columns: 1fr 1fr; 
    }
    .siarhe-map-actions button {
        width: auto;
    }
}

@media (max-width: 767px) {
    .siarhe-title { font-size: 20px; } 
    .siarhe-map-actions { flex-direction: column; align-items: stretch; }
    .siarhe-map-actions button { width: 100%; }
}