@import 'bootstrap/dist/css/bootstrap.min.css';
@import 'bootstrap-icons/font/bootstrap-icons.css';

.ajax-loading {
    opacity: 0.65;
    pointer-events: none;
    transition: opacity 0.15s ease-in-out;
}

/* ============================================
   VARIÁVEIS E CONFIGURAÇÕES GLOBAIS
   ============================================ */
:root {
    --sidebar-width: 200px;
    --sidebar-width-collapsed: 60px;
    --topbar-height: 45px;
    --transition-speed: 0.3s;
    --border-radius: 0.5rem;
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.15);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.2);
}

/* ============================================
   RESET E BASE
   ============================================ */
* {
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    margin: 0;
    padding: 0;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Permitir scroll horizontal em mobile */
@media (max-width: 768px) {
    body {
        overflow-x: auto !important;
    }
}

/* Permitir scroll horizontal em mobile quando necessário - PRIORIDADE MÁXIMA */
@media (max-width: 768px) {
    html {
        overflow-x: auto !important;
        overflow-y: auto !important;
        touch-action: pan-x pan-y !important;
        -webkit-overflow-scrolling: touch !important;
        position: relative;
        width: 100%;
        max-width: 100vw;
        /* Forçar scroll */
        -ms-overflow-style: -ms-autohiding-scrollbar !important;
    }
    
    body,
    body.auth-layout {
        overflow-x: auto !important;
        overflow-y: auto !important;
        touch-action: pan-x pan-y !important;
        -webkit-overflow-scrolling: touch !important;
        position: relative;
        width: 100%;
        max-width: 100vw;
        margin: 0;
        padding: 0;
        /* Forçar scroll */
        -ms-overflow-style: -ms-autohiding-scrollbar !important;
    }
    
    /* REMOVER qualquer bloqueio de scroll em elementos principais */
    * {
        -webkit-overflow-scrolling: touch;
    }
    
    /* FORÇAR que table-responsive SEMPRE tenha scroll */
    .table-responsive {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
        touch-action: pan-x pan-y !important;
        display: block !important;
        width: 100% !important;
        max-width: 100vw !important;
    }
}

body.auth-layout {
    padding-left: 0;
}

/* ============================================
   COMPONENTES GLOBAIS
   ============================================ */
.card {
    box-shadow: var(--shadow-sm);
    border: none;
    border-radius: var(--border-radius);
    transition: transform 0.2s, box-shadow 0.2s;
    margin-bottom: 1rem;
}

.card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.card.text-white.bg-primary-custom {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
    border: none;
}

.table-responsive {
    border-radius: 0.25rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-x pan-y;
    width: 100%;
}

/* Garantir scroll horizontal em mobile */
@media (max-width: 768px) {
    .table-responsive {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
        touch-action: pan-x pan-y !important;
        -ms-overflow-style: -ms-autohiding-scrollbar;
    }
}

/* Melhorar scroll em mobile */
.table-responsive::-webkit-scrollbar {
    height: 8px;
}

.table-responsive::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.table-responsive::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 4px;
}

.table-responsive::-webkit-scrollbar-thumb:hover {
    background: #555;
}

.btn-primary-custom {
    color: #fff;
    transition: all 0.2s;
}

.btn-primary-custom:hover {
    color: #fff;
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

/* ============================================
   SIDEBAR - DESKTOP
   ============================================ */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    width: var(--sidebar-width);
    background-color: #6b7280 !important;
    background: #6b7280 !important;
    background-image: linear-gradient(135deg, #6b7280 0%, #4b5563 100%) !important;
    color: #ffffff;
    transition: all var(--transition-speed) ease;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    border-right: 2px solid #4b5563 !important;
    box-shadow: 2px 0 8px rgba(0, 0, 0, 0.2) !important;
    overflow-y: auto;
    overflow-x: hidden;
    box-sizing: border-box;
}

.sidebar.collapsed {
    width: var(--sidebar-width-collapsed) !important;
    min-width: var(--sidebar-width-collapsed) !important;
    max-width: var(--sidebar-width-collapsed) !important;
}

.sidebar-header {
    padding: 0.4rem 0.6rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid #4b5563 !important;
    background-color: rgba(107, 114, 128, 0.9) !important;
    backdrop-filter: blur(10px);
    min-height: var(--topbar-height);
}

.sidebar-title {
    margin: 0;
    font-weight: 600;
    font-size: 0.75rem;
    white-space: nowrap;
    overflow: hidden;
    color: #ffffff;
}

.sidebar.collapsed .sidebar-title {
    display: none;
}

.sidebar-toggle {
    color: rgba(255, 255, 255, 0.9);
    padding: 0.2rem 0.4rem;
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 0.9rem;
    text-decoration: none;
    border-radius: 0.2rem;
    transition: all 0.2s;
    min-width: 32px;
    min-height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sidebar.collapsed .sidebar-header {
    padding: 0.4rem 0.2rem;
    justify-content: center;
    flex-direction: column;
}

.sidebar.collapsed .sidebar-toggle {
    margin: 0.3rem auto 0;
    width: 100%;
    display: flex;
    justify-content: center;
}

.sidebar-toggle:hover {
    color: #ffffff;
    background-color: rgba(255, 255, 255, 0.2);
    text-decoration: none;
    border-radius: 4px;
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0.25rem 0;
    -webkit-overflow-scrolling: touch;
}

.sidebar-nav .nav-link {
    color: rgba(255, 255, 255, 0.9);
    padding: 0.5rem 0.6rem;
    display: flex;
    align-items: center;
    text-decoration: none;
    transition: all 0.15s;
    border-left: 3px solid transparent;
    margin: 0.02rem 0;
    font-size: 0.75rem;
    white-space: nowrap;
    border-radius: 0 4px 4px 0;
}

.sidebar-nav .nav-link:hover {
    background-color: rgba(255, 255, 255, 0.15);
    color: #ffffff;
    border-left-color: rgba(255, 255, 255, 0.5);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.sidebar-nav .nav-link.active {
    background-color: rgba(255, 255, 255, 0.25);
    color: #ffffff;
    border-left-color: #ffffff;
    font-weight: 600;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

.sidebar-nav .nav-link i {
    width: 18px;
    margin-right: 0.5rem;
    font-size: 0.85rem;
    flex-shrink: 0;
}

/* Botão Sair no Sidebar */
.sidebar-logout {
    border-top: 1px solid rgba(255, 255, 255, 0.2);
    padding-top: 0.5rem;
    margin-top: auto !important;
}

.sidebar-logout .nav-link {
    color: rgba(255, 255, 255, 0.9) !important;
    cursor: pointer;
}

.sidebar-logout .nav-link:hover {
    background-color: rgba(255, 255, 255, 0.15) !important;
    color: #ffffff !important;
}

.sidebar.collapsed .nav-text {
    display: none;
}

.sidebar.collapsed .nav-link {
    justify-content: center;
    padding: 0.5rem 0.15rem;
    margin: 0.02rem 0.1rem;
    border-radius: 0.2rem;
}

.sidebar.collapsed .nav-link i {
    margin-right: 0;
    width: auto;
    font-size: 0.9rem;
}

/* Menu Hambúrguer para Mobile */
.mobile-menu-toggle {
    display: none;
    position: fixed;
    top: 10px;
    left: 10px;
    z-index: 1001;
    background: #fff;
    border: 1px solid #dee2e6;
    border-radius: 0.25rem;
    padding: 0.5rem;
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    min-width: 44px;
    min-height: 44px;
    align-items: center;
    justify-content: center;
}

.mobile-menu-toggle:hover {
    background: #f8f9fa;
}

.mobile-menu-toggle i {
    font-size: 1.25rem;
    color: #495057;
}

/* Overlay para fechar sidebar no mobile */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
    opacity: 0;
    transition: opacity var(--transition-speed);
    /* GARANTIR que não bloqueie quando não está ativo */
    pointer-events: none;
}

.sidebar-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

/* ============================================
   TOPBAR
   ============================================ */
.topbar {
    position: fixed;
    top: 0;
    left: var(--sidebar-width);
    right: 0;
    height: var(--topbar-height);
    background-color: #6b7280 !important;
    background: #6b7280 !important;
    background-image: linear-gradient(135deg, #6b7280 0%, #4b5563 100%) !important;
    color: #ffffff;
    border-bottom: 2px solid #4b5563;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1rem;
    z-index: 998;
    transition: left var(--transition-speed) ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
}

/* Estilos para os containers do topbar */
.topbar-spacer {
    flex: 1;
}

.topbar-title-wrapper {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.topbar-icons-wrapper {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.5rem;
}

.sidebar.collapsed ~ .topbar,
.topbar.expanded {
    left: var(--sidebar-width-collapsed) !important;
}

.topbar .dropdown-toggle::after {
    margin-left: 0.4rem;
}

.topbar .dropdown-menu {
    margin-top: 0.3rem;
    border: 1px solid #dee2e6;
    box-shadow: var(--shadow-md);
    font-size: 0.85rem;
}

.topbar .dropdown-toggle {
    color: rgba(255, 255, 255, 0.9) !important;
    font-size: 0.85rem;
    padding: 0.5rem 0.75rem;
    border-radius: 0.25rem;
    transition: all 0.2s;
}

.topbar .dropdown-toggle:hover {
    color: #ffffff !important;
    background-color: rgba(255, 255, 255, 0.15);
}

/* GARANTIR DROPDOWNS CLICÁVEIS - GLOBAL (PC e Mobile) */
.topbar .dropdown,
.topbar-dropdown {
    position: relative;
    z-index: 1001;
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
}

.topbar .dropdown-toggle,
.topbar-dropdown-btn {
    pointer-events: auto !important;
    cursor: pointer !important;
    z-index: 1002;
    position: relative;
    background: transparent !important;
    border: none !important;
    color: rgba(255, 255, 255, 0.9) !important;
    font-size: 0.85rem;
    padding: 0.5rem 0.75rem;
    border-radius: 4px;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
}

.topbar-dropdown-btn:hover,
.topbar-dropdown-btn:focus {
    color: #ffffff !important;
    background-color: rgba(255, 255, 255, 0.15) !important;
    box-shadow: none !important;
}

.topbar .dropdown-menu {
    z-index: 1003;
    pointer-events: auto !important;
}

.topbar .dropdown-toggle i,
.topbar .dropdown-toggle span,
.topbar .dropdown-toggle small,
.topbar-dropdown-btn i,
.topbar-dropdown-btn span,
.topbar-dropdown-btn small {
    pointer-events: none;
}

.topbar-title {
    font-weight: 500;
    font-size: 0.85rem;
    color: #ffffff;
    flex: 1;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ============================================
   MAIN CONTENT
   ============================================ */
.main-content {
    position: relative;
    margin-left: var(--sidebar-width);
    margin-top: var(--topbar-height);
    padding: 1rem;
    transition: margin-left var(--transition-speed) ease, width var(--transition-speed) ease;
    min-height: calc(100vh - var(--topbar-height));
    background-color: #ffffff;
    width: calc(100vw - var(--sidebar-width));
    box-sizing: border-box;
    z-index: 1;
}

.main-content.expanded {
    margin-left: var(--sidebar-width-collapsed) !important;
    width: calc(100vw - var(--sidebar-width-collapsed)) !important;
}

.main-content .container-fluid {
    padding: 0.5rem 0.75rem;
    max-width: 100%;
    width: 100%;
}

/* Permitir scroll horizontal na página de horários do aluno */
.main-content .horarios-mobile-wrapper,
.main-content .horario-scroll-wrapper {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
    touch-action: pan-x pan-y !important;
}

/* ============================================
   RESPONSIVE - TABLET (768px - 1024px)
   ============================================ */
@media (max-width: 1024px) {
    .sidebar {
        width: 180px;
    }
    
    .sidebar.collapsed {
        width: 60px !important;
    }
    
    .topbar {
        left: 180px;
        padding: 0 0.75rem;
    }
    
    .topbar.expanded {
        left: 60px !important;
    }
    
    .main-content {
        margin-left: 180px;
        width: calc(100vw - 180px);
        padding: 0.75rem;
    }
    
    .main-content.expanded {
        margin-left: 60px !important;
        width: calc(100vw - 60px) !important;
    }
    
    .topbar-title {
        font-size: 0.75rem;
    }
    
    .card {
        margin-bottom: 0.75rem;
    }
}

/* ============================================
   RESPONSIVE - MOBILE (< 768px)
   ============================================ */
@media (max-width: 768px) {
    /* Permitir scroll horizontal globalmente no mobile */
    html {
        overflow-x: auto !important;
        overflow-y: auto !important;
        touch-action: pan-x pan-y !important;
        -webkit-overflow-scrolling: touch !important;
        position: relative;
        width: 100%;
        max-width: 100vw;
    }
    
    body,
    body.auth-layout {
        overflow-x: auto !important;
        overflow-y: auto !important;
        touch-action: pan-x pan-y !important;
        -webkit-overflow-scrolling: touch !important;
        position: relative;
        width: 100%;
        max-width: 100vw;
        margin: 0;
        padding: 0;
    }
    
    /* Sidebar Mobile */
    .sidebar {
        transform: translateX(-100%);
        width: 280px !important;
        box-shadow: var(--shadow-lg);
    }
    
    .sidebar.mobile-open {
        transform: translateX(0);
    }
    
    .sidebar.collapsed {
        transform: translateX(-100%);
        width: 280px !important;
    }
    
    .sidebar.collapsed.mobile-open {
        transform: translateX(0);
    }
    
    .sidebar-overlay {
        display: block;
        /* GARANTIR que não bloqueie quando não está ativo */
        pointer-events: none;
    }
    
    .sidebar-overlay.active {
        pointer-events: auto;
    }
    
    .mobile-menu-toggle {
        display: flex;
    }
    
    /* Topbar Mobile */
    .topbar {
        left: 0 !important;
        right: 0 !important;
        padding: 0 0.1rem !important;
        padding-left: 50px !important;
        padding-right: 0.1rem !important;
        height: 50px;
        overflow: visible !important;
        min-width: 100vw !important;
        max-width: 100vw !important;
        width: 100vw !important;
    }
    
    /* Ajustar layout do topbar no mobile - dar mais espaço aos ícones */
    .topbar-spacer {
        flex: 0 0 auto !important;
        min-width: 0 !important;
        width: 0 !important;
        display: none !important;
    }
    
    .topbar-title-wrapper {
        flex: 0 1 auto !important;
        min-width: 0 !important;
        max-width: calc(100% - 180px) !important;
        overflow: hidden !important;
        flex-shrink: 1 !important;
    }
    
    /* Garantir que todos os ícones apareçam no mobile */
    .topbar-icons-wrapper {
        display: flex !important;
        flex-wrap: nowrap !important;
        gap: 0.08rem !important;
        overflow: visible !important;
        min-width: 152px !important; /* 4 ícones de 38px cada */
        flex: 0 0 auto !important;
        width: auto !important;
        max-width: none !important;
        flex-shrink: 0 !important;
        position: relative !important;
        z-index: 1000 !important;
    }
    
    /* Forçar todos os ícones a aparecerem - regra muito específica */
    .topbar-icons-wrapper > *,
    .topbar > div:last-child > * {
        display: block !important;
        visibility: visible !important;
        opacity: 1 !important;
        flex-shrink: 0 !important;
    }
    
    .topbar-icons-wrapper .dropdown,
    .topbar-icons-wrapper .topbar-dropdown,
    .topbar > div:last-child .dropdown,
    .topbar > div:last-child .topbar-dropdown {
        display: block !important;
        visibility: visible !important;
        opacity: 1 !important;
        flex-shrink: 0 !important;
        width: auto !important;
        min-width: 36px !important;
    }
    
    /* Fallback para estrutura antiga */
    .topbar > div:first-child {
        flex: 0 0 auto !important;
        min-width: 0 !important;
        width: 0 !important;
        display: none !important;
    }
    
    .topbar > div:nth-child(2) {
        flex: 0 1 auto !important;
        min-width: 0 !important;
        max-width: calc(100% - 180px) !important;
        overflow: hidden !important;
        flex-shrink: 1 !important;
    }
    
    .topbar > div:last-child {
        display: flex !important;
        flex-wrap: nowrap !important;
        gap: 0.1rem !important;
        overflow: visible !important;
        min-width: 160px !important;
        flex: 0 0 auto !important;
        width: auto !important;
        max-width: none !important;
        flex-shrink: 0 !important;
    }
    
    .topbar .dropdown,
    .topbar-dropdown {
        flex-shrink: 0 !important;
        display: block !important;
        visibility: visible !important;
        opacity: 1 !important;
        width: auto !important;
        min-width: 36px !important;
        max-width: none !important;
        margin: 0 !important;
        padding: 0 !important;
    }
    
    .topbar-title {
        font-size: 0.7rem;
        text-align: left;
        margin-left: 0.5rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 100%;
    }
    
    /* Ocultar título em telas médias para dar mais espaço aos ícones */
    @media (max-width: 600px) {
        .topbar-title {
            display: none !important;
        }
        
        .topbar-title-wrapper {
            display: none !important;
            flex: 0 0 0 !important;
            width: 0 !important;
            min-width: 0 !important;
            max-width: 0 !important;
        }
        
        .topbar > div:nth-child(2) {
            display: none !important;
            flex: 0 0 0 !important;
            width: 0 !important;
        }
        
        .topbar-spacer {
            display: none !important;
            flex: 0 0 0 !important;
            width: 0 !important;
        }
        
        .topbar > div:first-child {
            display: none !important;
            flex: 0 0 0 !important;
            width: 0 !important;
        }
        
        .topbar-icons-wrapper,
        .topbar > div:last-child {
            min-width: 152px !important;
            gap: 0.08rem !important;
            flex: 1 1 auto !important;
            justify-content: flex-end !important;
        }
        
        .topbar {
            padding-right: 0.1rem !important;
        }
    }
    
    .topbar .dropdown-toggle,
    .topbar-dropdown-btn {
        font-size: 0.7rem !important;
        padding: 0.3rem 0.35rem !important;
        min-width: 36px !important;
        min-height: 36px !important;
        max-width: 36px !important;
        max-height: 36px !important;
        flex-shrink: 0 !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        visibility: visible !important;
        opacity: 1 !important;
        position: relative !important;
        z-index: 1001 !important;
    }
    
    .topbar .dropdown-toggle i,
    .topbar-dropdown-btn i {
        font-size: 1.05rem !important;
        margin: 0 !important;
        line-height: 1 !important;
        display: inline-block !important;
    }
    
    /* Main Content Mobile */
    .main-content {
        margin-left: 0 !important;
        margin-top: 50px;
        width: 100% !important;
        max-width: 100vw !important;
        padding: 0.75rem 0.5rem;
        overflow-x: auto !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
        touch-action: pan-x pan-y !important;
        position: relative;
        z-index: 10 !important;
        /* Garantir que não bloqueie elementos filhos */
        pointer-events: auto !important;
    }
    
    .main-content.expanded {
        margin-left: 0 !important;
        width: 100% !important;
        max-width: 100vw !important;
    }
    
    .main-content .container-fluid {
        padding: 0.5rem;
        overflow-x: auto !important;
        overflow-y: visible !important;
        min-width: 100%;
        width: 100%;
        max-width: 100%;
        -webkit-overflow-scrolling: touch !important;
        touch-action: pan-x pan-y !important;
    }
    
    /* Garantir que todos os elementos permitam scroll horizontal */
    .row {
        overflow-x: auto !important;
        touch-action: pan-x pan-y !important;
        width: 100%;
        -webkit-overflow-scrolling: touch !important;
    }
    
    .card {
        overflow-x: auto !important;
        touch-action: pan-x pan-y !important;
        width: 100%;
        -webkit-overflow-scrolling: touch !important;
    }
    
    .card-body {
        overflow-x: auto !important;
        touch-action: pan-x pan-y !important;
        width: 100%;
        -webkit-overflow-scrolling: touch !important;
    }
    
    /* Garantir que card-body com tabelas permita scroll */
    .card-body:has(.table-responsive),
    .card-body:has(table),
    .card-body:has(.table) {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
        touch-action: pan-x pan-y !important;
    }
    
    /* Forçar scroll horizontal em elementos com conteúdo largo */
    .table-responsive,
    table,
    .table {
        touch-action: pan-x pan-y !important;
        -webkit-overflow-scrolling: touch !important;
    }
    
    /* Garantir que nenhum elemento bloqueie scroll */
    * {
        -webkit-overflow-scrolling: touch;
    }
    
    /* Remover max-width que possa bloquear */
    .container,
    .container-fluid {
        max-width: none !important;
        width: 100% !important;
    }
    
    /* Cards Mobile */
    .card {
        margin-bottom: 0.75rem;
        border-radius: 0.375rem;
    }
    
    .card-header {
        padding: 0.75rem;
        font-size: 0.9rem;
    }
    
    .card-body {
        padding: 0.75rem;
    }
    
    /* Tabelas Mobile */
    .table {
        font-size: 0.8rem;
    }
    
    .table th,
    .table td {
        padding: 0.5rem 0.25rem;
        white-space: nowrap;
    }
    
    /* Garantir scroll horizontal em tabelas - FORÇAR - PRIORIDADE MÁXIMA */
    .table-responsive {
        overflow-x: auto !important;
        overflow-y: visible !important;
        -webkit-overflow-scrolling: touch !important;
        touch-action: pan-x pan-y !important;
        width: 100% !important;
        position: relative !important;
        -ms-overflow-style: -ms-autohiding-scrollbar !important;
        display: block !important;
        max-width: 100vw !important;
        /* Forçar scroll */
        scroll-behavior: smooth !important;
        will-change: scroll-position !important;
    }
    
    .table-wrapper,
    .horarios-mobile-wrapper,
    .horario-scroll-wrapper {
        overflow-x: auto !important;
        overflow-y: visible !important;
        -webkit-overflow-scrolling: touch !important;
        touch-action: pan-x pan-y !important;
        width: 100% !important;
        position: relative !important;
        -ms-overflow-style: -ms-autohiding-scrollbar !important;
        display: block !important;
        max-width: 100vw !important;
    }
    
    div[class*="table"],
    .border.rounded {
        overflow-x: auto !important;
        overflow-y: visible !important;
        -webkit-overflow-scrolling: touch !important;
        touch-action: pan-x pan-y !important;
        width: 100% !important;
        position: relative !important;
        -ms-overflow-style: -ms-autohiding-scrollbar !important;
        display: block !important;
        max-width: 100vw !important;
    }
    
    /* Permitir scroll em cards com tabelas - FORÇAR */
    .card .table-responsive,
    .border .table-responsive,
    .card .table-responsive table,
    .border .table-responsive table {
        overflow-x: auto !important;
        overflow-y: visible !important;
        -webkit-overflow-scrolling: touch !important;
        touch-action: pan-x pan-y !important;
    }
    
    .card .table,
    .border .table {
        min-width: 600px !important;
    }
    
    /* Tabelas devem permitir scroll horizontal */
    table,
    .table {
        min-width: 100% !important;
        width: auto !important;
        display: table !important;
        table-layout: auto !important;
    }
    
    /* Células da tabela - não quebrar linha */
    table td,
    table th,
    .table td,
    .table th {
        white-space: nowrap !important;
        min-width: 80px !important;
    }
    
    /* Remover qualquer bloqueio de scroll */
    * {
        -webkit-overflow-scrolling: touch;
    }
    
    /* Garantir que elementos com conteúdo largo possam ser rolados */
    .table-responsive > .table,
    .table-responsive > table {
        margin-bottom: 0;
    }
    
    /* Botões Mobile - GARANTIR CLICÁVEIS */
    .btn,
    button,
    a.btn,
    input[type="button"],
    input[type="submit"],
    .btn-link {
        padding: 0.5rem 0.75rem !important;
        font-size: 0.875rem !important;
        min-height: 44px !important;
        min-width: 44px !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        touch-action: manipulation !important;
        -webkit-tap-highlight-color: rgba(0, 0, 0, 0.2) !important;
        pointer-events: auto !important;
        cursor: pointer !important;
        position: relative !important;
        z-index: 10 !important;
        user-select: none !important;
        -webkit-user-select: none !important;
    }
    
    .btn-sm,
    button.btn-sm {
        padding: 0.375rem 0.5rem !important;
        font-size: 0.8rem !important;
        min-height: 44px !important;
        min-width: 44px !important;
    }
    
    /* Garantir que links dentro de botões funcionem */
    .btn a,
    button a {
        pointer-events: auto !important;
        touch-action: manipulation !important;
    }
    
    /* Formulários Mobile */
    .form-control,
    .form-select {
        font-size: 16px; /* Previne zoom no iOS */
        padding: 0.625rem 0.75rem;
        min-height: 44px;
    }
    
    .form-label {
        font-size: 0.875rem;
        margin-bottom: 0.5rem;
    }
    
    /* Grids Mobile */
    .row {
        margin-left: -0.5rem;
        margin-right: -0.5rem;
        overflow-x: visible;
    }
    
    .row > * {
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }
    
    /* Garantir que elementos com scroll horizontal funcionem */
    * {
        -webkit-overflow-scrolling: touch;
    }
    
    /* Permitir scroll horizontal em elementos específicos */
    .table,
    .table-responsive,
    .card-body,
    .container-fluid,
    .border,
    .border.rounded {
        touch-action: pan-x pan-y !important;
        -webkit-overflow-scrolling: touch !important;
    }
    
    /* FORÇAR scroll horizontal em TODAS as tabelas no mobile */
    table,
    .table {
        min-width: 600px !important;
        width: auto !important;
    }
    
    /* Garantir que elementos com tabelas permitam scroll */
    .table-responsive {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
        touch-action: pan-x pan-y !important;
        width: 100% !important;
        max-width: 100vw !important;
    }
    
    /* Seletores com :has() para navegadores modernos */
    div:has(table),
    div:has(.table) {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
        touch-action: pan-x pan-y !important;
        width: 100% !important;
        max-width: 100vw !important;
    }
    
    /* Fallback para navegadores sem suporte a :has() */
    @supports not selector(:has(*)) {
        .card-body,
        .border,
        .border.rounded,
        .container,
        .container-fluid {
            overflow-x: auto !important;
            -webkit-overflow-scrolling: touch !important;
            touch-action: pan-x pan-y !important;
        }
    }
    
    /* Garantir que botões sejam sempre clicáveis */
    .btn,
    button,
    a.btn,
    input[type="button"],
    input[type="submit"],
    .btn-link,
    a[role="button"] {
        pointer-events: auto !important;
        touch-action: manipulation !important;
        -webkit-tap-highlight-color: rgba(0, 0, 0, 0.2) !important;
        cursor: pointer !important;
        z-index: 100 !important;
        position: relative !important;
    }
    
    /* Alerts Mobile */
    .alert {
        padding: 0.75rem;
        font-size: 0.875rem;
        margin-bottom: 0.75rem;
    }
    
    /* Modals Mobile */
    .modal-dialog {
        margin: 0.5rem;
        max-width: calc(100% - 1rem);
    }
    
    .modal-content {
        border-radius: 0.5rem;
    }
    
    .modal-header {
        padding: 0.75rem 1rem;
    }
    
    .modal-body {
        padding: 1rem;
    }
    
    .modal-footer {
        padding: 0.75rem 1rem;
        flex-wrap: wrap;
        gap: 0.5rem;
    }
    
    .modal-footer .btn {
        flex: 1;
        min-width: 120px;
    }
    
    /* Dropdowns Mobile */
    .dropdown-menu {
        max-width: calc(100vw - 2rem);
        font-size: 0.875rem;
    }
    
    /* Utilitários Mobile */
    .d-flex {
        flex-wrap: wrap;
    }
    
    .gap-3 {
        gap: 0.75rem !important;
    }
    
    .gap-2 {
        gap: 0.5rem !important;
    }
    
    /* Texto Mobile */
    h1, .h1 {
        font-size: 1.5rem;
    }
    
    h2, .h2 {
        font-size: 1.25rem;
    }
    
    h3, .h3 {
        font-size: 1.1rem;
    }
    
    h4, .h4 {
        font-size: 1rem;
    }
    
    h5, .h5 {
        font-size: 0.9rem;
    }
}

/* ============================================
   RESPONSIVE - SMALL MOBILE (< 480px)
   ============================================ */
@media (max-width: 480px) {
    .sidebar {
        width: 260px !important;
    }
    
    .topbar {
        height: 48px;
        padding-left: 48px;
        padding-right: 0.15rem;
        padding-left: 48px !important;
        padding-right: 0.15rem !important;
    }
    
    /* Ajustar layout do topbar em telas muito pequenas */
    .topbar-spacer {
        display: none !important;
    }
    
    .topbar-title-wrapper {
        flex: 0 1 auto !important;
        max-width: calc(100% - 160px) !important;
        flex-shrink: 1 !important;
    }
    
    .topbar-icons-wrapper {
        flex: 0 0 auto !important;
        gap: 0.08rem !important;
        min-width: 152px !important; /* 4 ícones de 38px cada */
        flex-shrink: 0 !important;
    }
    
    /* Fallback para estrutura antiga */
    .topbar > div:first-child {
        display: none !important;
    }
    
    .topbar > div:nth-child(2) {
        flex: 0 1 auto !important;
        max-width: calc(100% - 180px) !important;
    }
    
    .topbar > div:last-child {
        flex: 0 0 auto !important;
        gap: 0.1rem !important;
        min-width: auto !important;
        flex-shrink: 0 !important;
    }
    
    .topbar-title {
        font-size: 0.65rem;
        display: none; /* Ocultar título em telas muito pequenas */
    }
    
    /* Ajustar ícones em telas muito pequenas */
    .topbar .dropdown-toggle,
    .topbar-dropdown-btn {
        min-width: 36px !important;
        min-height: 36px !important;
        padding: 0.3rem !important;
        font-size: 0.7rem !important;
    }
    
    .topbar .dropdown-toggle i,
    .topbar-dropdown-btn i {
        font-size: 1.1rem !important;
    }
    
    /* Garantir que os dropdowns não sejam cortados */
    .topbar .dropdown,
    .topbar-dropdown {
        min-width: 36px !important;
        width: auto !important;
    }
    
    .main-content {
        margin-top: 48px;
        padding: 0.5rem;
    }
    
    .main-content .container-fluid {
        padding: 0.25rem;
    }
    
    .card {
        margin-bottom: 0.5rem;
    }
    
    .card-header,
    .card-body {
        padding: 0.5rem;
    }
    
    .btn {
        width: 100%;
        margin-bottom: 0.5rem;
    }
    
    .btn-group {
        flex-direction: column;
        width: 100%;
    }
    
    .btn-group .btn {
        width: 100%;
        border-radius: 0.25rem !important;
        margin-bottom: 0.5rem;
    }
    
    .table {
        font-size: 0.75rem;
    }
    
    .table th,
    .table td {
        padding: 0.375rem 0.2rem;
    }
    
    .form-control,
    .form-select {
        font-size: 16px;
        padding: 0.5rem;
    }
    
    .modal-dialog {
        margin: 0.25rem;
        max-width: calc(100% - 0.5rem);
    }
    
    h1, .h1 {
        font-size: 1.25rem;
    }
    
    h2, .h2 {
        font-size: 1.1rem;
    }
    
    h3, .h3 {
        font-size: 1rem;
    }
    
    h4, .h4 {
        font-size: 0.9rem;
    }
}

/* ============================================
   MELHORIAS DE TOUCH
   ============================================ */
@media (hover: none) and (pointer: coarse) {
    /* Dispositivos touch */
    .btn,
    .nav-link,
    .dropdown-toggle {
        min-height: 44px;
        min-width: 44px;
    }
    
    .sidebar-nav .nav-link {
        padding: 0.75rem 0.6rem;
    }
    
    .card:hover {
        transform: none; /* Remover hover em touch */
    }
    
    .btn-primary-custom:hover {
        transform: none;
    }
}

/* ============================================
   CORREÇÕES CRÍTICAS PARA MOBILE - BOTÕES E TABELAS
   ============================================ */
@media (max-width: 768px) {
    /* GARANTIR QUE TODOS OS BOTÕES SEJAM CLICÁVEIS */
    .btn,
    button,
    a.btn,
    input[type="button"],
    input[type="submit"],
    .btn-link,
    a[role="button"],
    .dropdown-toggle,
    .nav-link,
    .btn-sm,
    /* Links que funcionam como botões */
    a[onclick],
    a[href]:not([href="#"]):not([href=""]),
    /* Elementos clicáveis */
    [onclick],
    [data-bs-toggle],
    [data-toggle] {
        pointer-events: auto !important;
        touch-action: manipulation !important;
        -webkit-tap-highlight-color: rgba(0, 0, 0, 0.2) !important;
        cursor: pointer !important;
        z-index: 1000 !important;
        position: relative !important;
        min-height: 44px !important;
        min-width: 44px !important;
        user-select: none !important;
        -webkit-user-select: none !important;
        /* Garantir que não seja bloqueado */
        -webkit-touch-callout: none !important;
        -webkit-user-drag: none !important;
    }
    
    /* Remover qualquer bloqueio de pointer-events em elementos pais */
    .card,
    .card-body,
    .container,
    .container-fluid,
    .row,
    [class*="col-"] {
        pointer-events: auto !important;
    }
    
    /* Garantir que elementos filhos de botões também funcionem */
    .btn *,
    button * {
        pointer-events: none !important;
    }
    
    .btn,
    button {
        pointer-events: auto !important;
    }
    
    /* GARANTIR SCROLL HORIZONTAL EM TODAS AS TABELAS - PRIORIDADE MÁXIMA */
    .table-responsive {
        overflow-x: auto !important;
        overflow-y: visible !important;
        -webkit-overflow-scrolling: touch !important;
        touch-action: pan-x pan-y !important;
        width: 100% !important;
        max-width: 100vw !important;
        display: block !important;
        position: relative !important;
        -ms-overflow-style: -ms-autohiding-scrollbar !important;
        /* Forçar scroll mesmo se houver conflitos */
        scroll-behavior: smooth !important;
    }
    
    /* Containers que podem ter tabelas */
    .border.rounded,
    .border,
    div[class*="table"],
    div[class*="border"] {
        overflow-x: auto !important;
        overflow-y: visible !important;
        -webkit-overflow-scrolling: touch !important;
        touch-action: pan-x pan-y !important;
        width: 100% !important;
        max-width: 100vw !important;
        display: block !important;
        position: relative !important;
        -ms-overflow-style: -ms-autohiding-scrollbar !important;
    }
    
    /* Qualquer elemento que contenha uma tabela - usar :has() */
    div:has(table),
    div:has(.table) {
        overflow-x: auto !important;
        overflow-y: visible !important;
        -webkit-overflow-scrolling: touch !important;
        touch-action: pan-x pan-y !important;
        width: 100% !important;
        max-width: 100vw !important;
    }
    
    /* Containers comuns - garantir que não bloqueiem */
    .container:has(table),
    .container:has(.table),
    .container-fluid:has(table),
    .container-fluid:has(.table),
    .row:has(table),
    .row:has(.table) {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
        touch-action: pan-x pan-y !important;
    }
    
    /* Garantir que elementos com tabelas internas permitam scroll */
    /* Usar seletores mais compatíveis */
    .card-body table,
    .border table,
    .border.rounded table,
    .table-responsive table {
        min-width: 600px !important;
    }
    
    /* Garantir que containers com tabelas permitam scroll */
    .card-body:has(table),
    .border:has(table),
    .border.rounded:has(table),
    .table-responsive:has(table) {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
        touch-action: pan-x pan-y !important;
    }
    
    /* Fallback para navegadores sem suporte a :has() */
    @supports not selector(:has(*)) {
        .card-body,
        .border,
        .border.rounded {
            overflow-x: auto !important;
            -webkit-overflow-scrolling: touch !important;
            touch-action: pan-x pan-y !important;
        }
    }
    
    /* Qualquer div que contenha uma tabela */
    .card-body table,
    .border table,
    .border.rounded table {
        min-width: 600px !important;
    }
    
    /* FORÇAR LARGURA MÍNIMA NAS TABELAS */
    table,
    .table {
        min-width: 600px !important;
        width: auto !important;
        display: table !important;
        table-layout: auto !important;
    }
    
    /* CÉLULAS NÃO QUEBRAM LINHA */
    table td,
    table th,
    .table td,
    .table th {
        white-space: nowrap !important;
        min-width: 80px !important;
    }
    
    /* REMOVER QUALQUER BLOQUEIO */
    * {
        -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
    }
    
    /* Garantir que elementos fixos não bloqueiem */
    .sidebar,
    .topbar,
    .mobile-menu-toggle {
        pointer-events: auto !important;
    }
    
    /* GARANTIR que overlay NUNCA bloqueie quando fechado */
    .sidebar-overlay {
        pointer-events: none !important;
    }
    
    .sidebar-overlay.active {
        pointer-events: auto !important;
    }
    
    /* Garantir que main-content esteja acima de elementos fixos quando necessário */
    .main-content {
        z-index: 10 !important;
    }
    
    /* Garantir que botões estejam sempre acima de TUDO */
    .btn,
    button,
    a.btn,
    input[type="button"],
    input[type="submit"],
    .btn-link,
    .dropdown-toggle {
        z-index: 10000 !important;
        position: relative !important;
    }
    
    /* Garantir que tabelas e seus containers possam receber eventos de scroll */
    .table-responsive,
    .table-wrapper,
    .horario-scroll-wrapper,
    table,
    .table {
        z-index: 5 !important;
        position: relative !important;
    }
    
    /* DROPDOWNS DA TOPBAR - GARANTIR CLICÁVEIS NO MOBILE */
    .topbar .dropdown,
    .topbar-dropdown {
        position: relative !important;
        z-index: 10001 !important;
        display: block !important;
        visibility: visible !important;
        opacity: 1 !important;
        flex-shrink: 0 !important;
        width: auto !important;
        min-width: 40px !important;
    }
    
    .topbar .dropdown-toggle,
    .topbar-dropdown-btn {
        pointer-events: auto !important;
        touch-action: manipulation !important;
        z-index: 10002 !important;
        position: relative !important;
        min-width: 40px !important;
        min-height: 40px !important;
        padding: 0.4rem 0.5rem !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        visibility: visible !important;
        opacity: 1 !important;
        width: auto !important;
        flex-shrink: 0 !important;
    }
    
    /* Ajustar ícones no mobile */
    .topbar .dropdown-toggle i,
    .topbar-dropdown-btn i {
        font-size: 1.2rem !important;
        margin: 0 !important;
        line-height: 1 !important;
    }
    
    /* Remover margem do ícone quando não há texto */
    .topbar .dropdown-toggle .me-1,
    .topbar-dropdown-btn .me-1 {
        margin-right: 0 !important;
    }
    
    /* Badges de notificação e chat no mobile */
    .topbar .badge {
        font-size: 0.6rem !important;
        padding: 0.15em 0.4em !important;
        min-width: 16px !important;
        height: 16px !important;
        line-height: 1.2 !important;
        top: 2px !important;
        right: 2px !important;
        left: auto !important;
        transform: translate(50%, -50%) !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
    }
    
    /* Ajustar dropdown menu no mobile */
    .topbar .dropdown-menu {
        min-width: 280px !important;
        max-width: 90vw !important;
        font-size: 0.85rem !important;
    }
    
    /* Ajustar espaçamento entre ícones no mobile */
    .topbar-icons-wrapper,
    .topbar > div:last-child {
        gap: 0.25rem !important;
        flex-shrink: 0 !important;
    }
    
    /* Garantir que os botões sejam bem visíveis no mobile */
    .topbar .dropdown-toggle:hover,
    .topbar-dropdown-btn:hover {
        background-color: rgba(255, 255, 255, 0.2) !important;
    }
    
    /* Ajustar tamanho do texto pequeno (idioma) no mobile */
    .topbar .dropdown-toggle small,
    .topbar-dropdown-btn small {
        font-size: 0.65rem !important;
        margin-left: 0.25rem !important;
    }
    
    /* Garantir que botões sejam clicáveis no mobile */
    .topbar .dropdown-toggle,
    .topbar-dropdown-btn {
        min-height: 44px !important;
        min-width: 44px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        padding: 0.5rem !important;
        cursor: pointer !important;
        -webkit-tap-highlight-color: rgba(0, 0, 0, 0.2) !important;
    }
    
    .topbar .dropdown-menu {
        z-index: 10003 !important;
        position: absolute !important;
    }
    
    /* Garantir que a topbar não bloqueie os dropdowns */
    .topbar {
        overflow: visible !important;
        z-index: 999 !important;
    }
    
    /* Garantir que os dropdowns apareçam acima de tudo */
    .topbar .dropdown.show .dropdown-menu {
        display: block !important;
        z-index: 10003 !important;
    }
    
    /* Ícones dentro de dropdowns não bloqueiam clique */
    .topbar .dropdown-toggle i,
    .topbar .dropdown-toggle span,
    .topbar .dropdown-toggle small {
        pointer-events: none !important;
    }
}

/* ============================================
   PAGINAÇÃO - LIMPA E RESPONSIVA
   ============================================ */
.pagination {
    flex-wrap: wrap;
    gap: 0.25rem;
    margin-bottom: 0.5rem;
}

.pagination .page-link {
    padding: 0.25rem 0.55rem;
    font-size: 0.875rem;
    line-height: 1.1;
}

@media (max-width: 576px) {
    .pagination {
        justify-content: center;
    }

    .pagination .page-link {
        padding: 0.2rem 0.45rem;
        font-size: 0.8rem;
    }
}

/* ============================================
   IMPRESSÃO
   ============================================ */
@media print {
    .sidebar,
    .topbar,
    .mobile-menu-toggle,
    .sidebar-overlay,
    .btn,
    .no-print {
        display: none !important;
    }
    
    .main-content {
        margin: 0 !important;
        padding: 0 !important;
        width: 100% !important;
    }
    
    .card {
        box-shadow: none;
        border: 1px solid #dee2e6;
        page-break-inside: avoid;
    }
}

/* ============================================
   REGRAS ESPECÍFICAS PARA TABELA MOBILE FINANCEIRO
   PRIORIDADE MÁXIMA - Sobrescrever estilos globais
   ============================================ */
@media (max-width: 768px) {
    /* Forçar que a tabela mobile de financeiro NÃO tenha scroll horizontal */
    .financeiro-mobile-table,
    .financeiro-mobile-table *,
    .financeiro-mobile-table .table-responsive,
    .financeiro-mobile-table .table,
    .financeiro-mobile-table table,
    div.financeiro-mobile-table,
    div.financeiro-mobile-table .table-responsive,
    div.financeiro-mobile-table .table,
    div.financeiro-mobile-table table {
        overflow-x: hidden !important;
        -webkit-overflow-scrolling: auto !important;
        touch-action: pan-y !important;
    }
    
    /* Garantir que não seja afetado por regras globais de table-responsive */
    .financeiro-mobile-table .table-responsive {
        overflow-x: hidden !important;
        overflow-y: visible !important;
        width: 100% !important;
        max-width: 100% !important;
        display: block !important;
        -webkit-overflow-scrolling: auto !important;
        touch-action: pan-y !important;
    }
    
    /* Garantir que a tabela não tenha scroll */
    .financeiro-mobile-table .table,
    .financeiro-mobile-table table {
        overflow-x: hidden !important;
        width: 100% !important;
        max-width: 100% !important;
        table-layout: fixed !important;
        -webkit-overflow-scrolling: auto !important;
        touch-action: pan-y !important;
    }
}
