:root {
  --accent: #8b7268;
  --accent-dark: #6d574e;
  --ink: #2b2420;
  --line: rgba(139,114,104,0.25);
  --bg: #f7f4ee;
  --good: #2e7d32;
  --bad: #c1272d;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--ink); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
#app { max-width: 760px; margin: 0 auto; padding: 16px; padding-bottom: 100px; }

h1 { font-size: 22px; margin: 0 0 4px; }
.sub { color: #7a6f66; font-size: 13px; margin: 0 0 20px; }

.card { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 16px; margin-bottom: 16px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

input[type="text"], input[type="password"], input[type="number"] {
  font-size: 16px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px;
  outline: none; background: #fff; color: var(--ink); width: 100%;
}
input:focus { border-color: var(--accent); }

button {
  font-size: 15px; font-weight: 600; padding: 12px 18px; border-radius: 10px;
  border: 1px solid var(--line); background: #fff; color: var(--ink); cursor: pointer;
}
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { background: var(--accent-dark); }
button.ghost { background: transparent; border-color: transparent; color: var(--accent-dark); }
button.danger { color: var(--bad); border-color: var(--bad); background: #fff; }
button.sm { padding: 6px 10px; font-size: 13px; }
button:disabled { opacity: .45; cursor: not-allowed; }

.login-wrap { display: flex; align-items: center; justify-content: center; min-height: 80vh; }
.login-card { width: 100%; max-width: 340px; text-align: center; }
.login-card h1 { margin-bottom: 18px; }

.box-header { display: flex; align-items: baseline; gap: 10px; margin-bottom: 4px; }
.box-header .num { font-size: 26px; font-weight: 800; color: var(--accent-dark); }
.count-pill { display: inline-block; background: #efe9e0; color: var(--accent-dark); border-radius: 999px; padding: 3px 10px; font-size: 12px; font-weight: 700; }

table.items { width: 100%; border-collapse: collapse; margin-top: 10px; font-size: 14px; }
table.items th { text-align: left; font-size: 11px; text-transform: uppercase; color: #9a8f85; padding: 6px 4px; border-bottom: 1px solid var(--line); }
table.items td { padding: 8px 4px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.items td.isbn { font-family: monospace; font-size: 12px; color: #7a6f66; }
table.items td.qty { text-align: center; white-space: nowrap; }
.qty-btn { width: 28px; height: 28px; padding: 0; border-radius: 6px; font-size: 16px; line-height: 1; }
.qty-val { display: inline-block; min-width: 28px; text-align: center; font-weight: 700; }
.item-name.unknown { color: var(--bad); }
.item-name.unknown::after { content: " (not in master sheet)"; font-size: 11px; font-weight: 400; }

.scan-tabs { display: flex; gap: 8px; margin-top: 4px; }
.mode-tab { flex: 1; background: #f2ede4; border-color: transparent; color: #7a6f66; font-size: 13px; padding: 10px; }
.mode-tab.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.name-results { margin-top: 10px; max-height: 340px; overflow-y: auto; }
.name-result-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.name-result-row:last-child { border-bottom: none; }
.name-result-text { flex: 1; font-size: 14px; min-width: 0; }
.name-result-text .isbn { font-family: monospace; font-size: 11px; color: #9a8f85; margin-top: 2px; }

.empty-row { text-align: center; color: #9a8f85; padding: 24px 0; font-size: 14px; }

.scan-modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.75); z-index: 500;
  display: flex; align-items: center; justify-content: center; flex-direction: column;
}
.scan-modal { width: min(92vw, 480px); background: #000; border-radius: 12px; overflow: hidden; position: relative; }
#qr-reader { width: 100%; }
.scan-close { margin-top: 16px; }
.scan-status { color: #fff; font-size: 15px; font-weight: 600; margin-top: 10px; min-height: 20px; transition: color .15s; }
.scan-status.ok { color: #6fd18a; }
.scan-status.err { color: #ff8a80; }
.torch-toggle { margin-top: 10px; background: rgba(255,255,255,.1); border-color: rgba(255,255,255,.3); color: #fff; }
.torch-toggle.on { background: #f2c14e; border-color: #f2c14e; color: #2b2420; }

.prev-boxes { margin-top: 8px; }
.prev-box-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.prev-box-row:last-child { border-bottom: none; }

.status-pill { display: inline-block; border-radius: 999px; padding: 2px 9px; font-size: 11px; font-weight: 700; margin-left: 6px; vertical-align: middle; }
.status-pill.draft { background: #f2ede4; color: #8a7a6b; }
.status-pill.saved { background: #e3f3e6; color: var(--good); }

.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 600;
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal-box { background: #fff; border-radius: 12px; padding: 20px; width: 100%; max-width: 360px; box-shadow: 0 10px 30px rgba(0,0,0,.2); }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 999px; font-size: 14px; z-index: 999; box-shadow: 0 4px 14px rgba(0,0,0,.25); }

@media print {
  body * { visibility: hidden; }
  #print-area, #print-area * { visibility: visible; }
  #print-area { display: block; position: absolute; top: 0; left: 0; width: 100%; padding: 20px; }
}
#print-area { display: none; }
#print-area table { width: 100%; border-collapse: collapse; }
#print-area th, #print-area td { border: 1px solid #999; padding: 6px 8px; text-align: left; font-size: 14px; }
#print-area h2 { margin-bottom: 4px; }
#print-area .meta { color: #555; font-size: 12px; margin-bottom: 14px; }
