:root {
  /* ── Pastel palette (exact) ───────────────────────────────────────────
     pink rgb(249,178,215) · blue rgb(207,236,243) · green rgb(218,249,222)
     · yellow rgb(246,255,220) · charcoal #2A2A2A (all text)               */
  --bg: rgb(246, 255, 220);          /* pastel yellow — page background   */
  --panel: rgb(207, 236, 243);       /* pastel blue — cards/header/tables */
  --surface: #ffffff;                /* inputs & inner controls           */
  --line: rgba(42, 42, 42, 0.14);    /* soft charcoal hairline borders    */
  --text: #2A2A2A;                   /* charcoal — all text               */
  --muted: #59607a;                  /* muted charcoal-grey (AA on bg)    */
  --primary: rgb(249, 178, 215);     /* pastel pink accent                */
  --primary-d: rgb(243, 150, 199);   /* pink hover                        */
  --on-primary: #2A2A2A;             /* charcoal on pink (white fails)    */
  --success: rgb(218, 249, 222);     /* pastel green highlight            */
  --ok: #1f7a4d;                     /* readable green text               */
  --danger: #c2413b;                 /* readable red text                 */
  --chip: rgb(218, 249, 222);        /* green chip fill                   */
  --hover: rgba(249, 178, 215, 0.22);/* soft pink row/hover wash          */
  --placeholder: rgba(42, 42, 42, 0.05);
  --shadow-sm: 0 3px 10px rgba(42, 42, 42, 0.07);
  --shadow-md: 0 10px 26px rgba(42, 42, 42, 0.12);
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
header {
  display: flex; align-items: center; gap: 16px 24px; flex-wrap: wrap;
  padding: 12px 24px; background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 700; color: var(--text); text-decoration: none; white-space: nowrap; }
nav { display: flex; flex-wrap: wrap; gap: 4px 16px; }
nav a { color: var(--muted); text-decoration: none; padding: 4px 0;
  border-bottom: 2px solid transparent; transition: color .15s, border-color .15s; }
nav a:hover { color: var(--text); border-bottom-color: var(--primary); }
main { max-width: 1100px; margin: 24px auto; padding: 0 24px; }
h1 { font-size: 22px; margin: 0 0 16px; }

.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; margin-bottom: 12px; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; }
.actions { display: flex; gap: 8px; }

input, select, textarea {
  background: var(--surface); color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 10px; font: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--text); }
input, select, textarea { max-width: 100%; }
:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }

.btn, button.link {
  display: inline-block; border: 1px solid var(--line); background: var(--surface);
  color: var(--text); border-radius: 8px; padding: 8px 14px; cursor: pointer;
  text-decoration: none; font: inherit; transition: border-color .15s, background .15s, color .15s, box-shadow .15s;
}
.btn:hover { border-color: var(--primary); box-shadow: var(--shadow-sm); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); font-weight: 600; }
.btn.primary:hover { background: var(--primary-d); border-color: var(--primary-d); }
button.link { border: none; background: none; padding: 0 8px; color: var(--muted); }
button.link.danger { color: var(--danger); }

table.grid { width: 100%; border-collapse: collapse; background: var(--panel);
  border: 1px solid var(--line); border-radius: 10px; overflow: hidden; box-shadow: var(--shadow-sm); }
.grid th, .grid td { padding: 12px 14px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.grid th { color: var(--muted); font-weight: 600; font-size: 13px; }
.grid tbody tr { transition: background .12s; }
.grid tbody tr:hover { background: var(--hover); }
.grid tr:last-child td { border-bottom: none; }
.thumb img, .thumb .thumb-empty { width: 52px; height: 72px; }
.thumb img { object-fit: cover; border-radius: 5px; }

/* Placeholder box for items with no photo */
.thumb-empty { display: flex; align-items: center; justify-content: center;
  background: var(--placeholder); border: 1px solid var(--line); border-radius: 5px;
  color: var(--muted); font-size: 22px; }

/* Restructured "Item" cell: bold name + secondary meta line */
.item-name { font-weight: 600; color: var(--text); }
.item-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
  margin-top: 4px; color: var(--muted); font-size: 13px; }

.attrs { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { background: var(--chip); border-radius: 999px; padding: 2px 8px; font-size: 12px; color: var(--text); }
.row-actions { display: flex; align-items: center; gap: 8px; }
.row-actions form { display: inline; }
.row-actions a { color: var(--muted); }

/* List / Grid view toggle (segmented control) */
.view-toggle { display: inline-flex; border: 1px solid var(--line);
  border-radius: 8px; overflow: hidden; }
.view-toggle a { padding: 8px 12px; color: var(--muted); text-decoration: none;
  font-size: 14px; background: var(--surface); transition: color .15s, background .15s; }
.view-toggle a + a { border-left: 1px solid var(--line); }
.view-toggle a:hover { color: var(--text); }
.view-toggle a.active { background: var(--primary); color: var(--on-primary); font-weight: 600; }

/* Grid (thumbnail) view */
.inv-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px; }
.inv-card { display: flex; flex-direction: column; background: var(--panel);
  border: 1px solid var(--line); border-radius: 10px; overflow: hidden;
  box-shadow: var(--shadow-sm); transition: border-color .15s, transform .15s, box-shadow .15s; }
.inv-card:hover { border-color: var(--primary); transform: translateY(-3px); box-shadow: var(--shadow-md); }
.inv-thumb { aspect-ratio: 5 / 7; background: var(--placeholder); }
.inv-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.inv-thumb .thumb-empty { width: 100%; height: 100%; border: none; border-radius: 0;
  font-size: 40px; }
.inv-body { display: flex; flex-direction: column; gap: 6px; padding: 10px 12px 12px; }
.inv-body .attrs { margin-top: 2px; }
.inv-foot { display: flex; align-items: center; justify-content: space-between;
  gap: 8px; margin-top: auto; padding-top: 6px; }
.inv-actions { display: flex; align-items: center; gap: 8px;
  opacity: 0; transition: opacity .15s; }
.inv-card:hover .inv-actions, .inv-card:focus-within .inv-actions { opacity: 1; }
.inv-actions a { color: var(--muted); text-decoration: none; }
.inv-actions form { display: inline; }
.empty-state { padding: 24px 0; }

.qty { display: inline-flex; align-items: center; gap: 8px; }
.step { width: 30px; height: 30px; border-radius: 6px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); cursor: pointer; font-size: 16px; line-height: 1;
  transition: border-color .15s; }
.step:hover { border-color: var(--primary); }

.muted { color: var(--muted); }
.ok { color: var(--ok); }

.card-form { display: flex; flex-direction: column; gap: 12px; max-width: 520px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 18px; box-shadow: var(--shadow-sm); }
.card-form label { display: flex; flex-direction: column; gap: 4px; font-size: 14px; color: var(--muted); }
.card-form label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); }
.card-form input, .card-form select, .card-form textarea { color: var(--text); }
.form-actions { display: flex; gap: 10px; margin-top: 4px; }
fieldset { border: 1px solid var(--line); border-radius: 8px; }
legend { color: var(--muted); padding: 0 6px; }
.field-row { display: flex; gap: 8px; margin-bottom: 8px; }

.confirm { margin-top: 20px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; padding: 18px; box-shadow: var(--shadow-sm); }
.confirm-body { display: flex; gap: 20px; flex-wrap: wrap; }
.preview { width: 220px; max-width: 100%; height: auto; object-fit: contain;
  border-radius: 8px; border: 1px solid var(--line); background: var(--placeholder); }

/* ── Manual rotate & crop editor ─────────────────────────────────────── */
.editor { display: flex; flex-direction: column; gap: 10px; }
.editor-stage { position: relative; touch-action: none; max-width: 100%;
  border-radius: 8px; border: 1px solid var(--line); background: #2a2d33;
  overflow: hidden; align-self: flex-start; }
.editor-canvas { display: block; max-width: 100%; }

/* Dim everything outside the crop box, keep the selection bright. */
.crop-box { position: absolute; box-sizing: border-box; cursor: move;
  border: 1px solid rgba(255, 255, 255, .95);
  box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .5); }
.crop-grid { position: absolute; inset: 0; pointer-events: none; }
.crop-grid .gl { position: absolute; background: rgba(255, 255, 255, .45); }
.crop-grid .gl-v { top: 0; bottom: 0; width: 1px; }
.crop-grid .gl-h { left: 0; right: 0; height: 1px; }

.crop-handle { position: absolute; width: 14px; height: 14px; box-sizing: border-box;
  background: var(--primary); border: 2px solid #fff; border-radius: 3px; }
.crop-nw { left: -7px; top: -7px; cursor: nwse-resize; }
.crop-ne { right: -7px; top: -7px; cursor: nesw-resize; }
.crop-se { right: -7px; bottom: -7px; cursor: nwse-resize; }
.crop-sw { left: -7px; bottom: -7px; cursor: nesw-resize; }
.crop-n { left: 50%; top: -7px; transform: translateX(-50%); cursor: ns-resize; }
.crop-s { left: 50%; bottom: -7px; transform: translateX(-50%); cursor: ns-resize; }
.crop-w { left: -7px; top: 50%; transform: translateY(-50%); cursor: ew-resize; }
.crop-e { right: -7px; top: 50%; transform: translateY(-50%); cursor: ew-resize; }

.editor-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.btn.small { padding: 5px 10px; font-size: 13px; }
.editor-fine { display: inline-flex; align-items: center; gap: 6px; color: var(--muted);
  font-size: 13px; }
.editor-fine input[type="range"] { width: 110px; accent-color: var(--primary-d); }
.editor-fine-val { min-width: 34px; color: var(--text); }
.editor-hint { font-size: 12px; margin: 0; }

/* Match picker (decide screen) */
.match-picker { border: 1px solid var(--line); border-radius: 10px; padding: 12px;
  margin: 0; display: flex; flex-direction: column; gap: 6px; }
.match-picker legend { font-size: 13px; color: var(--muted); padding: 0 4px; }
.cand { display: grid; grid-template-columns: auto 42px 1fr; align-items: center;
  gap: 10px; padding: 6px 8px; border-radius: 8px; cursor: pointer; }
.cand:hover { background: var(--panel); }
.cand-match { background: var(--success); }
.cand-new { grid-template-columns: auto 1fr; }
.cand-thumb { width: 42px; height: 58px; object-fit: cover; border-radius: 4px;
  background: var(--placeholder); }
.cand-name { color: var(--text); font-size: 14px; }
.cand-meta { grid-column: 3; color: var(--muted); font-size: 12px; }
.cand-search { display: flex; flex-direction: column; gap: 4px; font-size: 13px;
  color: var(--muted); margin-top: 4px; }
.cand-empty { margin: 4px 8px; font-size: 13px; }

/* Header task bar + live badges */
.taskbar { margin-left: auto; display: inline-flex; align-items: center; gap: 8px;
  text-decoration: none; }
.taskbar-label { color: var(--text); font-weight: 600; }
.taskbar-label.muted { color: var(--muted); font-weight: 500; }
.badge { display: inline-block; border-radius: 999px; padding: 2px 10px;
  font-size: 12px; font-weight: 600; }
.badge-run { background: #cdeaf3; color: #1c4a5a; }
.badge-review { background: var(--primary); color: var(--on-primary); }

/* Job status chips */
.chip-run { background: #cdeaf3; color: #1c4a5a; }
.chip-review { background: var(--primary); color: var(--on-primary); }
.chip-ok { background: var(--success); color: #1f6b43; }
.chip-fail { background: #f7d7d5; color: #a3322d; }

.sig-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 14px; margin: 8px 0 18px; }
.sig-card { margin: 0; text-align: center; background: var(--panel);
  border: 1px solid var(--line); border-radius: 10px; padding: 8px; box-shadow: var(--shadow-sm); }
.sig-card img { width: 110px; height: 154px; object-fit: cover; border-radius: 6px;
  background: var(--placeholder); }
.sig-card figcaption { display: flex; flex-wrap: wrap; gap: 4px; justify-content: center;
  margin: 6px 0; }
.sig-card form { display: inline; }

.logo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
  gap: 14px; margin-top: 18px; }
.logo-grid figure { margin: 0; text-align: center; }
.logo-grid img { width: 90px; height: 90px; object-fit: contain; background: #fff;
  border-radius: 8px; padding: 6px; border: 1px solid var(--line); }
.logo-grid figcaption { color: var(--muted); font-size: 12px; margin-top: 4px; }

/* ── Responsive: tablet & down ───────────────────────────────────────── */
@media (max-width: 680px) {
  main { margin: 16px auto; padding: 0 14px; }
  h1 { font-size: 19px; }
  header { gap: 10px 16px; padding: 10px 14px; }
  nav { width: 100%; order: 3; }
  .taskbar { margin-left: auto; }

  /* Toolbars & filters stack and fill the width */
  .toolbar { flex-direction: column; align-items: stretch; }
  .filters { flex-direction: column; }
  .filters input, .filters select { flex: 1 1 auto; min-width: 0; width: 100%; }
  .filters button { width: 100%; }
  .actions { flex-wrap: wrap; }
  .actions .btn { flex: 1 1 auto; text-align: center; }
  .view-toggle { width: 100%; }
  .view-toggle a { flex: 1 1 auto; text-align: center; }

  /* Forms go full-width */
  .card-form { max-width: 100%; }
  .confirm-body { flex-direction: column; }
  .field-row { flex-wrap: wrap; }

  /* Bigger tap targets */
  .step { width: 34px; height: 34px; }
  .row-actions { gap: 12px; }
  .row-actions a, button.link { padding: 6px 4px; }

  /* Data tables → stacked, labeled cards */
  table.grid { border: none; background: none; border-radius: 0; box-shadow: none; }
  .grid thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .grid tr { display: block; background: var(--panel); border: 1px solid var(--line);
    border-radius: 10px; margin-bottom: 12px; padding: 4px 14px; box-shadow: var(--shadow-sm); }
  .grid td { display: flex; justify-content: space-between; align-items: center; gap: 12px;
    padding: 9px 0; border-bottom: 1px solid var(--line); text-align: right; }
  .grid tr td:last-child { border-bottom: none; }
  .grid td::before { content: attr(data-label); color: var(--muted); font-weight: 600;
    text-align: left; flex-shrink: 0; }
  /* Cells with an empty label span the full width with no label gutter */
  .grid td[data-label=""]::before { content: none; }
  .grid td.thumb { justify-content: flex-start; }
  .grid td.attrs { flex-wrap: wrap; justify-content: flex-end; }
  .grid td.row-actions { justify-content: flex-start; flex-wrap: wrap; }
  /* Restructured "Item" cell stacks name + meta full-width, left-aligned */
  .grid td.item { flex-direction: column; align-items: flex-start; text-align: left; }
  .grid td.item::before { content: none; }
  .grid td.item .item-meta { justify-content: flex-start; }
  /* The "no items yet" empty row shouldn't render as a label:value pair */
  .grid td[colspan] { justify-content: center; text-align: center; }
  .grid td[colspan]::before { content: none; }

  /* Grid view: smaller cards, actions always tappable on touch */
  .inv-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
  .inv-actions { opacity: 1; }
}

/* ── Webcam scanning station (/identify/camera) ─────────────────────────── */
.scan-controls { flex-direction: row; flex-wrap: wrap; max-width: 640px; }
.scan-controls label { flex: 1 1 220px; }
.scan-stage {
  max-width: 640px; margin: 14px 0; background: #000; border-radius: 12px;
  overflow: hidden; box-shadow: var(--shadow-sm); position: relative;
}
.scan-video { display: block; width: 100%; height: auto; }
.scan-error { padding: 16px; color: var(--danger); background: var(--surface); }
.scan-actions {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap; margin-bottom: 12px;
}
.scan-auto-toggle { display: flex; align-items: center; gap: 8px; }
.scan-interval-wrap { display: flex; align-items: center; gap: 6px; }
.scan-interval { width: 64px; }
.scan-status { margin: 8px 0; }
.scan-thumbs { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0 4px; }
.scan-thumb {
  width: 64px; height: 90px; object-fit: cover; border-radius: 8px;
  border: 1px solid var(--line); box-shadow: var(--shadow-sm);
}
