:root {
  --bg: #f5f5f4; --card: #ffffff; --text: #1c1917; --muted: #78716c; --line: #e7e5e4;
  --accent: #0f766e; --accent-text: #ffffff; --err: #b91c1c; --note: #fef9c3;
  --to_print: #64748b; --printed: #d97706; --glued: #7c3aed; --dispatched: #16a34a;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #151413; --card: #211f1e; --text: #f5f5f4; --muted: #a8a29e; --line: #3a3735; --note: #4a4318; --err: #f87171; }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
body { padding-bottom: calc(80px + env(safe-area-inset-bottom)); }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 4px; padding: 10px 12px; padding-top: calc(10px + env(safe-area-inset-top)); background: var(--accent); color: var(--accent-text); }
.title { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.title b { font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.title small { opacity: .85; font-size: 12px; }
.icon { background: transparent; border: 0; color: inherit; font-size: 24px; width: 44px; height: 44px; border-radius: 22px; }
.icon:active { background: rgba(255,255,255,.2); }
.icon.spin { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

main { max-width: 720px; margin: 0 auto; padding: 0 12px; }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 18px; margin-top: 16px; }
.panel h2 { margin-top: 0; }
.panel form { display: grid; gap: 10px; }
input[type=password], input[type=search], textarea { width: 100%; padding: 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); }
.btn, button.primary, a.primary { display: inline-block; text-align: center; text-decoration: none; padding: 12px 16px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--text); font-weight: 600; }
.primary { background: var(--accent) !important; color: var(--accent-text) !important; border-color: var(--accent) !important; }
.ghost { background: transparent; border: 1px solid var(--line); border-radius: 10px; padding: 0 14px; font-weight: 600; }
.ghost.on { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.error { color: var(--err); margin: 0; min-height: 1em; }

#tabs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; padding: 12px 0 8px; position: sticky; top: calc(64px + env(safe-area-inset-top)); background: var(--bg); z-index: 4; }
#tabs button { border: 0; background: var(--card); border-radius: 12px; padding: 8px 2px; border-bottom: 4px solid var(--line); display: grid; gap: 0; line-height: 1.15; }
#tabs button b { font-size: 20px; }
#tabs button span { font-size: 12px; color: var(--muted); }
#tabs button.on { background: var(--card); box-shadow: 0 0 0 2px var(--accent) inset; }
#tabs button.to_print { border-bottom-color: var(--to_print); }
#tabs button.printed { border-bottom-color: var(--printed); }
#tabs button.glued { border-bottom-color: var(--glued); }
#tabs button.dispatched { border-bottom-color: var(--dispatched); }

.tools { display: flex; gap: 8px; margin: 4px 0 8px; }
.tools input { flex: 1; }
.tools .ghost { height: 44px; }
#summary { color: var(--muted); font-size: 14px; margin: 4px 2px 10px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px; margin-bottom: 10px; border-left: 6px solid var(--to_print); }
.card.printed { border-left-color: var(--printed); }
.card.glued { border-left-color: var(--glued); }
.card.dispatched { border-left-color: var(--dispatched); }
.card.picked { outline: 3px solid var(--accent); }
.card .head { display: flex; align-items: center; gap: 10px; }
.card .head .who { flex: 1; min-width: 0; }
.card .head b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .head small { color: var(--muted); }
.card .head small.late { color: var(--err); font-weight: 600; }
.check { width: 26px; height: 26px; border-radius: 8px; border: 2px solid var(--muted); display: grid; place-items: center; flex: none; font-weight: 800; }
.picked .check { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.items { list-style: none; margin: 10px 0; padding: 0; display: grid; gap: 8px; }
.items li { display: flex; gap: 10px; }
.qty { flex: none; min-width: 34px; height: 28px; border-radius: 8px; background: var(--bg); display: grid; place-items: center; font-weight: 800; }
.qty.many { background: var(--accent); color: var(--accent-text); }
.items .t { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.items .v { color: var(--muted); font-size: 14px; }
.items .v b { color: var(--text); font-weight: 600; }
.badges { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.badge { font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 99px; background: var(--bg); color: var(--muted); }
.badge.to_print { color: var(--to_print); } .badge.printed { color: var(--printed); } .badge.glued { color: var(--glued); } .badge.dispatched { color: var(--dispatched); }
details { margin: 6px 0; font-size: 14px; }
details summary { color: var(--accent); font-weight: 600; cursor: pointer; }
details p { margin: 6px 0 0; white-space: pre-wrap; }
.steps { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; margin: 10px 0 8px; }
.step { border: 1px solid var(--line); background: transparent; border-radius: 8px; padding: 6px 0; font-size: 12px; color: var(--muted); }
.step.done { color: var(--text); background: var(--bg); }
.step.on { color: #fff; border-color: transparent; font-weight: 700; }
.step.on.to_print { background: var(--to_print); } .step.on.printed { background: var(--printed); } .step.on.glued { background: var(--glued); } .step.on.dispatched { background: var(--dispatched); }
.next { width: 100%; padding: 14px; border-radius: 10px; border: 0; font-weight: 700; font-size: 17px; color: #fff; background: var(--accent); }
.next.printed { background: var(--printed); } .next.glued { background: var(--glued); } .next.dispatched { background: var(--dispatched); }
.next:active { filter: brightness(.9); }
.noteBtn { background: transparent; border: 0; color: var(--accent); font-weight: 600; padding: 8px 0 0; }
.card textarea { background: var(--note); margin-top: 8px; resize: vertical; min-height: 56px; }
.empty { text-align: center; color: var(--muted); padding: 40px 10px; }

#bar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; background: var(--card); border-top: 1px solid var(--line); padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); display: grid; gap: 8px; }
#bar .row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
#bar button { padding: 12px 0; border-radius: 10px; border: 0; color: #fff; font-weight: 700; font-size: 13px; }
#bar button.to_print { background: var(--to_print); } #bar button.printed { background: var(--printed); } #bar button.glued { background: var(--glued); } #bar button.dispatched { background: var(--dispatched); }
#bar .info { display: flex; justify-content: space-between; align-items: center; font-weight: 600; }
#bar .info button { background: transparent; color: var(--accent); padding: 0; font-size: 14px; }

dialog { border: 0; border-radius: 16px; padding: 18px; width: min(92vw, 380px); background: var(--card); color: var(--text); }
dialog::backdrop { background: rgba(0,0,0,.5); }
dialog h3 { margin-top: 0; }
.stack { display: grid; gap: 8px; }
.fine { font-size: 12px; color: var(--muted); }
#toast { position: fixed; left: 50%; bottom: calc(190px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px); background: #1c1917; color: #fff; padding: 10px 16px; border-radius: 99px; opacity: 0; pointer-events: none; transition: .25s; max-width: 90vw; text-align: center; z-index: 10; font-size: 14px; }
#toast.show { opacity: 1; transform: translateX(-50%); }

.itemBody { min-width: 0; flex: 1; }
.file { margin: 6px 0 2px; }
.thumb { display: block; max-width: 100%; max-height: 220px; object-fit: contain; border-radius: 8px; border: 1px solid var(--line); background: #fff; cursor: zoom-in; }
.fileTile { display: block; padding: 14px; border: 1px dashed var(--line); border-radius: 10px; text-decoration: none; color: var(--text); font-size: 14px; background: var(--bg); }
.fileBtns { display: flex; gap: 8px; margin-top: 8px; }
.btn.small { padding: 6px 12px; font-size: 14px; }
#viewer { width: min(96vw, 720px); }
#viewer img { display: block; max-width: 100%; max-height: 68vh; margin: 0 auto 12px; object-fit: contain; }

.skip { width: 100%; margin-top: 8px; padding: 11px; border-radius: 10px; border: 1px solid var(--line); background: transparent; font-weight: 600; font-size: 15px; }
.skip:disabled { opacity: .45; }
.badge.premade { background: var(--accent); color: var(--accent-text); }

.listingThumb { width: 56px; height: 56px; flex: none; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); background: #fff; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 10px; }
.chips:empty { display: none; }
.chip { background: var(--card); border: 1px solid var(--line); border-radius: 99px; padding: 3px 10px; font-size: 13px; font-weight: 600; }
.badge.late { background: #fee2e2; color: #b91c1c; }
.badge.soon { background: #fef3c7; color: #b45309; }
.warn { color: var(--err); font-weight: 700; font-size: 14px; margin-top: 2px; }
#products { width: min(96vw, 520px); max-height: 88vh; overflow: auto; }
.prod { display: flex; gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.prod img, .prod .noimg { width: 48px; height: 48px; flex: none; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); }
.prod .pt { flex: 1; min-width: 0; font-size: 14px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.prod .pt small { display: block; color: var(--muted); }
.seg { display: grid; gap: 4px; flex: none; }
.seg button { padding: 6px 10px; border: 1px solid var(--line); background: transparent; border-radius: 8px; font-size: 13px; }
.seg button.on { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.items { grid-template-columns: minmax(0, 1fr); }
.fileBtns { flex-wrap: wrap; }
.thumb { width: auto; height: auto; }
