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

:root {
    --primary-color: #2563eb;
    --secondary-color: #64748b;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --background: #f8fafc;
    --card-background: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--background);
    color: var(--text-primary);
    line-height: 1.6;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 2rem;
}

header {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    margin-bottom: 3rem;
    padding: 2rem;
    background: linear-gradient(135deg, var(--primary-color), #3b82f6);
    color: white;
    border-radius: 1rem;
    box-shadow: var(--shadow-lg);
}

.header-logo {
    flex-shrink: 0;
}

.header-logo img {
    height: 140px;
    width: auto;
    display: block;
    border-radius: 8px;
}

.header-text {
    flex: 1;
    text-align: center;
}

header h1 {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
}

.subtitle {
    font-size: 1.1rem;
    opacity: 0.9;
}

.disclaimer {
    display: inline-block;
    margin-top: 0.6rem;
    padding: 0.35rem 0.85rem;
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.4);
    border-radius: 6px;
    font-size: 0.82rem;
    opacity: 0.9;
}

.main-layout {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 2rem;
    align-items: start;
}

.sidebar {
    background: var(--card-background);
    padding: 1.5rem;
    border-radius: 0.75rem;
    box-shadow: var(--shadow);
    position: sticky;
    top: 2rem;
}

.sidebar h3 {
    font-size: 1rem;
    color: var(--text-primary);
    margin-bottom: 1rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 700;
}

.content {
    flex: 1;
}

.controls {
    display: flex;
    flex-wrap: wrap;
    gap: 1.5rem;
    align-items: flex-end;
    background: var(--card-background);
    padding: 1.5rem;
    border-radius: 0.75rem;
    box-shadow: var(--shadow);
    margin-bottom: 2rem;
}

.control-group {
    flex: 1;
    min-width: 200px;
}

.control-group label {
    display: block;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.control-group select,
.control-group input {
    width: 100%;
    padding: 0.75rem;
    border: 2px solid var(--border-color);
    border-radius: 0.5rem;
    font-size: 1rem;
    transition: border-color 0.3s;
}

.control-group select:focus,
.control-group input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.date-inputs {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.date-inputs input {
    flex: 1;
}

.date-inputs span {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

button {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 0.5rem;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
}

.button-group {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.button-group-vertical {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.btn-filter {
    padding: 0.75rem 1rem;
    background-color: var(--card-background);
    color: var(--text-primary);
    border: 2px solid var(--border-color);
    font-size: 0.9rem;
    text-align: left;
    width: 100%;
}

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

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

.btn-historic {
    background-color: white;
    color: var(--text-primary);
    border-color: var(--border-color);
    font-weight: 700;
}

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

.btn-historic.active {
    background: linear-gradient(135deg, #059669, #10b981);
    color: white;
    border-color: #059669;
}

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

.btn-primary:hover {
    background-color: #1d4ed8;
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

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

.btn-secondary:hover {
    background-color: #475569;
}

.loading {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    z-index: 9999;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    backdrop-filter: blur(4px);
}

.loading.active {
    display: flex;
}

.loading p {
    color: white;
    font-size: 1.2rem;
    font-weight: 500;
    margin-top: 1rem;
}

.spinner {
    width: 60px;
    height: 60px;
    border: 5px solid rgba(255, 255, 255, 0.3);
    border-top-color: #10b981;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.current-values-header {
    background: linear-gradient(135deg, #10b981, #059669);
    color: white;
    padding: 1.5rem;
    border-radius: 0.75rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow-lg);
}

.current-values-header h2 {
    font-size: 1.5rem;
    margin-bottom: 0.25rem;
}

.current-date {
    font-size: 0.95rem;
    opacity: 0.95;
    font-weight: 500;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--card-background);
    padding: 1.5rem;
    border-radius: 0.75rem;
    box-shadow: var(--shadow);
    transition: transform 0.3s, box-shadow 0.3s;
}

.stat-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
}

.stat-card h3 {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.info-icon {
    display: inline-block;
    margin-left: 0.3rem;
    font-size: 0.75rem;
    cursor: help;
    vertical-align: baseline;
    opacity: 0.7;
    position: relative;
    top: -0.1em;
}

.stat-card .value {
    font-size: 2rem;
    font-weight: bold;
    color: var(--primary-color);
    margin-bottom: 0.5rem;
}

.stat-card .change {
    font-size: 0.9rem;
    font-weight: 600;
}

.stat-card .change.positive {
    color: var(--success-color);
}

.stat-card .change.negative {
    color: var(--danger-color);
}

.view-chart-link {
    display: inline-block;
    margin-top: 0.75rem;
    padding: 0.4rem 0.75rem;
    font-size: 0.85rem;
    color: var(--primary-color);
    text-decoration: none;
    border: 1px solid var(--border-color);
    border-radius: 0.375rem;
    transition: all 0.2s ease;
    background: var(--background);
}

.view-chart-link:hover {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
    transform: translateY(-1px);
}

/* Toggle switch para vista anual/mensual */
.chart-controls {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1rem;
    justify-content: center;
    align-items: center;
}

.toggle-label {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-secondary);
    user-select: none;
}

.toggle-switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 26px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--primary-color);
    transition: 0.3s;
    border-radius: 26px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: 0.3s;
    border-radius: 50%;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

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

.toggle-switch input:checked + .slider:before {
    transform: translateX(24px);
}

.toggle-switch:hover .slider {
    opacity: 0.9;
}

.toggle-switch input:disabled + .slider {
    background-color: var(--border-color);
    cursor: not-allowed;
    opacity: 0.5;
}

.toggle-switch input:disabled + .slider:before {
    background-color: #e5e7eb;
}

.chart-controls.disabled {
    opacity: 0.5;
    pointer-events: none;
}

.chart-controls.disabled .toggle-label {
    color: var(--border-color);
}

.charts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(500px, 1fr));
    gap: 2rem;
    margin-bottom: 2rem;
}

.chart-container {
    background: var(--card-background);
    padding: 0;
    border-radius: 0.75rem;
    box-shadow: var(--shadow);
    overflow: hidden;
}

.chart-container h2 {
    font-size: 1.25rem;
    margin-bottom: 0;
    color: white;
}

/* Estilos para el acordeón */
.accordion-header {
    padding: 1.5rem 2rem;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: linear-gradient(135deg, #003399 0%, #0051c9 100%);
    color: white;
    user-select: none;
    transition: background 0.3s ease;
}

.accordion-header:hover {
    background: linear-gradient(135deg, #00297a 0%, #003d9e 100%);
}

.accordion-header h2 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
}

.accordion-icon {
    font-size: 1.2rem;
    transition: transform 0.3s ease;
    font-weight: bold;
}

.accordion-header.collapsed .accordion-icon {
    transform: rotate(-90deg);
}

.accordion-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.4s ease-out, padding 0.4s ease-out;
    padding: 0 2rem;
}

.accordion-content.expanded {
    max-height: 800px;
    padding: 2rem;
}

.chart-description {
    margin-bottom: 1.5rem;
    padding: 1rem;
    background-color: rgba(37, 99, 235, 0.05);
    border-left: 4px solid var(--primary-color);
    border-radius: 0.25rem;
    font-size: 0.9rem;
    line-height: 1.6;
    color: var(--text-secondary);
}

.chart-description strong {
    color: var(--text-primary);
    font-weight: 600;
}

footer {
    text-align: center;
    padding: 2rem;
    background: var(--card-background);
    border-radius: 0.75rem;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

footer a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 600;
}

footer a:hover {
    text-decoration: underline;
}

.last-update {
    margin-top: 0.5rem;
    font-size: 0.85rem;
}

/* Responsive Design */
@media (max-width: 768px) {
    .container {
        padding: 1rem;
    }

    header {
        flex-direction: column;
        text-align: center;
    }

    .header-logo img {
        height: 60px;
    }

    header h1 {
        font-size: 1.75rem;
    }

    .main-layout {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: static;
    }

    .controls {
        flex-direction: column;
        align-items: stretch;
    }

    .control-group {
        min-width: 100%;
    }

    button {
        width: 100%;
    }

    .charts-grid {
        grid-template-columns: 1fr;
    }

    .chart-container {
        min-width: 100%;
    }
}

/* Botón para volver al inicio */
.scroll-to-top {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    width: 50px;
    height: 50px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 50%;
    font-size: 1.5rem;
    cursor: pointer;
    box-shadow: var(--shadow-lg);
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.scroll-to-top:hover {
    background: #1d4ed8;
    transform: translateY(-3px);
    box-shadow: 0 15px 25px -5px rgba(0, 0, 0, 0.2);
}

.scroll-to-top.show {
    opacity: 1;
    visibility: visible;
}

/* Sistema de Tabs */
.tabs-container {
    margin-bottom: 2rem;
}

.tabs-header {
    display: flex;
    gap: 0.5rem;
    background: var(--card-background);
    padding: 0.5rem;
    border-radius: 0.75rem;
    box-shadow: var(--shadow);
}

.tab-button {
    flex: 1;
    padding: 1rem 1.5rem;
    background: transparent;
    color: var(--text-secondary);
    border: 2px solid transparent;
    border-radius: 0.5rem;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.tab-button:hover {
    background: var(--background);
    color: var(--text-primary);
}

.tab-button.active {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
    animation: fadeIn 0.3s ease-in;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Tooltip para las tarjetas de estadísticas */
.info-icon-wrapper {
    position: relative;
    display: inline-block;
}

.tooltip-box {
    visibility: hidden;
    position: absolute;
    bottom: 150%;
    left: 50%;
    transform: translateX(-50%);
    background-color: #000000;
    color: #ffffff;
    padding: 0.75rem 1rem;
    border-radius: 0.5rem;
    font-size: 0.85rem;
    line-height: 1.5;
    white-space: normal;
    max-width: 280px;
    width: max-content;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.5), 0 8px 10px -6px rgba(0, 0, 0, 0.5);
    z-index: 10000;
    text-transform: none;
    font-weight: normal;
}

.tooltip-box::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    margin-left: -6px;
    border-width: 6px;
    border-style: solid;
    border-color: #000000 transparent transparent transparent;
}

.info-icon-wrapper:hover .tooltip-box {
    visibility: visible;
}

@keyframes tooltipFadeIn {
    from {
        transform: translateX(-50%) translateY(-4px);
    }
    to {
        transform: translateX(-50%) translateY(-8px);
    }
}

/* Estilos específicos para la cabecera de la pestaña Seguridad y las sub-pestañas ENUSC */
.tab-content#tab-seguridad .current-values-header {
    background: linear-gradient(135deg, #0f4ed6 0%, #083a9a 100%);
    color: #ffffff;
    padding: 1rem 1.25rem;
    border-radius: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.tab-content#tab-seguridad .current-values-header h2,
.tab-content#tab-seguridad .current-values-header .current-date {
    color: #ffffff;
}

.current-values-header .btn {
    background: transparent;
    color: rgba(255,255,255,0.95);
    padding: 0.25rem 0.5rem;
    border-radius: 0.5rem;
    display: inline-flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.15rem;
}

.current-values-header .btn:hover {
    background: rgba(255,255,255,0.06);
}

.current-values-header .btn .current-date {
    color: rgba(255,255,255,0.85);
}

.seguridad-view.active,
.enusc-view.active {
    background: rgba(255,255,255,0.12) !important;
    color: #fff !important;
}

/* Contenedor principal para poder alternar como pestañas */
#seguridad-main {
    transition: opacity 0.32s ease, transform 0.32s ease;
}

#seguridad-main:not(.active) {
    opacity: 0;
    transform: translateY(6px);
}

.enusc-section {
    transition: opacity 0.32s ease, transform 0.32s ease;
    opacity: 0;
    transform: translateY(6px);
}

.enusc-section.active {
    opacity: 1;
    transform: translateY(0);
}

/* Estilos para sub-pestañas dentro de Seguridad (ENUSC / Seguridad) */
.subtab-header-row {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* =========================================================
   Overlay: datos insuficientes para graficar
   ========================================================= */
.insufficient-data-overlay {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 280px;
    padding: 2rem 1rem;
}

.insufficient-data-content {
    text-align: center;
    max-width: 440px;
}

.insufficient-data-icon {
    font-size: 2.8rem;
    margin-bottom: 0.75rem;
    opacity: 0.65;
}

.insufficient-data-title {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 0.4rem;
}

.insufficient-data-subtitle {
    font-size: 0.875rem;
    color: var(--text-secondary);
    line-height: 1.65;
    margin-bottom: 1.25rem;
}

.insufficient-data-value-block {
    background: #f1f5f9;
    border-radius: 12px;
    padding: 0.9rem 1.4rem;
    margin-bottom: 1rem;
    border: 1px solid var(--border-color);
    display: inline-block;
    min-width: 200px;
}

.insufficient-data-label {
    font-size: 0.7rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 0.25rem;
}

.insufficient-data-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--primary-color);
}

.insufficient-data-note {
    font-size: 0.78rem;
    color: #94a3b8;
    font-style: italic;
}

.subtab-row {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    width: 100%;
}

.subtab-button {
    background: transparent;
    border: none;
    padding: 0.8rem 1rem;
    cursor: pointer;
    color: rgba(255,255,255,0.95);
    border-radius: 0.6rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.12rem;
    transition: background 0.18s ease, transform 0.12s ease, box-shadow 0.12s ease;
    flex: 1 1 0;
    min-width: 0;
    text-align: center;
}

.subtab-button + .subtab-button {
    margin-left: 0.5rem;
}

.subtab-button:hover {
    background: rgba(255,255,255,0.06);
    transform: translateY(-1px);
}

.subtab-button:focus {
    outline: 2px solid rgba(255,255,255,0.14);
    outline-offset: 2px;
}

.subtab-button .subtab-title {
    font-size: 1rem;
    font-weight: 700;
    line-height: 1;
}

.subtab-button .subtab-subtitle {
    font-size: 0.86rem;
    color: rgba(255,255,255,0.9);
    line-height: 1;
}

.subtab-button.active,
.subtab-button[aria-selected="true"] {
    background: linear-gradient(90deg, rgba(255,255,255,0.14), rgba(255,255,255,0.08));
    color: #ffffff;
    box-shadow: inset 0 -2px 0 rgba(0,0,0,0.06);
}

/* Ajuste responsivo para evitar que los subtabs se superpongan en pantallas pequeñas */
@media (max-width: 640px) {
    .tab-content#tab-seguridad .current-values-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }

    .subtab-row {
        flex-direction: column;
        gap: 0.5rem;
    }

    .subtab-button {
        width: 100%;
        padding: 0.6rem 0.8rem;
        border-radius: 0.5rem;
    }
}

/* Ajustes finos visuales */
.current-values-header .btn div { line-height: 1; }

/* Asegurar buen comportamiento en móvil */
@media (max-width: 768px) {
    .tab-content#tab-seguridad .current-values-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }
}

/* Subtabs: apariencia tipo pestañas dentro del header de Seguridad */
.subtab-button {
    display: inline-flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.12rem;
    padding: 0.6rem 0.9rem;
    border-radius: 0.6rem;
    background: transparent;
    color: rgba(255,255,255,0.95);
    border: 1px solid transparent;
    cursor: pointer;
    font-weight: 700;
    transition: background 0.18s ease, transform 0.12s ease, box-shadow 0.18s ease;
}

.subtab-button + .subtab-button { margin-left: 0.6rem; }

.subtab-button .subtitle { font-size: 0.85rem; color: rgba(255,255,255,0.88); font-weight:500; }

.subtab-button:hover { background: rgba(255,255,255,0.06); }

.subtab-button:focus { outline: 3px solid rgba(255,255,255,0.08); outline-offset: 2px; }

.subtab-button.active {
    background: linear-gradient(90deg, rgba(255,255,255,0.12), rgba(255,255,255,0.06));
    box-shadow: 0 6px 18px rgba(2,6,23,0.12);
    transform: translateY(-2px);
}

/* Ajustes para que el header tenga un padding uniforme y las subtabs no se solapen */
.tab-content#tab-seguridad .current-values-header { padding: 0.9rem 1rem; }
.tab-content#tab-seguridad .current-values-header .subtab-button div { line-height: 1; }

/* ENUSC container: bordes y fondo más discreto */
.enusc-section {
    background: linear-gradient(180deg, #ffffff, #fbfcfe);
    border: 1px dashed #e6e9ef;
    box-shadow: 0 6px 18px rgba(2,6,23,0.04);
    padding: 1.25rem;
}

/* Footer spacing when ENUSC shown */
#seguridad-footer { margin-top: 1.75rem; }

@media (max-width: 768px) {
    .subtab-button { width: 100%; }
    .subtab-button + .subtab-button { margin-left: 0; }
}
