:root {
  --indigo: #2746E8;
  --turq: #1AA8D6;
  --mint: #37D9A4;
  --ink: #161A2E;
  --bg: #F4F6FB;
  --surface: #fff;
  --border: #E6E9F2;
  --muted: #5B6172;
  --faint: #9AA3B2;
  --grad-btn: linear-gradient(120deg, #2746E8, #1AA8D6);
  --radius: 12px;
}

* { box-sizing: border-box; }
body { font-family: "Onest", system-ui, sans-serif; margin: 0; color: var(--ink); background: var(--bg); }
*::selection { background: var(--indigo); color: #fff; }

#app { max-width: 760px; margin: 0 auto; padding: 24px 16px 64px; }

.brand { display: inline-flex; align-items: center; gap: 10px; margin-bottom: 18px; }
.brand svg { display: block; flex: none; }
.brand-word { font-size: 19px; font-weight: 800; letter-spacing: -0.02em; }
.brand-grad { background: var(--grad-btn); -webkit-background-clip: text; background-clip: text; color: transparent; }

h1 { font-size: 24px; font-weight: 800; letter-spacing: -0.02em; margin: 0 0 8px; }
.hint { color: var(--muted); font-size: 14px; line-height: 1.5; margin: 0 0 22px; }

.grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; margin-bottom: 16px; }
.field { display: flex; flex-direction: column; }
.field label, .reload label { font-weight: 600; font-size: 11px; color: var(--faint); margin-bottom: 6px; }
input { padding: 10px 12px; font-size: 14px; font-weight: 500; border: 1px solid var(--border); border-radius: var(--radius); width: 100%; outline: none; background: var(--surface); transition: border-color .12s; }
input:focus { border-color: var(--indigo); }

.boxes-bar { display: flex; align-items: center; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
#box-tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.tab { padding: 8px 14px; border: 1px solid var(--border); background: var(--surface); color: var(--muted); border-radius: 10px; cursor: pointer; font-size: 13px; font-weight: 600; }
.tab.on { background: var(--grad-btn); color: #fff; border-color: transparent; }
#add-box { padding: 8px 14px; border: 1px dashed #CBD2E0; color: var(--indigo); background: var(--surface); border-radius: 10px; cursor: pointer; font-weight: 600; }

table.editor { width: 100%; border-collapse: collapse; margin-bottom: 10px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
table.editor th { text-align: left; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--faint); padding: 10px 8px; border-bottom: 1px solid var(--border); }
table.editor td { padding: 4px 6px; border-bottom: 1px solid var(--border); }
table.editor tr:last-child td { border-bottom: none; }
table.editor td:first-child { width: 28px; color: var(--faint); font-size: 12px; text-align: center; }
table.editor input { border: 1px solid transparent; background: transparent; border-radius: 8px; }
table.editor input:focus { border-color: var(--indigo); background: var(--surface); }
table.editor input.qty { width: 60px; }
.charcount { display: none; font-size: 10px; font-weight: 600; margin-top: 2px; padding: 0 5px; border-radius: 3px; background: #ff8c00; color: #fff; }
.x { width: 32px; height: 32px; border: 1px solid var(--border); background: var(--surface); border-radius: 8px; cursor: pointer; color: var(--muted); }

.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.actions { margin-top: 20px; }
button { font-size: 14px; font-family: inherit; }
#add-item { padding: 9px 14px; border: 1px solid var(--border); background: var(--surface); color: var(--muted); border-radius: 10px; cursor: pointer; font-weight: 600; }
.count { color: var(--faint); font-size: 12px; }
.danger { margin-left: auto; padding: 9px 14px; border: 1px solid #C0392B; color: #C0392B; background: var(--surface); border-radius: 10px; cursor: pointer; font-weight: 600; }
button.primary { background: var(--grad-btn); color: #fff; border: none; padding: 12px 22px; border-radius: var(--radius); cursor: pointer; font-weight: 700; }
#pdf, #share { padding: 12px 18px; border: 1px solid var(--border); background: var(--surface); color: var(--indigo); border-radius: var(--radius); cursor: pointer; font-weight: 700; }
#pdf[disabled], #share[disabled] { opacity: .4; cursor: not-allowed; }

.reload { margin-top: 24px; padding-top: 18px; border-top: 1px solid var(--border); }
#scan-cam { padding: 10px 14px; border: 1px solid var(--border); background: var(--surface); color: var(--muted); border-radius: 10px; cursor: pointer; font-weight: 600; }
.msg { display: block; font-size: 12px; color: var(--indigo); margin-top: 8px; font-weight: 500; }
.error { color: #C0392B; font-size: 13px; font-weight: 500; }

/* scanner modal */
.modal { position: fixed; inset: 0; background: rgba(22,26,46,.55); z-index: 80; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal.hidden { display: none; }
.modal-card { background: var(--surface); border-radius: 18px; padding: 16px; width: min(92vw, 380px); box-shadow: 0 20px 60px rgba(22,26,46,.3); }
.modal-head { display: flex; justify-content: space-between; align-items: center; font-weight: 700; margin-bottom: 12px; }
.modal-head button { border: none; background: var(--bg); border-radius: 8px; width: 32px; height: 32px; cursor: pointer; font-size: 16px; color: var(--muted); }
.scan-area { position: relative; width: 100%; aspect-ratio: 1 / 1; background: #000; border-radius: 12px; overflow: hidden; }
.scan-area video { width: 100%; height: 100%; object-fit: cover; }
.scan-frame { position: absolute; inset: 15%; border: 3px solid rgba(255,255,255,.95); border-radius: 14px; box-shadow: 0 0 0 1000px rgba(0,0,0,.35); }
.scan-status { text-align: center; font-size: 13px; color: var(--muted); margin-top: 10px; }

/* printable inventory — Times New Roman, template style (unchanged) */
.page { width: 210mm; min-height: 297mm; margin: 18px auto; padding: 12mm; background: #fff; border: 1px solid #ddd; font-family: "Times New Roman", Times, serif; color: #000; }
.copy { position: relative; }
.qr { position: absolute; top: 0; right: 0; width: 26mm; height: 26mm; image-rendering: pixelated; }
.doc-title { text-align: center; font-weight: 700; font-size: 16px; margin: 0 0 10px; }
.doc-fields { font-size: 13px; line-height: 1.7; margin-bottom: 8px; }
.doc-fields u { text-decoration: none; border-bottom: 1px solid #000; padding: 0 4px; min-width: 60mm; display: inline-block; }
.doc-table { width: 100%; border-collapse: collapse; font-size: 12px; table-layout: fixed; }
.doc-table th, .doc-table td { border: 1px solid #000; padding: 2px 5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.doc-table th { font-weight: 700; text-align: center; }
.doc-table td.n, .doc-table td.qty { text-align: center; width: 14mm; }
.doc-table th:nth-child(1) { width: 14mm; }
.doc-table th:nth-child(3) { width: 18mm; }
.doc-table th:nth-child(4) { width: 45mm; }
.doc-sign { font-size: 12px; margin-top: 10px; }
.copyno { font-size: 10px; color: #555; margin-top: 4px; text-align: right; }
.tear { text-align: center; color: #999; font-size: 11px; margin: 10px 0; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 10px; font-size: 13px; font-weight: 500; z-index: 60; box-shadow: 0 10px 30px rgba(22,26,46,.3); }
.toast.hidden { display: none; }

.page.half { min-height: auto; }

@media (max-width: 620px) {
  #app { padding: 18px 14px 56px; }
  h1 { font-size: 21px; }
  .grid { grid-template-columns: 1fr; }
  .danger { margin-left: 0; }
  .actions { flex-direction: column; align-items: stretch; }
  .actions button { width: 100%; }
}

@media print {
  .screen-only, .scanner { display: none !important; }
  body { margin: 0; background: #fff; }
  .page { width: auto; min-height: auto; margin: 0; padding: 8mm; border: none; }
  .page-break { page-break-before: always; }
  @page { size: A4; margin: 8mm; }
}
