/* ============================================
   CORREÇÕES CRÍTICAS PARA LAYOUT DESKTOP
   Força o layout desktop mesmo com outros CSS
   IMPORTANTE: Este arquivo deve ser carregado POR ÚLTIMO
   ============================================ */

/* Desktop - FORÇAR layout correto com prioridade máxima */
@media screen and (min-width: 993px) {
    /* Main wrapper - CRÍTICO */
    .main-wrapper {
        margin-left: 260px !important;
        transition: margin-left 0.3s ease !important;
        width: calc(100% - 260px) !important;
    }
    
    .main-wrapper.sidebar-collapsed {
        margin-left: 72px !important;
        width: calc(100% - 72px) !important;
    }
    
    /* Sidebar - CRÍTICO */
    .sidebar {
        position: fixed !important;
        left: 0 !important;
        top: 0 !important;
        height: 100vh !important;
        width: 260px !important;
        z-index: 1000 !important;
        transform: translateX(0) !important;
        display: block !important;
    }
    
    .sidebar.collapsed {
        width: 72px !important;
    }
    
    .sidebar.show {
        transform: translateX(0) !important;
    }
    
    /* Conteúdo principal */
    .main-content {
        padding: 1.25rem !important;
        max-width: 100% !important;
        width: 100% !important;
    }
    
    /* Esconder botão mobile */
    .mobile-menu-btn {
        display: none !important;
    }
    
    /* Mostrar toggle desktop */
    .sidebar-toggle {
        display: flex !important;
    }
    
    /* Topbar */
    .topbar {
        position: sticky !important;
        top: 0 !important;
        z-index: 100 !important;
        width: 100% !important;
    }
    
    /* Garantir que body não tenha overflow horizontal */
    body {
        overflow-x: hidden !important;
    }
}

/* Garantir que Bootstrap funcione mesmo se CDN falhar */
.container,
.container-fluid {
    width: 100%;
    padding-right: 15px;
    padding-left: 15px;
    margin-right: auto;
    margin-left: auto;
}

.row {
    display: flex;
    flex-wrap: wrap;
    margin-right: -15px;
    margin-left: -15px;
}

.col,
[class*="col-"] {
    flex: 1 0 0%;
    padding-right: 15px;
    padding-left: 15px;
}

/* Garantir que tabelas funcionem */
.table {
    width: 100%;
    margin-bottom: 1rem;
    color: #212529;
    border-collapse: collapse;
}

.table thead th {
    vertical-align: bottom;
    border-bottom: 2px solid #dee2e6;
    padding: 0.75rem;
    text-align: left;
}

.table tbody td {
    padding: 0.75rem;
    vertical-align: top;
    border-top: 1px solid #dee2e6;
}

.table-hover tbody tr:hover {
    background-color: rgba(0, 0, 0, 0.075);
}

/* Garantir que cards funcionem */
.card {
    position: relative;
    display: flex;
    flex-direction: column;
    min-width: 0;
    word-wrap: break-word;
    background-color: #fff;
    background-clip: border-box;
    border: 1px solid rgba(0, 0, 0, 0.125);
    border-radius: 0.25rem;
}

.card-body {
    flex: 1 1 auto;
    padding: 1rem;
}

.card-header {
    padding: 0.5rem 1rem;
    margin-bottom: 0;
    background-color: rgba(0, 0, 0, 0.03);
    border-bottom: 1px solid rgba(0, 0, 0, 0.125);
}

/* Garantir que botões funcionem */
.btn {
    display: inline-block;
    font-weight: 400;
    line-height: 1.5;
    color: #212529;
    text-align: center;
    text-decoration: none;
    vertical-align: middle;
    cursor: pointer;
    user-select: none;
    background-color: transparent;
    border: 1px solid transparent;
    padding: 0.375rem 0.75rem;
    font-size: 1rem;
    border-radius: 0.25rem;
    transition: color 0.15s ease-in-out, background-color 0.15s ease-in-out, border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}

.btn-primary {
    color: #fff;
    background-color: #0d6efd;
    border-color: #0d6efd;
}

.btn-primary:hover {
    color: #fff;
    background-color: #0b5ed7;
    border-color: #0a58ca;
}

.btn-secondary {
    color: #fff;
    background-color: #6c757d;
    border-color: #6c757d;
}

.btn-secondary:hover {
    color: #fff;
    background-color: #5c636a;
    border-color: #565e64;
}

.btn-outline-primary {
    color: #0d6efd;
    border-color: #0d6efd;
}

.btn-outline-primary:hover {
    color: #fff;
    background-color: #0d6efd;
    border-color: #0d6efd;
}

.btn-outline-secondary {
    color: #6c757d;
    border-color: #6c757d;
}

.btn-outline-secondary:hover {
    color: #fff;
    background-color: #6c757d;
    border-color: #6c757d;
}

.btn-sm {
    padding: 0.25rem 0.5rem;
    font-size: 0.875rem;
    border-radius: 0.2rem;
}

/* Garantir que badges funcionem */
.badge {
    display: inline-block;
    padding: 0.35em 0.65em;
    font-size: 0.75em;
    font-weight: 700;
    line-height: 1;
    color: #fff;
    text-align: center;
    white-space: nowrap;
    vertical-align: baseline;
    border-radius: 0.25rem;
}

.bg-success {
    background-color: #198754 !important;
}

.bg-secondary {
    background-color: #6c757d !important;
}

/* Garantir que formulários funcionem */
.form-control {
    display: block;
    width: 100%;
    padding: 0.375rem 0.75rem;
    font-size: 1rem;
    font-weight: 400;
    line-height: 1.5;
    color: #212529;
    background-color: #fff;
    background-image: none;
    border: 1px solid #ced4da;
    border-radius: 0.25rem;
    transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}

.form-select {
    display: block;
    width: 100%;
    padding: 0.375rem 2.25rem 0.375rem 0.75rem;
    font-size: 1rem;
    font-weight: 400;
    line-height: 1.5;
    color: #212529;
    background-color: #fff;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23343a40' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M2 5l6 6 6-6'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    background-size: 16px 12px;
    border: 1px solid #ced4da;
    border-radius: 0.25rem;
    transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}

/* Garantir que modais funcionem */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 1055;
    display: none;
    width: 100%;
    height: 100%;
    overflow-x: hidden;
    overflow-y: auto;
    outline: 0;
}

.modal.show {
    display: block;
}

.modal-dialog {
    position: relative;
    width: auto;
    margin: 0.5rem;
    pointer-events: none;
}

.modal-content {
    position: relative;
    display: flex;
    flex-direction: column;
    width: 100%;
    pointer-events: auto;
    background-color: #fff;
    background-clip: padding-box;
    border: 1px solid rgba(0, 0, 0, 0.2);
    border-radius: 0.3rem;
    outline: 0;
}

.modal-header {
    display: flex;
    flex-shrink: 0;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1rem;
    border-bottom: 1px solid #dee2e6;
    border-top-left-radius: calc(0.3rem - 1px);
    border-top-right-radius: calc(0.3rem - 1px);
}

.modal-body {
    position: relative;
    flex: 1 1 auto;
    padding: 1rem;
}

.modal-footer {
    display: flex;
    flex-wrap: wrap;
    flex-shrink: 0;
    align-items: center;
    justify-content: flex-end;
    padding: 0.75rem;
    border-top: 1px solid #dee2e6;
    border-bottom-right-radius: calc(0.3rem - 1px);
    border-bottom-left-radius: calc(0.3rem - 1px);
}

/* Garantir que topbar funcione */
.topbar {
    position: sticky !important;
    top: 0 !important;
    z-index: 100 !important;
    background: #ffffff !important;
    border-bottom: 1px solid #e5e5e5 !important;
}

/* Garantir que ícones Bootstrap sejam exibidos */
.bi,
[class^="bi-"],
[class*=" bi-"] {
    display: inline-block !important;
    font-family: "bootstrap-icons" !important;
    font-style: normal !important;
    font-weight: normal !important;
    font-variant: normal !important;
    text-transform: none !important;
    line-height: 1 !important;
    vertical-align: -.125em !important;
    -webkit-font-smoothing: antialiased !important;
    -moz-osx-font-smoothing: grayscale !important;
    font-size: 1em !important;
    visibility: visible !important;
    opacity: 1 !important;
}

/* Fallback para ícones mais comuns se a fonte não carregar */
.bi::before {
    display: inline-block;
}

/* Se a fonte bootstrap-icons não estiver disponível, usar fallback Unicode */
@supports not (font-family: "bootstrap-icons") {
    .bi-check::before { content: "✓"; font-family: sans-serif; }
    .bi-x::before { content: "✕"; font-family: sans-serif; }
    .bi-pencil::before { content: "✎"; font-family: sans-serif; }
    .bi-trash::before { content: "🗑"; font-family: sans-serif; }
    .bi-eye::before { content: "👁"; font-family: sans-serif; }
    .bi-plus::before { content: "+"; font-family: sans-serif; }
    .bi-dash::before { content: "−"; font-family: sans-serif; }
    .bi-chevron-left::before { content: "‹"; font-family: sans-serif; }
    .bi-chevron-right::before { content: "›"; font-family: sans-serif; }
    .bi-chevron-down::before { content: "▼"; font-family: sans-serif; }
    .bi-chevron-up::before { content: "▲"; font-family: sans-serif; }
    .bi-calendar3::before { content: "📅"; font-family: sans-serif; }
    .bi-list-ul::before { content: "☰"; font-family: sans-serif; }
    .bi-people::before { content: "👥"; font-family: sans-serif; }
    .bi-bug::before { content: "🐛"; font-family: sans-serif; }
    .bi-bell::before { content: "🔔"; font-family: sans-serif; }
    .bi-envelope::before { content: "✉"; font-family: sans-serif; }
    .bi-telephone::before { content: "☎"; font-family: sans-serif; }
    .bi-card-text::before { content: "🆔"; font-family: sans-serif; }
    .bi-box-arrow-right::before { content: "→"; font-family: sans-serif; }
    .bi-list::before { content: "☰"; font-family: sans-serif; }
    .bi-check-square::before { content: "☑"; font-family: sans-serif; }
}

/* Garantir que sidebar e tabelas funcionem no desktop */
@media screen and (min-width: 993px) {
    body {
        overflow-x: hidden !important;
    }
    
    .sidebar {
        transform: translateX(0) !important;
        position: fixed !important;
        left: 0 !important;
    }
    
    .sidebar.show {
        transform: translateX(0) !important;
    }
    
    /* FORÇAR que tabelas usem layout desktop, não mobile */
    .table-modern,
    .table,
    table.table {
        display: table !important;
        width: 100% !important;
    }
    
    .table-modern thead,
    .table thead,
    table.table thead {
        display: table-header-group !important;
    }
    
    .table-modern tbody,
    .table tbody,
    table.table tbody {
        display: table-row-group !important;
    }
    
    .table-modern tr,
    .table tr,
    table.table tr {
        display: table-row !important;
        width: auto !important;
    }
    
    .table-modern td,
    .table-modern th,
    .table td,
    .table th,
    table.table td,
    table.table th {
        display: table-cell !important;
        width: auto !important;
        padding: 0.75rem !important;
        border: 1px solid #dee2e6 !important;
    }
    
    .table-modern td::before,
    .table td::before {
        display: none !important;
        content: none !important;
    }
    
    /* Garantir que cards não usem layout mobile */
    .row {
        display: flex !important;
        flex-wrap: wrap !important;
    }
    
    .row > [class*="col-"] {
        display: block !important;
    }
}
