/* ═══════════ Reset & Tokens ═══════════ */
* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --text: #0f172a;
  --text-2: #64748b;
  --text-3: #94a3b8;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --primary-light: #eef2ff;
  --success: #10b981;
  --success-bg: #ecfdf5;
  --warning: #f59e0b;
  --warning-bg: #fffbeb;
  --danger: #ef4444;
  --danger-bg: #fef2f2;
  --shadow: 0 4px 16px rgba(15,23,42,0.06);
  --shadow-lg: 0 20px 40px -12px rgba(15,23,42,0.15);
  --radius: 16px;
  --radius-sm: 10px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Inter', Roboto, sans-serif;
}

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  font-size: 15px;
  line-height: 1.5;
  min-height: 100vh;
}

img, svg { max-width: 100%; display: block; }

.hidden { display: none !important; }

/* ═══════════ Topbar ═══════════ */
.topbar {
  background: #fff;
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
  backdrop-filter: saturate(180%) blur(8px);
}
.topbar-inner {
  max-width: 1040px; margin: 0 auto;
  padding: 12px 16px;
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px;
}
.brand {
  display: flex; align-items: center; gap: 8px;
  font-weight: 700; font-size: 0.95rem;
  letter-spacing: -0.01em;
  min-width: 0;
}
.brand-mark {
  width: 28px; height: 28px; border-radius: 8px;
  background: linear-gradient(135deg, var(--primary), #7c3aed);
  color: #fff; display: grid; place-items: center;
  font-weight: 700; font-size: 0.9rem;
  flex-shrink: 0;
}
.topbar-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.user-chip {
  background: var(--primary-light); color: var(--primary);
  padding: 5px 10px; border-radius: 999px;
  font-size: 0.75rem; font-weight: 600;
  max-width: 120px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ═══════════ Buttons ═══════════ */
button { font-family: inherit; cursor: pointer; border: none; transition: all 0.15s; }

.btn-primary {
  width: 100%; padding: 14px 20px;
  background: var(--primary); color: #fff;
  font-size: 0.98rem; font-weight: 600;
  border-radius: var(--radius-sm);
  box-shadow: 0 1px 2px rgba(79,70,229,0.2);
  min-height: 48px;
}
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }
.btn-primary:disabled { background: #c7d2fe; cursor: not-allowed; }
.btn-lg { padding: 15px 20px; font-size: 1rem; }

.btn-ghost {
  background: transparent; color: var(--text-2);
  padding: 8px 12px; font-size: 0.85rem;
  border-radius: 8px; font-weight: 500;
}
.btn-ghost:hover { background: #f1f5f9; color: var(--text); }

.btn-outline-danger {
  width: 100%; margin-top: 20px;
  padding: 13px 20px;
  background: transparent; color: var(--danger);
  border: 1.5px solid #fecaca;
  border-radius: var(--radius-sm);
  font-weight: 600; font-size: 0.95rem;
  min-height: 48px;
}
.btn-outline-danger:hover { background: var(--danger-bg); border-color: var(--danger); }

/* ═══════════ Layout ═══════════ */
.main {
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  padding: 20px 16px 48px;
}

/* ═══════════ Card ═══════════ */
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 24px 20px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.card-title { font-size: 1.25rem; font-weight: 700; letter-spacing: -0.02em; }
.card-subtitle { color: var(--text-2); font-size: 0.88rem; margin-top: 4px; margin-bottom: 22px; }

/* ═══════════ Inputs ═══════════ */
.field { margin-bottom: 18px; }
.field label {
  display: block; font-size: 0.78rem; font-weight: 600;
  color: var(--text-2); margin-bottom: 8px;
  text-transform: uppercase; letter-spacing: 0.03em;
}

.amount-input-wrap {
  position: relative; display: flex; align-items: center;
  background: #f8fafc;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color 0.15s, background 0.15s;
}
.amount-input-wrap:focus-within {
  border-color: var(--primary);
  background: #fff;
  box-shadow: 0 0 0 4px rgba(79,70,229,0.08);
}
.currency-prefix {
  padding: 0 4px 0 16px;
  font-size: 1.3rem; font-weight: 600; color: var(--text-2);
}
#amount {
  flex: 1; min-width: 0;
  padding: 15px 16px 15px 4px;
  border: none; background: transparent;
  font-size: 1.4rem; font-weight: 700; color: var(--text);
  outline: none; font-family: inherit;
  -moz-appearance: textfield;
  letter-spacing: -0.02em;
}
#amount::-webkit-outer-spin-button,
#amount::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
#amount::placeholder { color: #cbd5e1; font-weight: 600; }

/* ═══════════ Breakdown ═══════════ */
.breakdown {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin-bottom: 18px;
}
.breakdown-row {
  display: flex; justify-content: space-between;
  padding: 5px 0; font-size: 0.88rem; color: var(--text-2);
  gap: 8px;
}
.breakdown-row.total {
  border-top: 1px dashed var(--border-strong);
  margin-top: 6px; padding-top: 10px;
  font-weight: 700; color: var(--text); font-size: 0.98rem;
}
.breakdown-row.total span:last-child { color: var(--primary); }

/* ═══════════ QR Card ═══════════ */
.qr-card { position: relative; padding-top: 28px; overflow: hidden; }

.timer-bar {
  position: absolute; top: 0; left: 0; right: 0; height: 4px;
  background: #f1f5f9; overflow: hidden;
}
.timer-bar-fill {
  height: 100%; width: 100%;
  background: linear-gradient(90deg, var(--primary), #7c3aed);
  transition: width 1s linear;
}

.payee-block {
  display: flex; align-items: center; gap: 12px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}
.payee-avatar {
  width: 42px; height: 42px; border-radius: 12px;
  background: linear-gradient(135deg, var(--primary), #7c3aed);
  color: #fff; display: grid; place-items: center;
  font-weight: 700; font-size: 1rem;
  flex-shrink: 0;
}
.payee-info { display: flex; flex-direction: column; min-width: 0; }
.payee-label {
  font-size: 0.72rem; color: var(--text-3);
  text-transform: uppercase; letter-spacing: 0.05em; font-weight: 600;
}
.payee-name {
  font-weight: 700; color: var(--text); font-size: 0.95rem;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.amount-display {
  text-align: center; margin-bottom: 2px;
  letter-spacing: -0.03em;
}
.amount-display .currency {
  font-size: 1.3rem; font-weight: 600; color: var(--text-2);
  vertical-align: top; margin-right: 2px;
}
.amount-display .value { font-size: 2.2rem; font-weight: 800; color: var(--text); }

.amount-breakdown {
  text-align: center; color: var(--text-3);
  font-size: 0.82rem; margin-bottom: 20px;
}

/* ═══════════ QR Box — hardened for scannability ═══════════ */
.qr-wrapper {
  position: relative;
  width: 100%;
  max-width: 300px;
  aspect-ratio: 1 / 1;
  margin: 0 auto;
  padding: 10px;
  background: #ffffff;
  border-radius: 14px;
  border: 1px solid var(--border);
}

#qr-container {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #ffffff;
  overflow: hidden;
}

#qr-container svg {
  width: 100% !important;
  height: 100% !important;
  display: block;
  shape-rendering: crispEdges;
  image-rendering: pixelated;
  -ms-interpolation-mode: nearest-neighbor;
}

/* Remove any visual artifacts that could confuse scanners */
#qr-container svg path { shape-rendering: crispEdges; }

/* Corner brackets */
.corner {
  position: absolute;
  width: 20px; height: 20px;
  border: 3px solid var(--primary);
  border-radius: 6px;
  pointer-events: none;
  z-index: 2;
}
.corner.tl { top: -3px; left: -3px; border-right: none; border-bottom: none; }
.corner.tr { top: -3px; right: -3px; border-left: none; border-bottom: none; }
.corner.bl { bottom: -3px; left: -3px; border-right: none; border-top: none; }
.corner.br { bottom: -3px; right: -3px; border-left: none; border-top: none; }

.scan-hint {
  text-align: center; margin-top: 14px;
  color: var(--text-2); font-size: 0.82rem; font-weight: 500;
}

.app-row {
  display: flex; justify-content: center; gap: 6px;
  margin-top: 10px; flex-wrap: wrap;
}
.app-pill {
  padding: 4px 10px;
  background: #f1f5f9;
  color: var(--text-2);
  border-radius: 999px;
  font-size: 0.72rem; font-weight: 600;
}

/* ═══════════ Status Line ═══════════ */
.status-line {
  display: flex; align-items: center; justify-content: center;
  gap: 10px; margin-top: 18px;
  padding: 11px 14px;
  background: var(--warning-bg);
  border-radius: 12px;
  font-size: 0.88rem; font-weight: 500;
}
.status-dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--warning);
  flex-shrink: 0;
}
.status-dot.pending { animation: pulse 1.6s infinite ease-in-out; }
.status-dot.success { background: var(--success); animation: none; }
.status-dot.expired,
.status-dot.cancelled { background: var(--danger); animation: none; }

.status-line:has(.status-dot.success) { background: var(--success-bg); }
.status-line:has(.status-dot.expired),
.status-line:has(.status-dot.cancelled) { background: var(--danger-bg); }

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(245,158,11,0.6); }
  50% { box-shadow: 0 0 0 8px rgba(245,158,11,0); }
}

.status-text { color: #92400e; font-weight: 600; font-size: 0.85rem; }
.status-text.success { color: #065f46; }
.status-text.expired,
.status-text.cancelled { color: #991b1b; }

.timer-text {
  margin-left: auto; font-variant-numeric: tabular-nums;
  font-weight: 700; color: var(--text-2); font-size: 0.85rem;
  flex-shrink: 0;
}

/* ═══════════ Result Card ═══════════ */
.result-card { text-align: center; padding: 32px 20px; }
.result-icon {
  width: 64px; height: 64px; border-radius: 50%;
  margin: 0 auto 18px;
  display: grid; place-items: center;
  font-size: 1.8rem; font-weight: 700;
  background: var(--success-bg); color: var(--success);
}
.result-card.expired .result-icon,
.result-card.cancelled .result-icon {
  background: var(--danger-bg); color: var(--danger);
}
.result-title { font-size: 1.2rem; font-weight: 700; letter-spacing: -0.02em; margin-bottom: 6px; }
.result-message { color: var(--text-2); font-size: 0.88rem; margin-bottom: 22px; }
.result-details {
  text-align: left; margin-bottom: 18px;
  padding: 14px;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.result-details .breakdown-row { font-size: 0.85rem; }

/* ═══════════ Auth Page ═══════════ */
.auth-page {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 20px 16px;
  background: linear-gradient(180deg, #eef2ff 0%, #f4f6fb 100%);
}
.auth-card {
  background: var(--card);
  border-radius: 20px;
  padding: 32px 24px;
  max-width: 400px; width: 100%;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
  text-align: center;
}
.auth-logo { display: flex; justify-content: center; margin-bottom: 18px; }
.logo-mark {
  width: 52px; height: 52px; border-radius: 16px;
  background: linear-gradient(135deg, var(--primary), #7c3aed);
  color: #fff; display: grid; place-items: center;
  font-size: 1.5rem; font-weight: 800;
  box-shadow: 0 8px 20px -8px rgba(79,70,229,0.5);
}
.auth-title { font-size: 1.4rem; font-weight: 700; letter-spacing: -0.02em; margin-bottom: 4px; }
.auth-subtitle { color: var(--text-2); font-size: 0.88rem; margin-bottom: 26px; }
.auth-card .field { text-align: left; }
.auth-card input {
  width: 100%; padding: 13px 16px;
  border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  font-size: 1rem; font-family: inherit; color: var(--text);
  background: #f8fafc; outline: none;
  transition: border-color 0.15s, background 0.15s;
}
.auth-card input:focus {
  border-color: var(--primary); background: #fff;
  box-shadow: 0 0 0 4px rgba(79,70,229,0.08);
}
.auth-footer { margin-top: 18px; color: var(--text-3); font-size: 0.8rem; }

/* ═══════════ Alerts ═══════════ */
.alert {
  padding: 11px 14px;
  background: var(--danger-bg);
  color: #991b1b;
  border-radius: var(--radius-sm);
  font-size: 0.85rem; font-weight: 500;
  margin-bottom: 14px;
  border: 1px solid #fecaca;
}

/* ═══════════ Responsive Breakpoints ═══════════ */

@media (min-width: 480px) {
  .main { padding: 28px 20px 60px; }
  .card { padding: 28px 24px; }
  .amount-display .value { font-size: 2.6rem; }
  .qr-wrapper { max-width: 320px; padding: 12px; }
  .topbar-inner { padding: 14px 20px; }
}

@media (max-width: 360px) {
  body { font-size: 14px; }
  .main { padding: 16px 12px 40px; }
  .card { padding: 20px 16px; border-radius: 14px; }
  .amount-display .value { font-size: 2rem; }
  .amount-display .currency { font-size: 1.15rem; }
  .qr-wrapper { max-width: 260px; padding: 8px; }
  .brand { font-size: 0.9rem; }
  .brand-mark { width: 26px; height: 26px; font-size: 0.85rem; }
  .user-chip { max-width: 90px; font-size: 0.7rem; padding: 4px 8px; }
  .btn-ghost { padding: 6px 10px; font-size: 0.8rem; }
  .result-card { padding: 26px 16px; }
}

@media (max-height: 500px) and (orientation: landscape) {
  .main { padding: 12px 16px 24px; }
  .qr-wrapper { max-width: 220px; }
}

@media (min-width: 1024px) {
  .main { padding: 40px 20px 80px; }
}