:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #07090c;
  color: #f8fafc;
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: #07090c; }
body.feedback-success { animation: success-flash 220ms ease-out; }
body.feedback-error { animation: error-flash 320ms ease-out; }
button, input, select { font: inherit; }
button {
  min-height: 52px;
  border: 0;
  border-radius: 8px;
  color: #f8fafc;
  background: #1f2937;
  font-weight: 800;
}
button.danger {
  background: #991b1b;
}
button:active { transform: translateY(1px); }

.app-shell {
  width: min(760px, 100%);
  margin: 0 auto;
  padding: 12px;
  display: grid;
  gap: 12px;
}

.topbar {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 10px;
  align-items: end;
}

label {
  display: block;
  color: #94a3b8;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

select, input {
  width: 100%;
  min-height: 48px;
  padding: 0 12px;
  border: 1px solid #334155;
  border-radius: 8px;
  color: #f8fafc;
  background: #111827;
}

.sync-pill {
  padding: 10px 12px;
  border-radius: 999px;
  background: #78350f;
  color: #fed7aa;
  font-size: 12px;
  font-weight: 900;
}

.scanner-panel {
  position: relative;
  overflow: hidden;
  height: clamp(150px, 26vh, 220px);
  border: 4px solid #22c55e;
  border-radius: 8px;
  background: #020617;
}
.scanner-panel.bulk { border-color: #38bdf8; }
.scanner-panel.sleep video { filter: blur(10px) brightness(0.35); }
video { width: 100%; height: 100%; object-fit: cover; }
.scanner-overlay { position: absolute; inset: 0; pointer-events: none; }
.icon-button, .auto-scan-badge, .wake-button, .pulse { pointer-events: auto; }
.auto-scan-badge {
  position: absolute;
  top: 12px;
  left: 12px;
  padding: 10px 12px;
  border-radius: 999px;
  background: #7f1d1d;
  color: #fecaca;
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}
.auto-scan-badge.on {
  background: #14532d;
  color: #bbf7d0;
}
.icon-button { position: absolute; top: 12px; right: 12px; min-width: 78px; background: #0f172a; }
.wake-button {
  position: absolute;
  inset: 34% 18px auto;
  min-height: 92px;
  background: #2563eb;
  font-size: clamp(22px, 6vw, 36px);
}
.pulse {
  position: absolute;
  left: 18px;
  right: 18px;
  bottom: 18px;
  padding: 14px;
  border-radius: 8px;
  background: rgb(0 0 0 / 76%);
  text-align: center;
  white-space: pre-line;
  font-size: 22px;
  font-weight: 900;
}
.hidden { display: none !important; }

.mode-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.mode.active { background: #16a34a; }
.mode-row.bulk .mode.active { background: #0284c7; }

.product-card {
  display: grid;
  grid-template-columns: 84px 1fr;
  gap: 12px;
  padding: 12px;
  border-radius: 8px;
  background: #111827;
}
.photo-slot {
  display: grid;
  place-items: center;
  width: 84px;
  height: 84px;
  border-radius: 8px;
  background: #1f2937;
  color: #94a3b8;
  font-weight: 800;
  overflow: hidden;
}
.photo-slot img { width: 100%; height: 100%; object-fit: cover; }
h1, h2, p { margin: 0; }
h1 { font-size: 20px; }
p { margin-top: 6px; color: #cbd5e1; }

.manual-scan { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: start; }
.manual-panel {
  min-width: 0;
  border-radius: 8px;
  background: #111827;
}
.manual-panel summary {
  display: grid;
  place-items: center;
  min-height: 52px;
  padding: 0 14px;
  border-radius: 8px;
  color: #f8fafc;
  background: #1f2937;
  font-weight: 900;
  cursor: pointer;
  list-style: none;
}
.manual-panel summary::-webkit-details-marker { display: none; }
.manual-controls { display: grid; grid-template-columns: 1fr 96px; gap: 8px; padding: 8px 0 0; }
#retryCameraButton { min-width: 140px; }
.keypad { display: grid; gap: 10px; }
output {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}
#quantityInput {
  min-height: 58px;
  padding: 6px 14px;
  font-size: 38px;
  font-weight: 900;
  text-align: right;
}
#quantityInput.pending {
  border-color: #93c5fd;
  background: #172554;
}
#quantityInput.error {
  border-color: #fca5a5;
  background: #7f1d1d;
}
.keys { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.keys button { min-height: 56px; font-size: 21px; }
.keys .confirm { grid-row: span 2; background: #16a34a; }
.keys .filler { visibility: hidden; }

.actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.actions button:last-child { background: #2563eb; }

dialog {
  width: min(720px, calc(100% - 24px));
  border: 1px solid #334155;
  border-radius: 8px;
  color: #f8fafc;
  background: #0f172a;
}
.dialog-shell { display: grid; gap: 12px; }
.dialog-shell header { display: flex; justify-content: space-between; gap: 12px; align-items: center; }
.line-list { display: grid; gap: 8px; max-height: 60vh; overflow: auto; }
.line-row {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border-radius: 8px;
  background: #111827;
  text-align: left;
}
.line-thumb {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  border-radius: 8px;
  background: #1f2937;
  color: #94a3b8;
  font-size: 11px;
  font-weight: 900;
  overflow: hidden;
}
.line-thumb img { width: 100%; height: 100%; object-fit: cover; }
.line-main { min-width: 0; }
.line-main strong, .line-main small { display: block; }
.line-main strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.line-row small { margin-top: 4px; color: #94a3b8; }
.line-badges { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.badge {
  padding: 4px 6px;
  border-radius: 999px;
  background: #1e293b;
  color: #cbd5e1;
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}
.badge.warning { background: #7f1d1d; color: #fecaca; }
.badge.draft { background: #78350f; color: #fed7aa; }
.qty { font-size: 24px; font-weight: 900; }
.duplicate-grid {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 12px;
  padding: 12px;
  border-radius: 8px;
  background: #111827;
}
.duplicate-grid span { color: #94a3b8; font-weight: 800; }
.duplicate-grid strong { font-size: 24px; }
.duplicate-shell button:first-of-type { background: #16a34a; }
.duplicate-shell button:nth-of-type(2) { background: #2563eb; }
.diagnostics-list {
  display: grid;
  grid-template-columns: minmax(120px, auto) 1fr;
  gap: 8px 12px;
  margin: 0;
  padding: 12px;
  border-radius: 8px;
  background: #111827;
}
.diagnostics-list dt {
  color: #94a3b8;
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}
.diagnostics-list dd {
  min-width: 0;
  margin: 0;
  overflow-wrap: anywhere;
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  color: #f8fafc;
}
.diagnostics-shell button:nth-last-child(2) { background: #2563eb; }

@media (max-width: 560px) {
  .app-shell { gap: 8px; padding: 10px; }
  .topbar { grid-template-columns: 1fr 1fr; }
  .sync-pill { grid-column: 1 / -1; padding: 8px 10px; }
  button { min-height: 48px; }
  .mode-row { gap: 7px; }
  .product-card { grid-template-columns: 72px 1fr; gap: 10px; padding: 10px; }
  .photo-slot { width: 72px; height: 72px; }
  h1 { font-size: 18px; }
  p { margin-top: 4px; }
  .actions { grid-template-columns: 1fr 1fr; }
  .manual-scan { grid-template-columns: 1fr auto; }
  .manual-panel summary, #retryCameraButton { min-height: 46px; }
  #retryCameraButton { min-width: 116px; }
  .manual-controls { grid-template-columns: 1fr; }
  .scanner-panel { height: clamp(118px, 18vh, 150px); }
  .auto-scan-badge { top: 8px; left: 8px; padding: 8px 10px; }
  .icon-button { top: 8px; right: 8px; min-height: 44px; min-width: 68px; }
  .pulse { left: 10px; right: 10px; bottom: 10px; padding: 10px; font-size: 18px; }
  .keypad { gap: 7px; }
  #quantityInput { min-height: 48px; font-size: 32px; }
  .keys { gap: 7px; }
  .keys button { min-height: 44px; font-size: 18px; }
  dialog {
    width: 100%;
    max-width: none;
    margin: auto 0 0;
    border-radius: 12px 12px 0 0;
  }
  .diagnostics-list { grid-template-columns: 1fr; }
  .line-list { max-height: 68vh; }
}

@keyframes success-flash {
  0% { background: #14532d; }
  100% { background: #07090c; }
}

@keyframes error-flash {
  0% { background: #7f1d1d; }
  100% { background: #07090c; }
}
