:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-light: #dbeafe;
    --success: #16a34a;
    --success-light: #dcfce7;
    --danger: #dc2626;
    --danger-light: #fee2e2;
    --warning: #f59e0b;
    --warning-light: #fef3c7;
    --info: #0891b2;
    --info-light: #cffafe;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;
    --sidebar-w: 260px;
    --topbar-h: 60px;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
    --shadow-lg: 0 10px 15px rgba(0,0,0,.1), 0 4px 6px rgba(0,0,0,.05);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: 'Segoe UI', system-ui, -apple-system, sans-serif; background: var(--gray-50); color: var(--gray-800); }

/* LOGIN */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: linear-gradient(135deg, #1e3a5f 0%, #2563eb 100%); }
.login-container { display: flex; max-width: 900px; width: 95%; border-radius: 16px; overflow: hidden; box-shadow: var(--shadow-lg); }
.login-left { flex: 1; background: var(--gray-900); color: white; padding: 48px 36px; display: flex; flex-direction: column; justify-content: center; }
.login-brand { margin-bottom: 32px; }
.login-brand i { font-size: 48px; color: var(--primary); margin-bottom: 12px; display: block; }
.login-brand h1 { font-size: 28px; margin-bottom: 4px; }
.login-brand p { color: var(--gray-400); }
.login-features { list-style: none; }
.login-features li { padding: 8px 0; color: var(--gray-300); }
.login-features li i { color: var(--success); margin-right: 10px; }
.login-right { flex: 1; background: white; padding: 48px 36px; display: flex; align-items: center; }
.login-form-box { width: 100%; }
.login-form-box h2 { font-size: 24px; margin-bottom: 24px; color: var(--gray-800); }

/* FORMS */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; font-weight: 600; color: var(--gray-600); margin-bottom: 6px; }
.form-group label i { margin-right: 6px; width: 16px; text-align: center; }
.form-group input, .form-group select, .form-group textarea {
    width: 100%; padding: 10px 12px; border: 1px solid var(--gray-300); border-radius: var(--radius);
    font-size: 14px; transition: border-color .2s;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }
.input-group { display: flex; }
.input-group input { flex: 1; border-radius: var(--radius) 0 0 var(--radius); }
.btn-toggle-pass { padding: 10px 12px; border: 1px solid var(--gray-300); border-left: none; border-radius: 0 var(--radius) var(--radius) 0; background: var(--gray-50); cursor: pointer; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* BUTTONS */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 10px 18px; border: none; border-radius: var(--radius); font-size: 14px; font-weight: 500; cursor: pointer; transition: all .2s; }
.btn i { font-size: 13px; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: #15803d; }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #b91c1c; }
.btn-outline { background: white; color: var(--gray-700); border: 1px solid var(--gray-300); }
.btn-outline:hover { background: var(--gray-50); }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-block { width: 100%; justify-content: center; }
.btn-group { display: flex; gap: 8px; flex-wrap: wrap; }

/* ALERTS */
.alert { padding: 12px 16px; border-radius: var(--radius); margin-bottom: 16px; font-size: 14px; }
.alert-error { background: var(--danger-light); color: var(--danger); border: 1px solid #fca5a5; }
.alert-success { background: var(--success-light); color: var(--success); border: 1px solid #86efac; }
.alert-info { background: var(--info-light); color: var(--info); border: 1px solid #67e8f9; }

/* SIDEBAR */
.sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: var(--sidebar-w); background: var(--gray-900); color: white; display: flex; flex-direction: column; z-index: 100; transition: transform .3s; }
.sidebar-header { padding: 20px; display: flex; align-items: center; gap: 12px; border-bottom: 1px solid var(--gray-700); }
.sidebar-header i { font-size: 28px; color: var(--primary); }
.sidebar-header span { font-size: 16px; font-weight: 600; }
.sidebar-nav { flex: 1; padding: 12px 0; overflow-y: auto; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 10px 20px; color: var(--gray-400); text-decoration: none; font-size: 14px; transition: all .2s; }
.nav-item:hover, .nav-item.active { color: white; background: rgba(255,255,255,.08); }
.nav-item.active { border-right: 3px solid var(--primary); }
.nav-item i { width: 20px; text-align: center; }
.nav-divider { height: 1px; background: var(--gray-700); margin: 8px 20px; }
.sidebar-footer { padding: 16px 20px; border-top: 1px solid var(--gray-700); display: flex; align-items: center; justify-content: space-between; }
.user-info { display: flex; align-items: center; gap: 10px; }
.user-avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--gray-700); display: flex; align-items: center; justify-content: center; }
.user-name { font-size: 13px; font-weight: 500; display: block; }
.user-role { font-size: 11px; color: var(--gray-400); display: block; }
.btn-logout { background: none; border: none; color: var(--gray-400); cursor: pointer; font-size: 18px; padding: 6px; }
.btn-logout:hover { color: var(--danger); }

/* TOPBAR */
.main-content { margin-left: var(--sidebar-w); min-height: 100vh; }
.topbar { height: var(--topbar-h); background: white; border-bottom: 1px solid var(--gray-200); display: flex; align-items: center; padding: 0 24px; gap: 16px; position: sticky; top: 0; z-index: 50; }
.menu-toggle { display: none; background: none; border: none; font-size: 20px; color: var(--gray-600); cursor: pointer; }
.topbar-search { display: flex; align-items: center; gap: 8px; background: var(--gray-100); border-radius: var(--radius); padding: 8px 14px; flex: 1; max-width: 400px; }
.topbar-search i { color: var(--gray-400); }
.topbar-search input { border: none; background: none; outline: none; flex: 1; font-size: 14px; }
.topbar-actions { display: flex; align-items: center; gap: 16px; margin-left: auto; }
.select-unidade { padding: 6px 12px; border: 1px solid var(--gray-300); border-radius: var(--radius); font-size: 13px; background: white; }
.topbar-user { font-size: 13px; color: var(--gray-600); font-weight: 500; }

/* CONTENT */
.content-area { padding: 24px; }

/* CARDS */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card { background: white; border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); border-left: 4px solid var(--primary); }
.stat-card.success { border-left-color: var(--success); }
.stat-card.danger { border-left-color: var(--danger); }
.stat-card.warning { border-left-color: var(--warning); }
.stat-card.info { border-left-color: var(--info); }
.stat-card .stat-label { font-size: 12px; color: var(--gray-500); text-transform: uppercase; letter-spacing: .5px; }
.stat-card .stat-value { font-size: 28px; font-weight: 700; margin: 4px 0; color: var(--gray-800); }
.stat-card .stat-sub { font-size: 12px; color: var(--gray-400); }

/* PANELS */
.panel { background: white; border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 20px; }
.panel-header { padding: 16px 20px; border-bottom: 1px solid var(--gray-200); display: flex; align-items: center; justify-content: space-between; }
.panel-header h3 { font-size: 16px; color: var(--gray-800); }
.panel-body { padding: 20px; }

/* TABLE */
.table-container { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
thead th { text-align: left; padding: 10px 12px; font-size: 12px; font-weight: 600; color: var(--gray-500); text-transform: uppercase; letter-spacing: .5px; background: var(--gray-50); border-bottom: 1px solid var(--gray-200); }
tbody td { padding: 12px; font-size: 14px; border-bottom: 1px solid var(--gray-100); }
tbody tr:hover { background: var(--gray-50); }
tbody tr.row-expandable { cursor: pointer; }
.row-expanded { background: var(--gray-50) !important; }
.row-detail { display: none; }
.row-detail.show { display: table-row; }
.row-detail td { padding: 12px 20px; background: var(--gray-50); border-bottom: 2px solid var(--primary-light); }
.row-detail .detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.detail-item { font-size: 13px; }
.detail-item label { color: var(--gray-500); font-size: 11px; text-transform: uppercase; display: block; margin-bottom: 2px; }

/* STATUS BADGES */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 4px 10px; border-radius: 20px; font-size: 12px; font-weight: 500; }
.badge-pendente { background: var(--warning-light); color: #92400e; }
.badge-recebido, .badge-pago { background: var(--success-light); color: #166534; }
.badge-atrasado { background: var(--danger-light); color: #991b1b; }
.badge-parcial { background: var(--info-light); color: #155e75; }
.badge-em_andamento { background: var(--primary-light); color: #1e40af; }
.badge-concluido { background: var(--success-light); color: #166534; }
.badge-cancelado { background: var(--gray-200); color: var(--gray-600); }
.badge-ativo { background: var(--success-light); color: #166534; }
.badge-inativo { background: var(--gray-200); color: var(--gray-600); }
.badge-cliente { background: var(--primary-light); color: #1e40af; }
.badge-fornecedor { background: #fee2e2; color: #991b1b; }
.badge-ambos { background: var(--info-light); color: #155e75; }
.badge-rascunho { background: var(--gray-200); color: var(--gray-700); }
.badge-enviado { background: var(--info-light); color: #155e75; }
.badge-aprovado { background: var(--success-light); color: #166534; }
.badge-reprovado { background: var(--danger-light); color: #991b1b; }
.badge-aprovado_entregue { background: #dcfce7; color: #166534; }
.badge-pendente_emissao { background: #fef3c7; color: #92400e; }
.badge-email_financeiro_enviado { background: #dbeafe; color: #1d4ed8; }
.badge-em_emissao { background: #e0f2fe; color: #0369a1; }
.badge-emitido { background: #dcfce7; color: #166534; }

/* FILTERS BAR */
.filters-bar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.filters-bar select, .filters-bar input { padding: 8px 12px; border: 1px solid var(--gray-300); border-radius: var(--radius); font-size: 13px; }
.filters-bar select:focus, .filters-bar input:focus { border-color: var(--primary); outline: none; }
.inline-filter-bar { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; }
.inline-filter-field { margin-bottom: 0; min-width: 180px; flex: 0 1 220px; }
.inline-filter-actions { margin-left: auto; }
.items-editor { display: flex; flex-direction: column; gap: 10px; }
.items-editor-header, .item-row { display: grid; grid-template-columns: minmax(220px, 2fr) minmax(120px, 1fr) minmax(120px, 1fr) minmax(130px, 1fr) 44px; gap: 10px; align-items: end; }
.items-editor-header { color: var(--gray-500); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .4px; }
.item-row { padding: 10px; border: 1px solid var(--gray-200); border-radius: var(--radius); background: var(--gray-50); }
.item-row-total { padding: 10px 12px; border: 1px solid var(--gray-200); border-radius: var(--radius); background: white; min-height: 42px; display: flex; align-items: center; font-weight: 600; }
.catalog-note { margin-bottom: 14px; padding: 12px 14px; border: 1px solid var(--primary-light); border-radius: var(--radius); background: #eff6ff; color: var(--gray-700); font-size: 13px; line-height: 1.5; }
.catalog-hint { margin-top: 6px; display: flex; gap: 12px; flex-wrap: wrap; color: var(--gray-500); font-size: 12px; }
.catalog-hint strong { color: var(--gray-700); }
.catalog-manager { margin-top: 18px; padding: 16px; border: 1px solid var(--gray-200); border-radius: var(--radius); background: white; }
.catalog-manager-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.catalog-manager-header h4 { font-size: 15px; color: var(--gray-800); margin-bottom: 4px; }
.catalog-manager-header p { font-size: 13px; color: var(--gray-500); line-height: 1.5; }
.catalog-preview { padding: 10px 12px; border: 1px solid var(--gray-200); border-radius: var(--radius); background: var(--gray-50); min-height: 42px; display: flex; align-items: center; font-size: 14px; color: var(--gray-700); }
.catalog-table-wrap { overflow-x: auto; }
.catalog-table { width: 100%; border-collapse: collapse; }
.catalog-table th { text-align: left; padding: 10px 12px; font-size: 12px; font-weight: 600; color: var(--gray-500); text-transform: uppercase; letter-spacing: .4px; background: var(--gray-50); border-bottom: 1px solid var(--gray-200); }
.catalog-table td { padding: 12px; border-bottom: 1px solid var(--gray-100); font-size: 14px; vertical-align: middle; }
.catalog-empty { padding: 14px; border: 1px dashed var(--gray-300); border-radius: var(--radius); background: var(--gray-50); color: var(--gray-500); font-size: 14px; }
.summary-box { border: 1px solid var(--gray-200); border-radius: var(--radius); background: var(--gray-50); padding: 14px; }
.summary-line { display: flex; justify-content: space-between; gap: 16px; margin-bottom: 8px; font-size: 14px; }
.summary-line:last-child { margin-bottom: 0; }

/* MODAL */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 200; display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal { background: white; border-radius: 12px; width: 100%; max-width: 900px; max-height: 85vh; overflow: hidden; display: flex; flex-direction: column; }
.modal-header { padding: 16px 20px; border-bottom: 1px solid var(--gray-200); display: flex; align-items: center; justify-content: space-between; }
.modal-header h3 { font-size: 18px; }
.modal-close { background: none; border: none; font-size: 20px; color: var(--gray-400); cursor: pointer; }
.modal-close:hover { color: var(--danger); }
.modal-body { padding: 20px; overflow-y: auto; flex: 1; }
.modal-footer { padding: 12px 20px; border-top: 1px solid var(--gray-200); display: flex; justify-content: flex-end; gap: 8px; }

/* TOAST */
.toast-container { position: fixed; top: 20px; right: 20px; z-index: 300; display: flex; flex-direction: column; gap: 8px; }
.toast { padding: 12px 20px; border-radius: var(--radius); color: white; font-size: 14px; animation: slideIn .3s; min-width: 280px; box-shadow: var(--shadow-lg); }
.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }
.toast-info { background: var(--info); }

/* CHART CONTAINER */
.chart-container { position: relative; height: 250px; width: 100%; }

/* RESPONSIVE */
@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .main-content { margin-left: 0; }
    .menu-toggle { display: block; }
    .login-container { flex-direction: column; }
    .login-left { padding: 24px; }
    .form-row { grid-template-columns: 1fr; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .filters-bar { flex-direction: column; align-items: stretch; }
    .inline-filter-bar { align-items: stretch; }
    .inline-filter-field { min-width: 100%; flex-basis: 100%; }
    .inline-filter-actions { margin-left: 0; width: 100%; }
    .items-editor-header { display: none; }
    .item-row { grid-template-columns: 1fr; }
    .catalog-manager-header { flex-direction: column; }
}

@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
