:root {
  color-scheme: light;
  --bg: #f5f5f7;
  --card: #ffffff;
  --ink: #1c1c1e;
  --muted: #6e6e73;
  --line: rgba(28, 28, 30, 0.08);
  --line-strong: rgba(28, 28, 30, 0.14);
  --blue: #0a66c2;
  --focus: #0a66c2;
  --fill: #1c1c1e;
  --fill-hover: #000000;
  --quiet: #ffffff;
  --ok: #166534;
  --ok-bg: #f0fdf4;
  --ok-line: #bbf7d0;
  --warn: #92400e;
  --warn-bg: #fffbeb;
  --warn-line: #fde68a;
  --bad: #991b1b;
  --bad-bg: #fef2f2;
  --bad-line: #fecaca;
  --shadow: 0 1px 2px rgba(28, 28, 30, 0.04);
  --radius: 16px;
  --pad: 20px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
}

* { box-sizing: border-box; }
html, body { margin: 0; max-width: 100%; }
html { overflow-x: clip; }
body {
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  overflow-wrap: break-word;
  -webkit-font-smoothing: antialiased;
}
img, video, canvas, svg { max-width: 100%; }
button, input { font: inherit; }
a { color: var(--blue); }
::selection { background: #dbeafe; }

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

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

main {
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: 28px var(--pad) 56px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 44px;
  margin-bottom: 16px;
}
h1 {
  margin: 0;
  min-width: 0;
  font-size: clamp(26px, 4vw, 34px);
  font-weight: 700;
  letter-spacing: -0.035em;
  line-height: 1.1;
}
h2 {
  margin: 0 0 10px;
  font-size: 15px;
  font-weight: 650;
  letter-spacing: -0.01em;
}
.intro, #status, .muted { color: var(--muted); }
.intro { margin: 0 0 18px; max-width: 40rem; font-size: 15px; line-height: 1.45; }
#status {
  margin: 0 0 14px;
  font-size: 13px;
  line-height: 1.45;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px;
  width: min(280px, 100%);
  padding: 4px;
  margin: 0 0 20px;
  background: #e8e8ed;
  border-radius: 14px;
}
.tabs a {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 8px 6px;
  border-radius: 10px;
  color: var(--ink);
  text-decoration: none;
  font-weight: 650;
  font-size: 14px;
  text-align: center;
}
.tabs a.current { background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06); }
.tabs a:hover { color: var(--ink); }

.share-link {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: -6px 0 16px;
  color: var(--muted);
  font-size: 14px;
}
.share-actions { display: flex; gap: 8px; align-items: center; }
.quiet-link, .share-actions button {
  min-height: 36px;
  padding: 6px 12px;
  border-radius: 12px;
  font-size: 14px;
}
.quiet-link {
  display: inline-flex;
  align-items: center;
  background: var(--quiet);
  color: var(--ink);
  text-decoration: none;
  font-weight: 650;
  box-shadow: inset 0 0 0 1px var(--line-strong);
}
.quiet-link:hover { background: #f3f3f5; color: var(--ink); }

.signout, button.text {
  border: 0;
  background: transparent;
  color: var(--blue);
  font-weight: 650;
  font-size: 15px;
  cursor: pointer;
  min-height: 44px;
  padding: 10px 2px;
}
.signout:hover, .signout:active, button.text:hover, button.text:active { background: transparent; color: #004e98; }

button, .add-btn {
  border: 0;
  border-radius: 12px;
  min-height: 44px;
  padding: 10px 16px;
  background: var(--fill);
  color: #fff;
  font-weight: 650;
  font-size: 15px;
  line-height: 1.2;
  cursor: pointer;
  touch-action: manipulation;
}
button:hover, .add-btn:hover { background: var(--fill-hover); }
button:active, .add-btn:active { background: #000; }
button.quiet {
  background: var(--quiet);
  color: var(--ink);
  box-shadow: inset 0 0 0 1px var(--line-strong);
}
button.quiet:hover, button.quiet:active { background: #f3f3f5; }
button:disabled {
  background: #d2d2d7;
  color: #fff;
  box-shadow: none;
  cursor: default;
}
button.quiet:disabled { color: #8e8e93; background: #f3f3f5; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}
.toolbar > button { flex: 0 1 auto; }
.switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  margin-left: auto;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
}
.switch input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  margin: 0;
}
.track {
  width: 51px;
  height: 31px;
  border-radius: 16px;
  background: #e9e9eb;
  position: relative;
  flex: 0 0 auto;
}
.track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 27px;
  height: 27px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.22);
  transition: transform 0.2s ease;
}
.switch input:checked + .track { background: #34c759; }
.switch input:checked + .track::after { transform: translateX(20px); }
.switch input:focus-visible + .track {
  outline: 2px solid var(--focus);
  outline-offset: 3px;
}
.switch input:focus-visible { outline: none; }

.counts {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 0 0 14px;
}
.count-card, .panel, .table-wrap, .card, .preview {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.count-card { padding: 14px 14px 12px; min-width: 0; }
.count-card span {
  display: block;
  min-height: 2.4em;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.25;
}
.count-card strong {
  display: block;
  margin-top: 4px;
  font-size: clamp(26px, 4vw, 34px);
  font-weight: 700;
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.table-wrap { overflow: auto; max-width: 100%; }
table { width: 100%; border-collapse: collapse; }
th, td {
  padding: 12px 14px;
  text-align: left;
  vertical-align: middle;
  border-bottom: 1px solid var(--line);
  overflow-wrap: anywhere;
}
th {
  font-size: 12px;
  font-weight: 650;
  letter-spacing: 0.02em;
  color: var(--muted);
  background: #fafafa;
}
tr:last-child td { border-bottom: 0; }
td img, .table-wrap img {
  width: 44px;
  height: 44px;
  object-fit: cover;
  border-radius: 10px;
  background: var(--bg);
  display: block;
}
.empty { padding: 28px 16px; color: var(--muted); text-align: center; }
.pager {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  margin-top: 16px;
}
.pager button { min-width: 0; flex: 0 1 148px; }
.pager span {
  color: var(--muted);
  min-width: 64px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  font-size: 14px;
}

#toast {
  position: fixed;
  left: 50%;
  right: auto;
  bottom: 24px;
  width: max-content;
  max-width: calc(100% - 32px);
  transform: translateX(-50%);
  background: rgba(28, 28, 30, 0.92);
  color: #fff;
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.35;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  z-index: 30;
  transition: opacity 0.2s ease;
}
#toast.show { opacity: 1; }

.card { padding: 16px; margin-bottom: 12px; min-width: 0; }
.scan-title { margin: 0 0 4px; }
.scan-help { margin: 0 0 12px; color: var(--muted); font-size: 14px; line-height: 1.4; }
#reader {
  width: 100%;
  border-radius: 12px;
  overflow: hidden;
  background: #111;
  min-height: 180px;
  max-height: 320px;
}
#reader video, #reader img, #reader canvas {
  width: 100% !important;
  max-width: 100% !important;
  max-height: 320px !important;
  object-fit: cover;
}
#reader__dashboard, #reader__scan_region { max-width: 100% !important; }
#camera-note { margin: 10px 0 0; min-height: 0; font-size: 14px; line-height: 1.4; }
#camera-note:empty { display: none; margin: 0; }
.mode-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  margin: 0 0 12px;
  background: #e8e8ed;
  border-radius: 14px;
}
.mode-switch button {
  min-height: 40px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--ink);
  font-weight: 650;
  font-size: 14px;
  box-shadow: none;
}
.mode-switch button[aria-selected="true"] {
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}
.mode-switch button:hover,
.mode-switch button:active {
  background: transparent;
  color: var(--ink);
}
.mode-switch button[aria-selected="true"]:hover,
.mode-switch button[aria-selected="true"]:active {
  background: #fff;
  color: var(--ink);
}
form#manual, .add { display: flex; gap: 8px; align-items: center; margin-top: 12px; }
form#manual input, .add input, .login-card input {
  flex: 1;
  min-width: 0;
  width: 100%;
  min-height: 44px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: #f2f2f4;
  padding: 12px 14px;
  color: var(--ink);
  font-size: 16px;
}
.login-card input:focus, form#manual input:focus {
  background: #fff;
  border-color: var(--ink);
}
form#manual button { flex: 0 0 auto; }
.result h2 {
  margin: 0 0 4px;
  font-size: clamp(22px, 5vw, 28px);
  letter-spacing: -0.03em;
  overflow-wrap: anywhere;
}
.result { border-top: 4px solid var(--line-strong); }
.result[data-state="pending"] { background: #fafafa; border-top-color: #a1a1aa; }
.result[data-state="success"] { background: var(--ok-bg); border-top-color: #16a34a; }
.result[data-state="already"] { background: var(--warn-bg); border-top-color: #d97706; }
.result[data-state="missing"],
.result[data-state="error"],
.result[data-state="network"] { background: var(--bad-bg); border-top-color: #dc2626; }
.result[data-state="success"] h2 { color: var(--ok); }
.result[data-state="already"] h2 { color: var(--warn); }
.result[data-state="missing"] h2,
.result[data-state="error"] h2,
.result[data-state="network"] h2 { color: var(--bad); }
pre, #ticket {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-family: inherit;
  margin: 10px 0 0;
  text-align: center;
  font-weight: 700;
  font-size: 15px;
  line-height: 1.4;
}
#ticket:empty { display: none; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 12px 0; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; }
.timeline li:last-child { border-bottom: 0; }
.timeline strong { display: block; font-size: 16px; }
.timeline .muted { margin-top: 2px; font-size: 13px; }

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(240px, 320px);
  gap: 16px;
  align-items: start;
}
.layout > div { min-width: 0; }
section { margin-bottom: 22px; min-width: 0; }
.panel { overflow: hidden; }
.line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 52px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
}
.line:last-child { border-bottom: 0; }
.line strong { font-weight: 650; min-width: 0; overflow-wrap: anywhere; }
.line .switch { margin-left: 0; flex: 0 0 auto; }
.tune .control {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1 1 220px;
  max-width: 100%;
}
.tune input[type="range"] {
  flex: 1 1 auto;
  width: 100%;
  min-width: 0;
  height: 44px;
  margin: 0;
  accent-color: var(--fill);
  cursor: pointer;
}
.tune output {
  min-width: 2ch;
  text-align: right;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-size: 14px;
}
.preview {
  color: var(--ink);
  background: #f3f3f5;
  padding: 16px;
  min-height: 180px;
  min-width: 0;
  overflow: hidden;
}
.preview p {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.slip {
  text-align: center;
  font-weight: 800;
  line-height: 1.35;
  overflow-wrap: anywhere;
  color: #111;
  background: #fff;
  border-radius: 10px;
  box-shadow: inset 0 0 0 1px var(--line);
}
.slip .time { color: #3f3f46; font-weight: 700; }
.sample { width: 100%; margin-top: 12px; }

.login {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: calc(24px + var(--safe-top)) 16px calc(24px + var(--safe-bottom));
}
.login-card {
  width: min(400px, 100%);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 28px 22px 22px;
  box-shadow: var(--shadow);
}
.login-card h1 { margin-bottom: 6px; font-size: 32px; }
.login-card p { margin: 0 0 18px; color: var(--muted); line-height: 1.4; }
.login-card label {
  display: block;
  margin-bottom: 12px;
  font-size: 13px;
  font-weight: 650;
  color: var(--muted);
}
.login-card input { display: block; margin-top: 6px; }
.login-card button { width: 100%; margin-top: 6px; }
.login-card .error { color: var(--bad); margin: 0 0 12px; font-weight: 600; }

@page { margin: 0; }
#print-sheet { display: none; }
@media print {
  html, body { background: #fff !important; }
  body > *:not(#print-sheet) { display: none !important; }
  #print-sheet {
    display: block !important;
    width: 100%;
    color: #000 !important;
    background: #fff !important;
    text-align: center !important;
    font-weight: 800 !important;
  }
  #print-sheet * {
    color: #000 !important;
    text-align: center !important;
    font-weight: 800 !important;
  }
}

@media (min-width: 801px) {
  .layout > div { position: sticky; top: 16px; }
  #toast { bottom: 24px; }
  tbody tr:hover td { background: #fafafa; }
}

@media (max-width: 800px) {
  :root { --pad: 16px; }
  html { scroll-padding-bottom: calc(96px + var(--safe-bottom)); }
  main { padding: 8px var(--pad) calc(96px + var(--safe-bottom)); }
  body.gate main { padding-bottom: calc(24px + var(--safe-bottom)); }
  .topbar {
    position: sticky;
    top: 0;
    z-index: 15;
    margin: 0 calc(var(--pad) * -1) 12px;
    padding: calc(8px + var(--safe-top)) var(--pad) 8px;
    background: rgba(245, 245, 247, 0.92);
    backdrop-filter: blur(16px);
  }
  .tabs {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    z-index: 20;
    margin: 0;
    border-radius: 0;
    border-top: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.94);
    backdrop-filter: blur(16px);
    padding: 6px 8px calc(6px + var(--safe-bottom));
    box-shadow: none;
  }
  .tabs a.current { background: #ececf1; box-shadow: none; }
  #toast { bottom: calc(78px + var(--safe-bottom)); }
  .toolbar { display: grid; grid-template-columns: 1fr 1fr; }
  .toolbar > button { width: 100%; }
  .toolbar .switch {
    grid-column: 1 / -1;
    margin-left: 0;
    flex-direction: row-reverse;
    justify-content: space-between;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 8px 14px;
  }
  .layout { grid-template-columns: minmax(0, 1fr); }
  .tune .line { flex-direction: column; align-items: stretch; padding-top: 12px; padding-bottom: 12px; }
  .tune .control, .tune input[type="range"] { width: 100%; min-width: 0; }
  .count-card { padding: 12px 10px; }
  .count-card span { font-size: 12px; }
  .table-wrap { background: transparent; border: 0; box-shadow: none; overflow: visible; }
  thead { display: none; }
  table, tbody, tr, td { display: block; width: 100%; }
  tbody tr {
    margin-bottom: 10px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 16px;
    box-shadow: var(--shadow);
    overflow: hidden;
  }
  td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid var(--line);
  }
  td::before {
    content: attr(data-label);
    color: var(--muted);
    font-weight: 650;
    font-size: 12px;
    flex: 0 0 84px;
  }
  td.empty { display: block; text-align: center; }
  td.empty::before { content: none; }
  tbody tr td:last-child { border-bottom: 0; }
  tbody tr:hover td { background: transparent; }
}

@media (max-width: 640px) {
  form#manual { flex-direction: column; align-items: stretch; }
  form#manual button { width: 100%; }
}

@media (max-height: 700px) {
  #reader, #reader video, #reader img, #reader canvas { max-height: 190px !important; }
  #reader { min-height: 120px; }
}

@media (max-width: 380px) {
  :root { --pad: 12px; }
  h1 { font-size: 24px; }
  .count-card span { font-size: 11px; }
  .count-card strong { font-size: 22px; }
  .pager { display: grid; grid-template-columns: 1fr 1fr; }
  .pager span { grid-column: 1 / -1; }
  .pager button { width: 100%; max-width: none; }
  td::before { flex-basis: 72px; }
  .login-card { padding: 24px 16px 16px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
