/* ─── SectorPlus Public CSS ──────────────────────────────────── */

@import url('https://fonts.googleapis.com/css2?family=Google+Sans:wght@300;400;500;600;700&display=swap');
@import url('https://fonts.googleapis.com/css2?family=Google+Sans+Display:wght@400;500;700&display=swap');

/* Fallback: Google Sans no siempre está en Google Fonts public,
   usamos Product Sans / Nunito como alternativa muy similar */
@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@300;400;500;600;700;800&display=swap');

:root {
    --sp-primary:      #2563eb;
    --sp-primary-dk:   #1d4ed8;
    --sp-grad-a:       #6366f1;
    --sp-grad-b:       #2563eb;
    --sp-accent:       #f97316;
    --sp-success:      #10b981;
    --sp-warning:      #f59e0b;
    --sp-danger:       #ef4444;
    --sp-bg:           #f1f5ff;
    --sp-card-bg:      rgba(255,255,255,0.92);
    --sp-border:       rgba(99,102,241,0.13);
    --sp-text:         #0f172a;
    --sp-text-light:   #64748b;
    --sp-radius:       16px;
    --sp-radius-sm:    10px;
    --sp-shadow:       0 4px 24px rgba(99,102,241,.09);
    --sp-shadow-hover: 0 12px 40px rgba(99,102,241,.17);
    --sp-font:         'Nunito', 'Google Sans', sans-serif;
    --sp-glass:        blur(12px) saturate(1.4);
    --sp-verde:        #10b981;
    --sp-amarillo:     #f59e0b;
    --sp-rojo:         #ef4444;
}

/* ─── CONMUTADOR MODO ────────────────────────────────────────── */
.sp-modo-wrap {
    display: flex;
    justify-content: center;
    margin-bottom: 20px;
}

.sp-modo-tabs {
    display: inline-flex;
    background: rgba(255,255,255,.9);
    border: 1.5px solid var(--sp-border);
    border-radius: 14px;
    padding: 5px;
    gap: 4px;
    box-shadow: var(--sp-shadow);
    backdrop-filter: var(--sp-glass);
    max-width: 100%;
}

.sp-modo-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border: none;
    border-radius: 10px;
    font-size: 14px;
    font-family: var(--sp-font);
    font-weight: 600;
    color: var(--sp-text-light);
    background: transparent;
    cursor: pointer;
    transition: all .22s;
    white-space: nowrap;
    flex: 1;
    justify-content: center;
    min-width: 0;
}

@media (max-width: 520px) {
    .sp-modo-wrap { padding: 0 2px; }
    .sp-modo-tabs { width: 100%; border-radius: 12px; }
    .sp-modo-btn { padding: 9px 8px; font-size: 12px; gap: 5px; }
    .sp-modo-btn svg { width: 13px; height: 13px; flex-shrink: 0; }
}

.sp-modo-btn svg {
    width: 16px;
    height: 16px;
    stroke: currentColor;
    flex-shrink: 0;
}

.sp-modo-btn.active {
    background: linear-gradient(135deg, #7c3aed, #2563eb);
    color: #fff;
    box-shadow: 0 4px 14px rgba(99,102,241,.3);
}

.sp-modo-btn:hover:not(.active) {
    background: rgba(99,102,241,.07);
    color: var(--sp-grad-a);
}

/* ─── BASE ────────────────────────────────────────────────────── */
.sp-app {
    font-family: var(--sp-font);
    color: var(--sp-text);
    max-width: 1120px;
    margin: 0 auto;
    padding: 0 4px;
}
.sp-app *, .sp-app *::before, .sp-app *::after { box-sizing: border-box; }

/* ── ANCHO UNIFORME MOBILE — todos los widgets al 100% ────────── */
@media (max-width: 700px) {
    .sp-app { 
        width: 100% !important; 
        max-width: 100% !important; 
        overflow-x: hidden !important;
        padding: 0 !important;
    }
    .sp-app > * {
        width: 100% !important;
        max-width: 100% !important;
        overflow-x: hidden !important;
    }
    .sp-search-panel,
    .sp-result-header,
    .sp-kpi-card,
    .sp-chart-card,
    .sp-gauge-card,
    .sp-comp-card,
    .sp-map-card,
    .sp-ter-section,
    .sp-dashboard,
    .sp-dashboard-territorio,
    .sp-empty-state,
    .sp-loading,
    #sp-panel-sector,
    #sp-panel-territorio,
    #sp-dashboard,
    #sp-dashboard-territorio {
        width: 100% !important;
        max-width: 100% !important;
        overflow-x: hidden !important;
        box-sizing: border-box !important;
    }
    /* Forzar canvas de Chart.js al ancho del contenedor */
    canvas {
        max-width: 100% !important;
        width: 100% !important;
        height: auto !important;
    }
    .sp-chart-wrap,
    .sp-chart-wrap-sm {
        width: 100% !important;
        max-width: 100% !important;
        overflow: hidden !important;
    }
}

/* ─── HERO — oculto, lo gestiona Elementor ───────────────────── */
.sp-hero { display: none !important; }

/* ─── PANEL DE BÚSQUEDA ───────────────────────────────────────── */
.sp-search-panel {
    background: var(--sp-card-bg);
    backdrop-filter: var(--sp-glass);
    border: 1.5px solid var(--sp-border);
    border-radius: var(--sp-radius);
    padding: 22px 24px;
    margin-bottom: 28px;
    box-shadow: var(--sp-shadow);
    position: relative;
    z-index: 1000;
    overflow: visible;
}

.sp-search-grid {
    display: grid;
    grid-template-columns: 2fr 1fr 1.2fr auto;
    gap: 14px;
    align-items: end;
}

@media (max-width: 900px) {
    .sp-search-grid {
        grid-template-columns: 1fr 1fr;
    }
    .sp-field-action { grid-column: 1 / -1; }
}

@media (max-width: 560px) {
    .sp-search-grid { grid-template-columns: 1fr; }
}

.sp-field-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
}

.sp-field-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .09em;
    color: var(--sp-grad-a);
    white-space: nowrap;
}

.sp-field-svg {
    width: 14px;
    height: 14px;
    stroke: var(--sp-grad-a);
    flex-shrink: 0;
}

/* ─── INPUTS ──────────────────────────────────────────────────── */
.sp-input, .sp-select {
    height: 44px;
    border: 1.5px solid rgba(99,102,241,.16);
    border-radius: 10px;
    padding: 0 14px;
    font-size: 14px;
    font-family: var(--sp-font);
    font-weight: 500;
    color: var(--sp-text);
    background: rgba(255,255,255,.95);
    transition: border-color .2s, box-shadow .2s, background .2s;
    outline: none;
    width: 100%;
    -webkit-appearance: none;
    appearance: none;
    box-shadow: none;
}

.sp-select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' fill='none'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236366f1' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 12px;
    padding-right: 36px;
    cursor: pointer;
}

.sp-input:focus, .sp-select:focus {
    border-color: var(--sp-grad-a);
    box-shadow: 0 0 0 3px rgba(99,102,241,.10);
    background: #fff;
}

.sp-input::placeholder { color: #94a3b8; font-weight: 400; }

/* ─── AUTOCOMPLETE ────────────────────────────────────────────── */
.sp-autocomplete-wrap { position: relative; }

.sp-autocomplete-dropdown {
    position: absolute;
    top: calc(100% + 6px);
    left: 0; right: 0;
    background: #fff;
    border: 1.5px solid rgba(99,102,241,.15);
    border-radius: 10px;
    box-shadow: 0 8px 32px rgba(0,0,0,.12);
    z-index: 99999;
    max-height: 280px;
    overflow-y: auto;
    animation: spDropIn .15s ease;
}

@keyframes spDropIn {
    from { opacity: 0; transform: translateY(-6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.sp-autocomplete-dropdown::-webkit-scrollbar { width: 4px; }
.sp-autocomplete-dropdown::-webkit-scrollbar-track { background: transparent; }
.sp-autocomplete-dropdown::-webkit-scrollbar-thumb { background: rgba(99,102,241,.2); border-radius: 4px; }

.sp-ac-item {
    display: flex;
    flex-direction: column;
    padding: 10px 14px;
    cursor: pointer;
    border-bottom: 1px solid rgba(99,102,241,.06);
    transition: background .15s;
}
.sp-ac-item:last-child { border-bottom: none; }
.sp-ac-item:hover, .sp-ac-item.active {
    background: linear-gradient(135deg, rgba(99,102,241,.05), rgba(37,99,235,.03));
}

.sp-ac-label { font-size: 13px; font-weight: 600; color: var(--sp-text); }
.sp-ac-sub   { font-size: 11px; color: var(--sp-text-light); margin-top: 2px; }
.sp-ac-cod {
    display: inline-block;
    background: rgba(99,102,241,.09);
    color: var(--sp-grad-a);
    border-radius: 5px;
    padding: 1px 7px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: .06em;
    margin-right: 4px;
}
.sp-ac-empty { padding: 14px; font-size: 13px; color: var(--sp-text-light); text-align: center; }

/* ─── SEGMENTED CONTROL ───────────────────────────────────────── */
.sp-segmented {
    display: flex;
    background: rgba(99,102,241,.07);
    border-radius: 10px;
    padding: 3px;
    gap: 2px;
    height: 44px;
    align-items: center;
}

.sp-seg-btn {
    flex: 1;
    height: 36px;
    border: none;
    border-radius: 8px;
    font-size: 12px;
    font-family: var(--sp-font);
    font-weight: 600;
    color: var(--sp-text-light);
    background: transparent;
    cursor: pointer;
    transition: all .2s;
    white-space: nowrap;
    padding: 0 6px;
}
.sp-seg-btn.active {
    background: #fff;
    color: var(--sp-primary);
    box-shadow: 0 2px 8px rgba(99,102,241,.15);
}
.sp-seg-btn:hover:not(.active) {
    background: rgba(255,255,255,.5);
    color: var(--sp-text);
}

/* ─── BOTÓN ANALIZAR ──────────────────────────────────────────── */
.sp-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 44px;
    padding: 0 24px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 700;
    font-family: var(--sp-font);
    cursor: pointer;
    text-decoration: none;
    transition: all .22s;
    border: none;
    white-space: nowrap;
}

.sp-btn-analizar {
    background: linear-gradient(135deg, #7c3aed 0%, #3b82f6 100%);
    color: #fff;
    box-shadow: 0 4px 18px rgba(99,102,241,.32);
    width: 100%;
    height: 44px;
}
.sp-btn-analizar:hover:not(:disabled) {
    background: linear-gradient(135deg, #3b82f6 0%, #7c3aed 100%);
    transform: translateY(-2px);
    box-shadow: 0 8px 28px rgba(99,102,241,.42);
}
.sp-btn-analizar:disabled {
    opacity: .42;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* ─── LOADING ─────────────────────────────────────────────────── */
.sp-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 60px 24px;
    gap: 16px;
}
.sp-spinner {
    width: 36px; height: 36px;
    border: 3px solid rgba(99,102,241,.12);
    border-top-color: var(--sp-grad-a);
    border-radius: 50%;
    animation: spSpin .7s linear infinite;
}
@keyframes spSpin { to { transform: rotate(360deg); } }
.sp-loading-text { font-size: 14px; color: var(--sp-text-light); font-weight: 500; }

/* ─── EMPTY STATE ─────────────────────────────────────────────── */
.sp-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 24px;
    gap: 14px;
    animation: spFadeIn .4s ease;
}
@keyframes spFadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}
.sp-empty-icon { font-size: 44px; opacity: .45; }
.sp-empty-text { font-size: 15px; color: var(--sp-text-light); font-weight: 500; text-align: center; }

/* ─── DASHBOARD ───────────────────────────────────────────────── */
.sp-dashboard { animation: spFadeIn .4s ease; position: relative; z-index: 1; }

/* Cabecera resultado */
.sp-result-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    background: linear-gradient(135deg, rgba(99,102,241,.06) 0%, rgba(37,99,235,.04) 100%);
    backdrop-filter: var(--sp-glass);
    border: 1.5px solid var(--sp-border);
    border-radius: var(--sp-radius);
    padding: 20px 24px;
    margin-bottom: 20px;
    box-shadow: var(--sp-shadow);
}
.sp-result-meta {
    display: flex;
    flex-direction: column;
    gap: 5px;
    min-width: 0;
    flex: 1;
}
.sp-result-meta .sp-result-badge { align-self: flex-start; }

@media (max-width: 640px) {
    .sp-result-header {
        flex-direction: column;
        align-items: stretch;
    }
    .sp-semaforo-wrap { width: 100%; }
    .sp-semaforo { min-width: unset; width: 100%; }
}
.sp-result-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: linear-gradient(135deg, rgba(99,102,241,.1), rgba(37,99,235,.07));
    border: 1px solid rgba(99,102,241,.18);
    border-radius: 8px;
    padding: 5px 13px;
    font-size: 11px;
    font-weight: 700;
    color: var(--sp-grad-a);
    letter-spacing: .05em;
    text-transform: uppercase;
    white-space: nowrap;
}
.sp-result-title {
    font-family: var(--sp-font);
    font-size: 20px;
    font-weight: 800;
    margin: 0 0 3px;
    color: var(--sp-text);
}
.sp-result-subtitle { font-size: 12px; color: var(--sp-text-light); margin: 0; }

/* ─── SELECTOR DE RANGO DE FECHAS ───────────────────────────── */
.sp-rango-wrap {
    display: flex;
    align-items: center;
    gap: 7px;
    margin-top: 8px;
    flex-wrap: wrap;
}

.sp-rango-label {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .07em;
    color: var(--sp-text-light);
    white-space: nowrap;
}

.sp-rango-select {
    height: 28px;
    border: 1.5px solid rgba(99,102,241,.15);
    border-radius: 7px;
    padding: 0 24px 0 8px;
    font-size: 12px;
    font-family: var(--sp-font);
    font-weight: 600;
    color: var(--sp-text);
    background: rgba(255,255,255,.9);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' fill='none'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%236366f1' stroke-width='1.3' stroke-linecap='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 7px center;
    background-size: 10px;
    -webkit-appearance: none;
    appearance: none;
    cursor: pointer;
    outline: none;
    transition: border-color .2s, box-shadow .2s;
}

.sp-rango-select:focus {
    border-color: var(--sp-grad-a);
    box-shadow: 0 0 0 2px rgba(99,102,241,.1);
}

.sp-rango-sep {
    font-size: 12px;
    color: var(--sp-text-light);
    font-weight: 500;
}

.sp-rango-btn {
    height: 28px;
    padding: 0 12px;
    background: linear-gradient(135deg, var(--sp-grad-a), var(--sp-grad-b));
    color: #fff;
    border: none;
    border-radius: 7px;
    font-size: 11px;
    font-weight: 700;
    font-family: var(--sp-font);
    cursor: pointer;
    transition: opacity .2s, transform .2s;
    white-space: nowrap;
}

.sp-rango-btn:hover {
    opacity: .88;
    transform: translateY(-1px);
}

.sp-rango-info {
    font-size: 11px;
    color: var(--sp-text-light);
    font-weight: 500;
}

/* ─── SEMÁFORO ────────────────────────────────────────────────── */
.sp-semaforo {
    display: flex;
    align-items: center;
    gap: 14px;
    background: #fff;
    border-radius: 14px;
    padding: 14px 18px;
    border: 1.5px solid var(--sp-border);
    box-shadow: var(--sp-shadow);
    min-width: 200px;
}
.sp-sem-lights { display: flex; flex-direction: column; gap: 5px; }
.sp-sem-light {
    width: 13px; height: 13px;
    border-radius: 50%;
    opacity: .18;
    transition: opacity .3s, transform .3s;
}
.sp-sem-light.active { opacity: 1; transform: scale(1.2); box-shadow: 0 0 10px currentColor; }
.sp-sem-r { background: var(--sp-rojo);    color: var(--sp-rojo); }
.sp-sem-y { background: var(--sp-amarillo); color: var(--sp-amarillo); }
.sp-sem-g { background: var(--sp-verde);   color: var(--sp-verde); }
.sp-sem-info { flex: 1; }
.sp-sem-score {
    font-family: var(--sp-font);
    font-size: 30px;
    font-weight: 800;
    line-height: 1;
    margin-bottom: 2px;
}
.sp-sem-score.verde    { color: var(--sp-verde); }
.sp-sem-score.amarillo { color: var(--sp-amarillo); }
.sp-sem-score.rojo     { color: var(--sp-rojo); }
.sp-sem-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--sp-text-light); }
.sp-sem-desc  { font-size: 11px; color: var(--sp-text-light); margin-top: 4px; line-height: 1.4; max-width: 190px; }

/* ─── KPIs GRID ───────────────────────────────────────────────── */
.sp-kpis-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 14px;
    margin-bottom: 18px;
}

@media (max-width: 900px) {
    .sp-kpis-grid { grid-template-columns: repeat(3, 1fr) !important; }
}

@media (max-width: 700px) {
    .sp-kpis-grid { grid-template-columns: repeat(2, 1fr) !important; }
}

@media (max-width: 400px) {
    .sp-kpis-grid { grid-template-columns: 1fr !important; }
}

.sp-kpi-card {
    background: var(--sp-card-bg);
    backdrop-filter: var(--sp-glass);
    border: 1.5px solid var(--sp-border);
    border-radius: var(--sp-radius);
    padding: 18px 20px;
    box-shadow: var(--sp-shadow);
    display: flex;
    flex-direction: column;
    gap: 5px;
    position: relative;
    overflow: hidden;
    transition: box-shadow .25s, transform .25s;
}
.sp-kpi-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--sp-grad-a), var(--sp-grad-b));
    opacity: 0;
    transition: opacity .25s;
}
.sp-kpi-card:hover { box-shadow: var(--sp-shadow-hover); transform: translateY(-2px); }
.sp-kpi-card:hover::before { opacity: 1; }

/* Icono plano SVG */
.sp-kpi-icon {
    width: 28px; height: 28px;
    margin-bottom: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.sp-kpi-icon svg { width: 22px; height: 22px; }

.sp-kpi-value {
    font-family: var(--sp-font);
    font-size: 28px;
    font-weight: 800;
    color: var(--sp-primary);
    line-height: 1;
}
.sp-kpi-value.positive { color: var(--sp-success); }
.sp-kpi-value.negative { color: var(--sp-danger); }
.sp-kpi-value.neutral  { color: var(--sp-warning); }
.sp-kpi-value.text-val { font-size: 16px; font-weight: 700; }

.sp-kpi-label {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .07em;
    color: var(--sp-text-light);
}
.sp-kpi-sub { font-size: 11px; color: var(--sp-text-light); font-weight: 400; line-height: 1.4; }

/* ─── SECCIÓN DE GRÁFICAS ─────────────────────────────────────── */
.sp-charts-row {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 16px;
    margin-bottom: 16px;
}
@media (max-width: 820px) { .sp-charts-row { grid-template-columns: 1fr; } }

.sp-charts-row-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    margin-bottom: 16px;
}
@media (max-width: 900px) { .sp-charts-row-3 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 560px) { .sp-charts-row-3 { grid-template-columns: 1fr; } }

/* ─── CARDS ───────────────────────────────────────────────────── */
.sp-chart-card,
.sp-comp-card,
.sp-map-card,
.sp-gauge-card {
    background: var(--sp-card-bg);
    backdrop-filter: var(--sp-glass);
    border: 1.5px solid var(--sp-border);
    border-radius: var(--sp-radius);
    padding: 20px 22px;
    box-shadow: var(--sp-shadow);
    width: 100%;
    box-sizing: border-box;
}

.sp-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    flex-wrap: wrap;
    gap: 8px;
}
.sp-card-title { font-size: 13px; font-weight: 700; color: var(--sp-text); }
.sp-card-badge {
    font-size: 11px;
    font-weight: 600;
    background: rgba(99,102,241,.09);
    color: var(--sp-grad-a);
    border-radius: 100px;
    padding: 3px 11px;
}
.sp-card-note { font-size: 11px; color: var(--sp-text-light); font-weight: 500; }

/* Gráfica */
.sp-chart-wrap { position: relative; height: 210px; }

/* Card ancha en grid de 3 */
.sp-chart-card-wide { grid-column: span 2; }
@media (max-width: 820px) {
    .sp-chart-card-wide { grid-column: span 1; }
    .sp-charts-row-3 .sp-gauge-card,
    .sp-charts-row-3 .sp-chart-card,
    .sp-charts-row-3 .sp-chart-card-wide {
        width: 100% !important;
        grid-column: 1 !important;
    }
}
.sp-chart-wrap-sm { position: relative; height: 160px; }

/* ─── COMPARATIVA ─────────────────────────────────────────────── */
.sp-comp-content { display: flex; flex-direction: column; gap: 14px; }
.sp-comp-row { display: flex; flex-direction: column; gap: 6px; }
.sp-comp-label { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--sp-text-light); }
.sp-comp-bar-wrap { background: rgba(99,102,241,.07); border-radius: 100px; height: 7px; overflow: hidden; }
.sp-comp-bar { height: 100%; border-radius: 100px; transition: width .8s cubic-bezier(.4,0,.2,1); }
.sp-comp-bar-geo { background: linear-gradient(90deg, var(--sp-grad-a), var(--sp-grad-b)); }
.sp-comp-bar-nac { background: #94a3b8; }
.sp-comp-val { font-size: 13px; font-weight: 600; color: var(--sp-text); }
.sp-comp-diff {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: rgba(16,185,129,.09);
    color: var(--sp-success);
    border-radius: 6px;
    padding: 4px 10px;
    font-size: 12px;
    font-weight: 700;
    margin-top: 4px;
}
.sp-comp-diff.negative { background: rgba(239,68,68,.07); color: var(--sp-danger); }
.sp-comp-diff.neutral  { background: rgba(245,158,11,.07); color: var(--sp-warning); }

/* ─── GAUGE (medidor circular) ────────────────────────────────── */
.sp-gauge-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}
.sp-gauge-svg { width: 140px; height: 80px; }
.sp-gauge-val { font-size: 22px; font-weight: 800; color: var(--sp-primary); line-height: 1; }
.sp-gauge-sub { font-size: 11px; color: var(--sp-text-light); font-weight: 500; text-align: center; }

/* ─── MAPA ────────────────────────────────────────────────────── */
.sp-map-card { margin-bottom: 16px; }
.sp-map-wrap { height: 320px; border-radius: 10px; overflow: hidden; border: 1px solid var(--sp-border); }

/* ─── AVISO DETALLE ───────────────────────────────────────────── */
.sp-notice-detalle {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(245,158,11,.07);
    border: 1px solid rgba(245,158,11,.22);
    border-radius: 10px;
    padding: 10px 16px;
    font-size: 13px;
    color: #92400e;
    font-weight: 500;
    margin-bottom: 14px;
}

/* ─── PIE ─────────────────────────────────────────────────────── */
.sp-footer-note {
    font-size: 11px;
    color: var(--sp-text-light);
    text-align: center;
    padding: 12px 0 4px;
    border-top: 1px solid var(--sp-border);
    margin-top: 4px;
}

/* ─── RESPONSIVE ──────────────────────────────────────────────── */
@media (max-width: 680px) {
    .sp-search-panel { padding: 16px; }
    .sp-kpis-grid { grid-template-columns: repeat(2, 1fr); }
    .sp-result-header { flex-direction: column; }
    .sp-semaforo { min-width: unset; width: 100%; }
}
@media (max-width: 400px) {
    .sp-kpis-grid { grid-template-columns: 1fr; }
}

/* ─── FIX SELECT TERRITORIO ──────────────────────────────────── */
#sp-panel-territorio .sp-search-grid {
    grid-template-columns: 1fr 1fr auto !important;
    align-items: end;
}

#sp-ter-ccaa-wrap,
#sp-ter-prov-wrap,
#sp-ter-mun-wrap {
    min-width: 0;
    transition: all .2s;
}

#sp-ter-ccaa, #sp-ter-ambito, #sp-ter-prov {
    width: 100%;
    min-width: 0;
}

/* Cuando el selector secundario está oculto, el botón ocupa su lugar */
#sp-ter-ccaa-wrap[style*="visibility: hidden"],
#sp-ter-prov-wrap[style*="visibility: hidden"],
#sp-ter-mun-wrap[style*="visibility: hidden"] {
    pointer-events: none;
}

@media (max-width: 700px) {
    #sp-panel-territorio .sp-search-grid {
        grid-template-columns: 1fr !important;
    }
    #sp-ter-ccaa-wrap,
    #sp-ter-prov-wrap,
    #sp-ter-mun-wrap {
        width: 100% !important;
        visibility: visible !important;
    }
}

/* ─── DASHBOARD TERRITORIO ───────────────────────────────────── */
.sp-ter-section {
    background: var(--sp-card-bg);
    backdrop-filter: var(--sp-glass);
    border: 1.5px solid var(--sp-border);
    border-radius: var(--sp-radius);
    padding: 22px 24px;
    box-shadow: var(--sp-shadow);
    margin-bottom: 16px;
}

.sp-ter-section-title {
    font-size: 14px;
    font-weight: 700;
    color: var(--sp-text);
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.sp-ter-section-title svg {
    width: 16px;
    height: 16px;
    stroke: var(--sp-grad-a);
}

.sp-ranking-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 0;
    border-bottom: 1px solid rgba(99,102,241,.06);
}
.sp-ranking-row:last-child { border-bottom: none; }

.sp-ranking-num {
    font-size: 11px;
    font-weight: 700;
    color: var(--sp-text-light);
    width: 20px;
    flex-shrink: 0;
}

.sp-ranking-name,
.sp-ranking-nombre {
    flex: 1;
    font-size: 13px;
    font-weight: 500;
    color: var(--sp-text);
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sp-ranking-bar-wrap {
    width: 120px;
    background: rgba(99,102,241,.07);
    border-radius: 100px;
    height: 6px;
    flex-shrink: 0;
}

.sp-ranking-bar {
    height: 100%;
    border-radius: 100px;
    background: linear-gradient(90deg, var(--sp-grad-a), var(--sp-grad-b));
    transition: width .6s ease;
}

.sp-ranking-val {
    font-size: 12px;
    font-weight: 700;
    color: var(--sp-text);
    width: 70px;
    text-align: right;
    flex-shrink: 0;
}

.sp-ranking-var {
    font-size: 11px;
    font-weight: 700;
    width: 50px;
    text-align: right;
    flex-shrink: 0;
}

.sp-ranking-var.pos { color: var(--sp-success); }
.sp-ranking-var.neg { color: var(--sp-danger); }

.sp-ter-grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 16px;
}

.sp-ter-grid-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    margin-bottom: 16px;
}

@media (max-width: 820px) {
    .sp-ter-grid-2, .sp-ter-grid-3 { grid-template-columns: 1fr; }
}

.sp-sector-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 12px;
    border-radius: 100px;
    font-size: 12px;
    font-weight: 600;
    margin: 3px;
}

.sp-sector-pill.emergente {
    background: rgba(16,185,129,.1);
    color: var(--sp-success);
    border: 1px solid rgba(16,185,129,.2);
}

.sp-sector-pill.declive {
    background: rgba(239,68,68,.08);
    color: var(--sp-danger);
    border: 1px solid rgba(239,68,68,.15);
}

/* ─── MAPA DE CALOR ───────────────────────────────────────────── */
.sp-mapa-btn {
    height: 30px;
    padding: 0 14px;
    border: 1.5px solid rgba(99,102,241,.18);
    border-radius: 100px;
    font-size: 11px;
    font-weight: 600;
    font-family: var(--sp-font);
    color: var(--sp-text-light);
    background: transparent;
    cursor: pointer;
    transition: all .2s;
}
.sp-mapa-btn.active,
.sp-mapa-btn:hover {
    background: linear-gradient(135deg, var(--sp-grad-a), var(--sp-grad-b));
    color: #fff;
    border-color: transparent;
}

/* ─── ALERTA TENDENCIA ────────────────────────────────────────── */
.sp-alerta-tendencia {
    animation: spFadeIn .4s ease;
}

/* ─── OPORTUNIDADES DE MERCADO ───────────────────────────────── */
.sp-op-panel {
    background: var(--sp-card-bg);
    border: 1.5px solid var(--sp-border);
    border-radius: var(--sp-radius);
    padding: 22px 24px;
    box-shadow: var(--sp-shadow);
    margin-bottom: 16px;
    animation: spFadeIn .4s ease;
}

.sp-op-header {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    margin-bottom: 20px;
}

.sp-op-icon { font-size: 28px; flex-shrink: 0; }

.sp-op-title {
    font-size: 15px;
    font-weight: 800;
    color: var(--sp-text);
    margin: 0 0 4px;
}

.sp-op-subtitle {
    font-size: 12px;
    color: var(--sp-text-light);
    margin: 0;
    line-height: 1.5;
}

.sp-op-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 12px;
}

.sp-op-card {
    border-radius: 12px;
    padding: 16px;
    text-align: center;
    border: 1.5px solid transparent;
    transition: transform .2s, box-shadow .2s;
}

.sp-op-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--sp-shadow-hover);
}

.sp-op-alta {
    background: rgba(16,185,129,.07);
    border-color: rgba(16,185,129,.2);
}

.sp-op-media {
    background: rgba(245,158,11,.07);
    border-color: rgba(245,158,11,.2);
}

.sp-op-baja {
    background: rgba(99,102,241,.06);
    border-color: rgba(99,102,241,.15);
}

.sp-op-territorio {
    font-size: 12px;
    font-weight: 700;
    color: var(--sp-text);
    margin-bottom: 8px;
    line-height: 1.3;
}

.sp-op-score {
    font-size: 28px;
    font-weight: 800;
    color: var(--sp-primary);
    line-height: 1;
}

.sp-op-alta .sp-op-score { color: #10b981; }
.sp-op-media .sp-op-score { color: #f59e0b; }

.sp-op-score span { font-size: 13px; font-weight: 600; color: var(--sp-text-light); }

.sp-op-label {
    font-size: 9px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .07em;
    color: var(--sp-text-light);
    margin: 4px 0 8px;
}

.sp-op-stats {
    display: flex;
    flex-direction: column;
    gap: 3px;
    font-size: 11px;
    font-weight: 600;
}

.sp-op-pos { color: var(--sp-success); }
.sp-op-neg { color: var(--sp-danger); }
.sp-op-neutral { color: var(--sp-text-light); }

/* ─── COMPARATIVA TERRITORIAL ────────────────────────────────── */
.sp-comp-ter-panel {
    background: var(--sp-card-bg);
    border: 1.5px solid var(--sp-border);
    border-radius: var(--sp-radius);
    padding: 22px 24px;
    box-shadow: var(--sp-shadow);
    margin-bottom: 16px;
    animation: spFadeIn .4s ease;
}

.sp-comp-ter-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
    flex-wrap: wrap;
}

.sp-comp-ter-title {
    font-size: 15px;
    font-weight: 800;
    color: var(--sp-text);
    margin: 0 0 4px;
}

.sp-comp-ter-subtitle {
    font-size: 12px;
    color: var(--sp-text-light);
    margin: 0;
}

.sp-comp-ter-leyenda {
    display: flex;
    gap: 12px;
    font-size: 11px;
    font-weight: 600;
    flex-shrink: 0;
}

.sp-comp-ter-ley-item { display: flex; align-items: center; gap: 4px; }

.sp-comp-ter-tabla { display: flex; flex-direction: column; gap: 2px; }

.sp-comp-ter-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 0;
    border-bottom: 1px solid rgba(99,102,241,.05);
}

.sp-comp-ter-row:last-child { border-bottom: none; }

.sp-comp-ter-num {
    font-size: 11px;
    font-weight: 700;
    color: var(--sp-text-light);
    width: 20px;
    flex-shrink: 0;
    text-align: right;
}

.sp-comp-ter-nombre {
    flex: 1;
    font-size: 13px;
    font-weight: 500;
    color: var(--sp-text);
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sp-comp-ter-bar-wrap {
    width: 100px;
    background: rgba(99,102,241,.07);
    border-radius: 100px;
    height: 6px;
    flex-shrink: 0;
}

.sp-comp-ter-bar {
    height: 100%;
    border-radius: 100px;
    transition: width .6s ease;
}

.sp-comp-ter-emp {
    font-size: 12px;
    font-weight: 700;
    color: var(--sp-text);
    width: 80px;
    text-align: right;
    flex-shrink: 0;
}

.sp-comp-ter-var {
    font-size: 11px;
    font-weight: 700;
    width: 50px;
    text-align: right;
    flex-shrink: 0;
}

.sp-comp-ter-pos { color: var(--sp-success); }
.sp-comp-ter-neg { color: var(--sp-danger); }

/* Mobile fixes */
@media (max-width: 600px) {
    .sp-op-grid { grid-template-columns: repeat(2, 1fr); }
    .sp-comp-ter-bar-wrap { display: none; }
    .sp-comp-ter-emp { width: 60px; font-size: 11px; }
    .sp-op-panel, .sp-comp-ter-panel { padding: 16px; }
}

/* ─── POTENCIAL DEL SECTOR ───────────────────────────────────── */
.sp-op-score-grande {
    text-align: center;
    background: rgba(99,102,241,.06);
    border-radius: 12px;
    padding: 14px 20px;
    flex-shrink: 0;
}

.sp-op-score-num {
    font-size: 40px;
    font-weight: 800;
    line-height: 1;
}

.sp-op-score-max {
    font-size: 16px;
    color: var(--sp-text-light);
    font-weight: 600;
}

.sp-op-score-label {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--sp-text-light);
    margin-top: 4px;
}

.sp-op-factores {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 16px;
}

.sp-op-factor-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}

.sp-op-factor-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--sp-text);
}

.sp-op-factor-val {
    font-size: 12px;
    font-weight: 700;
    color: var(--sp-text-light);
}

.sp-op-factor-bar-wrap {
    height: 6px;
    background: rgba(99,102,241,.08);
    border-radius: 100px;
    overflow: hidden;
}

.sp-op-factor-bar {
    height: 100%;
    border-radius: 100px;
    transition: width .6s ease;
}

/* ─── MAPA COROPLÉTICO ───────────────────────────────────────── */
.sp-mapa-panel {
    background: var(--sp-card-bg);
    border: 1.5px solid var(--sp-border);
    border-radius: var(--sp-radius);
    padding: 22px 24px;
    box-shadow: var(--sp-shadow);
    margin-bottom: 16px;
    animation: spFadeIn .4s ease;
}

.sp-mapa-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    flex-wrap: wrap;
    gap: 12px;
}

.sp-mapa-title {
    font-size: 15px;
    font-weight: 800;
    color: var(--sp-text);
    margin: 0;
}

.sp-mapa-select {
    height: 32px;
    padding: 0 28px 0 10px;
    border: 1.5px solid var(--sp-border);
    border-radius: 8px;
    background: var(--sp-card-bg);
    color: var(--sp-text);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%236366f1' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
}

.sp-mapa-leyenda {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 12px;
    flex-wrap: wrap;
}

.sp-mapa-leyenda-title {
    font-size: 11px;
    font-weight: 700;
    color: var(--sp-text-light);
    text-transform: uppercase;
    letter-spacing: .06em;
}

.sp-mapa-leyenda-scale {
    display: flex;
    gap: 6px;
    align-items: center;
    flex-wrap: wrap;
}

.sp-mapa-leyenda-item {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 10px;
    color: var(--sp-text-light);
    font-weight: 600;
}

.sp-mapa-leyenda-color {
    width: 14px;
    height: 14px;
    border-radius: 3px;
    flex-shrink: 0;
}

.sp-mapa-tooltip {
    background: #1a202c !important;
    border: none !important;
    border-radius: 8px !important;
    padding: 8px 12px !important;
    font-size: 12px !important;
    font-weight: 500 !important;
    color: white !important;
    box-shadow: 0 4px 12px rgba(0,0,0,.15) !important;
}

.sp-mapa-tooltip::before { display: none !important; }

@media (max-width: 600px) {
    .sp-mapa-panel { padding: 16px; }
    #sp-mapa-container { height: 280px !important; }
}

/* ─── IMPRESIÓN PDF ──────────────────────────────────────────── */
@media print {
    /* Ocultar elementos de navegación */
    .sp-modo-wrap,
    #sp-panel-sector,
    #sp-panel-territorio,
    #sp-empty-state,
    #sp-loading,
    #sp-btn-pdf-sector,
    #sp-btn-pdf-territorio,
    #sp-btn-comparar,
    .sp-footer-note,
    #sp-ter-footer,
    .sp-mapa-controls,
    .leaflet-control-zoom,
    .leaflet-control-attribution { display: none !important; }

    /* Mostrar solo el dashboard activo */
    .sp-app { background: white !important; padding: 0 !important; }
    .sp-card, .sp-kpi-card, .sp-comp-ter-panel,
    .sp-op-panel, .sp-mapa-panel { box-shadow: none !important; border: 1px solid #e2e8f0 !important; }

    /* Evitar cortes en tarjetas */
    .sp-kpi-card, .sp-ranking-row, .sp-ter-section { break-inside: avoid; }

    /* Colores en impresión */
    * { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; }

    body { background: white !important; }
}

/* ─── TOOLTIPS INFORMATIVOS EN KPIs ─────────────────────────── */
.sp-kpi-card { position: relative; }

/* Icono "i" — elemento HTML añadido por JS */
.sp-kpi-info {
    position: absolute;
    top: 6px;
    right: 7px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: rgba(99,102,241,.12);
    color: #6366f1;
    font-size: 9px;
    font-weight: 800;
    font-style: normal;
    line-height: 14px;
    text-align: center;
    cursor: help;
    transition: background .15s;
    user-select: none;
    z-index: 2;
}

.sp-kpi-info:hover { background: rgba(99,102,241,.28); }

/* Tooltip — generado por JS */
.sp-kpi-tooltip {
    position: fixed;
    background: #1a202c;
    color: #f8fafc;
    font-size: 12px;
    font-weight: 400;
    line-height: 1.5;
    padding: 8px 12px;
    border-radius: 8px;
    width: 200px;
    text-align: left;
    pointer-events: none;
    z-index: 9999;
    box-shadow: 0 4px 16px rgba(0,0,0,.25);
    opacity: 0;
    transition: opacity .15s;
}
.sp-kpi-tooltip.visible { opacity: 1; }

