:root {
  --sidebar-width: 264px;
  --brand: #4f46e5;
  --brand-dark: #4338ca;
  --brand-light: #eef2ff;
  --bg: #f8fafc;
  --surface: #ffffff;
  --border: #e5e7eb;
  --text: #0f172a;
  --text-muted: #64748b;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.1);
  --sidebar-bg: #0b1120;
  --sidebar-bg-hover: rgba(255, 255, 255, 0.06);
  --sidebar-text: #94a3b8;
}

* { box-sizing: border-box; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.app-shell {
  display: flex;
  min-height: 100vh;
}

/* ---------- Sidebar ---------- */

.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  transition: width 0.18s ease;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 1.5rem 1.25rem 1.15rem;
}

.sidebar-toggle {
  margin-left: auto;
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  border: none;
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.06);
  color: #94a3b8;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s ease, color 0.12s ease;
}

.sidebar-toggle:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

/* ---------- Collapsed sidebar ---------- */

html.sidebar-collapsed .sidebar {
  width: 76px;
}

html.sidebar-collapsed .sidebar-brand {
  padding: 1.5rem 0 1.15rem;
  justify-content: center;
  flex-wrap: wrap;
}

html.sidebar-collapsed .sidebar-brand-text {
  display: none;
}

html.sidebar-collapsed .sidebar-toggle {
  margin-left: 0;
  margin-top: 0.6rem;
}

html.sidebar-collapsed .nav-section-label,
html.sidebar-collapsed .nav-label,
html.sidebar-collapsed .user-name {
  display: none;
}

html.sidebar-collapsed .sidebar-nav {
  padding: 0.75rem 0.6rem;
}

html.sidebar-collapsed .sidebar-nav .nav-link {
  justify-content: center;
  padding: 0.6rem;
}

html.sidebar-collapsed .sidebar-nav .nav-link i {
  width: auto;
}

html.sidebar-collapsed .user-chip {
  justify-content: center;
  gap: 0;
  padding: 0.5rem 0.3rem;
}

html.sidebar-collapsed .user-logout {
  margin-left: 4px;
}

.sidebar-brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--brand), #818cf8);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 1.05rem;
  box-shadow: 0 4px 14px rgba(79, 70, 229, 0.45);
  flex-shrink: 0;
}

.sidebar-brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.25;
  min-width: 0;
}

.sidebar-brand-name {
  font-weight: 700;
  font-size: 1rem;
  color: #fff;
  letter-spacing: -0.01em;
}

.sidebar-brand-sub {
  font-size: 0.72rem;
  color: #64748b;
  font-weight: 500;
}

.sidebar-nav {
  padding: 0.4rem 0.9rem 1rem;
  flex: 1;
  overflow-y: auto;
}

.nav-section-label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
  color: #475569;
  padding: 1rem 0.6rem 0.4rem;
}

.nav-section-label:first-child {
  padding-top: 0.4rem;
}

.sidebar-nav .nav-link {
  color: var(--sidebar-text);
  border-radius: 9px;
  padding: 0.55rem 0.7rem;
  margin-bottom: 2px;
  font-size: 0.875rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: background 0.12s ease, color 0.12s ease;
}

.sidebar-nav .nav-link i {
  width: 18px;
  text-align: center;
  font-size: 0.95rem;
}

.sidebar-nav .nav-link:hover {
  background: var(--sidebar-bg-hover);
  color: #fff;
}

.sidebar-nav .nav-link.active {
  background: var(--brand);
  color: #fff;
  box-shadow: 0 2px 10px rgba(79, 70, 229, 0.35);
}

.sidebar-footer {
  padding: 0.9rem;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 12px;
  padding: 0.5rem 0.6rem;
}

.user-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--brand-light);
  color: var(--brand-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.8rem;
  flex-shrink: 0;
}

.user-name {
  flex: 1;
  font-size: 0.82rem;
  font-weight: 600;
  color: #e2e8f0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-logout {
  color: #94a3b8;
  font-size: 1rem;
  padding: 4px 6px;
  border-radius: 6px;
  transition: background 0.12s ease, color 0.12s ease;
}

.user-logout:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.08);
}

/* ---------- Main content ---------- */

.main-content {
  flex: 1;
  padding: 2rem 2.25rem;
  min-width: 0;
}

.topbar {
  margin: -0.5rem 0 0.75rem;
}

.mobile-nav-toggle {
  display: none;
  width: 38px;
  height: 38px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 10px;
  color: var(--text-muted);
  font-size: 1.15rem;
  align-items: center;
  justify-content: center;
}

.mobile-nav-toggle:hover {
  color: var(--brand);
  border-color: #c7d2fe;
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  z-index: 1040;
}

html.mobile-nav-open .sidebar-backdrop {
  display: block;
}

.notif-bell-btn {
  position: relative;
  width: 38px;
  height: 38px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 10px;
  color: var(--text-muted);
  font-size: 1.05rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.notif-bell-btn:hover {
  color: var(--brand);
  border-color: #c7d2fe;
}

.notif-badge {
  position: absolute;
  top: -6px;
  right: -6px;
  font-size: 0.62rem;
  padding: 0.25em 0.42em;
  line-height: 1;
}

.notif-dropdown {
  width: 340px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
}

.notif-item {
  transition: background 0.1s ease;
}

.notif-item:hover {
  background: #f8fafc;
}

#notif-list {
  max-height: 360px;
  overflow-y: auto;
}

.page-header {
  margin-bottom: 1.5rem;
}

.page-header h2 {
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 0.2rem;
  font-size: 1.5rem;
}

.page-header .text-muted {
  font-size: 0.9rem;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.15rem 1.3rem;
  box-shadow: var(--shadow-sm);
}

.stat-value {
  font-size: 1.85rem;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -0.02em;
}

.stat-label {
  color: var(--text-muted);
  font-size: 0.82rem;
  font-weight: 500;
  margin-top: 2px;
}

.dash-card {
  display: flex;
  align-items: center;
  gap: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  text-decoration: none;
  color: inherit;
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
  height: 100%;
}

.dash-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
  border-color: #c7d2fe;
  color: inherit;
}

.dash-card i {
  font-size: 1.4rem;
  color: var(--brand);
  background: var(--brand-light);
  width: 44px;
  height: 44px;
  border-radius: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.dash-card-title {
  font-weight: 700;
  font-size: 0.95rem;
}

.dash-card-sub {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 1px;
}

.card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.card-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 0.92rem;
  border-radius: var(--radius) var(--radius) 0 0 !important;
  padding: 0.85rem 1.1rem;
}

.card-body {
  padding: 1.15rem;
}

/* ---------- Forms & buttons ---------- */

.form-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: #334155;
  margin-bottom: 0.35rem;
}

.form-control,
.form-select {
  border-radius: 9px;
  border-color: var(--border);
  font-size: 0.875rem;
}

.form-control:focus,
.form-select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}

.form-text {
  font-size: 0.78rem;
}

.btn {
  border-radius: 9px;
  font-weight: 600;
  font-size: 0.875rem;
}

.btn-primary {
  background-color: var(--brand);
  border-color: var(--brand);
}

.btn-primary:hover,
.btn-primary:focus,
.btn-primary:active {
  background-color: var(--brand-dark) !important;
  border-color: var(--brand-dark) !important;
}

.btn-outline-primary {
  color: var(--brand);
  border-color: var(--brand);
}

.btn-outline-primary:hover {
  background-color: var(--brand);
  border-color: var(--brand);
}

.btn-outline-secondary {
  border-color: var(--border);
  color: #475569;
}

.btn-outline-secondary:hover {
  background-color: #f1f5f9;
  border-color: #cbd5e1;
  color: var(--text);
}

.text-primary {
  color: var(--brand) !important;
}

/* ---------- Tabs ---------- */

.nav-tabs {
  border-bottom: 1px solid var(--border);
  gap: 0.25rem;
}

.nav-tabs .nav-link {
  border: none;
  border-radius: 9px 9px 0 0;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.875rem;
  padding: 0.6rem 1.05rem;
}

.nav-tabs .nav-link:hover {
  border-color: transparent;
  color: var(--brand);
}

.nav-tabs .nav-link.active {
  color: var(--brand);
  background: var(--brand-light);
  border-color: transparent;
}

/* ---------- Tables ---------- */

.table {
  font-size: 0.875rem;
}

.table thead th {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  font-weight: 700;
  border-bottom: 1px solid var(--border);
  background: #f8fafc;
  white-space: nowrap;
}

.table td,
.table th {
  padding: 0.65rem 0.75rem;
  vertical-align: middle;
}

.table-hover tbody tr:hover {
  background: #f8fafc;
}

.badge {
  font-weight: 600;
  border-radius: 6px;
  padding: 0.38em 0.6em;
  font-size: 0.72rem;
  letter-spacing: 0.01em;
}

.alert {
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: 0.875rem;
}

.list-group-item {
  border-color: var(--border);
  font-size: 0.875rem;
}

.list-group-flush > .list-group-item:last-child {
  border-radius: 0 0 var(--radius) var(--radius);
}

/* ---------- Feature-specific ---------- */

.barcode-preview {
  max-width: 100%;
  max-height: 260px;
  background: #fff;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.pdf-preview {
  width: 100%;
  height: 320px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.camera-wrap {
  background: #000;
  border-radius: var(--radius-sm);
  overflow: hidden;
  max-width: 480px;
  margin: 0 auto;
}

.camera-wrap video {
  width: 100%;
  display: block;
}

.scan-hit {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.75rem;
}

.badge.status-success {
  background: #16a34a;
}

.badge.status-duplicate {
  background: #f59e0b;
}

.badge.status-unrecognized {
  background: #dc2626;
}

.sort-link {
  color: var(--text);
  text-decoration: none;
}

.sort-link:hover {
  color: var(--brand);
}

.bar-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.bar-label {
  width: 90px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.bar-track {
  flex: 1;
  background: #eef0f3;
  border-radius: 6px;
  height: 14px;
  overflow: hidden;
}

.bar-fill {
  background: var(--brand);
  height: 100%;
  border-radius: 6px;
}

.bar-value {
  width: 30px;
  text-align: right;
  font-size: 0.82rem;
  font-weight: 600;
}

/* ---------- Login ---------- */

.login-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at top left, #1e293b 0%, #0b1120 55%, #0b1120 100%);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.login-card {
  width: 100%;
  max-width: 380px;
  border-radius: 18px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
}

.login-mark {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--brand), #818cf8);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  margin: 0 auto 0.75rem;
  box-shadow: 0 6px 18px rgba(79, 70, 229, 0.4);
}

@media (max-width: 768px) {
  /* Off-canvas hamburger menu: the sidebar becomes a fixed panel hidden
     past the left edge until toggled, instead of stacking full-width above
     the content (which used to push everything down on small screens). */
  .sidebar,
  html.sidebar-collapsed .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 280px;
    max-width: 85vw;
    height: 100vh;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    z-index: 1050;
    box-shadow: 0 0 0 rgba(0, 0, 0, 0);
  }
  html.mobile-nav-open .sidebar {
    transform: translateX(0);
    box-shadow: 8px 0 24px rgba(15, 23, 42, 0.25);
  }
  .mobile-nav-toggle {
    display: flex;
  }
  /* The desktop collapse-to-icon-rail toggle doesn't apply to an off-canvas
     panel that's already full width when open - hide it here instead. */
  .sidebar-toggle {
    display: none;
  }
  html.sidebar-collapsed .sidebar-brand-text,
  html.sidebar-collapsed .nav-section-label,
  html.sidebar-collapsed .nav-label,
  html.sidebar-collapsed .user-name {
    display: block;
  }
  html.sidebar-collapsed .sidebar-brand {
    justify-content: flex-start;
    padding: 1.5rem 1.25rem 1.15rem;
  }
  html.sidebar-collapsed .sidebar-nav .nav-link {
    justify-content: flex-start;
    padding: 0.55rem 0.7rem;
  }
  html.sidebar-collapsed .user-chip {
    justify-content: flex-start;
  }
  .main-content {
    padding: 1.25rem;
  }
}
