*,
*::before,
*::after {
    box-sizing: border-box;
}

:root {
    --bg: #f2f6f9;
    --card: #ffffff;
    --text: #0f1e2d;
    --muted: #5b6b7c;
    --border: #e3ebf1;
    --primary: #22adc8;
    --primary-dark: #1890a8;
    --primary-soft: #e8f7fa;
    --accent: #f52d80;
    --accent-dark: #d4206e;
    --accent-soft: #fde8f1;
    --danger: #e0513c;
    --success: #21a873;
    --teal: #22adc8;
    --shadow: 0 14px 40px rgba(13, 45, 60, .07);
    --radius: 18px;
}

html {
    scroll-behavior: smooth;
}

body {
    margin: 0;
    background:
        radial-gradient(900px 420px at 85% -10%, rgba(34, 173, 200, .10), transparent 60%),
        radial-gradient(800px 400px at -10% 0%, rgba(245, 45, 128, .06), transparent 55%),
        var(--bg);
    color: var(--text);
    font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, Roboto, sans-serif;
    -webkit-font-smoothing: antialiased;
}

.container {
    width: min(1440px, calc(100% - 40px));
    margin: 0 auto;
    padding: 30px 0 46px;
}

/* ---------- Header ---------- */

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 22px;
    padding: 22px 28px;
    margin-bottom: 22px;
    /*background: linear-gradient(135deg, #0f1e2d 0%, #162b3d 55%, #1a3348 100%);*/
    background-color: #22adc8;
    border-radius: var(--radius);
    box-shadow: 0 8px 32px rgba(15, 30, 45, .25);
    position: relative;
    overflow: hidden;
}

.page-header::before {
    content: '';
    position: absolute;
    top: -60px;
    right: -40px;
    width: 220px;
    height: 220px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(34, 173, 200, .18) 0%, transparent 70%);
    pointer-events: none;
}

.page-header::after {
    content: '';
    position: absolute;
    bottom: -50px;
    left: 30%;
    width: 180px;
    height: 180px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(245, 45, 128, .12) 0%, transparent 70%);
    pointer-events: none;
}

.header-text {
    position: relative;
    z-index: 1;
}

.eyebrow {
    margin: 0 0 7px;
    color: var(--primary);
    font-size: 11px;
    font-weight: 800;
    letter-spacing: .18em;
    text-transform: uppercase;
}

h1 {
    margin: 0;
    font-size: clamp(24px, 4vw, 38px);
    line-height: 1.08;
    letter-spacing: -.02em;
    color: #ffffff;
}

.gradient-text {
    background: linear-gradient(100deg, var(--accent) 0%, var(--primary) 100%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.subtitle {
    margin: 8px 0 0;
    color: rgba(255, 255, 255, .55);
    font-size: 13.5px;
    max-width: 680px;
    line-height: 1.45;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
    position: relative;
    z-index: 1;
}

.header-fecha {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 8px 14px;
    /* background: rgba(34, 173, 200, .15); */
    background: #f52d80;

    border: 1px solid rgba(34, 173, 200, .25);
    border-radius: 10px;
    color: #ffffff;
    font-size: 12px;
    font-weight: 700;
    white-space: nowrap;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}

.header-fecha svg {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
    opacity: .85;
    color: #ffffff;
}

.header-fecha-acual {
    
    color: #ffffff;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}

.last-update {
    color: rgba(255, 255, 255, .45);
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}

.btn-secondary {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    border: 1px solid rgba(255, 255, 255, .15);
    background: rgba(255, 255, 255, .08);
    border-radius: 10px;
    padding: 9px 16px;
    cursor: pointer;
    font-weight: 700;
    font-size: 13px;
    color: #ffffff;
    transition: border-color .15s, background .15s, transform .15s;
    white-space: nowrap;
}

.btn-secondary:hover {
    border-color: var(--primary);
    background: rgba(34, 173, 200, .15);
    transform: translateY(-1px);
}

/* ---------- Filtros ---------- */

.filters-card {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 14px;
    padding: 20px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 20px;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 7px;
    min-width: 0;
}

.filter-group label {
    color: #33475b;
    font-size: 12.5px;
    font-weight: 800;
    letter-spacing: .02em;
}

select {
    width: 100%;
    height: 44px;
    border: 1px solid var(--border);
    border-radius: 11px;
    background: #fff;
    color: var(--text);
    padding: 0 12px;
    outline: none;
    font-size: 14px;
    transition: border-color .15s, box-shadow .15s;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%235b6b7c' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 11px center;
    padding-right: 34px;
}

select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(34, 173, 200, .12);
}

/* ---------- KPI ---------- */

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 16px;
    margin-bottom: 20px;
}

.kpi-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 18px 16px;
    box-shadow: var(--shadow);
    transition: transform .18s, box-shadow .18s;
}

.kpi-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 18px 44px rgba(13, 45, 60, .12);
}

.kpi-label {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--muted);
    font-size: 12.5px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: .04em;
}

.kpi-label svg {
    width: 16px;
    height: 16px;
    color: var(--primary);
    flex-shrink: 0;
}

.kpi-card strong {
    display: block;
    margin: 9px 0 5px;
    font-size: 31px;
    letter-spacing: -.02em;
    line-height: 1;
}

.kpi-card small {
    color: var(--muted);
    font-size: 12.5px;
}

.kpi-avance {
    border-color: rgba(34, 173, 200, .35);
    background: linear-gradient(160deg, #ffffff 0%, var(--primary-soft) 100%);
}

.progress {
    margin-top: 12px;
    height: 9px;
    border-radius: 99px;
    background: rgba(34, 173, 200, .14);
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    width: 0;
    border-radius: 99px;
    background: linear-gradient(90deg, var(--accent), var(--primary));
    transition: width .8s cubic-bezier(.22, 1, .36, 1);
}

/* ---------- Paneles y tablas ---------- */

.panel {
    min-width: 0;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
}

.panel-header h2 {
    margin: 0;
    font-size: 17px;
    letter-spacing: -.01em;
}

.panel-header p {
    margin: 5px 0 0;
    color: var(--muted);
    font-size: 13px;
}

.panel-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
}

.panel-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.btn-export {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    border: 1px solid var(--border);
    background: #fff;
    border-radius: 11px;
    padding: 9px 13px;
    cursor: pointer;
    font-weight: 700;
    font-size: 13px;
    color: var(--text);
    transition: border-color .15s, box-shadow .15s, transform .15s;
    white-space: nowrap;
}

.btn-export:hover {
    border-color: var(--primary);
    box-shadow: 0 4px 14px rgba(13, 125, 111, .15);
    transform: translateY(-1px);
}

.charts-row {
    display: grid;
    grid-template-columns: 3fr 2fr 5fr;
    gap: 18px;
    margin-bottom: 20px;
}

.panel-wide .chart-wrap {
    height: 300px;
}

.chart-wrap {
    position: relative;
    margin-top: 14px;
}

.chart-small {
    height: 300px;
}

.chart-line {
    height: 230px;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: auto;
    scrollbar-color: var(--primary) #e8f1f4;
}

.chart-line-content {
    width: max(100%, var(--chart-width, 100%));
    height: 210px;
    position: relative;
}

.chart-line::-webkit-scrollbar {
    height: 10px;
}

.chart-line::-webkit-scrollbar-track {
    background: #e8f1f4;
    border-radius: 10px;
}

.chart-line::-webkit-scrollbar-thumb {
    background: var(--primary);
    border-radius: 10px;
}

.chart-zoom {
    margin-top: 10px;
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.chart-zoom label {
    white-space: nowrap;
}

.chart-zoom-control {
    display: flex;
    align-items: center;
    gap: 7px;
    flex: 1;
    min-width: 80px;
    color: var(--primary);
    font-size: 18px;
}

.chart-zoom input {
    width: 100%;
    min-width: 0;
    accent-color: var(--primary);
    cursor: pointer;
}

.dimension-panel .tab-panel {
    min-height: 400px;
}

.table-wrap {
    margin-top: 15px;
}

.table-scroll {
    max-height: 300px;
    overflow-y: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13.5px;
}

.table-scroll thead th {
    position: sticky;
    top: 0;
    background: #f8fafc;
    z-index: 1;
}

th,
td {
    padding: 10px 10px;
    border-bottom: 1px solid var(--border);
    text-align: left;
}

th {
    color: #486071;
    font-size: 11.5px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: .05em;
    white-space: nowrap;
}

tbody tr:last-child td {
    border-bottom: 0;
}

tbody tr:hover td {
    background: #f5faf9;
}

.text-right {
    text-align: right;
}

.text-muted {
    color: var(--muted);
}

.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 99px;
    font-size: 11px;
    font-weight: 800;
    white-space: nowrap;
}

.badge-meta {
    background: var(--primary-soft);
    color: var(--primary-dark);
}

.badge-nometa {
    background: #f1f4f8;
    color: var(--muted);
}

/* ---------- Tabs de ámbito ---------- */

.dimension-panel {
    margin-bottom: 20px;
}

.tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 16px;
    padding-bottom: 2px;
    border-bottom: 1px solid var(--border);
}

.tab {
    border: 1px solid transparent;
    background: transparent;
    color: var(--muted);
    padding: 9px 16px;
    border-radius: 11px 11px 0 0;
    cursor: pointer;
    font-weight: 800;
    font-size: 13.5px;
    transition: color .15s, background .15s;
}

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

.tab.is-active {
    color: var(--primary-dark);
    background: var(--primary-soft);
    border-color: var(--border);
    border-bottom-color: transparent;
}

.tab-panel {
    display: none;
    padding-top: 16px;
}

.tab-panel.is-active {
    display: block;
    animation: fadeUp .28s ease;
}

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

.dim-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
    margin-bottom: 4px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 600;
}

.dim-note {
    color: var(--muted);
    font-size: 12.5px;
    margin: 0 0 10px;
}

.dim-grid {
    display: grid;
    grid-template-columns: 1.35fr 1fr;
    gap: 22px;
    align-items: stretch;
}

.dim-chart {
    position: relative;
    height: 500px;
    overflow-y: auto;
}

.dim-chart-content {
    position: relative;
    height: var(--chart-height, 500px);
    min-height: 500px;
}

.dim-empty {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    color: var(--muted);
    font-size: 13.5px;
    padding: 0 20px;
}

.pct {
    font-weight: 800;
}

.pct-low {
    color: var(--danger);
}

.pct-mid {
    color: #b9860f;
}

.pct-high {
    color: #21a873;
}

.dot {
    display: inline-block;
    width: 9px;
    height: 9px;
    border-radius: 50%;
    margin-right: 5px;
    vertical-align: middle;
}

.dim-meta span {
    display: inline-flex;
    align-items: center;
    margin-right: 14px;
}

.row-leader td:first-child::before {
    content: '';
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #21a873;
    margin-right: 7px;
    vertical-align: middle;
}

.dim-table {
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: 12px;
}

.dim-table .table-scroll {
    max-height: 380px;
    margin-top: 0;
    overflow-y: auto;
    overflow-x: auto;
}

.dim-table th,
.dim-table td {
    padding: 9px 12px;
}

/* ---------- Footer / estados ---------- */

.page-footer {
    margin-top: 6px;
    color: var(--muted);
    font-size: 12.5px;
    text-align: center;
}

.loading {
    position: fixed;
    right: 22px;
    bottom: 22px;
    z-index: 1000;
    display: flex;
    align-items: center;
    gap: 10px;
    background: #0f1e2d;
    color: #fff;
    padding: 12px 16px;
    border-radius: 12px;
    box-shadow: var(--shadow);
    font-weight: 700;
    font-size: 14px;
}

.spinner {
    width: 17px;
    height: 17px;
    border: 2.5px solid rgba(255, 255, 255, .3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin .7s linear infinite;
}

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

.error-box {
    margin-top: 18px;
    padding: 13px 15px;
    border: 1px solid #f6c9c2;
    background: #fdf1ef;
    color: #a3382a;
    border-radius: 12px;
    white-space: pre-wrap;
}

.hidden {
    display: none !important;
}

.table-scroll::-webkit-scrollbar {
    width: 9px;
    height: 9px;
}

.table-scroll::-webkit-scrollbar-thumb {
    background: #cdd9e2;
    border-radius: 99px;
}

.table-scroll::-webkit-scrollbar-track {
    background: transparent;
}

/* ---------- Responsive ---------- */

@media (max-width: 1280px) {
    .filters-card {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }

    .kpi-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

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

    .charts-row .panel-wide {
        grid-column: 1 / -1;
    }

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

@media (max-width: 860px) {
    .container {
        width: min(100% - 24px, 1440px);
        padding-top: 20px;
    }

    .page-header {
        flex-direction: column;
        align-items: flex-start;
        padding: 18px 20px;
    }

    .header-actions {
        width: 100%;
        flex-wrap: wrap;
    }

    .btn-secondary {
        flex: 1;
        justify-content: center;
    }

    .filters-card {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .kpi-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 560px) {
    .container {
        width: min(100% - 16px, 1440px);
        padding-top: 16px;
    }

    .filters-card,
    .kpi-grid,
    .charts-row {
        grid-template-columns: 1fr;
    }

    .tabs {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .tab {
        flex: 0 0 auto;
        padding: 9px 14px;
        font-size: 13px;
    }

    .kpi-card strong {
        font-size: 27px;
    }

    .dim-table .table-scroll {
        max-height: none;
    }
}
