/* ============ RESET & BASE ============ */
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; font-size: 14px; transition: background 0.3s, color 0.3s; }

/* ============ TEMA CLARO ============ */
.light-theme { background: #f0f2f5; color: #333; }
.light-theme .sidebar { background: #2c3e50; color: #ecf0f1; }
.light-theme .main-content { background: #f0f2f5; }
.light-theme .card { background: #fff; border: 1px solid #ddd; }
.light-theme .table-container { background: #fff; }
.light-theme table th { background: #4a4a4a; color: #fff; }
.light-theme table td { border-bottom: 1px solid #eee; }
.light-theme table tr:hover td { background: #f5f5f5; }
.light-theme .form-control { background: #fff; border: 1px solid #ccc; color: #333; }
.light-theme .modal-content { background: #fff; color: #333; }
.light-theme .page-title { color: #2c3e50; border-bottom: 3px solid #4a4a4a; }
.light-theme .subtotal-bar { background: #f8f8f8; border: 1px solid #ddd; }
.light-theme .input-group label { color: #555; }

/* ============ TEMA ESCURO ============ */
.dark-theme { background: #1a1a2e; color: #e0e0e0; }
.dark-theme .sidebar { background: #16213e; color: #e0e0e0; }
.dark-theme .main-content { background: #1a1a2e; }
.dark-theme .card { background: #16213e; border: 1px solid #0f3460; }
.dark-theme .table-container { background: #16213e; }
.dark-theme table th { background: #0f3460; color: #e0e0e0; }
.dark-theme table td { border-bottom: 1px solid #1a1a4e; color: #e0e0e0; }
.dark-theme table tr:hover td { background: #1a1a4e; }
.dark-theme .form-control { background: #16213e; border: 1px solid #0f3460; color: #e0e0e0; }
.dark-theme .modal-content { background: #16213e; color: #e0e0e0; }
.dark-theme .page-title { color: #e0e0e0; border-bottom: 3px solid #0f3460; }
.dark-theme .subtotal-bar { background: #16213e; border: 1px solid #0f3460; }
.dark-theme .input-group label { color: #aaa; }
.dark-theme .btn-primary { background: #0f3460; }
.dark-theme .btn-secondary { background: #533483; border-color: #533483; }
.dark-theme select option { background: #16213e; color: #e0e0e0; }
.dark-theme .sidebar-footer { border-top-color: #0f3460; }

/* ============ LAYOUT ============ */
.app-container { display: flex; height: 100vh; }
.sidebar { width: 250px; min-width: 250px; display: flex; flex-direction: column; overflow-y: auto; z-index: 100; }
.sidebar-header { padding: 15px; border-bottom: 1px solid rgba(255,255,255,0.1); }
.logo-container { display: flex; flex-direction: column; text-align: center; align-items: center; gap: 10px; }
.logo-img { width: 100px; height: 70px; margin-bottom: 5px; border-radius: 8px; object-fit: contain; }
.logo-text { width: 40px; height: 40px; background: #3498db; border-radius: 8px; display: flex; align-items: center; justify-content: center; font-weight: bold; font-size: 18px; color: #fff; }
.logo-title { display: block; font-size: 16px; font-weight: 600; }
.nav-menu { list-style: none; padding: 10px 0; flex: 1; }
.nav-link { display: flex; align-items: center; gap: 10px; padding: 12px 20px; color: inherit; text-decoration: none; transition: all 0.2s; border-left: 3px solid transparent; }
.nav-link:hover { background: rgba(255,255,255,0.1); border-left-color: #3498db; }
.icon { font-size: 18px; }
.sidebar-footer { padding: 15px; border-top: 1px solid rgba(255,255,255,0.1); }
.user-info { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.user-name { font-weight: 600; font-size: 14px; }
.user-level { font-size: 11px; padding: 2px 8px; border-radius: 10px; display: inline-block; width: fit-content; }
.badge-master { background: #e74c3c; color: #fff; }
.badge-admin { background: #f39c12; color: #fff; }
.badge-usuario { background: #3498db; color: #fff; }
.btn-logout { display: block; text-align: center; padding: 8px; background: #c0392b; color: #fff; text-decoration: none; border-radius: 6px; font-size: 13px; transition: background 0.2s; }
.btn-logout:hover { background: #a93226; }

.main-content { flex: 1; overflow-y: auto; padding: 20px 30px; }

/* ============ PAGE ============ */
.page-title { font-size: 22px; font-weight: 700; padding-bottom: 10px; margin-bottom: 20px; display: inline-block; }

/* ============ SUBTOTAL BAR ============ */
.subtotal-bar { display: flex; align-items: center; gap: 15px; padding: 12px 20px; border-radius: 8px; margin-bottom: 20px; flex-wrap: wrap; }
.subtotal-item { display: flex; align-items: center; gap: 6px; }
.subtotal-label { font-weight: 600; font-size: 12px; text-transform: uppercase; color: #888; }
.subtotal-value { font-weight: 700; font-size: 16px; }
.subtotal-value.green { color: #27ae60; }
.subtotal-value.blue { color: #2980b9; }
.subtotal-value.red { color: #c0392b; }
.subtotal-value.yellow { color: #f39c12; }

/* ============ BUTTONS ============ */
.btn { padding: 8px 18px; border: none; border-radius: 6px; cursor: pointer; font-size: 13px; font-weight: 600; transition: all 0.2s; text-decoration: none; display: inline-flex; align-items: center; gap: 5px; }
.btn-primary { background: #2c3e50; color: #fff; }
.btn-primary:hover { background: #34495e; }
.btn-success { background: #27ae60; color: #fff; }
.btn-success:hover { background: #229954; }
.btn-danger { background: #c0392b; color: #fff; }
.btn-danger:hover { background: #a93226; }
.btn-warning { background: #f39c12; color: #fff; }
.btn-warning:hover { background: #d68910; }
.btn-info { background: #2980b9; color: #fff; }
.btn-info:hover { background: #2471a3; }
.btn-secondary { background: #7f8c8d; color: #fff; }
.btn-secondary:hover { background: #707b7c; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-lg { padding: 12px 28px; font-size: 15px; }

/* ============ TOOLBAR ============ */
.toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 20px; flex-wrap: wrap; justify-content: space-between; }
.toolbar-left { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.toolbar-right { display: flex; gap: 10px; align-items: center; }

/* ============ TABLES ============ */
.table-container { border-radius: 8px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.08); margin-bottom: 20px; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; white-space: nowrap; }
table th { padding: 10px 12px; text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; font-weight: 700; position: sticky; top: 0; }
table td { padding: 8px 12px; font-size: 13px; }
table th select { background: transparent; color: inherit; border: none; font-size: 11px; cursor: pointer; }
.text-right { text-align: right; }
.text-center { text-align: center; }

/* ============ STATUS BADGES ============ */
.status { padding: 4px 12px; border-radius: 12px; font-size: 11px; font-weight: 700; display: inline-block; text-align: center; min-width: 110px; }
.status-recebido { background: #d4edda; color: #155724; }
.status-recebido-parcial { background: #fff3cd; color: #856404; }
.status-vencido { background: #f8d7da; color: #721c24; }
.status-no-prazo { background: #cce5ff; color: #004085; }

/* ============ FORMS ============ */
.form-control { padding: 8px 12px; border-radius: 6px; font-size: 13px; width: 100%; transition: border-color 0.2s; }
.form-control:focus { outline: none; border-color: #3498db; box-shadow: 0 0 0 2px rgba(52,152,219,0.2); }
select.form-control { cursor: pointer; }
.form-group { margin-bottom: 15px; }
.form-group label { display: block; margin-bottom: 5px; font-weight: 600; font-size: 12px; text-transform: uppercase; }
.form-row { display: flex; gap: 15px; flex-wrap: wrap; }
.form-row .form-group { flex: 1; min-width: 180px; }

/* ============ CARDS ============ */
.card { border-radius: 10px; padding: 20px; box-shadow: 0 2px 8px rgba(0,0,0,0.06); }
.card-title { font-size: 12px; font-weight: 700; text-transform: uppercase; color: #888; margin-bottom: 8px; }
.card-value { font-size: 24px; font-weight: 800; }
.cards-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 20px; margin-bottom: 25px; }

.card-vendido { border-left: 4px solid #2c3e50; }
.card-vendido .card-value { color: #2c3e50; }
.card-recebido { border-left: 4px solid #27ae60; }
.card-recebido .card-value { color: #27ae60; }
.card-pendente { border-left: 4px solid #c0392b; }
.card-pendente .card-value { color: #c0392b; }
.card-saldo { border-left: 4px solid #f39c12; }
.card-saldo .card-value { color: #f39c12; }

/* ============ CHARTS ============ */
.chart-container { padding: 20px; margin-bottom: 25px; border-radius: 10px; }
.chart-title { font-size: 14px; font-weight: 700; margin-bottom: 15px; text-transform: uppercase; }
.chart-wrapper { position: relative; height: 300px; }

/* ============ MODAL ============ */
.modal-overlay { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.6); z-index: 1000; justify-content: center; align-items: flex-start; padding-top: 50px; }
.modal-overlay.active { display: flex; }
.modal-content { width: 90%; max-width: 750px; border-radius: 12px; padding: 30px; position: relative; max-height: 85vh; overflow-y: auto; box-shadow: 0 10px 40px rgba(0,0,0,0.2); }
.modal-title { font-size: 18px; font-weight: 700; margin-bottom: 20px; padding-bottom: 10px; border-bottom: 2px solid #3498db; }
.modal-close { position: absolute; top: 15px; right: 20px; font-size: 24px; cursor: pointer; background: none; border: none; color: inherit; line-height: 1; }
.modal-close:hover { color: #e74c3c; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; padding-top: 15px; border-top: 1px solid #eee; }

/* ============ VENDA FORM TOP ============ */
.venda-form-top { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; padding: 15px; border-radius: 8px; margin-bottom: 15px; align-items: end; }
.venda-form-top .input-group { display: flex; flex-direction: column; }
.venda-form-top .input-group label { font-size: 11px; font-weight: 700; text-transform: uppercase; margin-bottom: 4px; }

/* ============ FILTER BAR ============ */
.filter-bar { display: flex; gap: 15px; align-items: end; margin-bottom: 25px; padding: 15px; border-radius: 8px; flex-wrap: wrap; }
.filter-bar .input-group { display: flex; flex-direction: column; }
.filter-bar .input-group label { font-size: 11px; font-weight: 700; text-transform: uppercase; margin-bottom: 4px; padding: 4px 10px; border-radius: 4px; }
.label-ano { background: #c0392b; color: #fff; }
.label-cliente { background: #27ae60; color: #fff; }
.label-mes { background: #2980b9; color: #fff; }

/* ============ MARCA TABLE ============ */
.marca-table { width: auto; min-width: 250px; }
.marca-table th { background: #4a4a4a; color: #fff; }
.dark-theme .marca-table th { background: #0f3460; }
.marca-farm { border-left: 4px solid #2c3e50; }
.marca-open { border-left: 4px solid #27ae60; }
.marca-raia { border-left: 4px solid #e74c3c; }
.marca-fpm { border-left: 4px solid #3498db; }
.marca-outros { border-left: 4px solid #f39c12; }

/* ============ LOGIN ============ */
.login-container { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-box { width: 400px; padding: 40px; border-radius: 16px; text-align: center; }
.login-box .logo-img { width: 80px; height: 80px; margin-bottom: 20px; }
.login-box h2 { margin-bottom: 30px; font-size: 22px; }
.login-box .form-group { text-align: left; }
.login-box .btn { width: 100%; justify-content: center; padding: 12px; font-size: 15px; }
.login-error { background: #f8d7da; color: #721c24; padding: 10px; border-radius: 6px; margin-bottom: 15px; font-size: 13px; }

/* ============ CONFIG PAGE ============ */
.config-section { margin-bottom: 30px; }
.config-section h3 { margin-bottom: 15px; padding-bottom: 8px; border-bottom: 2px solid #3498db; display: inline-block; }
.theme-selector { display: flex; gap: 15px; }
.theme-option { padding: 20px 30px; border-radius: 10px; cursor: pointer; border: 3px solid transparent; transition: all 0.2s; text-align: center; font-weight: 600; }
.theme-option.active { border-color: #3498db; }
.theme-light { background: #f0f2f5; color: #333; }
.theme-dark { background: #1a1a2e; color: #e0e0e0; }
.theme-option:hover { transform: scale(1.05); }

/* ============ DASHBOARD ============ */
.dashboard-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 20px; }

/* ============ RANKING ============ */
.ranking-table { max-height: 400px; overflow-y: auto; }

/* ============ RESPONSIVE ============ */
@media (max-width: 768px) {
    .sidebar { position: fixed; left: -250px; height: 100%; transition: left 0.3s; }
    .sidebar.open { left: 0; }
    .main-content { padding: 15px; }
    .venda-form-top { grid-template-columns: 1fr 1fr; }
    .cards-row { grid-template-columns: 1fr; }
}

/* ============ INSTALL ============ */
.install-container { max-width: 600px; margin: 50px auto; padding: 30px; }
.install-title { text-align: center; font-size: 28px; margin-bottom: 30px; }
.step-indicator { display: flex; justify-content: center; gap: 30px; margin-bottom: 40px; }
.step { display: flex; flex-direction: column; align-items: center; gap: 5px; }
.step-number { width: 40px; height: 40px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 700; background: #ddd; color: #666; }
.step.active .step-number { background: #2c3e50; color: #fff; }
.step.done .step-number { background: #27ae60; color: #fff; }
.step-label { font-size: 12px; color: #888; }

.scrollable-table { max-height: 700px; overflow-y: auto; }

/* Action buttons in table */
.action-btns { display: flex; gap: 5px; }


/* ============ BOTÃO SANDUÍCHE / SIDEBAR COLAPSÁVEL ============ */
.btn-toggle-sidebar {
    position: fixed;
    top: 15px;
    left: 260px;
    z-index: 200;
    width: 40px;
    height: 40px;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #2c3e50;
    color: #fff;
    transition: left 0.3s ease, background 0.2s;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.btn-toggle-sidebar:hover {
    background: #34495e;
}
.dark-theme .btn-toggle-sidebar {
    background: #0f3460;
}
.dark-theme .btn-toggle-sidebar:hover {
    background: #16478a;
}

.hamburger-icon {
    display: inline-flex;
    flex-direction: column;
    justify-content: space-between;
    width: 20px;
    height: 15px;
}
.hamburger-icon span {
    display: block;
    height: 2px;
    width: 100%;
    background: #fff;
    border-radius: 2px;
    transition: all 0.3s;
}

/* Sidebar recolhida */
.sidebar.collapsed {
    width: 70px;
    min-width: 70px;
}
.sidebar.collapsed .logo-title,
.sidebar.collapsed .nav-text,
.sidebar.collapsed .user-info,
.sidebar.collapsed .btn-logout {
    display: none;
}
.sidebar.collapsed .logo-container {
    justify-content: center;
}
.sidebar.collapsed .nav-link {
    justify-content: center;
    padding: 12px 10px;
    position: relative;
}
.sidebar.collapsed .nav-link .icon {
    margin: 0;
    font-size: 22px;
}
.sidebar.collapsed .sidebar-footer {
    padding: 10px;
    text-align: center;
}

/* Tooltip ao passar mouse na sidebar recolhida */
.sidebar.collapsed .nav-link:hover::after {
    content: attr(data-title);
    position: absolute;
    left: 75px;
    top: 50%;
    transform: translateY(-50%);
    background: #2c3e50;
    color: #fff;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 13px;
    white-space: nowrap;
    z-index: 300;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}
.dark-theme .sidebar.collapsed .nav-link:hover::after {
    background: #0f3460;
}

/* Botão desloca quando sidebar recolhe */
.sidebar.collapsed ~ .main-content .btn-toggle-sidebar,
body.sidebar-collapsed .btn-toggle-sidebar {
    left: 80px;
}

/* Ajuste da main-content */
.main-content {
    padding-top: 65px;
    position: relative;
}

@media (max-width: 768px) {
    .btn-toggle-sidebar {
        left: 15px;
    }
    body.sidebar-collapsed .btn-toggle-sidebar {
        left: 15px;
    }
}
/* ============ ATUALIZAÇÕES ============ */
/* Filtros mais visíveis */

.dark-theme .filter-bar .input-group label {
    color: #fff !important;
}
.filter-bar .form-control {
    color: #333 !important;
    background: #fff !important;
    border: 1px solid #ccc !important;
}
.dark-theme .filter-bar .form-control {
    color: #fff !important;
    background: #0f3460 !important;
    border: 1px solid #16478a !important;
}

/* Cores de status para linhas */
tr.linha-sem-financeiro td {
    background: rgba(231, 76, 60, 0.15) !important;
    color: #c0392b;
}
.dark-theme tr.linha-sem-financeiro td {
    background: rgba(231, 76, 60, 0.25) !important;
    color: #ff6b5b;
}

/* Filtros de coluna estilo Excel */
.column-filters th {
    padding: 4px 6px !important;
}
.column-filter-input {
    width: 100%;
    padding: 3px 6px;
    font-size: 11px;
    border: 1px solid #999;
    border-radius: 3px;
    background: #fff;
    color: #333;
}
.dark-theme .column-filter-input {
    background: #16213e;
    color: #e0e0e0;
    border-color: #0f3460;
}

/* Botão WhatsApp */
.btn-whatsapp {
    background: #25d366 !important;
    color: #fff !important;
}
.btn-whatsapp:hover {
    background: #20b859 !important;
}

/* Ajuste gráficos - altura menor */
.chart-wrapper {
    height: 220px !important;
}

/* Status badges na tabela de vendas */
.status-com-financeiro {
    background: #d4edda;
    color: #155724;
    padding: 3px 10px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 700;
}
.status-sem-financeiro {
    background: #f8d7da;
    color: #721c24;
    padding: 3px 10px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 700;
}


/* ============ CSS DA ATUALIZAÇÃO V3 ============ */
.col-hidden { display: none !important; }
.dropdown-colunas { position: relative; display: inline-block; }
.dropdown-colunas-content { display: none; position: absolute; right: 0; background-color: #f9f9f9; min-width: 160px; box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2); z-index: 1000; padding: 10px; border-radius: 8px; }
.dark-theme .dropdown-colunas-content { background-color: #16213e; color: #fff; }
.dropdown-colunas:hover .dropdown-colunas-content { display: flex; flex-direction: column; gap: 8px; }
.badge-acordo { background: #8e44ad; color: white; padding: 2px 6px; border-radius: 4px; font-size: 10px; font-weight: bold; margin-left: 5px; }

@media print {
    .sidebar, .filter-bar, .toolbar, .subtotal-bar, .action-btns, .btn, .modal-overlay { display: none !important; }
    .main-content { padding: 0 !important; margin: 0 !important; width: 100% !important; background: #fff !important; }
    body { background: #fff !important; color: #000 !important; }
    .table-container { box-shadow: none !important; border: 1px solid #ddd; }
    .page-title { border-bottom: 2px solid #000 !important; color: #000 !important; }
}


/* Cores corretas dos filtros por tema */
.light-theme .filter-bar .input-group label, .light-theme .filter-bar label { color: #333 !important; font-weight: 700 !important; }
.dark-theme .filter-bar .input-group label, .dark-theme .filter-bar label { color: #fff !important; font-weight: 700 !important; }

/* Classes para ocultar colunas */
.col-hidden { display: none !important; }
.dropdown-colunas { position: relative; display: inline-block; z-index: 900; }
.dropdown-colunas-content { display: none; position: absolute; left: 0; background-color: #f9f9f9; min-width: 170px; box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2); padding: 10px; border-radius: 8px; }
.dark-theme .dropdown-colunas-content { background-color: #16213e; color: #fff; }
.dropdown-colunas:hover .dropdown-colunas-content { display: flex; flex-direction: column; gap: 8px; }


/* ============ CORREÇÃO IMPRESSÃO (PDF COMPLETO A4) ============ */
@media print {
    /* Ocultar elementos desnecessários */
    .sidebar, .filter-bar, .toolbar, .subtotal-bar, .action-btns, .btn, .modal-overlay, .btn-toggle-sidebar, .dropdown-colunas { 
        display: none !important; 
    }
    /* Resetar corpo da página */
    body, html { 
        background: #fff !important; 
        color: #000 !important; 
        height: auto !important; 
        overflow: visible !important; 
    }
    .main-content { 
        padding: 0 !important; 
        margin: 0 !important; 
        width: 100% !important; 
        position: static !important; 
        overflow: visible !important;
    }
    /* Forçar tabela a exibir todas as linhas sem scrollbar */
    .table-container, .scrollable-table { 
        overflow: visible !important; 
        max-height: none !important; 
        height: auto !important; 
        box-shadow: none !important; 
        border: none !important; 
    }
    table { 
        width: 100% !important; 
        border-collapse: collapse !important; 
        font-size: 9px !important; /* Fonte menor para caber no A4 */
        page-break-inside: auto !important; 
    }
    tr { 
        page-break-inside: avoid !important; 
        page-break-after: auto !important; 
    }
    td, th { 
        padding: 4px !important; 
        white-space: normal !important; 
        word-wrap: break-word !important; 
        border: 1px solid #ccc !important; 
        color: #000 !important;
    }
    /* Esconder colunas de Ações / Checkbox nas impressões específicas */
    #tabelaPag th:nth-child(1), #tabelaPag td:nth-child(1), 
    #tabelaPag th:nth-child(3), #tabelaPag td:nth-child(3),
    #tabelaVendas th:nth-child(1), #tabelaVendas td:nth-child(1) { 
        display: none !important; 
    }
    /* Formatar página para Paisagem para caber colunas */
    @page { 
        size: A4 landscape; 
        margin: 10mm; 
    }
}
