:root {
  --navy: #0b2a4a;
  --navy-2: #14518a;
  --blue: #1677c8;
  --ice: #e6f2fa;
  --bg: #f2f6f9;
  --card: #fff;
  --line: #d9e3ec;
  --text: #10233a;
  --muted: #5d6f82;
  --green: #1a9a52;
  --green-bg: #e3f6eb;
  --red: #d23f3f;
  --red-bg: #fdeaea;
  --amber: #b7791f;
  --amber-bg: #fff4dd;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(11, 42, 74, .06), 0 4px 16px rgba(11, 42, 74, .06);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}
a { color: var(--blue); }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  min-height: 44px; padding: .6rem 1.1rem;
  border: 1px solid transparent; border-radius: 10px;
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
  background: #fff; color: var(--navy); border-color: var(--line);
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { border-color: #b8c8d7; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--blue); color: #fff; border-color: var(--blue); }
.btn.primary:hover { background: #1269b2; }
.btn.dark { background: var(--navy); color: #fff; border-color: var(--navy); }
.btn.danger { color: var(--red); }
.btn.danger:hover { border-color: var(--red); }
.btn.big { min-height: 56px; font-size: 1.1rem; width: 100%; border-radius: 12px; }
.btn.huge { min-height: 84px; font-size: 1.5rem; width: 100%; border-radius: 16px; }
.btn.sm { min-height: 36px; padding: .35rem .8rem; font-size: .9rem; }
.btn-link { background: none; border: 0; padding: .25rem; font: inherit; color: var(--blue); cursor: pointer; text-decoration: underline; }
.icon-btn { background: none; border: 0; font-size: 1.4rem; line-height: 1; padding: .4rem .6rem; cursor: pointer; color: var(--muted); border-radius: 8px; }
.icon-btn:hover { background: var(--bg); }

/* ---------- forms */
label { display: block; font-weight: 600; font-size: .9rem; color: var(--muted); }
input, textarea, select {
  display: block; width: 100%; margin-top: .3rem;
  font: inherit; color: var(--text);
  padding: .7rem .8rem; border: 1px solid var(--line); border-radius: 10px; background: #fff;
}
input:focus, textarea:focus { outline: 3px solid rgba(22, 119, 200, .25); border-color: var(--blue); }
.form { display: grid; gap: 1rem; }
.grid2 { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.error { color: var(--red); font-weight: 600; margin: 0; }

/* ---------- layout */
.topbar {
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  padding: .6rem 1rem; padding-top: max(.6rem, env(safe-area-inset-top));
  background: var(--navy); color: #fff;
}
.brand { display: flex; align-items: baseline; gap: .5rem; color: #fff; text-decoration: none; }
.brand-mark { font-weight: 800; font-size: 1.35rem; letter-spacing: .12em; }
.brand-sub { font-size: .85rem; color: #9fd0f0; letter-spacing: .05em; text-transform: uppercase; }
.topbar nav { display: flex; gap: .25rem; flex: 1; overflow-x: auto; }
.topbar nav a {
  color: #d4e6f5; text-decoration: none; padding: .45rem .75rem; border-radius: 8px; white-space: nowrap; font-weight: 600; font-size: .95rem;
}
.topbar nav a:hover { background: rgba(255, 255, 255, .08); }
.topbar nav a.active { background: rgba(255, 255, 255, .16); color: #fff; }
.topbar .who { color: #9fd0f0; font-size: .85rem; }
.topbar .btn-link { color: #fff; }
.spacer { flex: 1; }
@media (max-width: 640px) {
  .topbar nav { order: 3; flex-basis: 100%; }
}

.wrap { max-width: 980px; margin: 0 auto; padding: 1.25rem 1rem 4rem; }
.wrap.narrow { max-width: 560px; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.25rem; }
.split { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); align-items: start; }
.stack { display: grid; gap: 1rem; }
.page-head { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; margin-bottom: 1rem; }
.page-head h1 { flex: 1; }
.back { text-decoration: none; font-weight: 600; }
.row { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; }
.row > .btn { flex: 1 1 auto; }
.section-title { margin: 1.75rem 0 .75rem; display: flex; align-items: center; gap: .5rem; }
.loading { padding: 3rem; text-align: center; color: var(--muted); }

/* ---------- login */
.login { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 2rem 1rem; background: linear-gradient(180deg, #e6f2fa 0%, var(--bg) 60%); }
.login-logo { width: 220px; max-width: 70vw; height: auto; margin-bottom: 1.5rem; }
.login-card { width: 100%; max-width: 380px; display: grid; gap: 1rem; }
.lang-switch { margin-bottom: 1.25rem; }
.lang-switch button { padding: .45rem 1rem; }
.login-card h1 { font-size: 1.2rem; text-align: center; color: var(--muted); font-weight: 600; }

/* ---------- delivery info */
.label { font-size: .75rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.supplier { font-size: 1.5rem; font-weight: 700; }
.info { display: grid; gap: 1rem; }
.info-grid { display: flex; flex-wrap: wrap; gap: 1.25rem 2rem; }
.notes { background: var(--amber-bg); border-radius: 10px; padding: .6rem .8rem; white-space: pre-wrap; }
.chip { display: inline-block; padding: .15rem .6rem; margin: .2rem .3rem 0 0; border-radius: 999px; background: var(--ice); color: var(--navy); font-weight: 700; letter-spacing: .03em; }
.plate {
  display: inline-flex; align-items: stretch; margin-top: .25rem;
  border: 2px solid #1b1b1b; border-radius: 6px; background: #fff; overflow: hidden;
  font-weight: 800; font-size: 1.15rem; letter-spacing: .08em; color: #111;
}
.plate::before { content: ""; width: 10px; background: #1d4fa3; }
.plate span { padding: .1rem .55rem; }

/* ---------- progress */
.progress { text-align: center; padding: .5rem 0 1.25rem; }
.count { font-variant-numeric: tabular-nums; line-height: 1; }
.count .done { font-size: 4.5rem; font-weight: 800; color: var(--navy); }
.count .of { font-size: 2rem; font-weight: 700; color: var(--muted); margin-left: .25rem; }
.caption { color: var(--muted); font-weight: 600; margin-top: .25rem; }
.bar { height: 14px; background: var(--ice); border-radius: 999px; overflow: hidden; margin: 1rem 0 .5rem; }
.bar span { display: block; height: 100%; background: linear-gradient(90deg, var(--blue), #2bb3e6); border-radius: 999px; transition: width .4s; }
.bar.full span { background: var(--green); }
.qty { color: var(--muted); font-size: .95rem; }
.mini-progress { display: flex; align-items: center; gap: .75rem; }
.mini-progress .bar { flex: 1; margin: 0; height: 10px; }

/* ---------- home */
.home { display: grid; gap: 1rem; }
.empty { text-align: center; padding: 3rem 1.25rem; }
.empty .big-icon { font-size: 3rem; line-height: 1; margin-bottom: .75rem; }
.empty h2 { margin-bottom: .5rem; }
.banner { display: flex; gap: 1rem; align-items: center; padding: 1rem 1.25rem; border-radius: var(--radius); background: var(--green-bg); color: #10522d; }
.banner .grow { flex: 1; }
.banner strong { display: block; font-size: 1.1rem; }

/* ---------- dialog */
dialog {
  border: 0; border-radius: 18px; padding: 0; width: min(480px, calc(100vw - 1.5rem));
  box-shadow: 0 20px 60px rgba(0, 0, 0, .3); color: var(--text);
}
dialog::backdrop { background: rgba(11, 42, 74, .55); }
.dlg { padding: 1.25rem; display: grid; gap: .9rem; }
.dlg-head { display: flex; align-items: center; justify-content: space-between; }
.digits {
  font-size: 2.6rem; font-weight: 800; text-align: center; letter-spacing: .3em;
  padding: .6rem; font-variant-numeric: tabular-nums;
}
.digits::placeholder { color: #d3dee8; }
.result:empty { display: none; }
.res { border-radius: 12px; padding: 1rem; display: grid; gap: .35rem; }
.res-title { font-size: 1.35rem; font-weight: 800; }
.res.ok { background: var(--green-bg); color: #10522d; }
.res.bad { background: var(--red-bg); color: #8a1f1f; }
.res.warn { background: var(--amber-bg); color: #6b4510; }
.res.done { background: var(--green); color: #fff; text-align: center; padding: 1.5rem 1rem; }
.res.done .res-title { font-size: 1.8rem; }
.res .btn-link { justify-self: start; color: inherit; }
.choice {
  display: flex; justify-content: space-between; align-items: center; gap: .5rem; width: 100%;
  padding: .8rem 1rem; border: 2px solid var(--line); border-radius: 10px; background: #fff;
  font: inherit; text-align: left; cursor: pointer; color: var(--text);
}
.choice:hover:not(:disabled) { border-color: var(--blue); }
.choice:disabled { opacity: .55; cursor: default; }
.pno { font-variant-numeric: tabular-nums; font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; letter-spacing: .02em; }
.pno b { color: var(--blue); font-size: 1.08em; }

/* ---------- tables */
.table-wrap { overflow-x: auto; margin: 0 -1.25rem; padding: 0 1.25rem; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: .75rem; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); padding: .5rem .5rem; border-bottom: 2px solid var(--line); white-space: nowrap; }
td { padding: .55rem .5rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr.is-done td { background: #f4fbf7; }
td.right, th.right { text-align: right; }
.tick { display: inline-flex; width: 26px; height: 26px; border-radius: 50%; align-items: center; justify-content: center; border: 2px solid var(--line); color: transparent; font-weight: 800; font-size: .85rem; }
.tick.on { background: var(--green); border-color: var(--green); color: #fff; }
.when { display: block; font-size: .8rem; color: var(--green); }
.seg { display: inline-flex; background: var(--ice); border-radius: 10px; padding: 3px; }
.seg button { border: 0; background: none; font: inherit; font-weight: 600; padding: .45rem .9rem; border-radius: 8px; cursor: pointer; color: var(--navy); }
.seg button.on { background: #fff; box-shadow: var(--shadow); }

table.edit input { margin: 0; padding: .45rem .55rem; min-width: 70px; }
table.edit input.pallet { min-width: 190px; font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; }
table.edit input.qty { width: 90px; text-align: right; }
table.edit input[type=checkbox] { width: 22px; height: 22px; margin: 0 auto; }
.savebar { position: sticky; bottom: 0; display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; padding: .9rem 1.25rem; margin: 1rem -1.25rem -1.25rem; background: #fffbea; border-top: 1px solid #f1e2a8; border-radius: 0 0 var(--radius) var(--radius); }
.savebar .grow { flex: 1; font-weight: 600; }

/* ---------- lists */
.items { display: grid; gap: .75rem; }
.item { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; }
.item .grow { flex: 1 1 260px; min-width: 0; }
.item-title { font-weight: 700; font-size: 1.05rem; }
.item-meta { color: var(--muted); font-size: .9rem; display: flex; flex-wrap: wrap; gap: .25rem .9rem; margin-top: .2rem; }
.badge { display: inline-block; padding: .15rem .55rem; border-radius: 999px; font-size: .75rem; font-weight: 800; letter-spacing: .05em; text-transform: uppercase; background: var(--ice); color: var(--navy); vertical-align: middle; }
.badge.active { background: var(--blue); color: #fff; }
.badge.completed { background: var(--green-bg); color: #10522d; }
.badge.paused { background: var(--amber-bg); color: #6b4510; }

.notice { border-radius: 12px; padding: 1rem 1.1rem; background: var(--ice); }
.notice.warn { background: var(--amber-bg); }
.notice ul { margin: .5rem 0 0; padding-left: 1.2rem; }
.notice ul.checks { list-style: none; padding-left: 0; display: grid; gap: .3rem; }
.checks li { padding-left: 1.6rem; position: relative; }
.checks li::before { position: absolute; left: 0; font-weight: 800; }
.checks li.ok::before { content: "✓"; color: var(--green); }
.checks li.bad::before { content: "!"; color: var(--amber); left: .35rem; }
.rowtext {
  display: block; max-width: 340px; margin-top: .2rem; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
  font-size: .75rem; color: var(--muted); font-weight: 400; letter-spacing: 0;
}
.entry-row { display: flex; gap: .5rem; align-items: stretch; }
.entry-row .digits { margin: 0; flex: 1; min-width: 0; }
.kbd-btn { min-width: 64px; font-size: .9rem; }
.hint { margin: 0; }
.choice .grow { flex: 1; min-width: 0; }
.choice .rowtext { max-width: 100%; }
td .rowtext { width: 0; min-width: 100%; max-width: none; } /* fills the column without widening it */
td.nowrap { white-space: nowrap; }
@media (max-width: 480px) {
  .table-wrap { padding: 0 .25rem; }
  th, td { padding: .5rem .35rem; }
  td .pno { font-size: .95rem; }
}
.dlg, .res { grid-template-columns: minmax(0, 1fr); } /* long row text must not widen the dialog */

.file-drop {
  position: relative; display: grid; place-items: center; gap: .35rem; text-align: center; cursor: pointer;
  padding: 2rem 1rem; border: 2px dashed #a9c3da; border-radius: 14px; background: #f7fbfe; color: var(--navy);
}
.file-drop.over { border-color: var(--blue); background: var(--ice); }
.file-drop input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.file-drop b { font-size: 1.1rem; }
.file-name { font-weight: 700; color: var(--blue); word-break: break-all; }

/* ---------- offloading / loading */
.badge.t-offload { background: #e3eefb; color: #14518a; }
.badge.t-load { background: #dff4f2; color: #0b5f66; }
.btn.primary.load { background: #0e7c86; border-color: #0e7c86; }
.btn.primary.load:hover { background: #0b6a73; }
.type-switch { display: flex; width: 100%; }
.type-switch button { flex: 1; padding: .75rem .5rem; font-size: 1rem; }
.type-pick { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.type-opt { position: relative; display: block; cursor: pointer; color: var(--navy); }
.type-opt input { position: absolute; opacity: 0; pointer-events: none; }
.type-opt span { display: grid; gap: .15rem; height: 100%; padding: .9rem 1rem; border: 2px solid var(--line); border-radius: 12px; font-size: 1rem; }
.type-opt small { color: var(--muted); font-weight: 500; font-size: .8rem; }
.type-opt input:checked + span { border-color: var(--blue); background: var(--ice); }
.type-opt input[value="load"]:checked + span { border-color: #0e7c86; background: #dff4f2; }
.type-opt input:focus-visible + span { outline: 3px solid rgba(22, 119, 200, .3); }

/* ---------- inspection */
.excl {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: 1.35em; height: 1.35em; border-radius: 50%; background: var(--red); color: #fff;
  font-weight: 900; font-size: .9em; line-height: 1; vertical-align: -.2em;
}
.txt-bad { color: var(--red); font-weight: 700; }
.txt-ok { color: var(--green); font-weight: 700; }
.badge.bad { background: var(--red); color: #fff; }
.warnbar { background: var(--red-bg); color: #8a1f1f; padding: .6rem 1rem; text-align: center; font-size: .9rem; }
.warnbar a { color: inherit; font-weight: 700; }
.notice.bad { background: var(--red-bg); color: #8a1f1f; border: 2px solid var(--red); }
.alert-link { display: block; width: 100%; margin-bottom: 1rem; text-align: left; font: inherit; cursor: pointer; }
.insp-strip { background: var(--ice); border-radius: 12px; padding: .75rem 1rem; margin-bottom: 1rem; display: grid; gap: .25rem; text-align: left; }
.insp-count { font-weight: 700; }
.add-row { flex-wrap: nowrap; }
.add-row .btn { flex: 1 1 0; width: auto; min-width: 0; padding-left: .5rem; padding-right: .5rem; }
.insp-btn { background: var(--ice); color: var(--navy); border-color: #b9d8ee; }
.tag-insp {
  display: inline-flex; align-items: center; gap: .3rem; margin-top: .25rem; padding: .1rem .5rem;
  border-radius: 999px; background: var(--ice); color: var(--navy); font-size: .8rem; font-weight: 700;
  border: 0; font-family: inherit; cursor: pointer;
}
.res .tag-insp { justify-self: start; }
.insp-item.is-bad, .card.is-bad { border-left: 5px solid var(--red); }
.insp { border: 1px solid var(--line); border-radius: 12px; padding: 1rem; display: grid; gap: .6rem; }
.insp.is-bad { border: 2px solid var(--red); background: #fff8f8; }
.insp-head { display: flex; gap: .75rem; align-items: flex-start; flex-wrap: wrap; }
.insp-head .grow { flex: 1 1 220px; min-width: 0; }
.insp-facts { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.insp-facts .temp { font-weight: 800; font-size: 1.1rem; }
.insp-note { background: #fff; border-left: 4px solid var(--amber); padding: .5rem .75rem; border-radius: 6px; white-space: pre-wrap; }
.insp.is-bad .insp-note { border-left-color: var(--red); }
.thumbs { display: grid; gap: .5rem; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); }
.thumbs.mini { grid-template-columns: repeat(7, minmax(0, 1fr)); gap: .35rem; }
.thumb {
  position: relative; display: block; padding: 0; border: 1px solid var(--line); border-radius: 8px; overflow: hidden;
  background: var(--bg); cursor: pointer; aspect-ratio: 1; font: inherit; color: var(--muted);
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb span {
  position: absolute; left: 0; right: 0; bottom: 0; padding: .2rem .35rem; font-size: .7rem; font-weight: 700;
  background: rgba(11, 42, 74, .72); color: #fff; text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.thumb.missing { display: grid; place-items: center; cursor: default; border-style: dashed; }
.thumb.missing span { background: none; color: var(--muted); position: static; white-space: normal; text-align: center; }
.thumbs.mini .thumb.missing { cursor: pointer; }
.thumbs.mini .thumb.missing span { font-size: .9rem; }
.steps { display: flex; gap: .35rem; flex-wrap: wrap; }
.step {
  width: 2.3rem; height: 2.3rem; border-radius: 50%; border: 2px solid var(--line); background: #fff;
  font: inherit; font-weight: 800; color: var(--muted); cursor: pointer;
}
@media (max-width: 420px) {
  .steps { flex-wrap: nowrap; justify-content: space-between; gap: .2rem; }
  .step { width: 2rem; height: 2rem; flex: none; font-size: .9rem; }
}
.step.done { background: var(--green); border-color: var(--green); color: #fff; }
.step.on { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(22, 119, 200, .25); color: var(--navy); }
.step.done.on { color: #fff; }
.photo-box {
  position: relative; display: grid; place-items: center; min-height: 220px; max-height: 55vh; overflow: hidden;
  border-radius: 12px; background: var(--bg); border: 2px dashed #c5d5e3;
}
.photo-box img { width: 100%; max-height: 55vh; object-fit: contain; display: block; }
.photo-empty { font-size: 4rem; opacity: .35; }
.photo-busy { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(255, 255, 255, .85); font-weight: 800; font-size: 1.2rem; color: var(--navy); }
.photo-busy[hidden] { display: none; }
.gallery { justify-self: center; font-size: .9rem; }
.digits.temp { letter-spacing: .05em; }
.result-btns { flex-wrap: nowrap; }
.result-btns .btn { flex: 1 1 0; width: auto; min-width: 0; padding-left: .4rem; padding-right: .4rem; }
.ok-btn.on { background: var(--green); border-color: var(--green); color: #fff; }
.bad-btn.on { background: var(--red); border-color: var(--red); color: #fff; }
dialog.wide { width: min(900px, calc(100vw - 1.5rem)); }
.photo-full { width: 100%; max-height: 70vh; object-fit: contain; border-radius: 8px; background: var(--bg); }

#toast {
  position: fixed; left: 50%; bottom: 1.25rem; transform: translate(-50%, 150%);
  background: var(--navy); color: #fff; padding: .75rem 1.1rem; border-radius: 10px; font-weight: 600;
  box-shadow: var(--shadow); transition: transform .25s, opacity .25s; z-index: 50; max-width: calc(100vw - 2rem);
  opacity: 0; pointer-events: none;
}
#toast.show { transform: translate(-50%, 0); opacity: 1; }
#toast.bad { background: var(--red); }
