/*
 * Handheld-first. This is used standing up, one-handed, in a warehouse:
 * big targets, high contrast, nothing that needs a precise tap. The layout is
 * built for a ~360px phone/scanner screen and simply centres on anything wider.
 */

:root {
  --bg: #12151a;
  --card: #1c212a;
  --line: #2f3742;
  --fg: #eef2f7;
  --muted: #9aa7b6;
  --accent: #3b82f6;
  --ok: #34d399;
  --bad: #f87171;
  --warn: #fbbf24;
  --tap: 56px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 17px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 5;
}

h1 {
  font-size: 19px;
  margin: 0;
  letter-spacing: 0.01em;
}

h2 {
  font-size: 16px;
  margin: 24px 0 8px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

main,
#gate {
  max-width: 560px;
  margin: 0 auto;
  padding: 16px 16px 48px;
}

.lede {
  font-size: 18px;
  margin: 8px 0 24px;
}

.muted {
  color: var(--muted);
}

/* --- buttons ------------------------------------------------------------ */

.big-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: 100%;
  min-height: 72px;
  margin: 8px 0;
  padding: 16px;
  border: 0;
  border-radius: 14px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-size: 20px;
  font-weight: 600;
  cursor: pointer;
}

.big-button:disabled {
  background: var(--line);
  color: var(--muted);
  cursor: default;
}

.big-button-icon {
  font-size: 26px;
}

.secondary-button {
  width: 100%;
  min-height: var(--tap);
  margin: 4px 0 8px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: transparent;
  color: var(--fg);
  font: inherit;
  cursor: pointer;
}

.link-button {
  display: block;
  width: 100%;
  min-height: var(--tap);
  margin: 12px 0;
  border: 0;
  background: none;
  color: var(--accent);
  font: inherit;
  text-decoration: underline;
  cursor: pointer;
}

/* --- inputs ------------------------------------------------------------- */

input[type="text"],
input[type="number"],
select {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  color: var(--fg);
  /* 17px minimum stops mobile Safari/Chrome zooming the page on focus. */
  font: inherit;
  font-size: 17px;
}

label {
  display: block;
  color: var(--muted);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

label input,
label select {
  margin-top: 4px;
  color: var(--fg);
  font-size: 17px;
  text-transform: none;
  letter-spacing: normal;
}

.field-row {
  display: flex;
  gap: 12px;
}

.field-row label {
  flex: 1;
}

.printer-row {
  margin: 20px 0 8px;
}

/* --- cards, meta -------------------------------------------------------- */

.card {
  margin: 12px 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
}

.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 18px;
  font-size: 15px;
}

.meta .k {
  display: block;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

.note {
  margin: 10px 0 0;
  color: var(--warn);
  font-size: 14px;
}

/* --- label rows --------------------------------------------------------- */

.label-row {
  margin: 10px 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--ok);
  border-radius: 12px;
  background: var(--card);
}

.label-row.unresolved {
  border-left-color: var(--bad);
}

.label-main {
  display: flex;
  align-items: center;
  gap: 12px;
}

.label-main .r-size {
  width: 110px;
  flex: 0 0 auto;
  text-transform: uppercase;
}

.r-upc {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 17px;
  letter-spacing: 0.02em;
  word-break: break-all;
}

.r-upc em {
  color: var(--bad);
  font-family: inherit;
  font-style: normal;
}

.label-sub {
  display: flex;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 10px;
}

.qty {
  flex: 0 0 auto;
}

.qty input {
  width: 72px;
}

/*
 * `flex-wrap` above plus `margin-left: auto` here: on a wide screen the toggle
 * sits out to the right, and on a 360px handheld it drops to its own line
 * rather than being clipped by `overflow: hidden` — which reads as a layout
 * that fits while the word "print" is off the edge.
 */
.print-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  padding-bottom: 12px;
  font-size: 14px;
  white-space: nowrap;
}

.print-toggle input {
  width: 26px;
  height: 26px;
  min-height: 0;
  margin: 0;
}

.row-problem {
  margin: 10px 0 0;
  color: var(--bad);
  font-size: 14px;
}

.row-note {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 13px;
}

/* --- status ------------------------------------------------------------- */

.error,
.warn {
  margin: 12px 0;
  padding: 12px;
  border-radius: 10px;
  font-size: 15px;
}

.error {
  border: 1px solid var(--bad);
  color: var(--bad);
}

.warn {
  border: 1px solid var(--warn);
  color: var(--warn);
}

.ok {
  color: var(--ok);
}

.bad {
  color: var(--bad);
}

.results {
  margin: 12px 0 0;
  padding-left: 20px;
  font-size: 15px;
}

.results li {
  margin: 6px 0;
}

/* --- working ------------------------------------------------------------ */

#step-working {
  padding-top: 48px;
  text-align: center;
}

.spinner {
  width: 46px;
  height: 46px;
  margin: 0 auto 20px;
  border: 4px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .spinner {
    animation-duration: 3s;
  }
}

#preview {
  max-width: 100%;
  margin-top: 24px;
  border: 1px solid var(--line);
  border-radius: 12px;
}

#verify-result {
  margin-top: 12px;
  font-size: 16px;
}

/* ---------------------------------------------------------------------------
 * The scan log (public/log.html), and the two diagnostics it made worth
 * showing on the scanning page itself.
 *
 * Wider than the rest of the app on purpose: this is the one surface that gets
 * read on a desktop, because it is what you sit down with after scanning a
 * stack of cartons. It still has to work at 360px, so every table scrolls
 * rather than squeezing.
 * ------------------------------------------------------------------------ */

.header-right {
  display: flex;
  align-items: center;
  gap: 14px;
}

.log-link {
  color: var(--accent);
  text-decoration: none;
  font-size: 15px;
  white-space: nowrap;
}

.log-page main {
  max-width: 900px;
}

/* Near-miss styles, offered as taps on the review screen. */
.candidates {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.candidate {
  background: var(--card);
  color: var(--fg);
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 10px 14px;
  font: inherit;
  font-size: 15px;
  min-height: 44px;
}

/* "We matched this loosely" — deliberately amber, not silent and not red: the
 * label will still print, and the operator is the one deciding whether the
 * assumption is right. */
.assumed {
  background: rgba(251, 191, 36, 0.12);
  border-left: 3px solid var(--warn);
  color: var(--warn);
  padding: 10px 12px;
  border-radius: 6px;
  margin: 8px 0;
  font-size: 15px;
}

.summary-table {
  width: 100%;
  border-collapse: collapse;
  margin: 8px 0;
}

.summary-table tr {
  cursor: pointer;
  border-bottom: 1px solid var(--line);
}

.summary-table tr:hover {
  background: rgba(59, 130, 246, 0.08);
}

.summary-table tr.selected {
  background: rgba(59, 130, 246, 0.18);
}

.summary-table td {
  padding: 9px 8px;
  vertical-align: baseline;
}

.summary-table .n {
  font-weight: 700;
  font-size: 19px;
  text-align: right;
  width: 3.5em;
}

.summary-table .pct {
  color: var(--muted);
  width: 4em;
}

.summary-table .ok-row .n {
  color: var(--ok);
}

.log-tools {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin: 16px 0 8px;
}

.log-tools input {
  flex: 1 1 180px;
  min-height: 44px;
  background: var(--card);
  color: var(--fg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  font: inherit;
}

.scan-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  margin-bottom: 8px;
  overflow: hidden;
}

.scan-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  cursor: pointer;
  flex-wrap: wrap;
  min-height: 52px;
}

.badge {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid currentColor;
}

.badge.ok {
  color: var(--ok);
}
.badge.bad {
  color: var(--bad);
}
.badge.warn-badge {
  color: var(--warn);
}

.scan-style {
  font-weight: 600;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.scan-color,
.scan-counts {
  color: var(--muted);
  font-size: 14px;
}

.scan-when {
  color: var(--muted);
  font-size: 13px;
  margin-left: auto;
}

.scan-body {
  padding: 0 12px 14px;
  border-top: 1px solid var(--line);
}

.kv {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 4px 14px;
  margin: 12px 0;
  font-size: 15px;
}

.kv dt {
  color: var(--muted);
}

.kv dd {
  margin: 0;
}

.size-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  margin: 10px 0;
}

.size-table th {
  text-align: left;
  color: var(--muted);
  font-weight: 500;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.size-table th,
.size-table td {
  padding: 6px 8px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

.size-table .bad-row td {
  color: var(--bad);
}

.scan-photo {
  display: block;
  width: 100%;
  max-width: 520px;
  border-radius: 8px;
  margin-top: 10px;
}

/* `.link-button` is full-width block by design — it is a bottom-of-screen
 * action everywhere else in the app. In the log toolbar it is one of three
 * controls on a row, so narrow it back down here rather than weakening the
 * shared rule. */
.log-tools .link-button {
  display: inline-block;
  width: auto;
  margin: 0;
  white-space: nowrap;
}
