:root {
  --accent: #1f5f5b; --accent-ink: #ffffff; --accent-soft: #e2efed;
  --bg: #f4f2ee; --card: #ffffff; --text: #1b1f1e; --muted: #5f6866; --line: #e1ddd5;
  --good: #1d6b3a; --bad: #b3261e; --warn: #8a5a00; --warn-bg: #fff4dc;
  --pill: #ece8e1;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --accent: #7cc7c0; --accent-ink: #0d1716; --accent-soft: #1d2f2d;
    --bg: #101615; --card: #19211f; --text: #e9eeec; --muted: #9faaa7; --line: #2c3634;
    --good: #7fd49b; --bad: #ffb4ab; --warn: #f2c66d; --warn-bg: #2f2817; --pill: #26302e;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --accent: #7cc7c0; --accent-ink: #0d1716; --accent-soft: #1d2f2d;
  --bg: #101615; --card: #19211f; --text: #e9eeec; --muted: #9faaa7; --line: #2c3634;
  --good: #7fd49b; --bad: #ffb4ab; --warn: #f2c66d; --warn-bg: #2f2817; --pill: #26302e;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.45 -apple-system, system-ui, "Segoe UI", Roboto, sans-serif; -webkit-text-size-adjust: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
h1 { font-size: 1.45rem; margin: 4px 0 10px; line-height: 1.2; overflow-wrap: anywhere; }
h2 { font-size: .8rem; margin: 0 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
p { margin: 6px 0; }
.muted { color: var(--muted); } .small { font-size: .85rem; } .center { text-align: center; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.good { color: var(--good); } .bad { color: var(--bad); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.top { position: sticky; top: 0; z-index: 5; display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: calc(8px + env(safe-area-inset-top)) 16px 8px; background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.top .brand { font-weight: 700; font-size: 1.05rem; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; background: none; border: 0; padding: 4px 0; text-align: left; }
.sync { flex: 0 0 auto; background: var(--card); border: 1px solid var(--line); border-radius: 20px; padding: 4px 10px; font-size: .78rem; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); display: inline-block; }
.dot.on { background: var(--good); } .dot.wait { background: var(--warn); } .dot.off { background: var(--bad); }

main { padding: 12px 16px calc(92px + env(safe-area-inset-bottom)); max-width: 720px; margin: 0 auto; }
main.center { min-height: 80vh; display: flex; align-items: center; justify-content: center; }

.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.tabs button { background: none; border: 0; padding: 8px 0 6px; font-size: .72rem; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 2px; min-height: 52px; }
.tabs button span { font-size: 1.25rem; line-height: 1; }
.tabs button.on { color: var(--accent); font-weight: 700; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px; margin: 0 0 12px; }
button.card { display: block; width: 100%; text-align: left; cursor: pointer; }
.btn, button.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 12px; padding: 10px 16px; font-weight: 600; text-decoration: none; min-height: 44px; cursor: pointer; }
.btn.ghost { background: transparent; color: var(--accent); border: 1px solid var(--line); }
.btn.small { min-height: 34px; padding: 4px 12px; font-size: .85rem; }
.btn.block { display: flex; width: 100%; margin: 8px 0; }
.btn.danger { background: transparent; color: var(--bad); border: 1px solid var(--line); }
.btn:disabled { opacity: .5; }
button.link { background: none; border: 0; color: var(--accent); text-decoration: underline; padding: 0; cursor: pointer; }
.back { margin: 0 0 8px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row > * { min-width: 0; }
.spread { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 10px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 8px; }
.grid2 > *, .grid3 > * { min-width: 0; }

input, select, textarea { width: 100%; min-width: 0; max-width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); min-height: 44px; }
textarea { min-height: 80px; resize: vertical; }
input[type="checkbox"] { width: 22px; height: 22px; min-height: 0; accent-color: var(--accent); flex: 0 0 auto; }
.form label { display: block; margin-bottom: 10px; font-size: .85rem; color: var(--muted); }
.form label > input, .form label > select, .form label > textarea { margin-top: 4px; color: var(--text); font-size: 1rem; }
.form .check { display: flex; gap: 10px; align-items: center; color: var(--text); font-size: .95rem; }
.hint { font-size: .78rem; color: var(--muted); margin-top: 2px; }
fieldset { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px 2px; margin: 0 0 12px; }
legend { font-size: .8rem; color: var(--muted); padding: 0 4px; text-transform: uppercase; letter-spacing: .05em; }

.hero { background: var(--accent); color: var(--accent-ink); border-radius: 16px; padding: 16px; margin-bottom: 12px; }
.hero .label { opacity: .85; font-size: .82rem; }
.hero .big { font-size: 2rem; font-weight: 750; line-height: 1.1; }
.hero .sub { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 6px; font-size: .9rem; opacity: .95; }
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px; min-width: 0; }
.tile b { display: block; font-size: 1.15rem; overflow-wrap: anywhere; }
.tile span { font-size: .75rem; color: var(--muted); }
.actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.actions button { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 4px; display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: .82rem; cursor: pointer; min-height: 70px; }
.actions button span { font-size: 1.4rem; line-height: 1; }

.alert { background: var(--warn-bg); color: var(--warn); border: 1px solid color-mix(in srgb, var(--warn) 35%, transparent); border-radius: 12px; padding: 10px 12px; margin-bottom: 12px; font-size: .9rem; }
.alert button.link { color: inherit; font-weight: 600; }

.chips { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 8px; margin-bottom: 4px; scrollbar-width: none; }
.chips button { flex: 0 0 auto; border: 1px solid var(--line); background: var(--card); border-radius: 18px; padding: 6px 12px; font-size: .85rem; cursor: pointer; min-height: 36px; }
.chips button.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.search { margin-bottom: 8px; }

.list { display: flex; flex-direction: column; gap: 8px; }
.li { display: grid; grid-template-columns: 52px 1fr auto; gap: 10px; align-items: center; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px; text-align: left; width: 100%; cursor: pointer; }
.li.noimg { grid-template-columns: 1fr auto; }
.li .t { font-weight: 600; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; line-height: 1.3; }
.li .m { font-size: .8rem; color: var(--muted); overflow-wrap: anywhere; }
.li .r { text-align: right; font-size: .85rem; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.thumb { width: 52px; height: 52px; border-radius: 8px; object-fit: cover; background: var(--pill); display: block; }
.pill { display: inline-block; border-radius: 10px; padding: 1px 8px; font-size: .72rem; font-weight: 600; background: var(--pill); color: var(--muted); white-space: nowrap; }
.pill.listed { background: var(--accent-soft); color: var(--accent); }
.pill.sold, .pill.shipped { background: color-mix(in srgb, var(--good) 15%, transparent); color: var(--good); }
.pill.delivered { background: var(--good); color: var(--card); }
.pill.returned { background: color-mix(in srgb, var(--bad) 15%, transparent); color: var(--bad); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.empty { text-align: center; color: var(--muted); padding: 24px 8px; }

table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { padding: 6px 3px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
td:first-child { overflow-wrap: anywhere; }
@media (max-width: 420px) { table { font-size: .82rem; } }
th { font-size: .75rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
td.n, th.n { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.total td { font-weight: 700; border-top: 2px solid var(--text); }
.tablewrap { overflow-x: auto; }
dl.money { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; margin: 0; }
dl.money dt { color: var(--muted); }
dl.money dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
dl.money .net { font-weight: 750; font-size: 1.1rem; border-top: 1px solid var(--line); padding-top: 6px; }

.photos { display: flex; gap: 8px; overflow-x: auto; margin: 4px 0 12px; }
.photos img { height: 120px; border-radius: 10px; border: 1px solid var(--line); }
.lines .line { display: grid; grid-template-columns: 1fr 64px 96px 36px; gap: 6px; align-items: center; margin-bottom: 6px; }
.lines .line .lt { font-size: .85rem; overflow-wrap: anywhere; }
.lines .line input { padding: 8px; }
.x { background: none; border: 1px solid var(--line); border-radius: 10px; min-height: 40px; cursor: pointer; color: var(--muted); }
.pick { display: flex; flex-direction: column; gap: 4px; margin-top: 6px; }
.pick button { text-align: left; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; cursor: pointer; font-size: .9rem; }

.scan video { width: 100%; max-height: 60vh; border-radius: 14px; background: #000; display: block; object-fit: cover; }
.scan .frame { position: relative; }
.scan .frame::after { content: ""; position: absolute; inset: 18% 18%; border: 3px solid rgba(255,255,255,.85); border-radius: 16px; box-shadow: 0 0 0 999px rgba(0,0,0,.25); pointer-events: none; }
.linkbox { font-family: ui-monospace, Consolas, monospace; font-size: .8rem; background: var(--bg); border: 1px dashed var(--line); border-radius: 10px; padding: 8px; overflow-wrap: anywhere; }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(80px + env(safe-area-inset-bottom)); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; z-index: 20; font-size: .9rem; max-width: calc(100% - 32px); }

/* Print: summaries and box labels */
.printonly { display: none; }
.sheet { width: 8.5in; height: 11in; position: relative; background: #fff; color: #000; margin: 0 auto 16px; box-shadow: 0 0 0 1px var(--line); page-break-after: always; break-after: page; }
.lab { position: absolute; left: .75in; width: 7in; height: 3in; padding: .18in .22in; display: grid; grid-template-columns: 2in 1fr; gap: .18in; overflow: hidden; font-family: "Segoe UI", Arial, sans-serif; border: 1px dashed #bbb; }
.lab .qr svg { width: 2in; height: 2in; display: block; margin-top: .12in; }
.lab .code { font-size: 26pt; font-weight: 800; line-height: .95; }
.lab .ttl { font-size: 9.5pt; font-weight: 600; margin-top: .04in; }
.lab .meta { font-size: 7.5pt; margin-top: .03in; }
.lab ul { margin: .05in 0 0; padding: .04in 0 0 1em; font-size: 8pt; line-height: 1.15; border-top: 1.2px solid #000; columns: 2; column-gap: .2in; overflow: hidden; max-height: 1.9in; }
.labels-scroll { overflow-x: auto; }
body.labels main { max-width: none; }
@media print {
  html, body { background: #fff !important; color: #000 !important; }
  .top, .tabs, .noprint, .toast { display: none !important; }
  main { padding: 0; max-width: none; }
  .card { border: 0; padding: 0; margin: 0 0 12px; background: #fff; }
  .printonly { display: block; }
  a { color: #000; }
  :root, :root[data-theme="dark"] { --muted: #333; --line: #bbb; --text: #000; --card: #fff; --bg: #fff; --good: #000; --bad: #000; }
  body.labels .labels-scroll { overflow: visible; }
  body.labels .sheet { box-shadow: none; margin: 0; zoom: 1; }
  body.labels .lab { border: 0; }
}
@media screen and (max-width: 860px) { .labels-scroll .sheet { zoom: .44; } }

@media (max-width: 380px) {
  .tile { padding: 8px; }
  .tile b { font-size: 1rem; }
  .lines .line { grid-template-columns: 1fr 52px 80px 34px; }
  .hero .big { font-size: 1.7rem; }
}
