/* ═══════════════════════════════════════════════════════════════════════
   RENAC DataViewer — Estilos Globales
   ═══════════════════════════════════════════════════════════════════════ */

:root {
    /* Paleta RENAC */
    --blue-900: #0F2D52;
    --blue-800: #1E5596;
    --blue-700: #2565A8;
    --blue-600: #2E75B6;
    --blue-500: #4A90D9;
    --blue-400: #7AB3E8;
    --blue-300: #A8CEF0;
    --blue-200: #D6E4F0;
    --blue-100: #EBF2F8;
    --blue-50:  #F5F9FC;

    --red-500:  #C0504D;
    --red-400:  #D4736F;
    --green-600: #4F6D28;
    --green-500: #6B8F3A;
    --amber-500: #E5A832;

    --gray-900: #1A1A1A;
    --gray-800: #333333;
    --gray-700: #4D4D4D;
    --gray-600: #666666;
    --gray-500: #888888;
    --gray-400: #AAAAAA;
    --gray-300: #CCCCCC;
    --gray-200: #E0E0E0;
    --gray-100: #F0F0F0;
    --gray-50:  #F8F8F8;

    --white: #FFFFFF;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.10);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);
    --radius: 8px;
    --radius-sm: 4px;
    --radius-lg: 12px;
    --transition: 0.2s ease;

    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* ─── Reset ──────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
    font-size: 15px;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font);
    color: var(--gray-800);
    background: var(--gray-50);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ─── HEADER ─────────────────────────────────────────────────────────── */
#site-header {
    background: linear-gradient(135deg, var(--blue-900) 0%, var(--blue-700) 100%);
    color: var(--white);
    padding: 0;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-md);
}

.header-inner {
    max-width: 1280px;
    margin: 0 auto;
    padding: 16px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 14px;
}

.header-logo svg {
    display: block;
}

.header-text h1 {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: 1.5px;
    line-height: 1.2;
}

.header-text p {
    font-size: 0.78rem;
    opacity: 0.8;
    font-weight: 300;
    letter-spacing: 0.3px;
}

.header-meta {
    font-size: 0.75rem;
    opacity: 0.7;
    text-align: right;
    font-weight: 300;
}

/* ─── NAV TABS ───────────────────────────────────────────────────────── */
#main-nav {
    background: var(--white);
    border-bottom: 1px solid var(--gray-200);
    box-shadow: var(--shadow-sm);
    position: sticky;
    top: 68px;
    z-index: 90;
}

.nav-inner {
    max-width: 1280px;
    margin: 0 auto;
    padding: 0 24px;
    display: flex;
    gap: 0;
}

.nav-tab {
    border: none;
    background: none;
    font-family: var(--font);
    font-size: 0.88rem;
    font-weight: 500;
    color: var(--gray-600);
    padding: 14px 20px;
    cursor: pointer;
    border-bottom: 3px solid transparent;
    transition: all var(--transition);
    display: flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
}

.nav-tab:hover {
    color: var(--blue-600);
    background: var(--blue-50);
}

.nav-tab.active {
    color: var(--blue-800);
    border-bottom-color: var(--blue-600);
    font-weight: 600;
}

.tab-icon {
    font-size: 1rem;
}

/* ─── MAIN CONTENT ───────────────────────────────────────────────────── */
#main-content {
    max-width: 1280px;
    margin: 0 auto;
    padding: 24px;
    width: 100%;
    flex: 1;
}

.view {
    display: none;
    animation: fadeIn 0.3s ease;
}

.view.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ─── FILTERS BAR ────────────────────────────────────────────────────── */
.filters-bar {
    display: flex;
    gap: 16px;
    align-items: flex-end;
    flex-wrap: wrap;
    margin-bottom: 20px;
    padding: 16px 20px;
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--gray-200);
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 180px;
}

.filter-group label {
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--gray-600);
}

.filter-group select {
    font-family: var(--font);
    font-size: 0.88rem;
    padding: 8px 32px 8px 12px;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-sm);
    background: var(--white);
    color: var(--gray-800);
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M3 5l3 3 3-3' stroke='%23666' stroke-width='1.5' fill='none'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    transition: border-color var(--transition);
    max-width: 320px;
}

.filter-group select:hover {
    border-color: var(--blue-400);
}

.filter-group select:focus {
    outline: none;
    border-color: var(--blue-600);
    box-shadow: 0 0 0 3px rgba(46, 117, 182, 0.15);
}

.filter-checks {
    min-width: auto;
}

.check-group {
    display: flex;
    gap: 14px;
}

.check-label {
    font-size: 0.85rem !important;
    font-weight: 400 !important;
    text-transform: none !important;
    letter-spacing: 0 !important;
    color: var(--gray-700) !important;
    display: flex;
    align-items: center;
    gap: 5px;
    cursor: pointer;
}

.check-label input[type="checkbox"] {
    accent-color: var(--blue-600);
    width: 15px;
    height: 15px;
}

/* ─── CONTENT PANEL ──────────────────────────────────────────────────── */
.content-panel {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--gray-200);
    padding: 20px 24px;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--gray-100);
}

.panel-header h2 {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--blue-800);
}

.panel-actions {
    display: flex;
    gap: 6px;
    align-items: center;
}

.btn-toggle {
    border: 1px solid var(--gray-300);
    background: var(--white);
    font-family: var(--font);
    font-size: 0.78rem;
    font-weight: 500;
    color: var(--gray-600);
    padding: 6px 12px;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all var(--transition);
    display: flex;
    align-items: center;
    gap: 5px;
}

.btn-toggle:hover {
    border-color: var(--blue-400);
    color: var(--blue-600);
}

.btn-toggle.active {
    background: var(--blue-600);
    color: var(--white);
    border-color: var(--blue-600);
}

.btn-download {
    border: 1px solid var(--gray-300);
    background: var(--white);
    padding: 6px 8px;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all var(--transition);
    color: var(--gray-500);
}

.btn-download:hover {
    border-color: var(--blue-400);
    color: var(--blue-600);
    background: var(--blue-50);
}

/* ─── CHART ──────────────────────────────────────────────────────────── */
.chart-container {
    position: relative;
    height: 380px;
    width: 100%;
}

.chart-tall {
    height: 640px;
}

.chart-footnote {
    font-size: 0.75rem;
    color: var(--gray-500);
    margin-top: 12px;
    padding-top: 8px;
    border-top: 1px solid var(--gray-100);
    font-style: italic;
}

/* ─── DATA TABLE ─────────────────────────────────────────────────────── */
.table-container {
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.data-table thead th {
    background: var(--blue-800);
    color: var(--white);
    font-weight: 600;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 10px 14px;
    text-align: left;
    white-space: nowrap;
    position: sticky;
    top: 0;
}

.data-table thead th:first-child {
    border-radius: var(--radius-sm) 0 0 0;
}

.data-table thead th:last-child {
    border-radius: 0 var(--radius-sm) 0 0;
}

.data-table thead th.num {
    text-align: center;
}

.data-table tbody td {
    padding: 8px 14px;
    border-bottom: 1px solid var(--gray-100);
    white-space: nowrap;
}

.data-table tbody td.num {
    text-align: center;
    font-variant-numeric: tabular-nums;
}

/* Porcentaje entre paréntesis en las columnas de clasificación */
.data-table .pct {
    color: inherit;
    font-size: inherit;
    font-weight: inherit;
}

/* Tabla jerárquica: font-size reducido para acomodar más columnas */
.data-table.hierarchical {
    font-size: 0.80rem;
}

.data-table.hierarchical thead th {
    padding: 9px 10px;
    font-size: 0.72rem;
}

.data-table.hierarchical tbody td {
    padding: 7px 10px;
}


.data-table tbody tr:hover {
    background: var(--blue-50);
}

.data-table tbody tr:nth-child(even) {
    background: var(--gray-50);
}

.data-table tbody tr:nth-child(even):hover {
    background: var(--blue-50);
}

/* Hierarchical table styles */
.data-table.hierarchical tbody tr.row-group {
    background: var(--blue-100);
    font-weight: 600;
    cursor: pointer;
}

.data-table.hierarchical tbody tr.row-group:hover {
    background: var(--blue-200);
}

.data-table.hierarchical tbody tr.row-group td:first-child {
    padding-left: 14px;
}

.data-table.hierarchical tbody tr.row-group td:first-child::before {
    content: '▾ ';
    font-size: 0.7rem;
    color: var(--blue-600);
    margin-right: 4px;
}

.data-table.hierarchical tbody tr.row-group.collapsed td:first-child::before {
    content: '▸ ';
}

.data-table.hierarchical tbody tr.row-child td:first-child {
    padding-left: 36px;
    font-weight: 400;
}

.data-table.hierarchical tbody tr.row-child.hidden {
    display: none;
}

.data-table.hierarchical tbody tr.row-total {
    background: var(--blue-800);
    color: var(--white);
    font-weight: 700;
}

.data-table.hierarchical tbody tr.row-total:hover {
    background: var(--blue-900);
}

.data-table.hierarchical tbody tr.row-section {
    background: var(--gray-100);
    font-weight: 600;
    font-size: 0.82rem;
    color: var(--gray-700);
}

.row-argentina {
    background: var(--blue-200) !important;
    font-weight: 700;
}

/* ─── FOOTER ─────────────────────────────────────────────────────────── */
#site-footer {
    background: var(--blue-900);
    color: rgba(255,255,255,0.75);
    padding: 20px 24px;
    margin-top: auto;
}

.footer-inner {
    max-width: 1280px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.footer-source {
    font-size: 0.78rem;
}

.footer-source strong {
    color: rgba(255,255,255,0.95);
}

.footer-notes {
    font-size: 0.72rem;
    opacity: 0.7;
}

/* ─── LOADING OVERLAY ────────────────────────────────────────────────── */
#loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(255,255,255,0.95);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    gap: 16px;
    transition: opacity 0.4s ease;
}

#loading-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--blue-200);
    border-top-color: var(--blue-600);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

#loading-overlay p {
    font-size: 0.9rem;
    color: var(--gray-600);
    font-weight: 500;
}

/* ─── RESPONSIVE ─────────────────────────────────────────────────────── */
@media (max-width: 768px) {
    html { font-size: 14px; }

    .header-inner { flex-direction: column; gap: 8px; text-align: center; }
    .header-meta { text-align: center; }

    .nav-inner { overflow-x: auto; }
    .nav-tab { padding: 12px 14px; font-size: 0.82rem; }

    #main-content { padding: 16px; }

    .filters-bar { flex-direction: column; gap: 12px; }
    .filter-group { min-width: 100%; }
    .filter-group select { max-width: 100%; }

    .panel-header { flex-direction: column; gap: 10px; align-items: flex-start; }

    .chart-container { height: 280px; }
    .chart-tall { height: 500px; }
}

/* ─── MULTI-SELECT DROPDOWN ──────────────────────────────────────────── */
.multi-select-dropdown {
    position: relative;
    max-width: 320px;
    width: 100%;
}

.dropdown-toggle {
    font-family: var(--font);
    font-size: 0.88rem;
    padding: 8px 32px 8px 12px;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-sm);
    background: var(--white);
    color: var(--gray-800);
    cursor: pointer;
    text-align: left;
    width: 100%;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M3 5l3 3 3-3' stroke='%23666' stroke-width='1.5' fill='none'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-height: 35px;
}

.dropdown-toggle:hover {
    border-color: var(--blue-400);
}

.dropdown-toggle:focus {
    outline: none;
    border-color: var(--blue-600);
    box-shadow: 0 0 0 3px rgba(46, 117, 182, 0.15);
}

.dropdown-menu {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    z-index: 100;
    background: var(--white);
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-sm);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    padding: 10px;
    min-width: 240px;
    max-height: 300px;
    overflow-y: auto;
    flex-direction: column;
    gap: 8px;
}

.dropdown-menu.show {
    display: flex;
}
