:root {
  --bg: #f9fafb;
  --panel: #ffffff;
  --panel-2: #f3f4f6;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --text: #111827;
  --muted: #6b7280;
  --accent: #497256;
  --accent-2: #3a5a44;
  --accent-soft: #eef3ef;
  --danger: #dc2626;
  --success: #15803d;
  --row-hover: rgba(0,0,0,0.025);
  --shadow: rgba(0,0,0,0.06);
}

[data-theme="dark"] {
  --bg: #0b0f17;
  --panel: #111827;
  --panel-2: #1f2937;
  --border: #273142;
  --border-strong: #374151;
  --text: #e5e7eb;
  --muted: #9ca3af;
  --accent: #84a890;
  --accent-2: #6f9479;
  --accent-soft: rgba(132,168,144,0.12);
  --danger: #ef4444;
  --success: #34d399;
  --row-hover: rgba(255,255,255,0.03);
  --shadow: rgba(0,0,0,0.4);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Instrument Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
  width: 100%;
  max-width: 100vw;
  overscroll-behavior-x: none;
  -webkit-font-smoothing: antialiased;
}

body {
  padding-bottom: env(safe-area-inset-bottom);
  position: relative;
}

#app {
  width: 100%;
  max-width: 100vw;
  overflow-x: hidden;
}

.icon {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: 0 0 auto;
}
.icon-sm { width: 14px; height: 14px; }
.icon-lg { width: 22px; height: 22px; }

header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  padding: env(safe-area-inset-top) 16px 0;
  width: 100%;
  box-sizing: border-box;
}
header .bar {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 56px;
}
header h1 {
  font-size: 17px;
  margin: 0;
  font-weight: 600;
  color: var(--text);
  line-height: 1.2;
}
header .title-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
header .header-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 2px;
  flex-wrap: wrap;
}
header .version-badge,
header .worker-badge {
  font-size: 10px;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 0.3px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
header .worker-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  display: inline-block;
}
header .worker-dot.alive { background: var(--success); box-shadow: 0 0 0 2px rgba(21,128,61,0.15); }
header .worker-dot.stale { background: var(--danger); box-shadow: 0 0 0 2px rgba(220,38,38,0.12); }
header .iconbtn,
header .back {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 8px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
header .iconbtn:hover,
header .back:hover {
  color: var(--text);
  background: var(--panel-2);
}
header .back { margin-left: -8px; }
header .iconbtn { margin-right: -8px; }

nav.tabs {
  display: flex;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
nav.tabs a {
  flex: 1;
  text-align: center;
  padding: 12px 8px;
  color: var(--muted);
  text-decoration: none;
  font-weight: 500;
  font-size: 13px;
  border-bottom: 2px solid transparent;
}
nav.tabs a.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

main {
  padding: 16px;
  max-width: 1100px;
  margin: 0 auto;
  width: 100%;
  box-sizing: border-box;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 12px;
  max-width: 100%;
  box-sizing: border-box;
  overflow-wrap: anywhere;
}

button, .btn {
  background: var(--accent);
  color: white;
  border: 1px solid var(--accent);
  border-radius: 6px;
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-family: inherit;
  line-height: 1.3;
  transition: background-color 0.12s, border-color 0.12s, color 0.12s;
}
button:hover, .btn:hover { background: var(--accent-2); border-color: var(--accent-2); }
button.secondary, .btn.secondary {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border-strong);
}
button.secondary:hover, .btn.secondary:hover {
  background: var(--panel-2);
  border-color: var(--border-strong);
}
button.ghost, .btn.ghost {
  background: transparent;
  color: var(--accent);
  border: 1px solid transparent;
}
button.ghost:hover, .btn.ghost:hover {
  background: var(--accent-soft);
  color: var(--accent-2);
}
button.danger, .btn.danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--border-strong);
}
button.danger:hover, .btn.danger:hover { background: rgba(220,38,38,0.06); border-color: var(--danger); }

.card.danger-zone {
  border-color: rgba(220,38,38,0.25);
  background: rgba(220,38,38,0.02);
  margin-top: 16px;
}
.card.danger-zone h3 {
  margin-top: 0;
  color: var(--danger);
  font-size: 14px;
}

table.admin-users-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
table.admin-users-table th,
table.admin-users-table td {
  padding: 8px 10px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
table.admin-users-table th {
  font-weight: 600;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
table.admin-users-table tr:last-child td { border-bottom: none; }
.admin-role-select {
  font: inherit;
  padding: 4px 8px;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  background: var(--panel);
  color: var(--text);
}
button:disabled { opacity: 0.5; cursor: not-allowed; }

input, textarea, select {
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  padding: 8px 12px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  line-height: 1.4;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
label {
  display: block;
  margin-bottom: 4px;
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
}
.field { margin-bottom: 12px; }

.ai-hint {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
  font-size: 11px;
  color: var(--muted);
}
.ai-hint-label {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 0.4px;
  color: var(--accent);
  font-weight: 500;
}
.ai-hint-val {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
}
.ai-hint-use {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--border-strong);
  padding: 1px 8px;
  font-size: 10px;
  border-radius: 999px;
  font-weight: 500;
  text-transform: lowercase;
  letter-spacing: 0.3px;
  line-height: 1.4;
  cursor: pointer;
}
.ai-hint-use:hover { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-2); }

.row {
  display: flex;
  gap: 8px;
  align-items: center;
}
.row > * { flex: 1; }
.row > .fixed { flex: 0 0 auto; }

.grid {
  display: grid;
}

.list-item {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: var(--text);
  margin-bottom: 8px;
  transition: border-color 0.12s;
}
.list-item:hover { border-color: var(--border-strong); }
.list-item .thumb {
  width: 44px;
  height: 44px;
  border-radius: 6px;
  object-fit: cover;
  background: var(--panel-2);
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
}
.list-item .code-thumb {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
  font-size: 15px;
  letter-spacing: 0.5px;
}
.list-item .main { flex: 1; min-width: 0; }
.list-item .title { font-weight: 600; margin-bottom: 2px; font-size: 14px; }
.list-item .sub { color: var(--muted); font-size: 12px; }
.list-item .badge {
  background: var(--panel-2);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 11px;
  color: var(--muted);
  font-weight: 500;
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 40px 20px;
  font-size: 14px;
}

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  max-width: 100%;
}
table {
  border-collapse: collapse;
  font-size: 13px;
  min-width: 700px;
  width: 100%;
}
th, td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
th {
  background: var(--panel-2);
  font-weight: 500;
  position: sticky;
  top: 0;
  color: var(--muted);
  text-transform: uppercase;
  font-size: 10px;
  letter-spacing: 0.5px;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--row-hover); }
td img.thumb {
  width: 32px;
  height: 32px;
  object-fit: cover;
  border-radius: 4px;
}

/* Airtable-like editable grid — table-layout: fixed + <colgroup> widths force
   th and td in each column to render at exactly the same width. */
table.grid {
  table-layout: fixed;
  width: max-content;
  border-collapse: collapse;
}
table.grid th { position: static !important; top: auto !important; }
table.grid td,
table.grid th {
  padding: 6px 8px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Missing-values filter chips */
.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 12px;
  background: var(--panel);
  cursor: pointer;
  font-family: inherit;
  color: var(--text);
}
.filter-chip:hover { border-color: var(--accent); }
.filter-chip.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}
.filter-chip .count {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.filter-chip.active .count { color: white; }
.filter-clear {
  font-size: 12px;
  color: var(--muted);
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 8px;
  font-family: inherit;
}
.filter-clear:hover { color: var(--danger); }
table.grid th,
table.grid td {
  vertical-align: middle;
  border-right: 1px solid var(--border);
  box-sizing: border-box;
  white-space: nowrap;
}
table.grid th:last-child,
table.grid td:last-child { border-right: none; }
table.grid td.ship-cell,
table.grid td.id-cell {
  cursor: pointer;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}
table.grid td.id-cell { color: var(--muted); }
table.grid td.ship-cell:hover,
table.grid td.id-cell:hover { color: var(--accent); }
table.grid td.photos-cell {
  cursor: pointer;
  padding: 6px 8px;
}
table.grid .photo-strip {
  display: flex;
  gap: 4px;
  align-items: center;
}
table.grid .photo-strip img.thumb {
  width: 36px;
  height: 36px;
  object-fit: cover;
  border-radius: 4px;
  border: 1px solid var(--border);
}
table.grid .photo-strip .thumb.empty {
  width: 36px;
  height: 36px;
  border: 1px dashed var(--border);
  border-radius: 4px;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--panel-2);
}
table.grid td.edit-cell {
  cursor: text;
  position: relative;
  min-width: 90px;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
}
table.grid td.edit-cell:hover {
  background: var(--accent-soft);
  outline: 1px solid var(--accent);
  outline-offset: -1px;
}
table.grid td.edit-cell.empty {
  background: rgba(220, 38, 38, 0.04);
}
table.grid td.edit-cell.warn {
  background: rgba(217, 119, 6, 0.05);
}
table.grid td.edit-cell.warn .icon-warn {
  width: 14px;
  height: 14px;
  margin-left: 4px;
  vertical-align: -2px;
  color: rgb(217, 119, 6);
}

.field-warn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  margin-top: 4px;
  color: rgb(217, 119, 6);
}
.field-warn .icon-warn { width: 14px; height: 14px; }

.input-with-action {
  display: flex;
  gap: 6px;
  align-items: stretch;
}
.input-with-action input,
.input-with-action textarea { flex: 1; min-width: 0; }
.input-with-action .input-action {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  padding: 0 12px;
  white-space: nowrap;
}

.upc-display {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
  font-size: 12px;
  color: var(--muted);
}
.upc-display .upc-label {
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-size: 10px;
}
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  max-width: 420px;
  width: 100%;
  box-shadow: 0 12px 40px rgba(0,0,0,0.25);
}
.modal-msg {
  font-family: inherit;
  font-size: 13px;
  margin: 0 0 14px;
  white-space: pre-wrap;
  line-height: 1.45;
  color: var(--text);
}
.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.upc-display code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: var(--panel-2);
  padding: 1px 6px;
  border-radius: 4px;
  border: 1px solid var(--border);
  color: var(--text);
  user-select: all;
}
table.grid td.edit-cell.empty .placeholder { color: rgba(220, 38, 38, 0.5); }
table.grid td.edit-cell.saving { opacity: 0.6; }
table.grid td.edit-cell input,
table.grid td.edit-cell textarea {
  width: 100%;
  border: 1px solid var(--accent);
  background: var(--panel);
  padding: 6px 8px;
  font-size: 13px;
  font-family: inherit;
  border-radius: 4px;
  outline: none;
  resize: vertical;
}
table.grid td.num { text-align: right; font-variant-numeric: tabular-nums; }

table.grid td.actions-cell,
table.grid th.actions-cell {
  position: sticky;
  right: 0;
  z-index: 1;
  padding: 0;
  vertical-align: middle;
  text-align: center;
  /* Solid background so non-sticky cells don't bleed through during scroll */
  background: var(--panel);
  box-shadow: -4px 0 6px -4px rgba(0, 0, 0, 0.15);
}
table.grid th.actions-cell { background: var(--panel-2); }
table.grid tr:hover td.actions-cell { background: var(--row-hover); }
table.grid td.actions-cell .actions-inner {
  display: flex;
  gap: 4px;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 4px;
}
table.grid .row-action {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 6px;
  cursor: pointer;
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
table.grid .row-action:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}
table.grid .row-action:disabled { opacity: 0.5; cursor: not-allowed; }
table.grid .row-action .icon { width: 14px; height: 14px; }

.photos {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}
.photos .slot {
  aspect-ratio: 1;
  background: var(--panel-2);
  border: 1px dashed var(--border-strong);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  position: relative;
  overflow: hidden;
}
.photos .slot img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.photos .slot .remove {
  position: absolute;
  top: 4px;
  right: 4px;
  background: rgba(17,24,39,0.7);
  color: white;
  border: 1px solid transparent;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  padding: 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.photos .slot .remove .icon { stroke-width: 2.2; }
.photos .slot .remove:hover { background: rgba(17,24,39,0.9); }

.photos .slot .detect-photo {
  position: absolute;
  left: 4px;
  background: rgba(17,24,39,0.7);
  color: white;
  border: 1px solid transparent;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  padding: 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.photos .slot .detect-qr  { top: 4px; }
.photos .slot .detect-ean { top: 30px; }
.photos .slot .detect-photo .icon { stroke-width: 2.2; }
.photos .slot .detect-photo:hover { background: rgba(17,24,39,0.9); }
.photos .slot .detect-photo:disabled { opacity: 0.5; cursor: not-allowed; }

.photos .slot .rotate-photo {
  position: absolute;
  top: 30px;
  right: 4px;
  background: rgba(17,24,39,0.7);
  color: white;
  border: 1px solid transparent;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  padding: 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.photos .slot .rotate-photo .icon { stroke-width: 2.2; }
.photos .slot .rotate-photo:hover { background: rgba(17,24,39,0.9); }
.photos .slot .rotate-photo:disabled { opacity: 0.5; cursor: not-allowed; }

/* Primary-photo star (for product-grouping similarity). Lives bottom-left,
   opposite the edit button (bottom-right). */
.photos .slot .primary-photo {
  position: absolute;
  bottom: 4px;
  left: 4px;
  background: rgba(17,24,39,0.7);
  color: white;
  border: 1px solid transparent;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  padding: 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.photos .slot .primary-photo .icon { stroke-width: 2.2; }
.photos .slot .primary-photo:hover { background: rgba(17,24,39,0.9); }
.photos .slot .primary-photo.is-primary { background: var(--accent); color: white; }
.photos .slot .primary-photo.is-default { background: rgba(73,114,86,0.45); }
.photos .slot .primary-photo:disabled { opacity: 0.5; cursor: not-allowed; }

.photos .slot .straighten-photo,
.photos .slot .sharpen-photo,
.photos .slot .edit-photo {
  position: absolute;
  background: rgba(17,24,39,0.7);
  color: white;
  border: 1px solid transparent;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  padding: 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.photos .slot .straighten-photo { top: 56px; left: 4px; }
.photos .slot .sharpen-photo    { top: 56px; right: 4px; }
.photos .slot .edit-photo       { bottom: 4px; right: 4px; }
.photos .slot .straighten-photo .icon,
.photos .slot .sharpen-photo .icon,
.photos .slot .edit-photo .icon { stroke-width: 2.2; }
.photos .slot .straighten-photo:hover,
.photos .slot .sharpen-photo:hover,
.photos .slot .edit-photo:hover { background: rgba(17,24,39,0.9); }
.photos .slot .straighten-photo:disabled,
.photos .slot .sharpen-photo:disabled,
.photos .slot .edit-photo:disabled { opacity: 0.5; cursor: not-allowed; }

/* Photo editor (per-photo modal: zoom, pan, region select, OCR, barcode) */
.editor-overlay {
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 240;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}
.editor-toolbar {
  display: flex;
  gap: 6px;
  align-items: center;
  padding: 10px 12px;
  background: rgba(0,0,0,0.65);
  color: white;
  flex: 0 0 auto;
}
.editor-toolbar .btn { font-size: 13px; padding: 6px 12px; }
.editor-stage {
  flex: 1;
  position: relative;
  overflow: hidden;
  touch-action: none;
  background: #000;
  min-height: 0;
}
.editor-canvas,
.editor-overlay-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}
.editor-overlay-canvas { pointer-events: none; }
.editor-region-bar {
  display: flex;
  gap: 6px;
  padding: 8px 12px;
  background: rgba(0,0,0,0.65);
  flex: 0 0 auto;
  flex-wrap: wrap;
  justify-content: center;
}
.editor-region-bar .btn { font-size: 13px; padding: 6px 12px; }
.editor-status {
  text-align: center;
  color: white;
  background: rgba(0,0,0,0.4);
  font-size: 12px;
  padding: 6px 12px;
  flex: 0 0 auto;
}

/* Perspective corner-picker overlay */
.persp-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);
  z-index: 250;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}
.persp-img-wrap {
  flex: 1;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  min-height: 0;
}
.persp-img {
  max-width: 100%;
  max-height: 100%;
  display: block;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.persp-svg {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.persp-bar {
  display: flex;
  gap: 8px;
  justify-content: center;
  padding: 12px;
  background: rgba(0,0,0,0.4);
}
.persp-status {
  text-align: center;
  color: white;
  font-size: 13px;
  padding: 4px 12px 12px;
  background: rgba(0,0,0,0.4);
}

.cam-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 100vh;
  height: 100dvh;
  background: #000;
  z-index: 200;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding-bottom: env(safe-area-inset-bottom);
  padding-top: env(safe-area-inset-top);
  box-sizing: border-box;
}
body.cam-open { overflow: hidden; touch-action: none; }

input.input-error,
textarea.input-error {
  border-color: var(--danger) !important;
  background: rgba(220, 38, 38, 0.04);
  animation: shake 0.3s;
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-3px); }
  75% { transform: translateX(3px); }
}

/* Fullscreen QR scanner — uses absolute positioning, not flex, so the reader
   element has a real pixel height before Html5Qrcode attaches a video. */
.qr-overlay {
  position: fixed;
  inset: 0;
  height: 100vh;
  height: 100dvh;
  background: #000;
  z-index: 200;
  overflow: hidden;
}
.qr-overlay .qr-reader {
  position: absolute;
  inset: 0;
  background: #000;
  overflow: hidden;
}
/* No qrbox is requested from html5-qrcode (see _scanCodeFullscreen), so the
   only DOM that lives under .qr-reader is a wrapper containing <video>. We
   pin the video with position:fixed so it always fills the viewport, even
   when html5-qrcode's wrapper is sized to the camera's native resolution. */
.qr-overlay .qr-reader video {
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  width: 100vw !important;
  height: 100vh !important;
  height: 100dvh !important;
  object-fit: cover !important;
  display: block !important;
  background: #000;
  z-index: 0;
}

/* Aim reticle drawn on top of the video. Two presets — square for QR, wide
   strip for 1D barcodes. Pure CSS, no canvas needed. */
.qr-reticle {
  position: absolute;
  pointer-events: none;
  border: 2px solid rgba(255,255,255,0.85);
  border-radius: 8px;
  box-shadow: 0 0 0 9999px rgba(0,0,0,0.45);
  z-index: 1;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}
.qr-reticle-qr {
  width: min(72vw, 320px);
  height: min(72vw, 320px);
  max-height: 60vh;
}
.qr-reticle-barcode {
  width: min(80vw, 360px);
  height: min(34vw, 150px);
  max-height: 30vh;
}
.qr-reticle::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  border: 1px solid rgba(255,255,255,0.25);
}
.qr-overlay .qr-status {
  position: absolute;
  top: calc(20px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  color: white;
  background: rgba(0,0,0,0.6);
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 13px;
  z-index: 2;
  pointer-events: none;
}
.qr-overlay .qr-bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: space-between;
  padding: 14px 20px max(20px, env(safe-area-inset-bottom));
  background: rgba(0,0,0,0.6);
  z-index: 2;
}
.qr-overlay .cam-side {
  background: none;
  color: white;
  border: 1px solid rgba(255,255,255,0.4);
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 14px;
  cursor: pointer;
  font-family: inherit;
}
.cam-overlay video {
  flex: 1;
  width: 100%;
  min-height: 0;
  object-fit: cover;
  background: #000;
}
.cam-overlay .cam-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px max(20px, env(safe-area-inset-bottom));
  background: rgba(0,0,0,0.6);
  color: white;
  flex: 0 0 auto;
}
.cam-overlay .cam-shutter {
  width: 68px;
  height: 68px;
  border-radius: 50%;
  background: white;
  border: 4px solid rgba(255,255,255,0.4);
  cursor: pointer;
  padding: 0;
}
.cam-overlay .cam-shutter:hover { background: white; }
.cam-overlay .cam-shutter:active { transform: scale(0.94); }
.cam-overlay .cam-side {
  background: none;
  color: white;
  border: 1px solid rgba(255,255,255,0.4);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
}
.cam-overlay .cam-side:hover { background: rgba(255,255,255,0.1); border-color: rgba(255,255,255,0.4); }
.cam-overlay .cam-thumbs {
  position: absolute;
  top: calc(12px + env(safe-area-inset-top));
  right: 12px;
  display: flex;
  gap: 6px;
  z-index: 2;
}
.cam-overlay .cam-thumbs img {
  width: 40px;
  height: 40px;
  object-fit: cover;
  border-radius: 4px;
  border: 1px solid rgba(255,255,255,0.6);
}
.cam-overlay .cam-count {
  position: absolute;
  top: calc(12px + env(safe-area-inset-top));
  left: 12px;
  color: white;
  font-size: 12px;
  background: rgba(0,0,0,0.5);
  padding: 5px 10px;
  border-radius: 999px;
  z-index: 2;
}
.cam-flash {
  position: absolute;
  inset: 0;
  background: white;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s;
}
.cam-flash.fire { opacity: 0.85; transition: opacity 0s; }

#qr-reader {
  width: 100%;
  max-width: 400px;
  margin: 0 auto 12px;
  border-radius: 6px;
  overflow: hidden;
}

.status {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.2px;
  border: 1px solid transparent;
}
.status.ok { background: rgba(21,128,61,0.08); color: var(--success); border-color: rgba(21,128,61,0.2); }
.status.pending { background: var(--panel-2); color: var(--muted); border-color: var(--border); }
.status.error { background: rgba(220,38,38,0.08); color: var(--danger); border-color: rgba(220,38,38,0.2); }
.status.skipped { background: var(--panel-2); color: var(--muted); border-color: var(--border); }
.status.queued { background: var(--accent-soft); color: var(--accent); border-color: rgba(73,114,86,0.2); }
.status.processing { background: var(--accent-soft); color: var(--accent); border-color: rgba(73,114,86,0.2); }

/* Reset global `button` defaults so the badge keeps its compact pill look. */
.fingerprint-badge {
  display: inline-flex !important;
  align-items: center;
  gap: 4px;
  padding: 2px 8px !important;
  border-radius: 4px !important;
  font-size: 11px !important;
  font-weight: 500 !important;
  letter-spacing: 0.2px;
  border: 1px solid transparent !important;
  background: transparent !important;
  background-image: none !important;
  box-shadow: none !important;
  cursor: pointer;
  font-family: inherit;
  line-height: 1.3;
  transition: background-color 0.12s, border-color 0.12s, color 0.12s;
}
.fingerprint-badge:hover { filter: brightness(1.05); }
.fingerprint-badge.busy { cursor: progress; opacity: 0.7; }
.fingerprint-badge:disabled { cursor: progress; }
.fingerprint-badge.present {
  background: rgba(21,128,61,0.06) !important;
  color: var(--success) !important;
  border-color: rgba(21,128,61,0.18) !important;
}
.fingerprint-badge.missing {
  background: var(--panel-2) !important;
  color: var(--muted) !important;
  border-color: var(--border) !important;
}
.fingerprint-badge.missing:hover {
  background: var(--accent-soft) !important;
  color: var(--accent) !important;
  border-color: rgba(73,114,86,0.25) !important;
}
.fingerprint-badge .icon-sm { width: 12px; height: 12px; }

.fp-dot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  cursor: help;
}
.fp-dot.present { color: var(--success); opacity: 0.85; }
.fp-dot.missing { color: var(--muted); opacity: 0.35; }
.fp-dot .icon-sm { width: 12px; height: 12px; }

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

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--panel);
  border: 1px solid var(--text);
  padding: 8px 14px;
  border-radius: 6px;
  z-index: 1000;
  font-size: 13px;
  box-shadow: 0 4px 12px var(--shadow);
}

.fab {
  position: fixed;
  bottom: calc(20px + env(safe-area-inset-bottom));
  right: 20px;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  border: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  box-shadow: 0 6px 16px rgba(73,114,86,0.35);
  z-index: 50;
}
.fab:hover { background: var(--accent-2); }
.fab .icon { width: 22px; height: 22px; stroke-width: 2; }

h2 { font-size: 16px; margin: 0 0 12px; font-weight: 600; }
h3 {
  font-size: 11px;
  margin: 16px 0 8px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  font-weight: 500;
}
.muted { color: var(--muted); font-size: 13px; }

textarea { resize: vertical; min-height: 60px; }

/* Login card */
.login-card {
  max-width: 420px;
  margin: 32px auto;
}
.login-card label {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
  margin-bottom: 6px;
}
.login-card input { width: 100%; }

/* Header user-icon button + popover */
.user-icon-wrap {
  position: relative;
  margin-right: 6px;
}
.user-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  cursor: pointer;
  padding: 0;
  font-family: inherit;
}
.user-icon-btn:hover { border-color: var(--accent); color: var(--accent); }
.user-icon-btn .icon { width: 18px; height: 18px; }

.user-popover {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 220px;
  max-width: 280px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  z-index: 30;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.user-popover-email {
  font-size: 13px;
  color: var(--text);
  word-break: break-all;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.user-popover-logout {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
}
.user-popover-logout:hover {
  background: rgba(220, 38, 38, 0.08);
  color: var(--danger);
  border-color: var(--danger);
}

/* AI run history table inside the scan editor */
.ai-log-card { padding: 12px 16px; }
table.ai-log-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
table.ai-log-table th,
table.ai-log-table td {
  padding: 4px 8px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  vertical-align: top;
  text-align: left;
}
table.ai-log-table th {
  text-transform: uppercase;
  font-size: 10px;
  letter-spacing: 0.5px;
  color: var(--muted);
}
table.ai-log-table .num { text-align: right; font-variant-numeric: tabular-nums; }
table.ai-log-table .ai-log-err {
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
  max-width: 380px;
}
table.ai-log-table tr.ai-log-stuck .ai-log-err,
table.ai-log-table tr.ai-log-error .ai-log-err,
table.ai-log-table tr.ai-log-embed_error .ai-log-err,
table.ai-log-table tr.ai-log-exception .ai-log-err { color: var(--danger); }

.status.embedding   { background: var(--accent-soft); color: var(--accent); border-color: rgba(73,114,86,0.2); }
.status.embed_ok    { background: rgba(21,128,61,0.08); color: var(--success); border-color: rgba(21,128,61,0.2); }
.status.embed_error { background: rgba(220,38,38,0.08); color: var(--danger); border-color: rgba(220,38,38,0.2); }

/* ----- Settings page (tabbed) ----- */
.settings-tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
/* Explicit reset of every property the global `button` rule sets — the shorthand
   `background: none` doesn't reset background-color in every renderer, and we
   need to drop the rounded fill, border, and accent color too. */
.settings-tab,
.settings-tab:hover,
.settings-tab.active {
  background-color: transparent !important;
  background-image: none !important;
  border: none !important;
  border-radius: 0 !important;
  box-shadow: none !important;
  padding: 8px 14px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  margin-bottom: -1px;
  display: inline-flex;
  align-items: center;
}
.settings-tab {
  border-bottom: 2px solid transparent !important;
  color: var(--muted);
}
.settings-tab:hover {
  border-bottom: 2px solid transparent !important;
  color: var(--text);
}
.settings-tab.active {
  border-bottom: 2px solid var(--accent) !important;
  color: var(--accent);
}
/* Delete tab: keep the muted/active baseline behavior, just tint red so the
   destructive action announces itself in the tab strip. */
.settings-tab.settings-tab-danger { color: var(--danger); }
.settings-tab.settings-tab-danger:hover { color: var(--danger); }
.settings-tab.settings-tab-danger.active {
  color: var(--danger);
  border-bottom-color: var(--danger) !important;
}
.settings-content { display: block; }
.settings-panel { display: flex; flex-direction: column; gap: 12px; }
.settings-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 4px;
}

/* Products view (per-shipment, visual-similarity grouping) */
.products-wrap {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.products-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.product-card {
  display: flex;
  gap: 12px;
  padding: 10px 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  align-items: flex-start;
  transition: border-color 0.12s, background-color 0.12s, box-shadow 0.12s;
}
.product-card.drop-target {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: 0 0 0 2px rgba(73,114,86,0.25);
}
/* Reorder mode: an accent line on the top/bottom edge marks where the
   dragged group will land relative to this card. */
.product-card.reorder-before { box-shadow: 0 -3px 0 0 var(--accent) inset, 0 -3px 0 0 var(--accent); }
.product-card.reorder-after  { box-shadow: 0  3px 0 0 var(--accent) inset, 0  3px 0 0 var(--accent); }
.product-card[draggable="true"] {
  cursor: grab;
}
.product-card[draggable="true"]:active { cursor: grabbing; }
.product-card.dragging { opacity: 0.5; }
.product-thumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}
.product-card-main { flex: 1 1 auto; min-width: 0; }
.product-card-header {
  display: flex; align-items: baseline; gap: 12px;
  flex-wrap: wrap;
}
.product-label {
  font-weight: 600;
  font-size: 14px;
}
.product-card-actions { flex: 0 0 auto; }

/* Per-scan thumb tile inside a product card. Each tile represents one
   variant in the cluster — its primary photo, with size + ID overlays. */
.scan-thumb {
  position: relative;
  width: 88px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  border-radius: 4px;
  text-decoration: none;
  color: inherit;
}
.scan-thumb:active { cursor: grabbing; }
.scan-thumb.dragging { opacity: 0.4; }
.scan-thumb .thumb-img {
  width: 88px;
  height: 88px;
  object-fit: cover;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  display: block;
  pointer-events: none; /* let drag events bubble to parent */
}
.scan-thumb .thumb-img.empty {
  display: flex; align-items: center; justify-content: center;
  color: var(--muted);
}
.scan-thumb-size {
  position: absolute;
  top: 4px; left: 4px;
  background: rgba(0,0,0,0.65);
  color: white;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.3px;
  padding: 2px 5px;
  border-radius: 3px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  pointer-events: none;
}
.scan-thumb-fp.missing {
  position: absolute;
  top: 4px; right: 4px;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--danger);
  border: 1px solid white;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.2);
  pointer-events: none;
}
.scan-thumb-sub {
  font-size: 10px;
  color: var(--muted);
  text-align: center;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.scan-thumb:hover .thumb-img { border-color: var(--accent); }

/* Drop-target zone at the end of the products list — drop a scan onto this
   to spin up a fresh product group containing just that scan. */
.new-group-drop {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 16px;
  border: 2px dashed var(--border-strong);
  border-radius: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  background: var(--panel-2);
  transition: border-color 0.12s, background-color 0.12s, color 0.12s;
}
.new-group-drop.drop-target {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}
.new-group-drop .icon-sm,
.new-group-drop .icon { width: 16px; height: 16px; }

/* Product cell in the per-shipment grid */
table.grid td.product-cell {
  cursor: pointer;
  font-size: 12px;
}
table.grid td.product-cell:hover { background: var(--accent-soft); }
table.grid td.product-cell.empty { color: var(--muted); font-style: italic; }

/* Move-to-group picker modal */
.pg-modal { max-width: 420px; width: 100%; }
.pg-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 360px;
  overflow-y: auto;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 6px;
}
.pg-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
}
.pg-row:hover { background: var(--panel-2); }
.pg-row > input[type="radio"] { flex: 0 0 auto; margin: 0; }
.pg-row .pg-label {
  flex: 1 1 auto;
  min-width: 0;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Export tab — endpoint URL + actions */
.export-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}
.export-row .btn { font-size: 13px; padding: 6px 12px; }
.export-url {
  flex: 1 1 200px;
  min-width: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 6px 10px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  user-select: all;
}

/* ----- Configure modal (legacy class kept for any reuse, mostly unused now) ----- */
.cf-modal { max-width: 760px; width: 100%; }
.cf-section { margin-bottom: 16px; }
.cf-label {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
  margin-bottom: 6px;
}
.cf-table-head {
  display: grid;
  grid-template-columns: 140px 140px 1fr 120px 36px;
  gap: 6px;
  font-size: 10px;
  text-transform: uppercase;
  color: var(--muted);
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}
.cf-table-head.cf-head-typed {
  grid-template-columns: 140px 140px 100px 1fr 120px 36px;
}
.cf-row.cf-row-typed {
  grid-template-columns: 140px 140px 100px 1fr 120px 36px !important;
}
.cf-row.cf-row-typed select {
  font-size: 13px;
  padding: 6px 6px;
  font-family: inherit;
  width: 100%;
}
@media (max-width: 720px) {
  .cf-head-typed { display: none; }
  .cf-row.cf-row-typed { grid-template-columns: 1fr 1fr !important; }
  .cf-row.cf-row-typed > :nth-child(3),
  .cf-row.cf-row-typed > :nth-child(4),
  .cf-row.cf-row-typed > :nth-child(5) { grid-column: span 2; }
  .cf-row.cf-row-typed > :nth-child(6) { grid-column: span 2; justify-self: end; }
}
.cf-rows { display: flex; flex-direction: column; gap: 6px; }

/* Standard-fields opt-out — flat list, one row per field. */
.cf-std-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.cf-std-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  font-size: 13px;
  cursor: pointer;
  border-radius: 4px;
  line-height: 1.3;
}
.cf-std-item:hover { background: var(--panel-2); }
.cf-std-item input[type="checkbox"] {
  flex: 0 0 auto;
  margin: 0;
  width: 16px;
  height: 16px;
}
.cf-std-item .cf-std-key {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-weight: 600;
  flex: 0 0 auto;
}
.cf-std-item .cf-std-hint {
  color: var(--muted);
  font-size: 12px;
  flex: 1 1 auto;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cf-files {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 200px;
  overflow-y: auto;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: 6px;
}
/* Force tight, left-aligned row layout — overrides any inherited grid/text-align
   from the surrounding modal CSS. */
.cf-file-row {
  display: flex !important;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  font-size: 13px;
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 4px;
  text-align: left;
  width: 100%;
  box-sizing: border-box;
}
.cf-file-row > input[type="checkbox"] {
  flex: 0 0 auto;
  margin: 0;
}
.cf-file-row .cf-file-name {
  flex: 1 1 auto;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
.cf-file-row .muted,
.cf-file-row .files-row-err {
  flex: 0 0 auto;
  white-space: nowrap;
}
.cf-file-row:hover { background: var(--panel-2); }
.cf-row {
  display: grid;
  grid-template-columns: 140px 140px 1fr 120px 36px;
  gap: 6px;
  align-items: center;
}
.cf-row input { font-size: 13px; padding: 6px 8px; }
.cf-row .btn { padding: 6px 8px; }
@media (max-width: 720px) {
  .cf-table-head { display: none; }
  .cf-row { grid-template-columns: 1fr 1fr; }
  .cf-row > :nth-child(3),
  .cf-row > :nth-child(4) { grid-column: span 2; }
  .cf-row > :nth-child(5) { grid-column: span 2; justify-self: end; }
}

/* ----- SKU read-only line in scan editor (uses .upc-display look) ----- */
/* No new rule needed — .upc-display already styled. */

/* ----- Grid SKU column ----- */
table.grid td.sku-cell {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  color: var(--text);
  background: var(--accent-soft);
}

/* ----- Reference files section ----- */
.files-card { padding: 12px 16px; }
.files-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  gap: 8px;
}
.files-list { display: flex; flex-direction: column; gap: 6px; }
.files-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel);
}
.files-row-main { min-width: 0; flex: 1; }
.files-row-name {
  font-weight: 500;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.files-row-meta { font-size: 11px; }
.files-row-actions { display: flex; gap: 4px; flex-shrink: 0; }
.files-row-actions .btn { padding: 4px 8px; font-size: 12px; }
.files-row-err { color: var(--danger); font-size: 11px; }

/* ----- File preview modal ----- */
.preview-card { max-width: min(95vw, 900px); width: 100%; }
.preview-table-wrap {
  max-height: 60vh;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel);
}
table.preview-table {
  border-collapse: collapse;
  width: max-content;
  min-width: 100%;
  font-size: 12px;
}
table.preview-table th,
table.preview-table td {
  padding: 4px 8px;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  vertical-align: top;
}
table.preview-table th {
  background: var(--panel-2);
  font-weight: 500;
  text-transform: uppercase;
  font-size: 10px;
  letter-spacing: 0.5px;
  color: var(--muted);
  position: sticky;
  top: 0;
}
table.preview-table th:last-child,
table.preview-table td:last-child { border-right: none; }

.migration-banner {
  position: sticky;
  top: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 10px 16px;
  background: #fef3c7;
  border-bottom: 2px solid #b45309;
  color: #78350f;
  font-size: 14px;
  font-weight: 600;
  text-align: center;
  flex-wrap: wrap;
}
.migration-banner strong { letter-spacing: 0.02em; }
.migration-banner-link {
  display: inline-flex;
  align-items: center;
  padding: 4px 12px;
  background: #b45309;
  color: white;
  border-radius: 4px;
  text-decoration: none;
  font-weight: 700;
}
.migration-banner-link:hover { background: #92400e; }
