:root {
  --bg: #0f1220;
  --panel: #181c2e;
  --panel-2: #212641;
  --fg: #e8ecff;
  --muted: #8892b8;
  --accent: #6aa6ff;
  --danger: #ff6a7a;
  --success: #5ad39a;
  --border: #2b3150;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg); color: var(--fg);
  -webkit-text-size-adjust: 100%;
}

a { color: var(--accent); }
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; }
pre { white-space: pre-wrap; word-wrap: break-word; }

/* Topbar */
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 10px 16px;
  background: var(--panel); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 700; color: var(--fg); text-decoration: none; font-size: 18px; }
.topnav { margin-left: auto; display: flex; gap: 14px; flex-wrap: wrap; }
.topnav a, .topnav button { color: var(--muted); text-decoration: none; font-size: 14px; }
.topnav a:hover { color: var(--fg); }
.who { color: var(--muted); font-size: 14px; }
.inline { display: inline; margin: 0; padding: 0; }
.linklike {
  background: none; border: 0; color: var(--muted); cursor: pointer;
  font-size: 14px; padding: 0;
}

main { padding: 16px; max-width: 960px; margin: 0 auto; }

/* Cards */
.card { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 20px; margin-bottom: 20px; }
.card.narrow { max-width: 480px; margin-left: auto; margin-right: auto; }
h1 { margin: 0 0 8px; font-size: 22px; }
h2 { margin: 20px 0 10px; font-size: 18px; }

/* Forms */
form label { display: block; margin: 10px 0; color: var(--muted); font-size: 14px; }
form input, form textarea, form select {
  width: 100%; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--panel-2); color: var(--fg); font-size: 16px;
}
fieldset { border: 1px solid var(--border); border-radius: 8px; padding: 10px 14px; margin: 10px 0; }
legend { color: var(--muted); padding: 0 6px; font-size: 14px; }
.radio { display: inline-flex; align-items: center; gap: 6px; margin-right: 14px; color: var(--fg); }
.radio input { width: auto; }

button, .primary, .secondary, .danger {
  display: inline-block; padding: 10px 16px; border-radius: 8px; border: 1px solid transparent;
  cursor: pointer; font-size: 15px; text-decoration: none; text-align: center;
}
button.primary, a.primary {
  background: var(--accent); color: #0b1226; font-weight: 600; border-color: var(--accent);
}
button.secondary, a.secondary {
  background: transparent; color: var(--fg); border-color: var(--border);
}
button.danger { background: var(--danger); color: #120408; font-weight: 600; border-color: var(--danger); }
button { background: var(--panel-2); color: var(--fg); border-color: var(--border); }

.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px; }

.muted { color: var(--muted); }
.error { color: var(--danger); }
.success { color: var(--success); }

/* Key-value */
dl.kv { display: grid; grid-template-columns: max-content 1fr; column-gap: 14px; row-gap: 4px; margin: 10px 0; }
dl.kv dt { color: var(--muted); }

/* Tables */
table.data { width: 100%; border-collapse: collapse; margin-top: 10px; }
table.data th, table.data td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
table.data th { color: var(--muted); font-weight: 500; font-size: 13px; text-transform: uppercase; letter-spacing: 0.04em; }

/* Location item cards (tag/scan + admin/add footer) */
.location-list h2 { margin: 0 0 10px; }
.loc-scroll {
  display: flex; flex-direction: column; gap: 12px;
  max-height: 65vh; overflow-y: auto; padding-right: 4px;
}
.loc-card {
  display: grid; grid-template-columns: 64px 96px 1fr; gap: 12px;
  align-items: center; padding: 10px; border: 1px solid var(--border);
  border-radius: 10px; background: var(--panel-2);
  color: inherit; text-decoration: none;
}
.loc-card:hover { border-color: var(--accent); }
.loc-card-num { display: flex; flex-direction: column; align-items: flex-start; }
.loc-card-num strong { font-size: 22px; line-height: 1; }
.loc-card-num .small { font-size: 11px; margin-top: 4px; }
.loc-card-img img {
  width: 96px; height: 96px; object-fit: cover; border-radius: 8px;
  background: var(--panel);
}
.loc-card-img-empty {
  width: 96px; height: 96px; border-radius: 8px; background: var(--panel);
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; color: var(--muted);
}
.loc-card-title { font-weight: 500; line-height: 1.3; word-wrap: break-word; }
.small { font-size: 12px; }
.inline-delete { margin-top: 10px; }

/* Verify */
.notice {
  display: flex; align-items: center; gap: 10px;
  background: rgba(255, 196, 0, 0.10); border: 1px solid rgba(255, 196, 0, 0.35);
  padding: 10px 14px; border-radius: 8px; margin-bottom: 12px;
}
.prewarm-progress { margin-top: 16px; }
.progress-bar {
  width: 100%; height: 14px; background: var(--panel-2);
  border: 1px solid var(--border); border-radius: 8px; overflow: hidden;
}
.progress-fill {
  height: 100%; width: 0%; background: var(--accent);
  transition: width 0.6s ease;
}
.notice-warn {
  display: block;
  background: rgba(244, 114, 94, 0.12); border-color: rgba(244, 114, 94, 0.45);
}
.notice-warn strong { display: block; margin-bottom: 6px; }
.inline-url-retry { margin-top: 10px; }
.inline-url-retry input[type="url"] { width: 100%; }
.spinner {
  display: inline-block; width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid currentColor; border-top-color: transparent;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.variant-banner {
  background: rgba(106, 166, 255, 0.12); border: 1px solid rgba(106, 166, 255, 0.35);
  padding: 10px 14px; border-radius: 8px; margin-bottom: 12px;
}
.image-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; margin: 12px 0;
}
.image-grid img { width: 100%; height: auto; border-radius: 8px; background: var(--panel-2); }

/* Scan page */
.scan-wrap { max-width: 720px; margin: 0 auto; }
.scan-head { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; gap: 10px; flex-wrap: wrap; }
.scan-head-left { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.skip-form input { width: 6em; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

/* Edge-to-edge scanner on /tag/scan only */
body.scan-page main { padding: 8px; max-width: 100%; }
body.scan-page .scan-wrap { max-width: 100%; }

.scanner-viewport {
  position: relative; width: 100%; height: 65dvh; background: #000; border-radius: 12px; overflow: hidden;
}
.scanner-viewport video { width: 100%; height: 100%; object-fit: cover; }
.scanner-overlay {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; pointer-events: none;
}
.scanner-overlay .aim {
  width: 85%; height: 60%; border: 3px solid rgba(255,255,255,0.7); border-radius: 8px;
}
.scan-controls { display: flex; gap: 10px; margin: 10px 0; }
.manual-entry { margin-top: 14px; }
.inline-form { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; margin-bottom: 12px; }
.inline-form label { margin: 0; }
.row-2 { display: grid; grid-template-columns: minmax(120px, 1fr) 2fr; gap: 12px; }

/* Photo management on edit page */
.photo-slots { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; margin-top: 8px; }
.photo-slot { background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px; padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.photo-slot img { width: 100%; height: 140px; object-fit: cover; border-radius: 6px; background: #000; }
.photo-slot .slot-label { color: var(--muted); font-size: 13px; }
.photo-slot .slot-empty {
  width: 100%; height: 140px; display: flex; align-items: center; justify-content: center;
  color: var(--muted); background: #0b0e1c; border: 1px dashed var(--border); border-radius: 6px;
}
.photo-slot form { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.photo-slot form button { padding: 6px 10px; font-size: 13px; }
.photo-slot input[type=file] { font-size: 12px; flex: 1 1 auto; min-width: 0; }

/* Variant picker */
.variant-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; margin-top: 6px; }
.variant-option {
  display: flex; flex-direction: column; align-items: stretch; gap: 6px;
  padding: 8px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--panel-2); cursor: pointer;
}
.variant-option:has(input:checked) { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.variant-option.is-current { background: rgba(106, 166, 255, 0.08); }
.variant-option img { width: 100%; height: 90px; object-fit: contain; background: #0b0e1c; border-radius: 6px; }
.variant-option span { font-size: 13px; color: var(--fg); text-align: center; }
.variant-option input[type=radio] { width: auto; }

/* Instant variant switching: skeleton, error surface, global spinner.
   Skeleton placeholders are flat blocks — no shimmer keyframe because on
   warehouse wifi render time is dominated by the 5-20s scrape, not 16ms
   animation, and the extra CSS is visual noise on iPhone Safari. */
.skeleton {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: transparent;
}
.skeleton-text {
  display: block;
  min-height: 1.2em;
  margin-bottom: 10px;
}
.skeleton-img {
  width: 100%;
  height: 180px;
  background: var(--panel-2);
  border: 1px dashed var(--border);
}

/* Inline error surface shown when HTMX request errors out. Hidden by default
   — the variant radio's hx-on handler flips `hidden=false`. */
.variant-err {
  margin-top: 10px;
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}
.variant-err[hidden] { display: none; }

/* Global HTMX indicator: small fixed-position spinner that HTMX toggles via
   the `.htmx-request` class on elements with `hx-indicator` pointing here. */
#variant-spinner {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 100;
  opacity: 0;
  transition: opacity 200ms ease;
  pointer-events: none;
  background: var(--panel);
  color: var(--accent);
  border: 1px solid var(--border);
  border-radius: 50%;
  padding: 10px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}
#variant-spinner.htmx-request,
.htmx-request #variant-spinner {
  opacity: 1;
}
