:root {
  --bg: #f6f5f1; --surface: #ffffff; --surface2: #efede7; --border: #dedad0;
  --text: #1d1f1c; --muted: #6b6e66; --accent: #2f7d4f; --accent-ink: #ffffff;
  --keep: #2f7d4f; --resell: #2563a8; --later: #8a6d1c; --trash: #b43c32; --gift: #8a3ea8;
  --warn-bg: #fff4d6; --err: #b43c32; --radius: 12px;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 14px rgba(0,0,0,.05);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131512; --surface: #1c1f1b; --surface2: #262a25; --border: #343932;
    --text: #e8eae4; --muted: #9aa094; --accent: #5cb784; --accent-ink: #0c140f;
    --keep: #5cb784; --resell: #6ea8e6; --later: #d8b34a; --trash: #e07a6f; --gift: #c48ae0;
    --warn-bg: #3a3218; --err: #e07a6f;
    --shadow: none;
  }
}
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
  /* Column layout so the version footer sits at the bottom of short pages too. */
  min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column;
}
body.login-page { padding-bottom: env(safe-area-inset-bottom); }
body > main, body > .login-wrap { flex: 1 0 auto; width: 100%; }
/* Version: in normal flow (never fixed), so it can't cover a control. On phones the
   body's bottom padding keeps it above the fixed bottom nav. */
.app-version {
  flex: none; align-self: flex-start; padding: .15rem .6rem .3rem calc(.6rem + env(safe-area-inset-left));
  font-size: .7rem; line-height: 1.2; color: var(--muted); opacity: .75; user-select: all;
}
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .6rem; }
h1 { font-size: 1.35rem; } h2 { font-size: 1.1rem; } h3 { font-size: 1rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.hidden { display: none !important; }
.row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.stack > * + * { margin-top: .75rem; }

/* Top bar + bottom nav */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: .75rem;
  padding: .6rem 1rem; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; letter-spacing: .02em; text-decoration: none; color: var(--text); }
.brand span { color: var(--accent); }
.topnav { display: none; gap: .25rem; }
.topnav a, .bottomnav a {
  text-decoration: none; color: var(--muted); padding: .4rem .7rem; border-radius: 8px;
}
.topnav a.active, .bottomnav a.active { color: var(--accent); background: var(--surface2); }
.bottomnav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; display: grid;
  grid-template-columns: repeat(5, 1fr); background: var(--surface);
  border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom);
}
.bottomnav a { display: flex; flex-direction: column; align-items: center; font-size: .72rem; padding: .45rem 0; border-radius: 0; }
.bottomnav a .ico { font-size: 1.25rem; line-height: 1.2; }
.badge {
  display: inline-block; min-width: 1.3em; padding: 0 .35em; border-radius: 999px;
  background: var(--trash); color: #fff; font-size: .7rem; text-align: center; margin-left: .2em;
}
@media (min-width: 820px) {
  body { padding-bottom: 0; }
  .topnav { display: flex; }
  .bottomnav { display: none; }
}
main { max-width: 1100px; margin: 0 auto; padding: 1rem; }

/* Cards, buttons, forms */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow); }
.grid { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.stat { font-size: 1.8rem; font-weight: 700; }
button, .btn {
  font: inherit; border: 1px solid var(--border); background: var(--surface2); color: var(--text);
  padding: .55rem .9rem; border-radius: 10px; cursor: pointer; text-decoration: none;
  display: inline-flex; align-items: center; gap: .35rem; min-height: 42px;
}
button:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 600; }
.btn-danger { color: var(--trash); }
.btn-small { min-height: 32px; padding: .25rem .6rem; font-size: .85rem; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: .55rem .7rem; width: 100%; min-height: 42px;
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label.field { display: block; }
label.field > span { display: block; font-size: .8rem; color: var(--muted); margin-bottom: .2rem; }
.form-grid { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.check { display: inline-flex; align-items: center; gap: .4rem; }
.check input { width: auto; min-height: 0; }
.notice { background: var(--warn-bg); border-radius: 10px; padding: .6rem .8rem; }
.error { color: var(--err); }

/* Status pills */
.pill { display: inline-block; padding: .1rem .55rem; border-radius: 999px; font-size: .78rem; background: var(--surface2); border: 1px solid var(--border); white-space: nowrap; }
.pill.s-new { border-color: var(--later); color: var(--later); }
.pill.s-kept, .pill.s-in_use { border-color: var(--keep); color: var(--keep); }
.pill.s-resale, .pill.s-listed { border-color: var(--resell); color: var(--resell); }
.pill.s-sold { background: var(--resell); color: #fff; }
.pill.s-gifted { border-color: var(--gift); color: var(--gift); }
.pill.s-disposed, .pill.s-cancelled { border-color: var(--trash); color: var(--trash); }
.timer { font-size: .8rem; color: var(--muted); }
.timer.ok { color: var(--keep); font-weight: 600; }

/* Item list */
.toolbar { display: grid; gap: .5rem; grid-template-columns: 1fr; margin-bottom: .75rem; }
.toolbar .filters { display: grid; gap: .5rem; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
.list { display: flex; flex-direction: column; gap: .5rem; }
.li {
  display: grid; grid-template-columns: 64px 1fr auto; gap: .75rem; align-items: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .5rem;
  text-decoration: none; color: inherit;
}
.li .title { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; font-weight: 500; }
.li .meta { font-size: .8rem; color: var(--muted); }
.thumb { width: 64px; height: 64px; border-radius: 8px; object-fit: contain; background: #fff; border: 1px solid var(--border); }
.placeholder {
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
  background: var(--surface2); color: var(--muted); font-size: .65rem; border-radius: 8px; border: 1px dashed var(--border);
}
.thumb.placeholder { width: 64px; height: 64px; }

/* Item page */
.gallery { display: flex; gap: .5rem; overflow-x: auto; padding-bottom: .25rem; }
.gallery figure { margin: 0; position: relative; flex: 0 0 auto; }
.gallery img { height: 220px; max-width: 80vw; border-radius: 10px; background: #fff; border: 1px solid var(--border); object-fit: contain; }
.gallery figcaption { position: absolute; left: 6px; bottom: 6px; }
.status-buttons { display: flex; flex-wrap: wrap; gap: .4rem; }
.status-buttons button.current { background: var(--accent); color: var(--accent-ink); }
.codes .code { font-family: ui-monospace, monospace; }
.history li { font-size: .85rem; }

/* Triage */
.triage-card { max-width: 560px; margin: 0 auto; touch-action: pan-y; user-select: none; transition: transform .15s ease, opacity .15s ease; }
.triage-card .big { width: 100%; height: min(44vh, 460px); object-fit: contain; background: #fff; border-radius: 10px; border: 1px solid var(--border); display: block; }
.triage-card .big.placeholder { font-size: 1rem; }
.triage-card h2 { margin-top: .75rem; font-size: 1.05rem; }
.triage-actions { display: grid; grid-template-columns: repeat(5, 1fr); gap: .5rem; max-width: 560px; margin: .75rem auto 0; }
.triage-actions button { flex-direction: column; justify-content: center; min-height: 64px; font-weight: 600; }
.triage-actions kbd { font-size: .7rem; opacity: .7; font-weight: 400; }
.a-keep { background: var(--keep); color: #fff; border-color: transparent; }
.a-resell { background: var(--resell); color: #fff; border-color: transparent; }
.a-later { background: var(--surface2); color: var(--later); }
.a-trash { background: var(--surface2); color: var(--trash); }
.a-gift { background: var(--surface2); color: var(--gift); }
.swipe-hint { text-align: center; font-size: .8rem; color: var(--muted); margin-top: .5rem; }
.bulk-grid { display: grid; gap: .5rem; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.bulk-cell { position: relative; background: var(--surface); border: 2px solid var(--border); border-radius: 10px; padding: .4rem; cursor: pointer; }
.bulk-cell.sel { border-color: var(--accent); }
.bulk-cell img, .bulk-cell .placeholder { width: 100%; aspect-ratio: 1; object-fit: contain; background: #fff; border-radius: 6px; }
.bulk-cell .t { font-size: .78rem; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.bulk-cell input { position: absolute; top: .5rem; left: .5rem; width: 22px; height: 22px; min-height: 0; }
.actionbar { position: sticky; bottom: calc(64px + env(safe-area-inset-bottom)); z-index: 10; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .5rem; margin-top: .75rem; box-shadow: var(--shadow); }
@media (min-width: 820px) { .actionbar { bottom: .5rem; } }

/* Import */
.drop { border: 2px dashed var(--border); border-radius: var(--radius); padding: 2rem 1rem; text-align: center; background: var(--surface); }
.drop.over { border-color: var(--accent); }
table { border-collapse: collapse; width: 100%; font-size: .88rem; }
th, td { text-align: left; padding: .4rem .5rem; border-bottom: 1px solid var(--border); vertical-align: top; }
td img { width: 48px; height: 48px; object-fit: contain; background: #fff; border-radius: 6px; }
.table-wrap { overflow-x: auto; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* Scanner */
.scanner { position: relative; background: #000; border-radius: var(--radius); overflow: hidden; max-width: 560px; margin: 0 auto; }
.scanner video { width: 100%; display: block; }
.scanner .aim { position: absolute; left: 12%; right: 12%; top: 38%; bottom: 38%; border: 2px solid rgba(255,255,255,.8); border-radius: 8px; pointer-events: none; }

/* Modal + toast */
.modal-back { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 50; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.modal { background: var(--surface); border-radius: var(--radius); padding: 1rem; width: 100%; max-width: 520px; max-height: 90vh; overflow: auto; }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(84px + env(safe-area-inset-bottom)); z-index: 60; background: var(--text); color: var(--bg); padding: .6rem 1rem; border-radius: 10px; display: flex; gap: .75rem; align-items: center; max-width: 92vw; }
.toast button { min-height: 32px; padding: .2rem .6rem; background: transparent; color: inherit; border-color: currentColor; }

/* Login */
.login-wrap { min-height: 0; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.login-card { width: 100%; max-width: 380px; }

/* Listing draft + sales (M3) */
.offscreen { position: fixed; left: -9999px; top: 0; opacity: 0; }
.copy-field { display: grid; grid-template-columns: 1fr auto; gap: .4rem; align-items: start; }
.copy-field > button { white-space: nowrap; }
.listing textarea { min-height: 11rem; font-family: inherit; }
.counter { text-align: right; }
.counter.over { color: var(--err); }
.pos { color: var(--keep); } .neg { color: var(--err); }
