/* =========================
   CSS Variables & Reset
========================= */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --primary-light: #e0e7ff;
  --success: #22c55e;
  --danger: #ef4444;
  --warning: #f59e0b;
  --info: #3b82f6;
  --sidebar-bg: #1e293b;
  --sidebar-hover: #334155;
  --sidebar-active: #6366f1;
  --sidebar-text: #94a3b8;
  --sidebar-text-active: #fff;
  --topbar-bg: #fff;
  --content-bg: #f1f5f9;
  --card-bg: #fff;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 4px 16px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 10px 30px rgba(0,0,0,0.06);
  --radius: 10px;
  --sidebar-width: 240px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: 'Inter', -apple-system, sans-serif; background: var(--content-bg); color: var(--text); font-size: 14px; min-height: 100vh; display: flex; }
a { text-decoration: none; color: inherit; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; }
ul { list-style: none; }

/* =========================
   Sidebar
========================= */
.sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  height: 100vh;
  position: fixed;
  left: 0; top: 0;
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: transform .3s ease;
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar-header {
  padding: 20px 16px;
  border-bottom: 1px solid #334155;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-icon {
  width: 40px; height: 40px;
  background: var(--primary);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  font-size: 1.1rem;
  flex-shrink: 0;
}

.logo-name {
  display: block;
  font-size: 1rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: .3px;
}

.logo-sub {
  display: block;
  font-size: 0.7rem;
  color: var(--sidebar-text);
  margin-top: 1px;
}

.sidebar-nav {
  flex: 1;
  padding: 12px 8px;
}

.nav-section-label {
  font-size: 0.65rem;
  font-weight: 600;
  color: #475569;
  letter-spacing: 1px;
  text-transform: uppercase;
  padding: 16px 10px 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  color: var(--sidebar-text);
  font-size: 0.85rem;
  font-weight: 500;
  margin-bottom: 2px;
  transition: all .2s;
  cursor: pointer;
  position: relative;
}

.nav-item i {
  width: 18px;
  text-align: center;
  font-size: 0.9rem;
  flex-shrink: 0;
}

.nav-item:hover {
  background: var(--sidebar-hover);
  color: #e2e8f0;
}

.nav-item.active {
  background: var(--primary);
  color: var(--sidebar-text-active);
  font-weight: 600;
}

.nav-badge {
  margin-left: auto;
  background: #ef4444;
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  border-radius: 20px;
  padding: 2px 7px;
  min-width: 20px;
  text-align: center;
}

.sidebar-footer {
  padding: 12px 8px;
  border-top: 1px solid #334155;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  background: #334155;
}

.user-avatar {
  width: 34px; height: 34px;
  background: var(--primary);
  border-radius: 50%;
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
  font-size: 0.9rem;
  flex-shrink: 0;
}

.user-name {
  display: block;
  color: #e2e8f0;
  font-size: .82rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-role {
  display: block;
  color: var(--sidebar-text);
  font-size: .7rem;
}

.logout-btn {
  margin-left: auto;
  color: var(--sidebar-text);
  padding: 6px;
  border-radius: 6px;
  transition: all .2s;
}

.logout-btn:hover { color: #ef4444; background: rgba(239,68,68,.1); }

/* =========================
   Main Wrapper & Topbar
========================= */
.main-wrapper {
  margin-left: var(--sidebar-width);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  background: var(--topbar-bg);
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: 0 1px 4px rgba(0,0,0,.04);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.sidebar-toggle {
  background: none;
  border: none;
  font-size: 1.1rem;
  color: var(--text-muted);
  padding: 6px;
  border-radius: 6px;
  cursor: pointer;
  transition: all .2s;
  display: none;
}

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: .85rem;
  color: var(--text-muted);
}

.breadcrumb .sep { color: #cbd5e1; }
.breadcrumb a:hover { color: var(--primary); }
.breadcrumb-home { color: var(--primary); }

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.pos-btn {
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 7px 14px;
  border-radius: 8px;
  font-size: .82rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all .2s;
}

.pos-btn:hover { background: var(--primary-dark); color: #fff; transform: translateY(-1px); }

.topbar-date {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: .82rem;
  color: var(--text-muted);
}

.topbar-btn {
  background: none;
  border: 1px solid var(--border);
  padding: 6px 12px;
  border-radius: 8px;
  font-size: .82rem;
  color: var(--text);
  transition: all .2s;
}

.topbar-btn:hover { border-color: var(--primary); color: var(--primary); }

/* =========================
   Flash / Alerts
========================= */
.flash-container { padding: 12px 24px 0; }

.alert {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-radius: var(--radius);
  margin-bottom: 10px;
  font-size: .875rem;
  font-weight: 500;
  animation: slideIn .3s ease;
}

@keyframes slideIn {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

.alert-success { background: #f0fdf4; color: #16a34a; border: 1px solid #bbf7d0; }
.alert-danger { background: #fef2f2; color: #dc2626; border: 1px solid #fecaca; }
.alert-warning { background: #fffbeb; color: #d97706; border: 1px solid #fde68a; }
.alert-info { background: #eff6ff; color: #2563eb; border: 1px solid #bfdbfe; }
.alert-close { margin-left: auto; background: none; border: none; cursor: pointer; color: inherit; opacity: .6; font-size: .85rem; }
.alert-close:hover { opacity: 1; }

/* =========================
   Page Content
========================= */
.page-content { padding: 24px; flex: 1; }

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 24px;
  gap: 16px;
  flex-wrap: wrap;
}

.page-title {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text);
  margin: 0;
}

.page-subtitle {
  color: var(--text-muted);
  font-size: .85rem;
  margin-top: 4px;
}

.page-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.badge-date {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--primary-light);
  color: var(--primary);
  padding: 6px 14px;
  border-radius: 20px;
  font-size: .82rem;
  font-weight: 600;
}

/* =========================
   Cards
========================= */
.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  border: 1px solid rgba(0,0,0,0.04);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
  flex-wrap: wrap;
}

.card-title {
  font-size: .95rem;
  font-weight: 600;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
}

.card-title i { color: var(--primary); }
.card-body { padding: 20px; }
.card-body.p-0 { padding: 0; }
.card-footer { padding: 16px 20px; border-top: 1px solid var(--border); background: #f8fafc; }

.mt-4 { margin-top: 16px; }
.mt-3 { margin-top: 12px; }
.mb-3 { margin-bottom: 12px; }

/* =========================
   Stats Grid
========================= */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  align-items: flex-start;
  gap: 16px;
  box-shadow: var(--shadow);
  border: 1px solid rgba(0,0,0,0.04);
  transition: transform .2s, box-shadow .2s;
}

.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }

.stat-icon {
  width: 48px; height: 48px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.2rem;
  flex-shrink: 0;
}

.stat-blue .stat-icon { background: #eff6ff; color: #3b82f6; }
.stat-green .stat-icon { background: #f0fdf4; color: #22c55e; }
.stat-purple .stat-icon { background: #f5f3ff; color: #8b5cf6; }
.stat-red .stat-icon { background: #fef2f2; color: #ef4444; }
.stat-teal .stat-icon { background: #f0fdfa; color: #14b8a6; }

.stat-label {
  font-size: .78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.stat-value {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--text);
  line-height: 1;
  margin-bottom: 4px;
}

.stat-sub {
  font-size: .75rem;
  color: var(--text-muted);
}

/* =========================
   Dashboard Grid
========================= */
.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 20px;
}

.chart-card { }

/* =========================
   Tables
========================= */
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: .875rem;
}

.table th {
  background: #f8fafc;
  color: var(--text-muted);
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
  padding: 10px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.table td {
  padding: 12px 16px;
  border-bottom: 1px solid #f5f7fa;
  vertical-align: middle;
}

.table tbody tr { transition: background .15s; }
.table tbody tr:hover { background: #f8fafc; }
.table tbody tr:last-child td { border-bottom: none; }
.table-responsive { overflow-x: auto; }
.row-warning { background: #fffbeb !important; }

.text-right { text-align: right; }
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: .78rem; }
.text-success { color: #16a34a; }
.text-warning { color: #d97706; }
.text-danger { color: #dc2626; }
.text-primary { color: var(--primary); }
.font-medium { font-weight: 600; }
.font-bold { font-weight: 700; }

/* =========================
   Badges
========================= */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: .72rem;
  font-weight: 600;
  white-space: nowrap;
}

.badge-blue { background: #eff6ff; color: #2563eb; }
.badge-green { background: #f0fdf4; color: #16a34a; }
.badge-red { background: #fef2f2; color: #dc2626; }
.badge-orange { background: #fff7ed; color: #ea580c; }
.badge-purple { background: #f5f3ff; color: #7c3aed; }

.code-badge {
  display: inline-block;
  background: #f1f5f9;
  color: var(--text-muted);
  font-size: .72rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 6px;
  font-family: monospace;
  letter-spacing: .3px;
  border: 1px solid #e2e8f0;
}

/* =========================
   Buttons
========================= */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: .875rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: all .2s;
  white-space: nowrap;
  line-height: 1;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:hover { background: var(--primary-dark); color: #fff; transform: translateY(-1px); box-shadow: 0 4px 12px rgba(99,102,241,.3); }

.btn-outline {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-outline:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-light); }

.btn-danger {
  background: transparent;
  color: #dc2626;
  border: 1px solid #fecaca;
}
.btn-danger:hover { background: #fef2f2; border-color: #dc2626; }

.btn-block { width: 100%; justify-content: center; }

.btn-sm {
  padding: 5px 10px;
  font-size: .8rem;
}

.d-inline { display: inline; }

.action-buttons {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

/* =========================
   Forms
========================= */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: .82rem; font-weight: 600; color: var(--text); margin-bottom: 6px; }
.required { color: #ef4444; }

.form-input {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: .875rem;
  color: var(--text);
  background: #fff;
  transition: border-color .2s, box-shadow .2s;
  font-family: inherit;
}

.form-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99,102,241,.1);
}

select.form-input { cursor: pointer; }
textarea.form-input { resize: vertical; }

.form-hint { font-size: .75rem; color: var(--text-muted); margin-top: 4px; }

.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 24px;
}

.search-input-wrap {
  position: relative;
  flex: 1;
}

.search-input-wrap i {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
}

.search-input-wrap input {
  padding-left: 36px;
}

/* =========================
   Filter Card
========================= */
.filter-card { padding: 14px 16px; margin-bottom: 16px; }
.filter-form {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.filter-form .form-input { min-width: 140px; }

/* =========================
   Pagination
========================= */
.pagination-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 16px;
  border-top: 1px solid var(--border);
}

.pagination-info { font-size: .82rem; color: var(--text-muted); }

/* =========================
   Empty State
========================= */
.empty-state {
  text-align: center;
  padding: 60px 30px;
  color: var(--text-muted);
}

.empty-state i {
  font-size: 3rem;
  margin-bottom: 16px;
  opacity: .25;
  display: block;
}

.empty-state h3 { font-size: 1rem; font-weight: 600; color: var(--text); margin-bottom: 8px; }
.empty-state p { font-size: .875rem; margin-bottom: 20px; }
.empty-state.small { padding: 30px; }
.empty-state.small i { font-size: 1.8rem; }

/* =========================
   Product Search Autocomplete
========================= */
.product-search-wrap { position: relative; }

.product-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow-md);
  z-index: 100;
  max-height: 260px;
  overflow-y: auto;
  display: none;
}

.product-dropdown.show { display: block; }

.dropdown-item {
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 1px solid #f5f7fa;
  transition: background .15s;
}

.dropdown-item:hover { background: #f0f4ff; }
.dropdown-item:last-child { border-bottom: none; }
.dropdown-item-code { font-size: .72rem; color: var(--text-muted); font-family: monospace; }
.dropdown-item-name { font-size: .875rem; font-weight: 600; color: var(--text); }
.dropdown-item-stock { font-size: .72rem; color: var(--primary); }

.row-total { font-weight: 700; white-space: nowrap; }

/* =========================
   Import Page
========================= */
.import-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.drop-zone {
  border: 2px dashed var(--border);
  border-radius: 12px;
  padding: 40px 20px;
  text-align: center;
  transition: all .2s;
  cursor: pointer;
}

.drop-zone.drag-over {
  border-color: var(--primary);
  background: var(--primary-light);
}

.drop-icon { font-size: 2.5rem; color: var(--primary); opacity: .5; margin-bottom: 12px; }
.drop-text { font-size: .95rem; font-weight: 600; color: var(--text); margin-bottom: 4px; }
.drop-sub { color: var(--text-muted); font-size: .82rem; margin-bottom: 12px; }
.drop-file-name { font-size: .85rem; color: var(--primary); margin-top: 12px; font-weight: 600; }
.hidden { display: none; }

.code-block {
  background: #1e293b;
  color: #e2e8f0;
  padding: 14px 16px;
  border-radius: 8px;
  font-family: monospace;
  font-size: .85rem;
  overflow-x: auto;
}

/* =========================
   Login Page
========================= */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #1e293b 0%, #334155 50%, #1e293b 100%);
}

.login-container {
  width: 100%;
  max-width: 420px;
  padding: 20px;
}

.login-card {
  background: #fff;
  border-radius: 16px;
  padding: 40px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.login-logo {
  text-align: center;
  margin-bottom: 32px;
}

.login-logo-icon {
  width: 60px; height: 60px;
  background: var(--primary);
  border-radius: 16px;
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  font-size: 1.6rem;
  margin: 0 auto 16px;
}

.login-title {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--text);
  margin: 0;
}

.login-subtitle {
  color: var(--text-muted);
  font-size: .875rem;
  margin-top: 4px;
}

.login-form .btn { margin-top: 8px; padding: 12px; font-size: .95rem; }

.login-hint {
  text-align: center;
  color: var(--text-muted);
  font-size: .78rem;
  margin-top: 16px;
}

.input-icon-right { position: relative; }
.input-icon-right input { padding-right: 40px; }
.input-toggle {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: .9rem;
}

/* =========================
   Link styles
========================= */
.link { color: var(--primary); font-weight: 600; }
.link:hover { text-decoration: underline; }

/* =========================
   Modal
========================= */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
  backdrop-filter: blur(4px);
}

.modal {
  background: #fff;
  border-radius: 14px;
  width: 100%;
  max-width: 480px;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
  animation: modalIn .3s ease;
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(.95) translateY(10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header { padding: 20px 24px 0; }
.modal-header h3 { font-size: 1.1rem; font-weight: 700; }
.modal-body { padding: 16px 24px; max-height: 60vh; overflow-y: auto; }
.modal-footer { padding: 16px 24px; border-top: 1px solid var(--border); display: flex; gap: 10px; justify-content: flex-end; }

/* =========================
   Responsive
========================= */
@media (max-width: 1200px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .form-grid-4 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-wrapper { margin-left: 0; }
  .sidebar-toggle { display: flex; }
  .dashboard-grid { grid-template-columns: 1fr; }
  .form-grid-2 { grid-template-columns: 1fr; }
  .import-grid { grid-template-columns: 1fr; }
}

@media (max-width: 600px) {
  .stats-grid { grid-template-columns: 1fr; }
  .page-header { flex-direction: column; }
  .page-content { padding: 16px; }
}
