/* ===== PROFESSIONAL PREMIUM SAAS INTERFACE SYSTEM ===== */

:root {
    --primary-color: #2563eb; /* Modern Royal Blue */
    --primary-dark: #1d4ed8;
    --accent-color: #3b82f6; /* Modern Blue Accent */
    --bg-dark: #f8fafc; /* Pure Light Slate 50 content bg */
    --card-bg: #ffffff; /* White card bg */
    --text-main: #0f172a; /* Slate 900 primary text */
    --text-dim: #64748b; /* Slate 500 secondary text */
    --error: #ef4444; /* Clean Red */
    --success: #10b981; /* Clean Green */
    --glass-border: #cbd5e1; /* Slate 300 border (Darker for visibility) */
    --topbar-bg: #ffffff; /* White topbar */
    --footer-bg: #ffffff; /* White footer */
    --ai-primary: #2563eb;
    --ai-primary-dim: rgba(37, 99, 235, 0.05);

    /* Phase and KPI colors upgraded to professional SaaS badges */
    --kpi-despliegue: #10b981; /* Emerald */
    --kpi-despliegue-bg: #ecfdf5;
    --kpi-despliegue-border: #d1fae5;

    --kpi-mesas: #0ea5e9; /* Sky blue */
    --kpi-mesas-bg: #f0f9ff;
    --kpi-mesas-border: #e0f2fe;

    --kpi-repliegue: #f59e0b; /* Amber */
    --kpi-repliegue-bg: #fef3c7;
    --kpi-repliegue-border: #fde68a;

    --ticker-operator: #2563eb;
    --ticker-time: #d97706;

    /* Theme-aware sidebar color accents */
    --sidebar-gold: #8b7355; /* Muted Gold/Brown */
    --sidebar-cyan: #4f8ba8; /* Muted Slate Blue */
    --sidebar-yellow: #9ca3af; /* Cool Gray */
    --sidebar-olive: #6b7280; /* Gray */
    --sidebar-green: #5c8a6b; /* Muted Forest Green */

    /* Sidebar "un poquito más oscuro" Slate 800 */
    --sidebar-bg: #1e293b; 
    --sidebar-text: #f1f5f9;
    --sidebar-text-dim: #94a3b8;
    --sidebar-border: #334155;
}

body.dark-mode {
    --primary-color: #3b82f6; /* Modern Dodger Blue */
    --primary-dark: #2563eb;
    --accent-color: #60a5fa;
    --bg-dark: #0f172a; /* Slate 900 content bg */
    --card-bg: #1e293b; /* Slate 800 card bg */
    --text-main: #f8fafc; /* Slate 50 text */
    --text-dim: #94a3b8; /* Slate 400 dim text */
    --error: #f87171;
    --success: #34d399;
    --glass-border: #334155; /* Slate 700 border */
    --topbar-bg: #1e293b; /* Slate 800 topbar */
    --footer-bg: #1e293b; /* Slate 800 footer */
    --ai-primary: #3b82f6;
    --ai-primary-dim: rgba(59, 130, 246, 0.1);

    /* Dark Mode KPI colors */
    --kpi-despliegue: #34d399;
    --kpi-despliegue-bg: rgba(52, 211, 153, 0.08);
    --kpi-despliegue-border: rgba(52, 211, 153, 0.2);

    --kpi-mesas: #38bdf8;
    --kpi-mesas-bg: rgba(56, 189, 248, 0.08);
    --kpi-mesas-border: rgba(56, 189, 248, 0.2);

    --kpi-repliegue: #fbbf24;
    --kpi-repliegue-bg: rgba(251, 191, 36, 0.08);
    --kpi-repliegue-border: rgba(251, 191, 36, 0.2);

    --ticker-operator: #38bdf8;
    --ticker-time: #fbbf24;

    /* Theme-aware sidebar color accents */
    --sidebar-gold: #b39b7d;
    --sidebar-cyan: #78a3b8;
    --sidebar-yellow: #9ca3af;
    --sidebar-olive: #9ca3af;
    --sidebar-green: #82a890;

    --sidebar-bg: #0f172a; /* Slate 900 sidebar is a bit darker than cards #1e293b */
    --sidebar-text: #f8fafc;
    --sidebar-text-dim: #64748b;
    --sidebar-border: #1e293b;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: Arial, Helvetica, sans-serif;
}

/* ===== PREMIUM SCROLLBARS ===== */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-dark);
}

::-webkit-scrollbar-thumb {
    background: var(--glass-border);
    border-radius: 4px;
    transition: background 0.3s;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-dim);
}

/* Firefox Support */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--glass-border) var(--bg-dark);
}

h1, h2, h3, h4, h5, h6 {
    color: var(--text-main);
    font-weight: 700;
}

body {
    background-color: var(--bg-dark);
    color: var(--text-main);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* ===== FIXED TOPBAR ===== */
#topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 55px;
    background: var(--topbar-bg);
    border-bottom: 1px solid var(--glass-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    z-index: 10000;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

#topbar .topbar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--primary-color);
    font-weight: 700;
    font-size: 1.15rem;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

#topbar .topbar-brand i { font-size: 1.25rem; }

#topbar .topbar-center {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.85rem;
    color: var(--text-dim);
    font-weight: 500;
}

#topbar .topbar-right {
    display: flex;
    align-items: center;
    gap: 15px;
    font-size: 0.85rem;
    color: var(--text-main);
}

#topbar .topbar-clock {
    color: var(--primary-color);
    font-weight: 700;
}

#topbar .topbar-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: 600;
    color: var(--text-main);
}

#topbar .topbar-status .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--success);
}

/* ===== FIXED FOOTER BAR ===== */
#footerbar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 36px;
    background: var(--footer-bg);
    border-top: 1px solid var(--glass-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    z-index: 10000;
    font-size: 0.75rem;
    color: var(--text-dim);
    letter-spacing: 0.5px;
}

#footerbar .footer-left { display: flex; align-items: center; gap: 8px; }
#footerbar .footer-left i { color: var(--primary-color); }
#footerbar .footer-right { display: flex; align-items: center; gap: 15px; }

#footerbar .footer-badge {
    background: var(--bg-dark);
    border: 1px solid var(--glass-border);
    border-radius: 4px;
    padding: 3px 10px;
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--primary-color);
}

/* ===== MODERN CARDS ===== */
.glass-card {
    background: var(--card-bg);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 2.5rem;
    width: 100%;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.03), 0 1px 2px rgba(0, 0, 0, 0.02);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.glass-card:hover {
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.05), 0 2px 4px rgba(0, 0, 0, 0.03);
}

.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-main);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.form-input {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-dark);
    border: 1px solid var(--glass-border);
    border-radius: 6px;
    color: var(--text-main);
    font-size: 0.95rem;
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.form-input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

select.form-input option {
    background: var(--card-bg);
    color: var(--text-main);
}

/* ===== PROFESSIONAL BUTTONS ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 18px;
    background: #f1f5f9;
    color: #475569;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
}

.btn:hover {
    background: #e2e8f0;
    color: #1e293b;
    border-color: #94a3b8;
}

.btn-primary {
    background: var(--primary-color) !important;
    color: #ffffff !important;
    border: 1px solid var(--primary-color) !important;
}

.btn-primary:hover {
    background: var(--primary-dark) !important;
    border-color: var(--primary-dark) !important;
    color: #ffffff !important;
    box-shadow: 0 2px 4px rgba(37, 99, 235, 0.2);
}

.btn-secondary {
    background: #e2e8f0 !important;
    color: #334155 !important;
    border: 1px solid #cbd5e1 !important;
}

.btn-secondary:hover {
    background: #cbd5e1 !important;
    color: #0f172a !important;
}

.btn-danger {
    background: var(--error) !important;
    color: #ffffff !important;
    border: 1px solid var(--error) !important;
}

.btn-danger:hover {
    background: #dc2626 !important;
    border-color: #b91c1c !important;
}

.btn-warning {
    background: #f59e0b !important;
    color: #ffffff !important;
    border: 1px solid #d97706 !important;
}

.btn-warning:hover {
    background: #d97706 !important;
}

.btn-outline-info {
    background: transparent !important;
    color: var(--primary-color) !important;
    border: 1px solid var(--primary-color) !important;
}

.btn-outline-info:hover {
    background: rgba(37, 99, 235, 0.08) !important;
}

/* ===== SYSTEM ALERTS ===== */
.alert {
    padding: 12px 16px;
    margin-bottom: 1.5rem;
    font-size: 0.85rem;
    text-align: center;
    border-radius: 6px;
    font-weight: 600;
}

.alert-error {
    background: #fef2f2;
    color: var(--error);
    border: 1px solid #fee2e2;
}

.alert-success {
    background: #ecfdf5;
    color: var(--success);
    border: 1px solid #d1fae5;
}

/* ===== DASHBOARD CONTAINER ===== */
.dashboard-container {
    display: flex;
    min-height: 100vh;
    width: 100%;
    background: var(--bg-dark);
    padding-top: 55px;
    padding-bottom: 36px;
}

.sidebar {
    width: 285px;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--sidebar-border);
    padding: 1.75rem 1rem;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 55px;
    height: calc(100vh - 91px);
    overflow-y: auto;
    transition: all 0.3s ease;
}

/* Sidebar Headings and Links to Slate */
.sidebar-heading {
    font-size: 0.72rem;
    color: var(--sidebar-text-dim);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin: 1.25rem 0 0.5rem 10px;
    font-weight: 700;
}

.nav-links {
    list-style: none;
}

.nav-item {
    margin-bottom: 3px;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    color: var(--sidebar-text);
    text-decoration: none;
    border-radius: 6px;
    font-size: 0.88rem;
    font-weight: 500;
    transition: all 0.2s ease;
}

.nav-link i {
    width: 20px;
    font-size: 1rem;
    text-align: center;
    color: var(--sidebar-text-dim);
    transition: color 0.2s;
}

.nav-link:hover {
    background: rgba(255, 255, 255, 0.06);
    color: #ffffff;
}

.nav-link.active {
    background: var(--primary-color);
    color: #ffffff !important;
}

.nav-link.active i {
    color: #ffffff !important;
}

/* Sidebar Accordion / Dropdowns in Slate */
.sidebar-dropdown-btn {
    width: 100%;
    background: transparent;
    border: none;
    outline: none;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 9px 12px;
    color: var(--sidebar-text);
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    text-align: left;
    border-radius: 6px;
    transition: all 0.2s;
}

.sidebar-dropdown-btn:hover {
    background: rgba(255, 255, 255, 0.06);
    color: #ffffff;
}

.sidebar-dropdown-btn.active {
    background: rgba(255, 255, 255, 0.08);
}

.sidebar-dropdown-btn .arrow-icon {
    font-size: 0.75rem;
    color: var(--sidebar-text-dim);
    transition: transform 0.2s ease;
}

.sidebar-dropdown-btn.active .arrow-icon {
    transform: rotate(90deg);
}

.sidebar-dropdown-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.25s ease-out;
    padding-left: 10px;
    margin-left: 10px;
    border-left: 1px dashed var(--sidebar-border);
}

.sidebar-dropdown-content.show {
    max-height: 500px;
}

.sidebar-dropdown-content .nav-link {
    font-size: 0.82rem;
    padding: 7px 12px;
    color: var(--sidebar-text-dim);
}

.sidebar-dropdown-content .nav-link:hover {
    color: #ffffff;
}

.sidebar-dropdown-content .nav-link.active {
    color: #ffffff !important;
}

/* ===== MAIN CONTENT ===== */
.main-content {
    flex: 1;
    padding: 1.75rem;
    overflow-y: auto;
}

/* KPI / STAT CARDS */
.summary-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--card-bg);
    border: 1px solid var(--glass-border);
    padding: 1.5rem;
    border-radius: 10px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.01);
    position: relative;
}

.stat-card h3 {
    font-size: 0.8rem;
    color: var(--text-dim);
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}

.stat-card .value {
    font-size: 2.2rem;
    font-weight: 700;
    color: var(--primary-color);
}

/* ===== TABLES ===== */
table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 20px;
    font-size: 0.9rem;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--glass-border);
}

th {
    background: var(--bg-dark);
    color: var(--text-main);
    border: 1px solid var(--glass-border);
    padding: 12px 16px;
    text-transform: uppercase;
    font-size: 0.8rem;
    letter-spacing: 0.5px;
    text-align: left;
    font-weight: 700;
}

td {
    border: 1px solid var(--glass-border);
    padding: 12px 16px;
    color: var(--text-main);
    background: var(--card-bg);
}

tr:hover td {
    background: var(--bg-dark);
}

/* ===== PANIC AND SOS ALERTS ===== */
.btn-panic {
    background: var(--error) !important;
    color: #ffffff !important;
    border: 1px solid var(--error) !important;
    font-weight: 700 !important;
    padding: 16px !important;
    font-size: 1.1rem !important;
    border-radius: 8px !important;
    box-shadow: 0 4px 10px rgba(239, 68, 68, 0.3);
}

.btn-panic:hover {
    background: #dc2626 !important;
}

.sos-active {
    animation: pulse-red 2s infinite;
    border: 2px solid var(--error) !important;
}

@keyframes pulse-red {
    0% { background: #fee2e2; }
    50% { background: #fca5a5; box-shadow: 0 0 20px rgba(239, 68, 68, 0.2); }
    100% { background: #fee2e2; }
}

.sos-banner {
    background: var(--error);
    color: white;
    padding: 10px 16px;
    text-align: center;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    position: sticky;
    top: 55px;
    z-index: 9999;
}

#red-alert-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(239, 68, 68, 0.15);
    backdrop-filter: blur(4px);
    z-index: 9999;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    border: 10px solid var(--error);
    box-sizing: border-box;
}

.alert-text {
    color: var(--error);
    font-size: 5rem;
    font-weight: 900;
    text-shadow: 0 0 20px rgba(239, 68, 68, 0.4);
    letter-spacing: 10px;
    margin: 0;
    animation: blink-fast 0.6s infinite;
}

@keyframes blink-fast {
    0% { opacity: 1; }
    50% { opacity: 0.2; }
    100% { opacity: 1; }
}

/* ===== TABS ===== */
.ai-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 20px;
    border-bottom: 2px solid var(--glass-border);
}

.ai-tab {
    flex: 1;
    padding: 10px 16px;
    background: var(--bg-dark);
    border: 1px solid var(--glass-border);
    border-bottom: none;
    color: var(--text-dim);
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
    text-align: center;
    transition: all 0.2s ease;
    border-top-left-radius: 6px;
    border-top-right-radius: 6px;
}

.ai-tab.active {
    background: var(--card-bg);
    color: var(--primary-color);
    border-bottom: 2px solid var(--card-bg);
    box-shadow: inset 0 3px 0 var(--primary-color);
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* ===== SWEET ALERT 2 PREMIUM OVERRIDES ===== */
div:where(.swal2-container) div:where(.swal2-popup).wg-swal {
    background: var(--card-bg) !important;
    border: 1px solid var(--glass-border) !important;
    color: var(--text-main) !important;
    border-radius: 12px !important;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.08) !important;
}

div:where(.swal2-container) h2:where(.swal2-title) {
    color: var(--text-main) !important;
    font-weight: 700 !important;
}

div:where(.swal2-container) div:where(.swal2-html-container) {
    color: var(--text-dim) !important;
    font-size: 0.95rem !important;
}

div:where(.swal2-icon).swal2-warning { border-color: #f59e0b !important; color: #f59e0b !important; }
div:where(.swal2-icon).swal2-success { border-color: #10b981 !important; color: #10b981 !important; }
div:where(.swal2-icon).swal2-error { border-color: #ef4444 !important; color: #ef4444 !important; }

/* ===== AUDIT LOG ROWS ===== */
.audit-row {
    padding: 10px 14px;
    border-bottom: 1px solid var(--glass-border);
    font-size: 0.85rem;
    display: flex;
    gap: 12px;
    align-items: flex-start;
    transition: background-color 0.2s;
}

.audit-row:hover {
    background-color: var(--bg-dark);
}

.audit-row .timestamp {
    color: var(--text-dim);
    font-size: 0.78rem;
    min-width: 70px;
}

.audit-row .tag {
    color: var(--primary-color);
    font-weight: 700;
    min-width: 80px;
}

/* ===== RESPONSIVE OVERLAYS ===== */
@media (max-width: 992px) {
    .dashboard-container { flex-direction: column; }
    .sidebar {
        position: fixed;
        left: -300px;
        top: 55px;
        height: calc(100vh - 55px);
        z-index: 10001;
        width: 285px;
        box-shadow: 4px 0 20px rgba(0,0,0,0.08);
        background: var(--sidebar-bg);
    }
    .sidebar.active { left: 0; }
    #sidebar-overlay {
        display: none;
        position: fixed;
        top: 55px; left: 0; right: 0; bottom: 0;
        background: rgba(0,0,0,0.3);
        backdrop-filter: blur(2px);
        z-index: 10000;
    }
    #sidebar-overlay.active { display: block; }
    #mobile-menu-btn { display: inline-block !important; }
    
    /* Grid adjustments for tablets/mobile */
    .op-main-stats, .summary-cards {
        grid-template-columns: 1fr !important;
    }
    .stats-left-group, .stats-right-group {
        display: flex;
        flex-direction: column;
        gap: 1rem;
    }
    .glass-card {
        padding: 1.5rem;
    }
}

@media (max-width: 768px) {
    /* Topbar adjustments */
    #topbar .topbar-center {
        display: none !important; /* Hide clock to save space */
    }
    #topbar {
        padding: 0 10px;
    }
    #topbar .topbar-brand {
        font-size: 1rem !important;
    }
    #topbar .topbar-right span {
        display: none; /* Hide operator name, show only icon/button */
    }
    .main-content {
        padding: 1rem;
    }
    .btn {
        padding: 8px 12px;
        font-size: 0.8rem;
    }
    .filter-bar {
        flex-direction: column;
        align-items: stretch;
    }
    .filter-group, .filter-input {
        width: 100%;
    }
    .page-header {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 15px;
    }
    .page-header > div:last-child {
        width: 100%;
        display: flex;
        flex-direction: column;
        gap: 10px;
    }
    .page-header > div:last-child .btn-group {
        width: 100%;
        margin-right: 0 !important;
        justify-content: center;
    }
}

/* ===== TABLE RESPONSIVE WRAPPER ===== */
.table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 20px;
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    background: var(--card-bg);
}
.table-responsive table {
    margin-bottom: 0 !important;
    border: none !important;
}

/* ===== DOAM OFFICIAL EXCEL REPORTING COLORS (LIGHT MODE OVERRIDES) ===== */
body.light-mode table.summary-table,
body.light-mode table.excel-theme,
body.light-mode table.detail-matrix {
    border-collapse: collapse !important;
    border: 1px solid #000000 !important;
}

/* 1. Table Headers (thead th) */
body.light-mode table.summary-table thead th,
body.light-mode table.excel-theme thead th,
body.light-mode table.detail-matrix thead th {
    background-color: var(--phase-header-bg, #c2f0b5) !important;
    background: var(--phase-header-bg, #c2f0b5) !important;
    color: #000000 !important;
    font-weight: bold !important;
    text-align: center !important;
    vertical-align: middle !important;
    border: 1px solid #000000 !important;
    font-size: 1.1rem !important;
    padding: 10px 18px !important;
}

body.light-mode table.summary-table thead th:first-child,
body.light-mode table.excel-theme thead th:first-child,
body.light-mode table.detail-matrix thead th:first-child {
    text-align: center !important;
    padding-left: 0 !important;
}

/* 2. Base Table Cells in Body (Default: White Background, Regular Black Text) */
body.light-mode table.summary-table tbody tr:not(.details-row) td,
body.light-mode table.excel-theme tbody tr:not(.details-row) td,
body.light-mode table.detail-matrix tbody tr:not(.details-row) td {
    background-color: #ffffff !important;
    background: #ffffff !important;
    color: #000000 !important;
    font-weight: normal !important;
    border: 1px solid #000000 !important;
    text-align: center !important;
    padding: 10px 18px !important;
}

/* Exclude details rows themselves from generic styles to keep drilldown grids clean */
body.light-mode table.summary-table tbody tr.details-row td {
    background-color: var(--bg-dark) !important;
    background: var(--bg-dark) !important;
    border: none !important;
}

/* 3. DDEE/Unit Column (1st column) - Light Grey Background, Bold Black Text */
body.light-mode table.summary-table tbody tr:not(.details-row) > td:first-child,
body.light-mode table.excel-theme tbody tr:not(.details-row) > td:first-child,
body.light-mode table.detail-matrix tbody tr:not(.details-row) > td:first-child {
    background-color: #e8e8e8 !important;
    background: #e8e8e8 !important;
    color: #000000 !important;
    font-weight: bold !important;
    text-align: center !important;
    padding-left: 0 !important;
    padding-right: 0 !important;
}

body.light-mode table.summary-table tbody tr:not(.details-row) > td:first-child *,
body.light-mode table.excel-theme tbody tr:not(.details-row) > td:first-child *,
body.light-mode table.detail-matrix tbody tr:not(.details-row) > td:first-child * {
    color: #000000 !important;
    font-weight: bold !important;
}

/* Center first column content and hide chevrons, circles, badges in light-mode to match plain text */
body.light-mode table.summary-table tbody tr:not(.details-row) td:first-child div,
body.light-mode table.detail-matrix tbody tr:not(.details-row) td:first-child div,
body.light-mode table.excel-theme tbody tr:not(.details-row) td:first-child div {
    display: block !important;
    text-align: center !important;
    width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
}

body.light-mode table.summary-table tbody tr:not(.details-row) td:first-child i,
body.light-mode table.summary-table tbody tr:not(.details-row) td:first-child span,
body.light-mode table.detail-matrix tbody tr:not(.details-row) td:first-child i,
body.light-mode table.detail-matrix tbody tr:not(.details-row) td:first-child span,
body.light-mode table.excel-theme tbody tr:not(.details-row) td:first-child i,
body.light-mode table.excel-theme tbody tr:not(.details-row) td:first-child span {
    display: none !important;
}

/* 4. Percentage Columns - Peach Background, Bold Black Text */
body.light-mode table.summary-table tbody tr:not(.details-row) td:nth-child(4),
body.light-mode table.summary-table tbody tr:not(.details-row) td:nth-child(6),
body.light-mode #container-me table.summary-table tbody tr:not(.details-row) td:nth-child(5),
body.light-mode table.detail-matrix tbody tr:not(.details-row) td:nth-child(4),
body.light-mode table.detail-matrix tbody tr:not(.details-row) td:nth-child(6),
body.light-mode #container-me table.detail-matrix tbody tr:not(.details-row) td:nth-child(5),
body.light-mode table.excel-theme tbody tr:not(.details-row) td:nth-child(4):not(:has(input)),
body.light-mode table.excel-theme tbody tr:not(.details-row) td:nth-child(6),
body.light-mode table.excel-theme tbody tr:not(.details-row) td.col-perc {
    background-color: #f6c6ac !important;
    background: #f6c6ac !important;
    color: #000000 !important;
    font-weight: bold !important;
    text-align: center !important;
}

body.light-mode table.summary-table tbody tr:not(.details-row) td:nth-child(4) *,
body.light-mode table.summary-table tbody tr:not(.details-row) td:nth-child(6) *,
body.light-mode #container-me table.summary-table tbody tr:not(.details-row) td:nth-child(5) *,
body.light-mode table.detail-matrix tbody tr:not(.details-row) td:nth-child(4) *,
body.light-mode table.detail-matrix tbody tr:not(.details-row) td:nth-child(6) *,
body.light-mode #container-me table.detail-matrix tbody tr:not(.details-row) td:nth-child(5) *,
body.light-mode table.excel-theme tbody tr:not(.details-row) td:nth-child(4):not(:has(input)) *,
body.light-mode table.excel-theme tbody tr:not(.details-row) td:nth-child(6) *,
body.light-mode table.excel-theme tbody tr:not(.details-row) td.col-perc * {
    color: #000000 !important;
    font-weight: bold !important;
}

/* Hide progress bar and fix font size for percentage cells */
body.light-mode table.summary-table tbody tr:not(.details-row) td:nth-child(4) div,
body.light-mode table.summary-table tbody tr:not(.details-row) td:nth-child(6) div,
body.light-mode #container-me table.summary-table tbody tr:not(.details-row) td:nth-child(5) div {
    font-size: 1.15rem !important;
    display: inline !important;
}

body.light-mode table.summary-table tbody tr:not(.details-row) td .progress-track,
body.light-mode table.detail-matrix tbody tr:not(.details-row) td .progress-track {
    display: none !important;
}

/* 5. Total row (tfoot) */
/* Header Label (1st column) - White Background, Bold Black Text */
body.light-mode table.summary-table tfoot tr td:nth-child(1),
body.light-mode table.excel-theme tfoot tr td:nth-child(1),
body.light-mode table.detail-matrix tfoot tr td:nth-child(1) {
    background-color: #ffffff !important;
    background: #ffffff !important;
    color: #000000 !important;
    font-weight: bold !important;
    border: 1px solid #000000 !important;
    text-align: center !important;
    padding-left: 0 !important;
}

/* Numeric Sums - Bright Yellow Background, Bold Black Text */
body.light-mode table.summary-table tfoot tr td:nth-child(2),
body.light-mode table.summary-table tfoot tr td:nth-child(3),
body.light-mode table.summary-table tfoot tr td:nth-child(5),
body.light-mode table.summary-table tfoot tr td:nth-child(7),
body.light-mode table.summary-table tfoot tr td:nth-child(8),
body.light-mode #container-me table.summary-table tfoot tr td:nth-child(4),
body.light-mode table.detail-matrix tfoot tr td:nth-child(2),
body.light-mode table.detail-matrix tfoot tr td:nth-child(3),
body.light-mode table.detail-matrix tfoot tr td:nth-child(5),
body.light-mode table.detail-matrix tfoot tr td:nth-child(7),
body.light-mode table.detail-matrix tfoot tr td:nth-child(8),
body.light-mode #container-me table.detail-matrix tfoot tr td:nth-child(4),
body.light-mode table.excel-theme tfoot tr td:nth-child(2),
body.light-mode table.excel-theme tfoot tr td:nth-child(3),
body.light-mode table.excel-theme tfoot tr td:nth-child(4),
body.light-mode table.excel-theme tfoot tr td:nth-child(5) {
    background-color: #ffff00 !important;
    background: #ffff00 !important;
    color: #000000 !important;
    font-weight: bold !important;
    border: 1px solid #000000 !important;
    text-align: center !important;
}

body.light-mode table.summary-table tfoot tr td:nth-child(2) *,
body.light-mode table.summary-table tfoot tr td:nth-child(3) *,
body.light-mode table.summary-table tfoot tr td:nth-child(5) *,
body.light-mode table.summary-table tfoot tr td:nth-child(7) *,
body.light-mode table.summary-table tfoot tr td:nth-child(8) *,
body.light-mode #container-me table.summary-table tfoot tr td:nth-child(4) *,
body.light-mode table.detail-matrix tfoot tr td:nth-child(2) *,
body.light-mode table.detail-matrix tfoot tr td:nth-child(3) *,
body.light-mode table.detail-matrix tfoot tr td:nth-child(5) *,
body.light-mode table.detail-matrix tfoot tr td:nth-child(7) *,
body.light-mode table.detail-matrix tfoot tr td:nth-child(8) *,
body.light-mode #container-me table.detail-matrix tfoot tr td:nth-child(4) *,
body.light-mode table.excel-theme tfoot tr td:nth-child(2) *,
body.light-mode table.excel-theme tfoot tr td:nth-child(3) *,
body.light-mode table.excel-theme tfoot tr td:nth-child(4) *,
body.light-mode table.excel-theme tfoot tr td:nth-child(5) * {
    color: #000000 !important;
    font-weight: bold !important;
}

/* Percentage Cells in Tfoot - Peach Background, Bold RED Text */
body.light-mode table.summary-table tfoot tr td:nth-child(4),
body.light-mode table.summary-table tfoot tr td:nth-child(6),
body.light-mode #container-me table.summary-table tfoot tr td:nth-child(5),
body.light-mode table.detail-matrix tfoot tr td:nth-child(4),
body.light-mode table.detail-matrix tfoot tr td:nth-child(6),
body.light-mode #container-me table.detail-matrix tfoot tr td:nth-child(5),
body.light-mode table.excel-theme tfoot tr td:nth-child(6) {
    background-color: #f6c6ac !important;
    background: #f6c6ac !important;
    color: #ff0000 !important;
    font-weight: bold !important;
    border: 1px solid #000000 !important;
    text-align: center !important;
}

body.light-mode table.summary-table tfoot tr td:nth-child(4) *,
body.light-mode table.summary-table tfoot tr td:nth-child(6) *,
body.light-mode #container-me table.summary-table tfoot tr td:nth-child(5) *,
body.light-mode table.detail-matrix tfoot tr td:nth-child(4) *,
body.light-mode table.detail-matrix tfoot tr td:nth-child(6) *,
body.light-mode #container-me table.detail-matrix tfoot tr td:nth-child(5) *,
body.light-mode table.excel-theme tfoot tr td:nth-child(6) * {
    color: #ff0000 !important;
    font-weight: bold !important;
}

/* Grid borders to look organized and identical to spreadsheet */
body.light-mode table.summary-table,
body.light-mode table.summary-table thead,
body.light-mode table.summary-table tbody,
body.light-mode table.summary-table tfoot,
body.light-mode table.summary-table tr,
body.light-mode table.summary-table th,
body.light-mode table.summary-table td,
body.light-mode table.detail-matrix,
body.light-mode table.detail-matrix thead,
body.light-mode table.detail-matrix tbody,
body.light-mode table.detail-matrix tr,
body.light-mode table.detail-matrix th,
body.light-mode table.detail-matrix td,
body.light-mode table.excel-theme,
body.light-mode table.excel-theme thead,
body.light-mode table.excel-theme tbody,
body.light-mode table.excel-theme tfoot,
body.light-mode table.excel-theme tr,
body.light-mode table.excel-theme th,
body.light-mode table.excel-theme td {
    border: 1px solid #000000 !important;
    border-collapse: collapse !important;
}

/* Overall container border/shadow adjustments for perfect spreadsheet look */
body.light-mode .table-container {
    border: 2px solid #000000 !important;
    box-shadow: none !important;
}
body.light-mode .phase-title-bar {
    background: var(--phase-header-bg, #c2f0b5) !important;
    border-bottom: 2px solid #000000 !important;
}
body.light-mode .phase-title-bar h2,
body.light-mode .phase-title-bar h2 i,
body.light-mode .phase-title-bar div {
    color: #000000 !important;
    font-weight: bold !important;
}

/* Phase specific light mode headers */
body.light-mode .table-container-f1 {
    --phase-header-bg: #c2f0b5; /* Light green */
}
body.light-mode .table-container-f2 {
    --phase-header-bg: #cce5ff; /* Light cyan */
}
body.light-mode .table-container-f3 {
    --phase-header-bg: #fff9c4; /* Light yellow */
}
body.light-mode .table-container-me {
    --phase-header-bg: #e6e6fa; /* Light purple (Lavender) for Mesas Escrutadas */
}
body.light-mode .table-container-ep {
    --phase-header-bg: #ffe4e1; /* Light pink (Misty Rose) for Estado de Patrullas */
}

