/* Boxes app (docs/03 "boxes"). Phone first; light and dark follow the phone. */
:root {
  --bg: #f4f5f7; --surface: #ffffff; --ink: #111827; --muted: #6b7280; --line: #e5e7eb;
  --accent: #2563eb; --accent-ink: #ffffff; --warn-bg: #fef3c7; --warn-ink: #92400e;
  --toss: #b91c1c; --donate: #7c3aed; --sell: #047857; --keep: #374151; --flash: #fde68a;
  --radius: 12px; --shadow: 0 1px 2px rgba(0,0,0,.06), 0 2px 8px rgba(0,0,0,.05);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115; --surface: #1a1d23; --ink: #e8eaed; --muted: #9aa0a6; --line: #2c3038;
    --accent: #4f8cff; --warn-bg: #3b2f12; --warn-ink: #fcd34d; --toss: #f87171; --donate: #c4b5fd;
    --sell: #6ee7b7; --keep: #d1d5db; --flash: #4b3f12; --shadow: none;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
a { color: var(--accent); text-decoration: none; }
h1 { font-size: 1.35rem; margin: .2rem 0; }
h2 { font-size: 1rem; margin: 1.1rem 0 .4rem; }
h3 { font-size: .95rem; margin: 1rem 0 .3rem; }
.muted, small { color: var(--muted); }
small { display: block; font-size: .8rem; margin-top: .2rem; }

button, .chip, select, input, textarea { font: inherit; }
button {
  background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 10px;
  padding: .6rem 1rem; min-height: 44px; cursor: pointer; font-weight: 600;
}
button:disabled { opacity: .5; }
button.ghost { background: transparent; color: var(--accent); border: 1px solid var(--line); }
button.danger { background: transparent; color: var(--toss); border: 1px solid var(--line); margin-right: auto; }
button.small { min-height: 34px; padding: .3rem .6rem; font-size: .85rem; }
button.link { background: none; color: var(--muted); padding: 0; min-height: 0; font-weight: 400; text-decoration: underline; }
input, select, textarea {
  width: 100%; background: var(--surface); color: var(--ink); border: 1px solid var(--line);
  border-radius: 10px; padding: .6rem .7rem; min-height: 44px;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.top {
  position: sticky; top: 0; z-index: 5; display: flex; gap: .6rem; align-items: center;
  padding: .6rem 16px; padding-top: max(.6rem, env(safe-area-inset-top));
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 800; color: var(--ink); letter-spacing: .02em; }
.top input { flex: 1; min-width: 0; }
main#view { max-width: 820px; margin: 0 auto; padding: .8rem 16px 4rem; }

.bar { display: flex; align-items: center; justify-content: space-between; gap: .6rem; flex-wrap: wrap; }
.stats { color: var(--muted); display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.chips { display: flex; gap: .5rem; overflow-x: auto; padding: .7rem 0; scrollbar-width: none; }
.chip {
  white-space: nowrap; border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  border-radius: 999px; padding: .45rem .85rem; font-size: .9rem;
}
.pill { font-size: .75rem; border-radius: 999px; padding: .1rem .5rem; background: var(--line); color: var(--ink); white-space: nowrap; }
.pill.warn { background: var(--warn-bg); color: var(--warn-ink); }
.pill.st-toss { color: var(--toss); background: transparent; border: 1px solid currentColor; }
.pill.st-donate { color: var(--donate); background: transparent; border: 1px solid currentColor; }
.pill.st-sell { color: var(--sell); background: transparent; border: 1px solid currentColor; }
.pill.st-keep, .pill.st-gone { color: var(--keep); background: transparent; border: 1px solid currentColor; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .7rem; }
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; color: var(--ink); display: flex; flex-direction: column; border: 1px solid var(--line); }
.card img, .card .noimg { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; display: block; background: var(--line); }
.card .noimg { display: grid; place-items: center; font-size: 2rem; font-weight: 800; color: var(--muted); }
.card-body { padding: .5rem .65rem .65rem; }
.card-id { font-weight: 800; font-size: 1.1rem; display: flex; align-items: center; gap: .35rem; }
.card-title { font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-meta { font-size: .78rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #f59e0b; display: inline-block; }

.back { display: inline-block; margin: .2rem 0 .6rem; }
.boxhead { display: flex; gap: .9rem; align-items: center; flex-wrap: wrap; }
.bigid {
  font-size: 2.6rem; font-weight: 900; line-height: 1; padding: .55rem .7rem; border-radius: var(--radius);
  background: var(--ink); color: var(--bg); min-width: 4.2rem; text-align: center;
}
.boxhead-text { flex: 1; min-width: 12rem; }
.boxhead-actions { display: flex; gap: .5rem; }
.tags { display: flex; gap: .35rem; flex-wrap: wrap; margin-top: .3rem; }
.tag { font-size: .78rem; border: 1px solid var(--line); border-radius: 999px; padding: .05rem .5rem; color: var(--muted); }

.labelrow { display: flex; align-items: center; justify-content: space-between; gap: .6rem; margin-top: .7rem; font-size: .9rem; }
.photos { margin-top: .9rem; }
.strip { display: flex; gap: .5rem; overflow-x: auto; padding-bottom: .3rem; scroll-snap-type: x proximity; }
.thumb, .addphoto {
  flex: 0 0 auto; width: 104px; height: 104px; border-radius: 10px; overflow: hidden; padding: 0; min-height: 0;
  background: var(--line); border: 2px solid transparent; scroll-snap-align: start; position: relative;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb.new { border-color: #f59e0b; }
.addphoto { display: grid; place-items: center; background: var(--surface); border: 2px dashed var(--line); color: var(--accent); font-weight: 700; cursor: pointer; }
.addphoto input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; }
.hint { font-size: .85rem; color: var(--warn-ink); background: var(--warn-bg); border-radius: 10px; padding: .5rem .7rem; margin: .5rem 0 0; }

.quickadd { display: flex; gap: .5rem; margin: 1rem 0 .3rem; }
.quickadd .qtyin { width: 4.2rem; flex: 0 0 4.2rem; text-align: center; }
.quickadd button { flex: 0 0 auto; }

.group h2 { display: flex; align-items: baseline; gap: .2rem; color: var(--muted); text-transform: uppercase; font-size: .78rem; letter-spacing: .05em; }
.group h2 .count { font-weight: 400; }
.group h2 a { color: var(--ink); text-transform: none; font-size: 1rem; letter-spacing: 0; }
.list { list-style: none; margin: 0; padding: 0; background: var(--surface); border-radius: var(--radius); border: 1px solid var(--line); overflow: hidden; }
.list li + li { border-top: 1px solid var(--line); }
.row {
  display: flex; width: 100%; gap: .6rem; align-items: center; justify-content: space-between; text-align: left;
  background: transparent; color: var(--ink); border-radius: 0; padding: .65rem .8rem; min-height: 48px; font-weight: 400;
}
.row-main { min-width: 0; overflow-wrap: anywhere; }
.row-side { display: flex; gap: .4rem; align-items: center; flex: 0 0 auto; }
.qty { color: var(--muted); font-variant-numeric: tabular-nums; }
.crop { display: inline-block; flex: 0 0 auto; border-radius: 8px; background-color: var(--line); background-repeat: no-repeat; }
.crop.big { border-radius: 12px; }
.row .crop { margin-right: -.1rem; }
.row .row-main { flex: 1; }
.pic { display: flex; gap: .8rem; align-items: center; }
.pic-actions { display: grid; gap: .4rem; justify-items: start; }
#viewer .hl { position: absolute; border: 3px solid #f59e0b; border-radius: 8px; pointer-events: none;
  box-shadow: 0 0 0 9999px rgba(0,0,0,.45); }
#viewer .hl[hidden] { display: none; }
.boxtag { font-size: .8rem; color: var(--muted); white-space: nowrap; max-width: 45%; overflow: hidden; text-overflow: ellipsis; }
li.flash { animation: flash 2.4s ease-out; }
@keyframes flash { from { background: var(--flash); } to { background: transparent; } }

.decide { padding-bottom: .55rem; }
.decide .row { padding-bottom: .3rem; }
.seg { display: flex; gap: .4rem; padding: 0 .8rem; flex-wrap: wrap; }
.seg button { background: transparent; color: var(--muted); border: 1px solid var(--line); min-height: 36px; padding: .25rem .8rem; font-weight: 500; text-transform: capitalize; }
.seg button.on { color: var(--accent-ink); border-color: transparent; }
.seg button.on.st-keep { background: var(--keep); }
.seg button.on.st-toss { background: var(--toss); }
.seg button.on.st-donate { background: var(--donate); }
.seg button.on.st-sell { background: var(--sell); }
@media (prefers-color-scheme: dark) { .seg button.on { color: #111; } }

.notes p { white-space: pre-wrap; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .7rem .8rem; margin: 0; }
.empty { color: var(--muted); text-align: center; padding: 2rem 0; }
.foot { color: var(--muted); font-size: .85rem; text-align: center; margin-top: 1.5rem; }
.stack { display: grid; gap: .8rem; margin-top: 1rem; }
.field { display: block; }
.field > span { display: block; font-size: .85rem; font-weight: 600; margin-bottom: .25rem; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }

dialog#sheet {
  border: 0; padding: 0; width: min(560px, 100vw); max-width: 100vw; max-height: 92vh; margin: auto auto 0;
  border-radius: 16px 16px 0 0; background: var(--surface); color: var(--ink);
}
@media (min-width: 640px) { dialog#sheet { margin: auto; border-radius: 16px; } }
dialog#sheet::backdrop { background: rgba(0,0,0,.45); }
#sheetForm { display: grid; gap: .75rem; padding: 1rem 16px calc(1rem + env(safe-area-inset-bottom)); }
#sheetForm h2 { margin: 0 0 .2rem; font-size: 1.1rem; overflow-wrap: anywhere; }
#sheetForm p { margin: 0; }
.sheet-actions { display: flex; gap: .5rem; justify-content: flex-end; flex-wrap: wrap; margin-top: .3rem; }

#toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(1rem + env(safe-area-inset-bottom)); z-index: 30;
  background: var(--ink); color: var(--bg); padding: .6rem 1rem; border-radius: 999px; max-width: calc(100vw - 32px);
  box-shadow: 0 4px 16px rgba(0,0,0,.25); font-size: .92rem; text-align: center;
}
#viewer { position: fixed; inset: 0; z-index: 20; background: rgba(0,0,0,.92); display: flex; flex-direction: column; }
#viewer[hidden] { display: none; }
#viewer img { flex: 1; min-height: 0; width: 100%; object-fit: contain; }
.viewer-bar { display: flex; gap: .5rem; align-items: center; padding: .6rem 16px calc(.6rem + env(safe-area-inset-bottom)); color: #ddd;
  position: relative; z-index: 2; background: #000; }
.viewer-bar span { flex: 1; font-size: .85rem; }
.viewer-bar .ghost { color: #fca5a5; border-color: #555; }

body.center { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login { width: min(360px, 100%); text-align: center; display: grid; gap: .8rem; justify-items: center; }
.login h1 { margin: 0; font-size: 1.8rem; }
.login form { display: grid; gap: .6rem; width: 100%; }
.login form[hidden] { display: none; }
.login #code { text-align: center; font-size: 1.5rem; letter-spacing: .3em; }
.login button { width: 100%; }
#msg { min-height: 1.4em; color: var(--muted); margin: 0; }

section.shared { margin-bottom: 1.6rem; }
section.shared .strip { margin: .7rem 0; }
.row.static { cursor: default; }
