:root {
  color-scheme: light;
  --bg: #f4f7f6;
  --panel: #ffffff;
  --text: #15211f;
  --muted: #66736f;
  --line: #dce5e1;
  --primary: #0f766e;
  --primary-dark: #0b5f59;
  --danger: #b42318;
  --soft: #e8f3f0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}

button,
input,
select,
textarea {
  font: inherit;
}

.mobile-shell,
.desktop-shell,
.admin-shell {
  width: min(100%, 720px);
  margin: 0 auto;
  padding: 18px 14px 34px;
}

.desktop-shell {
  width: min(100%, 1280px);
  padding: 14px 18px 28px;
}

.admin-shell {
  width: min(100%, 1600px);
  padding-left: 18px;
  padding-right: 18px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 2px 18px;
}

.desktop-topbar {
  padding: 4px 2px 10px;
}

.test-banner {
  border: 1px solid #f4b740;
  background: #fff6df;
  color: #7a4a00;
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 12px;
  font-weight: 800;
  line-height: 1.4;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--primary);
  font-size: 13px;
  font-weight: 700;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 28px;
}

h2 {
  font-size: 18px;
}

.admin-link,
.as-link {
  text-decoration: none;
}

.admin-link {
  color: var(--primary);
  font-weight: 700;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 14px;
}

.desktop-shell .panel {
  padding: 14px;
}

.step-title {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

.step-title span {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  color: white;
  background: var(--primary);
  font-weight: 800;
}

.field {
  display: grid;
  gap: 7px;
  margin-bottom: 12px;
}

.field span {
  color: var(--muted);
  font-size: 14px;
}

select,
input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  padding: 12px;
  color: var(--text);
  outline: none;
}

textarea {
  resize: vertical;
  line-height: 1.5;
}

select:focus,
input:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.14);
}

.upload-box {
  min-height: 128px;
  border: 1.5px dashed #a8bbb5;
  border-radius: 8px;
  background: var(--soft);
  display: grid;
  place-items: center;
  text-align: center;
  padding: 18px;
  cursor: pointer;
  margin-bottom: 12px;
  transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}

.upload-copy {
  display: grid;
  gap: 6px;
}

.upload-actions {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.upload-actions.single-action {
  grid-template-columns: 1fr;
}

.mobile-upload {
  gap: 14px;
}

.upload-box.dragging {
  border-color: var(--primary);
  background: #dff1ec;
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.14);
}

.upload-box input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.upload-box strong,
.upload-box small {
  display: block;
}

.upload-box small {
  color: var(--muted);
  margin-top: 6px;
}

.preview {
  display: none;
  width: 100%;
  max-height: 420px;
  object-fit: contain;
  border-radius: 8px;
  border: 1px solid var(--line);
  margin: 10px 0;
  background: #eef2f1;
}

.preview-canvas {
  display: none;
  width: 100%;
  max-height: 420px;
  object-fit: contain;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #eef2f1;
}

.preview.visible {
  display: block;
}

.preview-canvas.visible {
  display: block;
}

.ocr-crop-panel,
.manual-crop-panel {
  display: grid;
  gap: 10px;
  margin: 10px 0 12px;
}

.ocr-crop-panel > span {
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

#ocrCropCanvas,
#manualCropCanvas {
  width: 100%;
  max-height: 360px;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #eef2f1;
  touch-action: none;
}

#manualCropCanvas {
  cursor: crosshair;
}

.camera-tools {
  display: grid;
  gap: 10px;
  margin-bottom: 12px;
}

.camera-panel {
  display: grid;
  gap: 10px;
}

.camera-panel video {
  width: 100%;
  max-height: 420px;
  object-fit: contain;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #10201d;
}

.copy-action {
  margin: -4px 0 12px;
}

.desktop-grid {
  display: grid;
  grid-template-columns: minmax(300px, 0.82fr) minmax(560px, 1.35fr);
  gap: 14px;
  align-items: start;
}

.compact-desktop-grid {
  min-height: 0;
}

.desktop-column {
  display: grid;
  gap: 14px;
}

.desktop-upload {
  min-height: 76px;
  grid-template-columns: minmax(220px, 1fr) 340px;
  align-items: center;
  justify-items: stretch;
  gap: 12px;
  padding: 10px 12px;
  text-align: left;
  margin-bottom: 8px;
}

.desktop-upload .upload-copy {
  gap: 2px;
}

.desktop-upload strong {
  font-size: 15px;
}

.desktop-upload small {
  margin-top: 2px;
  font-size: 12px;
}

.desktop-upload .upload-actions {
  gap: 8px;
}

.desktop-upload .primary,
.desktop-upload .secondary {
  min-height: 42px;
}

.desktop-info-panel textarea {
  min-height: 132px;
}

.desktop-photo-panel .camera-panel video {
  max-height: 260px;
}

.desktop-preview-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  align-items: start;
}

.desktop-preview-row .preview,
.desktop-preview-row .preview-canvas {
  max-height: 360px;
  margin: 0;
}

.desktop-preview-row .ocr-crop-panel {
  width: 100%;
  margin: 0;
}

.desktop-preview-row #ocrCropCanvas {
  min-height: 150px;
  max-height: 190px;
}

.desktop-photo-panel #manualCropCanvas {
  max-height: 280px;
}

.desktop-result-bar {
  display: grid;
  grid-template-columns: 138px minmax(360px, 1fr) 160px 320px;
  gap: 12px;
  align-items: center;
  margin-top: 14px;
}

.desktop-result-bar .step-title {
  margin-bottom: 0;
}

.desktop-result-bar .serial-result {
  margin: 0;
  padding: 12px 14px;
  font-size: 18px;
}

.desktop-result-bar .copy-action {
  margin: 0;
}

.desktop-result-bar .attempt-list {
  grid-column: 1 / -1;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

.primary,
.secondary {
  width: 100%;
  min-height: 48px;
  border: 0;
  border-radius: 8px;
  font-weight: 800;
  cursor: pointer;
}

.primary {
  background: var(--primary);
  color: white;
}

.primary:hover {
  background: var(--primary-dark);
}

.secondary {
  background: #eef2f1;
  color: var(--text);
}

.exchange-action {
  min-height: 64px;
  font-size: 18px;
  letter-spacing: 0;
}

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

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.status-text,
.hint {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
  margin: 10px 0 0;
}

.hidden {
  display: none !important;
}

.serial-result {
  background: #10201d;
  color: #e8fff9;
  border-radius: 8px;
  padding: 18px;
  font-size: 22px;
  font-weight: 900;
  line-height: 1.45;
  overflow-wrap: anywhere;
  margin: 14px 0;
}

.button-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.attempt-list {
  list-style: none;
  padding: 0;
  margin: 14px 0 0;
  display: grid;
  gap: 8px;
}

.attempt-list li {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  display: grid;
  gap: 4px;
}

.attempt-list span,
.attempt-list em {
  color: var(--muted);
  font-size: 13px;
}

.attempt-list strong {
  overflow-wrap: anywhere;
}

.toast {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: 20px;
  background: #10201d;
  color: white;
  border-radius: 8px;
  padding: 13px 14px;
  text-align: center;
  z-index: 20;
}

.admin-tools {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 220px;
  gap: 18px;
  align-items: end;
}

.import-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 120px;
  gap: 12px;
  align-items: end;
}

.import-form .field {
  margin-bottom: 0;
}

.admin-action {
  min-height: 52px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 18px;
  line-height: 1;
  white-space: nowrap;
}

.export-action {
  border: 1px solid var(--primary-dark);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.04);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.stat-card {
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}

.stat-card span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 8px;
}

.stat-card strong {
  font-size: 28px;
}

.table-wrap {
  overflow: auto;
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 1420px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 10px 12px;
  text-align: left;
  vertical-align: top;
  font-size: 14px;
}

th {
  background: #eef3f1;
  color: #31423e;
}

td {
  overflow-wrap: anywhere;
}

.cell-batch {
  min-width: 150px;
  white-space: nowrap;
}

.cell-employee,
.cell-small,
.cell-result,
.cell-photo {
  white-space: nowrap;
}

.cell-time {
  min-width: 170px;
  white-space: nowrap;
}

.cell-serial {
  min-width: 310px;
  white-space: nowrap;
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  letter-spacing: 0;
}

@media (max-width: 560px) {
  .button-row,
  .admin-tools,
  .import-form {
    grid-template-columns: 1fr;
  }

  h1 {
    font-size: 24px;
  }

  .serial-result {
    font-size: 18px;
  }
}

@media (min-width: 900px) {
  .mobile-shell {
    width: min(100%, 1040px);
    padding-top: 26px;
  }

  .mobile-shell {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
  }

  .mobile-shell > .test-banner,
  .mobile-shell > .topbar,
  .mobile-shell > .result-panel {
    grid-column: 1 / -1;
  }

  .panel {
    margin-bottom: 0;
  }

  .upload-box {
    min-height: 220px;
  }

  .desktop-upload {
    min-height: 76px;
  }

  .preview {
    max-height: 520px;
  }
}
