:root {
  --bg: #0b0f1a;
  --bg-elev: #131a2c;
  --bg-elev-2: #1b2440;
  --fg: #e6e9f5;
  --fg-dim: #8b93b0;
  --accent: #7c3aed;
  --accent-2: #06b6d4;
  --good: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 10px 30px -10px rgba(0, 0, 0, 0.5);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: radial-gradient(1200px 800px at 50% -200px, #1a2244 0%, var(--bg) 60%);
  color: var(--fg);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  min-height: 100svh;
  -webkit-font-smoothing: antialiased;
  /* block iOS double-tap-to-zoom and pinch zoom inside the PWA shell */
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

button { font-family: inherit; }

a { color: var(--accent-2); }

.app {
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  padding: calc(env(safe-area-inset-top, 0px) + 16px) calc(env(safe-area-inset-right, 0px) + 16px)
    calc(env(safe-area-inset-bottom, 0px) + 16px) calc(env(safe-area-inset-left, 0px) + 16px);
  gap: 16px;
  max-width: 640px;
  margin: 0 auto;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  letter-spacing: 0.2px;
}

.brand .dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 0 18px rgba(124, 58, 237, 0.6);
}

.iconbtn {
  background: var(--bg-elev);
  color: var(--fg);
  border: 1px solid rgba(255, 255, 255, 0.06);
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.iconbtn:hover { background: var(--bg-elev-2); }

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
}

.stat {
  background: var(--bg-elev);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  text-align: center;
}
.stat .label { font-size: 11px; color: var(--fg-dim); text-transform: uppercase; letter-spacing: 0.08em; }
.stat .value { font-size: 18px; font-weight: 700; margin-top: 2px; }

.card {
  background: var(--bg-elev);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}

.qr-stage {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 360px;
  padding: 12px;
}

.qr-wrap {
  position: relative;
  width: min(100%, 480px);
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
  transition: opacity 200ms ease, transform 200ms ease;
}

.qr-wrap svg {
  width: 100%;
  height: 100%;
}

.qr-meta {
  text-align: center;
  margin-top: 12px;
  color: var(--fg-dim);
  font-size: 13px;
}
.qr-meta .amount {
  color: var(--fg);
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 2px;
}

.qr-stage.is-claimed .qr-wrap { opacity: 0; transform: scale(0.96); }

.checkmark {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity 200ms ease;
}
.qr-stage.is-claimed .checkmark { opacity: 1; }

.checkmark .circle {
  width: 180px;
  height: 180px;
  border-radius: 50%;
  background: var(--good);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 60px rgba(34, 197, 94, 0.45);
  animation: pop 380ms cubic-bezier(0.2, 1.4, 0.5, 1) both;
}
.checkmark svg { width: 96px; height: 96px; }
.checkmark .path {
  stroke-dasharray: 60;
  stroke-dashoffset: 60;
  animation: draw 350ms 120ms ease-out forwards;
}
@keyframes pop {
  0% { transform: scale(0.3); opacity: 0; }
  60% { transform: scale(1.08); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}
@keyframes draw {
  to { stroke-dashoffset: 0; }
}

.empty {
  text-align: center;
  padding: 24px 18px;
  color: var(--fg-dim);
}
.empty h2 { color: var(--fg); margin: 0 0 8px; }
.empty p { margin: 0 0 16px; }

.row { display: flex; gap: 8px; }
.row > * { flex: 1; }

.btn {
  background: linear-gradient(135deg, var(--accent), #5b21b6);
  color: #fff;
  border: none;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.secondary { background: var(--bg-elev-2); color: var(--fg); border: 1px solid rgba(255, 255, 255, 0.06); }
.btn.danger { background: #7f1d1d; }
.btn.ghost { background: transparent; color: var(--fg-dim); border: 1px solid rgba(255,255,255,0.08); }

input, textarea, select {
  width: 100%;
  background: var(--bg);
  color: var(--fg);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 15px;
  font-family: inherit;
}
textarea { min-height: 100px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
label { display: block; font-size: 13px; color: var(--fg-dim); margin-bottom: 6px; }

.dialog-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 16px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease;
}
.dialog-backdrop.open { opacity: 1; pointer-events: auto; }
.dialog {
  background: var(--bg-elev);
  border-radius: var(--radius);
  width: 100%;
  max-width: 460px;
  padding: 18px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  max-height: calc(100svh - 32px);
  overflow-y: auto;
}
.dialog h2 { margin: 0 0 12px; font-size: 18px; }
.dialog .field + .field { margin-top: 12px; }
.dialog .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

.tabs { display: flex; gap: 4px; margin-bottom: 12px; background: var(--bg); padding: 4px; border-radius: var(--radius-sm); }
.tab {
  flex: 1; padding: 10px; text-align: center; border-radius: 10px; cursor: pointer; font-size: 14px; color: var(--fg-dim);
}
.tab.active { background: var(--bg-elev-2); color: var(--fg); }

.invoice {
  word-break: break-all;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  color: var(--fg-dim);
  background: var(--bg);
  padding: 10px;
  border-radius: 10px;
  margin-top: 12px;
  max-height: 120px;
  overflow-y: auto;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%) translateY(40px);
  background: var(--bg-elev-2);
  color: var(--fg);
  padding: 12px 16px;
  border-radius: 12px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms ease, transform 200ms ease;
  z-index: 100;
  max-width: calc(100vw - 32px);
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: #7f1d1d; }

.login-shell {
  min-height: 100svh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(env(safe-area-inset-top, 0px) + 20px) calc(env(safe-area-inset-right, 0px) + 20px)
    calc(env(safe-area-inset-bottom, 0px) + 20px) calc(env(safe-area-inset-left, 0px) + 20px);
}
.login-card { width: 100%; max-width: 380px; }
.login-card h1 { margin: 0 0 18px; font-size: 22px; }

@media (max-width: 380px) {
  .stats { grid-template-columns: 1fr 1fr; }
  .stats .stat:nth-child(3) { grid-column: span 2; }
}
