* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: -apple-system, BlinkMacSystemFont, sans-serif; background: #fff; color: #111; }
.screen { display: none; flex-direction: column; min-height: 100svh; }
.screen.active { display: flex; }
.hdr {
  padding: 13px 16px; display: flex; align-items: center; gap: 10px;
  border-bottom: 1px solid #eee; background: #fff; flex-shrink: 0; position: sticky; top: 0; z-index: 10;
}
.back-btn { background: none; border: none; cursor: pointer; font-size: 22px; padding: 2px; color: #666; display: flex; align-items: center; }
.hdr-title { font-size: 15px; font-weight: 600; }
.hdr-right { margin-left: auto; }
.body { flex: 1; padding: 18px 16px; display: flex; flex-direction: column; gap: 14px; overflow-y: auto; }
.chip { font-family: monospace; font-size: 11px; color: #666; background: #f4f4f4; padding: 3px 8px; border-radius: 6px; display: inline-flex; align-items: center; gap: 4px; align-self: flex-start; }
label { font-size: 12px; color: #666; display: block; margin-bottom: 5px; }
textarea { width: 100%; min-height: 90px; padding: 10px 12px; font-family: inherit; font-size: 16px; line-height: 1.5; border: 1px solid #ddd; border-radius: 10px; background: #fff; color: #111; resize: vertical; }
textarea:focus { outline: none; border-color: #999; }
.recent-row { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 8px; }
.r-chip { background: #f4f4f4; border: 1px solid #eee; border-radius: 20px; padding: 5px 12px; font-size: 13px; color: #555; cursor: pointer; max-width: 140px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.same-btn { width: 100%; padding: 11px 14px; background: none; border: 1px solid #ddd; border-radius: 10px; font-size: 13px; color: #555; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 8px; }
.photo-btn { width: 100%; padding: 10px; cursor: pointer; border: 1px dashed #ccc; border-radius: 10px; background: none; font-size: 13px; color: #888; display: flex; align-items: center; justify-content: center; gap: 7px; }
.photo-prev { width: 100%; border-radius: 10px; display: none; max-height: 180px; object-fit: cover; }
.primary-btn { padding: 15px; background: #111; color: #fff; border: none; border-radius: 12px; font-size: 16px; font-weight: 600; cursor: pointer; width: 100%; margin-top: auto; }
.primary-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.outline-btn { padding: 8px 14px; background: none; border: 1px solid #ddd; border-radius: 10px; font-size: 13px; cursor: pointer; color: #111; display: inline-flex; align-items: center; gap: 6px; }
.error-box { padding: 10px 13px; background: #fff0f0; border: 1px solid #ffcccc; border-radius: 10px; font-size: 13px; color: #c00; display: none; }
.info-box { padding: 10px 13px; background: #f0f6ff; border: 1px solid #cce0ff; border-radius: 10px; font-size: 13px; color: #336; line-height: 1.5; }
.view-text { font-size: 20px; line-height: 1.65; }
.meta { font-size: 12px; color: #999; margin-top: 4px; }
.center-body { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 40px 24px; gap: 14px; text-align: center; }
#screen-success { align-items: center; justify-content: center; }
.qr-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.qr-cell { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px; border-radius: 10px; border: 1px solid #eee; cursor: pointer; position: relative; }
.qr-cell:active { background: #f9f9f9; }
.qr-cell img, .qr-cell canvas { width: 100% !important; height: auto !important; max-width: 90px; pointer-events: none; }
.qr-uid { font-family: monospace; font-size: 8px; color: #aaa; text-align: center; }
.qr-status { font-size: 9px; font-weight: 600; padding: 2px 6px; border-radius: 10px; position: absolute; top: 4px; right: 4px; }
.qr-status.logged { background: #e6f9ee; color: #1a7a40; }
.qr-status.empty { background: #f4f4f4; color: #aaa; }
.logged-row { padding: 12px 14px; border: 1px solid #eee; border-radius: 10px; cursor: pointer; }
.logged-row:active { background: #f9f9f9; }

@media print {
  body * { visibility: hidden; }
  #screen-generate, #screen-generate * { visibility: visible; }
  #screen-generate { position: absolute; top: 0; left: 0; width: 100%; }
  .hdr, .gen-controls, .tap-hint { display: none !important; }
  .qr-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6mm;
    padding: 8mm;
    width: 100%;
    box-sizing: border-box;
  }
  .qr-cell {
    display: flex;
    flex-direction: column;
    align-items: center;
    border: 0.5px solid #ccc;
    padding: 4mm;
    break-inside: avoid;
  }
  .qr-cell canvas,
  .qr-cell img {
    width: 100% !important;
    height: auto !important;
    max-width: none !important;
    display: block;
  }
  .qr-uid { font-size: 7pt; color: #999; margin-top: 2mm; }
  .qr-status { display: none; }
}

#scan-wrap { flex: 1; background: #000; position: relative; min-height: 300px; }
#scan-video { width: 100%; height: 100%; object-fit: cover; display: block; }
#scan-canvas { display: none; }
.scan-frame {
  position: absolute; top: 50%; left: 50%;
  transform: translate(-50%,-50%);
  width: 200px; height: 200px;
  border: 2px solid rgba(255,255,255,0.6);
  border-radius: 12px; pointer-events: none;
}
.corner { position: absolute; width: 20px; height: 20px; }
.corner.tl { top:-2px; left:-2px; border-top:3px solid #fff; border-left:3px solid #fff; border-radius:4px 0 0 0; }
.corner.tr { top:-2px; right:-2px; border-top:3px solid #fff; border-right:3px solid #fff; border-radius:0 4px 0 0; }
.corner.bl { bottom:-2px; left:-2px; border-bottom:3px solid #fff; border-left:3px solid #fff; border-radius:0 0 0 4px; }
.corner.br { bottom:-2px; right:-2px; border-bottom:3px solid #fff; border-right:3px solid #fff; border-radius:0 0 4px 0; }
.scan-hint { position: absolute; bottom: 16px; width: 100%; text-align: center; color: rgba(255,255,255,0.7); font-size: 13px; }