/* ============================================================================
   DealZgo Merchant PWA — Stylesheet
   Design system: deep ink navy + violet accent, flat bordered surfaces,
   one system sans pushed on weight/scale, monospace reserved for voucher
   codes only. See README-DEPLOYMENT.md "Rebranding" section to swap colours.
   ============================================================================ */

:root {
  /* Colour tokens */
  --ink: #12203D;
  --ink-soft: #47536B;
  --ink-faint: #8993A8;
  --bg: #F5F6F8;
  --surface: #FFFFFF;
  --border: #E1E4EA;
  --accent: #7C3AED;
  --accent-ink: #FFFFFF;
  --accent-soft: #F1E9FE;
  --success: #1C8A5C;
  --success-bg: #E7F6EE;
  --danger: #C6323A;
  --danger-bg: #FBEAEA;
  --focus-ring: #1C6FD6;

  /* Type */
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "JetBrains Mono", "DejaVu Sans Mono", Consolas, monospace;

  /* Scale */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;

  --shell-max: 480px;
}

/* Reset */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  line-height: 1.45;
}
h1, h2, h3, p { margin: 0; }
button { font-family: inherit; }
input, select { font-family: inherit; }
a { color: inherit; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
}

/* App shell */
#app {
  max-width: var(--shell-max);
  margin: 0 auto;
  min-height: 100%;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  position: relative;
}

.screen { display: none; flex: 1; flex-direction: column; }
.screen.is-active { display: flex; }

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-5);
  background: var(--ink);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar__brand { display: flex; align-items: center; gap: var(--space-2); }
.topbar__logo { width: 30px; height: 30px; border-radius: 8px; display: block; }
.topbar__title { font-weight: 800; font-size: 1.05rem; letter-spacing: -0.01em; }
.topbar__sub { font-size: 0.72rem; color: rgba(255,255,255,0.6); margin-top: -2px; }
.icon-btn {
  background: rgba(255,255,255,0.1);
  border: none;
  color: #fff;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.icon-btn:hover { background: rgba(255,255,255,0.18); }

/* Main content area */
.content {
  flex: 1;
  padding: var(--space-5) var(--space-5) calc(var(--space-7) + 64px);
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
}
.content--centered { justify-content: center; }
.content--narrow-pad { padding-bottom: var(--space-6); }

/* Buttons */
.btn {
  appearance: none;
  border: none;
  cursor: pointer;
  border-radius: var(--radius-md);
  font-weight: 700;
  font-size: 1rem;
  padding: 16px 20px;
  min-height: 52px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  width: 100%;
  transition: transform 0.08s ease, opacity 0.15s ease;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover:not(:disabled) { background: #6427C8; }
.btn-secondary { background: var(--surface); color: var(--ink); border: 1.5px solid var(--border); }
.btn-secondary:hover:not(:disabled) { border-color: var(--ink-faint); }
.btn-ghost { background: transparent; color: var(--ink-soft); padding: 10px; min-height: auto; width: auto; font-weight: 600; }
.btn-danger-outline { background: var(--surface); color: var(--danger); border: 1.5px solid var(--danger); }
.btn-sm { min-height: 40px; padding: 8px 14px; font-size: 0.9rem; }

/* Cards & surfaces */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
}

/* Login screen */
.login-hero { text-align: center; display: flex; flex-direction: column; align-items: center; gap: var(--space-2); }
.login-hero__logo { width: 64px; height: 64px; border-radius: 16px; margin-bottom: var(--space-2); }
.login-hero__title { font-size: 1.5rem; font-weight: 800; letter-spacing: -0.02em; }
.login-hero__subtitle { color: var(--ink-soft); font-size: 0.95rem; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-weight: 700; font-size: 0.88rem; color: var(--ink); }
.field-input-wrap { position: relative; display: flex; align-items: center; }
.field input[type="email"],
.field input[type="password"],
.field input[type="text"],
.field input[type="search"],
.field input[type="date"],
.field select {
  width: 100%;
  padding: 14px 16px;
  font-size: 1rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
}
.field input:focus, .field select:focus { border-color: var(--focus-ring); }
.field input.has-error { border-color: var(--danger); }
.field-error { color: var(--danger); font-size: 0.85rem; font-weight: 600; min-height: 1.1em; }
.field-toggle-visibility {
  position: absolute;
  right: 6px;
  background: none;
  border: none;
  color: var(--ink-soft);
  font-size: 0.85rem;
  font-weight: 700;
  padding: 8px 10px;
  cursor: pointer;
}
.field-row { display: flex; align-items: center; justify-content: space-between; }
.checkbox-row { display: flex; align-items: center; gap: 8px; font-size: 0.92rem; color: var(--ink-soft); }
.checkbox-row input { width: 18px; height: 18px; }
.link { color: var(--accent); font-weight: 700; font-size: 0.9rem; text-decoration: none; background: none; border: none; cursor: pointer; padding: 0; }

.support-box {
  text-align: center;
  font-size: 0.85rem;
  color: var(--ink-soft);
  padding-top: var(--space-4);
  border-top: 1px solid var(--border);
}
.support-box strong { color: var(--ink); display: block; margin-bottom: 4px; }
.btn-whatsapp {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  margin-top: 12px; padding: 12px 16px; min-height: 44px;
  background: #25D366; color: #fff; border-radius: 12px;
  font-weight: 700; font-size: 0.95rem; text-decoration: none;
}
.btn-whatsapp:hover, .btn-whatsapp:focus-visible { background: #1EBE5A; }

.banner {
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  font-size: 0.92rem;
  font-weight: 600;
  display: flex;
  gap: var(--space-2);
  align-items: flex-start;
}
.banner--danger { background: var(--danger-bg); color: var(--danger); }
.banner--success { background: var(--success-bg); color: var(--success); }
.banner[hidden] { display: none; }

/* Scan screen */
.scan-hero { text-align: center; display: flex; flex-direction: column; align-items: center; gap: var(--space-2); }
.scan-hero__icon {
  width: 72px; height: 72px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  margin-bottom: var(--space-2);
}
.scan-hero h1 { font-size: 1.25rem; font-weight: 800; letter-spacing: -0.01em; }
.scan-hero p { color: var(--ink-soft); font-size: 0.95rem; }

.empty-state { text-align: center; color: var(--ink-faint); font-size: 0.9rem; padding: var(--space-5) 0; }

/* Redeem screen */
.code-input {
  font-family: var(--font-mono);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-size: 1.15rem !important;
  text-align: center;
}
.scan-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  background: var(--accent-soft);
  color: var(--accent);
  border: 1.5px dashed var(--accent);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  font-weight: 700;
  cursor: pointer;
  width: 100%;
}
.scan-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.divider-row { display: flex; align-items: center; gap: var(--space-3); color: var(--ink-faint); font-size: 0.8rem; font-weight: 700; }
.divider-row::before, .divider-row::after { content: ""; flex: 1; height: 1px; background: var(--border); }

.scanner-overlay {
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 50;
  display: flex;
  flex-direction: column;
}
.scanner-overlay[hidden] { display: none; }
.scanner-overlay video { flex: 1; object-fit: cover; width: 100%; }
.scanner-overlay__frame {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 70%;
  max-width: 320px;
  aspect-ratio: 1;
  border: 3px solid var(--accent);
  border-radius: var(--radius-lg);
  box-shadow: 0 0 0 999px rgba(0,0,0,0.45);
}
.scanner-overlay__bar {
  position: absolute;
  top: 0; left: 0; right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-5);
  color: #fff;
  z-index: 2;
}
.scanner-overlay__hint {
  position: absolute;
  bottom: var(--space-6);
  left: 0; right: 0;
  text-align: center;
  color: #fff;
  font-size: 0.9rem;
  font-weight: 600;
}

/* Voucher detail card (validation result) */
.voucher-card { display: flex; flex-direction: column; gap: var(--space-3); }
.voucher-card__code { font-family: var(--font-mono); font-size: 1.1rem; font-weight: 800; letter-spacing: 0.03em; }
.voucher-card__offer { font-size: 1.15rem; font-weight: 800; }
.voucher-meta { display: flex; flex-direction: column; gap: var(--space-2); }
.voucher-meta__row { display: flex; justify-content: space-between; font-size: 0.9rem; border-top: 1px solid var(--border); padding-top: var(--space-2); }
.voucher-meta__row dt { color: var(--ink-soft); font-weight: 600; }
.voucher-meta__row dd { margin: 0; font-weight: 700; }
.status-badge { display: inline-flex; padding: 4px 10px; border-radius: 999px; font-size: 0.75rem; font-weight: 800; }
.status-badge--active { background: var(--success-bg); color: var(--success); }
.status-badge--expired, .status-badge--redeemed { background: var(--danger-bg); color: var(--danger); }

/* Tickable voucher on a customer merchant-QR scan */
.voucher-pick { display: flex; gap: var(--space-3); align-items: flex-start; margin-top: var(--space-3); cursor: pointer; }
.voucher-pick.is-selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.voucher-pick.is-disabled { opacity: 0.55; cursor: not-allowed; }
.voucher-pick__box { width: 22px; height: 22px; margin: 2px 0 0; flex: none; accent-color: var(--accent); }
.voucher-pick__body { flex: 1; min-width: 0; }
.voucher-pick__reason { margin-top: var(--space-2); color: var(--danger); font-size: 0.85rem; font-weight: 600; }

/* Redemption result */
.result-hero { display: flex; flex-direction: column; align-items: center; text-align: center; gap: var(--space-3); padding-top: var(--space-5); }
.result-hero__icon {
  width: 92px; height: 92px;
  border-radius: 50%;
  background: var(--success-bg);
  display: flex; align-items: center; justify-content: center;
  color: var(--success);
}
.result-hero__title { font-size: 1.4rem; font-weight: 800; letter-spacing: -0.01em; }
.result-hero__sub { color: var(--ink-soft); }
.result-hero__icon.is-error { background: var(--danger-bg); color: var(--danger); }
.result-hero__icon.is-info { background: var(--accent-soft); color: var(--accent); }
.result-hero__sub { max-width: 34ch; }
.result-hero__hint {
  margin-top: var(--space-2);
  padding: var(--space-3) var(--space-4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--ink-soft);
  font-size: 0.9rem;
  max-width: 36ch;
}

.sticky-actions {
  position: sticky;
  bottom: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: var(--space-4) var(--space-5) calc(var(--space-4) + env(safe-area-inset-bottom));
  max-width: var(--shell-max);
  margin: 0 auto;
  width: 100%;
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 92px;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 12px 18px;
  border-radius: 999px;
  font-size: 0.88rem;
  font-weight: 600;
  box-shadow: 0 8px 24px rgba(0,0,0,0.25);
  z-index: 60;
  max-width: 90%;
  text-align: center;
}
.toast[hidden] { display: none; }
.toast--action { display: flex; align-items: center; gap: 12px; border-radius: var(--radius-md); }
.toast--action button { background: var(--accent); color: #fff; border: none; border-radius: 8px; padding: 8px 12px; font-weight: 700; font-size: 0.82rem; }

/* Loading spinner */
.spinner {
  width: 20px; height: 20px;
  border: 2.5px solid rgba(255,255,255,0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
.spinner--dark { border-color: rgba(18,32,61,0.2); border-top-color: var(--ink); }
@keyframes spin { to { transform: rotate(360deg); } }

.loading-block { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--space-3); padding: var(--space-7) 0; color: var(--ink-soft); }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0,0,0,0); white-space: nowrap; border: 0; padding: 0; margin: -1px;
}

/* Install prompt — bottom sheet shown on open until the app is installed (app.js initInstallPrompt) */
.install-sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40; /* under the QR scanner (50) and toasts (60) */
  display: flex;
  justify-content: center;
  padding: 0 var(--space-3) calc(var(--space-3) + env(safe-area-inset-bottom));
  pointer-events: none;
  animation: install-sheet-in 0.25s ease-out;
}
.install-sheet__card {
  pointer-events: auto;
  width: 100%;
  max-width: var(--shell-max);
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: 0 -6px 30px rgba(18, 32, 61, 0.18);
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}
body[data-screen="confirm"] .install-sheet,
body[data-screen="result"] .install-sheet { display: none; }
.install-sheet__head { display: flex; gap: var(--space-3); align-items: flex-start; }
.install-sheet__icon { width: 48px; height: 48px; border-radius: var(--radius-md); flex-shrink: 0; }
.install-sheet__title { font-weight: 700; font-size: 1rem; margin-bottom: 2px; }
.install-sheet__text { font-size: 0.85rem; color: var(--ink-soft); line-height: 1.4; }
.install-sheet__cta { text-decoration: none; text-align: center; }
.install-sheet__later {
  background: none;
  border: none;
  color: var(--ink-soft);
  font-weight: 600;
  font-size: 0.85rem;
  padding: var(--space-1);
  cursor: pointer;
}
@keyframes install-sheet-in {
  from { transform: translateY(24px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .install-sheet { animation: none; }
}

@media (min-width: 560px) {
  .content { padding-left: var(--space-6); padding-right: var(--space-6); }
}
