:root {
  --paper: #edf0f3;
  --panel: #ffffff;
  --ink: #17222e;
  --ink-soft: #4d5b6a;
  --line: #c9d1da;
  --go: #1d7348;
  --go-tint: #e3f1e9;
  --stop: #a8231b;
  --stop-tint: #f8e4e2;
  --tag: #f3c53c;
  --focus: #2c6bd6;
  --font: "Atkinson Hyperlegible", system-ui, sans-serif;
  --mono: "Atkinson Hyperlegible Mono", ui-monospace, Menlo, monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 1.0625rem/1.5 var(--font);
}

main { max-width: 860px; margin: 0 auto; padding: 32px 16px 64px; }

h1, h2 { line-height: 1.2; margin: 0; }
h1 { font-size: 2rem; }
h2 { font-size: 1.375rem; }
a { color: var(--ink); }

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

/* Top bar */
.topbar {
  display: flex; align-items: center; gap: 24px;
  padding: 12px 16px;
  background: var(--ink); color: #fff;
}
.topbar a { color: #fff; text-decoration: none; }
.brand { font-weight: 700; font-size: 1.125rem; }
.topbar nav { display: flex; gap: 4px; }
.topbar nav a { padding: 6px 12px; border-radius: 6px; opacity: .8; }
.topbar nav a:hover { opacity: 1; }
.topbar nav a[aria-current="page"] { background: rgba(255,255,255,.14); opacity: 1; }
.who { margin-left: auto; display: flex; gap: 12px; align-items: center; font-size: .9375rem; }
.link { background: none; border: 0; color: #fff; font: inherit; text-decoration: underline; cursor: pointer; padding: 0; }

.dryrun {
  margin: 0; padding: 8px 16px; text-align: center;
  background: var(--tag); color: var(--ink); font-weight: 700; font-size: .9375rem;
}

/* Buttons */
.btn {
  font: 700 1.0625rem/1 var(--font);
  padding: 14px 22px; border-radius: 8px; border: 2px solid transparent;
  cursor: pointer;
}
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-go { background: var(--go); color: #fff; }
.btn-stop { background: var(--stop); color: #fff; }
.btn-ink { background: var(--ink); color: #fff; }
.btn-quiet { background: transparent; border-color: var(--line); color: var(--ink); padding: 10px 16px; font-size: .9375rem; }
.btn-quiet:hover { border-color: var(--ink-soft); }
.btn-go:not(:disabled):hover { background: #165c39; }
.btn-stop:not(:disabled):hover { background: #8a1b14; }

/* Inputs */
input, textarea {
  font: inherit; color: var(--ink);
  width: 100%;
  padding: 10px 12px;
  border: 2px solid var(--line); border-radius: 8px; background: #fff;
}
input:focus, textarea:focus { border-color: var(--focus); outline: none; }
label { display: grid; gap: 6px; font-weight: 700; }

/* Login */
.login { max-width: 380px; margin: 10vh auto 0; }
.lede { color: var(--ink-soft); margin: 8px 0 24px; }
.stack { display: grid; gap: 16px; }
.error { color: var(--stop); margin: 0; font-weight: 700; }

/* Intake */
.intake-label { font-size: 1.25rem; margin-bottom: 10px; }
#codes {
  font: 400 1rem/1.7 var(--mono);
  letter-spacing: .02em;
  resize: vertical; min-height: 9rem;
}
.counter { margin: 8px 0 20px; color: var(--ink-soft); font-size: .9375rem; }
.counter.warn, .summary.warn { color: var(--stop); font-weight: 700; }
.actions { display: flex; gap: 12px; flex-wrap: wrap; }
.hint { color: var(--ink-soft); font-size: .9375rem; max-width: 62ch; margin: 16px 0 0; }

/* Results: each lock reads like its printed label */
.results { margin-top: 48px; }
.results-head { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; }
.summary { margin: 6px 0 16px; }
.tags { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.tag {
  display: grid;
  grid-template-columns: 2rem auto 1fr;
  grid-template-areas: "mark uid action" "mark msg msg" "mark status status";
  column-gap: 14px; row-gap: 2px;
  padding: 12px 16px;
  background: var(--panel);
  border: 2px solid var(--line); border-left-width: 8px;
  border-radius: 6px;
}
.tag-mark {
  grid-area: mark; align-self: center;
  width: 2rem; height: 2rem; border-radius: 50%;
  display: grid; place-items: center;
  font-weight: 700; font-size: 1.125rem; color: #fff; background: var(--line);
}
.tag-uid { grid-area: uid; font: 600 1.125rem/1.3 var(--mono); letter-spacing: .04em; }
.tag-action { grid-area: action; justify-self: end; color: var(--ink-soft); font-size: .875rem; }
.tag-msg { grid-area: msg; }
.tag-status { grid-area: status; color: var(--ink-soft); font-size: .875rem; }
.tag-status:empty { display: none; }
.tag.pending .tag-msg { color: var(--ink-soft); }
.tag.pending .tag-mark { animation: pulse 1s ease-in-out infinite; }
.tag.ok { border-color: var(--go); background: var(--go-tint); }
.tag.ok .tag-mark { background: var(--go); }
.tag.bad { border-color: var(--stop); background: var(--stop-tint); }
.tag.bad .tag-mark { background: var(--stop); }
.tag.skipped { border-color: var(--ink-soft); }
.tag.skipped .tag-mark { background: var(--ink-soft); }
@keyframes pulse { 50% { opacity: .35; } }

/* RMA confirm: a repair tag */
.confirm {
  max-width: 480px; width: calc(100% - 32px);
  border: 0; border-top: 14px solid var(--tag);
  border-radius: 8px; padding: 24px;
  color: var(--ink);
}
.confirm::backdrop { background: rgba(23, 34, 46, .6); }
.confirm form { display: grid; gap: 14px; }
.confirm p { margin: 0; }
.tagline {
  justify-self: start; background: var(--tag); color: var(--ink);
  font-weight: 700; padding: 2px 10px; border-radius: 4px; font-size: .875rem;
}
.uid-list {
  margin: 0; padding: 10px 14px; list-style: none;
  max-height: 10rem; overflow: auto;
  background: var(--paper); border-radius: 6px;
  font: 600 1rem/1.7 var(--mono); letter-spacing: .04em;
}
.uid-list:empty { display: none; }
.confirm .actions { justify-content: flex-end; }

/* History */
.history .results-head { margin-bottom: 20px; }
.search { display: flex; gap: 8px; align-items: center; }
.search input { width: 16rem; padding: 8px 10px; }
.table-wrap { overflow-x: auto; background: var(--panel); border: 2px solid var(--line); border-radius: 8px; }
table { border-collapse: collapse; width: 100%; font-size: .9375rem; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-weight: 700; background: var(--paper); }
tbody tr:last-child td { border-bottom: 0; }
.mono { font-family: var(--mono); letter-spacing: .03em; }
.nowrap { white-space: nowrap; }
td.ok { color: var(--go); }
td.bad { color: var(--stop); }
.pill { padding: 2px 8px; border-radius: 4px; font-weight: 700; font-size: .8125rem; white-space: nowrap; }
.pill-activate { background: var(--go-tint); color: var(--go); }
.pill-rma { background: var(--stop-tint); color: var(--stop); }
.empty { color: var(--ink-soft); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

@media (max-width: 600px) {
  .topbar { flex-wrap: wrap; gap: 12px; }
  .who { margin-left: 0; width: 100%; justify-content: space-between; }
  .actions .btn { flex: 1; }
  .tag-uid { font-size: 1rem; }
  .search { width: 100%; }
  .search input { flex: 1; width: auto; }

  /* History rows become stacked cards so the result stays visible */
  .table-wrap { background: none; border: 0; }
  table, tbody, tr, td { display: block; }
  thead { display: none; }
  tbody { display: grid; gap: 8px; }
  tr { background: var(--panel); border: 2px solid var(--line); border-radius: 6px; padding: 10px 12px; }
  td { border: 0; padding: 2px 0; display: grid; grid-template-columns: 7rem minmax(0, 1fr); gap: 8px; white-space: normal; }
  td > .pill { justify-self: start; }
  td.nowrap { white-space: normal; }
  .table-wrap { overflow: visible; }
  td::before { content: attr(data-label); color: var(--ink-soft); font-family: var(--font); letter-spacing: 0; }
  td:empty { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .tag.pending .tag-mark { animation: none; }
}
