:root {
  --bg: #0f1117;
  --bg2: #161b27;
  --bg3: #1e2535;
  --bg4: #252d42;
  --border: #2a3347;
  --primary: #6366f1;
  --primary-h: #818cf8;
  --primary-dim: rgba(99,102,241,0.15);
  --success: #10b981;
  --success-dim: rgba(16,185,129,0.15);
  --danger: #ef4444;
  --danger-dim: rgba(239,68,68,0.15);
  --warning: #f59e0b;
  --warning-dim: rgba(245,158,11,0.15);
  --info: #3b82f6;
  --text: #e2e8f0;
  --text2: #94a3b8;
  --text3: #64748b;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
  --sidebar-w: 220px;
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; font-family: var(--font); background: var(--bg); color: var(--text); font-size: 14px; }

/* SCROLLBAR */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg2); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* LOGIN */
.login-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: radial-gradient(ellipse at 30% 40%, rgba(99,102,241,0.15) 0%, transparent 60%), var(--bg); }
.login-box { background: var(--bg2); border: 1px solid var(--border); border-radius: 16px; padding: 40px; width: 380px; box-shadow: var(--shadow); }
.login-logo { text-align: center; margin-bottom: 32px; }
.logo-icon { font-size: 48px; margin-bottom: 12px; }
.login-logo h1 { font-size: 20px; font-weight: 700; color: var(--text); }
.login-logo p { color: var(--text2); font-size: 13px; margin-top: 4px; }

/* SIDEBAR */
.sidebar { width: var(--sidebar-w); background: var(--bg2); border-right: 1px solid var(--border); display: flex; flex-direction: column; position: fixed; top: 0; left: 0; height: 100vh; z-index: 100; transition: width 0.2s; overflow: hidden; }
.sidebar.collapsed { width: 64px; }
.sidebar-header { padding: 16px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--border); min-height: 64px; }
.brand { display: flex; align-items: center; gap: 10px; overflow: hidden; }
.brand-icon { font-size: 24px; flex-shrink: 0; }
.brand-name { font-weight: 700; font-size: 13px; white-space: nowrap; }
.brand-sub { font-size: 11px; color: var(--text3); }
.sidebar-toggle { background: none; border: none; color: var(--text2); cursor: pointer; font-size: 18px; padding: 4px; border-radius: 4px; flex-shrink: 0; }
.sidebar-toggle:hover { color: var(--text); background: var(--bg3); }
.sidebar.collapsed .brand-name, .sidebar.collapsed .brand-sub { display: none; }
.sidebar-nav { flex: 1; padding: 12px 8px; display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 10px 10px; border-radius: var(--radius-sm); color: var(--text2); text-decoration: none; transition: all 0.15s; white-space: nowrap; }
.nav-item:hover { background: var(--bg3); color: var(--text); }
.nav-item.active { background: var(--primary-dim); color: var(--primary-h); font-weight: 600; }
.nav-icon { font-size: 18px; flex-shrink: 0; width: 22px; text-align: center; }
.sidebar.collapsed .nav-label { display: none; }
.sidebar-footer { padding: 12px 8px; border-top: 1px solid var(--border); display: flex; align-items: center; gap: 8px; }
.user-info { display: flex; align-items: center; gap: 8px; flex: 1; overflow: hidden; }
.user-avatar { font-size: 20px; flex-shrink: 0; }
.user-details { overflow: hidden; }
.user-details div:first-child { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 11px; color: var(--text3); }
.sidebar.collapsed .user-details, .sidebar.collapsed .brand { display: none; }
.btn-logout { background: none; border: none; color: var(--text3); cursor: pointer; font-size: 18px; padding: 6px; border-radius: var(--radius-sm); }
.btn-logout:hover { color: var(--danger); background: var(--danger-dim); }

/* MAIN */
.main-content { margin-left: var(--sidebar-w); min-height: 100vh; display: flex; flex-direction: column; transition: margin-left 0.2s; }
.main-content.expanded { margin-left: 64px; }
.topbar { background: var(--bg2); border-bottom: 1px solid var(--border); padding: 0 24px; height: 64px; display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; z-index: 50; }
.topbar h2 { font-size: 18px; font-weight: 700; }
.topbar-actions { display: flex; gap: 8px; align-items: center; }
.page-content { padding: 24px; flex: 1; }

/* CARDS */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.stat-card .stat-label { font-size: 12px; color: var(--text2); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 8px; }
.stat-card .stat-value { font-size: 28px; font-weight: 700; }
.stat-card .stat-sub { font-size: 12px; color: var(--text3); margin-top: 4px; }
.stat-card.primary { border-color: var(--primary); background: linear-gradient(135deg, var(--primary-dim), var(--bg2)); }
.stat-card.success { border-color: var(--success); background: linear-gradient(135deg, var(--success-dim), var(--bg2)); }
.stat-card.warning { border-color: var(--warning); background: linear-gradient(135deg, var(--warning-dim), var(--bg2)); }
.stat-card.danger { border-color: var(--danger); background: linear-gradient(135deg, var(--danger-dim), var(--bg2)); }

/* CARDS GRID */
.card { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); }
.card-header { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.card-title { font-size: 14px; font-weight: 600; }
.card-body { padding: 20px; }

/* BUTTONS */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: var(--radius-sm); font-size: 13px; font-weight: 500; cursor: pointer; border: none; transition: all 0.15s; text-decoration: none; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-h); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { filter: brightness(1.1); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(1.1); }
.btn-ghost { background: var(--bg3); color: var(--text); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--bg4); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-full { width: 100%; justify-content: center; }
.btn-icon { padding: 6px; }

/* FORMS */
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 12px; font-weight: 600; color: var(--text2); margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.4px; }
.field input, .field select, .field textarea { width: 100%; background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 9px 12px; color: var(--text); font-size: 13px; outline: none; transition: border-color 0.15s; font-family: var(--font); }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--primary); }
.field textarea { resize: vertical; min-height: 80px; }
.fields-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.fields-row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }

/* TABLE */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
thead th { background: var(--bg3); padding: 10px 14px; text-align: left; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text2); border-bottom: 1px solid var(--border); white-space: nowrap; }
tbody td { padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:hover { background: var(--bg3); }
tbody tr:last-child td { border-bottom: none; }

/* SEARCH BAR */
.search-bar { display: flex; gap: 10px; margin-bottom: 20px; flex-wrap: wrap; align-items: center; }
.search-input-wrap { position: relative; flex: 1; min-width: 200px; }
.search-input-wrap input { width: 100%; background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 9px 12px 9px 36px; color: var(--text); font-size: 13px; outline: none; }
.search-input-wrap input:focus { border-color: var(--primary); }
.search-input-wrap .search-icon { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--text3); font-size: 16px; pointer-events: none; }

/* PRODUCT CARDS */
.products-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; }
.product-card { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; transition: all 0.2s; cursor: pointer; }
.product-card:hover { border-color: var(--primary); transform: translateY(-2px); box-shadow: 0 8px 24px rgba(99,102,241,0.2); }
.product-card.low-stock { border-color: var(--warning); }
.product-img { width: 100%; height: 140px; object-fit: cover; background: var(--bg3); display: flex; align-items: center; justify-content: center; font-size: 40px; color: var(--text3); }
.product-img img { width: 100%; height: 100%; object-fit: cover; }
.product-info { padding: 12px; }
.product-name { font-weight: 600; font-size: 13px; margin-bottom: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.product-sku { font-size: 11px; color: var(--text3); margin-bottom: 8px; }
.product-stock { display: flex; justify-content: space-between; align-items: center; }
.stock-badge { font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 20px; }
.stock-ok { background: var(--success-dim); color: var(--success); }
.stock-low { background: var(--warning-dim); color: var(--warning); }
.stock-zero { background: var(--danger-dim); color: var(--danger); }
.product-price { font-size: 13px; font-weight: 700; color: var(--success); }

/* CATEGORY BADGE */
.cat-badge { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; padding: 2px 8px; border-radius: 20px; }

/* MOVEMENT BADGE */
.mov-badge { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 20px; }
.mov-entrada { background: var(--success-dim); color: var(--success); }
.mov-saida { background: var(--danger-dim); color: var(--danger); }
.mov-ajuste { background: var(--warning-dim); color: var(--warning); }

/* MODAL */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.7); z-index: 1000; display: flex; align-items: center; justify-content: center; backdrop-filter: blur(4px); }
.modal { background: var(--bg2); border: 1px solid var(--border); border-radius: 14px; width: 90%; max-width: 560px; max-height: 90vh; display: flex; flex-direction: column; box-shadow: var(--shadow); }
.modal-lg { max-width: 800px; }
.modal-header { padding: 20px 24px 16px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal-header h3 { font-size: 16px; font-weight: 700; }
.modal-close { background: none; border: none; color: var(--text2); cursor: pointer; font-size: 18px; padding: 4px 8px; border-radius: var(--radius-sm); }
.modal-close:hover { background: var(--bg3); color: var(--text); }
.modal-body { padding: 24px; overflow-y: auto; }
.modal-footer { padding: 16px 24px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }

/* TOAST */
.toast-container { position: fixed; bottom: 24px; right: 24px; z-index: 9999; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px 16px; min-width: 280px; max-width: 380px; display: flex; align-items: center; gap: 10px; font-size: 13px; box-shadow: var(--shadow); animation: slideIn 0.3s ease; }
.toast.success { border-color: var(--success); }
.toast.error { border-color: var(--danger); }
.toast.warning { border-color: var(--warning); }
@keyframes slideIn { from { transform: translateX(120%); opacity:0; } to { transform: translateX(0); opacity:1; } }

/* BARCODE SCANNER */
.scanner-area { display: flex; gap: 10px; align-items: center; margin-bottom: 20px; }
.scanner-input { flex: 1; background: var(--bg3); border: 2px solid var(--primary); border-radius: var(--radius-sm); padding: 12px 16px; color: var(--text); font-size: 16px; outline: none; }
.scanner-hint { font-size: 12px; color: var(--text3); margin-top: 6px; }

/* IMAGE UPLOAD */
.img-upload-wrap { border: 2px dashed var(--border); border-radius: var(--radius); padding: 24px; text-align: center; cursor: pointer; transition: all 0.2s; }
.img-upload-wrap:hover { border-color: var(--primary); background: var(--primary-dim); }
.img-preview { width: 100%; height: 160px; object-fit: cover; border-radius: var(--radius-sm); margin-bottom: 8px; }

/* REPORT */
.report-header { display: flex; gap: 12px; align-items: center; margin-bottom: 24px; flex-wrap: wrap; }
.report-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 24px; }
.chart-wrap { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.chart-wrap h3 { font-size: 13px; font-weight: 600; margin-bottom: 16px; color: var(--text2); }

/* ALERT BANNER */
.alert-banner { background: var(--warning-dim); border: 1px solid var(--warning); border-radius: var(--radius-sm); padding: 10px 14px; display: flex; align-items: center; gap: 8px; font-size: 13px; margin-bottom: 16px; }

/* COLOR PICKER */
.color-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.color-opt { width: 28px; height: 28px; border-radius: 50%; cursor: pointer; border: 2px solid transparent; transition: all 0.15s; }
.color-opt.selected, .color-opt:hover { border-color: #fff; transform: scale(1.1); }

/* EMPTY STATE */
.empty-state { text-align: center; padding: 60px 20px; color: var(--text3); }
.empty-state .empty-icon { font-size: 48px; margin-bottom: 12px; }
.empty-state h3 { font-size: 16px; font-weight: 600; color: var(--text2); margin-bottom: 6px; }

/* TABS */
.tabs { display: flex; gap: 0; border-bottom: 1px solid var(--border); margin-bottom: 20px; }
.tab { padding: 10px 18px; font-size: 13px; cursor: pointer; border-bottom: 2px solid transparent; color: var(--text2); transition: all 0.15s; margin-bottom: -1px; }
.tab.active { color: var(--primary-h); border-bottom-color: var(--primary); font-weight: 600; }

/* PAGINATION */
.pagination { display: flex; gap: 6px; justify-content: center; margin-top: 20px; }
.page-btn { background: var(--bg3); border: 1px solid var(--border); color: var(--text2); padding: 6px 12px; border-radius: var(--radius-sm); cursor: pointer; font-size: 13px; }
.page-btn.active, .page-btn:hover { background: var(--primary); color: #fff; border-color: var(--primary); }

/* UTILS */
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }
.text-muted { color: var(--text3); }
.text-right { text-align: right; }
.font-bold { font-weight: 700; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.flex { display: flex; }
.gap-1 { gap: 8px; }
.gap-2 { gap: 16px; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }

/* RESPONSIVE */
@media (max-width: 768px) {
  .sidebar { width: 64px; }
  .sidebar .brand-name, .sidebar .brand-sub, .sidebar .nav-label, .sidebar .user-details { display: none; }
  .main-content { margin-left: 64px; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .fields-row, .fields-row3, .report-grid { grid-template-columns: 1fr; }
  .products-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
}
@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .page-content { padding: 16px; }
}
