:root {
    --primary: #2563eb;
    --primary-dark: #1e40af;
    --bg-dark: #0f172a;
    --bg-card: #1e293b;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --accent: #38bdf8;
    --danger: #ef4444;
    --success: #22c55e;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-primary);
    min-height: 100vh;
    padding: 1rem;
}

.dashboard-container {
    max-width: 1200px;
    margin: 0 auto;
}

/* Header */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    padding: 1rem;
    background: rgba(30, 41, 59, 0.7);
    backdrop-filter: blur(10px);
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.logo-section h1 {
    font-size: 1.5rem;
    background: linear-gradient(to right, var(--accent), var(--primary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.date-selector select {
    background: var(--bg-dark);
    color: var(--text-primary);
    border: 1px solid var(--text-secondary);
    padding: 0.5rem 1rem;
    border-radius: 6px;
    font-size: 1rem;
    outline: none;
}

/* KPI Grid */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.kpi-card {
    background: linear-gradient(145deg, var(--bg-card), rgba(30, 41, 59, 0.6));
    padding: 1.5rem;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.05);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    transition: transform 0.2s;
}

.kpi-card:hover {
    transform: translateY(-2px);
    border-color: var(--primary);
}

.kpi-title {
    color: var(--text-secondary);
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.5rem;
}

.kpi-value {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
}

.kpi-unit {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

/* Main Content Layout */
.main-content {
    display: grid;
    grid-template-columns: 1fr;
    gap: 2rem;
}

@media (min-width: 1024px) {
    .main-content {
        grid-template-columns: 2fr 1fr;
    }
}

.section-card {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 1.5rem;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.section-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--accent);
}

/* Data Tables */
.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th,
.data-table td {
    padding: 0.75rem;
    text-align: left;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.data-table th {
    color: var(--text-secondary);
    font-weight: 500;
    font-size: 0.875rem;
}

.data-table td {
    font-family: 'Roboto Mono', monospace;
}

.data-table tr:last-child td {
    border-bottom: none;
}

/* Loading State */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg-dark);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    border-top-color: var(--accent);
    animation: spin 1s ease-in-out infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.hidden {
    display: none !important;
}

/* IntegradoS1 Specific Styles */
.chart-content-row {
    display: flex;
    gap: 1.5rem;
    align-items: center;
    justify-content: center;
}

.chart-wrapper-compact {
    position: relative;
    height: 220px;
    width: 220px;
    margin: 0 auto;
}

.center-val-compact {
    font-size: 1.8rem;
    font-weight: 800;
    color: #fff;
    line-height: 1;
}

/* Custom Legend */
.legend-pemex {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    font-size: 0.95rem;
    color: var(--text-primary);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.legend-color {
    width: 12px;
    height: 12px;
    display: inline-block;
}

/* Export Table */
.export-table-clean {
    width: 100%;
    font-size: 0.95rem;
    border-collapse: collapse;
}

.export-table-clean td {
    padding: 2px 0;
    border: none;
}

.export-table-clean .val-col {
    text-align: right;
    font-weight: 700;
    padding-left: 1rem;
}

.section-title-pemex {
    font-size: 1.25rem;
    font-weight: 700;
    margin-bottom: 1rem;
    color: #fff;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

@media(max-width: 768px) {
    .chart-content-row {
        flex-direction: column;
        text-align: left;
        /* Changed from center to left for better alignment */
        align-items: center;
    }

    /* Better Grid Layout for Legend on Mobile */
    .legend-pemex {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
        margin-top: 1.5rem;
        width: 100%;
        max-width: 300px;
    }

    .legend-pemex .legend-item {
        justify-content: flex-start;
    }

    .export-table-clean {
        width: 100%;
        max-width: 300px;
        margin: 1rem auto;
    }

    /* Ensure the second card (Distribution) aligns items correctly */
    .section-card .legend-pemex[style*="align-items: flex-start"] {
        align-items: stretch !important;
        /* Override inline style on mobile */
    }
}

/* --- Navigation Tabs (Level 1) --- */
.nav-tabs-container {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
    border-bottom: 2px solid rgba(255, 255, 255, 0.1);
    overflow-x: auto;
    padding-bottom: 0.5rem;
    -ms-overflow-style: none;
    scrollbar-width: none;
    /* Add padding to prevent cut-off feeling on mobile */
    padding-right: 1rem;
}

.nav-tabs-container::-webkit-scrollbar {
    display: none;
}

.nav-tab {
    padding: 0.5rem 1rem;
    color: var(--text-secondary);
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: color 0.2s;
    border-bottom: 2px solid transparent;
    margin-bottom: -0.6rem;
}

.nav-tab:hover {
    color: var(--text-primary);
}

.nav-tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

/* --- Sub Navigation Pills (Level 2) --- */
.sub-nav-container {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 2rem;
    flex-wrap: wrap;
}

.sub-nav-pill {
    background: rgba(255, 255, 255, 0.05);
    padding: 0.4rem 1rem;
    border-radius: 20px;
    font-size: 0.875rem;
    color: var(--text-secondary);
    cursor: pointer;
    border: 1px solid transparent;
    transition: all 0.2s;
}

.sub-nav-pill:hover {
    background: rgba(255, 255, 255, 0.1);
}

.sub-nav-pill.active {
    background: rgba(37, 99, 235, 0.2);
    color: var(--accent);
    border-color: var(--primary);
}

/* --- Login Overlay --- */
#login-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.95);
    backdrop-filter: blur(10px);
    z-index: 2000;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
}

.login-card {
    background: var(--bg-card);
    padding: 2rem;
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    width: 90%;
    max-width: 400px;
    text-align: center;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.5);
}

.login-card h2 {
    margin-bottom: 1.5rem;
    color: var(--accent);
}

.login-input {
    width: 100%;
    padding: 0.75rem;
    margin-bottom: 1rem;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--text-secondary);
    border-radius: 8px;
    color: white;
    font-size: 1rem;
}

.login-btn {
    width: 100%;
    padding: 0.75rem;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.login-btn:hover {
    background: var(--primary-dark);
}

.error-msg {
    color: var(--danger);
    margin-top: 1rem;
    font-size: 0.875rem;
    display: none;
}

.dashboard-container.active {
    filter: none;
    pointer-events: all;
}

/* --- Added for Integrado Report Charts --- */
.charts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.chart-card {
    background: var(--bg-card);
    padding: 1.5rem;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.chart-title {
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 1rem;
    color: #fff;
    display: flex;
    justify-content: space-between;
}

.chart-wrapper {
    position: relative;
    height: 250px;
    width: 100%;
    display: flex;
    justify-content: center;
}

.center-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
}

.center-val {
    font-size: 2rem;
    font-weight: 800;
    line-height: 1;
}

.center-label {
    font-size: 0.8rem;
    color: #aaa;
}

/* Legend Styling & Alignment Fix */
.legend-custom {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    justify-content: center;
    margin-top: 1.5rem;
    font-size: 0.9rem;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.dot {
    width: 10px;
    height: 10px;
    border-radius: 2px;
}

/* Distributions Chart Specific Layout */
.dist-chart-row {
    display: flex;
    align-items: center;
}

.dist-chart-col-graph {
    flex: 1;
    position: relative;
    height: 250px;
}

.dist-chart-col-data {
    flex: 0 0 140px;
    padding-left: 1rem;
}

.export-table-mini {
    width: 100%;
    margin-top: 1rem;
    font-size: 0.9rem;
}

.export-table-mini td {
    padding: 4px 0;
    border-bottom: 1px solid #333;
}

.val-right {
    text-align: right;
    font-weight: bold;
    font-family: 'Roboto Mono';
}

/* Mobile Responsive Adjustments */
@media (max-width: 768px) {
    .charts-grid {
        grid-template-columns: 1fr;
    }

    /* Fix Legend Alignment: Use Grid for neat columns */
    .legend-custom {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
        justify-items: start;
        /* Left align items */
        padding: 0 0.5rem;
    }

    /* Fix Distribution Chart Layout Stacking */
    .dist-chart-row {
        flex-direction: column;
    }

    .dist-chart-col-data {
        flex: 1;
        width: 100%;
        padding-left: 0;
        padding-top: 1.5rem;
        display: grid;
        grid-template-columns: 1fr 1fr;
        /* Side by side table and legend */
        gap: 1rem;
        align-items: start;
    }

    .export-table-mini {
        margin-top: 0;
    }

    /* Override legend in data col to match */
    .dist-chart-col-data .legend-custom {
        margin-top: 0;
        display: flex;
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }
}