:root {
  color-scheme: light;
  --bg: #f4f2ee; --surface: #fff; --surface-2: #faf8f4; --line: #e4dfd6;
  --text: #1c1a17; --text-2: #58524a; --muted: #8a8378;
  --brand: #23379b; --brand-ink: #fff; --brand-soft: #e8ebf8;
  --accent: #b3261e;
  --good: #137a2e; --good-bg: #e4f3e7; --bad: #c22f2f; --bad-bg: #fbe9e9; --warn: #8a5a00; --warn-bg: #fff4dc;
  --ink: #23379b;            /* slip "printed" blue */
  --pen: #1b2a6b;            /* slip handwriting */
  --radius: 14px;
  --shadow: 0 1px 2px rgba(30, 20, 10, .05), 0 4px 14px rgba(30, 20, 10, .05);
  --font: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121316; --surface: #1b1c20; --surface-2: #222328; --line: #33353b;
    --text: #eeeef0; --text-2: #c3c4c9; --muted: #8b8d94;
    --brand: #6f86ff; --brand-ink: #0d1030; --brand-soft: #1f2545;
    --good: #45c46a; --good-bg: #15301e; --bad: #ef6b6b; --bad-bg: #3a1a1a; --warn: #f2c25c; --warn-bg: #3a2e12;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121316; --surface: #1b1c20; --surface-2: #222328; --line: #33353b;
  --text: #eeeef0; --text-2: #c3c4c9; --muted: #8b8d94;
  --brand: #6f86ff; --brand-ink: #0d1030; --brand-soft: #1f2545;
  --good: #45c46a; --good-bg: #15301e; --bad: #ef6b6b; --bad-bg: #3a1a1a; --warn: #f2c25c; --warn-bg: #3a2e12;
  --shadow: none;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.45 var(--font); -webkit-font-smoothing: antialiased; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0 0 10px; line-height: 1.2; }
h2 { font-size: 19px; } h3 { font-size: 15px; }
.muted { color: var(--muted); } .tiny { font-size: 12px; margin: 6px 0 0; }
.good { color: var(--good); } .bad { color: var(--bad); }

/* layout */
.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 16px;
  background: var(--brand); color: var(--brand-ink); }
.brand { display: flex; gap: 10px; align-items: center; }
.brand b { display: block; letter-spacing: .04em; font-size: 15px; }
.brand small { opacity: .8; font-size: 12px; }
.logo { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 10px; background: rgba(255,255,255,.16); }
.logo.big { width: 56px; height: 56px; margin: 0 auto 10px; background: var(--brand); color: #fff; border-radius: 16px; }
.who { font-size: 13px; opacity: .85; }
main { max-width: 860px; margin: 0 auto; padding: 14px 16px 150px; display: grid; gap: 12px; }
.tabs { position: fixed; bottom: 0; left: 0; right: 0; z-index: 6; display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.tabs a { display: grid; justify-items: center; gap: 2px; padding: 8px 0 7px; font-size: 11.5px; color: var(--muted); }
.tabs a.on { color: var(--brand); font-weight: 600; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; } .row.end { justify-content: flex-end; margin-top: 10px; } .small-gap { gap: 6px; margin-top: 8px; }
.grow { flex: 1; min-width: 0; } .spacer { flex: 1; }
label { display: grid; gap: 4px; font-size: 13px; color: var(--text-2); margin-bottom: 10px; }
.row label { margin-bottom: 0; }
input, select, textarea { width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); font-size: 16px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: -1px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 11px 16px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); font-weight: 600; cursor: pointer; white-space: nowrap; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, transparent); }
.btn.primary.danger, .modal .btn.danger#yes { background: var(--bad); color: #fff; }
.btn.block { width: 100%; } .btn.sm { padding: 6px 10px; font-size: 13px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: linear-gradient(160deg, var(--brand), #101a52); }
.login-card { width: min(380px, 100%); text-align: center; }
.login-card label { text-align: left; }

/* scan */
.step-h { display: flex; align-items: center; gap: 8px; font-weight: 700; margin-bottom: 10px; }
.step-h .n { display: grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); font-size: 13px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.chip { padding: 8px 16px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface-2); font-weight: 600; cursor: pointer; }
.chip.on { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.seg { margin: 0; }
.designs { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; }
.designs.big { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.dcard { display: grid; gap: 2px; justify-items: start; text-align: left; padding: 8px; border-radius: 12px; border: 2px solid var(--line); background: var(--surface-2); cursor: pointer; }
.dcard img, .dcard .swatch { width: 100%; aspect-ratio: 4/3; object-fit: cover; border-radius: 8px; margin-bottom: 4px; }
.dcard .swatch { aspect-ratio: 5/2; }
.swatch { display: block; background: repeating-linear-gradient(45deg, var(--c), var(--c) 8px, color-mix(in srgb, var(--c) 70%, #fff) 8px, color-mix(in srgb, var(--c) 70%, #fff) 12px); }
.dcard b { font-size: 13.5px; line-height: 1.2; } .dcard small { font-size: 12px; color: var(--muted); }
.dcard.on { border-color: var(--brand); background: var(--brand-soft); }
.dcard.add { place-items: center; justify-items: center; border-style: dashed; color: var(--brand); }
.dcard .plus { font-size: 30px; line-height: 1; }
.camera { position: relative; display: grid; place-items: center; gap: 6px; min-height: 150px; border: 2px dashed var(--brand); border-radius: 14px; color: var(--brand);
  background: var(--brand-soft); font-weight: 700; cursor: pointer; overflow: hidden; margin: 0; }
.camera img { width: 100%; max-height: 340px; object-fit: contain; background: #000; }
.camera svg { width: 44px; height: 44px; }
.camera .spin { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(10, 16, 50, .6); color: #fff; font-size: 16px; }
.camera.busy .spin::before { content: ""; width: 34px; height: 34px; border: 3px solid rgba(255,255,255,.3); border-top-color: #fff; border-radius: 50%; animation: r 1s linear infinite; margin-bottom: 70px; position: absolute; }
@keyframes r { to { transform: rotate(360deg); } }
.note { padding: 10px 12px; border-radius: 10px; font-size: 13.5px; margin-top: 10px; }
.note.warn { background: var(--warn-bg); color: var(--warn); }
.pieces { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; margin-bottom: 10px; }
.piece { display: flex; align-items: center; gap: 4px; padding: 4px 6px 4px 8px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); }
.piece.unsure { border-color: var(--warn); background: var(--warn-bg); }
.piece .idx { font-size: 11px; color: var(--muted); min-width: 16px; }
.piece input { border: 0; background: transparent; padding: 6px 2px; font-weight: 700; font-size: 17px; font-variant-numeric: tabular-nums; min-width: 0; }
.piece .u { color: var(--muted); font-size: 13px; }
.piece .flag { color: var(--warn); font-weight: 800; }
.piece .x { border: 0; background: none; font-size: 20px; color: var(--muted); cursor: pointer; padding: 0 4px; }
.savebar { position: fixed; left: 0; right: 0; bottom: calc(58px + env(safe-area-inset-bottom)); z-index: 6; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; background: var(--surface); border-top: 1px solid var(--line); box-shadow: 0 -4px 16px rgba(0,0,0,.06); }
.savebar small { display: block; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 55vw; }
.savebar b { font-size: 22px; font-variant-numeric: tabular-nums; }

/* lists */
.list { display: grid; gap: 8px; }
.item { display: flex; justify-content: space-between; align-items: center; gap: 10px; text-align: left; width: 100%; cursor: pointer; font: inherit; }
.item small { display: block; color: var(--muted); font-size: 12.5px; }
.item .right { text-align: right; font-variant-numeric: tabular-nums; }
.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600; }
.pill.open { background: var(--warn-bg); color: var(--warn); } .pill.closed { background: var(--good-bg); color: var(--good); }
.pill.big { font-size: 13px; padding: 6px 12px; }
.empty { text-align: center; color: var(--muted); padding: 30px 0; }
.actions { gap: 8px; }

/* reports */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.kpi small { color: var(--muted); } .kpi b { display: block; font-size: 24px; font-variant-numeric: tabular-nums; }
.bars { display: flex; align-items: flex-end; gap: 4px; height: 150px; }
.bar { flex: 1; display: grid; grid-template-rows: 1fr auto; height: 100%; min-width: 0; }
.bar i { align-self: end; background: var(--brand); border-radius: 4px 4px 0 0; min-height: 2px; }
.bar span { font-size: 10.5px; color: var(--muted); text-align: center; }
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th, .tbl td { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: left; }
.tbl th { font-size: 12px; color: var(--muted); font-weight: 600; }
.num { text-align: right !important; font-variant-numeric: tabular-nums; }

/* modal + toast */
.modal { position: fixed; inset: 0; z-index: 20; display: grid; place-items: end center; background: rgba(0,0,0,.45); padding: 0; }
.modal-card { width: min(520px, 100%); max-height: 92vh; overflow: auto; background: var(--surface); border-radius: 18px 18px 0 0; padding: 18px 16px 24px; }
@media (min-width: 640px) { .modal { place-items: center; } .modal-card { border-radius: 18px; } }
.sprev { width: 100%; max-height: 220px; object-fit: contain; border-radius: 10px; margin-top: 8px; background: #000; }
#toast { position: fixed; left: 50%; top: 14px; transform: translate(-50%, -120%); z-index: 30; max-width: calc(100% - 32px); padding: 11px 16px; border-radius: 12px;
  background: #222; color: #fff; font-weight: 600; font-size: 14px; transition: transform .25s; box-shadow: 0 6px 20px rgba(0,0,0,.25); }
#toast.show { transform: translate(-50%, 0); } #toast.good { background: var(--good); } #toast.bad { background: var(--bad); }
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; }
.photos img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 10px; }

/* ---------- the slip (screen + print), styled after the paper slip ---------- */
.slip { background: #fff; color: var(--ink); border: 1.5px solid var(--ink); border-radius: 10px; padding: 14px; font-family: Georgia, "Times New Roman", serif; color-scheme: light; }
.slip-head { text-align: center; border: 1.5px solid var(--ink); border-radius: 10px; padding: 10px; }
.slip-head h1 { font-size: clamp(24px, 6vw, 36px); letter-spacing: .06em; margin: 0; }
.slip-head .tag { font-family: var(--font); font-weight: 700; font-size: 12px; letter-spacing: .08em; }
.slip-head .addr { font-family: var(--font); font-size: 11.5px; }
.slip-meta { display: flex; gap: 8px; margin: 8px 0; font-family: var(--font); font-size: 13px; }
.slip-meta .box { border: 1.5px solid var(--ink); border-radius: 10px; padding: 8px 10px; }
.slip-meta .muted { color: #6b74a8; }
.hand { color: var(--pen); font-family: "Segoe Print", "Bradley Hand", "Comic Sans MS", cursive; font-size: 1.15em; }
.slip-body { display: grid; grid-template-columns: 1fr minmax(150px, 30%); border: 1.5px solid var(--ink); border-radius: 10px; overflow: hidden; }
.cols { display: flex; flex-wrap: wrap; gap: 0; padding: 8px; align-content: start; border-right: 1.5px solid var(--ink); }
.proc { margin: 0 6px 10px 0; padding: 4px 6px; border: 1px dashed #9aa3d6; border-radius: 14px; }
.proc-h { font-family: "Segoe Print", "Bradley Hand", cursive; color: var(--pen); font-size: 17px; text-decoration: underline; margin: 0 4px 2px; }
.proc-cols { display: flex; flex-wrap: wrap; }
.col { min-width: 74px; padding: 0 6px; text-align: right; }
.col-h { font-family: "Segoe Print", "Bradley Hand", cursive; color: var(--pen); font-size: 13.5px; text-align: center; border-bottom: 1px solid var(--pen); margin-bottom: 2px; line-height: 1.15; min-height: 34px; }
.col-h small { font-size: 12px; }
.ms { column-gap: 12px; }
.m { break-inside: avoid; color: var(--pen); font-family: "Segoe Print", "Bradley Hand", cursive; font-size: 14px; line-height: 1.55; font-variant-numeric: tabular-nums; }
.m.tap { cursor: pointer; border-radius: 4px; } .m.tap:hover { background: #eef0fb; }
.sub { border-top: 1.5px solid var(--pen); margin-top: 2px; padding-top: 2px; font-weight: 700; color: var(--pen); font-size: 15px; }
.sub small { display: block; font-weight: 400; font-size: 11px; font-family: var(--font); color: #6b74a8; }
.summary { display: flex; flex-direction: column; font-family: var(--font); }
.sum-h { text-align: center; font-weight: 700; font-size: 12px; letter-spacing: .06em; padding: 6px; border-bottom: 1.5px solid var(--ink); }
.sum-r { display: flex; justify-content: space-between; gap: 6px; padding: 6px 8px; font-size: 12px; border-bottom: 1px dotted #b8bee0; }
.sum-r b { font-family: "Segoe Print", "Bradley Hand", cursive; color: var(--pen); font-size: 15px; white-space: nowrap; }
.sum-t { margin-top: auto; display: flex; justify-content: space-between; align-items: center; padding: 8px; border-top: 2px solid var(--ink); font-weight: 800; }
.sum-t small { display: block; font-weight: 400; font-size: 11px; }
.sum-t b { font-size: 19px; color: var(--pen); white-space: nowrap; }
.gst { font-family: var(--font); font-weight: 800; font-size: 16px; margin: 8px 4px; }
.slip-foot { border: 1.5px solid var(--ink); border-radius: 10px; padding: 8px 10px; font-family: var(--font); font-size: 11px; }
.signs { display: flex; justify-content: space-between; margin-top: 22px; font-weight: 600; font-size: 13px; }
@media (max-width: 560px) {
  .slip-body { grid-template-columns: 1fr; }
  .cols { border-right: 0; border-bottom: 1.5px solid var(--ink); }
}
@media print {
  @page { size: A5 portrait; margin: 8mm; }
  body { background: #fff; }
  .top, .tabs, .savebar, .noprint, #toast { display: none !important; }
  main { padding: 0; max-width: none; }
  .slip { border: 0; padding: 0; }
  .slip-body { grid-template-columns: 1fr 32%; }
  .cols { border-right: 1.5px solid var(--ink); border-bottom: 0; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
