/* MODO CLARO (Light Mode - Padrão) */
:root,
[data-bs-theme="light"] {

    /* Focus Ring */
    --bs-focus-ring-color: rgba(var(--bs-primary-rgb), 0.25);

    /* Fundo e Superfícies (Light) */
    --bs-body-bg: #f5f6f8;
    --bs-body-bg-rgb: 245, 246, 248;
    --bs-body-color: #212529;

    /* Superfícies Customizadas (Cards, Header, Search) */
    --my-surface-bg: #ffffff;
    --my-search-bg: color-mix(in srgb, var(--bs-body-color) 4%, transparent);

    /* Dimensões Layout Geral */
    --bento-border-radius: 16px;
    --kpi-border-radius: 16px;
    --sidebar-width: 280px;
    --topbar-height: 80px;
    --chart-placeholder-min-height: 320px;

    /* Sombras Elevadas Claras */
    --soft-elevation: 0 6px 24px rgba(0, 0, 0, 0.04);
    --hover-elevation: 0 12px 32px rgba(0, 0, 0, 0.08);
    --bento-border-color: transparent;

    /* Bordas translúcidas */
    --bs-border-color-translucent: rgba(0, 0, 0, 0.1);

    .btn-light {
        --bs-btn-color: var(--bs-primary);
        --bs-btn-bg: var(--bs-secondary-bg-subtle);
        /* Cor de fundo personalizada */
        --bs-btn-border-color: var(--bs-secondary-bg-subtle);
        --bs-btn-hover-color: var(--bs-primary);
        --bs-btn-hover-bg: var(--bs-secondary-bg-subtle);
        --bs-btn-hover-border-color: var(--bs-secondary-bg-subtle);
        --bs-btn-focus-shadow-rgb: 111, 66, 193;
        /* Sombra ao clicar */
    }

    .btn-dark {
        --bs-btn-color: var(--bs-primary);
        --bs-btn-bg: var(--bs-primary-bg-subtle);
        /* Cor de fundo personalizada */
        --bs-btn-border-color: var(--bs-primary-bg-subtle);
        --bs-btn-hover-color: var(--bs-primary);
        --bs-btn-hover-bg: var(--bs-primary-bg-subtle);
        --bs-btn-hover-border-color: var(--bs-primary-bg-subtle);
        --bs-btn-focus-shadow-rgb: 111, 66, 193;
        /* Sombra ao clicar */
    }

    .btn-secondary {
        --bs-btn-color: var(--bs-primary);
        --bs-btn-bg: var(--bs-primary-bg-subtle);
        /* Cor de fundo personalizada */
        --bs-btn-border-color: var(--bs-primary-bg-subtle);
        --bs-btn-hover-color: var(--bs-primary);
        --bs-btn-hover-bg: var(--bs-primary-bg-subtle);
        --bs-btn-hover-border-color: var(--bs-primary-bg-subtle);
        --bs-btn-focus-shadow-rgb: 111, 66, 193;
        /* Sombra ao clicar */
    }

    .btn-secondary:focus,
    .btn-secondary:active {
        --bs-btn-color: var(--bs-light);
        --bs-btn-bg: var(--bs-primary);
        /* Cor de fundo personalizada */
        --bs-btn-border-color: var(--bs-primary);
        --bs-btn-hover-color: var(--bs-light);
        --bs-btn-hover-bg: var(--bs-primary);
        --bs-btn-hover-border-color: var(--bs-primary);
        --bs-btn-focus-shadow-rgb: 111, 66, 193;
        /* Sombra ao clicar */
    }

    .bg-gradient-custom {
        background: linear-gradient(135deg, var(--bs-primary) 0%, var(--bs-secondary) 100%);
    }

    .pagination {
        --bs-pagination-color: var(--bs-primary);
        --bs-pagination-bg: var(--bs-primary-bg-subtle);
        --bs-pagination-border-color: var(--bs-primary-bg-subtle);
        --bs-pagination-hover-color: var(--bs-primary);
        --bs-pagination-hover-bg: var(--bs-primary-bg-subtle);
        --bs-pagination-hover-border-color: var(--bs-primary-bg-subtle);
        --bs-pagination-active-color: var(--bs-white);
        --bs-pagination-active-bg: var(--bs-primary);
        --bs-pagination-active-border-color: var(--bs-primary);
        --bs-pagination-active-box-shadow: none;
    }

    .form-check-input:checked {
        background-color: var(--bs-primary);
        border-color: var(--bs-primary);
    }

}

/* MODO ESCURO (Dark Mode) */
[data-bs-theme="dark"] {

    /* Injeção global */
    --bs-primary: var(--bs-primary);
    --bs-primary-rgb: var(--bs-primary-rgb);

    /* Elementos sutis adaptados */
    --bs-primary-bg-subtle: color-mix(in srgb, var(--bs-light) 15%, transparent);
    --bs-primary-border-subtle: color-mix(in srgb, var(--bs-light) 30%, transparent);
    --bs-primary-text-emphasis: color-mix(in srgb, var(--bs-light) 90%, white);

    /* Links */
    --bs-link-color: var(--bs-primary);
    --bs-link-color-rgb: var(--bs-primary-rgb);
    --bs-link-hover-color: color-mix(in srgb, var(--bs-light) 80%, white);

    /* Fundo e Superfícies (Dark) */
    --bs-body-bg: #111317;
    --bs-body-bg-rgb: 17, 19, 23;
    --bs-body-color: #e0e0e0;

    /* Superfícies Customizadas (Cards, Header, Search) */
    --my-surface-bg: #1a1d24;
    --my-search-bg: #21252d;

    /* Sombras Elevadas Escuras (Opacidade maior) */
    --soft-elevation: 0 8px 30px rgba(0, 0, 0, 0.4);
    --hover-elevation: 0 14px 40px rgba(0, 0, 0, 0.6);

    /* Bordas translúcidas */
    --bs-border-color-translucent: rgba(255, 255, 255, 0.1);
    --bento-border-color: var(--bs-border-color-translucent);

    .bg-gradient-custom {
        background: linear-gradient(135deg, var(--bs-gray-600) 0%, var(--bs-gray-900) 100%);
    }

    .btn-light {
        --bs-btn-color: #e0e0e0;
        --bs-btn-bg: var(--bs-primary-bg-subtle);
        /* Cor de fundo personalizada */
        --bs-btn-border-color: var(--bs-primary-bg-subtle);
        --bs-btn-hover-color: #e0e0e0;
        --bs-btn-hover-bg: var(--bs-primary-bg-subtle);
        --bs-btn-hover-border-color: var(--bs-primary-bg-subtle);
        --bs-btn-focus-shadow-rgb: 111, 66, 193;
        /* Sombra ao clicar */
    }

    .btn-dark {
        --bs-btn-color: #e0e0e0;
        --bs-btn-bg: var(--bs-primary-bg-subtle);
        /* Cor de fundo personalizada */
        --bs-btn-border-color: var(--bs-primary-bg-subtle);
        --bs-btn-hover-color: #e0e0e0;
        --bs-btn-hover-bg: var(--bs-primary-bg-subtle);
        --bs-btn-hover-border-color: var(--bs-primary-bg-subtle);
        --bs-btn-focus-shadow-rgb: 111, 66, 193;
        /* Sombra ao clicar */
    }

    .btn-secondary {
        --bs-btn-color: #e0e0e0;
        --bs-btn-bg: var(--bs-primary-bg-subtle);
        /* Cor de fundo personalizada */
        --bs-btn-border-color: var(--bs-primary-bg-subtle);
        --bs-btn-hover-color: #e0e0e0;
        --bs-btn-hover-bg: var(--bs-primary-bg-subtle);
        --bs-btn-hover-border-color: var(--bs-primary-bg-subtle);
        --bs-btn-focus-shadow-rgb: 111, 66, 193;
        /* Sombra ao clicar */
    }

    .form-check-input:checked {
        background-color: var(--bs-secondary);
        border-color: var(--bs-secondary);
    }

}

/* Hide elements with class 'hide-in-dark' when the theme is dark */
html[data-bs-theme="dark"] .hide-in-dark {
    display: none !important;
}

/* Hide elements with class 'hide-in-light' when the theme is light */
html[data-bs-theme="light"] .hide-in-light {
    display: none !important;
}

.nav-item {
    width: 100% !important;
}

/* --------------------------------------------------------------------------
   2. REESCRITA DE COMPONENTES E MISTURA (Color-Mix)
   -------------------------------------------------------------------------- */

.form-control,
.form-select {
    border-width: 2px;
    padding: 10px 12px;
}

.form-control:focus,
.form-select:focus {
    box-shadow: none !important;
}

.form-control,
.form-select {
    border-width: 2px;
    padding: 10px 12px;
}

/* Inputs de Formulário (Anel de Foco Inteligente) */
.form-control:focus,
.form-select:focus {
    border-color: color-mix(in srgb, var(--bs-primary) 50%, transparent);
    box-shadow: 0 0 0 0.25rem var(--bs-focus-ring-color);
}

/* Base Components Injection (Cards, Search, Chart) */
.card-bento,
.card-kpi {
    background-color: var(--my-surface-bg);
}

[data-bs-theme="dark"] .chart-placeholder {
    background-color: rgba(255, 255, 255, 0.02) !important;
    border-color: rgba(255, 255, 255, 0.1) !important;
}

/* -----------------------------------------------------
   4. TIPOGRAFIA & BASE
   ----------------------------------------------------- */
body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Elementos Utilitários de Cursor */
.cursor-pointer {
    cursor: pointer;
}

/* -----------------------------------------------------
   5. LAYOUT PRINCIPAL (SIDEBAR + MAIN)
   ----------------------------------------------------- */

.sidebar-brand {
    height: var(--topbar-height);
    /* Adicionar um sutil outline border inferior, evitando shadow dura */
    border-bottom: 1px solid var(--bs-border-color-translucent);
}

/* Ajustes da main-content para desktop (reservar espaço da sidebar) */
@media (min-width: 992px) {
    .sidebar {
        width: var(--sidebar-width) !important;
        position: fixed;
        top: 0;
        bottom: 0;
        left: 0;
        z-index: 1045;
        border-right: 1px solid var(--bs-border-color-translucent);
        transition: transform 0.3s ease-in-out;
    }

    .sidebar-brand {
        height: var(--topbar-height);
        /* Mesma altura da topbar para alinhar a grade mental */
    }

    .main-content {
        margin-left: var(--sidebar-width);
        min-height: 100vh;
        display: flex;
        flex-direction: column;
        transition: margin-left 0.3s ease-in-out;
    }
}

/* Estado de Sidebar Colapsada (Desktop) */
.sidebar-logo-collapsed {
    display: none;
}

@media (min-width: 992px) {
    body.sidebar-collapsed .sidebar {
        width: 88px !important;
    }

    body.sidebar-collapsed .main-content {
        margin-left: 88px !important;
    }

    body.sidebar-collapsed .sidebar-brand span,
    body.sidebar-collapsed .sidebar-logo-expanded,
    body.sidebar-collapsed .nav-item>span.text-muted,
    body.sidebar-collapsed .nav-link span {
        display: none !important;
    }

    body.sidebar-collapsed .sidebar-logo-collapsed {
        display: block !important;
    }

    body.sidebar-collapsed .sidebar-brand {
        padding: 1.5rem 0 !important;
        justify-content: center;
    }

    body.sidebar-collapsed .sidebar-brand i {
        margin-right: 0 !important;
    }

    body.sidebar-collapsed .nav-link {
        justify-content: center;
        padding: 1rem !important;
    }

    body.sidebar-collapsed .nav-link i {
        margin-right: 0 !important;
        font-size: 1.3rem;
    }
}

/* Remover borda do Offcanvas native */
.offcanvas {
    border: none;
}

/* Efeito Hover nas Opções de Menu Lateral */
.nav-link {
    transition: all 0.2s ease-in-out;
}

.nav-link:hover,
.nav-link.active {
    background-color: var(--bs-primary-bg-subtle) !important;
    color: var(--bs-primary) !important;
}

.nav-link.active {
    font-weight: 600;
}

/* -----------------------------------------------------
   6. TOPBAR
   ----------------------------------------------------- */
.topbar {
    height: var(--topbar-height);
    z-index: 1020;
    /* Adicionar um sutil outline border inferior, evitando shadow dura */
    border-bottom: 1px solid var(--bs-border-color-translucent);
}


/* Ícones transparentes na topbar */
.topbar .btn-link {
    transition: color 0.15s ease;
}

.topbar .btn-link:focus,
.topbar .btn-link:active {
    box-shadow: none !important;
    outline: none !important;
}

/* -----------------------------------------------------
   7. CARDS BENTO & KPI
   ----------------------------------------------------- */
.card-bento,
.card-kpi {
    border-radius: var(--bento-border-radius);
    box-shadow: var(--soft-elevation);
    transition: transform 0.25s cubic-bezier(0.0, 0.0, 0.2, 1), box-shadow 0.25s cubic-bezier(0.0, 0.0, 0.2, 1);
    /* No Modo Claro a borda é nula, no Escuro ela possui stroke fino dependente da var --bento-border-color */
    border: 1px solid var(--bento-border-color);
}

/* Micro-Interação: Pequeno Float nos KPIs */
.card-kpi:hover {
    transform: translateY(-4px);
    box-shadow: var(--hover-elevation);
}

/* Formato Flexível do Ícone no KPI */
.kpi-icon {
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    /* Super arredondado */
    font-size: 1.3rem;
}

/* Área central pontilhada do Gráfico */
.chart-placeholder {
    min-height: var(--chart-placeholder-min-height);
    border-width: 2px !important;
}

/* -----------------------------------------------------
   8. COMPONENTE: TABELA LIMPA
   ----------------------------------------------------- */
.custom-table {
    --bs-table-bg: transparent;
}

.custom-table th,
.custom-table td {
    padding: 1.2rem 0.5rem;
    vertical-align: middle;
    background-color: transparent !important;
}

/* Mantém as divisórias horizontais limpas e suaves */
.custom-table> :not(caption)>*>* {
    border-bottom-width: 1px;
    border-bottom-color: var(--bs-border-color-translucent);
    box-shadow: none !important;
}

/* Remove a linha da última fileira para ficar mais clean e contido no card */
.custom-table> :last-child> :last-child>* {
    border-bottom: 0px !important;
}

/* Removemos a borda superior do thead padrão do bootstrap se ele estiver colado */
.custom-table>thead {
    border-top: none;
}

/* A tabela terá hover background sem sombrear a border */
.table-hover>tbody>tr:hover>* {
    --bs-table-bg-state: rgba(var(--bs-black-rgb), 0.02);
}

[data-bs-theme="dark"] .table-hover>tbody>tr:hover>* {
    --bs-table-bg-state: rgba(var(--bs-white-rgb), 0.025);
}

/* -----------------------------------------------------
   9. PAGE LOADER
   ----------------------------------------------------- */
.page-loader {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: var(--bs-body-bg);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    transition: opacity 0.4s ease-out, visibility 0.4s ease-out;
}

.page-loader.fade-out {
    opacity: 0;
    visibility: hidden;
}

/* -----------------------------------------------------
   10. FOOTER
   ----------------------------------------------------- */
.custom-footer {
    border-top: 1px solid var(--bs-border-color-translucent);
}

/* -----------------------------------------------------
   11. CUSTOMIZAÇÃO SCROLLBAR (Opcional Moderno)
   ----------------------------------------------------- */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(136, 136, 136, 0.3);
    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(136, 136, 136, 0.5);
}