:root {
    --primary-red: #dc3545;
    --primary-yellow: #ffc107;
    --dark-red: #c82333;
    --light-yellow: #fff3cd;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    height: 100%;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: #f5f5f5;
    min-height: 100vh;
    overflow-x: hidden;
    overflow-y: auto;
    padding-bottom: 50px; /* Espaço para o footer */
}

/* Notificações Toast */
.notification-container {
    position: fixed;
    top: 70px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.notification {
    background: white;
    border-radius: 8px;
    padding: 15px 20px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    transform: translateX(120%);
    transition: transform 0.3s ease;
    display: flex;
    align-items: center;
    min-width: 300px;
    max-width: 400px;
    border-left: 4px solid;
}

.notification.show {
    transform: translateX(0);
}

.notification-success { border-left-color: #28a745; }
.notification-error { border-left-color: #dc3545; }
.notification-warning { border-left-color: #ffc107; }
.notification-info { border-left-color: #17a2b8; }

.notification-content {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 10px;
}

.notification-close {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: #999;
    padding: 0 5px;
    flex-shrink: 0;
}

.notification-close:hover { color: #333; }

/* Loading Global */
.global-loader {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255,255,255,0.8);
    z-index: 9998;
    justify-content: center;
    align-items: center;
}

.loader-spinner {
    width: 50px;
    height: 50px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid var(--primary-red);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Modal Overlay */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    backdrop-filter: blur(3px);
    z-index: 1050;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 40px 20px;
    overflow-y: auto;
    animation: fadeIn 0.3s;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-container {
    background: white;
    border-radius: 10px;
    width: 95%;
    box-shadow: 0 10px 40px rgba(0,0,0,0.3);
    animation: slideDown 0.3s;
    display: flex;
    flex-direction: column;
    max-height: 85vh;
}

@keyframes slideDown {
    from { transform: translateY(-50px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.modal-header {
    background: linear-gradient(135deg, var(--primary-red), var(--dark-red));
    color: white;
    padding: 15px 20px;
    border-radius: 10px 10px 0 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.modal-header h3, .modal-header h4 {
    margin: 0;
    font-size: 18px;
}

.modal-close {
    background: none;
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
    padding: 0 5px;
    line-height: 1;
}

.modal-close:hover {
    opacity: 0.8;
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
}

.modal-footer {
    padding: 15px 20px;
    border-top: 1px solid #e0e0e0;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    flex-shrink: 0;
    background: white;
    border-radius: 0 0 10px 10px;
}

/* Topo Fixo */
.navbar-top {
    background: linear-gradient(135deg, var(--primary-red), var(--dark-red));
    border: none;
    border-radius: 0;
    margin-bottom: 0;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    width: 100%;
    z-index: 1030;
    height: 60px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 15px;
}

.navbar-brand {
    color: #fff !important;
    font-weight: bold;
    font-size: 20px;
    padding: 5px 15px;
    text-decoration: none;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 10px;
    height: 60px;
    white-space: nowrap;
    flex-shrink: 0;
}

.navbar-brand img {
    height: 40px;
    width: auto;
}

.navbar-brand:hover {
    color: var(--primary-yellow) !important;
}

.search-box {
    flex: 1;
    max-width: 400px;
    margin: 0 20px;
}

.search-box input {
    border-radius: 20px;
    border: none;
    padding: 8px 20px;
    width: 100%;
    height: 36px;
    font-size: 14px;
    background: rgba(255,255,255,0.15);
    color: white;
    transition: all 0.3s;
}

.search-box input::placeholder {
    color: rgba(255,255,255,0.7);
}

.search-box input:focus {
    background: rgba(255,255,255,0.25);
    outline: none;
    box-shadow: 0 0 0 2px rgba(255,193,7,0.3);
}

.navbar-right {
    display: flex;
    align-items: center;
    gap: 10px;
    color: white;
    flex-shrink: 0;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 10px;
    font-size: 14px;
}

.btn-icon {
    background: none;
    border: none;
    color: white;
    font-size: 18px;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    transition: all 0.3s;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-icon:hover {
    background: rgba(255,255,255,0.15);
    color: var(--primary-yellow);
}

/* Menu Lateral */
.sidebar {
    position: fixed;
    top: 60px;
    left: 0;
    height: calc(100vh - 100px);
    width: 60px;
    background: white;
    box-shadow: 2px 0 10px rgba(0,0,0,0.1);
    transition: width 0.3s ease;
    z-index: 1020;
    overflow-y: auto;
    overflow-x: hidden;
}

.sidebar:hover {
    width: 250px;
}

.sidebar-menu {
    list-style: none;
    padding: 0;
    margin: 0;
}

.sidebar-menu li {
    border-bottom: 1px solid #f0f0f0;
}

.sidebar-menu li a {
    display: flex;
    align-items: center;
    padding: 15px;
    color: #333;
    text-decoration: none;
    white-space: nowrap;
    transition: all 0.3s;
    cursor: pointer;
    min-height: 50px;
}

.sidebar-menu li a:hover {
    background: var(--light-yellow);
    color: var(--dark-red);
}

.sidebar-menu li a.active {
    background: var(--primary-red);
    color: white;
}

.sidebar-menu li a i {
    font-size: 20px;
    width: 30px;
    text-align: center;
    margin-right: 15px;
    flex-shrink: 0;
}

.menu-text {
    opacity: 0;
    transition: opacity 0.3s;
    white-space: nowrap;
}

.sidebar:hover .menu-text {
    opacity: 1;
}

/* Submenu */
.submenu {
    display: none;
    list-style: none;
    padding: 0;
    margin: 0;
    background: #f9f9f9;
}

.sidebar:not(:hover) .submenu {
    display: none !important;
}

.submenu li a {
    padding: 12px 15px 12px 45px;
    font-size: 13px;
}

/* ===== CONTEÚDO PRINCIPAL ===== */
.main-content {
    margin-left: 60px;
    margin-top: 60px;
    padding: 20px;
    transition: margin-left 0.3s;
    min-height: calc(100vh - 100px);
}

.content-area {
    background: white;
    border-radius: 8px;
    padding: 25px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
    /* REMOVIDO height fixo */
    overflow: visible;
}

/* Cards */
/* ============================================= */
/* PADRONIZAÇÃO DE CARDS */
/* ============================================= */

/* Container de cards em linha */
.card-row {
    display: flex;
    flex-wrap: wrap;
    margin: 0 -8px;
}

.card-row > [class*="col-"] {
    padding: 0 8px;
    margin-bottom: 16px;
    display: flex;
}

/* Card padrão */
.card {
    border: none;
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    min-height: 94px;    
}

.card:hover {
    box-shadow: 0 5px 20px rgba(0,0,0,0.1);
    transform: translateY(-2px);
}

/* Cabeçalho do card */
.card-header {
    background: linear-gradient(135deg, var(--dark-red), var(--primary-red));
    color: white;
    border-radius: 10px 10px 0 0 !important;
    padding: 12px 18px;
    font-weight: bold;
    font-size: 14px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 44px;
}

.card-header h3, .card-header h4, .card-header h5, .card-header h6 {
    margin: 0 !important;
    font-size: 14px;
}

/* Corpo do card */
.card-body {
    padding: 18px;
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

/* Cards KPI (coloridos) */
.card-kpi {
    border: none;
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.08);
    transition: all 0.3s ease;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.card-kpi:hover {
    box-shadow: 0 5px 20px rgba(0,0,0,0.15);
    transform: translateY(-3px);
}

.card-kpi .card-body {
    padding: 14px 10px;
    text-align: center;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    min-height: 85px;
}

.card-kpi h3, .card-kpi h4 {
    margin: 0 0 4px 0 !important;
    font-size: 22px;
    font-weight: bold;
    line-height: 1.2;
}

.card-kpi small {
    font-size: 11px;
    opacity: 0.9;
    line-height: 1.3;
    display: block;
}

/* Cards com cor de fundo */
.card-red { background: linear-gradient(135deg, #dc3545, #c82333) !important; color: white !important; }
.card-green { background: linear-gradient(135deg, #28a745, #218838) !important; color: white !important; }
.card-blue { background: linear-gradient(135deg, #17a2b8, #138496) !important; color: white !important; }
.card-yellow { background: linear-gradient(135deg, #ffc107, #e0a800) !important; color: #333 !important; }
.card-purple { background: linear-gradient(135deg, #6f42c1, #5a32a3) !important; color: white !important; }
.card-orange { background: linear-gradient(135deg, #fd7e14, #e06b0a) !important; color: white !important; }
.card-pink { background: linear-gradient(135deg, #e83e8c, #c8237b) !important; color: white !important; }
.card-teal { background: linear-gradient(135deg, #20c997, #17a673) !important; color: white !important; }
.card-gray { background: linear-gradient(135deg, #6c757d, #5a6268) !important; color: white !important; }

/* Cards sem padding (para tabelas) */
.card-table .card-body {
    padding: 0;
}

/* Tabela dentro de card */
.card-table .table {
    margin-bottom: 0;
}

/* Grade de cards responsiva */
@media (max-width: 768px) {
    .card-kpi h3, .card-kpi h4 {
        font-size: 18px;
    }
    .card-kpi .card-body {
        min-height: 70px;
        padding: 10px 8px;
    }
    .card-header {
        padding: 10px 14px;
        font-size: 13px;
    }
    .card-body {
        padding: 12px;
    }
}

/* ============================================= */
/* PADRONIZAÇÃO DE TABELAS */
/* ============================================= */

/* Container da tabela com altura fixa */
.table-container {
    max-height: 500px; /* Altura fixa para todas as tabelas */
    overflow-y: auto;
    overflow-x: auto;
    position: relative;
    border-radius: 8px;
    border: 1px solid #e0e0e0;
}

/* Ajuste para telas menores */
@media (max-width: 768px) {
    .table-container {
        max-height: 350px;
    }
}

@media (max-width: 480px) {
    .table-container {
        max-height: 250px;
    }
}

/* Tabela com cabeçalho fixo */
.table-fixed {
    width: 100%;
    margin-bottom: 0;
    border-collapse: separate;
    border-spacing: 0;
}

/* Cabeçalho fixo - fica colado no topo */
.table-fixed thead {
    position: sticky;
    top: 0;
    z-index: 10;
}

.table-fixed thead th {
    background: #dc3545 !important;
    color: white !important;
    padding: 10px 12px;
    font-weight: 600;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 2px solid #c82333;
    white-space: nowrap;
    position: sticky;
    top: 0;
    z-index: 11;
}

/* Células do corpo da tabela */
.table-fixed tbody td {
    padding: 8px 12px;
    vertical-align: middle;
    border-bottom: 1px solid #e9ecef;
    font-size: 13px;
}

/* Estilo alternado para linhas */
.table-fixed tbody tr:nth-child(even) {
    background-color: #f8f9fa;
}

.table-fixed tbody tr:hover {
    background-color: #fff3cd !important;
}

/* Células com texto alinhado à direita (valores) */
.table-fixed .text-right {
    text-align: right !important;
}

/* Células com texto alinhado ao centro */
.table-fixed .text-center {
    text-align: center !important;
}

/* Badge dentro da tabela */
.table-fixed .badge {
    font-size: 11px;
    padding: 3px 8px;
    border-radius: 12px;
}

/* Labels dentro da tabela */
.table-fixed .label {
    font-size: 11px;
    padding: 3px 8px;
    border-radius: 3px;
    display: inline-block;
}

/* Botões dentro da tabela */
.table-fixed .btn-xs {
    padding: 2px 6px;
    font-size: 11px;
    line-height: 1.4;
    border-radius: 3px;
}

/* Rodapé da tabela */
.table-fixed tfoot {
    position: sticky;
    bottom: 0;
    z-index: 10;
    background: #f8f9fa;
    font-weight: bold;
}

.table-fixed tfoot td {
    padding: 10px 12px;
    border-top: 2px solid #dc3545;
    background: #f8f9fa;
}

/* Scrollbar personalizada para o container da tabela */
.table-container::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

.table-container::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.table-container::-webkit-scrollbar-thumb {
    background: #dc3545;
    border-radius: 4px;
}

.table-container::-webkit-scrollbar-thumb:hover {
    background: #c82333;
}

/* ============================================= */
/* TABELA RESPONSIVA (mobile) */
/* ============================================= */

@media (max-width: 768px) {
    .table-fixed thead th {
        font-size: 11px;
        padding: 6px 8px;
    }
    
    .table-fixed tbody td {
        font-size: 11px;
        padding: 6px 8px;
    }
    
    .table-fixed .btn-xs {
        font-size: 10px;
        padding: 1px 4px;
    }
    
    .table-fixed .badge,
    .table-fixed .label {
        font-size: 10px;
        padding: 2px 6px;
    }
}

/* ============================================= */
/* TABELA DENTRO DE CARD */
/* ============================================= */

.card .table-container {
    border: none;
    border-radius: 0 0 8px 8px;
}

.card .table-fixed thead th {
    background: #dc3545 !important;
}

/* ============================================= */
/* TABELA DE DETALHES (MODAL) */
/* ============================================= */

.table-detalhes {
    width: 100%;
    margin-bottom: 0;
    border-collapse: collapse;
}

.table-detalhes th {
    width: 40%;
    background: #f8f9fa;
    padding: 8px 12px;
    font-weight: 600;
    border: 1px solid #dee2e6;
}

.table-detalhes td {
    padding: 8px 12px;
    border: 1px solid #dee2e6;
}

.table-detalhes tr:nth-child(even) {
    background-color: #f8f9fa;
}

/* ============================================= */
/* TABELA DE ITENS DA NOTA (MODAL) */
/* ============================================= */

.table-itens {
    width: 100%;
    margin-bottom: 0;
    border-collapse: collapse;
    font-size: 13px;
}

.table-itens thead th {
    background: #dc3545 !important;
    color: white !important;
    padding: 8px 10px;
    font-weight: 600;
    position: sticky;
    top: 0;
    z-index: 10;
}

.table-itens tbody td {
    padding: 6px 10px;
    border-bottom: 1px solid #e9ecef;
}

.table-itens tfoot td {
    padding: 8px 10px;
    border-top: 2px solid #dc3545;
    background: #f8f9fa;
    font-weight: bold;
}

.table-itens tbody tr:nth-child(even) {
    background-color: #f8f9fa;
}

.table-itens tbody tr:hover {
    background-color: #fff3cd !important;
}


/* Botões */
.btn {
    border-radius: 4px;
    transition: all 0.3s;
    color: #000;
}

.btn-primary {
    background: var(--primary-red);
    border-color: var(--dark-red);
}

.btn-primary:hover,
.btn-primary:focus {
    background: var(--dark-red);
    border-color: #a71d2a;
}

.btn-warning {
    background: var(--primary-yellow);
    border-color: #e0a800;
    color: #333;
}

.btn-warning:hover {
    background: #e0a800;
    border-color: #d39e00;
}

.btn-danger {
    background: #dc3545;
    border-color: #c82333;
}

.btn-success {
    background: #28a745;
    border-color: #218838;
}

.btn-info {
    background: #17a2b8;
    border-color: #138496;
}

/* Badges e Labels */
.badge {
    display: inline-block;
    padding: 3px 7px;
    font-size: 12px;
    font-weight: bold;
    border-radius: 10px;
}

.badge-danger { background: var(--primary-red); color: white; }
.badge-success { background: #28a745; color: white; }
.badge-warning { background: var(--primary-yellow); color: #333; }
.badge-info { background: #17a2b8; color: white; }
.badge-default { background: #777; color: white; }

.label {
    display: inline;
    padding: .2em .6em .3em;
    font-size: 75%;
    font-weight: bold;
    line-height: 1;
    color: white;
    text-align: center;
    white-space: nowrap;
    vertical-align: baseline;
    border-radius: .25em;
}

.label-default { background-color: #777; }
.label-danger { background-color: var(--primary-red); }
.label-info { background-color: #17a2b8; }

/* Footer */
.footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: 40px;
    background: linear-gradient(135deg, var(--dark-red), var(--primary-red));
    color: white;
    text-align: center;
    line-height: 40px;
    font-size: 12px;
    z-index: 1030;
}

/* Breadcrumb */
.breadcrumb {
    background: #f5f5f5;
    border-radius: 4px;
    padding: 8px 15px;
}

.breadcrumb > li + li:before {
    content: '› ';
    color: #999;
}

/* Alertas */
.alert {
    border-radius: 8px;
    border: none;
}

.alert-info {
    background: #d1ecf1;
    color: #0c5460;
}

.alert-warning {
    background: #fff3cd;
    color: #856404;
}

.alert-danger {
    background: #f8d7da;
    color: #721c24;
}

.alert-success {
    background: #d4edda;
    color: #155724;
}

/* Formulários */
.form-control {
    border-radius: 4px;
    border: 1px solid #ccc;
    box-shadow: inset 0 1px 1px rgba(0,0,0,.075);
}

.form-control:focus {
    border-color: var(--primary-yellow);
    box-shadow: 0 0 0 2px rgba(255,193,7,0.2);
    outline: none;
}

/* Checkbox e Radio estilizados */
.checkbox {
    margin-top: 0;
    margin-bottom: 10px;
}

.checkbox label {
    padding-left: 0;
    cursor: pointer;
}

.checkbox input[type="checkbox"] {
    margin-right: 8px;
}

@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(220, 53, 69, 0.7); }
    70% { box-shadow: 0 0 0 20px rgba(220, 53, 69, 0); }
    100% { box-shadow: 0 0 0 0 rgba(220, 53, 69, 0); }
}

/* Responsividade */
@media (max-width: 768px) {
    .navbar-brand {
        font-size: 16px;
        padding: 5px 10px;
    }
    
    .navbar-brand img {
        height: 30px;
    }
    
    .search-box {
        display: none;
    }
    
    .user-info span {
        display: none;
    }
    
    .sidebar {
        width: 50px;
    }
    
    .sidebar:hover {
        width: 200px;
    }
    
    .main-content {
        margin-left: 50px;
        padding: 10px;
    }
    
    .content-area {
        padding: 15px;
    }
    
    .modal-container {
        width: 95%;
        margin: 20px;
    }
    
    .modal-overlay {
        padding: 20px 10px;
    }
}

@media (max-width: 480px) {
    .navbar-brand {
        font-size: 14px;
    }
    
    .navbar-brand img {
        height: 25px;
    }
    
    .navbar-right {
        gap: 5px;
    }
    
    .main-content {
        margin-left: 45px;
        padding: 8px;
    }
    
    .content-area {
        padding: 10px;
        border-radius: 5px;
    }
}

/* Resultados da busca */
.search-box {
    position: relative;
}

#searchResults {
    position: absolute;
    top: 45px;
    left: 0;
    right: 0;
    width: 100%;
    max-width: 500px;
    margin: 0 auto;
    background: white;
    border-radius: 8px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
    z-index: 9999;
    max-height: 400px;
    overflow-y: auto;
}

.search-result-item {
    transition: background 0.2s;
}

.search-result-item:hover {
    background: #fff3cd !important;
}