:root {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", system-ui, sans-serif;
  color: #111;
  background: #f4f4f4;
  -webkit-font-smoothing: antialiased;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: #f4f4f4; }
body { min-height: 100dvh; }
button, input { font: inherit; }
.hidden { display: none !important; }

.app {
  width: min(100%, 760px);
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 16px max(28px, env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.eyebrow {
  margin: 0 0 3px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .12em;
}

h1 { margin: 0; font-size: 30px; line-height: 1; }
h2 { margin: 0; }
.version { font-size: 12px; color: #666; white-space: nowrap; }

.status-card,
.db-card,
.search-card,
.history-card,
.metric,
.product-result {
  background: #fff;
  border: 1px solid #e5e5e5;
  border-radius: 16px;
}

.status-card,
.db-card {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 12px 14px;
  margin-bottom: 12px;
}

.db-card { align-items: center; }
.db-copy { min-width: 0; flex: 1; }

.status-dot {
  flex: 0 0 auto;
  width: 10px;
  height: 10px;
  margin-top: 5px;
  border-radius: 50%;
  background: #999;
}
.status-dot.live { background: #16a34a; }
.status-dot.error { background: #dc2626; }
.status-dot.warning { background: #d97706; }

.status-card strong,
.db-card strong { display: block; font-size: 15px; }
.status-card p,
.db-card p { margin: 2px 0 0; font-size: 13px; color: #666; line-height: 1.35; }

.search-card {
  padding: 13px;
  margin-bottom: 12px;
}
.search-card label {
  display: block;
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: .04em;
  margin: 0 0 7px;
}
#productSearch,
#pinInput {
  width: 100%;
  border: 1px solid #d9d9d9;
  background: #fafafa;
  color: #111;
  border-radius: 13px;
  padding: 13px 14px;
  outline: none;
  font-size: 16px;
}
#productSearch:focus,
#pinInput:focus { border-color: #111; background: #fff; }
.search-meta {
  min-height: 16px;
  margin-top: 7px;
  color: #777;
  font-size: 11px;
}
.search-results {
  margin-top: 10px;
  border-top: 1px solid #ededed;
}
.search-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 11px 2px;
  background: transparent;
  border: 0;
  border-bottom: 1px solid #ededed;
  border-radius: 0;
  text-align: left;
  color: #111;
}
.search-item:last-child { border-bottom: 0; }
.search-item-main { min-width: 0; }
.search-item-main b {
  display: block;
  font-size: 14px;
  line-height: 1.25;
}
.search-item-main small { display: block; margin-top: 3px; color: #777; font-size: 11px; }
.search-item-price { flex: 0 0 auto; font-weight: 900; font-size: 15px; }

.camera-card {
  position: relative;
  overflow: hidden;
  width: 100%;
  aspect-ratio: 3 / 4;
  max-height: 62dvh;
  background: #111;
  border-radius: 20px;
  box-shadow: 0 8px 24px rgba(0,0,0,.12);
}

.dynamsoft-camera {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #111;
}

.dynamsoft-camera > * {
  width: 100% !important;
  height: 100% !important;
  max-width: none !important;
  max-height: none !important;
}

.dynamsoft-camera video,
.dynamsoft-camera canvas {
  width: 100% !important;
  height: 100% !important;
  object-fit: cover !important;
}

.camera-placeholder {
  position: absolute;
  z-index: 20;
  inset: 0;
  display: grid;
  place-items: center;
  color: #aaa;
  font-weight: 700;
  background: #111;
}
.camera-placeholder.hidden { display: none; }

.scan-guide {
  position: absolute;
  z-index: 15;
  left: 8%;
  right: 8%;
  top: 43%;
  height: 18%;
  border: 2px solid rgba(255,255,255,.85);
  border-radius: 14px;
  pointer-events: none;
  box-shadow: 0 0 0 999px rgba(0,0,0,.08);
}

.scan-line {
  position: absolute;
  left: 4%;
  right: 4%;
  top: 50%;
  height: 2px;
  background: rgba(255,255,255,.9);
}

.controls {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  margin: 12px 0;
}

button {
  border: 0;
  border-radius: 14px;
  padding: 14px 16px;
  font-weight: 800;
}
button:disabled { opacity: .45; }
.primary { background: #111; color: #fff; }
.secondary { background: #ddd; color: #111; }
.text-btn { background: transparent; color: #555; padding: 4px 0; }
.compact { padding: 9px 10px; border-radius: 10px; font-size: 11px; }

.product-result {
  overflow: hidden;
  margin: 0 0 12px;
}
.product-head {
  padding: 14px 15px 11px;
  border-bottom: 1px solid #ececec;
}
.product-head .source {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: #777;
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-bottom: 7px;
}
.product-name { font-size: 19px; font-weight: 900; line-height: 1.2; }
.product-ean { margin-top: 4px; font-size: 12px; color: #666; }
.price-hero {
  padding: 15px;
  background: #111;
  color: #fff;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
}
.price-hero span { font-size: 11px; font-weight: 800; letter-spacing: .06em; }
.price-hero strong { font-size: 38px; line-height: .95; white-space: nowrap; }
.price-hero.warning { background: #7c2d12; }
.product-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1px;
  background: #ececec;
}
.product-cell { background: #fff; padding: 11px 14px; min-width: 0; }
.product-cell span { display: block; font-size: 10px; color: #777; margin-bottom: 4px; }
.product-cell b { display: block; font-size: 14px; overflow-wrap: anywhere; }
.product-footer { padding: 9px 14px 12px; color: #777; font-size: 10px; }
.not-found { padding: 15px; }
.not-found b { display: block; margin-bottom: 4px; }

.result-grid {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 10px;
  margin-bottom: 12px;
}
.metric { padding: 12px 14px; min-width: 0; }
.metric span { display: block; font-size: 12px; color: #666; margin-bottom: 5px; }
.metric strong { display: block; font-size: 28px; line-height: 1.05; }
.code-metric strong { overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }

.history-card { padding: 14px; }
.history-head { display: flex; justify-content: space-between; align-items: center; }
.history-head h2 { margin: 0; font-size: 17px; }
.history { margin: 10px 0 0; padding-left: 30px; }
.history li { padding: 5px 0; font-size: 15px; font-variant-numeric: tabular-nums; }
.history li small { color: #999; font-size: 10px; }
.history .empty { color: #888; }
.history time { color: #888; font-size: 12px; margin-left: 8px; }

.test-note {
  margin: 12px 4px 0;
  color: #666;
  font-size: 12px;
  line-height: 1.4;
  text-align: center;
}

.modal {
  position: fixed;
  z-index: 9999;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(0,0,0,.58);
}
.modal-card {
  width: min(100%, 430px);
  background: #fff;
  border-radius: 20px;
  padding: 20px;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.modal-card h2 { font-size: 24px; }
.modal-card p:not(.eyebrow) { color: #666; font-size: 13px; line-height: 1.4; }
.modal-actions { display: grid; grid-template-columns: auto 1fr; gap: 9px; margin-top: 12px; }
.pin-error {
  margin-top: 9px;
  padding: 9px 10px;
  border-radius: 10px;
  background: #fee2e2;
  color: #991b1b;
  font-size: 12px;
  font-weight: 700;
}

@media (orientation: landscape) and (max-height: 600px) {
  .camera-card { aspect-ratio: 16 / 9; max-height: 48dvh; }
}
