:root {
  --bg: #f5f5f5;
  --surface: #ffffff;
  --surface-hover: #f3f3f3;
  --border: #e6e6e6;
  --text: #111111;
  --text-muted: #6b6b6b;
  --accent: #e11d2e;
  --accent-hover: #c41222;
  --accent-soft: rgba(225, 29, 46, 0.12);
  --danger: #b91c1c;
  --danger-soft: rgba(185, 28, 28, 0.08);
  --ok: #15803d;
  --ok-soft: rgba(21, 128, 61, 0.1);
  --warn: #b45309;
  --warn-soft: rgba(180, 83, 9, 0.1);
  --radius: 8px;
  --radius-sm: 6px;
  --shadow: 0 1px 8px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 28px rgba(0, 0, 0, 0.08);
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  color: var(--text);
  background: var(--bg);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

body.no-scroll {
  position: fixed;
  left: 0;
  right: 0;
  width: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

a { color: var(--accent); }

.hidden { display: none !important; }
.muted { color: var(--text-muted); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 0.7rem 1.05rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
  transition: background 0.15s, border-color 0.15s, transform 0.15s, opacity 0.15s;
}
.btn:hover { transform: translateY(-1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text);
}
.btn-ghost:hover { background: var(--surface-hover); border-color: #ccc; }
.btn-danger-quiet {
  color: var(--danger);
  border-color: rgba(185, 28, 28, 0.28);
}
.btn-danger-quiet:hover {
  background: var(--danger-soft);
  border-color: var(--danger);
}

.location-details {
  margin-top: 0.15rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
}
.location-summary {
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.55rem 0.7rem;
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
  user-select: none;
  touch-action: manipulation;
}
.location-summary::-webkit-details-marker {
  display: none;
}
.location-summary::before {
  content: "";
  width: 0.45rem;
  height: 0.45rem;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(-45deg);
  transition: transform 0.15s ease;
  flex: 0 0 auto;
}
.location-details[open] > .location-summary::before {
  transform: rotate(45deg);
}
.location-details[open] > .location-summary {
  color: var(--text);
  border-bottom: 1px solid var(--border);
}
.location-picks {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  max-height: 9rem;
  overflow: auto;
  padding: 0.55rem 0.65rem 0.65rem;
}
.location-chip {
  margin: 0;
  padding: 0.35rem 0.65rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 0.8rem;
  cursor: pointer;
  touch-action: manipulation;
}
.location-chip:hover,
.location-chip.is-active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-hover);
}

.field { display: flex; flex-direction: column; gap: 0.35rem; margin-bottom: 0.85rem; }
.field.hidden,
.field[hidden] { display: none !important; }
.field > label,
.field > .field-label {
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: 600;
}
.field input,
.field select,
.field textarea {
  width: 100%;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  padding: 0.75rem 0.85rem;
  font: inherit;
  font-size: 16px;
  outline: none;
}
.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.field textarea { min-height: 110px; resize: vertical; }
.hint {
  margin: 0.15rem 0 0;
  font-size: 0.8rem;
  line-height: 1.4;
  color: var(--text-muted);
}

.alert,
.ok,
.warn {
  border-radius: var(--radius-sm);
  padding: 0.7rem 0.85rem;
  font-size: 0.9rem;
  margin-bottom: 0.85rem;
}
.alert {
  border: 1px solid rgba(185, 28, 28, 0.3);
  background: var(--danger-soft);
  color: var(--danger);
}
.ok {
  border: 1px solid rgba(21, 128, 61, 0.3);
  background: var(--ok-soft);
  color: var(--ok);
}
.warn {
  border: 1px solid rgba(180, 83, 9, 0.3);
  background: var(--warn-soft);
  color: var(--warn);
}

.login-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem 1.25rem 1.25rem;
  background: #fff;
}
.login-inner { width: 100%; max-width: 400px; }
.login-brand { text-align: center; margin-bottom: 1.5rem; }
.login-brand img {
  height: 56px;
  width: auto;
  max-width: min(100%, 320px);
  object-fit: contain;
}
.login-brand h1 {
  margin: 0.85rem 0 0;
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.login-brand p { margin: 0.4rem 0 0; color: var(--text-muted); }
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.login-panel { overflow: hidden; box-shadow: var(--shadow-lg); }
.login-panel-accent { height: 3px; background: var(--accent); }
.login-panel-body { padding: 1.5rem 1.4rem; }
.login-footer {
  margin-top: 1.35rem;
  text-align: center;
  font-size: 0.78rem;
  color: var(--text-muted);
}
.login-footer a,
.site-footer a {
  color: inherit;
  text-decoration: none;
}
.login-footer a:hover,
.site-footer a:hover {
  color: var(--accent);
}
.site-footer {
  text-align: center;
  font-size: 0.78rem;
  color: var(--text-muted);
  padding: 0.35rem 1.25rem 1.35rem;
}

.topbar {
  background: #fff;
  border-bottom: 2px solid var(--accent);
  box-shadow: none;
}
.topbar-inner {
  max-width: 960px;
  margin: 0 auto;
  padding: 0.85rem 1.25rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}
.topbar-brand {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  font-weight: 600;
}
.topbar-brand img {
  height: 38px;
  width: auto;
  max-width: min(58vw, 240px);
  object-fit: contain;
}
.topbar-brand span {
  color: var(--text-muted);
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border-left: 1px solid var(--border);
  padding-left: 0.85rem;
}
.topbar-user {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.9rem;
}
.topbar-user span { color: var(--text-muted); }

#settingsForm:has(#settingsShopBlock.hidden) + .settings-password,
#settingsForm:has(#settingsShopBlock[hidden]) + .settings-password {
  margin-top: 0;
  padding-top: 0;
  border-top: none;
}

.wrap {
  max-width: 960px;
  margin: 0 auto;
  padding: 1.75rem 1.25rem 2.5rem;
}

.page-head h1 { margin: 0 0 1rem; font-size: 1.45rem; }
.page-head p { margin: 0.4rem 0 1.25rem; color: var(--text-muted); }

.form-card { padding: 1.35rem 1.3rem 1.5rem; }
.form-card.is-loading {
  opacity: 0.72;
  pointer-events: none;
}
.form-card.is-loading #cancelEditBtn,
.form-card.is-loading #formError {
  pointer-events: auto;
}
.form-grid {
  display: grid;
  gap: 0 1.1rem;
}
@media (min-width: 800px) {
  .form-grid { grid-template-columns: 1fr 1fr; }
  .span-2 { grid-column: 1 / -1; }
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  font-size: 0.95rem;
  margin: 0.35rem 0 0.9rem;
}
.checkbox-row input { width: 1.1rem; height: 1.1rem; accent-color: var(--accent); }

.checkbox-list {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.75rem;
  background: var(--bg);
  max-height: 220px;
  overflow: auto;
}
.checkbox-list label {
  display: flex;
  gap: 0.55rem;
  align-items: center;
  font-size: 0.9rem;
  margin: 0.35rem 0;
  text-transform: none;
  letter-spacing: 0;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
}
.checkbox-list label.is-filtered-out { display: none; }
.checkbox-list input[type="checkbox"] {
  width: 1.1rem;
  height: 1.1rem;
  margin: 0;
  accent-color: var(--accent);
}
.checkbox-empty {
  margin: 0.35rem 0;
  font-size: 0.85rem;
}

.status-pills {
  display: flex;
  gap: 0.65rem;
  flex-wrap: wrap;
}
.status-pills label {
  flex: 1;
  min-width: 140px;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.35rem 0.65rem;
  padding: 0.75rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  cursor: pointer;
  text-transform: none;
  letter-spacing: 0;
  font-weight: 500;
}
.status-pills label strong { font-size: 0.92rem; }
.status-pills label span {
  grid-column: 2;
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 400;
}
.status-pills label:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.sheet-photo {
  padding: 0.9rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  display: grid;
  gap: 0.75rem;
}
.sheet-photo.drag {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.sheet-photo.is-busy {
  opacity: 0.92;
}
.photo-status {
  display: grid;
  gap: 0.45rem;
  padding: 0.7rem 0.8rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
}
.photo-status[hidden] { display: none !important; }
.photo-status p {
  margin: 0;
  font-size: 0.9rem;
  line-height: 1.35;
  color: var(--text);
  font-weight: 600;
}
.photo-status.is-busy {
  border-color: rgba(15, 118, 110, 0.35);
  background: var(--accent-soft);
}
.photo-status.is-ok {
  border-color: rgba(21, 128, 61, 0.28);
  background: var(--ok-soft);
}
.photo-status.is-err {
  border-color: rgba(185, 28, 28, 0.28);
  background: var(--danger-soft);
}
.photo-progress {
  height: 0.4rem;
  border-radius: 999px;
  background: rgba(28, 25, 23, 0.08);
  overflow: hidden;
}
.photo-progress[hidden] { display: none !important; }
.photo-progress-bar {
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 0.2s ease;
}
.photo-toolbar {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.45rem;
}
.photo-toolbar:has(#photoCamAgain:not([hidden])) {
  grid-template-columns: 1fr 1fr;
}
.photo-tool-btn {
  position: relative;
  margin: 0;
  min-height: 2.6rem;
  width: 100%;
  justify-content: center;
  padding: 0.55rem 0.7rem;
  font-size: 0.86rem;
}
.photo-tool-btn input[type="file"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}
#photoCamAgain {
  grid-column: 1 / -1;
}
.photo-empty-hint {
  margin: 0;
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.4;
}
.photo-empty-hint[hidden] { display: none !important; }
.photo-select-row {
  display: none;
  flex-wrap: wrap;
  gap: 0.45rem;
  padding-top: 0.15rem;
  border-top: 1px solid var(--border);
}
.photo-select-row:not([hidden]) { display: flex; }
.photo-select-row .btn {
  flex: 1 1 auto;
  min-height: 2.5rem;
  padding: 0.45rem 0.7rem;
  font-size: 0.84rem;
  justify-content: center;
}
.photo-thumbs {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
  gap: 0.55rem;
}
.photo-thumb {
  position: relative;
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  border: 2px solid var(--border);
  background: #fff;
  overflow: hidden;
}
.photo-thumb.active { border-color: var(--accent); }
.photo-thumb.is-checked {
  box-shadow: 0 0 0 2px rgba(15, 118, 110, 0.28);
}
.photo-thumb.is-cut::after {
  content: "";
  position: absolute;
  right: 6px;
  bottom: 6px;
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 999px;
  background: var(--ok);
  box-shadow: 0 0 0 2px #fff;
}
.photo-thumb-check {
  position: absolute;
  top: 6px;
  left: 6px;
  z-index: 2;
  width: 1.15rem;
  height: 1.15rem;
  margin: 0;
  accent-color: var(--accent);
}
.photo-thumb-img {
  display: block;
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: zoom-in;
}
.photo-thumb-img img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  pointer-events: none;
}
.photo-thumb-cap {
  position: absolute;
  right: 6px;
  top: 6px;
  min-width: 1.15rem;
  height: 1.15rem;
  padding: 0 0.25rem;
  border-radius: 999px;
  background: rgba(28, 25, 23, 0.72);
  color: #fff;
  font-size: 0.68rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.photo-lightbox-inner {
  width: min(96vw, 42rem);
  margin: auto;
  padding: 1rem;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  display: grid;
  gap: 0.75rem;
  justify-items: center;
}
.photo-lightbox-inner img {
  max-width: 100%;
  max-height: min(70vh, 34rem);
  object-fit: contain;
  background: #fff;
  border-radius: var(--radius-sm);
}
.photo-lightbox-name {
  margin: 0;
  font-family: ui-monospace, "Cascadia Mono", monospace;
  font-size: 0.85rem;
  color: var(--text-muted);
}
#photoLightbox {
  align-items: center;
  z-index: 75;
}

.scan-toolbar {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.55rem;
  margin: 0.85rem 0 0.35rem;
}
.scan-choice {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.15rem;
  margin: 0;
  padding: 0.85rem 0.95rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
  touch-action: manipulation;
  position: relative;
  min-height: 3.6rem;
  transition: border-color 0.15s, background 0.15s;
}
.scan-choice:hover,
.scan-choice:focus-visible {
  border-color: var(--accent);
  background: var(--accent-soft);
  outline: none;
}
.scan-choice strong {
  font-size: 0.95rem;
  font-weight: 700;
}
.scan-choice span {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 400;
}
.scan-choice input[type="file"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}
.scan-btn { position: relative; cursor: pointer; margin: 0; }
.scan-btn input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.shop-status {
  border-radius: var(--radius-sm);
  padding: 0.55rem 0.75rem;
  font-size: 0.82rem;
  margin: 0 0 0.85rem;
}
.shop-status.shop-status-ok {
  padding: 0.15rem 0 0.55rem;
  margin-bottom: 0.35rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  background: transparent;
  border: 0;
}
.shop-status.shop-status-ok .dot {
  width: 0.4rem;
  height: 0.4rem;
  background: var(--ok);
  opacity: 0.7;
}
.shop-status.warn {
  border: 1px solid rgba(180, 83, 9, 0.3);
  background: var(--warn-soft);
  color: var(--warn);
}
.shop-status.alert {
  border: 1px solid rgba(185, 28, 28, 0.3);
  background: var(--danger-soft);
  color: var(--danger);
}

.scan-overlay {
  position: fixed;
  inset: 0;
  z-index: 70;
  background: #050805;
  display: none;
  flex-direction: column;
  width: 100%;
  height: 100%;
  height: 100dvh;
  overscroll-behavior: none;
  touch-action: manipulation;
}
.scan-overlay.open { display: flex; }
.scan-overlay video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
}
.scan-window {
  position: absolute;
  left: max(5%, env(safe-area-inset-left, 0px) + 0.75rem);
  right: max(5%, env(safe-area-inset-right, 0px) + 0.75rem);
  top: calc(env(safe-area-inset-top, 0px) + 4.5rem);
  bottom: calc(11.5rem + env(safe-area-inset-bottom, 0px));
  height: auto;
  transform: none;
  border: 2px solid var(--accent);
  border-radius: 12px;
  box-shadow: 0 0 0 999px rgba(5, 8, 5, 0.55);
  overflow: hidden;
  pointer-events: none;
}
.scan-window-qr {
  left: 12%;
  right: 12%;
  top: 42%;
  bottom: auto;
  height: min(42vw, 42vh);
  max-height: 320px;
  aspect-ratio: 1;
  margin: 0 auto;
  transform: translateY(-50%);
}
.scan-laser {
  position: absolute;
  left: 4%;
  right: 4%;
  height: 2px;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent), 0 0 18px rgba(225, 29, 46, 0.55);
  animation: scanlaser 1.8s ease-in-out infinite;
}
@keyframes scanlaser {
  0%, 100% { top: 14%; }
  50% { top: 86%; }
}
.scan-hud {
  position: relative;
  z-index: 1;
  margin-top: auto;
  padding:
    0.85rem max(1rem, env(safe-area-inset-right, 0px))
    calc(1rem + env(safe-area-inset-bottom, 0px))
    max(1rem, env(safe-area-inset-left, 0px));
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  align-items: stretch;
  width: 100%;
  max-width: 32rem;
  margin-left: auto;
  margin-right: auto;
  background: linear-gradient(transparent, rgba(5, 8, 5, 0.94) 22%);
}
.scan-hud p {
  color: #d6d3d1;
  font-size: 0.88rem;
  text-align: center;
  max-width: none;
  margin: 0;
}
.scan-hud .scan-live-status {
  font-size: 0.78rem;
  color: #5eead4;
  min-height: 1.1em;
}
.scan-hud .btn-ghost {
  color: #f5f5f4;
  border-color: #57534e;
}
.scan-hud-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  width: 100%;
}
.scan-hud-actions #liveScanDone {
  grid-column: 1 / -1;
}
.scan-hud-actions #liveScanTorch[hidden] ~ #liveScanClose,
.scan-hud-actions #wcKeyScanClose:only-child {
  grid-column: 1 / -1;
}
.scan-hud-actions .btn.is-torch-on {
  background: rgba(250, 204, 21, 0.2);
  border-color: #facc15;
  color: #fef9c3;
}
.live-scan-hits {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  justify-content: center;
  width: 100%;
  max-width: none;
  max-height: min(30vh, 9.5rem);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}
.scan-chip {
  font-size: 0.78rem;
  padding: 0.28rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  touch-action: manipulation;
}
.live-scan-hits .scan-chip {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.28);
  color: #fff;
  font-family: ui-monospace, "Cascadia Mono", monospace;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  margin: 0;
  min-height: 2.5rem;
  padding: 0.55rem 0.9rem;
  font-size: 0.92rem;
  appearance: none;
  -webkit-appearance: none;
}
.live-scan-hits .scan-chip.is-picked,
.scan-assign-row.is-picked {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(15, 118, 110, 0.35);
}
.scan-join-preview {
  margin: 0.35rem 0 0;
  font-size: 0.88rem;
  font-family: ui-monospace, "Cascadia Mono", monospace;
  color: var(--accent);
}
.scan-review-row {
  grid-template-columns: 1fr;
  opacity: 1;
}
.scan-review-pick {
  display: grid;
  gap: 0.15rem;
  width: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.scan-review-row code {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: wrap;
}
.scan-review-row .btn {
  padding: 0.35rem 0.7rem;
  font-size: 0.78rem;
}
.scan-assign-row.is-assign {
  cursor: default;
}
.scan-chip-n {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.1rem;
  height: 1.1rem;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 0.68rem;
  font-weight: 700;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(28, 25, 23, 0.45);
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding: 1.5rem 1rem 2rem;
  padding:
    max(1rem, env(safe-area-inset-top, 0px))
    max(1rem, env(safe-area-inset-right, 0px))
    max(1.5rem, env(safe-area-inset-bottom, 0px))
    max(1rem, env(safe-area-inset-left, 0px));
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}
.modal-overlay.open { display: flex; }
.modal {
  width: 100%;
  max-width: 34rem;
  padding: 1.25rem 1.2rem 1.35rem;
  margin-top: 2rem;
}
.modal h2 { margin: 0 0 0.4rem; font-size: 1.25rem; }
.modal h3 { margin: 0 0 0.35rem; font-size: 1.05rem; }
.settings-password {
  margin-top: 1.25rem;
  padding-top: 1.1rem;
  border-top: 1px solid var(--border);
}
#passwordModal { z-index: 80; }
.scan-preview {
  display: block;
  width: 100%;
  max-height: 160px;
  object-fit: contain;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin: 0.75rem 0;
}
.scan-assign-list { display: grid; gap: 0.55rem; margin-top: 0.75rem; }
.scan-assign-row {
  display: grid;
  grid-template-columns: 1fr minmax(10rem, 12rem);
  gap: 0.55rem 0.75rem;
  align-items: center;
  padding: 0.85rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  cursor: pointer;
  touch-action: manipulation;
  min-height: 3.1rem;
}
.scan-assign-row code {
  display: block;
  font-size: 0.95rem;
  word-break: break-all;
}
.scan-assign-row .muted { font-size: 0.75rem; }
.scan-assign-row select {
  width: 100%;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 0.55rem 0.65rem;
  font: inherit;
  font-size: 16px;
}
@media (max-width: 640px) {
  .scan-assign-row { grid-template-columns: 1fr; }
}

.toast {
  position: fixed;
  bottom: calc(1.4rem + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%) translateY(140%);
  background: var(--text);
  color: #fff;
  padding: 0.7rem 1.1rem;
  border-radius: 999px;
  font-size: 0.82rem;
  transition: transform 0.2s ease, opacity 0.2s ease, visibility 0.2s;
  z-index: 80;
  max-width: calc(100% - 2rem);
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
}
.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
  visibility: visible;
}
.toast[hidden] {
  display: none !important;
}

.product-list {
  display: grid;
  gap: 0.65rem;
}
.product-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.75rem;
  align-items: center;
  padding: 0.85rem 0.95rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
}
.product-row-main {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  min-width: 0;
}
.product-thumb {
  width: 56px;
  height: 56px;
  object-fit: contain;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: #fff;
  flex-shrink: 0;
}
.product-row strong {
  display: block;
  font-size: 0.98rem;
}
.product-row .meta {
  margin-top: 0.25rem;
  color: var(--text-muted);
  font-size: 0.8rem;
}
.product-row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}
@media (max-width: 640px) {
  .product-row { grid-template-columns: 1fr; }
  .product-row-actions .btn {
    flex: 1 1 auto;
    min-height: 2.6rem;
  }

  .topbar-inner {
    padding: 0.7rem 0.9rem;
    padding-left: max(0.9rem, env(safe-area-inset-left, 0px));
    padding-right: max(0.9rem, env(safe-area-inset-right, 0px));
    gap: 0.55rem;
  }
  .topbar-brand span { display: none; }
  .topbar-user {
    width: 100%;
    flex-wrap: wrap;
    gap: 0.4rem;
  }
  .topbar-user span {
    width: 100%;
    font-size: 0.8rem;
  }
  .topbar-user .btn {
    flex: 1 1 calc(50% - 0.25rem);
    min-height: 2.55rem;
    padding: 0.5rem 0.65rem;
    font-size: 0.82rem;
  }

  .wrap {
    padding: 1.1rem 0.9rem calc(2rem + env(safe-area-inset-bottom, 0px));
    padding-left: max(0.9rem, env(safe-area-inset-left, 0px));
    padding-right: max(0.9rem, env(safe-area-inset-right, 0px));
  }

  .page-head h1 {
    font-size: 1.28rem;
    margin-bottom: 0.65rem;
  }
  .scan-toolbar {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.45rem;
  }
  .scan-choice {
    min-height: 3.4rem;
    padding: 0.75rem 0.8rem;
  }

  .form-card,
  .success-card {
    padding: 1rem 0.9rem 1.15rem;
  }
  .form-actions .btn {
    flex: 1 1 100%;
    min-height: 2.85rem;
  }
  .success-links .btn {
    flex: 1 1 100%;
    min-height: 2.75rem;
  }

  .status-pills label {
    min-width: 0;
    flex: 1 1 100%;
  }

  .photo-thumbs {
    grid-template-columns: repeat(auto-fill, minmax(78px, 1fr));
  }
  .photo-select-row .btn {
    flex: 1 1 calc(50% - 0.25rem);
  }

  .scan-window {
    top: calc(env(safe-area-inset-top, 0px) + 3.4rem);
    bottom: calc(13.5rem + env(safe-area-inset-bottom, 0px));
    left: max(4%, env(safe-area-inset-left, 0px) + 0.55rem);
    right: max(4%, env(safe-area-inset-right, 0px) + 0.55rem);
  }

  .modal {
    margin-top: 0.35rem;
    margin-bottom: 0.5rem;
    max-height: calc(100dvh - 1.5rem - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
    overflow: auto;
    -webkit-overflow-scrolling: touch;
  }
  .modal .form-actions .btn {
    flex: 1 1 auto;
    min-height: 2.75rem;
  }
  .scan-preview {
    max-height: 120px;
  }

  .login-page {
    padding:
      max(1.25rem, env(safe-area-inset-top, 0px))
      max(1rem, env(safe-area-inset-right, 0px))
      max(1.25rem, env(safe-area-inset-bottom, 0px))
      max(1rem, env(safe-area-inset-left, 0px));
    align-items: flex-start;
  }
}

@media (max-width: 380px) {
  .topbar-user .btn {
    flex: 1 1 100%;
  }
}

@media (max-height: 520px) and (orientation: landscape) {
  .scan-window {
    top: calc(env(safe-area-inset-top, 0px) + 0.45rem);
    bottom: calc(5.8rem + env(safe-area-inset-bottom, 0px));
    left: 26%;
    right: max(3%, env(safe-area-inset-right, 0px) + 0.4rem);
  }
  .scan-hud {
    padding-top: 0.4rem;
    padding-bottom: calc(0.45rem + env(safe-area-inset-bottom, 0px));
    gap: 0.35rem;
  }
  .live-scan-hits {
    max-height: 3.6rem;
  }
  .live-scan-hits .scan-chip {
    min-height: 2.1rem;
    padding: 0.35rem 0.7rem;
    font-size: 0.82rem;
  }
  .scan-hud-actions .btn {
    min-height: 2.35rem;
  }
  .scan-hud .scan-live-status {
    font-size: 0.72rem;
  }
}

@media (min-width: 900px) {
  .scan-hud-actions {
    max-width: 26rem;
    margin: 0 auto;
  }
  .live-scan-hits {
    max-width: 26rem;
    margin: 0 auto;
  }
}

.form-actions {
  display: flex;
  gap: 0.65rem;
  flex-wrap: wrap;
  margin-top: 0.5rem;
}

.success-card {
  padding: 1.35rem 1.3rem;
}
.success-card h2 { margin: 0 0 0.4rem; }
.success-card p { margin: 0 0 1rem; color: var(--text-muted); }
.success-links { display: flex; flex-wrap: wrap; gap: 0.6rem; }

.dot {
  display: inline-block;
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 999px;
  background: var(--text-muted);
  margin-right: 0.35rem;
  vertical-align: middle;
}
.dot.ok { background: var(--ok); }
.dot.warn { background: var(--warn); }
.dot.err { background: var(--danger); }
