[x-cloak] { display: none !important; }

:root {
  --red: #c8102e;
  --red-dark: #9e0c24;
  --yellow: #f6c400;
  --ink: #1d1d1f;
  --muted: #6b6b70;
  --line: #e4e0d8;
  --paper: #faf8f4;
  --card: #ffffff;
  --ok: #2f7d32;
  --warn: #b26a00;
  --bad: #b3261e;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 2px 8px rgba(0,0,0,.05);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--paper);
}
* { box-sizing: border-box; }
body { margin: 0; }
.app { max-width: 1100px; margin: 0 auto; padding: 0 14px 120px; }

/* header */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 0 10px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { font-size: 1.3rem; margin: 0; letter-spacing: -.01em; }
.logo { display: grid; grid-template-columns: 1fr 1fr; gap: 3px; width: 30px; height: 30px; padding: 4px; background: var(--red); border-radius: 5px; }
.logo i { background: #e43b55; border-radius: 50%; box-shadow: inset 0 -1px 0 rgba(0,0,0,.25); }
.totals { display: flex; gap: 14px; color: var(--muted); font-size: .9rem; }
.totals b { color: var(--ink); }

/* tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; }
.tabs button { background: none; border: 0; padding: 10px 14px; font: inherit; font-weight: 600; color: var(--muted); border-bottom: 3px solid transparent; cursor: pointer; }
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--red); }
.pill { display: inline-block; min-width: 20px; padding: 1px 6px; border-radius: 10px; background: var(--red); color: #fff; font-size: .75rem; margin-left: 4px; }

/* controls */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); font: inherit; font-weight: 600; color: var(--ink); cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { border-color: #cbc5b9; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--red); border-color: var(--red); color: #fff; }
.btn.primary:hover { background: var(--red-dark); }
.btn.danger { color: var(--bad); }
.btn.small { padding: 5px 10px; font-size: .85rem; }
.btn.file { position: relative; overflow: hidden; }
.btn.file input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.link { background: none; border: 0; padding: 0; color: var(--red); font: inherit; text-decoration: underline; cursor: pointer; }
input[type=text], input[type=search], input[type=number], select, textarea {
  font: inherit; padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink); min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(200,16,46,.25); border-color: var(--red); }
textarea { width: 100%; resize: vertical; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row > input[type=text] { flex: 1 1 200px; }
.row.end { justify-content: flex-end; }
.grow { flex: 1; }
.hint { color: var(--muted); font-size: .85rem; margin: 6px 0; }
.empty { color: var(--muted); padding: 18px; text-align: center; border: 1px dashed var(--line); border-radius: var(--radius); }

/* scan layout */
.scan { display: grid; grid-template-columns: minmax(0, 420px) minmax(0, 1fr); gap: 18px; align-items: start; }
.scan .camera-card, .scan .manual { grid-column: 1; }
.scan .batch { grid-column: 2; grid-row: 1 / span 3; }
@media (max-width: 820px) {
  .scan { grid-template-columns: 1fr; }
  .scan .batch { grid-column: 1; grid-row: auto; }
}

.viewfinder { position: relative; background: #141416; border-radius: var(--radius); overflow: hidden; min-height: 220px; display: flex; align-items: center; justify-content: center; }
.viewfinder video { display: none; width: 100%; height: auto; }
.viewfinder.on video { display: block; }
.viewfinder.mirrored video { transform: scaleX(-1); }
.cam-off { padding: 24px; text-align: center; color: #ddd; }
.cam-off .err { color: #ffb4ab; }
.reticle { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; pointer-events: none; }
.reticle span { width: 72%; height: 34%; border: 2px solid rgba(255,255,255,.85); border-radius: 8px; box-shadow: 0 0 0 9999px rgba(0,0,0,.22); }
.flash { position: absolute; inset: 0; background: rgba(246,196,0,.35); pointer-events: none; }
.cam-controls { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.cam-controls .hint { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.manual { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; box-shadow: var(--shadow); }
.import { margin-top: 10px; border-top: 1px solid var(--line); padding-top: 10px; }
.import summary { cursor: pointer; font-weight: 600; }
.import textarea { margin: 6px 0; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .85rem; }

/* batch items */
.batch-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.batch-head h2 { font-size: 1.05rem; margin: 0 0 8px; }
.item { display: flex; gap: 12px; background: var(--card); border: 1px solid var(--line); border-left: 4px solid var(--line); border-radius: var(--radius); padding: 10px; margin-bottom: 8px; box-shadow: var(--shadow); }
.item.st-found { border-left-color: var(--ok); }
.item.st-pending { border-left-color: var(--yellow); }
.item.st-not_found { border-left-color: var(--warn); }
.item.st-error { border-left-color: var(--bad); }
.thumb { flex: 0 0 72px; height: 72px; display: flex; align-items: center; justify-content: center; background: #f3f1ec; border-radius: 6px; overflow: hidden; }
.thumb img { max-width: 100%; max-height: 100%; object-fit: contain; }
.nothumb { width: 34px; height: 22px; background: #ddd7cc; border-radius: 3px; box-shadow: 6px -6px 0 -2px #ddd7cc; }
.item .body { flex: 1; min-width: 0; }
.line1 { display: flex; align-items: center; gap: 8px; }
.num { font-weight: 700; font-variant-numeric: tabular-nums; }
.status { font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; padding: 2px 6px; border-radius: 4px; background: #eee9df; color: var(--muted); }
.st-found .status { background: #e5f2e5; color: var(--ok); }
.st-not_found .status { background: #fbefdc; color: var(--warn); }
.st-error .status { background: #fbe3e1; color: var(--bad); }
.x { margin-left: auto; background: none; border: 0; font-size: 1.3rem; line-height: 1; color: var(--muted); cursor: pointer; padding: 0 4px; }
.item .name { font-weight: 600; margin: 2px 0; }
.meta { display: flex; gap: 10px; flex-wrap: wrap; color: var(--muted); font-size: .85rem; }
.via, .msg, .owned { font-size: .85rem; margin-top: 4px; }
.via { color: var(--muted); }
.msg { color: var(--warn); }
.st-error .msg { color: var(--bad); }
.owned { color: #3a5a8c; }
.qty { display: flex; align-items: center; gap: 8px; margin-top: 6px; font-size: .85rem; color: var(--muted); }
.qty b { min-width: 18px; text-align: center; color: var(--ink); font-size: 1rem; }
.step { width: 28px; height: 28px; border-radius: 50%; border: 1px solid var(--line); background: #fff; font-size: 1rem; cursor: pointer; }
.step:disabled { opacity: .4; }
.fix { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.fix input { width: 120px; padding: 6px 8px; }
.manual-entry { display: flex; gap: 6px; flex-wrap: wrap; width: 100%; }
.manual-entry input[type=text] { flex: 1 1 160px; width: auto; }
.manual-entry input[type=number] { width: 90px; }
.actions { margin-top: 6px; }

.commit-bar { position: fixed; left: 0; right: 0; bottom: 0; display: flex; gap: 10px; align-items: center; justify-content: flex-end; flex-wrap: wrap;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); background: rgba(255,255,255,.96); border-top: 1px solid var(--line); box-shadow: 0 -4px 16px rgba(0,0,0,.06); z-index: 5; }
.commit-bar label { display: flex; gap: 8px; align-items: center; font-size: .9rem; color: var(--muted); }
.commit-bar select { max-width: 220px; }

/* inventory */
.filters { display: flex; gap: 8px; flex-wrap: wrap; }
.filters input[type=search] { flex: 1 1 240px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin-top: 8px; }
.card { text-align: left; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; font: inherit; color: inherit; cursor: pointer; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 3px; }
.card:hover { border-color: #cbc5b9; }
.card .img { height: 120px; display: flex; align-items: center; justify-content: center; background: #f3f1ec; border-radius: 6px; margin-bottom: 6px; overflow: hidden; }
.card .img img { max-width: 100%; max-height: 100%; object-fit: contain; }
.card .num { display: flex; justify-content: space-between; }
.card .q { background: var(--yellow); color: var(--ink); border-radius: 4px; padding: 0 6px; font-size: .8rem; }
.card .name { font-weight: 600; font-size: .92rem; line-height: 1.25; }
.card .loc { font-size: .78rem; color: #3a5a8c; }
.more { text-align: center; margin: 16px 0; }

/* locations */
.loclist { list-style: none; padding: 0; margin: 12px 0; }
.loclist li { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; margin-bottom: 8px; }

/* detail sheet */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.35); display: flex; align-items: flex-end; justify-content: center; z-index: 10; }
.sheet { position: relative; background: #fff; width: 100%; max-width: 560px; max-height: 92vh; overflow: auto; border-radius: 14px 14px 0 0; padding: 18px 18px calc(18px + env(safe-area-inset-bottom)); }
@media (min-width: 700px) { .sheet-backdrop { align-items: center; } .sheet { border-radius: 14px; } }
.sheet .close { position: absolute; top: 10px; right: 10px; }
.sheet-img { height: 200px; display: flex; align-items: center; justify-content: center; background: #f3f1ec; border-radius: 8px; }
.sheet-img img { max-height: 100%; max-width: 100%; object-fit: contain; }
.sheet h2 { font-size: 1.15rem; margin: 12px 0 4px; }
.links { display: flex; gap: 14px; font-size: .9rem; }
.links a { color: var(--red); }
.form { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 12px 0; }
.form label { display: flex; flex-direction: column; gap: 4px; font-size: .85rem; color: var(--muted); }
.form .wide { grid-column: 1 / -1; }

/* toasts */
.toasts { position: fixed; top: 12px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 6px; z-index: 20; width: min(92vw, 420px); }
.toast { background: #2a2a2d; color: #fff; padding: 10px 14px; border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.2); font-size: .9rem; cursor: pointer; }
.toast.error { background: var(--bad); }
.toast.ok { background: var(--ok); }
