:root {
  --bg: #f5f5f5;
  --surface: #ffffff;
  --border: #e0e0e0;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --danger: #dc2626;
  --success: #16a34a;
  --warning: #d97706;
  --text: #111827;
  --text-muted: #6b7280;
  --radius: 6px;
  --shadow: 0 1px 3px rgba(0,0,0,0.1);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* Login */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  width: 360px;
  box-shadow: var(--shadow);
}
.login-card h1 { font-size: 20px; margin-bottom: 4px; }
.login-card .subtitle { color: var(--text-muted); margin-bottom: 24px; font-size: 13px; }

/* App shell */
#app-shell { display: none; flex-direction: column; min-height: 100vh; }

header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  display: flex;
  align-items: center;
  gap: 32px;
  height: 52px;
}
header .logo { font-weight: 700; font-size: 16px; white-space: nowrap; }
header .logo span { color: var(--primary); }
nav { display: flex; gap: 2px; flex: 1; }
.nav-toggle { display: none; }
nav a {
  padding: 6px 14px;
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  transition: background 0.15s;
}
nav a:hover { background: var(--bg); color: var(--text); }
nav a.active { background: #eff6ff; color: var(--primary); }
.user-info { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.user-info span { color: var(--text-muted); font-size: 13px; }
.btn-logout {
  background: none; border: 1px solid var(--border);
  border-radius: var(--radius); padding: 5px 12px;
  cursor: pointer; font-size: 13px; color: var(--text-muted);
}
.btn-logout:hover { border-color: var(--danger); color: var(--danger); }

main { flex: 1; padding: 24px; max-width: 1280px; margin: 0 auto; width: 100%; }

section { display: none; }
section.active { display: block; }

/* Cards & panels */
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.page-header h2 { font-size: 18px; font-weight: 600; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
}
.card-header h3 { font-size: 15px; font-weight: 600; flex: 1; }
.card-body { padding: 20px; }

/* Sub-tabs */
.sub-tabs { display: flex; gap: 2px; margin-bottom: 20px; border-bottom: 1px solid var(--border); }
.sub-tabs button {
  background: none; border: none; padding: 8px 16px;
  font-size: 14px; font-weight: 500; cursor: pointer;
  color: var(--text-muted); border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.sub-tabs button.active { color: var(--primary); border-bottom-color: var(--primary); }

/* Forms */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 5px; }
.form-group input,
.form-group select,
.form-group textarea {
  width: 100%; padding: 8px 10px;
  border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 14px; font-family: inherit; background: var(--surface);
  transition: border-color 0.15s;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus { outline: none; border-color: var(--primary); }
.form-group textarea { resize: vertical; min-height: 60px; }
.form-group .hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.form-group.error input,
.form-group.error select { border-color: var(--danger); }
.form-group .error-msg { font-size: 12px; color: var(--danger); margin-top: 4px; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }

/* Color picker */
.color-input-row { display: flex; align-items: center; gap: 10px; }
.color-input-row input[type="color"] {
  width: 44px; height: 36px; padding: 2px; border-radius: var(--radius); cursor: pointer;
}
.color-input-row input[type="text"] { flex: 1; }
.color-swatch {
  width: 20px; height: 20px; border-radius: 3px; border: 1px solid var(--border); display: inline-block; vertical-align: middle;
}

/* Checkbox toggle */
.toggle-row { display: flex; align-items: center; gap: 10px; }
.toggle-row input[type="checkbox"] { width: 16px; height: 16px; cursor: pointer; }
.toggle-row label { margin-bottom: 0; cursor: pointer; }

/* Buttons */
.btn {
  padding: 8px 16px; border-radius: var(--radius); font-size: 13px;
  font-weight: 500; cursor: pointer; border: none; transition: background 0.15s;
  display: inline-flex; align-items: center; gap: 6px;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #b91c1c; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left; padding: 10px 12px; font-weight: 600;
  border-bottom: 2px solid var(--border); white-space: nowrap; color: var(--text-muted);
}
td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--bg); }

/* Search / filter bar */
.filter-bar { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.filter-bar input, .filter-bar select {
  padding: 7px 10px; border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 13px; background: var(--surface);
}
.filter-bar input { flex: 1; min-width: 160px; }

/* Status badges */
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 99px;
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px;
}
.badge-active { background: #dcfce7; color: #15803d; }
.badge-inactive { background: #f3f4f6; color: #6b7280; }
.badge-adjustment { background: #fef3c7; color: #92400e; }

/* Slide-over panel */
.panel-overlay {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.3); z-index: 40;
}
.panel-overlay.open { display: flex; justify-content: flex-end; }
.panel {
  background: var(--surface); width: 480px; height: 100%;
  box-shadow: -4px 0 16px rgba(0,0,0,0.12);
  display: flex; flex-direction: column; overflow: hidden;
}
.panel-header {
  padding: 16px 20px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.panel-header h3 { font-size: 16px; font-weight: 600; }
.panel-close {
  background: none; border: none; font-size: 20px; cursor: pointer;
  color: var(--text-muted); line-height: 1;
}
.panel-body { flex: 1; overflow-y: auto; padding: 20px; }
.panel-footer { padding: 16px 20px; border-top: 1px solid var(--border); }

/* Label preview modal */
.modal-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,0.5); z-index: 50;
  align-items: center; justify-content: center;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  width: 420px; max-width: 90vw;
}
.modal-header { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal-header h3 { font-size: 16px; font-weight: 600; }
.modal-body { padding: 20px; }
.modal-footer { padding: 16px 20px; border-top: 1px solid var(--border); display: flex; gap: 10px; justify-content: flex-end; }
.label-preview { border: 1px dashed var(--border); border-radius: var(--radius); padding: 16px; text-align: center; margin-bottom: 16px; }
.label-preview img { max-width: 240px; height: auto; display: block; margin: 0 auto; }
.barcode-text-display { font-family: monospace; font-size: 13px; color: var(--text-muted); margin-top: 8px; }

/* Threshold table */
.threshold-value { cursor: pointer; padding: 3px 6px; border-radius: 4px; }
.threshold-value:hover { background: #eff6ff; }
.threshold-edit { display: none; }
.threshold-edit input { width: 90px; padding: 3px 6px; border: 1px solid var(--primary); border-radius: 4px; font-size: 13px; }

/* Location settings card */
.location-card { max-width: 480px; }

/* Stock grid */
.stock-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
}
.stock-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.stock-card.low { border-color: var(--warning); background: #fffbeb; }
.stock-card.empty { border-color: var(--danger); background: #fef2f2; }
.stock-color-dot {
  width: 28px; height: 28px; border-radius: 50%; margin-bottom: 10px;
  border: 2px solid rgba(0,0,0,0.1);
}
.stock-print-name { font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.stock-inches { font-size: 26px; font-weight: 700; line-height: 1.1; }
.stock-inches span { font-size: 13px; font-weight: 400; color: var(--text-muted); }
.stock-threshold { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.stock-status { margin-top: 8px; }

/* Progress bar */
.progress-bar {
  height: 5px; background: var(--border); border-radius: 3px; overflow: hidden; margin-top: 8px;
}
.progress-bar-fill { height: 100%; border-radius: 3px; background: var(--success); transition: width 0.3s; }
.progress-bar-fill.low { background: var(--warning); }
.progress-bar-fill.empty { background: var(--danger); }

/* Badges (extended) */
.badge-low { background: #fef3c7; color: #92400e; }
.badge-source-pos { background: #eff6ff; color: var(--primary); }
.badge-source-shopify { background: #f0fdf4; color: var(--success); }
.badge-source-manual { background: #faf5ff; color: #7c3aed; }

/* Alert cards */
.alert-card {
  background: var(--surface);
  border: 1px solid var(--warning);
  border-left: 4px solid var(--warning);
  border-radius: var(--radius);
  padding: 14px 18px;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: var(--shadow);
}
.alert-card.acknowledged {
  border-color: var(--border);
  border-left-color: var(--border);
  opacity: 0.65;
}

/* Pagination */
.pagination {
  display: flex; align-items: center; justify-content: center; flex-wrap: wrap;
  gap: 6px; padding: 12px; border-top: 1px solid var(--border);
}
.pagination button {
  padding: 4px 10px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); cursor: pointer; font-size: 12px; color: var(--text);
}
.pagination button:disabled { opacity: 0.4; cursor: not-allowed; }
.pagination button.pg-active { background: var(--primary); color: white; border-color: var(--primary); }
.pagination-info { font-size: 12px; color: var(--text-muted); margin-right: 4px; }

/* Color dot (used in tables) */
.color-dot {
  display: inline-block; width: 12px; height: 12px; border-radius: 50%;
  border: 1px solid rgba(0,0,0,0.1); vertical-align: middle; margin-right: 6px;
}

/* Inline error alert */
.alert {
  padding: 12px 16px; border-radius: var(--radius); margin-bottom: 16px;
  font-size: 13px;
}
.alert-error { background: #fef2f2; border: 1px solid #fecaca; color: var(--danger); }
.alert-success { background: #f0fdf4; border: 1px solid #bbf7d0; color: var(--success); }

/* Searchable select */
.ss-wrap { position: relative; }
.ss-input {
  width: 100%; padding: 8px 10px;
  border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 14px; font-family: inherit; background: var(--surface);
  transition: border-color 0.15s;
}
.ss-input:focus { outline: none; border-color: var(--primary); }
.ss-input.ss-open { border-radius: var(--radius) var(--radius) 0 0; border-bottom-color: var(--border); }
.ss-list {
  display: none; position: absolute; top: 100%; left: 0; right: 0; z-index: 300;
  background: var(--surface); border: 1px solid var(--primary);
  border-top: none; border-radius: 0 0 var(--radius) var(--radius);
  max-height: 240px; overflow-y: auto;
  box-shadow: 0 6px 16px rgba(0,0,0,0.12);
}
.ss-list.open { display: block; }
.ss-item { padding: 8px 12px; cursor: pointer; font-size: 13px; }
.ss-item:hover, .ss-item.ss-focused { background: #eff6ff; color: var(--primary); }
.ss-none { padding: 10px 12px; color: var(--text-muted); font-size: 13px; font-style: italic; }

/* Stock filter chips */
.stock-filter-btn { background: var(--bg); color: var(--text-muted); border: 1px solid var(--border); }
.stock-filter-btn:hover { border-color: var(--primary); color: var(--primary); }
.stock-filter-btn.sf-active { background: var(--primary); color: white; border-color: var(--primary); }

/* Image upload tap area */
.image-upload-area {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  min-height: 100px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.image-upload-area:hover { border-color: var(--primary); background: #f0f7ff; }
#print-image-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
  font-size: 13px;
}
#print-image-placeholder svg { color: var(--text-muted); }

/* Sortable table headers */
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--primary); }
th.sort-asc::after  { content: " ↑"; color: var(--primary); }
th.sort-desc::after { content: " ↓"; color: var(--primary); }

/* Users table */
.role-badge { display:inline-block; padding:2px 8px; border-radius:12px; font-size:12px; font-weight:600; text-transform:capitalize; }
.role-admin { background:#fef3c7; color:#92400e; }
.role-operator { background:#eff6ff; color:#1d4ed8; }
.status-badge { display:inline-block; padding:2px 8px; border-radius:12px; font-size:12px; font-weight:600; }
.status-active { background:#dcfce7; color:#15803d; }
.status-inactive { background:#f3f4f6; color:#6b7280; }
.row-inactive td { opacity:0.55; }

/* =========================================================
   Mobile responsive — 768px and below
   ========================================================= */
@media (max-width: 768px) {

  /* Header — single row with hamburger */
  header {
    height: 52px;
    padding: 0 12px;
    position: relative;
  }
  header .logo { flex: 1; }

  /* Hide email address, keep logout button */
  .user-info span { display: none; }

  /* Hamburger button */
  .nav-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    width: 36px;
    height: 36px;
    font-size: 18px;
    cursor: pointer;
    color: var(--text);
    order: 2;
  }

  /* Nav becomes a dropdown on mobile */
  nav {
    display: none;
    position: absolute;
    top: 52px;
    left: 0;
    right: 0;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    flex-direction: column;
    padding: 8px;
    z-index: 100;
    order: 3;
  }
  nav.open { display: flex; }
  nav a {
    padding: 10px 14px;
    border-radius: var(--radius);
    font-size: 15px;
  }

  /* Main content — tighter padding */
  main { padding: 12px; }

  /* Login card — full width with margin */
  .login-card { width: calc(100% - 32px); padding: 24px; }

  /* Slide-over panel — full screen on mobile */
  .panel { width: 100%; }

  /* Form grid — single column */
  .form-row { grid-template-columns: 1fr; }

  /* Page header — allow wrapping */
  .page-header { flex-wrap: wrap; gap: 8px; }
  .page-header h2 { font-size: 16px; }

  /* Filter bar — stack inputs */
  .filter-bar { flex-direction: column; }
  .filter-bar input, .filter-bar select { width: 100%; min-width: unset; }

  /* Buttons — bigger touch targets */
  .btn { min-height: 38px; padding: 8px 14px; }
  .btn-sm { min-height: 32px; padding: 5px 10px; }

  /* Stock grid — 2 columns */
  .stock-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stock-card { padding: 12px; }
  .stock-inches { font-size: 22px; }

  /* Sub-tabs — scrollable */
  .sub-tabs { overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  .sub-tabs::-webkit-scrollbar { display: none; }
  .sub-tabs button { white-space: nowrap; }

  /* Tables — reduce padding */
  th, td { padding: 8px 8px; }

  /* Alert cards — stack content */
  .alert-card { flex-wrap: wrap; gap: 8px; }

  /* Card body — tighter */
  .card-body { padding: 14px; }
  .card-header { padding: 12px 14px; }
}

/* Extra small — phones in portrait */
@media (max-width: 420px) {
  .stock-grid { grid-template-columns: repeat(2, 1fr); }
  .page-header { flex-direction: column; align-items: flex-start; }
  .form-actions { flex-direction: column; }
  .form-actions .btn { width: 100%; justify-content: center; }
}
