*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --primary: #4a6cf7;
  --primary-dark: #3b5de7;
  --primary-light: #e8ecff;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #3b82f6;
  --gray-50: #f8fafc;
  --gray-100: #f1f5f9;
  --gray-200: #e2e8f0;
  --gray-300: #cbd5e1;
  --gray-400: #94a3b8;
  --gray-500: #64748b;
  --gray-600: #475569;
  --gray-700: #334155;
  --gray-800: #1e293b;
  --gray-900: #0f172a;
  --sidebar-w: 240px;
  --header-h: 56px;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,.1), 0 2px 4px rgba(0,0,0,.06);
}
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Hiragino Sans', sans-serif; background: var(--gray-100); color: var(--gray-800); font-size: 14px; line-height: 1.5; overflow-x: hidden; }
a { color: var(--primary); text-decoration: none; }
button { cursor: pointer; border: none; font-family: inherit; font-size: inherit; }
input, select, textarea { font-family: inherit; font-size: inherit; }

/* Login Screen */
.login-screen {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--gray-900) 0%, #1a2744 100%);
}
.login-card {
  background: #fff; border-radius: 16px; padding: 40px; width: 100%; max-width: 400px;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.login-card .login-logo { text-align: center; margin-bottom: 32px; }
.login-card .login-logo .logo-icon { width: 64px; height: 64px; background: var(--primary); border-radius: 16px; display: inline-flex; align-items: center; justify-content: center; font-size: 32px; margin-bottom: 12px; }
.login-card .login-logo h2 { font-size: 22px; color: var(--gray-800); }
.login-card .login-logo p { font-size: 13px; color: var(--gray-500); margin-top: 4px; }

/* Layout */
.app { display: flex; min-height: 100vh; }
.app.hidden { display: none; }
.sidebar {
  width: var(--sidebar-w); background: var(--gray-900); color: #fff;
  position: fixed; top: 0; left: 0; bottom: 0; z-index: 100;
  display: flex; flex-direction: column; transition: transform .3s;
}
.sidebar.closed { transform: translateX(-100%); }
.sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 99; }
.sidebar-overlay.show { display: block; }
.sidebar-logo {
  padding: 16px 20px; font-size: 18px; font-weight: 700;
  border-bottom: 1px solid var(--gray-700); display: flex; align-items: center; gap: 10px;
}
.sidebar-logo .logo-icon { width: 32px; height: 32px; background: var(--primary); border-radius: 8px; display: flex; align-items: center; justify-content: center; font-size: 16px; }
.sidebar-nav { flex: 1; overflow-y: auto; padding: 8px 0; }
.nav-section { padding: 12px 20px 4px; font-size: 11px; text-transform: uppercase; color: var(--gray-400); letter-spacing: .5px; }
.nav-item {
  display: flex; align-items: center; gap: 12px; padding: 10px 20px;
  color: var(--gray-300); transition: all .15s; cursor: pointer; border: none; background: none; width: 100%; text-align: left; font-size: 14px;
}
.nav-item:hover { background: var(--gray-800); color: #fff; }
.nav-item.active { background: var(--primary); color: #fff; }
.nav-item .icon { width: 20px; text-align: center; font-size: 16px; }
.sidebar-footer { padding: 12px 20px; border-top: 1px solid var(--gray-700); font-size: 12px; color: var(--gray-500); }

/* Main */
.main { flex: 1; margin-left: var(--sidebar-w); }
.header {
  height: var(--header-h); background: #fff; border-bottom: 1px solid var(--gray-200);
  display: flex; align-items: center; padding: 0 24px; gap: 16px;
  position: sticky; top: 0; z-index: 50;
}
.header .menu-btn { display: none; background: none; border: none; font-size: 20px; color: var(--gray-600); }
.header-title { font-size: 18px; font-weight: 600; }
.header-search { margin-left: auto; position: relative; }
.header-search input {
  padding: 8px 12px 8px 36px; border: 1px solid var(--gray-200); border-radius: 6px;
  width: 280px; background: var(--gray-50); outline: none; transition: border-color .2s;
}
.header-search input:focus { border-color: var(--primary); }
.header-search .search-icon { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--gray-400); }
.header-actions { display: flex; align-items: center; gap: 12px; }
.header-actions .notif-btn { background: none; border: none; font-size: 18px; color: var(--gray-500); position: relative; }
.header-actions .notif-badge { position: absolute; top: -2px; right: -2px; width: 8px; height: 8px; background: var(--danger); border-radius: 50%; }
.user-info {
  display: flex; align-items: center; gap: 8px; padding: 6px 12px;
  background: var(--gray-50); border-radius: 6px; font-size: 13px; cursor: pointer;
  border: 1px solid var(--gray-200);
}
.user-info:hover { background: var(--gray-100); }
.user-info .user-avatar { width: 28px; height: 28px; background: var(--primary); color: #fff; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 600; }
.site-badge {
  display: inline-flex; align-items: center; gap: 4px; padding: 4px 10px;
  background: var(--primary-light); color: var(--primary-dark); border-radius: 4px;
  font-size: 12px; font-weight: 600; cursor: pointer; border: 1px solid transparent;
}
.site-badge:hover { border-color: var(--primary); }

.content { padding: 24px; }

/* Cards */
.card { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.card-header { padding: 16px 20px; border-bottom: 1px solid var(--gray-100); display: flex; align-items: center; justify-content: space-between; }
.card-header h3 { font-size: 16px; font-weight: 600; }
.card-body { padding: 20px; }

/* Stats */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card { background: #fff; border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); display: flex; align-items: center; gap: 16px; }
.stat-icon { width: 48px; height: 48px; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 22px; }
.stat-icon.blue { background: #dbeafe; color: #2563eb; }
.stat-icon.green { background: #dcfce7; color: #16a34a; }
.stat-icon.yellow { background: #fef3c7; color: #d97706; }
.stat-icon.red { background: #fee2e2; color: #dc2626; }
.stat-icon.purple { background: #f3e8ff; color: #9333ea; }
.stat-info h4 { font-size: 24px; font-weight: 700; }
.stat-info p { font-size: 13px; color: var(--gray-500); }

/* Table */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
thead { background: var(--gray-50); }
th { padding: 10px 16px; text-align: left; font-weight: 600; font-size: 12px; text-transform: uppercase; color: var(--gray-500); letter-spacing: .5px; border-bottom: 1px solid var(--gray-200); white-space: nowrap; }
td { padding: 12px 16px; border-bottom: 1px solid var(--gray-100); }
tr:hover { background: var(--gray-50); }
tr[style*="cursor:pointer"]:hover { background: var(--primary-light); }
.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 12px; font-weight: 500; }
.badge-success { background: #dcfce7; color: #166534; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-info { background: #dbeafe; color: #1e40af; }

/* Buttons */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 16px; border-radius: 6px; font-weight: 500; transition: all .15s; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-outline { background: #fff; border: 1px solid var(--gray-300); color: var(--gray-700); }
.btn-outline:hover { background: var(--gray-50); }
.btn-sm { padding: 4px 10px; font-size: 13px; }
.btn-icon { padding: 6px 8px; }
.btn-group { display: flex; gap: 8px; flex-wrap: wrap; }

/* Modal */
.modal-overlay {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,.5);
  z-index: 200; align-items: center; justify-content: center; padding: 16px;
}
.modal-overlay.show { display: flex; }
.modal {
  background: #fff; border-radius: 12px; width: 100%; max-width: 560px;
  max-height: 90vh; overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.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; font-weight: 600; }
.modal-close { background: none; border: none; font-size: 20px; color: var(--gray-400); }
.modal-body { padding: 20px; }
.modal-footer { padding: 12px 20px; border-top: 1px solid var(--gray-200); display: flex; justify-content: flex-end; gap: 8px; }

/* Form */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; margin-bottom: 4px; font-weight: 500; font-size: 13px; color: var(--gray-700); }
.form-control { width: 100%; padding: 8px 12px; border: 1px solid var(--gray-300); border-radius: 6px; outline: none; transition: border-color .2s; }
.form-control:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(74,108,247,.1); }
select.form-control { appearance: auto; }
textarea.form-control { resize: vertical; min-height: 80px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* Toast */
.toast-container { position: fixed; top: 16px; right: 16px; z-index: 300; display: flex; flex-direction: column; gap: 8px; }
.toast { padding: 12px 20px; border-radius: 8px; color: #fff; font-weight: 500; box-shadow: var(--shadow-md); animation: slideIn .3s; display: flex; align-items: center; gap: 8px; }
.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }
.toast-info { background: var(--info); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* Tabs */
.tabs { display: flex; gap: 0; border-bottom: 2px solid var(--gray-200); margin-bottom: 20px; }
.tab-btn { padding: 10px 20px; background: none; border: none; color: var(--gray-500); font-weight: 500; border-bottom: 2px solid transparent; margin-bottom: -2px; transition: all .15s; }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-content { display: none; }
.tab-content.active { display: block; }

/* Filter bar */
.filter-bar { display: flex; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; align-items: center; }
.filter-bar .form-control { width: auto; min-width: 160px; }

/* Chart */
.chart-container { width: 100%; height: 250px; display: flex; align-items: flex-end; gap: 8px; padding: 20px 0; }
.chart-bar { flex: 1; background: var(--primary); border-radius: 4px 4px 0 0; transition: height .5s; position: relative; min-width: 20px; }
.chart-bar:hover { background: var(--primary-dark); }
.chart-bar .chart-label { position: absolute; bottom: -24px; left: 50%; transform: translateX(-50%); font-size: 11px; color: var(--gray-500); white-space: nowrap; }
.chart-bar .chart-value { position: absolute; top: -20px; left: 50%; transform: translateX(-50%); font-size: 11px; font-weight: 600; color: var(--gray-700); }

/* Scanner */
.scanner-area { width: 100%; max-width: 400px; margin: 0 auto; }
.scanner-video { width: 100%; border-radius: 8px; background: #000; }
.scanner-result { margin-top: 16px; padding: 12px; background: var(--gray-50); border-radius: 8px; text-align: center; }

/* Empty state */
.empty-state { text-align: center; padding: 60px 20px; color: var(--gray-400); }
.empty-state .empty-icon { font-size: 48px; margin-bottom: 12px; }
.empty-state p { font-size: 16px; }

/* Pagination */
.pagination { display: flex; justify-content: center; gap: 4px; margin-top: 16px; }
.pagination button { padding: 6px 12px; border: 1px solid var(--gray-200); border-radius: 4px; background: #fff; }
.pagination button.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* User Dropdown */
.user-dropdown {
  position: absolute; top: calc(var(--header-h) - 4px); right: 24px;
  background: #fff; border-radius: 8px; box-shadow: var(--shadow-md); border: 1px solid var(--gray-200);
  min-width: 200px; z-index: 60; display: none;
}
.user-dropdown.show { display: block; }
.user-dropdown .dropdown-item { display: flex; align-items: center; gap: 8px; padding: 10px 16px; width: 100%; background: none; border: none; color: var(--gray-700); font-size: 14px; text-align: left; cursor: pointer; }
.user-dropdown .dropdown-item:hover { background: var(--gray-50); }
.user-dropdown .dropdown-divider { height: 1px; background: var(--gray-200); margin: 4px 0; }
.user-dropdown .dropdown-header { padding: 10px 16px; font-size: 12px; color: var(--gray-400); font-weight: 600; }

/* Responsive */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; }
  .header .menu-btn { display: block; }
  .header-search { display: none; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .filter-bar { flex-direction: column; }
  .filter-bar .form-control { width: 100%; }
  .content { padding: 16px; }
  .user-info span.user-name-text { display: none; }
}
@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
}

/* Pagination */
.pagination-bar { display: flex; align-items: center; justify-content: space-between; padding: 10px 16px; border-top: 1px solid var(--gray-200); font-size: 13px; }
.pagination-info { color: var(--gray-500); }
.pagination-buttons { display: flex; align-items: center; gap: 4px; }
.pagination-buttons .btn-sm { min-width: 32px; padding: 4px 8px; font-size: 12px; }
.pagination-dots { color: var(--gray-400); padding: 0 4px; }

/* Notification Panel */
.notif-panel {
  position: absolute; top: calc(var(--header-h) - 4px); right: 80px;
  background: #fff; border-radius: 8px; box-shadow: var(--shadow-md); border: 1px solid var(--gray-200);
  width: 360px; z-index: 60; display: none;
}
.notif-panel.show { display: block; }
.notif-item { border-bottom: 1px solid var(--gray-100); }
.notif-item:last-child { border-bottom: none; }

/* Notification Badge with count */
.header-actions .notif-badge {
  position: absolute; top: -4px; right: -6px; min-width: 16px; height: 16px;
  background: var(--danger); border-radius: 8px; font-size: 10px; font-weight: 700;
  color: #fff; display: flex; align-items: center; justify-content: center;
  padding: 0 4px; line-height: 1;
}

/* Product thumbnail */
.prod-thumb { width: 32px; height: 32px; border-radius: 4px; object-fit: cover; vertical-align: middle; margin-right: 6px; }
.prod-thumb-placeholder { width: 32px; height: 32px; border-radius: 4px; background: var(--gray-100); display: inline-flex; align-items: center; justify-content: center; font-size: 14px; vertical-align: middle; margin-right: 6px; color: var(--gray-400); }

/* Bestseller Chart */
.bestseller-chart { display: flex; flex-direction: column; gap: 6px; }
.bestseller-row { display: flex; align-items: center; gap: 8px; }
.bestseller-rank { width: 28px; text-align: center; font-weight: 700; font-size: 13px; color: var(--gray-500); flex-shrink: 0; }
.bestseller-name { width: 140px; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex-shrink: 0; }
.bestseller-bar-wrap { flex: 1; height: 22px; background: var(--gray-100); border-radius: 4px; overflow: hidden; }
.bestseller-bar { height: 100%; background: linear-gradient(90deg, var(--primary), var(--primary-dark)); border-radius: 4px; transition: width 0.5s; min-width: 2px; }
.bestseller-qty { width: 60px; text-align: right; font-weight: 600; font-size: 13px; flex-shrink: 0; }
.bestseller-row:nth-child(1) .bestseller-rank { color: #d97706; font-size: 15px; }
.bestseller-row:nth-child(2) .bestseller-rank { color: var(--gray-500); font-size: 14px; }
.bestseller-row:nth-child(3) .bestseller-rank { color: #b45309; font-size: 14px; }

/* Print */
@media print {
  .sidebar, .header, .btn, .modal-overlay, .toast-container, .notif-panel, .filter-bar, .tabs, .site-badge, .user-dropdown { display: none !important; }
  .main { margin-left: 0; }
  .content { padding: 0; }
  .card { box-shadow: none; border: 1px solid #ddd; }
  table { font-size: 11px; }
  th, td { padding: 6px 8px; }
}
