:root {
  color-scheme: light;
  --blue: #0878c9;
  --blue-dark: #0563aa;
  --blue-soft: #eaf5fd;
  --ink: #172033;
  --muted: #667085;
  --line: #d8e0eb;
  --surface: #ffffff;
  --background: #f4f7fb;
  --success: #087a52;
  --danger: #b42318;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--background); }
body {
  min-height: 100%;
  margin: 0;
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--background);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
  -webkit-text-size-adjust: 100%;
}
button, input { font: inherit; }
button, label[for] { -webkit-tap-highlight-color: transparent; }

.app-header {
  position: sticky;
  z-index: 10;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: calc(74px + env(safe-area-inset-top));
  padding: calc(10px + env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) 10px max(18px, env(safe-area-inset-left));
  border-bottom: 1px solid rgba(216, 224, 235, .9);
  background: rgba(255, 255, 255, .94);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand img { width: 62px; height: 42px; object-fit: contain; }
.brand h1 { margin: 0; font-size: 21px; line-height: 1.1; }
.brand p { margin: 3px 0 0; color: var(--muted); font-size: 12px; }
.icon-button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0 12px;
  background: var(--surface);
  color: var(--blue-dark);
  font-weight: 750;
}

.shell { width: min(1180px, calc(100% - 28px)); margin: 18px auto 40px; }
.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  max-width: 520px;
  margin-bottom: 14px;
  padding: 4px;
  border-radius: 14px;
  background: #e5ebf3;
}
.tab {
  min-height: 44px;
  border: 0;
  border-radius: 11px;
  background: transparent;
  color: var(--muted);
  font-weight: 750;
}
.tab.active { background: white; color: var(--ink); box-shadow: 0 2px 8px rgba(23, 32, 51, .12); }
.panel { border: 1px solid var(--line); border-radius: 18px; padding: 20px; background: var(--surface); box-shadow: 0 12px 36px rgba(28, 46, 74, .07); }
.field-grid { display: grid; gap: 14px; margin-bottom: 14px; }
.field-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.field-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
label { display: grid; gap: 7px; color: var(--muted); font-size: 13px; font-weight: 650; }
input {
  width: 100%; min-height: 46px; border: 1px solid var(--line); border-radius: 11px; padding: 10px 12px;
  background: white; color: var(--ink); font-size: 16px;
}
input:focus { outline: 3px solid rgba(8, 120, 201, .16); border-color: var(--blue); }
.code-input { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: -.25px; }
.scan-field { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 7px; align-items: stretch; }
.scan-button {
  min-width: 78px; min-height: 46px; border: 1px solid var(--blue); border-radius: 11px; padding: 8px 10px;
  background: var(--blue-soft); color: var(--blue-dark); font-size: 13px; font-weight: 800;
}
.scan-button::before { content: "▣"; margin-right: 5px; font-size: 16px; }
.hint { margin: 8px 0 14px; color: var(--muted); font-size: 13px; line-height: 1.45; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 13px; -webkit-overflow-scrolling: touch; }
table { width: 100%; min-width: 900px; border-collapse: collapse; }
th, td { border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 9px; text-align: left; vertical-align: middle; }
th:last-child, td:last-child { border-right: 0; }
tbody tr:last-child td { border-bottom: 0; }
th { background: #f5f8fc; color: #475467; font-size: 12px; }
td input { min-height: 40px; border: 0; border-radius: 8px; padding: 7px; font-size: 14px; }
.count { white-space: nowrap; font-weight: 750; }
.result-cell { min-width: 155px; text-align: center; }
.result-cell img { display: block; width: 82px; height: 82px; margin: 0 auto 7px; image-rendering: pixelated; }
.result-title { margin-bottom: 5px; font-size: 11px; font-weight: 750; }
.download-links { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.download-links a { color: var(--blue-dark); font-size: 12px; font-weight: 750; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }
.actions button, .text-button {
  min-height: 46px; border: 0; border-radius: 11px; padding: 10px 15px; background: var(--blue); color: white;
  font-weight: 750; cursor: pointer; text-align: center;
}
.actions button:active, .icon-button:active { transform: scale(.98); }
.actions button.secondary { border: 1px solid var(--line); background: white; color: var(--ink); }
button:disabled { opacity: .45; cursor: not-allowed; }
.file-actions { display: flex; gap: 16px; align-items: center; margin-top: 14px; }
.text-button { min-height: auto; padding: 0; background: none; color: var(--blue-dark); font-size: 13px; }
.status { min-height: 20px; margin: 14px 0 0; color: var(--muted); font-size: 14px; }
.status.success { color: var(--success); }
.status.error { color: var(--danger); }
dialog { width: min(420px, calc(100% - 28px)); border: 0; border-radius: 20px; padding: 24px; color: var(--ink); box-shadow: 0 28px 90px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(15, 23, 42, .5); backdrop-filter: blur(3px); }
dialog h2 { margin: 0 36px 14px 0; font-size: 22px; }
dialog ol { padding-left: 22px; line-height: 1.6; }
dialog p { margin-bottom: 0; color: var(--muted); }
.dialog-close { position: absolute; top: 13px; right: 13px; width: 38px; height: 38px; border: 0; border-radius: 50%; background: #eef2f6; font-size: 25px; }
.scanner-dialog { padding: 14px; background: #0d1524; color: white; }
.scanner-dialog::backdrop { background: rgba(0, 0, 0, .78); }
.scanner-head { position: relative; padding: 5px 48px 10px 4px; }
.scanner-head h2 { margin: 0; font-size: 21px; }
.scanner-head p { margin: 4px 0 0; color: #b9c5d7; font-size: 13px; }
.scanner-dialog .dialog-close { background: rgba(255,255,255,.14); color: white; }
.camera-frame { position: relative; overflow: hidden; width: 100%; aspect-ratio: 3 / 4; border-radius: 15px; background: #000; }
.camera-frame video { width: 100%; height: 100%; object-fit: cover; }
.scan-guide { position: absolute; inset: 28% 8%; border: 3px solid #62d6ff; border-radius: 12px; box-shadow: 0 0 0 999px rgba(0,0,0,.3); }
.scanner-dialog .status { color: #d9e5f5; }
.scanner-dialog .status.success { color: #70e6b6; }
.scanner-dialog .status.error { color: #ffaaa4; }
.scanner-tip { margin: 8px 2px 2px; color: #9eacc1; font-size: 12px; line-height: 1.4; }
.print-area { display: none; }

@media (max-width: 760px) {
  .shell { width: min(100% - 20px, 620px); margin-top: 12px; }
  .panel { border-radius: 15px; padding: 14px; }
  .field-grid.three, .field-grid.two { grid-template-columns: 1fr; gap: 10px; }
  .brand img { width: 50px; }
  .brand p { display: none; }
  .tabs { max-width: none; }
  .table-wrap { overflow: visible; border: 0; }
  table, tbody { display: block; min-width: 0; }
  thead { display: none; }
  tbody { display: grid; gap: 12px; }
  tr { display: grid; grid-template-columns: 1fr 1fr; border: 1px solid var(--line); border-radius: 13px; overflow: hidden; background: #fff; }
  td { display: block; min-width: 0; border-right: 0; padding: 9px 10px; }
  td::before { content: attr(data-label); display: block; margin-bottom: 4px; color: var(--muted); font-size: 11px; font-weight: 700; }
  td.wide, td.result-cell { grid-column: 1 / -1; }
  td.result-cell { padding: 12px; }
  td input { padding: 4px 0; }
  td .scan-field { grid-template-columns: minmax(0, 1fr) 72px; }
  td .scan-button { min-width: 0; min-height: 40px; padding: 6px; font-size: 0; }
  td .scan-button::before { margin: 0; font-size: 20px; }
  .result-cell img { width: 118px; height: 118px; }
  .actions { display: grid; grid-template-columns: 1fr 1fr; }
  .actions button { width: 100%; }
  .actions button:last-child:nth-child(odd) { grid-column: 1 / -1; }
}

@media print {
  @page { size: 60mm 20mm; margin: 0; }
  body > *:not(.print-area) { display: none !important; }
  .print-area { display: block; width: 60mm; }
  .print-item { display: grid; grid-template-columns: 18mm 1fr; align-items: center; width: 60mm; height: 20mm; break-after: page; overflow: hidden; }
  .print-item:last-child { break-after: auto; }
  .print-item img { width: 17mm; height: 17mm; image-rendering: pixelated; }
  .print-item span { font: 8pt Arial, sans-serif; line-height: 1.15; }
}
