/* Anncraft DO — count screen (phone-first) + printable A4 delivery order */
:root {
  --paper: #f3f5f8;
  --card: #ffffff;
  --ink: #1b2233;
  --muted: #5d6679;
  --line: #d5dae3;
  --accent: #2346a8;
  --accent-ink: #ffffff;
  --accent-soft: #e6ecfa;
  --done: #1d7a4a;
  --done-soft: #e3f3ea;
  --warn: #9a5b00;
  --warn-soft: #fff3dc;
  --danger: #b3261e;
  --display: "Barlow Condensed", "Arial Narrow", sans-serif;
  --body: "Barlow", "Segoe UI", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #12151c; --card: #1a1f29; --ink: #e6e9f0; --muted: #98a1b3; --line: #2d3442;
    --accent: #8aa6ff; --accent-ink: #10162a; --accent-soft: #232c45; --done: #5cc98e; --done-soft: #1b3326;
    --warn: #f0b860; --warn-soft: #3a2e18; --danger: #ff8a80; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #12151c; --card: #1a1f29; --ink: #e6e9f0; --muted: #98a1b3; --line: #2d3442;
  --accent: #8aa6ff; --accent-ink: #10162a; --accent-soft: #232c45; --done: #5cc98e; --done-soft: #1b3326;
  --warn: #f0b860; --warn-soft: #3a2e18; --danger: #ff8a80; color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--paper); color: var(--ink); font: 15px/1.4 var(--body); }
[hidden] { display: none !important; }
button, input, textarea { font: inherit; color: inherit; }

/* ---- top bar ---- */
.bar {
  position: sticky; top: 0; z-index: 20; background: var(--card); border-bottom: 1px solid var(--line);
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px;
  padding: calc(8px + env(safe-area-inset-top, 0px)) 16px 8px;
}
.brand { font-family: var(--display); font-size: 1.35rem; letter-spacing: .02em; white-space: nowrap; }
.brand b { color: var(--accent); font-weight: 700; }
.brand span { font-weight: 500; color: var(--muted); }
.tabs { display: flex; gap: 4px; }
.tabs button {
  border: 1px solid var(--line); background: transparent; border-radius: 999px; padding: 6px 14px;
  font-weight: 600; font-size: .9rem; cursor: pointer; color: var(--muted);
}
.tabs button[aria-selected="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

.view { max-width: 860px; margin: 0 auto; padding: 16px 16px 120px; display: grid; gap: 14px; }
#view-do { max-width: 940px; padding-bottom: 48px; }

/* ---- cards ---- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 16px; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px 12px; flex-wrap: wrap; margin-bottom: 8px; }
.card-head h2 { font-family: var(--display); font-weight: 600; font-size: 1.35rem; margin: 0; letter-spacing: .02em; }
.card-head .sub { color: var(--muted); font-size: .85rem; }
.sec-total { font-family: var(--mono); font-size: .85rem; color: var(--muted); }
.sec-total b { color: var(--ink); font-size: 1rem; }

.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px 16px; }
.field { display: grid; gap: 3px; min-width: 0; }
.field.full { grid-column: 1 / -1; }
.lbl, .field label { font-size: .7rem; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); font-weight: 600; }
.field input, .field textarea {
  background: transparent; border: none; border-bottom: 1px dashed var(--line); padding: 5px 0; width: 100%; resize: vertical; min-width: 0;
}
.field input:focus, .field textarea:focus { outline: none; border-bottom: 1px solid var(--accent); }

/* ---- count rows ---- */
.cols, .row { display: grid; grid-template-columns: 64px 1fr; gap: 8px; align-items: center; }
.cols.two, .row.two { grid-template-columns: 64px 1fr 1fr; }
.cols { padding: 4px 0 6px; border-bottom: 1px solid var(--line); }
.cols span { font-size: .7rem; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); font-weight: 600; }
.row { padding: 6px 0; border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: none; }
.size { font-family: var(--display); font-weight: 700; font-size: 1.35rem; letter-spacing: .03em; }

.cell { display: flex; align-items: center; gap: 8px; padding: 5px 6px; border-radius: 6px; min-width: 0; transition: background .15s; }
.cell.ticked { background: var(--done-soft); }
.cell .tag { display: none; font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 600; width: 64px; }

.tick {
  appearance: none; -webkit-appearance: none; margin: 0; width: 30px; height: 30px; border: 2px solid var(--muted); border-radius: 5px;
  cursor: pointer; flex: none; display: grid; place-items: center; background: var(--card);
}
.tick:checked { background: var(--done); border-color: var(--done); }
.tick:checked::after { content: ""; width: 8px; height: 14px; border: solid var(--card); border-width: 0 3px 3px 0; transform: translateY(-2px) rotate(45deg); }

.stepper { display: inline-flex; align-items: stretch; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; background: var(--card); }
.step { font: 600 1.2rem var(--mono); width: 40px; min-height: 40px; border: none; background: var(--accent-soft); color: var(--accent); cursor: pointer; touch-action: manipulation; }
.step:active { filter: brightness(.9); }
.qty {
  width: 56px; text-align: center; font: 600 1.1rem var(--mono); background: transparent; border: none; padding: 6px 0;
  font-variant-numeric: tabular-nums; -moz-appearance: textfield; appearance: textfield;
}
.qty::-webkit-outer-spin-button, .qty::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.qty::placeholder { color: var(--line); }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* customer order (expected qty) */
.exp { font: 600 .85rem var(--mono); color: var(--muted); white-space: nowrap; min-width: 0; }
.exp.ok { color: var(--done); }
.exp.short { color: var(--warn); }
.exp.over { color: var(--danger); }
.ord { flex-basis: 100%; font-size: .85rem; color: var(--muted); }
.ord b { color: var(--ink); font-family: var(--mono); }
.ord .lbl { margin-right: 4px; }
.ord em { font-style: normal; font-weight: 600; font-size: .8rem; padding: 1px 6px; border-radius: 999px; }
.ord em.ok { color: var(--done); background: var(--done-soft); }
.ord em.short { color: var(--warn); background: var(--warn-soft); }
.ord em.over { color: var(--danger); background: var(--warn-soft); }
.orderpick { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.orderpick select { font: 600 .95rem var(--body); padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--card); color: var(--ink); max-width: 100%; }
#order-tools { display: inline-flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.chk { display: inline-flex; gap: 6px; align-items: center; font-size: .9rem; color: var(--muted); cursor: pointer; padding: 0 4px; }

/* other items */
.extra { display: grid; grid-template-columns: 1fr 90px auto auto; gap: 8px; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--line); }
.extra input.txt { border: none; border-bottom: 1px dashed var(--line); background: transparent; padding: 6px 0; min-width: 0; width: 100%; }
.extra input.txt:focus { outline: none; border-bottom-color: var(--accent); }
.x { border: none; background: transparent; color: var(--muted); font-size: 1.3rem; width: 36px; height: 36px; cursor: pointer; border-radius: 6px; }
.x:hover { color: var(--danger); background: var(--warn-soft); }
#add-extra { margin-top: 10px; }

/* buttons */
.btn {
  font: 600 .92rem var(--body); padding: 10px 16px; border-radius: 6px; border: 1px solid var(--line);
  background: var(--card); color: var(--ink); cursor: pointer; white-space: nowrap;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; color: var(--accent); border-style: dashed; }
.btn.danger { color: var(--danger); border-color: currentColor; background: transparent; }
.btn.small { padding: 6px 10px; font-size: .85rem; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.confirm { display: inline-flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: .9rem; }
.note { color: var(--muted); font-size: .82rem; margin: 0; }

/* bottom dock */
.dock { position: fixed; left: 0; right: 0; bottom: 0; z-index: 15; background: var(--card); border-top: 1px solid var(--line); padding: 10px 16px calc(10px + env(safe-area-inset-bottom, 0px)); }
.dock-in { max-width: 828px; margin: 0 auto; display: flex; align-items: center; gap: 16px; }
.dock-n b { font: 600 1.6rem var(--mono); font-variant-numeric: tabular-nums; }
.dock-n, .dock-t { display: grid; line-height: 1.1; }
.dock-n { grid-template-columns: auto auto; column-gap: 4px; align-items: baseline; }
.dock-n .lbl { grid-column: 1 / -1; }
.dock-t b { font-family: var(--mono); }
.dock .btn { margin-left: auto; padding: 12px 18px; }

/* ---- DO screen ---- */
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; }
.msgs { display: grid; gap: 6px; }
.msg { padding: 9px 12px; border-radius: 6px; font-size: .9rem; background: var(--warn-soft); color: var(--warn); }
.msg.ok { background: var(--done-soft); color: var(--done); }
.paper-wrap { overflow-x: auto; }

/* the printed document — always black on white */
.paper {
  --p-ink: #111; --p-muted: #555; --p-line: #bbb; --p-accent: #1f3d94;
  background: #fff; color: var(--p-ink); width: 100%; max-width: 210mm; min-width: 560px; margin: 0 auto;
  padding: 14mm 14mm 12mm; border: 1px solid var(--line); box-shadow: 0 2px 12px rgba(0,0,0,.08);
  font: 10.5pt/1.35 var(--body);
}
.lh { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; border-bottom: 2.5px solid var(--p-accent); padding-bottom: 10px; }
.lh .co { font-family: var(--display); font-weight: 700; font-size: 20pt; letter-spacing: .03em; line-height: 1; color: var(--p-accent); }
.lh .co small { font-family: var(--body); font-size: 8.5pt; font-weight: 500; color: var(--p-muted); letter-spacing: 0; margin-left: 4px; }
.lh .addr { font-size: 9pt; color: var(--p-muted); margin-top: 5px; }
.lh .title { text-align: right; }
.lh .title h1 { margin: 0; white-space: nowrap; font-family: var(--display); font-weight: 700; font-size: 18pt; letter-spacing: .06em; line-height: 1; }
.lh .title .no { font: 600 11pt var(--mono); margin-top: 6px; }

.meta { display: grid; grid-template-columns: 1.4fr 1fr; gap: 10px 20px; margin: 10px 0; }
.box { border: 1px solid var(--p-line); border-radius: 3px; padding: 7px 9px; }
.box .k { font-size: 7.5pt; text-transform: uppercase; letter-spacing: .1em; color: var(--p-muted); font-weight: 600; }
.box .v { white-space: pre-line; min-height: 1.3em; }
.box .v.big { font-weight: 700; font-size: 11.5pt; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 3px 10px; }
.kv .k { align-self: center; }

table.items { width: 100%; border-collapse: collapse; margin-top: 4px; font-size: 9.5pt; }
.items th { font-size: 8pt; text-transform: uppercase; letter-spacing: .08em; text-align: left; background: #eef1f8; border: 1px solid var(--p-line); padding: 5px 7px; }
.items td { border: 1px solid var(--p-line); padding: 2px 7px; vertical-align: top; line-height: 1.25; }
.items .n, .items .q { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; }
.items th.n, .items th.q { text-align: right; white-space: nowrap; }
.items td.n { color: var(--p-muted); width: 34px; }
.items td.q { width: 80px; font-weight: 600; }
.items td.o { color: var(--p-muted); font-weight: 500; }
.items td.b { font-weight: 500; }
.items td.s { width: 80px; font-weight: 600; }
.items td.d { vertical-align: middle; }
.items td.d small { display: block; color: var(--p-muted); font-size: 8.5pt; }
.items tfoot td { font-weight: 700; background: #eef1f8; }
.items tr { break-inside: avoid; }
.empty { text-align: center; color: var(--p-muted); padding: 18px; }

.remark { margin-top: 10px; }
.ack { font-size: 8.5pt; color: var(--p-muted); margin: 8px 0 4px; }
.sigs { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin-top: 6px; break-inside: avoid; }
.sig .space { height: 46px; border-bottom: 1px solid var(--p-ink); }
.sig .k { font-size: 7.5pt; text-transform: uppercase; letter-spacing: .1em; color: var(--p-muted); font-weight: 600; margin-top: 4px; }
.sig .line { display: grid; grid-template-columns: 52px 1fr; gap: 4px; font-size: 9pt; margin-top: 5px; }
.sig .line span:last-child { border-bottom: 1px dotted var(--p-line); min-height: 1.2em; }
.foot { margin-top: 8px; font-size: 7.5pt; color: var(--p-muted); text-align: center; }

/* ---- history ---- */
.hrow { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; padding: 10px 0; border-bottom: 1px solid var(--line); align-items: center; }
.hrow:last-child { border-bottom: none; }
.hrow .t { font-weight: 600; }
.hrow .t span { font-family: var(--mono); color: var(--accent); margin-right: 8px; }
.hrow .m { color: var(--muted); font-size: .85rem; }
.hrow .b { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }

@media (max-width: 600px) {
  .cols.two { display: none; }
  .row.two { grid-template-columns: 1fr; gap: 4px; }
  .row.two .size { margin-top: 2px; }
  .row.two .cell .tag { display: inline-block; }
  .card { padding: 14px; }
  .extra { grid-template-columns: 1fr 70px; }
  .extra .stepper { grid-column: 1; justify-self: start; }
  .tabs button { padding: 6px 10px; }
  .dock-in { gap: 12px; }
  .meta, .sigs { grid-template-columns: 1fr; }
}

@media print {
  @page { size: A4 portrait; margin: 0; }
  body { background: #fff; }
  .bar, .toolbar, .msgs, #view-count, #view-hist { display: none !important; }
  #view-do { display: block !important; padding: 0; max-width: none; }
  .paper-wrap { overflow: visible; }
  .paper { border: none; box-shadow: none; max-width: none; min-width: 0; width: 210mm; padding: 12mm 14mm; }
  .meta { grid-template-columns: 1.4fr 1fr; }
  .sigs { grid-template-columns: 1fr 1fr; }
  .items th, .items tfoot td { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
@media (prefers-reduced-motion: reduce) { .cell { transition: none; } }
