* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  background: #eef3fb;
  color: #1d2b45;
}

body.auth-locked #mobileShell,
body.auth-locked #scannerModal {
  visibility: hidden;
  pointer-events: none;
}

.mobile-shell {
  width: min(100%, 980px);
  margin: 0 auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.page-head,
.card-head,
.photo-row,
.scanner-actions,
.scanner-card-head,
.manual-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.page-head {
  align-items: flex-start;
}

h1, h2, p {
  margin: 0;
}

h1 { font-size: 30px; font-weight: 900; }
h2 { font-size: 20px; font-weight: 900; }
p { margin-top: 4px; color: #4b5f83; }

.card {
  background: #fff;
  border: 1px solid #d6dfef;
  border-radius: 8px;
  padding: 14px;
  box-shadow: 0 10px 24px rgba(17, 38, 78, 0.08);
}

.form-grid {
  margin-top: 12px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}

label,
.photo-block {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

label span,
.field-label {
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0;
  color: #46597a;
}

input,
select,
button {
  font: inherit;
}

input,
select {
  width: 100%;
  min-height: 44px;
  border: 1px solid #bccae2;
  border-radius: 8px;
  padding: 10px 12px;
  background: #fff;
}

button,
.ghost-link {
  min-height: 44px;
  border-radius: 8px;
  border: 1px solid #99add0;
  background: #fff;
  color: #17335d;
  font-weight: 900;
  padding: 0 14px;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

button.primary-btn {
  background: #3567d6;
  border-color: #3567d6;
  color: #fff;
}

button.secondary-btn {
  background: #edf3ff;
}

.status-pill {
  font-size: 12px;
  font-weight: 900;
  border-radius: 999px;
  background: #edf3ff;
  color: #284b85;
  padding: 8px 12px;
}

.helper {
  font-size: 12px;
  color: #4b5f83;
}

#openScannerBtn {
  flex: 1 1 180px;
}

.photo-row {
  margin-top: 14px;
  align-items: stretch;
}

.photo-block {
  flex: 1 1 auto;
}

.photo-box {
  min-height: 180px;
  border: 2px dashed #9cb0d2;
  border-radius: 8px;
  background: #f5f8fe;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 12px;
  color: #556b8a;
  overflow: hidden;
}

.photo-box img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 6px;
}

.session-stats {
  width: 180px;
  display: grid;
  gap: 10px;
}

.stat {
  border: 1px solid #d6dfef;
  border-radius: 8px;
  padding: 14px 12px;
  background: #f8fbff;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat strong {
  font-size: 24px;
}

.stat span {
  font-size: 12px;
  color: #5a6d8c;
  text-transform: uppercase;
}

.tile-grid {
  margin-top: 12px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

.scan-tile {
  border: 1px solid #d6dfef;
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
  position: relative;
}

.recent-scan-tile {
  width: 100%;
  text-align: left;
  cursor: pointer;
  font: inherit;
}

.recent-scan-tile:active {
  transform: translateY(1px);
}

.scan-tile.unknown {
  border-color: #d06c7a;
  background: #fff3f5;
}

.scan-tile.shelf-break {
  border-style: dashed;
  background: #edf3ff;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 88px;
  font-weight: 900;
}

.scan-tile-image {
  height: 150px;
  background: #eef3fb;
  display: flex;
  align-items: center;
  justify-content: center;
}

.scan-tile-image img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.scan-tile-body {
  padding: 12px;
  display: grid;
  gap: 6px;
}

.scan-tile-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 2px;
}

.scan-edit-btn {
  min-height: 28px;
  padding: 0 10px;
  border-radius: 7px;
  border: 1px solid #b7c8e4;
  background: #f4f8ff;
  color: #1f3d69;
  font-size: 12px;
  font-weight: 800;
}

.scan-edit-panel {
  display: none;
  margin-top: 4px;
  padding: 10px;
  border: 1px solid #d5e0f1;
  border-radius: 8px;
  background: #f7faff;
  gap: 8px;
}

.scan-edit-panel.open {
  display: grid;
}

.scan-edit-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.scan-edit-grid label {
  display: grid;
  gap: 4px;
  font-size: 11px;
  font-weight: 800;
  color: #395073;
  text-transform: uppercase;
}

.scan-edit-grid input {
  width: 100%;
  min-height: 34px;
  padding: 0 8px;
  border: 1px solid #bccbe1;
  border-radius: 7px;
  font-size: 14px;
  font-weight: 700;
  color: #1d2b45;
  background: #fff;
  box-sizing: border-box;
}

.scan-edit-save {
  justify-self: end;
  min-height: 32px;
  padding: 0 12px;
  border-radius: 7px;
  border: none;
  background: #2f62c9;
  color: #fff;
  font-size: 12px;
  font-weight: 900;
}

.scan-remove-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 32px;
  min-height: 32px;
  padding: 0;
  border-radius: 8px;
  background: rgba(255,255,255,0.94);
  border: 1px solid #b8c6df;
  color: #18355f;
  font-weight: 900;
  z-index: 2;
}

.scan-title {
  font-size: 18px;
  font-weight: 900;
  line-height: 1.1;
}

.scan-meta {
  font-size: 13px;
  line-height: 1.35;
  color: #314768;
}

.scan-flag {
  font-size: 12px;
  font-weight: 900;
  color: #8b2338;
}

.scanner-modal {
  position: fixed;
  inset: 0;
  background: rgba(10, 16, 29, 0.78);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 14px;
  overflow: auto;
}

.scanner-modal.hidden {
  display: none;
}

.lookup-modal {
  position: fixed;
  inset: 0;
  z-index: 2600;
  background: rgba(8, 13, 24, 0.86);
  display: flex;
  justify-content: center;
  align-items: stretch;
  padding: 0;
}

.lookup-modal.hidden {
  display: none;
}

.lookup-shell {
  width: min(100%, 980px);
  height: 100%;
  overflow: auto;
  background: #eef3fb;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.lookup-head,
.lookup-section-head,
.lookup-actions,
.lookup-zoom-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.lookup-tools {
  display: grid;
  gap: 12px;
}

.lookup-scanner-host {
  min-height: 220px;
}

.lookup-section.hidden {
  display: none;
}

.lookup-match-list {
  display: grid;
  gap: 10px;
}

.lookup-match-card {
  border: 1px solid #d4def0;
  border-radius: 10px;
  background: #fff;
  padding: 12px;
  display: grid;
  gap: 8px;
}

.lookup-match-title {
  font-size: 15px;
  font-weight: 900;
  color: #1b3157;
}

.lookup-match-meta {
  font-size: 12px;
  color: #4b6288;
  line-height: 1.4;
}

.lookup-metric-controls {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid #d6dfef;
  border-radius: 10px;
  background: #f7faff;
}

.lookup-metric-controls.hidden {
  display: none;
}

.lookup-metric-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
}

.lookup-metric-row label {
  display: inline-flex;
  flex-direction: row;
  gap: 6px;
  align-items: center;
  font-size: 13px;
  font-weight: 800;
  color: #1f355b;
}

.lookup-image-scroll {
  overflow: auto;
  border: 1px solid #d6dfef;
  border-radius: 12px;
  background: #f7faff;
  min-height: 260px;
  max-height: 58vh;
  padding: 12px;
  touch-action: pan-x pan-y;
}

.lookup-image-stage {
  transform-origin: top left;
  width: max-content;
}

.lookup-image-stage img {
  display: block;
  max-width: none;
  width: auto;
  height: auto;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 10px 24px rgba(17, 38, 78, 0.12);
}

.lookup-detail-head,
.lookup-detail-row {
  display: grid;
  grid-template-columns: 110px 112px minmax(180px, 1fr) 80px;
  gap: 8px;
  align-items: start;
}

.lookup-detail-head {
  font-size: 11px;
  font-weight: 900;
  color: #506685;
  text-transform: uppercase;
  padding: 0 4px;
}

.lookup-detail-list {
  display: grid;
  gap: 6px;
}

.lookup-detail-row {
  border: 1px solid #d6dfef;
  border-radius: 8px;
  background: #fff;
  padding: 8px;
  font-size: 12px;
  color: #233958;
}

.lookup-detail-row.section {
  grid-template-columns: 1fr;
  font-weight: 900;
  background: #edf3ff;
}

.scanner-card {
  width: min(100%, 720px);
  max-height: calc(100vh - 28px);
  background: #fff;
  border-radius: 8px;
  padding: 14px;
  display: grid;
  gap: 10px;
  overflow: auto;
}

.scanner-host {
  min-height: 260px;
  height: min(48vh, 360px);
  border: 1px solid #d6dfef;
  border-radius: 8px;
  overflow: hidden;
  background: #f4f8ff;
}

.scanner-host video,
.scanner-host canvas {
  width: 100% !important;
  height: 100% !important;
  max-height: 100% !important;
  object-fit: cover;
}

.scanner-modal-actions {
  position: sticky;
  bottom: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  padding-top: 8px;
  background: #fff;
}

.current-shelf-pill {
  min-width: 86px;
  padding: 10px 12px;
  border: 1px solid #bccae2;
  border-radius: 8px;
  background: #edf3ff;
  color: #1d2b45;
  font-weight: 900;
  text-align: center;
  white-space: nowrap;
}

.manual-trigger-row {
  display: flex;
  justify-content: flex-end;
}

.manual-row.hidden {
  display: none;
}

#scanAckFlash {
  position: fixed;
  inset: 0;
  background: rgba(255,255,255,0.88);
  opacity: 0;
  pointer-events: none;
  z-index: 2500;
  transition: opacity 0.06s ease-in-out;
}

#scanAckFlash.active {
  opacity: 1;
}

.scan-notice {
  position: fixed;
  top: 18px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2600;
  width: min(calc(100% - 32px), 360px);
  padding: 14px 18px;
  border: 2px solid #8b2338;
  border-radius: 8px;
  background: #fff;
  color: #8b2338;
  box-shadow: 0 12px 28px rgba(10, 16, 29, 0.28);
  font-size: 18px;
  font-weight: 900;
  text-align: center;
}

.scan-notice.hidden {
  display: none;
}

.login-gate {
  position: fixed;
  inset: 0;
  background: rgba(12, 18, 31, 0.86);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 3000;
}

body.auth-locked .login-gate {
  display: flex;
}

.login-card {
  width: min(100%, 420px);
  background: #fff;
  border-radius: 8px;
  padding: 18px;
  display: grid;
  gap: 12px;
}

.icon-btn {
  width: 44px;
  padding: 0;
}

@media (max-width: 760px) {
  .page-head,
  .card-head,
  .photo-row,
  .scanner-actions,
  .scanner-card-head,
  .manual-row,
  .lookup-head,
  .lookup-section-head,
  .lookup-actions,
  .lookup-zoom-row {
    flex-direction: column;
    align-items: stretch;
  }

  .session-stats {
    width: 100%;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .scanner-actions > button,
  .manual-trigger-row > button,
  .manual-row > button,
  .lookup-actions > button,
  .lookup-zoom-row > button {
    width: 100%;
  }

  .scan-edit-grid {
    grid-template-columns: 1fr;
  }

  .scanner-modal {
    padding: 8px;
  }

  .scanner-card {
    max-height: calc(100vh - 16px);
    gap: 8px;
    padding: 10px;
  }

  .scanner-host {
    min-height: 230px;
    height: 42vh;
  }

  .scanner-modal-actions {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .scanner-modal-actions #saveScanBtnModal {
    grid-column: 1 / -1;
  }

  .current-shelf-pill {
    box-sizing: border-box;
  }

  .lookup-detail-head,
  .lookup-detail-row {
    grid-template-columns: 1fr;
  }
}
