/* ============================================
   DESIGN TOKENS
   ============================================ */
:root {
  --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;

  /* Palette: Neutral */
  --neutral-50:  #fafafa;
  --neutral-100: #f5f5f5;
  --neutral-200: #e5e5e5;
  --neutral-300: #d4d4d4;
  --neutral-400: #a3a3a3;
  --neutral-500: #737373;
  --neutral-600: #525252;
  --neutral-700: #404040;
  --neutral-800: #262626;
  --neutral-900: #171717;
  --neutral-950: #0a0a0a;

  /* Palette: Blue (Brand) */
  --blue-50:  #eff6ff;
  --blue-100: #dbeafe;
  --blue-200: #bfdbfe;
  --blue-300: #93c5fd;
  --blue-400: #60a5fa;
  --blue-500: #3b82f6;
  --blue-600: #2563eb;
  --blue-700: #1d4ed8;
  --blue-800: #1e40af;
  --blue-900: #1e3a8a;

  /* Palette: Slate (sidebar/structure) */
  --slate-50:  #f8fafc;
  --slate-100: #f1f5f9;
  --slate-200: #e2e8f0;
  --slate-300: #cbd5e1;
  --slate-400: #94a3b8;
  --slate-500: #64748b;
  --slate-600: #475569;
  --slate-700: #334155;
  --slate-800: #1e293b;
  --slate-900: #0f172a;
  --slate-950: #020617;

  /* Status */
  --emerald-50:  #ecfdf5;
  --emerald-100: #d1fae5;
  --emerald-500: #10b981;
  --emerald-600: #059669;
  --emerald-700: #047857;

  --red-50:  #fef2f2;
  --red-100: #fee2e2;
  --red-500: #ef4444;
  --red-600: #dc2626;
  --red-700: #b91c1c;

  --amber-50:  #fffbeb;
  --amber-100: #fef3c7;
  --amber-400: #fbbf24;
  --amber-500: #f59e0b;
  --amber-600: #d97706;
  --amber-700: #b45309;

  /* Semantic - Light Mode */
  --primary:       var(--blue-600);
  --primary-hover: var(--blue-700);
  --primary-light: var(--blue-50);
  --primary-text:  #ffffff;

  --bg-body:    #f0f2f5;
  --bg-card:    #ffffff;
  --bg-sidebar: #ffffff;
  --bg-input:   #ffffff;
  --bg-hover:   var(--neutral-100);

  --text-primary:   #111827;
  --text-secondary: #4b5563;
  --text-muted:     #9ca3af;
  --text-inverse:   #ffffff;

  --border-color: #e5e7eb;
  --border-light: #f3f4f6;
  --border-focus: var(--blue-500);

  /* Shadows */
  --shadow-xs: 0 1px 2px rgba(0,0,0,.04);
  --shadow-sm: 0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,.07), 0 2px 4px -2px rgba(0,0,0,.05);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,.07), 0 4px 6px -4px rgba(0,0,0,.05);
  --shadow-xl: 0 20px 25px -5px rgba(0,0,0,.08), 0 8px 10px -6px rgba(0,0,0,.06);
  --shadow-2xl: 0 25px 50px -12px rgba(0,0,0,.14);

  /* Border Radius */
  --radius-sm:   0.375rem;
  --radius:      0.5rem;
  --radius-md:   0.625rem;
  --radius-lg:   0.75rem;
  --radius-xl:   1rem;
  --radius-2xl:  1.25rem;
  --radius-full: 9999px;

  /* Transitions */
  --t-fast: all 0.12s ease;
  --t:      all 0.18s ease;
  --t-slow: all 0.28s ease;

  /* Spacing */
  --sp-1: 0.25rem;
  --sp-2: 0.5rem;
  --sp-3: 0.75rem;
  --sp-4: 1rem;
  --sp-5: 1.25rem;
  --sp-6: 1.5rem;
  --sp-8: 2rem;
  --sp-10: 2.5rem;
  --sp-12: 3rem;

  /* Sidebar */
  --sidebar-width: 256px;
}

/* ============================================
   DARK MODE
   ============================================ */
[data-theme="dark"] {
  --bg-body:    #0d1117;
  --bg-card:    #161b22;
  --bg-sidebar: #161b22;
  --bg-input:   #21262d;
  --bg-hover:   #21262d;

  --text-primary:   #e6edf3;
  --text-secondary: #8b949e;
  --text-muted:     #6e7681;

  --border-color: #30363d;
  --border-light: #21262d;
  --border-focus: var(--blue-400);

  --shadow-xs: 0 1px 2px rgba(0,0,0,.3);
  --shadow-sm: 0 1px 3px rgba(0,0,0,.35);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,.4), 0 2px 4px -2px rgba(0,0,0,.3);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,.45), 0 4px 6px -4px rgba(0,0,0,.35);
  --shadow-xl: 0 20px 25px -5px rgba(0,0,0,.5), 0 8px 10px -6px rgba(0,0,0,.4);
  --shadow-2xl: 0 25px 50px -12px rgba(0,0,0,.6);
}

/* ============================================
   RESET & BASE
   ============================================ */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html { scroll-behavior: smooth; }

body {
  font-family: var(--font-family);
  background-color: var(--bg-body);
  color: var(--text-primary);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background-color 0.2s ease, color 0.2s ease;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--neutral-300); border-radius: var(--radius-full); }
::-webkit-scrollbar-thumb:hover { background: var(--neutral-400); }
[data-theme="dark"] ::-webkit-scrollbar-thumb { background: var(--slate-700); }
[data-theme="dark"] ::-webkit-scrollbar-thumb:hover { background: var(--slate-600); }

/* Selection */
::selection { background: var(--blue-100); color: var(--blue-900); }
[data-theme="dark"] ::selection { background: var(--blue-800); color: var(--blue-100); }

/* ============================================
   BUTTONS
   ============================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  padding: 0.5rem 1rem;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-family: var(--font-family);
  font-weight: 500;
  font-size: 0.875rem;
  line-height: 1.4;
  letter-spacing: 0.01em;
  cursor: pointer;
  white-space: nowrap;
  transition: var(--t);
  text-decoration: none;
}

.btn:active { transform: scale(0.97); }

.btn-primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  box-shadow: 0 1px 3px rgba(37,99,235,.2);
}
.btn-primary:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
  box-shadow: 0 2px 6px rgba(37,99,235,.3);
}

.btn-secondary {
  background: var(--bg-card);
  border-color: var(--border-color);
  color: var(--text-secondary);
}
.btn-secondary:hover {
  background: var(--bg-hover);
  border-color: var(--neutral-300);
  color: var(--text-primary);
}
[data-theme="dark"] .btn-secondary:hover {
  background: var(--slate-700);
  border-color: var(--slate-600);
}

.btn-success {
  background: var(--emerald-600);
  color: #fff;
  border-color: var(--emerald-600);
  box-shadow: 0 1px 3px rgba(5,150,105,.2);
}
.btn-success:hover {
  background: var(--emerald-700);
  border-color: var(--emerald-700);
}

.btn-danger {
  background: var(--red-600);
  color: #fff;
  border-color: var(--red-600);
}
.btn-danger:hover { background: var(--red-700); border-color: var(--red-700); }

.btn-warning {
  background: var(--amber-500);
  color: #fff;
  border-color: var(--amber-500);
}
.btn-warning:hover { background: var(--amber-600); border-color: var(--amber-600); }

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

.btn-outline-secondary {
  background: transparent;
  border-color: var(--border-color);
  color: var(--text-secondary);
}
.btn-outline-secondary:hover {
  background: var(--bg-hover);
  border-color: var(--neutral-300);
  color: var(--text-primary);
}
[data-theme="dark"] .btn-outline-secondary:hover {
  border-color: var(--slate-600);
}

.btn-outline-success {
  background: transparent;
  border-color: var(--emerald-600);
  color: var(--emerald-600);
}
.btn-outline-success:hover { background: var(--emerald-600); color: #fff; }

.btn-outline-danger {
  background: transparent;
  border-color: var(--red-600);
  color: var(--red-600);
}
.btn-outline-danger:hover { background: var(--red-600); color: #fff; }

.btn-outline-warning {
  background: transparent;
  border-color: var(--amber-500);
  color: var(--amber-600);
}
.btn-outline-warning:hover { background: var(--amber-500); color: #fff; }

.btn-sm { padding: 0.375rem 0.75rem; font-size: 0.8125rem; }
.btn-lg { padding: 0.625rem 1.25rem; font-size: 1rem; }

.btn-icon {
  padding: 0.5rem;
  border-radius: var(--radius);
}
.btn-icon i { font-size: 1rem; }

/* Button Group */
.btn-group { display: inline-flex; }
.btn-group > .btn { position: relative; flex: 1 1 auto; }
.btn-group > .btn:not(:first-child) {
  margin-left: -1px;
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
}
.btn-group > .btn:not(:last-child) {
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
}

/* ============================================
   CARDS
   ============================================ */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.card-header {
  padding: var(--sp-5) var(--sp-6);
  border-bottom: 1px solid var(--border-color);
  background: transparent;
}

.card-body { padding: var(--sp-6); }

.card-footer {
  padding: var(--sp-4) var(--sp-6);
  border-top: 1px solid var(--border-color);
  background: var(--bg-hover);
}
[data-theme="dark"] .card-footer { background: rgba(255,255,255,.02); }

/* ============================================
   FORM ELEMENTS
   ============================================ */
.form-control {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 0.5625rem 0.875rem;
  font-family: var(--font-family);
  font-size: 0.9375rem;
  color: var(--text-primary);
  transition: var(--t);
  outline: none;
}
.form-control:hover { border-color: var(--neutral-400); }
[data-theme="dark"] .form-control:hover { border-color: var(--slate-500); }
.form-control:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(59,130,246,.15);
}
[data-theme="dark"] .form-control {
  background: var(--bg-input);
  color: var(--text-primary);
}
[data-theme="dark"] .form-control:focus {
  background: var(--bg-input);
  box-shadow: 0 0 0 3px rgba(96,165,250,.18);
}
.form-control::placeholder { color: var(--text-muted); }
.form-control:disabled {
  background: var(--bg-hover);
  opacity: 0.6;
  cursor: not-allowed;
}

/* Autofill */
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
textarea:-webkit-autofill,
select:-webkit-autofill {
  -webkit-box-shadow: 0 0 0 1000px var(--bg-input) inset !important;
  -webkit-text-fill-color: var(--text-primary) !important;
  transition: background-color 5000s ease-in-out 0s;
}
[data-theme="dark"] input:-webkit-autofill,
[data-theme="dark"] input:-webkit-autofill:hover,
[data-theme="dark"] input:-webkit-autofill:focus,
[data-theme="dark"] textarea:-webkit-autofill,
[data-theme="dark"] select:-webkit-autofill {
  -webkit-box-shadow: 0 0 0 1000px var(--slate-800) inset !important;
  -webkit-text-fill-color: var(--text-primary) !important;
}

.form-label {
  display: block;
  font-weight: 500;
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-bottom: var(--sp-2);
}

.form-group { margin-bottom: var(--sp-5); }
.form-text { font-size: 0.8125rem; color: var(--text-muted); margin-top: var(--sp-1); }

/* Floating label */
.form-floating { position: relative; }
.form-floating > .form-control { padding-top: var(--sp-6); padding-bottom: var(--sp-2); }
.form-floating > label {
  position: absolute;
  top: 0; left: 0;
  height: 100%;
  padding: var(--sp-3) var(--sp-4);
  pointer-events: none;
  transform-origin: 0 0;
  transition: var(--t);
  color: var(--text-muted);
  font-weight: 500;
  border: 1px solid transparent;
}
.form-floating > .form-control:focus ~ label,
.form-floating > .form-control:not(:placeholder-shown) ~ label {
  transform: scale(0.85) translateY(-0.5rem) translateX(0.15rem);
  color: var(--primary);
}

/* Input Group */
.input-group {
  position: relative;
  display: flex;
  align-items: stretch;
  width: 100%;
}
.input-group-text {
  display: flex;
  align-items: center;
  padding: 0.5625rem 0.875rem;
  font-size: 0.9375rem;
  color: var(--text-secondary);
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  white-space: nowrap;
}
[data-theme="dark"] .input-group-text {
  background: var(--slate-800);
  border-color: var(--slate-700);
  color: var(--slate-400);
}
.input-group > .form-control { position: relative; flex: 1 1 auto; width: 1%; min-width: 0; }
.input-group > .form-control:focus { z-index: 3; }
.input-group > :not(:first-child) { margin-left: -1px; border-top-left-radius: 0; border-bottom-left-radius: 0; }
.input-group > :not(:last-child) { border-top-right-radius: 0; border-bottom-right-radius: 0; }

/* Input icon helper */
.input-icon {
  position: absolute;
  left: var(--sp-4);
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 1.125rem;
  z-index: 10;
  pointer-events: none;
  transition: var(--t);
}
.input-group:focus-within .input-icon { color: var(--primary); }
[data-theme="dark"] .input-icon { color: var(--slate-400); }

/* Form Select */
.form-select {
  width: 100%;
  background-color: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 0.5625rem 2.5rem 0.5625rem 0.875rem;
  font-family: var(--font-family);
  font-size: 0.9375rem;
  color: var(--text-primary);
  transition: var(--t);
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 5 6 6 6-6'/%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right 0.875rem center;
  background-size: 14px 10px;
  outline: none;
}
[data-theme="dark"] .form-select { background-color: var(--bg-input); color: var(--text-primary); }
.form-select:hover { border-color: var(--neutral-400); }
[data-theme="dark"] .form-select:hover { border-color: var(--slate-500); }
.form-select:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(59,130,246,.15);
}
[data-theme="dark"] .form-select:focus {
  background-color: var(--bg-input) !important;
  color: var(--text-primary) !important;
}

textarea.form-control { min-height: 100px; resize: vertical; }

/* Checkbox / Radio */
.form-check { display: flex; align-items: center; gap: var(--sp-3); margin-bottom: var(--sp-2); }
.form-check-input {
  width: 1.125rem;
  height: 1.125rem;
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  cursor: pointer;
  transition: var(--t);
  appearance: none;
  flex-shrink: 0;
}
.form-check-input:checked {
  background-color: var(--primary);
  border-color: var(--primary);
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3e%3cpath fill='none' stroke='%23fff' stroke-linecap='round' stroke-linejoin='round' stroke-width='3' d='m6 10 3 3 6-6'/%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: center;
  background-size: 12px;
}
.form-check-input:focus { border-color: var(--border-focus); box-shadow: 0 0 0 3px rgba(59,130,246,.15); outline: none; }
.form-check-label { font-size: 0.9375rem; color: var(--text-secondary); cursor: pointer; user-select: none; }

/* ============================================
   ALERTS
   ============================================ */
.alert {
  border-radius: var(--radius-lg);
  padding: var(--sp-4) var(--sp-5);
  margin-bottom: var(--sp-4);
  border: 1px solid transparent;
  font-size: 0.9375rem;
  font-weight: 500;
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
}
.alert::before { font-family: 'bootstrap-icons'; font-size: 1.125rem; flex-shrink: 0; }

.alert-danger  { background: var(--red-50);    color: var(--red-700);    border-color: var(--red-100);    }
.alert-success { background: var(--emerald-50); color: var(--emerald-700); border-color: var(--emerald-100); }
.alert-warning { background: var(--amber-50);  color: var(--amber-700);  border-color: var(--amber-100);  }
.alert-info    { background: var(--blue-50);   color: var(--blue-700);   border-color: var(--blue-100);   }

.alert-danger::before  { content: '\F332'; }
.alert-success::before { content: '\F26B'; }
.alert-warning::before { content: '\F33A'; }
.alert-info::before    { content: '\F430'; }

[data-theme="dark"] .alert-danger  { background: rgba(239,68,68,.08);   color: #fca5a5; border-color: rgba(239,68,68,.15);  }
[data-theme="dark"] .alert-success { background: rgba(16,185,129,.08);  color: #6ee7b7; border-color: rgba(16,185,129,.15); }
[data-theme="dark"] .alert-warning { background: rgba(245,158,11,.08);  color: #fcd34d; border-color: rgba(245,158,11,.15); }
[data-theme="dark"] .alert-info    { background: rgba(59,130,246,.08);  color: #93c5fd; border-color: rgba(59,130,246,.15); }

/* ============================================
   BADGES
   ============================================ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 0.2em 0.6em;
  border-radius: var(--radius-full);
  font-weight: 600;
  font-size: 0.75rem;
  letter-spacing: 0.03em;
}
.badge::before {
  content: '';
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}

.badge-primary  { background: var(--blue-100);    color: var(--blue-700);    }
.badge-success  { background: var(--emerald-100); color: var(--emerald-700); }
.badge-danger   { background: var(--red-100);     color: var(--red-700);     }
.badge-warning  { background: var(--amber-100);   color: var(--amber-700);   }

[data-theme="dark"] .badge-primary  { background: rgba(59,130,246,.15); color: #93c5fd; }
[data-theme="dark"] .badge-success  { background: rgba(16,185,129,.15); color: #6ee7b7; }
[data-theme="dark"] .badge-danger   { background: rgba(239,68,68,.15);  color: #fca5a5; }
[data-theme="dark"] .badge-warning  { background: rgba(245,158,11,.15); color: #fcd34d; }

/* Bootstrap bg-primary etc */
.bg-primary { background: var(--primary) !important; color: #fff !important; }

/* Status connected/disconnected */
.status-connected    { background: var(--emerald-100); color: var(--emerald-600); }
.status-disconnected { background: var(--red-100);     color: var(--red-600);     }
.status-connected::before    { background: var(--emerald-600); }
.status-disconnected::before { background: var(--red-600); }
[data-theme="dark"] .status-connected    { background: rgba(16,185,129,.15); color: #34d399; }
[data-theme="dark"] .status-disconnected { background: rgba(239,68,68,.15);  color: #f87171; }

/* ============================================
   MODALS
   ============================================ */
.modal {
  position: fixed; top: 0; left: 0;
  z-index: 1050; display: none;
  width: 100%; height: 100%;
  overflow-x: hidden; overflow-y: auto;
}
.modal.show { display: block; }

.modal-dialog {
  position: relative;
  width: auto;
  margin: 1.75rem auto;
  max-width: 500px;
  pointer-events: none;
}
.modal-dialog-centered { display: flex; align-items: center; min-height: calc(100% - 3.5rem); }
.modal-dialog-centered .modal-content { max-height: calc(100vh - 3.5rem); }
.modal-dialog-centered .modal-body { overflow-y: auto; }
.modal-dialog.modal-lg  { max-width: 780px; }
.modal-dialog.modal-xl  { max-width: 1100px; }

.modal-content {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  pointer-events: auto;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-2xl);
  outline: 0;
  animation: modalSlideIn 0.22s ease-out;
}
@keyframes modalSlideIn {
  from { opacity: 0; transform: translateY(-16px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--sp-5) var(--sp-6);
  border-bottom: 1px solid var(--border-color);
}
.modal-header .modal-title {
  font-weight: 600;
  font-size: 1rem;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

.modal-body {
  padding: var(--sp-6);
  flex: 1 1 auto;
  background: var(--bg-card);
  color: var(--text-primary);
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-6);
  border-top: 1px solid var(--border-color);
  background: var(--bg-hover);
  border-radius: 0 0 var(--radius-xl) var(--radius-xl);
}
[data-theme="dark"] .modal-footer { background: rgba(255,255,255,.02); }

/* Dark modal overrides */
[data-theme="dark"] .modal-content { background: var(--bg-card); border-color: var(--border-color); }
[data-theme="dark"] .modal-header  { background: rgba(255,255,255,.02); border-color: var(--border-color); }
[data-theme="dark"] .modal-body    { background: var(--bg-card); }
[data-theme="dark"] .modal-body h2,
[data-theme="dark"] .modal-body h3,
[data-theme="dark"] .modal-body h4,
[data-theme="dark"] .modal-body h5 { color: var(--text-primary); }
[data-theme="dark"] .modal-body .text-muted { color: var(--text-muted) !important; }
[data-theme="dark"] .modal-body .table      { color: var(--text-primary); }
[data-theme="dark"] .modal-body .table thead th { background: var(--bg-hover); border-color: var(--border-color); }
[data-theme="dark"] .modal-body .table tbody td { border-color: var(--border-color); }

.btn-close {
  width: 1.875rem; height: 1.875rem;
  padding: 0; background: transparent; border: none;
  cursor: pointer; display: flex; align-items: center;
  justify-content: center; border-radius: var(--radius);
  transition: var(--t); color: var(--text-muted);
}
.btn-close:hover { background: var(--bg-hover); color: var(--text-primary); }
[data-theme="dark"] .btn-close:hover { background: var(--slate-700); }
.btn-close::before { content: '\F62A'; font-family: 'bootstrap-icons'; font-size: 1.125rem; }

/* Modal Backdrop */
.modal-backdrop {
  position: fixed; top: 0; left: 0; z-index: 1040;
  width: 100vw; height: 100vh;
  background: rgba(0,0,0,.45);
  backdrop-filter: blur(3px);
  opacity: 0; transition: opacity 0.25s ease;
}
.modal-backdrop.show { opacity: 1; }

/* ============================================
   DROPDOWNS
   ============================================ */
.dropdown { position: relative; }

.dropdown-menu {
  position: absolute;
  z-index: 1000;
  display: none;
  min-width: 11rem;
  padding: var(--sp-2);
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  animation: dropdownIn 0.15s ease-out;
}
.dropdown-menu.show { display: block; }
@keyframes dropdownIn {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  width: 100%;
  padding: var(--sp-2) var(--sp-3);
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 500;
  text-decoration: none;
  background: transparent;
  border: 0;
  border-radius: var(--radius);
  cursor: pointer;
  transition: var(--t-fast);
}
.dropdown-item:hover { background: var(--bg-hover); color: var(--text-primary); }
[data-theme="dark"] .dropdown-item:hover { background: var(--slate-700); }
.dropdown-item i { font-size: 1rem; }

.dropdown-divider { height: 0; margin: var(--sp-1) 0; border-top: 1px solid var(--border-color); }

.dropdown-toggle::after {
  content: '';
  display: inline-block;
  margin-left: var(--sp-2);
  vertical-align: middle;
  border-top: 0.3em solid;
  border-right: 0.3em solid transparent;
  border-left: 0.3em solid transparent;
  transition: var(--t-fast);
}
.dropdown-toggle.show::after { transform: rotate(180deg); }

/* NEW CUSTOMER dropdown item dark */
[data-theme="dark"] .dropdown-item[data-id="NEW_CUSTOMER"] {
  background: rgba(37,99,235,.15) !important;
}
[data-theme="dark"] .dropdown-item[data-id="NEW_CUSTOMER"] .text-primary { color: var(--blue-400) !important; }
[data-theme="dark"] .dropdown-item[data-id="NEW_CUSTOMER"] .text-muted  { color: var(--slate-400) !important; }

/* ============================================
   THEME TOGGLE
   ============================================ */
.theme-toggle {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 50;
  width: 2.5rem;
  height: 2.5rem;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: var(--t);
}
.theme-toggle:hover { border-color: var(--primary); box-shadow: var(--shadow-md); }
.theme-toggle:active { transform: scale(0.93); }
.theme-toggle i { font-size: 1rem; color: var(--text-secondary); }
.theme-toggle:hover i { color: var(--primary); }

/* ============================================
   TOASTS
   ============================================ */
.toast-container {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  max-width: 380px;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-4);
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  cursor: pointer;
  pointer-events: auto;
  animation: toastIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  transition: var(--t);
}
.toast:hover { transform: translateX(-3px); }
.toast.hiding { animation: toastOut 0.25s ease forwards; }

@keyframes toastIn  { from { opacity: 0; transform: translateX(100%) scale(0.92); } to { opacity: 1; transform: translateX(0) scale(1); } }
@keyframes toastOut { to   { opacity: 0; transform: translateX(100%) scale(0.92); } }

.toast-icon {
  width: 2rem; height: 2rem;
  border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.toast-icon i { font-size: 1rem; }

.toast-success .toast-icon { background: var(--emerald-100); color: var(--emerald-600); }
.toast-error   .toast-icon { background: var(--red-100);     color: var(--red-600);     }
.toast-warning .toast-icon { background: var(--amber-100);   color: var(--amber-600);   }
.toast-info    .toast-icon { background: var(--blue-100);    color: var(--blue-600);    }

[data-theme="dark"] .toast-success .toast-icon { background: rgba(16,185,129,.15); color: #34d399; }
[data-theme="dark"] .toast-error   .toast-icon { background: rgba(239,68,68,.15);  color: #f87171; }
[data-theme="dark"] .toast-warning .toast-icon { background: rgba(245,158,11,.15); color: #fbbf24; }
[data-theme="dark"] .toast-info    .toast-icon { background: rgba(59,130,246,.15); color: #60a5fa; }

.toast-content { flex: 1; min-width: 0; }
.toast-title   { font-weight: 600; font-size: 0.875rem; color: var(--text-primary); margin-bottom: 2px; }
.toast-message { font-size: 0.8125rem; color: var(--text-secondary); line-height: 1.4; }

.toast-close {
  background: none; border: none; padding: var(--sp-1);
  cursor: pointer; color: var(--text-muted);
  border-radius: var(--radius);
  display: flex; align-items: center;
  transition: var(--t-fast);
}
.toast-close:hover { color: var(--text-primary); background: var(--bg-hover); }
[data-theme="dark"] .toast-close:hover { background: var(--slate-700); }

/* ============================================
   LOADING STATES
   ============================================ */
.skeleton {
  background: linear-gradient(90deg, var(--neutral-200) 25%, var(--neutral-100) 50%, var(--neutral-200) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
  border-radius: var(--radius);
}
[data-theme="dark"] .skeleton {
  background: linear-gradient(90deg, var(--slate-800) 25%, var(--slate-700) 50%, var(--slate-800) 75%);
  background-size: 200% 100%;
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

.skeleton-text   { height: 1rem;    margin-bottom: var(--sp-2); }
.skeleton-text:last-child { width: 80%; }
.skeleton-title  { height: 1.5rem;  width: 60%; margin-bottom: var(--sp-3); }
.skeleton-avatar { width: 3rem;     height: 3rem; border-radius: 50%; }
.skeleton-card   { height: 200px; }

/* Spinner */
.spinner {
  display: inline-block;
  width: 1.5rem; height: 1.5rem;
  border: 2.5px solid var(--border-color);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.spinner-sm { width: 1rem;  height: 1rem;  border-width: 2px; }
.spinner-lg { width: 2rem;  height: 2rem;  border-width: 3px; }

/* Button loading */
.btn-loading { position: relative; color: transparent !important; pointer-events: none; }
.btn-loading::after {
  content: '';
  position: absolute;
  width: 1rem; height: 1rem;
  border: 2px solid transparent;
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

/* Spinning icon (balance refresh) */
.spinning-icon {
  display: inline-block;
  animation: spin 1s linear infinite;
}

/* ============================================
   DASHBOARD LAYOUT
   ============================================ */
.dashboard-container {
  display: flex;
  min-height: 100vh;
}

/* ---- SIDEBAR ---- */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  position: fixed;
  height: 100vh;
  z-index: 40;
  transition: transform 0.25s ease;
}

.sidebar-header {
  padding: var(--sp-5) var(--sp-5);
  border-bottom: 1px solid var(--border-color);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  font-weight: 700;
  font-size: 1.125rem;
  color: var(--text-primary);
  text-decoration: none;
  letter-spacing: -0.01em;
}
.sidebar-brand i {
  font-size: 1.375rem;
  color: var(--primary);
}

.sidebar-nav {
  flex: 1;
  padding: var(--sp-4) var(--sp-3);
  overflow-y: auto;
}

.nav-section { margin-bottom: var(--sp-6); }

.nav-section-title {
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding: 0 var(--sp-3);
  margin-bottom: var(--sp-2);
}

.nav-link {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 0.5rem var(--sp-3);
  border-radius: var(--radius);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  transition: var(--t-fast);
  margin-bottom: 2px;
  position: relative;
}
.nav-link i { font-size: 1.125rem; flex-shrink: 0; }
.nav-link:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}
[data-theme="dark"] .nav-link:hover {
  background: var(--slate-800);
  color: var(--text-primary);
}
.nav-link.active {
  background: var(--blue-50);
  color: var(--primary);
  font-weight: 600;
}
[data-theme="dark"] .nav-link.active {
  background: rgba(59,130,246,.12);
  color: var(--blue-400);
}

.sidebar-footer {
  padding: var(--sp-4) var(--sp-3);
  border-top: 1px solid var(--border-color);
}

.sidebar-footer-mobile { display: none; }

.user-card {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3);
  border-radius: var(--radius-lg);
  background: var(--bg-hover);
  transition: var(--t-fast);
}
.user-card:hover { background: var(--neutral-200); }
[data-theme="dark"] .user-card { background: var(--slate-800); }
[data-theme="dark"] .user-card:hover { background: var(--slate-700); }

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

.user-info { flex: 1; min-width: 0; }
.user-name {
  font-weight: 600; font-size: 0.875rem;
  color: var(--text-primary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.user-role {
  font-size: 0.75rem; color: var(--text-muted);
  text-transform: capitalize; font-weight: 500;
}

/* Mobile Menu Toggle */
.mobile-menu-toggle {
  display: none;
  position: fixed;
  top: 0.875rem;
  left: 0.875rem;
  z-index: 45;
  width: 2.5rem; height: 2.5rem;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  align-items: center; justify-content: center;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: var(--t);
}
.mobile-menu-toggle:hover { border-color: var(--primary); }
.mobile-menu-toggle i { font-size: 1.125rem; color: var(--text-secondary); }

/* ---- MAIN CONTENT ---- */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  padding: var(--sp-8);
  max-width: calc(100vw - var(--sidebar-width));
  transition: margin-left 0.25s ease, max-width 0.25s ease;
}

.content-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: var(--sp-6);
}

.page-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.025em;
  margin-bottom: 0.25rem;
}

.page-subtitle {
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 400;
  margin: 0;
}

.header-actions { display: flex; gap: var(--sp-3); align-items: center; }

/* ============================================
   WELCOME CARD
   ============================================ */
.welcome-card {
  background: linear-gradient(135deg, var(--blue-700) 0%, var(--blue-600) 50%, #1a56db 100%);
  color: #fff;
  border-radius: var(--radius-xl);
  padding: var(--sp-8) var(--sp-8);
  margin-bottom: var(--sp-6);
  position: relative;
  overflow: hidden;
}
.welcome-card::before {
  content: '';
  position: absolute;
  top: -60px; right: -60px;
  width: 250px; height: 250px;
  background: rgba(255,255,255,.06);
  border-radius: 50%;
  pointer-events: none;
}
.welcome-card::after {
  content: '';
  position: absolute;
  bottom: -80px; right: 60px;
  width: 180px; height: 180px;
  background: rgba(255,255,255,.04);
  border-radius: 50%;
  pointer-events: none;
}

.welcome-content { position: relative; z-index: 1; }
.welcome-content h1 {
  font-size: 1.75rem;
  font-weight: 700;
  margin-bottom: var(--sp-2);
  letter-spacing: -0.02em;
}
.welcome-description {
  font-size: 0.9375rem;
  opacity: 0.85;
  margin-bottom: var(--sp-5);
  max-width: 560px;
  line-height: 1.65;
}
.welcome-status {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  font-size: 0.875rem;
  margin-bottom: var(--sp-5);
  padding: 0.375rem 0.875rem;
  background: rgba(255,255,255,.15);
  border-radius: var(--radius-full);
  backdrop-filter: blur(4px);
}
.welcome-status i { font-size: 1rem; }
.welcome-actions { display: flex; gap: var(--sp-3); }

/* ============================================
   SECTIONS
   ============================================ */
.products-section {
  display: none;
  animation: sectionIn 0.22s ease-out;
}
.products-section.visible { display: block; }
@keyframes sectionIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.menu-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: var(--sp-5) var(--sp-6);
  border-bottom: 1px solid var(--border-color);
}
.menu-header h2 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.015em;
  margin-bottom: 2px;
}
.menu-header p { margin: 0; color: var(--text-muted); font-size: 0.875rem; }

/* ============================================
   PRODUCT SEARCH
   ============================================ */
.product-search-container { max-width: 480px; }

.product-search-container .input-group {
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  overflow: hidden;
  transition: var(--t);
}
.product-search-container .input-group:focus-within {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(59,130,246,.12);
}
.product-search-container .input-group-text {
  background: var(--bg-input);
  border: none;
  color: var(--text-muted);
}
.product-search-container .form-control {
  border: none;
  box-shadow: none;
  padding: 0.5625rem 0.875rem;
}
.product-search-container .form-control:focus { box-shadow: none; }
.product-search-container .btn-outline-secondary {
  border: none;
  background: var(--bg-input);
  color: var(--text-muted);
  padding: 0.5rem 0.875rem;
}
.product-search-container .btn-outline-secondary:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}
[data-theme="dark"] .product-search-container .input-group { border-color: var(--slate-700); }
[data-theme="dark"] .product-search-container .input-group:focus-within { border-color: var(--blue-400); }
[data-theme="dark"] .product-search-container .input-group-text { background: var(--slate-800); }
[data-theme="dark"] .product-search-container .form-control { background: var(--slate-800); color: var(--text-primary); }
[data-theme="dark"] .product-search-container .btn-outline-secondary { background: var(--slate-800); }
[data-theme="dark"] .product-search-container .btn-outline-secondary:hover { background: var(--slate-700); }

.search-results-count { font-size: 0.875rem; color: var(--text-muted); }

/* ============================================
   FILTERS
   ============================================ */
.category-filters,
.order-filters {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  margin-bottom: var(--sp-5);
}

.category-filter,
.order-filter {
  padding: 0.375rem 0.875rem;
  border: 1px solid var(--border-color);
  background: var(--bg-card);
  color: var(--text-secondary);
  border-radius: var(--radius-full);
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--t-fast);
  white-space: nowrap;
}
.category-filter:hover, .order-filter:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--blue-50);
}
[data-theme="dark"] .category-filter:hover,
[data-theme="dark"] .order-filter:hover {
  background: rgba(59,130,246,.08);
  border-color: var(--blue-500);
  color: var(--blue-400);
}
.category-filter.active, .order-filter.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  font-weight: 600;
}

/* Stock filters active states */
.stock-filter.active { color: #fff !important; }
.stock-filter[data-filter="all"].active          { background: var(--primary)         !important; border-color: var(--primary)         !important; }
.stock-filter[data-filter="in-stock"].active     { background: var(--emerald-600)      !important; border-color: var(--emerald-600)      !important; }
.stock-filter[data-filter="limited-stock"].active{ background: var(--amber-500)        !important; border-color: var(--amber-500)        !important; }
.stock-filter[data-filter="out-of-stock"].active { background: var(--red-600)          !important; border-color: var(--red-600)          !important; }
.stock-filter[data-filter="out-of-stock-in-transit"].active { background: var(--neutral-500) !important; border-color: var(--neutral-500) !important; }

/* ============================================
   PRODUCTS GRID
   ============================================ */
.products-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: var(--sp-5);
  padding: var(--sp-2);
}

.product-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  overflow: hidden;
  cursor: pointer;
  transition: var(--t);
  position: relative;
}
.product-card:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--neutral-300);
  transform: translateY(-1px);
}
[data-theme="dark"] .product-card {
  border-color: var(--border-color);
  background: var(--bg-card);
}
[data-theme="dark"] .product-card:hover {
  border-color: var(--slate-600);
  box-shadow: var(--shadow-md);
}
body:not([data-theme="dark"]) .product-card { border-color: var(--neutral-200); }

.product-image {
  width: 100%;
  aspect-ratio: 1;
  background: var(--neutral-100);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
}
[data-theme="dark"] .product-image { background: var(--slate-700); }
.product-image img { width: 100%; height: 100%; object-fit: cover; }

/* Special badges */
.special-badges-overlay {
  position: absolute; top: 8px; left: 8px; z-index: 10;
  display: flex; flex-wrap: wrap; gap: 4px;
}
@media (max-width: 480px) {
  .special-badges-overlay { top: 6px; left: 6px; }
  .special-flashy-badge { font-size: 0.55rem; padding: 2px 6px; }
}
.special-flashy-badge {
  font-size: 0.625rem;
  font-weight: 700;
  padding: 3px 8px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-radius: 2px 10px 10px 2px;
  line-height: 1.4;
}
.special-badge-new  { background: #16a34a; color: #fff; }
.special-badge-offer{ background: #d97706; color: #fff; }
.special-badge-sale { background: #dc2626; color: #fff; }
[data-theme="dark"] .special-badge-new  { background: #22c55e; color: #052e16; }
[data-theme="dark"] .special-badge-offer{ background: #f59e0b; color: #451a03; }
[data-theme="dark"] .special-badge-sale { background: #ef4444; color: #fff; }

.product-info { padding: var(--sp-4); }

.product-name {
  font-weight: 600;
  font-size: 0.875rem;
  color: var(--text-primary);
  margin-bottom: 2px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.35;
}
[data-theme="dark"] .product-name { color: var(--text-primary) !important; }

.product-subtitle {
  font-size: 0.8125rem;
  color: var(--text-muted);
  font-weight: 400;
  margin-bottom: var(--sp-2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
[data-theme="dark"] .product-subtitle { color: var(--text-muted); }

.product-price {
  font-weight: 700;
  font-size: 1rem;
  color: var(--primary);
  display: flex;
  align-items: center;
  gap: 2px;
}
.product-price::before { content: '$'; font-size: 0.875rem; font-weight: 600; }
body:not([data-theme="dark"]) .product-price { color: var(--blue-700); }
[data-theme="dark"] .product-price { color: var(--blue-400); }

.product-sale-price { display: flex; flex-direction: row; align-items: baseline; gap: 6px; }
.original-price   { font-size: 0.8125rem; font-weight: 500; text-decoration: line-through; color: var(--text-muted); }
.sale-price-display { font-size: 1rem; font-weight: 700; color: var(--red-600); }
[data-theme="dark"] .sale-price-display { color: #f87171; }

.case-pack-qty { font-size: 0.8125rem; color: var(--text-muted); margin-left: 2px; }

/* Mini tags */
.product-mini-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: var(--sp-2); }
.product-availability-badge { margin-bottom: 2px; display: flex; align-items: center; gap: 4px; }

.mini-tag {
  font-size: 0.625rem;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 4px;
  display: inline-block;
  line-height: 1.4;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  border: 1px solid var(--neutral-200);
  background: var(--neutral-100);
  color: var(--neutral-600);
}
body:not([data-theme="dark"]) .mini-tag {
  background: var(--slate-100);
  color: #475569;
  border-color: var(--slate-300);
}
[data-theme="dark"] .mini-tag { background: var(--slate-700); color: var(--slate-300); border-color: var(--slate-600); }

.stock-badge-small {
  font-size: 0.625rem;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}

.stock-eta-label { font-size: 0.625rem; font-style: italic; color: var(--text-muted); margin-left: 3px; white-space: nowrap; }

/* Product image preview */
.product-image-preview {
  background: var(--neutral-100);
  border-radius: var(--radius-lg);
  aspect-ratio: 1;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
  border: 1px solid var(--border-color);
}
[data-theme="dark"] .product-image-preview { background: var(--slate-800); border-color: var(--slate-600); }
[data-theme="dark"] .product-image-preview #previewIcon { color: var(--slate-400); opacity: 0.3; }

/* ============================================
   PRODUCT PREVIEW MODAL
   ============================================ */
#productPreviewModal .modal-dialog { max-width: 860px; }
#productPreviewModal .row {
  display: flex !important;
  flex-direction: row !important;
  flex-wrap: nowrap !important;
}
#productPreviewModal .col-md-5 { flex: 0 0 41.666% !important; max-width: 41.666% !important; }
#productPreviewModal .col-md-7 { flex: 0 0 58.333% !important; max-width: 58.333% !important; }
@media (max-width: 768px) {
  #productPreviewModal .row { flex-direction: column !important; }
  #productPreviewModal .col-md-5,
  #productPreviewModal .col-md-7 { flex: 0 0 100% !important; max-width: 100% !important; }
  #productPreviewModal .modal-dialog { margin: var(--sp-2); max-width: calc(100% - 1rem); }
}

#previewName {
  color: var(--text-primary);
  font-weight: 700;
  font-size: 1.5rem;
  margin-bottom: var(--sp-2);
  line-height: 1.25;
}
#previewPrice {
  color: var(--primary);
  font-weight: 700;
  font-size: 1.375rem;
  margin-bottom: var(--sp-4);
}
[data-theme="dark"] #previewName  { color: var(--text-primary); }
[data-theme="dark"] #previewPrice { color: var(--blue-400); }

#previewCategory { background: var(--primary); color: #fff; border: none; }
[data-theme="dark"] #previewCategory { background: var(--blue-600); color: #fff; }

#previewQuantity { color: var(--text-primary); font-weight: 600; font-size: 1rem; }
#previewDescription { color: var(--text-secondary); line-height: 1.7; font-size: 0.9rem; }
[data-theme="dark"] #previewDescription { color: var(--text-secondary); }

#previewImage { max-width: 100%; border-radius: var(--radius-lg); box-shadow: var(--shadow-md); }
#previewIcon  { font-size: 4rem; color: var(--text-muted); opacity: 0.25; }

/* Product Details Grid (modal) */
#productPreviewModal .product-details-grid { display: flex; flex-direction: column; gap: 6px; }
#productPreviewModal .detail-item {
  display: flex;
  align-items: center;
  padding: 9px 12px;
  background: var(--bg-hover);
  border-radius: var(--radius);
  border: 1px solid var(--border-color);
  transition: var(--t-fast);
}
#productPreviewModal .detail-item:hover { background: var(--neutral-200); }
[data-theme="dark"] #productPreviewModal .detail-item { background: var(--slate-800); border-color: var(--slate-700); }
[data-theme="dark"] #productPreviewModal .detail-item:hover { background: var(--slate-700); }

#productPreviewModal .detail-label {
  flex: 0 0 100px;
  font-weight: 600;
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  white-space: nowrap;
}
#productPreviewModal .detail-value {
  flex: 1;
  font-weight: 500;
  font-size: 0.9rem;
  color: var(--text-primary);
  padding-left: 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#productPreviewModal .detail-item-full { flex-direction: column; align-items: flex-start; gap: 4px; }
#productPreviewModal .detail-item-full .detail-label { flex: none; width: 100%; }
#productPreviewModal .detail-item-full .detail-value {
  width: 100%; padding-left: 0;
  white-space: normal; line-height: 1.5; font-size: 0.875rem;
}

/* ============================================
   PRODUCT DETAILS TABLE (modal)
   ============================================ */
.product-details-table {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.product-details-table table { margin-bottom: 0; width: 100%; border-collapse: collapse; }
.product-details-table td {
  padding: 10px 14px;
  vertical-align: middle;
  border-bottom: 1px solid var(--border-color);
  line-height: 1.4;
}
.product-details-table tr:last-child td { border-bottom: none; }
.product-details-table .label {
  font-weight: 600;
  color: var(--text-muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: var(--bg-hover);
  border-right: 1px solid var(--border-color);
  white-space: nowrap;
  padding-right: 14px;
  width: 35%; min-width: 110px;
  vertical-align: middle;
}
.product-details-table .value {
  font-weight: 500;
  color: var(--text-primary);
  font-size: 0.9rem;
  word-break: break-word;
  padding-left: 14px;
  width: 65%;
  vertical-align: middle;
}
.product-details-table tr:hover .label { background: var(--neutral-200); }
[data-theme="dark"] .product-details-table { background: var(--bg-card) !important; border-color: var(--border-color) !important; }
[data-theme="dark"] .product-details-table td { border-bottom-color: var(--border-color) !important; }
[data-theme="dark"] .product-details-table .label {
  background: var(--bg-hover) !important;
  border-right-color: var(--border-color) !important;
  color: var(--text-muted) !important;
}
[data-theme="dark"] .product-details-table .value { color: var(--text-primary) !important; }
[data-theme="dark"] .product-details-table tr:hover .label { background: var(--slate-700) !important; }
body:not([data-theme="dark"]) .product-details-table .label { background: var(--neutral-50); color: var(--neutral-600); }
body:not([data-theme="dark"]) .product-details-table .value { color: #111827; }
body:not([data-theme="dark"]) .product-details-table tr:hover .label { background: var(--neutral-100); }

/* ============================================
   TABLES
   ============================================ */
.table-container {
  background: var(--bg-card);
  border-radius: var(--radius-xl);
  border: 1px solid var(--border-color);
  overflow: hidden;
}

.table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.9rem;
}

.table thead th {
  padding: 0.75rem 1rem;
  text-align: left;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-hover);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}
[data-theme="dark"] .table thead th {
  background: rgba(255,255,255,.025);
  color: var(--text-muted);
  border-bottom-color: var(--border-color);
}

.table tbody td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-light);
  color: var(--text-primary);
  vertical-align: middle;
}
[data-theme="dark"] .table tbody td {
  border-bottom-color: var(--border-color);
  color: var(--text-primary);
}
[data-theme="dark"] .table { background: transparent; }
[data-theme="dark"] .table tbody td { background: transparent; }

.table tbody tr { transition: background-color 0.1s ease; }
.table tbody tr:hover { background: var(--bg-hover); }
[data-theme="dark"] .table tbody tr:hover { background: var(--slate-800); }
.table tbody tr:last-child td { border-bottom: none; }
.table-hover tbody tr { cursor: pointer; }

.table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; }
[data-theme="dark"] .table-responsive { background: transparent; }

/* ============================================
   STATUS BADGES
   ============================================ */
.badge-status {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 0.25em 0.65em;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: capitalize;
  letter-spacing: 0.02em;
}
.badge-status::before {
  content: '';
  width: 5px; height: 5px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}

.badge-pending        { background: var(--amber-50);  color: var(--amber-600); }
.badge-processing     { background: var(--blue-50);   color: var(--blue-600);  }
.badge-completed      { background: var(--emerald-50); color: var(--emerald-600); }
.badge-incomplete     { background: #fef3c7;           color: #92400e;          }
.badge-cancelled      { background: var(--red-50);    color: var(--red-600);   }
.badge-pending-update { background: #faf5ff;           color: #7c3aed;          }

[data-theme="dark"] .badge-pending        { background: rgba(251,191,36,.12); color: #fbbf24; }
[data-theme="dark"] .badge-processing     { background: rgba(59,130,246,.12); color: #60a5fa; }
[data-theme="dark"] .badge-completed      { background: rgba(16,185,129,.12); color: #34d399; }
[data-theme="dark"] .badge-incomplete     { background: rgba(251,191,36,.12); color: #fcd34d; }
[data-theme="dark"] .badge-cancelled      { background: rgba(239,68,68,.12);  color: #f87171; }
[data-theme="dark"] .badge-pending-update { background: rgba(139,92,246,.12); color: #a78bfa; }

/* ============================================
   PENDING ORDERS BADGES
   ============================================ */
.pending-orders-badge { position: relative; display: inline-block; margin-left: 4px; }

#pendingOrdersBadge,
#pendingUpdateBadge {
  background: var(--red-600);
  color: #fff;
  border-radius: var(--radius-full);
  padding: 2px 7px;
  font-size: 0.6875rem;
  font-weight: 600;
  min-width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: pulse 2s infinite;
}
#pendingOrdersCount,
#pendingUpdateCount { font-size: 0.6875rem; }

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50%       { transform: scale(1.1); }
}

/* ============================================
   ORDER SEARCH DROPDOWN
   ============================================ */
.order-search-container { position: relative; }

.search-dropdown-menu {
  position: absolute;
  top: 100%; left: 0; right: 0;
  z-index: 1000;
  max-height: 280px;
  overflow-y: auto;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  margin-top: 4px;
}
[data-theme="dark"] .search-dropdown-menu { background: var(--bg-card); border-color: var(--border-color); }

.search-dropdown-item {
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--border-light);
  transition: background-color 0.1s;
}
.search-dropdown-item:hover { background: var(--bg-hover); }
.search-dropdown-item:last-child { border-bottom: none; }
[data-theme="dark"] .search-dropdown-item { border-bottom-color: var(--border-color); }
[data-theme="dark"] .search-dropdown-item:hover { background: var(--slate-700); }

.search-dropdown-item .order-info { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.search-dropdown-item .customer-name { font-weight: 500; font-size: 0.9rem; color: var(--text-primary); }
.search-dropdown-item .invoice-number { font-size: 0.8125rem; color: var(--text-secondary); }
.search-dropdown-item .order-id { font-size: 0.75rem; color: var(--text-muted); }

.search-dropdown-empty { padding: 14px; text-align: center; color: var(--text-muted); font-size: 0.875rem; }

/* ============================================
   ORDER INFO GRID
   ============================================ */
.order-info-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--sp-4);
  margin-bottom: var(--sp-5);
}
.order-info-item { display: flex; flex-direction: column; gap: var(--sp-1); }
.order-info-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.order-info-value { font-size: 0.9375rem; color: var(--text-primary); font-weight: 500; }
[data-theme="dark"] .order-info-value { color: var(--text-primary); }
[data-theme="dark"] .order-info-label { color: var(--text-muted); }

/* Order notes highlight */
.order-notes-highlight {
  background: #fef3c7;
  border-left: 4px solid #d97706;
  padding: 10px 14px;
  margin-top: 6px;
  border-radius: 0 var(--radius) var(--radius) 0;
  color: #78350f;
  font-weight: 600;
  line-height: 1.6;
}
[data-theme="dark"] .order-notes-highlight {
  background: rgba(217,119,6,.18);
  border-left-color: #f59e0b;
  color: #fde68a;
}

/* Customer link */
.customer-link {
  color: var(--primary);
  text-decoration: none;
  font-weight: 500;
  border-bottom: 1px dotted var(--primary);
  transition: var(--t-fast);
}
.customer-link:hover {
  color: var(--primary-hover);
  border-bottom-style: solid;
}
[data-theme="dark"] .customer-link { color: var(--blue-400); border-bottom-color: var(--blue-400); }

/* Delete order button */
#deleteOrderBtn {
  background: var(--red-600);
  border: none;
  color: #fff;
  width: 34px; height: 34px;
  display: inline-flex;
  align-items: center; justify-content: center;
  border-radius: var(--radius);
  padding: 0;
  transition: var(--t-fast);
}
#deleteOrderBtn:hover { background: var(--red-700); }
#deleteOrderBtn i { font-size: 1rem; }

/* Preview order IDs */
#previewOrderId, #previewCustomerName, #previewOrderDate,
#previewCreatedBy, #previewOrderNotes {
  color: var(--text-primary); font-weight: 500;
}

/* ============================================
   USER MANAGEMENT
   ============================================ */
.user-avatar-sm {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 0.8125rem;
}

#usersList .badge { font-size: 0.75rem; padding: 0.2em 0.55em; }
#usersSection .table { font-size: 0.9rem; }
#usersSection .table th {
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.6875rem;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  background: var(--bg-hover);
  border-bottom: 1px solid var(--border-color);
}
[data-theme="dark"] #usersSection .table th { background: rgba(255,255,255,.025); }
#usersSection .table td {
  vertical-align: middle;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-light);
}
[data-theme="dark"] #usersSection .table td { border-bottom-color: var(--border-color); }

/* ============================================
   EMPTY STATE
   ============================================ */
.empty-state {
  text-align: center;
  padding: var(--sp-12) var(--sp-8);
  color: var(--text-muted);
}
.empty-state i { font-size: 3rem; margin-bottom: var(--sp-4); opacity: 0.3; display: block; }
.empty-state h3 { font-size: 1.125rem; font-weight: 600; margin-bottom: var(--sp-2); color: var(--text-secondary); }
.empty-state p  { font-size: 0.9rem; max-width: 380px; margin: 0 auto; }

/* ============================================
   PRICING TOGGLE (Private/Licensee)
   ============================================ */
.pricing-toggle { position: relative; display: inline-flex; cursor: pointer; }
.pricing-toggle input { display: none; }
.pricing-toggle .toggle-label {
  display: flex;
  background: var(--bg-hover);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-full);
  padding: 2px;
  gap: 0;
}
[data-theme="dark"] .pricing-toggle .toggle-label { background: var(--slate-800); border-color: var(--slate-700); }
.pricing-toggle .toggle-option {
  padding: 4px 14px;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-secondary);
  border-radius: var(--radius-full);
  transition: var(--t-fast);
  user-select: none;
}
.pricing-toggle input:not(:checked) ~ .toggle-label .toggle-option:first-child {
  background: #fff;
  color: var(--text-primary);
  font-weight: 600;
  box-shadow: var(--shadow-xs);
}
[data-theme="dark"] .pricing-toggle input:not(:checked) ~ .toggle-label .toggle-option:first-child {
  background: var(--slate-600);
  color: var(--text-primary);
}
.pricing-toggle input:checked ~ .toggle-label .toggle-option:last-child {
  background: var(--primary);
  color: #fff;
  font-weight: 600;
}

/* Unit toggle (Bottle/Case) */
.unit-toggle { position: relative; display: inline-flex; align-items: center; cursor: pointer; }
.unit-toggle input { display: none; }
.unit-toggle .toggle-label {
  display: flex;
  background: var(--bg-hover);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-full);
  padding: 2px;
}
[data-theme="dark"] .unit-toggle .toggle-label { background: var(--slate-800); border-color: var(--slate-700); }
.unit-toggle .toggle-option {
  padding: 4px 12px;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-secondary);
  border-radius: var(--radius-full);
  transition: var(--t-fast);
  user-select: none;
}
.unit-toggle input:not(:checked) ~ .toggle-label .toggle-option:first-child {
  background: #fff;
  color: var(--text-primary);
  font-weight: 600;
  box-shadow: var(--shadow-xs);
}
[data-theme="dark"] .unit-toggle input:not(:checked) ~ .toggle-label .toggle-option:first-child {
  background: var(--slate-600);
  color: var(--text-primary);
}
.unit-toggle input:checked ~ .toggle-label .toggle-option:last-child {
  background: var(--primary);
  color: #fff;
  font-weight: 600;
}

/* ============================================
   CROP CONTAINER
   ============================================ */
#cropContainer, #editCropContainer {
  background: var(--bg-body);
  padding: var(--sp-6);
  border-radius: var(--radius-xl);
  border: 2px dashed var(--border-color);
  margin-top: var(--sp-5);
  transition: var(--t);
}
#cropContainer:hover, #editCropContainer:hover { border-color: var(--primary); }
#imageToCrop, #editImageToCrop { max-width: 100%; display: block; border-radius: var(--radius-lg); }

#cropContainer .cropper-bg,
#editCropContainer .cropper-bg { background-color: transparent !important; background-image: none !important; }
#cropContainer .cropper-canvas,
#editCropContainer .cropper-canvas { background-color: transparent !important; }
#cropContainer .cropper-view-box,
#editCropContainer .cropper-view-box { background-color: transparent !important; outline-color: rgba(59,130,246,.75) !important; }
#cropContainer .cropper-container,
#editCropContainer .cropper-container { background-color: transparent !important; }
#cropContainer .cropper-container img,
#editCropContainer .cropper-container img { background-color: transparent !important; max-width: none; }
#cropContainer .cropper-face,
#editCropContainer .cropper-face { background-color: rgba(0,0,0,.08) !important; box-shadow: 0 0 0 9999px rgba(0,0,0,.4); }
#cropContainer .cropper-drag-box,
#editCropContainer .cropper-drag-box { background-color: transparent !important; }

[data-theme="dark"] #cropContainer .cropper-view-box,
[data-theme="dark"] #editCropContainer .cropper-view-box { outline-color: rgba(96,165,250,.75) !important; }
[data-theme="dark"] #cropContainer .cropper-face,
[data-theme="dark"] #editCropContainer .cropper-face { background-color: rgba(255,255,255,.04) !important; box-shadow: 0 0 0 9999px rgba(0,0,0,.6); }

/* ============================================
   LOGIN PAGE
   ============================================ */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-body);
  padding: var(--sp-6);
}
[data-theme="dark"] .login-page { background: #0d1117; }

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

.login-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-2xl);
  box-shadow: var(--shadow-xl);
  overflow: hidden;
}

.login-header {
  text-align: center;
  padding: var(--sp-10) var(--sp-8) var(--sp-6);
  border-bottom: 1px solid var(--border-light);
}
[data-theme="dark"] .login-header { border-bottom-color: var(--border-color); }

.login-logo { font-size: 3rem; color: var(--primary); margin-bottom: var(--sp-4); display: inline-block; }

.login-title {
  font-size: 1.875rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: var(--sp-2);
  letter-spacing: -0.025em;
}

.login-subtitle { color: var(--text-muted); font-size: 0.9rem; margin: 0; }

.login-body { padding: var(--sp-6) var(--sp-8) var(--sp-8); }
.alert-container { margin-bottom: var(--sp-5); }

.input-group .form-control {
  padding-left: 3rem;
  height: 3.25rem;
  font-size: 0.9375rem;
}
.input-group .form-control:focus { z-index: 3; }
.input-group .form-control::placeholder { color: var(--text-muted); }

.btn-login {
  width: 100%;
  height: 3.25rem;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-lg);
  font-weight: 600;
  font-size: 0.9375rem;
  cursor: pointer;
  transition: var(--t);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  margin-top: var(--sp-2);
  box-shadow: 0 2px 8px rgba(37,99,235,.25);
}
.btn-login:hover { background: var(--primary-hover); box-shadow: 0 4px 12px rgba(37,99,235,.35); }
.btn-login:active { transform: scale(0.98); }

.divider {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: var(--sp-6) 0;
  color: var(--text-muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 500;
}
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: var(--border-color); }
.divider::before { margin-right: var(--sp-4); }
.divider::after  { margin-left: var(--sp-4); }

.login-footer {
  padding: var(--sp-4) var(--sp-8);
  background: var(--bg-hover);
  border-top: 1px solid var(--border-color);
  text-align: center;
}
[data-theme="dark"] .login-footer { background: rgba(255,255,255,.02); }
.login-footer p {
  color: var(--text-muted);
  font-size: 0.8125rem;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
}
.login-footer i { color: var(--emerald-600); }
[data-theme="dark"] .login-footer i { color: var(--emerald-500); }

/* ============================================
   DARK MODE - BOOTSTRAP OVERRIDES
   ============================================ */
[data-theme="dark"] .bg-light { background: var(--slate-800) !important; }
[data-theme="dark"] .border   { border-color: var(--border-color) !important; }
[data-theme="dark"] .card-body { background: var(--bg-card); }

/* WooCommerce table sticky header dark */
[data-theme="dark"] .sticky-top { background: var(--bg-card) !important; }

/* ============================================
   UTILITIES
   ============================================ */
.d-flex        { display: flex !important; }
.d-inline-flex { display: inline-flex !important; }
.d-block       { display: block !important; }
.d-inline      { display: inline !important; }
.d-none        { display: none !important; }

.flex-row    { flex-direction: row !important; }
.flex-column { flex-direction: column !important; }
.flex-wrap   { flex-wrap: wrap !important; }
.flex-nowrap { flex-wrap: nowrap !important; }
.flex-grow-1 { flex-grow: 1 !important; }
.flex-shrink-0 { flex-shrink: 0 !important; }

.justify-content-start   { justify-content: flex-start !important; }
.justify-content-end     { justify-content: flex-end !important; }
.justify-content-center  { justify-content: center !important; }
.justify-content-between { justify-content: space-between !important; }
.justify-content-around  { justify-content: space-around !important; }

.align-items-start   { align-items: flex-start !important; }
.align-items-end     { align-items: flex-end !important; }
.align-items-center  { align-items: center !important; }
.align-items-stretch { align-items: stretch !important; }

.gap-1 { gap: var(--sp-1) !important; }
.gap-2 { gap: var(--sp-2) !important; }
.gap-3 { gap: var(--sp-3) !important; }
.gap-4 { gap: var(--sp-4) !important; }
.gap-5 { gap: var(--sp-5) !important; }
.gap-6 { gap: var(--sp-6) !important; }

.m-0  { margin: 0 !important; }
.mt-0 { margin-top: 0 !important; }
.mt-1 { margin-top: var(--sp-1) !important; }
.mt-2 { margin-top: var(--sp-2) !important; }
.mt-3 { margin-top: var(--sp-3) !important; }
.mt-4 { margin-top: var(--sp-4) !important; }
.mt-5 { margin-top: var(--sp-5) !important; }
.mt-6 { margin-top: var(--sp-6) !important; }

.mb-0 { margin-bottom: 0 !important; }
.mb-1 { margin-bottom: var(--sp-1) !important; }
.mb-2 { margin-bottom: var(--sp-2) !important; }
.mb-3 { margin-bottom: var(--sp-3) !important; }
.mb-4 { margin-bottom: var(--sp-4) !important; }
.mb-5 { margin-bottom: var(--sp-5) !important; }
.mb-6 { margin-bottom: var(--sp-6) !important; }

.ms-auto { margin-left: auto !important; }
.me-auto { margin-right: auto !important; }
.me-2    { margin-right: var(--sp-2) !important; }
.mx-auto { margin-left: auto !important; margin-right: auto !important; }

.p-0  { padding: 0 !important; }
.p-2  { padding: var(--sp-2) !important; }
.p-3  { padding: var(--sp-3) !important; }
.p-4  { padding: var(--sp-4) !important; }
.p-5  { padding: var(--sp-5) !important; }
.p-6  { padding: var(--sp-6) !important; }

.text-start   { text-align: left !important; }
.text-end     { text-align: right !important; }
.text-center  { text-align: center !important; }

.text-primary   { color: var(--primary) !important; }
.text-secondary { color: var(--text-secondary) !important; }
.text-muted     { color: var(--text-muted) !important; }
.text-success   { color: var(--emerald-600) !important; }
.text-danger    { color: var(--red-600) !important; }
.text-warning   { color: var(--amber-600) !important; }

.fw-normal   { font-weight: 400 !important; }
.fw-medium   { font-weight: 500 !important; }
.fw-semibold { font-weight: 600 !important; }
.fw-bold     { font-weight: 700 !important; }

.fs-sm  { font-size: 0.875rem !important; }
.fs-base{ font-size: 1rem !important; }
.fs-lg  { font-size: 1.125rem !important; }

.small  { font-size: 0.875em; }

.w-100 { width: 100% !important; }
.h-100 { height: 100% !important; }

.position-relative { position: relative !important; }
.position-absolute { position: absolute !important; }
.position-fixed    { position: fixed !important; }

.overflow-hidden { overflow: hidden !important; }
.overflow-auto   { overflow: auto !important; }

.rounded      { border-radius: var(--radius) !important; }
.rounded-lg   { border-radius: var(--radius-lg) !important; }
.rounded-xl   { border-radius: var(--radius-xl) !important; }
.rounded-full { border-radius: var(--radius-full) !important; }

.border   { border: 1px solid var(--border-color) !important; }
.border-0 { border: 0 !important; }
.border-bottom { border-bottom: 1px solid var(--border-color) !important; }

.shadow-sm { box-shadow: var(--shadow-sm) !important; }
.shadow    { box-shadow: var(--shadow-md) !important; }
.shadow-lg { box-shadow: var(--shadow-lg) !important; }

/* ============================================
   SIDEBAR OVERLAY
   ============================================ */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  backdrop-filter: blur(2px);
  z-index: 35;
  opacity: 0;
  visibility: hidden;
  transition: var(--t);
}
.sidebar-overlay.show { opacity: 1; visibility: visible; }

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 1280px) {
  :root { --sidebar-width: 240px; }
  .main-content { padding: var(--sp-6); }
}

@media (max-width: 1024px) {
  :root { --sidebar-width: 220px; }
  .main-content { padding: var(--sp-5); }
  .products-grid { grid-template-columns: repeat(auto-fill, minmax(185px, 1fr)); }
  .sidebar-footer { display: none !important; }
  .sidebar-footer-mobile {
    display: block !important;
    padding: var(--sp-3);
    border-top: 1px solid var(--border-color);
    background: var(--bg-sidebar);
  }
}

@media (max-width: 768px) {
  .mobile-menu-toggle { display: flex; }
  .sidebar-overlay    { display: block; }

  .sidebar {
    transform: translateX(-100%);
    width: 272px;
    box-shadow: var(--shadow-2xl);
    max-height: 100vh;
    overflow-y: auto;
  }
  .sidebar.open { transform: translateX(0); }

  .sidebar-footer { display: none !important; }
  .sidebar-footer-mobile {
    display: block !important;
    padding: var(--sp-3);
    border-top: 1px solid var(--border-color);
    background: var(--bg-sidebar);
  }

  .main-content {
    margin-left: 0;
    max-width: 100vw;
    padding: var(--sp-4);
    padding-top: calc(var(--sp-4) + 52px);
  }

  .content-header { flex-direction: column; gap: var(--sp-3); }
  .header-actions { width: 100%; }
  .header-actions .btn { flex: 1; }

  .products-grid { grid-template-columns: repeat(2, 1fr); gap: var(--sp-3); }

  .menu-header { flex-direction: column; gap: var(--sp-3); }
  .menu-header .d-flex { width: 100%; }
  .menu-header .d-flex .btn { flex: 1; }

  .welcome-card { padding: var(--sp-5); }
  .welcome-content h1 { font-size: 1.375rem; }
  .welcome-description { font-size: 0.875rem; }

  .order-info-grid { grid-template-columns: 1fr; gap: var(--sp-3); }

  .theme-toggle { top: 0.875rem; right: 0.875rem; width: 2.25rem; height: 2.25rem; }
  .toast-container { left: var(--sp-4); right: var(--sp-4); max-width: none; }

  .modal-dialog { margin: var(--sp-3); max-width: none; }
  .modal-content { border-radius: var(--radius-xl); }

  .category-filters { gap: var(--sp-2); }
  .category-filter, .order-filter { padding: 0.3125rem 0.75rem; font-size: 0.8125rem; }

  .login-container { max-width: 100%; }
  .login-header { padding: var(--sp-8) var(--sp-5) var(--sp-5); }
  .login-body { padding: var(--sp-5) var(--sp-5) var(--sp-6); }
  .login-logo { font-size: 2.5rem; }
  .login-title { font-size: 1.625rem; }
  .input-group .form-control { font-size: 16px !important; }

  .product-details-table { font-size: 0.8125rem; }
  .product-details-table td { padding: var(--sp-2) var(--sp-3); }

  #orderPreviewModal .order-info-grid { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
  .products-grid { grid-template-columns: 1fr; gap: var(--sp-3); }
  .page-title { font-size: 1.25rem; }
  .sidebar-brand { font-size: 1rem; }
  .sidebar-brand i { font-size: 1.25rem; }

  .product-info { padding: var(--sp-3); }
  .product-name { font-size: 0.875rem; }
  .product-price { font-size: 0.9375rem; }

  .table td, .table th { padding: 0.625rem 0.75rem; font-size: 0.8125rem; }
  .modal-body { padding: var(--sp-4); }
  .btn { padding: 0.4375rem 0.875rem; font-size: 0.875rem; min-height: 42px; }

  .product-details-table td { padding: var(--sp-2); display: flex; flex-direction: column; border-bottom: none; }
  .product-details-table tr { display: flex; flex-direction: column; border-bottom: 1px solid var(--border-color); margin-bottom: var(--sp-2); }
  .product-details-table .label { width: 100%; border-right: none; border-bottom: 1px solid var(--border-color); padding: var(--sp-1) 0; font-size: 0.625rem; margin-bottom: var(--sp-1); }
  .product-details-table .value { width: 100%; padding: 0; font-size: 0.875rem; }

  .welcome-actions { flex-direction: column; }
  .welcome-actions .btn { width: 100%; }
}

@media (max-width: 375px) {
  .products-grid { gap: var(--sp-2); }
  .main-content { padding: var(--sp-3); padding-top: calc(var(--sp-3) + 52px); }
  .welcome-card { padding: var(--sp-4); }
  .category-filters { flex-wrap: nowrap; overflow-x: auto; padding-bottom: var(--sp-2); -webkit-overflow-scrolling: touch; }
  .category-filter { white-space: nowrap; flex-shrink: 0; }
}

/* iPad/Tablet */
@media (min-width: 769px) and (max-width: 1024px) and (orientation: landscape) {
  .sidebar-footer { display: none !important; }
  .sidebar-footer-mobile {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
    padding: var(--sp-3) !important;
    border-top: 1px solid var(--border-color) !important;
    background: var(--bg-sidebar) !important;
  }
}

/* Touch devices */
@media (hover: none) and (pointer: coarse) {
  .btn:hover, .product-card:hover, .nav-link:hover { transform: none; }
  .btn { min-height: 44px; }
  .btn-login:active { transform: scale(0.98); }
}

/* iOS */
@supports (-webkit-touch-callout: none) {
  .login-page { min-height: -webkit-fill-available; }
  .input-group .form-control { font-size: 16px !important; }
}

/* Landscape mobile */
@media (max-width: 768px) and (orientation: landscape) {
  .modal-dialog { margin: var(--sp-2) auto; max-height: 85vh; overflow-y: auto; }
  .login-card { display: flex; flex-direction: row; }
  .login-header { flex: 0 0 38%; display: flex; flex-direction: column; justify-content: center; padding: var(--sp-6); border-bottom: none; border-right: 1px solid var(--border-color); }
  .login-body  { flex: 1; padding: var(--sp-6); display: flex; flex-direction: column; justify-content: center; }
  .login-footer { display: none; }
  .login-logo  { font-size: 2rem; margin-bottom: var(--sp-2); }
  .login-title { font-size: 1.375rem; }
}

/* Mobile product details table responsive */
@media (max-width: 768px) {
  .product-details-table .label { font-size: 0.6875rem; width: 90px; min-width: 90px; }
  .product-details-table .value { font-size: 0.8125rem; }
}

/* Modal responsive improvements */
@media (max-width: 768px) {
  #productPreviewModal .modal-body { padding: var(--sp-4); }
  #orderPreviewModal .order-info-grid { grid-template-columns: 1fr; }
  #orderPreviewModal .order-info-item {
    padding: var(--sp-3);
    background: var(--bg-hover);
    border-radius: var(--radius);
  }
  [data-theme="dark"] #orderPreviewModal .order-info-item { background: var(--slate-800); }
}

/* Nav improvements for mobile */
@media (max-width: 768px) {
  .sidebar-nav { padding: var(--sp-2); }
  .nav-link    { padding: 0.5625rem var(--sp-3); }
  .nav-section-title { font-size: 0.625rem; padding: 0 var(--sp-3); }
}
