/* ===== CSS RESET & BASE ===== */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --primary: #1a56db;
  --primary-dark: #1341b1;
  --primary-light: #dbeafe;
  --accent: #7c3aed;
  --success: #059669;
  --success-light: #d1fae5;
  --warning: #d97706;
  --warning-light: #fef3c7;
  --danger: #dc2626;
  --danger-light: #fee2e2;
  --hold: #ea580c;
  --hold-light: #ffedd5;
  --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: 240px;
  --sidebar-collapsed-w: 60px;
  --header-h: 64px;
  --radius: 8px;
  --radius-lg: 12px;
  --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, .07), 0 2px 4px rgba(0, 0, 0, .06);
  --shadow-lg: 0 10px 15px rgba(0, 0, 0, .1), 0 4px 6px rgba(0, 0, 0, .05);
  --transition: .15s ease;
}

html,
body {
  height: 100%;
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 14px;
  color: var(--gray-800);
  background: var(--gray-50);
  overflow: hidden;
}

/* ===== LOGIN PAGE ===== */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0f172a 0%, #1e3a5f 50%, #1a56db 100%);
  position: relative;
  overflow: hidden;
}

.login-page::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 30% 20%, rgba(124, 58, 237, .3) 0%, transparent 60%),
    radial-gradient(ellipse at 70% 80%, rgba(26, 86, 219, .4) 0%, transparent 60%);
}

.login-card {
  background: rgba(255, 255, 255, .97);
  border-radius: 20px;
  padding: 48px 40px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 25px 50px rgba(0, 0, 0, .4);
  position: relative;
  z-index: 1;
  animation: slideUp .4s ease;
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(24px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.login-logo {
  text-align: center;
  margin-bottom: 36px;
}

.logo-icon {
  font-size: 48px;
  margin-bottom: 8px;
  display: block;
  animation: float 3s ease-in-out infinite;
}

@keyframes float {

  0%,
  100% {
    transform: translateY(0);
  }

  50% {
    transform: translateY(-6px);
  }
}

.login-logo h1 {
  font-size: 24px;
  font-weight: 800;
  color: var(--gray-900);
  margin-bottom: 4px;
}

.login-logo p {
  color: var(--gray-500);
  font-size: 13px;
}

.login-hint {
  text-align: center;
  color: var(--gray-400);
  font-size: 12px;
  margin-top: 16px;
}

/* ===== FORMS ===== */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-weight: 600;
  font-size: 13px;
  color: var(--gray-700);
  margin-bottom: 6px;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
select,
textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 14px;
  color: var(--gray-800);
  background: white;
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(26, 86, 219, .1);
}

textarea {
  resize: vertical;
  min-height: 80px;
}

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all var(--transition);
  text-decoration: none;
  white-space: nowrap;
}

.btn:disabled {
  opacity: .5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-dark);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.btn-secondary {
  background: var(--gray-100);
  color: var(--gray-700);
  border: 1.5px solid var(--gray-200);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--gray-200);
}

.btn-success {
  background: var(--success);
  color: white;
}

.btn-success:hover:not(:disabled) {
  background: #047857;
}

.btn-warning {
  background: var(--warning);
  color: white;
}

.btn-warning:hover:not(:disabled) {
  background: #b45309;
}

.btn-danger {
  background: var(--danger);
  color: white;
}

.btn-danger:hover:not(:disabled) {
  background: #b91c1c;
}

.btn-hold {
  background: var(--hold);
  color: white;
}

.btn-hold:hover:not(:disabled) {
  background: #c2410c;
}

.btn-ghost {
  background: transparent;
  color: var(--gray-600);
}

.btn-ghost:hover {
  background: var(--gray-100);
}

.btn-sm {
  padding: 6px 12px;
  font-size: 12px;
}

.btn-full {
  width: 100%;
  justify-content: center;
  padding: 12px;
}

.btn-icon {
  padding: 7px;
}

/* ===== ALERTS / STATUS ===== */
.alert {
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  margin-top: 10px;
}

.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 #6ee7b7;
}

.alert-warning {
  background: var(--warning-light);
  color: var(--warning);
  border: 1px solid #fcd34d;
}

.hidden {
  display: none !important;
}

/* ===== STATUS BADGES ===== */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
}

.badge-registered {
  background: var(--primary-light);
  color: var(--primary);
}

.badge-picked {
  background: #ede9fe;
  color: var(--accent);
}

.badge-hold {
  background: var(--hold-light);
  color: var(--hold);
}

.badge-shipped {
  background: var(--success-light);
  color: var(--success);
}

.badge-instock {
  background: var(--success-light);
  color: var(--success);
}

.badge-reserved {
  background: var(--warning-light);
  color: var(--warning);
}

/* ===== LAYOUT ===== */
#app {
  height: 100vh;
  display: flex;
}

#main-app {
  display: flex;
  width: 100%;
  height: 100vh;
  overflow: hidden;
}

/* ===== SIDEBAR ===== */
.sidebar {
  width: var(--sidebar-w);
  height: 100vh;
  background: var(--gray-900);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width .25s ease;
  flex-shrink: 0;
  position: relative;
  z-index: 50;
}

.sidebar.collapsed {
  width: var(--sidebar-collapsed-w);
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  border-bottom: 1px solid var(--gray-800);
  min-height: 64px;
  flex-shrink: 0;
}

.sidebar-logo {
  font-size: 22px;
  flex-shrink: 0;
  line-height: 1;
}

.sidebar-title {
  color: white;
  font-weight: 800;
  font-size: 15px;
  white-space: nowrap;
  max-width: 140px;
  overflow: hidden;
  transition: max-width .25s ease, opacity .25s ease;
  opacity: 1;
}

.sidebar.collapsed .sidebar-title {
  max-width: 0;
  opacity: 0;
}

.sidebar-toggle-btn {
  background: none;
  border: none;
  color: var(--gray-400);
  cursor: pointer;
  font-size: 18px;
  margin-left: auto;
  padding: 0;
  border-radius: 6px;
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sidebar.collapsed .sidebar-header {
  justify-content: center;
  padding: 0 8px;
}

.sidebar.collapsed .sidebar-logo {
  display: none;
}

.sidebar.collapsed .sidebar-toggle-btn {
  margin-left: 0;
}

.sidebar-toggle-btn:hover {
  background: var(--gray-700);
  color: white;
}

.sidebar-nav {
  flex: 1;
  padding: 12px 8px;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 10px;
  border-radius: 8px;
  color: var(--gray-400);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  transition: all var(--transition);
  white-space: nowrap;
  min-width: 0;
}

.nav-item:hover {
  background: var(--gray-800);
  color: white;
}

.nav-item.active {
  background: var(--primary);
  color: white;
}

.sidebar.collapsed .nav-item {
  justify-content: center;
  padding: 9px 0;
}

.nav-icon {
  font-size: 18px;
  flex-shrink: 0;
  line-height: 1;
}

.nav-label {
  overflow: hidden;
  max-width: 160px;
  opacity: 1;
  white-space: nowrap;
  transition: max-width .25s ease, opacity .25s ease;
}

.sidebar.collapsed .nav-label {
  max-width: 0;
  opacity: 0;
}

.nav-divider {
  height: 1px;
  background: var(--gray-800);
  margin: 6px 0;
}

.sidebar-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 12px;
  border-top: 1px solid var(--gray-800);
  overflow: hidden;
  min-height: 60px;
}

.sidebar.collapsed .sidebar-footer {
  justify-content: center;
  padding: 12px 8px;
}

.user-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  flex-shrink: 0;
}

.user-details {
  overflow: hidden;
  transition: opacity .2s;
}

.sidebar.collapsed .user-details {
  opacity: 0;
  width: 0;
}

.user-name {
  font-weight: 600;
  font-size: 12px;
  color: white;
  white-space: nowrap;
}

.user-role {
  font-size: 11px;
  color: var(--gray-400);
}

.btn-logout {
  background: none;
  border: none;
  color: var(--gray-400);
  cursor: pointer;
  font-size: 17px;
  padding: 6px;
  border-radius: 6px;
  margin-left: auto;
  flex-shrink: 0;
}

.btn-logout:hover {
  background: var(--gray-800);
  color: white;
}

/* ===== MAIN CONTENT ===== */
.main-content {
  flex: 1;
  overflow-y: auto;
  background: var(--gray-50);
}

.page {
  display: none;
  padding: 24px 28px;
  min-height: 100%;
}

.page.active {
  display: block;
  animation: fadeIn .2s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 12px;
}

.page-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.page-header h2 {
  font-size: 20px;
  font-weight: 800;
  color: var(--gray-900);
}

.page-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.btn-back {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  padding: 6px 10px;
  border-radius: var(--radius);
  transition: background var(--transition);
}

.btn-back:hover {
  background: var(--primary-light);
}

/* ===== SEARCH & FILTERS ===== */
.search-input {
  max-width: 220px;
  padding: 8px 12px;
}

.select-input {
  max-width: 160px;
  padding: 8px 12px;
}

/* ===== CARDS ===== */
.card {
  background: white;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  border: 1px solid var(--gray-200);
}

.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: 14px;
  font-weight: 700;
  color: var(--gray-800);
}

.card-body {
  padding: 20px;
}

/* ===== DASHBOARD ===== */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: white;
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow);
  border: 1px solid var(--gray-200);
  transition: transform var(--transition), box-shadow var(--transition);
  cursor: default;
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.stat-number {
  font-size: 36px;
  font-weight: 800;
  color: var(--gray-900);
  line-height: 1;
  margin-bottom: 6px;
}

.stat-label {
  font-size: 12px;
  color: var(--gray-500);
  font-weight: 500;
}

.stat-card.primary .stat-number {
  color: var(--primary);
}

.stat-card.warning .stat-number {
  color: var(--warning);
}

.stat-card.hold .stat-number {
  color: var(--hold);
}

.stat-card.success .stat-number {
  color: var(--success);
}

.stat-card.danger .stat-number {
  color: var(--danger);
}

.dashboard-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 20px;
}

@media (max-width: 900px) {
  .dashboard-row {
    grid-template-columns: 1fr;
  }
}

/* ===== TABLES ===== */
.table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

table {
  width: 100%;
  border-collapse: collapse;
  background: white;
}

th {
  padding: 11px 16px;
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--gray-500);
  background: var(--gray-50);
  border-bottom: 1px solid var(--gray-200);
  white-space: nowrap;
}

td {
  padding: 12px 16px;
  font-size: 13px;
  color: var(--gray-700);
  border-bottom: 1px solid var(--gray-100);
  vertical-align: middle;
}

tr:last-child td {
  border-bottom: none;
}

tr:hover td {
  background: var(--gray-50);
}

.table-link {
  color: var(--primary);
  font-weight: 600;
  cursor: pointer;
  background: none;
  border: none;
  font-size: 13px;
  padding: 0;
  text-decoration: none;
}

.table-link:hover {
  text-decoration: underline;
}

/* ===== ORDER DETAIL ===== */
.order-meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.meta-item {
  background: white;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 14px 16px;
}

.meta-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--gray-400);
  margin-bottom: 5px;
}

.meta-value {
  font-size: 14px;
  font-weight: 600;
  color: var(--gray-800);
}

.order-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
  border-bottom: 2px solid var(--gray-200);
}

.tab-btn {
  padding: 8px 18px;
  background: none;
  border: none;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--gray-500);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all var(--transition);
}

.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.tab-btn:hover {
  color: var(--gray-800);
}

.tab-pane {
  display: none;
}

.tab-pane.active {
  display: block;
  animation: fadeIn .2s;
}

.package-card {
  background: white;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg);
  margin-bottom: 16px;
  overflow: hidden;
}

.package-header {
  padding: 12px 16px;
  background: var(--primary-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.package-header h4 {
  color: var(--primary);
  font-weight: 700;
  font-size: 13px;
}

.package-dims {
  font-size: 12px;
  color: var(--gray-500);
}

.package-body {
  padding: 16px;
}

/* ===== MODAL ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .55);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn .15s ease;
}

.modal {
  background: white;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  animation: slideUp .2s ease;
}

.modal-header {
  padding: 20px 24px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--gray-100);
}

.modal-header h3 {
  font-size: 16px;
  font-weight: 700;
}

.modal-close {
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  color: var(--gray-400);
  padding: 4px;
  border-radius: 4px;
}

.modal-close:hover {
  background: var(--gray-100);
  color: var(--gray-700);
}

.modal-body {
  padding: 20px 24px;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--gray-100);
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.modal-lg {
  max-width: 700px;
}

.modal-xl {
  max-width: 900px;
}

/* ===== TOASTS ===== */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toast {
  padding: 12px 18px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  animation: slideIn .25s ease;
  max-width: 320px;
  display: flex;
  align-items: center;
  gap: 10px;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateX(40px);
  }

  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.toast-success {
  background: #064e3b;
  color: #a7f3d0;
}

.toast-error {
  background: #7f1d1d;
  color: #fca5a5;
}

.toast-info {
  background: #1e3a5f;
  color: #bfdbfe;
}

.toast-warning {
  background: #78350f;
  color: #fde68a;
}

/* ===== MISC ===== */
.loading-spinner {
  text-align: center;
  padding: 48px;
  color: var(--gray-400);
  font-size: 14px;
}

.empty-state {
  text-align: center;
  padding: 60px 24px;
  color: var(--gray-400);
}

.empty-state .empty-icon {
  font-size: 48px;
  margin-bottom: 12px;
}

.empty-state h3 {
  font-size: 16px;
  color: var(--gray-600);
  margin-bottom: 6px;
}

.text-muted {
  color: var(--gray-400);
  font-size: 12px;
}

.text-right {
  text-align: right;
}

.flex {
  display: flex;
}

.flex-wrap {
  flex-wrap: wrap;
}

.items-center {
  align-items: center;
}

.gap-2 {
  gap: 8px;
}

.gap-3 {
  gap: 12px;
}

.mt-2 {
  margin-top: 8px;
}

.mt-4 {
  margin-top: 16px;
}

.mb-4 {
  margin-bottom: 16px;
}

.divider {
  height: 1px;
  background: var(--gray-200);
  margin: 16px 0;
}

.section-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--gray-600);
  text-transform: uppercase;
  letter-spacing: .5px;
  margin-bottom: 12px;
}

.low-stock-alert {
  background: var(--danger-light);
  border: 1px solid #fca5a5;
  border-radius: var(--radius);
  padding: 8px 12px;
  font-size: 12px;
  color: var(--danger);
  font-weight: 600;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.admin-only {
  display: revert;
}

/* visibility controlled by JS applyRole() */

/* ===== ARTICLE SEARCH DROPDOWN ===== */
.article-search-box {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  margin-bottom: 6px;
  flex-wrap: wrap;
}

.article-search-box>div {
  flex: 1;
  min-width: 200px;
}

.art-dropdown {
  position: absolute;
  top: calc(100% + 2px);
  left: 0;
  right: 0;
  z-index: 200;
  background: white;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  max-height: 260px;
  overflow-y: auto;
}

.art-dd-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--gray-100);
  transition: background .1s;
  flex-wrap: wrap;
}

.art-dd-item:last-child {
  border-bottom: none;
}

.art-dd-item:hover {
  background: var(--primary-light);
}

.art-dd-num {
  font-family: monospace;
  font-size: 12px;
  font-weight: 700;
  color: var(--gray-800);
  min-width: 90px;
}

.art-dd-cust {
  font-size: 11px;
  color: var(--primary);
  font-weight: 600;
  background: var(--primary-light);
  padding: 1px 6px;
  border-radius: 4px;
}

.art-dd-name {
  flex: 1;
  font-size: 13px;
  color: var(--gray-700);
}

.art-dd-stock {
  font-size: 11px;
  font-weight: 700;
  color: var(--success);
  margin-left: auto;
}

.art-dd-stock-low {
  color: var(--danger);
}

/* ===== CANCELLED / MAKULERAD STATUS ===== */
.badge-cancelled {
  background: #f1f5f9;
  color: #64748b;
}

/* ===== PICKING WIZARD ===== */
.pick-wizard-row {
  background: white;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.pick-wizard-row.done {
  border-color: var(--success);
  background: var(--success-light);
}

.pick-wizard-art {
  font-weight: 700;
  font-size: 13px;
  min-width: 120px;
}

.pick-wizard-remaining {
  font-size: 12px;
  color: var(--warning);
  font-weight: 600;
}

.pick-wizard-remaining.zero {
  color: var(--success);
}

/* ===== SIDEBAR – always show logout, collapse safely ===== */
.sidebar.collapsed .btn-logout {
  margin: 0 auto;
}

.sidebar.collapsed .sidebar-footer {
  justify-content: center;
  padding: 12px 8px;
}

/* ===== ORDER DETAIL misc ===== */
.mb-4 {
  margin-bottom: 16px;
}