:root {
    --sidebar-width: 250px;
    --sidebar-width-collapsed: 70px;
    --primary-color: #0f172a;
    /* Darker blue/slate */
    --secondary-color: #1e293b;
    --accent-color: #3b82f6;
    /* Bright blue for active/hover */
    --text-color: #334155;
    --text-light: #f8fafc;
    /* Almost white */
    --header-height: 60px;
}

body {
    background-color: #f1f5f9;
    font-family: 'Inter', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    margin: 0;
    padding: 0;
    overflow-x: hidden;
}

/* Login Page */
.login-container {
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    background: linear-gradient(-45deg, #0f172a, #1e293b, #0f172a, #0ca0c5);
    background-size: 400% 400%;
    animation: gradient 15s ease infinite;
}

@keyframes gradient {
    0% {
        background-position: 0% 50%;
    }

    50% {
        background-position: 100% 50%;
    }

    100% {
        background-position: 0% 50%;
    }
}

.login-card {
    background-color: white;
    padding: 40px;
    border-radius: 10px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
    width: 100%;
    max-width: 400px;
    text-align: center;
}

.login-card img {
    width: 80px;
    margin-bottom: 20px;
}

/* Sidebar */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--sidebar-width);
    height: 100vh;
    z-index: 1050;
    /* Higher than content */
    padding: 0;
    background-color: var(--secondary-color);
    transition: all 0.3s;
    overflow-x: hidden;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.sidebar-header {
    height: var(--header-height);
    display: flex;
    align-items: center;
    padding: 0 20px;
    background-color: rgba(235, 227, 227, 0.1);
    margin-bottom: 20px;
    cursor: pointer;
    /* Allow clicking to toggle */
}

.sidebar-logo {
    width: 35px;
    height: 35px;
    object-fit: contain;
    transition: all 0.3s;
    flex-shrink: 0;
}

.sidebar-brand {
    margin-left: 12px;
    color: var(--text-light);
    white-space: nowrap;
    opacity: 1;
    transition: opacity 0.2s;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.sidebar-brand h4 {
    font-size: 1.1rem;
    font-weight: 700;
    margin: 0;
    letter-spacing: 0.5px;
}

.sidebar-brand small {
    font-size: 0.75rem;
    color: #94a3b8;
    /* Lighter slate for subtitle */
}

/* Navigation Links */
.nav-pills .nav-link {
    display: flex;
    align-items: center;
    padding: 12px 20px;
    color: #94a3b8;
    border-radius: 0;
    transition: all 0.2s;
    margin-bottom: 2px;
    border-left: 3px solid transparent;
    cursor: pointer;
}

.nav-pills .nav-link:hover {
    background-color: rgba(255, 255, 255, 0.05);
    color: var(--text-light);
}

.nav-pills .nav-link.active {
    background-color: rgba(59, 130, 246, 0.1);
    /* Transparent blue */
    color: var(--accent-color);
    border-left-color: var(--accent-color);
}

.sidebar-icon {
    font-size: 1.25rem;
    min-width: 30px;
    text-align: center;
    display: flex;
    justify-content: center;
    align-items: center;
}

.sidebar-text {
    margin-left: 12px;
    white-space: nowrap;
    opacity: 1;
    transition: opacity 0.2s;
}

/* Content */
.content {
    margin-left: var(--sidebar-width);
    padding: 20px;
    transition: all 0.3s;
    min-height: 100vh;
}

/* Header */
.header {
    height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 40px;
    /* Increased padding */
    background-color: #fff;
    /* box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05); */
    margin-bottom: 20px;
    /* border-radius: 10px; */
    border-bottom: 1px solid #e2e8f0;
    margin-left: -20px;
    margin-right: -20px;
    margin-top: -20px;
}

.header h3 {
    font-size: 1.75rem;
    /* Increased font size */
    font-weight: 700;
    color: var(--primary-color);
    margin: 0;
    letter-spacing: -0.5px;
    font-family: 'Inter', sans-serif;
}

.user-menu {
    display: flex;
    align-items: center;
    gap: 15px;
}

/* Global Card Styles */
.card {
    box-shadow: none !important;
    border: 1px solid #e2e8f0 !important;
    border-radius: 4px !important;
}

/* Sidebar Collapsed State */
.sidebar.collapsed {
    width: var(--sidebar-width-collapsed);
}

.sidebar.collapsed .sidebar-header {
    justify-content: center;
    padding: 0;
}

.sidebar.collapsed .sidebar-brand,
.sidebar.collapsed .sidebar-text,
.sidebar.collapsed #admin-submenu,
.sidebar.collapsed #paginas-submenu {
    display: none !important;
    opacity: 0;
    width: 0;
    height: 0;
    overflow: hidden;
}

.sidebar.collapsed .nav-link {
    justify-content: center;
    padding: 12px 0;
}

.sidebar.collapsed .sidebar-icon {
    margin: 0;
}

.content.collapsed {
    margin-left: var(--sidebar-width-collapsed);
}

/* Overlay for mobile only */
.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 1040;
    display: none;
    opacity: 0;
    transition: opacity 0.3s ease-in-out;
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
    .sidebar {
        width: var(--sidebar-width);
        transform: translateX(0);
        /* Open by default logic, but we toggle class */
    }

    .sidebar.collapsed {
        width: var(--sidebar-width);
        transform: translateX(-100%);
        /* Hidden when collapsed */
    }

    .content {
        margin-left: 0 !important;
        width: 100%;
    }

    .content.collapsed {
        margin-left: 0 !important;
        width: 100%;
    }

    .sidebar-overlay.show {
        display: block;
        opacity: 1;
    }

    .sidebar .sidebar-brand {
        display: flex;
        opacity: 1;
        width: auto;
    }

    .sidebar .sidebar-text {
        display: block;
        opacity: 1;
    }

    .sidebar .nav-link {
        justify-content: flex-start;
        padding: 12px 20px;
    }

    .sidebar .sidebar-icon {
        margin-right: 0;
        border-left-color: var(--accent-color);
    }

    .sidebar-icon {
        font-size: 1.25rem;
        min-width: 30px;
        text-align: center;
        display: flex;
        justify-content: center;
        align-items: center;
    }

    .sidebar-text {
        margin-left: 12px;
        white-space: nowrap;
        opacity: 1;
        transition: opacity 0.2s;
    }

    /* Content */
    .content {
        margin-left: var(--sidebar-width);
        padding: 20px;
        transition: all 0.3s;
        min-height: 100vh;
    }

    /* Header */
    .header {
        height: var(--header-height);
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 0 30px;
        background-color: #fff;
    }

    /* Sidebar Collapsed State */
    .sidebar.collapsed {
        width: var(--sidebar-width-collapsed);
    }

    .sidebar.collapsed .sidebar-header {
        justify-content: center;
        padding: 0;
    }

    .sidebar.collapsed .sidebar-brand,
    .sidebar.collapsed .sidebar-text,
    .sidebar.collapsed #admin-submenu,
    .sidebar.collapsed #paginas-submenu {
        display: none !important;
        opacity: 0;
        width: 0;
        height: 0;
        overflow: hidden;
    }

    .sidebar.collapsed .nav-link {
        justify-content: center;
        padding: 12px 0;
    }

    .sidebar.collapsed .sidebar-icon {
        margin: 0;
    }

    .content.collapsed {
        margin-left: var(--sidebar-width-collapsed);
    }

    /* Overlay for mobile only */
    .sidebar-overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100vw;
        height: 100vh;
        background-color: rgba(0, 0, 0, 0.5);
        z-index: 1040;
        display: none;
        opacity: 0;
        transition: opacity 0.3s ease-in-out;
    }

    /* Mobile Responsiveness */
    @media (max-width: 768px) {
        .sidebar {
            width: var(--sidebar-width);
            transform: translateX(0);
            /* Open by default logic, but we toggle class */
        }

        .sidebar.collapsed {
            width: var(--sidebar-width);
            transform: translateX(-100%);
            /* Hidden when collapsed */
        }

        .content {
            margin-left: 0 !important;
            width: 100%;
        }

        .content.collapsed {
            margin-left: 0 !important;
            width: 100%;
        }

        .sidebar-overlay.show {
            display: block;
            opacity: 1;
        }

        .sidebar .sidebar-brand {
            display: flex;
            opacity: 1;
            width: auto;
        }

        .sidebar .sidebar-text {
            display: block;
            opacity: 1;
        }

        .sidebar .nav-link {
            justify-content: flex-start;
            padding: 12px 20px;
        }

        .sidebar .sidebar-icon {
            margin-right: 0;
            /* Reset if needed */
        }
    }

    /* Desktop Overlay - ensure hidden */
    @media (min-width: 769px) {
        .sidebar-overlay.show {
            display: none;
        }
    }

    /* Pulsing Green Animation */
    @keyframes pulse-green {
        0% {
            transform: scale(0.95);
            box-shadow: 0 0 0 0 rgba(25, 135, 84, 0.7);
        }

        70% {
            transform: scale(1);
            box-shadow: 0 0 0 10px rgba(25, 135, 84, 0);
        }

        100% {
            transform: scale(0.95);
            box-shadow: 0 0 0 0 rgba(25, 135, 84, 0);
        }
    }

    .pulsing-green {
        animation: pulse-green 2s infinite;
    }

    /* IA Chat Table Styles */
    #ia-chat-output table {
        width: 100% !important;
        border-collapse: collapse !important;
        margin: 15px 0 !important;
        font-size: 0.9rem !important;
        border: 1px solid #dee2e6 !important;
    }

    #ia-chat-output th,
    #ia-chat-output td {
        padding: 10px !important;
        border: 1px solid #dee2e6 !important;
    }

    #ia-chat-output th {
        background-color: #f8f9fa !important;
        font-weight: 600 !important;
    }

    #ia-chat-output tr:nth-child(even) {
        background-color: #f8f9fa !important;
    }

    #ia-chat-output tr:hover {
        background-color: #f1f5f9 !important;
    }

    /* Print Optimization */
    @media print {
        @page {
            size: A4;
            margin: 5mm;
        }

        body {
            background-color: white;
            -webkit-print-color-adjust: exact;
            print-color-adjust: exact;
            zoom: 0.65;
        }

        /* Hide Sidebar, Buttons, and unnecessary elements */
        .sidebar,
        .sidebar-overlay,
        #dash-btn-filters,
        #dash-btn-pdf,
        .btn-close,
        .offcanvas,
        .offcanvas-backdrop {
            display: none !important;
        }

        /* Reset Content Margins */
        .content,
        .content.collapsed {
            margin-left: 0 !important;
            padding: 0 !important;
            width: 100% !important;
            min-height: auto !important;
        }

        /* Adjust Layout for Print */
        .container-fluid {
            padding: 0 !important;
            max-width: 100% !important;
        }

        /* Force Grid System for Print */
        .row {
            display: flex !important;
            flex-wrap: wrap !important;
            margin-right: 0 !important;
            margin-left: 0 !important;
        }

        /* Default to full width */
        .col-12 {
            flex: 0 0 100% !important;
            max-width: 100% !important;
            width: 100% !important;
            padding-right: 5px !important;
            padding-left: 5px !important;
        }

        /* Cards: 4 per row on PC (md-3), force 2 per row (50%) for print readability */
        .col-md-3 {
            flex: 0 0 50% !important;
            max-width: 50% !important;
            width: 50% !important;
        }

        /* Charts: 2 per row on PC (lg-6/md-6), force 2 per row (50%) for print */
        .col-lg-6,
        .col-md-6 {
            flex: 0 0 50% !important;
            max-width: 50% !important;
            width: 50% !important;
        }

        /* Specific override for full width charts if any (like Ranking por Familia) */
        /* If it has only col-12 and no md/lg specific class, it stays 100% from .col-12 rule above */

        /* Compact Cards */
        .card {
            break-inside: avoid;
            page-break-inside: avoid;
            border: 1px solid #eee !important;
            box-shadow: none !important;
            margin-bottom: 10px !important;
        }

        .card-header {
            padding: 5px 10px !important;
            background-color: #f8f9fa !important;
        }

        .card-body {
            padding: 5px !important;
        }

        /* Adjust Graph Heights for Print */
        .js-plotly-plot {
            height: auto !important;
            max-height: 300px !important;
        }

        /* Ensure text is readable */
        h2,
        h3,
        h4,
        h5,
        h6 {
            color: #000 !important;
        }
    }
}

/* KPI Card Styles */
.card-body-kpi {
    display: flex;
    opacity: 1;
}

.sidebar .sidebar-brand {
    display: flex;
    opacity: 1;
    width: auto;
}

.sidebar .sidebar-text {
    display: block;
    opacity: 1;
}

.sidebar .nav-link {
    justify-content: flex-start;
    padding: 12px 20px;
}

.sidebar .sidebar-icon {
    margin-right: 0;
    /* Reset if needed */
}
}

/* Desktop Overlay - ensure hidden */
@media (min-width: 769px) {
    .sidebar-overlay.show {
        display: none;
    }
}

/* Pulsing Green Animation */
@keyframes pulse-green {
    0% {
        transform: scale(0.95);
        box-shadow: 0 0 0 0 rgba(25, 135, 84, 0.7);
    }

    70% {
        transform: scale(1);
        box-shadow: 0 0 0 10px rgba(25, 135, 84, 0);
    }

    100% {
        transform: scale(0.95);
        box-shadow: 0 0 0 0 rgba(25, 135, 84, 0);
    }
}

.pulsing-green {
    animation: pulse-green 2s infinite;
}

/* IA Chat Table Styles */
#ia-chat-output table {
    width: 100% !important;
    border-collapse: collapse !important;
    margin: 15px 0 !important;
    font-size: 0.9rem !important;
    border: 1px solid #dee2e6 !important;
}

#ia-chat-output th,
#ia-chat-output td {
    padding: 10px !important;
    border: 1px solid #dee2e6 !important;
}

#ia-chat-output th {
    background-color: #f8f9fa !important;
    font-weight: 600 !important;
}

#ia-chat-output tr:nth-child(even) {
    background-color: #f8f9fa !important;
}

#ia-chat-output tr:hover {
    background-color: #f1f5f9 !important;
}

/* Print Optimization */
@media print {
    @page {
        size: A4;
        margin: 5mm;
    }

    body {
        background-color: white;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
        zoom: 0.65;
    }

    /* Hide Sidebar, Buttons, and unnecessary elements */
    .sidebar,
    .sidebar-overlay,
    #dash-btn-filters,
    #dash-btn-pdf,
    .btn-close,
    .offcanvas,
    .offcanvas-backdrop {
        display: none !important;
    }

    /* Reset Content Margins */
    .content,
    .content.collapsed {
        margin-left: 0 !important;
        padding: 0 !important;
        width: 100% !important;
        min-height: auto !important;
    }

    /* Adjust Layout for Print */
    .container-fluid {
        padding: 0 !important;
        max-width: 100% !important;
    }

    /* Force Grid System for Print */
    .row {
        display: flex !important;
        flex-wrap: wrap !important;
        margin-right: 0 !important;
        margin-left: 0 !important;
    }

    /* Default to full width */
    .col-12 {
        flex: 0 0 100% !important;
        max-width: 100% !important;
        width: 100% !important;
        padding-right: 5px !important;
        padding-left: 5px !important;
    }

    /* Cards: 4 per row on PC (md-3), force 2 per row (50%) for print readability */
    .col-md-3 {
        flex: 0 0 50% !important;
        max-width: 50% !important;
        width: 50% !important;
    }

    /* Charts: 2 per row on PC (lg-6/md-6), force 2 per row (50%) for print */
    .col-lg-6,
    .col-md-6 {
        flex: 0 0 50% !important;
        max-width: 50% !important;
        width: 50% !important;
    }

    /* Specific override for full width charts if any (like Ranking por Familia) */
    /* If it has only col-12 and no md/lg specific class, it stays 100% from .col-12 rule above */

    /* Compact Cards */
    .card {
        break-inside: avoid;
        page-break-inside: avoid;
        border: 1px solid #eee !important;
        box-shadow: none !important;
        margin-bottom: 10px !important;
    }

    .card-header {
        padding: 5px 10px !important;
        background-color: #f8f9fa !important;
    }

    .card-body {
        padding: 5px !important;
    }

    /* Adjust Graph Heights for Print */
    .js-plotly-plot {
        height: auto !important;
        max-height: 300px !important;
    }

    /* Ensure text is readable */
    h2,
    h3,
    h4,
    h5,
    h6 {
        color: #000 !important;
    }
}
}

/* KPI Card Styles */
.card-body-kpi {
    display: flex;
    flex-direction: column;
    height: 100%;
    justify-content: space-between;
}

.kpi-content-container {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    flex-grow: 1;
}

/* Novo wrapper que envolve o número grande e os badges */
.kpi-value-wrapper {
    display: flex;
    flex-direction: column;
    justify-content: center;
    /* Centraliza verticalmente o número e os badges de comparação */
    flex-grow: 1;
    /* Garante que ocupe o espaço para centralização */
}

/* Additional Print Styles */
@media print {

    /* Force KPI Cards to be in one line (5 cards -> 20%) */
    .kpi-row>.col {
        flex: 0 0 20% !important;
        max-width: 20% !important;
        width: 20% !important;
    }
}