/* Eberhardt's Shop VIN — dark shop UI */
:root {
  --bg: #0a0e16;
  --bg-elevated: #121826;
  --bg-card: #1a2233;
  --border: #2a3548;
  --text: #f2f4f8;
  --muted: #9aa3b5;
  --navy: #0d1b2a;
  --orange: #f59e0b;
  --orange-hot: #fbbf24;
  --orange-deep: #d97706;
  --danger: #ef4444;
  --ok: #22c55e;
  --radius: 14px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  --max: 480px;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: #05070c;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body {
  padding: var(--safe-top) 0 var(--safe-bottom);
}

.app {
  max-width: var(--max);
  margin: 0 auto;
  min-height: 100dvh;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  box-shadow: 0 0 0 1px #111, 0 0 80px rgba(0,0,0,0.6);
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px 10px;
  background: linear-gradient(180deg, #121a28 0%, var(--bg) 100%);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--orange);
  color: #111;
  font-weight: 800;
  font-size: 13px;
  display: grid;
  place-items: center;
  letter-spacing: -0.5px;
}

.brand h1 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.brand p {
  margin: 2px 0 0;
  font-size: 0.75rem;
  color: var(--muted);
}

.icon-btn {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font-size: 1.25rem;
  display: grid;
  place-items: center;
  cursor: pointer;
}

.icon-btn:active { transform: scale(0.96); }

main {
  flex: 1;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.panel { display: none; }
.panel.active { display: flex; flex-direction: column; gap: 16px; }

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.4;
}

.scanner-wrap {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  background: #000;
  border: 1px solid var(--border);
  aspect-ratio: 3 / 4;
  max-height: 55vh;
}

#reader, #nativeVideo {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  background: #000;
}

#nativeVideo { position: absolute; inset: 0; width: 100%; height: 100%; }

.scan-overlay {
  pointer-events: none;
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
}

.scan-frame {
  width: min(78%, 280px);
  aspect-ratio: 2.2 / 1;
  border: 3px solid var(--orange);
  border-radius: 12px;
  box-shadow: 0 0 0 9999px rgba(0,0,0,0.35);
}

.scan-status {
  margin: 0;
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
}

.btn-row {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.btn {
  appearance: none;
  border: none;
  border-radius: 14px;
  min-height: 54px;
  padding: 14px 18px;
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-decoration: none;
  color: inherit;
}

.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-primary {
  background: linear-gradient(180deg, var(--orange-hot), var(--orange));
  color: #111;
}

.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px dashed var(--border);
  min-height: 48px;
  font-weight: 600;
}

.manual-toggle {
  text-align: center;
}

.manual-box label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 8px;
}

.manual-box input,
.settings-box input {
  width: 100%;
  min-height: 52px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 1.15rem;
  letter-spacing: 0.08em;
  padding: 12px 14px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  text-transform: uppercase;
}

.settings-box input {
  letter-spacing: normal;
  text-transform: none;
  font-family: inherit;
  font-size: 1rem;
}

.manual-box input:focus,
.settings-box input:focus {
  outline: 2px solid var(--orange);
  outline-offset: 1px;
}

.result-vin {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: clamp(1.35rem, 6vw, 1.85rem);
  font-weight: 800;
  letter-spacing: 0.06em;
  word-break: break-all;
  text-align: center;
  line-height: 1.25;
  padding: 18px 8px;
  background: var(--bg);
  border-radius: 12px;
  border: 1px solid var(--border);
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  align-self: center;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
}

.badge-ok {
  background: rgba(34, 197, 94, 0.15);
  color: #86efac;
}

.badge-warn {
  background: rgba(245, 158, 11, 0.15);
  color: var(--orange-hot);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + var(--safe-bottom));
  transform: translateX(-50%) translateY(120%);
  background: #1f2937;
  color: #fff;
  padding: 12px 18px;
  border-radius: 999px;
  font-weight: 600;
  opacity: 0;
  transition: transform 0.2s ease, opacity 0.2s ease;
  z-index: 50;
  border: 1px solid var(--border);
  max-width: 90vw;
  text-align: center;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.settings-box h2 {
  margin: 0 0 8px;
  font-size: 1.15rem;
}

.settings-box p {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.4;
}

.footer-note {
  margin: 0;
  text-align: center;
  color: var(--muted);
  font-size: 0.8rem;
  padding-bottom: 8px;
}

#html5qr-region {
  width: 100%;
  min-height: 240px;
}

#html5qr-region video {
  border-radius: 0 !important;
  object-fit: cover !important;
}

.hidden { display: none !important; }

/* Photo packet for invoice email */
.photo-packet {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.photo-packet-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
}
.photo-slot {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 4px;
  border-top: 1px solid var(--border);
}
.photo-slot:first-of-type { border-top: none; padding-top: 0; }
.photo-slot-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}
.photo-slot-label {
  font-weight: 700;
  font-size: 0.95rem;
}
.photo-slot-meta {
  font-size: 0.75rem;
  color: var(--muted);
}
.photo-add-btn {
  position: relative;
  min-height: 48px;
  font-size: 0.95rem;
  cursor: pointer;
}
.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}
.thumb-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.thumb {
  position: relative;
  width: 88px;
  height: 88px;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: #000;
}
.thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.thumb-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  border: none;
  background: rgba(0,0,0,0.75);
  color: #fff;
  font-size: 1.1rem;
  line-height: 1;
  display: grid;
  place-items: center;
  cursor: pointer;
  padding: 0;
}
.thumb-remove:active { transform: scale(0.92); }
.note-label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 4px;
}
#packetNote {
  width: 100%;
  min-height: 72px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
  padding: 12px 14px;
  font-family: inherit;
  resize: vertical;
}
#packetNote:focus {
  outline: 2px solid var(--orange);
  outline-offset: 1px;
}
.download-fallback {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  border-radius: 12px;
  border: 1px dashed var(--orange);
  background: rgba(245, 158, 11, 0.08);
}
.download-fallback-title {
  margin: 0;
  font-size: 0.88rem;
  color: var(--orange-hot);
  line-height: 1.35;
  font-weight: 600;
}
.download-link {
  min-height: 44px;
  font-size: 0.95rem;
}

/* Live preview rotation (0/90/180/270) — outer layout stays portrait */
.scanner-wrap.rotate-0 {
  transform: none;
}
.scanner-wrap.rotate-90,
.scanner-wrap.rotate-180,
.scanner-wrap.rotate-270 {
  transform-origin: center center;
}
.scanner-wrap.rotate-90 {
  transform: rotate(90deg) scale(0.75);
}
.scanner-wrap.rotate-180 {
  transform: rotate(180deg);
}
.scanner-wrap.rotate-270 {
  transform: rotate(270deg) scale(0.75);
}

/* Landscape fallback when orientation.lock is unavailable (Safari tab) */
@media (orientation: landscape) {
  .header {
    padding: 6px 12px;
  }
  .brand-mark {
    width: 32px;
    height: 32px;
    font-size: 11px;
  }
  .brand h1 {
    font-size: 0.95rem;
  }
  .brand p {
    display: none;
  }
  .icon-btn {
    width: 40px;
    height: 40px;
  }
  main {
    padding: 8px 12px;
    gap: 8px;
  }
  .panel.active {
    gap: 8px;
  }
  #panelScan .hint {
    display: none;
  }
  .scanner-wrap {
    aspect-ratio: auto;
    max-height: none;
    height: 85vh;
    width: 100%;
  }
  .scanner-wrap.rotate-90,
  .scanner-wrap.rotate-270 {
    transform: rotate(90deg);
    /* In landscape, 90/270 can use full area without extra shrink */
  }
  .scanner-wrap.rotate-270 {
    transform: rotate(270deg);
  }
  .scan-status {
    font-size: 0.8rem;
  }
  .btn {
    min-height: 44px;
    padding: 10px 14px;
    font-size: 0.95rem;
  }
  .btn-ghost {
    min-height: 40px;
  }
  .btn-row {
    gap: 6px;
  }
  .manual-toggle {
    display: none;
  }
  .footer-note {
    display: none;
  }
}
