:root {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #182230;
  background: #eef2f6;
  font-synthesis: none;
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: #eef2f6; }
button, input { font: inherit; }
button { cursor: pointer; border: 0; border-radius: 10px; font-weight: 700; }
button:disabled { cursor: not-allowed; opacity: .5; }

.topbar {
  background: #132238;
  color: white;
  padding: 18px max(18px, env(safe-area-inset-right)) 18px max(18px, env(safe-area-inset-left));
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: 0 2px 12px rgba(0,0,0,.18);
}
h1, h2 { margin: 0; }
h1 { font-size: clamp(21px, 4vw, 30px); }
h2 { font-size: 20px; }
.subtitle { margin: 5px 0 0; color: #ccd6e2; font-size: 14px; }
.header-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.privacy-pill {
  background: #1c7247;
  color: white;
  border-radius: 999px;
  padding: 7px 11px;
  font-size: 12px;
  font-weight: 800;
}

.app-shell {
  width: min(1180px, calc(100% - 24px));
  margin: 20px auto 50px;
  display: grid;
  gap: 18px;
}
.card {
  background: white;
  border-radius: 16px;
  padding: 20px;
  box-shadow: 0 3px 16px rgba(19,34,56,.08);
}
.section-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}
.section-heading p { margin: 4px 0 0; color: #667085; font-size: 14px; }

.scanner-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(260px, .55fr);
  gap: 18px;
}
.preview-wrap {
  position: relative;
  min-height: 370px;
  background: #0d1117;
  overflow: hidden;
  border-radius: 14px;
}
#cameraPreview {
  width: 100%;
  height: 100%;
  min-height: 370px;
  object-fit: cover;
  display: none;
}
.camera-placeholder {
  min-height: 370px;
  display: grid;
  place-content: center;
  gap: 10px;
  justify-items: center;
  color: #dbe5f0;
  text-align: center;
  padding: 30px;
}
.camera-placeholder span { color: #9fb0c3; font-size: 14px; }
.barcode-art {
  width: min(360px, 78vw);
  height: 105px;
  border-radius: 8px;
  opacity: .9;
  background:
    repeating-linear-gradient(90deg,
      #fff 0 2px, #111 2px 4px, #fff 4px 5px, #111 5px 9px,
      #fff 9px 12px, #111 12px 14px, #fff 14px 16px, #111 16px 21px);
  box-shadow: 0 0 0 12px rgba(255,255,255,.08);
}
.scan-controls { display: grid; align-content: start; gap: 10px; }
.primary, .secondary, .danger { padding: 12px 15px; }
.primary { background: #1769e0; color: white; }
.primary.alt { background: #136f63; }
.secondary { background: #e8edf3; color: #1e293b; }
.danger { background: #b42318; color: white; }
.compact { padding: 9px 12px; font-size: 13px; }
.tip-box {
  background: #f1f7ff;
  border: 1px solid #c8dcff;
  border-radius: 12px;
  padding: 12px;
  font-size: 13px;
  display: grid;
  gap: 4px;
}
.message { font-size: 13px; color: #667085; min-height: 1.2em; }
.status {
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}
.status.neutral { background: #eef2f6; color: #475467; }
.status.working { background: #fff2cc; color: #7a5a00; }
.status.success { background: #dff5e8; color: #146c43; }
.status.error { background: #ffe3e0; color: #9e241c; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0,1fr));
  gap: 13px;
}
label { display: grid; gap: 6px; font-size: 12px; font-weight: 800; color: #344054; }
label.wide { grid-column: span 2; }
input {
  width: 100%;
  border: 1px solid #cfd7e2;
  border-radius: 9px;
  padding: 10px 11px;
  background: #fff;
  color: #111827;
  outline: none;
}
input:focus { border-color: #1769e0; box-shadow: 0 0 0 3px rgba(23,105,224,.12); }
.save-row { display: flex; align-items: center; gap: 12px; margin-top: 18px; }

.button-group { display: flex; gap: 8px; flex-wrap: wrap; }
.table-wrap { width: 100%; overflow: auto; }
table { width: 100%; border-collapse: collapse; min-width: 820px; }
th, td {
  border-bottom: 1px solid #eaecf0;
  padding: 11px 9px;
  text-align: left;
  font-size: 13px;
  vertical-align: middle;
}
th { color: #475467; background: #f8fafc; position: sticky; top: 0; }
td.actions { white-space: nowrap; }
.table-btn { padding: 7px 9px; margin-right: 4px; font-size: 12px; background: #e8edf3; color: #1e293b; }
.table-btn.delete { background: #fee4e2; color: #912018; }
.empty { text-align: center; color: #667085; padding: 28px; }

.privacy-card { background: #fbfcfe; }
.privacy-card p { color: #475467; line-height: 1.55; }

dialog {
  border: 0;
  border-radius: 16px;
  max-width: 460px;
  padding: 24px;
  box-shadow: 0 20px 70px rgba(0,0,0,.3);
}
dialog::backdrop { background: rgba(15,23,42,.62); }
dialog p { color: #475467; line-height: 1.5; }

@media (max-width: 850px) {
  .topbar { position: static; align-items: flex-start; flex-direction: column; }
  .scanner-grid { grid-template-columns: 1fr; }
  .preview-wrap, #cameraPreview, .camera-placeholder { min-height: 300px; }
  .form-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
}
@media (max-width: 520px) {
  .app-shell { width: min(100% - 12px, 1180px); margin-top: 8px; }
  .card { border-radius: 12px; padding: 15px; }
  .section-heading { flex-direction: column; }
  .form-grid { grid-template-columns: 1fr; }
  label.wide { grid-column: span 1; }
  .button-group { width: 100%; }
  .button-group button { flex: 1 1 auto; }
  .preview-wrap, #cameraPreview, .camera-placeholder { min-height: 260px; }
}

.camera-debug {
  font-size: 11px;
  color: #7a8699;
  word-break: break-word;
}

.button-label {
  display: block;
  text-align: center;
  border-radius: 10px;
  font-weight: 700;
  cursor: pointer;
  padding: 12px 15px;
}
.native-file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0.001;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}


.crop-editor {
  margin-top: 18px;
  border-top: 1px solid #e4e7ec;
  padding-top: 18px;
}
.crop-editor-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 12px;
}
.crop-editor-head h3 {
  margin: 0;
  font-size: 18px;
}
.crop-editor-head p {
  margin: 4px 0 0;
  color: #667085;
  font-size: 13px;
}
.crop-canvas-wrap {
  width: 100%;
  overflow: auto;
  background: #111827;
  border-radius: 12px;
  padding: 8px;
  touch-action: none;
}
#cropCanvas {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 0 auto;
  background: #000;
  cursor: crosshair;
  touch-action: none;
}
.crop-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}
.crop-actions button {
  flex: 1 1 180px;
}

.version-note {
  font-size: 12px;
  font-weight: 800;
}


.diagnostic-panel {
  margin-top: 18px;
  padding: 16px;
  border: 1px solid #d6deea;
  border-radius: 12px;
  background: #f8fafc;
}
.diagnostic-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
  margin-bottom: 12px;
}
.diagnostic-head h3 {
  margin: 0;
  font-size: 18px;
}
.diagnostic-head p {
  margin: 4px 0 0;
  color: #667085;
  font-size: 13px;
}
.quality-box {
  background: white;
  border: 1px solid #e4e7ec;
  border-radius: 9px;
  padding: 10px 12px;
  margin-bottom: 12px;
  font-size: 13px;
  line-height: 1.45;
}
.diag-table-wrap {
  overflow-x: auto;
}
.diag-table {
  min-width: 760px;
}
.diag-table td,
.diag-table th {
  font-size: 12px;
}
.diag-result-running {
  color: #7a5a00;
  font-weight: 800;
}
.diag-result-pass {
  color: #146c43;
  font-weight: 800;
}
.diag-result-fail {
  color: #b42318;
  font-weight: 800;
}
.diag-result-unsupported {
  color: #475467;
  font-weight: 800;
}
.diagnostic-conclusion {
  margin-top: 12px;
  border-left: 4px solid #1769e0;
  background: white;
  padding: 12px;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.5;
}
@media (max-width: 620px) {
  .diagnostic-head {
    flex-direction: column;
  }
  .diagnostic-head button {
    width: 100%;
  }
}


.zoom-control {
  margin-top: 8px;
  padding: 10px 12px;
  background: #f8fafc;
  border: 1px solid #e4e7ec;
  border-radius: 10px;
}
.zoom-control label {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 800;
  margin-bottom: 6px;
}
.zoom-control input[type="range"] {
  width: 100%;
}
