/* ============================================================
   READY INVENTORY — Design System
   ============================================================ */

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  /* Brand — monochrome */
  --primary: #ffffff;
  --primary-dark: #e5e5e5;
  --primary-light: rgba(255, 255, 255, 0.08);
  --primary-border: #333333;

  /* Semantic — subtle tints on black */
  --success: #22c55e;
  --success-light: rgba(34, 197, 94, 0.12);
  --success-border: #166534;
  --danger: #ef4444;
  --danger-light: rgba(239, 68, 68, 0.12);
  --danger-border: #7f1d1d;
  --warning: #f59e0b;
  --warning-light: rgba(245, 158, 11, 0.12);
  --warning-border: #78350f;
  --info: #3b82f6;
  --info-light: rgba(59, 130, 246, 0.12);
  --info-border: #1e40af;

  /* Neutrals — pure black & white */
  --bg: #000000;
  --bg-subtle: #0a0a0a;
  --card: #0f0f0f;
  --border: #1f1f1f;
  --border-light: #141414;
  --border-strong: #333333;
  --text: #ffffff;
  --text-muted: #a3a3a3;
  --text-subtle: #666666;

  /* Sidebar */
  --sb-bg: #000000;
  --sb-surface: #141414;
  --sb-border: #1f1f1f;
  --sb-text: #d4d4d4;
  --sb-text-muted: #737373;
  --sb-active-bg: #1f1f1f;
  --sb-active-text: #ffffff;
  --sb-active-accent: #ffffff;

  /* Shadows */
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.5);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.55), 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.6), 0 2px 4px -1px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.7), 0 4px 6px -2px rgba(0, 0, 0, 0.4);
  --shadow-xl: 0 20px 40px -10px rgba(0, 0, 0, 0.85);
  --ring: 0 0 0 3px rgba(255, 255, 255, 0.2);

  /* Radius */
  --radius-sm: 6px;
  --radius: 8px;
  --radius-md: 10px;
  --radius-lg: 12px;
  --radius-xl: 16px;

  /* Sizes */
  --sidebar-w: 248px;
  --header-h: 64px;
}

input, select, textarea {
  background: var(--bg-subtle);
  color: var(--text);
  border-color: var(--border);
}

.code-block {
  background: var(--bg-subtle);
  color: var(--text);
}

img { opacity: 0.92; }

html, body { height: 100%; background: var(--bg); }
html { color-scheme: dark; overflow-x: hidden; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
  max-width: 100vw;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; }

/* ===== Scrollbars ===== */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: #0a0a0a; }
::-webkit-scrollbar-thumb { background: #262626; border-radius: 5px; border: 2px solid #0a0a0a; }
::-webkit-scrollbar-thumb:hover { background: #404040; }
::-webkit-scrollbar-corner { background: #0a0a0a; }
* { scrollbar-color: #262626 #0a0a0a; }

/* ===== Selection ===== */
::selection { background: rgba(255, 255, 255, 0.15); color: #fff; }

/* ===== Icons ===== */
.icon-svg {
  width: 18px;
  height: 18px;
  stroke-width: 2;
  flex-shrink: 0;
}
.icon-svg.sm { width: 14px; height: 14px; }
.icon-svg.lg { width: 22px; height: 22px; }

/* ============================================================
   LAYOUT
   ============================================================ */

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

/* ===== Sidebar (dark) ===== */
.sidebar {
  width: var(--sidebar-w);
  background: var(--sb-bg);
  border-right: 1px solid var(--sb-border);
  padding: 18px 0 12px;
  position: fixed;
  inset: 0 auto 0 0;
  overflow-y: auto;
  z-index: 100;
  display: flex;
  flex-direction: column;
  color: var(--sb-text);
  contain: layout;
}

.sidebar-logo {
  padding: 0 20px 18px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--sb-border);
  display: flex;
  align-items: center;
  gap: 10px;
}
.sidebar-logo-mark {
  width: 36px;
  height: 36px;
  border-radius: 9px;
  background: #ffffff;
  display: grid;
  place-items: center;
  color: #000000;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(255, 255, 255, 0.08);
}
.sidebar-logo h2 {
  font-size: 15px;
  font-weight: 600;
  color: #fff;
  letter-spacing: -0.01em;
}
.sidebar-logo small {
  color: var(--sb-text-muted);
  font-size: 11px;
  display: block;
  margin-top: 2px;
}

.sidebar-section-label {
  padding: 14px 20px 6px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--sb-text-muted);
}

.sidebar-nav { padding: 0 10px; flex: 1; }

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  margin: 1px 0;
  border-radius: 7px;
  color: var(--sb-text);
  font-size: 13.5px;
  font-weight: 500;
  transition: background 0.12s, color 0.12s;
  cursor: pointer;
}
.nav-link:hover { background: var(--sb-surface); color: #fff; }
.nav-link.active {
  background: var(--sb-active-bg);
  color: var(--sb-active-text);
  font-weight: 600;
}
.nav-link.active .icon-svg { color: var(--sb-active-accent); }
.nav-link .icon-svg { color: var(--sb-text-muted); }

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--sb-border);
}
.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: 7px;
  margin-bottom: 8px;
}
.sidebar-user:hover { background: var(--sb-surface); }
.sidebar-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #262626;
  border: 1px solid var(--border-strong);
  display: grid;
  place-items: center;
  color: #ffffff;
  font-weight: 600;
  font-size: 12px;
  flex-shrink: 0;
}
.sidebar-user-info { min-width: 0; flex: 1; }
.sidebar-user-name {
  font-size: 12.5px;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-user-role {
  font-size: 11px;
  color: var(--sb-text-muted);
  text-transform: capitalize;
}
.sidebar-logout {
  width: 100%;
  padding: 8px 10px;
  background: transparent;
  border: 1px solid var(--sb-border);
  border-radius: 7px;
  color: var(--sb-text);
  font-size: 12.5px;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  transition: all 0.12s;
}
.sidebar-logout:hover { background: var(--sb-surface); color: #fff; }
.sidebar-logout + .sidebar-logout { margin-top: 6px; }

/* ===== Main content ===== */
.main-content {
  flex: 1;
  min-width: 0;
  margin-left: var(--sidebar-w);
  padding: 28px 36px 40px;
  max-width: 1600px;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 24px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}
.page-header h1 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.015em;
  color: var(--text);
}
.page-header .subtitle {
  color: var(--text-muted);
  font-size: 13px;
  margin-top: 4px;
}
.page-header-actions { display: flex; gap: 8px; flex-shrink: 0; }

/* ============================================================
   CARDS
   ============================================================ */

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 20px;
  margin-bottom: 16px;
}
.card-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.card-title .icon-svg { color: var(--text-muted); }
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  gap: 12px;
}
.card-header h3 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}
.card-subtitle {
  font-size: 12.5px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ===== Stats ===== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}
.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 18px;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s, box-shadow 0.15s;
  position: relative;
  overflow: hidden;
}
.stat-card:hover {
  border-color: var(--border-strong);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}
.stat-card::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--border);
}
.stat-card.success::before { background: var(--success); }
.stat-card.danger::before { background: var(--danger); }
.stat-card.warning::before { background: var(--warning); }
.stat-card.info::before { background: var(--info); }
.stat-card.primary::before { background: var(--primary); }

.stat-card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.stat-card .label {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.stat-card .value {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.1;
  color: var(--text);
}
.stat-card .change {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 6px;
}
.stat-card.success .value { color: var(--success); }
.stat-card.danger .value { color: var(--danger); }
.stat-card.warning .value { color: var(--warning); }
.stat-card.info .value { color: var(--info); }

.stat-card-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: var(--bg-subtle);
  color: var(--text-muted);
}
.stat-card.success .stat-card-icon { background: var(--success-light); color: var(--success); }
.stat-card.danger .stat-card-icon { background: var(--danger-light); color: var(--danger); }
.stat-card.warning .stat-card-icon { background: var(--warning-light); color: var(--warning); }
.stat-card.info .stat-card-icon { background: var(--info-light); color: var(--info); }
.stat-card.primary .stat-card-icon { background: var(--primary-light); color: var(--primary); }

/* ============================================================
   BUTTONS
   ============================================================ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.12s;
  white-space: nowrap;
  line-height: 1.2;
}
.btn:focus-visible { outline: none; box-shadow: var(--ring); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: #ffffff;
  color: #000000;
  font-weight: 600;
}
.btn-primary:hover:not(:disabled) { background: #e5e5e5; }

.btn-secondary {
  background: #1a1a1a;
  color: var(--text);
  border-color: var(--border-strong);
}
.btn-secondary:hover:not(:disabled) { background: #262626; border-color: #444; }

.btn-success { background: var(--success); color: #000; font-weight: 600; }
.btn-success:hover:not(:disabled) { background: #16a34a; }

.btn-danger { background: var(--danger); color: #fff; font-weight: 600; }
.btn-danger:hover:not(:disabled) { background: #dc2626; }

.btn-warning { background: var(--warning); color: #000; font-weight: 600; }
.btn-warning:hover:not(:disabled) { background: #d97706; }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: transparent;
}
.btn-ghost:hover:not(:disabled) { background: #1a1a1a; color: var(--text); }

.btn-outline {
  background: transparent;
  color: var(--text);
  border-color: var(--border-strong);
}
.btn-outline:hover:not(:disabled) { background: #1a1a1a; border-color: #555; }

.btn-sm { padding: 5px 10px; font-size: 12.5px; gap: 4px; }
.btn-sm .icon-svg { width: 14px; height: 14px; }
.btn-lg { padding: 11px 20px; font-size: 14.5px; }
.btn-block { width: 100%; }
.btn-icon { padding: 7px; }

/* Filter button group */
.filter-group {
  display: inline-flex;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 3px;
  gap: 2px;
}
.filter-btn {
  padding: 5px 12px;
  background: transparent;
  border: none;
  border-radius: 4px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.12s;
}
.filter-btn:hover { color: var(--text); }
.filter-btn.active {
  background: #262626;
  color: var(--text);
  box-shadow: var(--shadow-xs);
}

/* ============================================================
   FORMS
   ============================================================ */

.form-group { margin-bottom: 14px; }
.form-group label {
  display: block;
  margin-bottom: 6px;
  font-weight: 500;
  font-size: 13px;
  color: var(--text);
}
.form-group label .required { color: var(--danger); }
.form-group .help-text {
  margin-top: 6px;
  font-size: 12px;
  color: var(--text-muted);
}

.form-control,
input[type="text"], input[type="number"], input[type="email"],
input[type="password"], input[type="date"], input[type="search"],
select, textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-family: inherit;
  background: var(--card);
  color: var(--text);
  transition: border-color 0.12s, box-shadow 0.12s;
}
.form-control:hover:not(:focus),
input:hover:not(:focus), select:hover:not(:focus), textarea:hover:not(:focus) {
  border-color: var(--border-strong);
}
.form-control:focus, input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: var(--ring);
}
.form-control::placeholder, input::placeholder, textarea::placeholder { color: var(--text-subtle); }

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
}

.search-input {
  position: relative;
}
.search-input input {
  padding-left: 36px;
}
.search-input .icon-svg {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-subtle);
  pointer-events: none;
}

/* Checkbox / Radio */
.checkbox-wrap {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 13.5px;
  user-select: none;
}
.checkbox-wrap input[type="checkbox"],
.checkbox-wrap input[type="radio"] {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
  cursor: pointer;
}

/* ============================================================
   TABLES
   ============================================================ */

.table-wrapper {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: auto;
}
.card .table-wrapper {
  border: none;
  border-radius: 0;
  margin: 0 -20px -20px;
  border-top: 1px solid var(--border);
}
.card .table-wrapper:first-child {
  border-top: none;
  margin-top: -20px;
}

table { width: 100%; border-collapse: collapse; }
th, td {
  padding: 11px 16px;
  text-align: left;
  font-size: 13px;
  vertical-align: middle;
}
thead th {
  background: var(--bg-subtle);
  font-weight: 600;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 1;
}
tbody tr { border-bottom: 1px solid var(--border-light); }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--bg-subtle); }

.table-cell-strong { font-weight: 600; color: var(--text); }
.table-cell-muted { color: var(--text-muted); }
.table-cell-mono {
  font-family: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;
  font-size: 12.5px;
  color: var(--text-muted);
}
.table-empty {
  padding: 40px 16px !important;
  text-align: center;
  color: var(--text-muted);
}
.table-empty .icon-svg {
  width: 32px;
  height: 32px;
  stroke-width: 1.5;
  color: var(--text-subtle);
  margin-bottom: 8px;
}

/* ============================================================
   BADGES
   ============================================================ */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  line-height: 1.4;
  border: 1px solid transparent;
}
.badge-success { background: var(--success-light); color: #4ade80; border-color: var(--success-border); }
.badge-danger  { background: var(--danger-light);  color: #f87171; border-color: var(--danger-border); }
.badge-warning { background: var(--warning-light); color: #fbbf24; border-color: var(--warning-border); }
.badge-info    { background: var(--info-light);    color: #60a5fa; border-color: var(--info-border); }
.badge-primary { background: var(--primary-light); color: #ffffff; border-color: var(--primary-border); }
.badge-muted   { background: #141414;              color: #a3a3a3; border-color: var(--border); }

.badge-dot::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.8;
}

/* ============================================================
   MODALS
   ============================================================ */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
  animation: fadeIn 0.15s ease;
}
.modal-overlay.active { display: flex; }
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal {
  background: var(--card);
  border-radius: var(--radius-lg);
  padding: 0;
  max-width: 600px;
  width: 100%;
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-xl);
  animation: modalIn 0.18s ease;
}
@keyframes modalIn {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.modal-sm { max-width: 440px; }
.modal-lg { max-width: 820px; }

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-header h3 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}
.modal-close {
  background: transparent;
  border: none;
  width: 32px;
  height: 32px;
  border-radius: 6px;
  display: grid;
  place-items: center;
  cursor: pointer;
  color: var(--text-muted);
  transition: background 0.12s;
}
.modal-close:hover { background: var(--bg-subtle); color: var(--text); }

.modal-body {
  padding: 20px 24px;
  overflow-y: auto;
  flex: 1;
}
.modal-footer {
  padding: 14px 24px;
  border-top: 1px solid var(--border);
  background: var(--bg-subtle);
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  flex-shrink: 0;
}

/* ============================================================
   TOASTS
   ============================================================ */

.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}
.toast {
  background: var(--card);
  padding: 12px 16px 12px 14px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
  border-left: 3px solid var(--primary);
  min-width: 280px;
  max-width: 400px;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text);
  animation: slideIn 0.2s ease;
  transition: opacity 0.2s;
  pointer-events: auto;
}
.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
.toast.warning { border-left-color: var(--warning); }
.toast.info { border-left-color: var(--info); }
@keyframes slideIn {
  from { transform: translateX(110%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ============================================================
   AUTH PAGES
   ============================================================ */

.auth-layout {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
  background: #000000;
  position: relative;
  overflow: hidden;
}
.auth-layout::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(255,255,255,0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.025) 1px, transparent 1px);
  background-size: 40px 40px;
  mask-image: radial-gradient(ellipse at center, #000 30%, transparent 75%);
  pointer-events: none;
}

.auth-card {
  background: var(--card);
  border: 1px solid var(--border);
  padding: 36px 32px;
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  width: 100%;
  max-width: 420px;
  position: relative;
  z-index: 1;
}
.auth-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
}
.auth-logo-mark {
  width: 52px;
  height: 52px;
  border-radius: 13px;
  background: #ffffff;
  display: grid;
  place-items: center;
  color: #000000;
  box-shadow: 0 8px 24px rgba(255, 255, 255, 0.1);
}
.auth-card h1 {
  text-align: center;
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.015em;
}
.auth-card .tagline {
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  margin-top: 4px;
}

.auth-tabs {
  display: flex;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px;
  margin-bottom: 22px;
}
.auth-tab {
  flex: 1;
  padding: 8px 12px;
  background: transparent;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
}
.auth-tab:hover { color: var(--text); }
.auth-tab.active {
  background: #262626;
  color: var(--text);
  box-shadow: var(--shadow-xs);
}

.auth-notice {
  margin-top: 14px;
  padding: 10px 12px;
  background: var(--warning-light);
  border: 1px solid var(--warning-border);
  border-radius: var(--radius-sm);
  font-size: 12px;
  color: #fbbf24;
  display: flex;
  gap: 8px;
  align-items: flex-start;
}

/* ============================================================
   SCANNER
   ============================================================ */

.scanner-container {
  max-width: 720px;
  margin: 0 auto;
}

.mode-selector {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 20px;
}
.mode-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 16px 10px;
  border: 1px solid var(--border);
  background: var(--card);
  border-radius: var(--radius-md);
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
  color: var(--text);
  transition: all 0.15s;
}
.mode-btn .icon-svg { width: 22px; height: 22px; color: var(--text-muted); }
.mode-btn:hover { border-color: var(--border-strong); }
.mode-btn.active { border-color: transparent; color: white; }
.mode-btn.active .icon-svg { color: white; }
.mode-btn[data-mode="add"].active { background: var(--success); }
.mode-btn[data-mode="minus"].active { background: var(--danger); }
.mode-btn[data-mode="rto"].active { background: var(--warning); }
.mode-btn[data-mode="dto"].active { background: var(--info); }

.scan-input-wrap {
  background: var(--card);
  border: 1px solid var(--border);
  padding: 20px;
  border-radius: var(--radius-md);
  margin-bottom: 16px;
}
.scan-input {
  font-size: 18px !important;
  padding: 14px 16px !important;
  font-family: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;
  letter-spacing: 0.02em;
}

#scanner-video, #scanner-wrap > div {
  width: 100%;
  max-width: 500px;
  border-radius: var(--radius);
  display: block;
  margin: 0 auto;
  overflow: hidden;
}

.scan-log-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border-light);
}
.scan-log-item:last-child { border-bottom: none; }
.scan-log-item-meta {
  font-weight: 500;
  font-size: 13px;
  color: var(--text);
}
.scan-log-item-time {
  color: var(--text-muted);
  font-size: 12px;
  margin-top: 2px;
}

/* ============================================================
   LIST BLOCKS
   ============================================================ */

.list-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border-light);
}
.list-row:last-child { border-bottom: none; }
.list-row-title { font-weight: 500; font-size: 13px; color: var(--text); }
.list-row-sub { color: var(--text-muted); font-size: 12px; margin-top: 2px; }
.list-row-value { font-weight: 600; font-size: 14px; color: var(--text); text-align: right; }
.list-row-value.danger { color: var(--danger); }

/* ============================================================
   LOADING / SKELETON
   ============================================================ */

.skeleton {
  background: linear-gradient(90deg, var(--bg-subtle) 0%, var(--border-light) 50%, var(--bg-subtle) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: 4px;
  display: inline-block;
}
@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
.skeleton-text { height: 14px; width: 100%; }
.skeleton-stat { height: 28px; width: 80px; }

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-cell {
  text-align: center;
  padding: 30px 16px !important;
  color: var(--text-muted);
}

/* ============================================================
   WEBHOOK / CODE BLOCK
   ============================================================ */

.code-block {
  font-family: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;
  font-size: 12px;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  padding: 14px 16px;
  border-radius: var(--radius);
  line-height: 1.7;
  color: var(--text);
  overflow-x: auto;
}
.code-block code {
  background: var(--card);
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid var(--border);
  font-size: 11.5px;
}

/* ============================================================
   UTILITIES
   ============================================================ */

.flex { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.flex-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.flex-wrap { flex-wrap: wrap; }
.flex-1 { flex: 1; }
.items-center { align-items: center; }
.items-start { align-items: flex-start; }
.justify-end { justify-content: flex-end; }

.gap-4 { gap: 4px; }
.gap-6 { gap: 6px; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }

.mt-4 { margin-top: 4px; }
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mt-20 { margin-top: 20px; }
.mt-24 { margin-top: 24px; }
.mb-8 { margin-bottom: 8px; }
.mb-12 { margin-bottom: 12px; }
.mb-16 { margin-bottom: 16px; }
.mb-20 { margin-bottom: 20px; }

.text-muted { color: var(--text-muted); }
.text-subtle { color: var(--text-subtle); }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.text-sm { font-size: 12px; }
.text-xs { font-size: 11px; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.font-mono { font-family: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace; }
.font-semibold { font-weight: 600; }
.font-bold { font-weight: 700; }

.hidden { display: none !important; }
.w-full { width: 100%; }
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Layout helpers */
.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}
.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}
.grid-dashboard {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 16px;
}

/* ============================================================
   MOBILE
   ============================================================ */

.mobile-menu-btn {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 101;
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  width: 40px;
  height: 40px;
  place-items: center;
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(2px);
  z-index: 99;
}

/* ===== Tablet & small laptop ===== */
@media (max-width: 1024px) {
  .main-content { padding: 24px 24px 32px; }
  .stats-grid { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
}

@media (max-width: 900px) {
  .grid-dashboard,
  .grid-2,
  .grid-3 { grid-template-columns: 1fr; }
}

/* ===== Tablet (sidebar turns into drawer) ===== */
@media (max-width: 768px) {
  .app-layout { display: block; min-height: 100vh; }

  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    width: min(280px, 85vw);
  }
  .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-xl); }
  .sidebar.open + .sidebar-backdrop,
  body.sidebar-open .sidebar-backdrop { display: block; }

  .main-content {
    margin-left: 0;
    padding: 60px 12px 24px;
    max-width: 100vw;
    width: 100%;
    overflow-x: hidden;
    min-width: 0;
  }
  .mobile-menu-btn { display: grid; }

  .mode-selector { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .mode-btn { padding: 14px 8px; font-size: 12.5px; }
  .mode-btn .icon-svg { width: 20px; height: 20px; }

  .page-header {
    flex-direction: column;
    align-items: stretch;
    padding-bottom: 14px;
    margin-bottom: 18px;
    gap: 10px;
  }
  .page-header h1 { font-size: 19px; }
  .page-header .subtitle { font-size: 12.5px; }
  .page-header-actions {
    flex-wrap: wrap;
    gap: 6px;
    width: 100%;
  }
  .page-header-actions .btn { flex: 1 1 auto; justify-content: center; }

  .card {
    padding: 14px;
    border-radius: var(--radius);
    overflow: hidden;
  }
  .card .table-wrapper { margin: 0 -14px -14px; }
  .card .table-wrapper:first-child { margin-top: -14px; }

  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 16px; }
  .stat-card { padding: 14px; }
  .stat-card .value { font-size: 22px; }
  .stat-card .label { font-size: 11px; }
  .stat-card .change { font-size: 11px; }
  .stat-card-icon { width: 28px; height: 28px; }

  /* Modals: bottom-sheet style on mobile */
  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal, .modal-sm, .modal-lg {
    max-width: 100%;
    width: 100%;
    max-height: 92vh;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  }
  .modal-header { padding: 14px 16px; }
  .modal-header h3 { font-size: 15px; }
  .modal-body { padding: 14px 16px; }
  .modal-footer {
    padding: 12px 16px;
    flex-direction: column-reverse;
  }
  .modal-footer .btn { width: 100%; }
  @keyframes modalIn {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
  }

  /* Tables: allow horizontal scroll, smaller padding */
  .table-wrapper {
    -webkit-overflow-scrolling: touch;
    overflow-x: auto;
    max-width: 100%;
  }
  table { min-width: 520px; }
  th, td { padding: 9px 10px; font-size: 12.5px; white-space: nowrap; }
  thead th { font-size: 11px; }
  td .truncate { max-width: 140px !important; }

  /* Forms: prevent iOS zoom (16px), bigger touch targets */
  .form-control,
  input[type="text"], input[type="number"], input[type="email"],
  input[type="password"], input[type="date"], input[type="search"],
  select, textarea {
    font-size: 16px;
    padding: 10px 12px;
    max-width: 100% !important;
  }
  .form-row { grid-template-columns: 1fr; }

  .btn { padding: 10px 14px; font-size: 13.5px; min-height: 40px; }
  .btn-sm { padding: 7px 10px; min-height: 32px; font-size: 12.5px; }
  .btn-lg { padding: 13px 20px; min-height: 46px; }

  /* Filter group wraps if needed */
  .filter-group { flex-wrap: wrap; }

  /* Force wrapping flex rows to stack cleanly */
  .flex-wrap { flex-wrap: wrap !important; }
  .card .flex.gap-12,
  .card .flex.flex-wrap {
    gap: 8px !important;
  }
  .card .flex-wrap > *,
  .card .flex.flex-wrap > * {
    flex: 1 1 100%;
    min-width: 0 !important;
    max-width: 100% !important;
  }
  .card .search-input { min-width: 0 !important; width: 100%; }
  .flex-between { flex-wrap: wrap; gap: 8px; }

  /* Toasts: full width near top */
  .toast-container {
    top: 8px;
    left: 8px;
    right: 8px;
  }
  .toast { min-width: 0; max-width: 100%; }
  @keyframes slideIn {
    from { transform: translateY(-20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
  }

  /* Scanner input larger for mobile */
  .scan-input { font-size: 17px !important; padding: 12px 14px !important; }
  .scan-input-wrap { padding: 14px; }
  .scanner-container { max-width: 100%; }

  /* Dashboard date filter bar */
  .date-filter-bar { gap: 6px !important; }
  .date-pill { padding: 6px 11px !important; font-size: 12px !important; }
  .date-summary { width: 100%; margin-left: 0 !important; margin-top: 4px; font-size: 11.5px !important; }
  .date-custom input[type="date"] { flex: 1 1 100px; min-width: 0; }

  /* Stock-details page-specific overrides (inline styles can't adapt) */
  .filters-grid { grid-template-columns: 1fr !important; gap: 10px !important; }
  .stats-row { grid-template-columns: repeat(2, 1fr) !important; gap: 10px !important; }
  .view-tab { padding: 6px 10px !important; font-size: 12px !important; }
  .actions-bar { flex-wrap: wrap; width: 100%; }
  .actions-bar .btn { flex: 1 1 auto; }

  /* Pagination controls */
  .pagination { gap: 4px !important; padding: 10px !important; }
  .pagination button { padding: 5px 10px !important; font-size: 11.5px !important; }

  /* Prevent long SKUs/words from overflowing */
  .table-cell-mono, .font-mono { word-break: break-all; }
}

/* ===== Phone (small) ===== */
@media (max-width: 480px) {
  .main-content { padding: 56px 10px 20px; }

  .stats-grid { grid-template-columns: 1fr; }
  .stat-card .value { font-size: 24px; }

  .mode-selector { grid-template-columns: repeat(2, 1fr); }

  .page-header h1 { font-size: 18px; }

  .auth-card { padding: 28px 20px; }
  .auth-card h1 { font-size: 19px; }
  .auth-logo-mark { width: 46px; height: 46px; }

  .card { padding: 12px; }
  .card .table-wrapper { margin: 0 -12px -12px; }
  .card .table-wrapper:first-child { margin-top: -12px; }

  /* Stock-details stats collapse fully */
  .stats-row { grid-template-columns: 1fr !important; }

  th, td { padding: 8px 10px; font-size: 12px; }
  table { min-width: 480px; }

  .mobile-menu-btn { width: 38px; height: 38px; top: 10px; left: 10px; }

  /* Dispatch/stat modals with extra-wide tables */
  .modal-body .table-wrapper table { min-width: 440px; }
}

/* ===== Very small phones ===== */
@media (max-width: 360px) {
  .mode-selector { grid-template-columns: 1fr 1fr; }
  .btn { font-size: 13px; padding: 9px 12px; }
  .page-header h1 { font-size: 17px; }
  table { min-width: 420px; }
}

/* ===== Landscape phones: keep modals usable ===== */
@media (max-height: 500px) and (max-width: 900px) {
  .modal { max-height: 96vh; }
  .modal-body { padding: 12px 16px; }
}
