:root {
  --bg: #e7ebee;
  --panel: #ffffff;
  --ink: #18222d;
  --muted: #5e6b78;
  --line: #cbd3da;
  --accent: #1e4e8c;
  --accent-hover: #173e70;
  --accent-ink: #ffffff;
  --liner: #e8d7a4;
  --liner-edge: #d6c085;
  --error-bg: #fbe9e7;
  --error-ink: #9b2c1f;
  --ok: #2d6a3e;
  --radius: 10px;
  --ui: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: "DejaVu Sans Mono", "Cascadia Mono", Consolas, "Liberation Mono", Menlo, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12171d;
    --panel: #1a2129;
    --ink: #e4e9ee;
    --muted: #95a2af;
    --line: #2c3640;
    --accent: #6fa1e0;
    --accent-hover: #8db5e8;
    --accent-ink: #0d1520;
    --liner: #4a4232;
    --liner-edge: #5b513c;
    --error-bg: #3a1f1b;
    --error-ink: #f2b3a8;
    --ok: #7cc690;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 var(--ui);
}
h1, h2 { line-height: 1.2; margin: 0; }
h1 { font-size: 1.25rem; font-weight: 650; }
h2 { font-size: 1rem; font-weight: 650; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); }

label { display: block; font-size: .875rem; font-weight: 550; margin: 14px 0 6px; }
input, textarea, select {
  width: 100%;
  font: inherit;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 11px;
}
select { appearance: auto; }
textarea { font-family: var(--mono); min-height: 140px; resize: vertical; }
input:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible, summary:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}
.hint { font-size: .8125rem; color: var(--muted); margin: 6px 0 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: inherit; font-weight: 600;
  border: 1px solid var(--line);
  background: var(--panel); color: var(--ink);
  border-radius: 8px; padding: 10px 16px; cursor: pointer;
  text-decoration: none;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.wide { width: 100%; margin-top: 20px; padding: 12px 16px; }
.btn[disabled] { opacity: .55; cursor: progress; }

.error { background: var(--error-bg); color: var(--error-ink); padding: 10px 12px; border-radius: 8px; font-size: .9rem; }

/* sign-in page */
body.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card {
  width: 100%; max-width: 380px;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 32px 28px;
}
.auth-card h1 { margin-bottom: 6px; }
.auth-card p { margin: 0 0 8px; }
.auth-mark {
  width: 56px; height: 56px; margin-bottom: 20px;
  background: var(--liner); border-radius: 6px; padding: 7px;
}
.auth-mark span {
  display: block; width: 100%; height: 100%; background: #fff; border-radius: 3px;
  background-image:
    linear-gradient(#18222d,#18222d), linear-gradient(#18222d,#18222d),
    linear-gradient(#18222d,#18222d), linear-gradient(#18222d,#18222d);
  background-size: 12px 12px, 12px 12px, 12px 12px, 16px 3px;
  background-position: 7px 6px, 23px 6px, 7px 21px, 12px 36px;
  background-repeat: no-repeat;
}

/* main app */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 24px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.topbar a { color: var(--muted); font-size: .9rem; }
.layout {
  display: grid;
  grid-template-columns: minmax(300px, 380px) 1fr;
  gap: 24px; padding: 24px; max-width: 1200px; margin: 0 auto;
}
@media (max-width: 860px) { .layout { grid-template-columns: 1fr; padding: 16px; } }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.panel + .panel { margin-top: 16px; }

.switch { display: grid; grid-template-columns: 1fr 1fr; background: var(--bg); border-radius: 8px; padding: 4px; gap: 4px; }
.switch button {
  font: inherit; font-size: .9rem; font-weight: 600; border: 0; border-radius: 6px;
  padding: 8px; background: transparent; color: var(--muted); cursor: pointer;
}
.switch button[aria-pressed="true"] { background: var(--panel); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.12); }

.link-label { margin: 18px 0 4px; font-size: .875rem; font-weight: 550; }
.link { display: block; font-size: .8rem; color: var(--accent); word-break: break-all; }
.range { margin: 14px 0 0; font-size: .9rem; }
.range .mono { font-weight: 600; }
.status { margin: 12px 0 0; font-size: .875rem; min-height: 1.3em; }
.status.ok { color: var(--ok); }
.status.bad { color: var(--error-ink); }

details summary { cursor: pointer; font-weight: 650; }
details[open] summary { margin-bottom: 4px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.log { width: 100%; border-collapse: collapse; font-size: .85rem; margin-top: 10px; }
.log td { padding: 6px 0; border-top: 1px solid var(--line); }
.log td:last-child { text-align: right; color: var(--muted); white-space: nowrap; padding-left: 12px; }
.log td:first-child { word-break: break-all; }
.log-foot { margin-top: 12px; font-size: .875rem; }
.log-foot a { color: var(--accent); }

/* preview: the label sits on its backing liner, like on the roll */
.stage {
  position: sticky; top: 24px; align-self: start;
  background: var(--liner);
  border-left: 10px solid var(--liner-edge);
  border-right: 10px solid var(--liner-edge);
  border-radius: 4px;
  padding: 36px 20px 20px;
  display: flex; flex-direction: column; align-items: center;
}
.stage .frame { position: relative; }
.stage .frame .label {
  position: absolute; top: 0; left: 0; transform-origin: 0 0;
  box-shadow: 0 1px 2px rgba(0,0,0,.18), 0 6px 18px rgba(0,0,0,.12);
  border-radius: .08in;
}
.stage figcaption { margin-top: 16px; font-size: .85rem; color: var(--ink); opacity: .75; }

/* the label itself, in real inches */
.label {
  width: 4in; height: 4in;
  background: #fff; color: #000;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: .3in; gap: .16in;
  overflow: hidden;
  -webkit-print-color-adjust: exact; print-color-adjust: exact;
}
.label .qr { width: 2.85in; height: 2.85in; flex: none; }
.label .qr svg { width: 100%; height: 100%; display: block; shape-rendering: crispEdges; }
.label .sn {
  font-family: "Helvetica Neue", Arial, "Liberation Sans", sans-serif;
  font-weight: 700; color: #000;
  white-space: nowrap; line-height: 1; letter-spacing: .03em;
}
.label .empty { color: #8a949e; font: 600 .2in/1.3 var(--ui); text-align: center; }

#sheet { display: none; }

@page { size: 4in 4in; margin: 0; }
@media print {
  html, body { background: #fff !important; margin: 0 !important; padding: 0 !important; }
  .app { display: none !important; }
  #sheet { display: block !important; }
  #sheet .label { break-after: page; page-break-after: always; border-radius: 0; }
  #sheet .label:last-child { break-after: auto; page-break-after: auto; }
}
@media (prefers-reduced-motion: no-preference) {
  .btn, .switch button { transition: background-color .15s, border-color .15s; }
}
