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

:root {
  --navy: #1a2d4f;
  --navy-deep: #0d1b35;
  --navy-mid: #223660;
  --red: #bf1f3a;
  --red-light: #e8253f;
  --bg: #f0f4f8;
  --white: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: linear-gradient(160deg, #1e3358 0%, #0d1b35 100%);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 88px 24px 56px;
  position: relative;
  overflow-x: hidden;
}

/* ── Background orbs ── */
.orb {
  position: fixed;
  border-radius: 50%;
  pointer-events: none;
  z-index: 0;
}
.orb-1 {
  width: 700px; height: 700px;
  top: -250px; right: -200px;
  background: radial-gradient(circle, rgba(191,31,58,0.12) 0%, transparent 70%);
  animation: orbDrift 16s ease-in-out infinite alternate;
}
.orb-2 {
  width: 600px; height: 600px;
  bottom: -250px; left: -200px;
  background: radial-gradient(circle, rgba(34,54,96,0.5) 0%, transparent 70%);
  animation: orbDrift 22s ease-in-out infinite alternate-reverse;
}

@keyframes orbDrift {
  from { transform: translate(0, 0) scale(1); }
  to   { transform: translate(24px, 16px) scale(1.07); }
}

/* ── Nav ── */
nav {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 10;
  padding: 0 28px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo {
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--white);
  text-decoration: none;
  letter-spacing: -0.3px;
}
.logo span { color: var(--red); }

.nav-back {
  font-size: 0.8rem;
  font-weight: 600;
  color: rgba(255,255,255,0.45);
  text-decoration: none;
  padding: 6px 14px;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 8px;
  transition: all 0.15s;
}
.nav-back:hover { color: white; border-color: rgba(255,255,255,0.35); }

/* ── Card ── */
.card {
  position: relative;
  z-index: 1;
  background: var(--white);
  border-radius: 24px;
  padding: 40px;
  max-width: 440px;
  width: 100%;
  box-shadow: 0 32px 80px rgba(0,0,0,0.4), 0 0 0 1px rgba(255,255,255,0.05);
  animation: cardIn 0.55s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes cardIn {
  from { opacity: 0; transform: translateY(28px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ── QR State ── */
#qr-state { text-align: center; }

.connect-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #fff1f3;
  color: var(--red);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  padding: 5px 12px;
  border-radius: 100px;
  margin-bottom: 18px;
}

#qr-state h1 {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--navy);
  letter-spacing: -0.5px;
  margin-bottom: 8px;
  line-height: 1.2;
}

.subtitle {
  font-size: 0.875rem;
  color: var(--muted);
  line-height: 1.55;
  margin-bottom: 28px;
}

/* QR frame with corner brackets */
#qr-container {
  display: flex;
  justify-content: center;
  margin-bottom: 24px;
}

.qr-frame {
  position: relative;
  display: inline-block;
  padding: 14px;
  border-radius: 18px;
  background: var(--white);
  overflow: hidden;
}

.corner {
  position: absolute;
  width: 22px; height: 22px;
  z-index: 2;
}
.corner.tl { top: 5px; left: 5px;   border-top: 2.5px solid var(--red); border-left: 2.5px solid var(--red);   border-radius: 5px 0 0 0; }
.corner.tr { top: 5px; right: 5px;  border-top: 2.5px solid var(--red); border-right: 2.5px solid var(--red);  border-radius: 0 5px 0 0; }
.corner.bl { bottom: 5px; left: 5px;  border-bottom: 2.5px solid var(--red); border-left: 2.5px solid var(--red);   border-radius: 0 0 0 5px; }
.corner.br { bottom: 5px; right: 5px; border-bottom: 2.5px solid var(--red); border-right: 2.5px solid var(--red);  border-radius: 0 0 5px 0; }

.scan-line {
  position: absolute;
  left: 14px; right: 14px;
  height: 2px;
  background: linear-gradient(90deg, transparent 0%, var(--red) 50%, transparent 100%);
  border-radius: 1px;
  box-shadow: 0 0 10px rgba(191,31,58,0.55);
  animation: scanLine 2.6s ease-in-out infinite;
  z-index: 3;
}

@keyframes scanLine {
  0%   { top: 14px; opacity: 0; }
  8%   { opacity: 1; }
  92%  { opacity: 1; }
  100% { top: calc(100% - 16px); opacity: 0; }
}

/* QR loading state (shown until JS renders QR) */
.qr-placeholder {
  width: 200px; height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.qr-spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--navy);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* Steps */
.steps {
  text-align: left;
  background: #f8fafc;
  border-radius: 14px;
  padding: 16px 18px;
  margin-bottom: 22px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.step {
  display: flex;
  align-items: center;
  gap: 12px;
}

.step-num {
  flex-shrink: 0;
  width: 26px; height: 26px;
  background: var(--navy);
  color: white;
  border-radius: 50%;
  font-size: 0.72rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
}

.step-text {
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.4;
}
.step-text strong { color: var(--text); font-weight: 600; }

/* Status row */
.status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.status-waiting {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 0.82rem;
  color: var(--muted);
}

.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #f59e0b;
  flex-shrink: 0;
  animation: pulseDot 1.6s ease-in-out infinite;
}

@keyframes pulseDot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.35; transform: scale(0.8); }
}

.timer-pill {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--navy);
  background: #eef2ff;
  padding: 4px 11px;
  border-radius: 100px;
  white-space: nowrap;
}

#countdown { font-variant-numeric: tabular-nums; }

/* Error */
#error-msg {
  display: none;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 10px;
  padding: 12px 16px;
  font-size: 0.83rem;
  color: #dc2626;
  margin-top: 16px;
  text-align: left;
}

/* ── Success State ── */
.success-card {
  display: none;
  text-align: center;
  animation: stateIn 0.55s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes stateIn {
  from { opacity: 0; transform: scale(0.94) translateY(10px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.check-ring {
  width: 72px; height: 72px;
  margin: 0 auto 22px;
}

.check-svg { width: 72px; height: 72px; overflow: visible; }

.check-circle {
  stroke: #22c55e;
  stroke-width: 2;
  fill: none;
  stroke-linecap: round;
  stroke-dasharray: 151;
  stroke-dashoffset: 151;
  animation: strokeDraw 0.65s cubic-bezier(0.65, 0, 0.45, 1) 0.1s forwards;
}

.check-mark {
  stroke: #22c55e;
  stroke-width: 3;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 60;
  stroke-dashoffset: 60;
  animation: strokeDraw 0.4s cubic-bezier(0.65, 0, 0.45, 1) 0.7s forwards;
}

@keyframes strokeDraw { to { stroke-dashoffset: 0; } }

.success-card h2 {
  font-size: 1.55rem;
  font-weight: 800;
  color: var(--navy);
  letter-spacing: -0.4px;
  margin-bottom: 6px;
}

.success-org-text {
  font-size: 0.875rem;
  color: var(--muted);
  margin-bottom: 20px;
}

.user-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--navy);
  color: white;
  padding: 8px 18px;
  border-radius: 100px;
  font-size: 0.875rem;
  font-weight: 600;
  margin-bottom: 8px;
}

.role-chip {
  background: var(--red);
  color: white;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 100px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.redirect-msg {
  font-size: 0.82rem;
  color: var(--muted);
  margin-top: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.redirect-spinner {
  width: 14px; height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--muted);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
  flex-shrink: 0;
}

/* ── Upgrade State ── */
.upgrade-card {
  display: none;
  text-align: center;
  animation: stateIn 0.55s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.upgrade-icon {
  width: 72px; height: 72px;
  background: linear-gradient(135deg, #fffbeb, #fef3c7);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 22px;
  font-size: 32px;
  box-shadow: 0 6px 24px rgba(251,191,36,0.2);
}

.upgrade-card h2 {
  font-size: 1.55rem;
  font-weight: 800;
  color: var(--navy);
  letter-spacing: -0.4px;
  margin-bottom: 10px;
}

.upgrade-card p {
  font-size: 0.875rem;
  color: var(--muted);
  line-height: 1.6;
  margin-bottom: 28px;
}
.upgrade-card p strong { color: var(--text); }

.upgrade-btn {
  display: inline-block;
  background: linear-gradient(135deg, var(--red), #e8253f);
  color: white;
  font-weight: 700;
  font-size: 0.9rem;
  padding: 13px 32px;
  border-radius: 12px;
  text-decoration: none;
  box-shadow: 0 4px 16px rgba(191,31,58,0.35);
  transition: transform 0.15s, box-shadow 0.15s;
}
.upgrade-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 22px rgba(191,31,58,0.45);
}

/* ── Footer ── */
.page-footer {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  padding: 18px 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  z-index: 1;
}

.page-footer a {
  font-size: 0.78rem;
  color: rgba(255,255,255,0.28);
  text-decoration: none;
  transition: color 0.15s;
}
.page-footer a:hover { color: rgba(255,255,255,0.65); }
.page-footer .sep { color: rgba(255,255,255,0.12); font-size: 0.75rem; }
