/* ==========================================================================
   Sign-up gate: <dialog> (bottom sheet on phones, centred on desktop), form
   fields, 6-digit OTP boxes, submit spinner, sticky sign-up bar, toast.
   Reusable on any gated page. Requires tokens.css + base.css.
   ========================================================================== */

/* Dialog ------------------------------------------------------------------- */
.gate {
  width: 100%;
  max-width: none;
  margin: auto 0 0;            /* bottom sheet */
  padding: 0;
  border: 0;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  background: var(--c-white);
  color: var(--c-text);
  box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.25);
  max-height: 92dvh;
  overflow: auto;              /* dialog scrolls with the on-screen keyboard open */
}
.gate::backdrop { background: rgba(20, 24, 28, 0.55); }
.gate__panel { position: relative; padding: var(--s-4) var(--s-3) var(--s-4); }
.gate__close {
  position: absolute; /* inside the panel, not page layout */
  top: var(--s-1);
  right: var(--s-1);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--tap-min);
  height: var(--tap-min);
  border-radius: 50%;
  color: var(--c-text-muted);
}
.gate__close svg { width: 20px; height: 20px; }
.gate__close:hover { background: var(--c-surface); color: var(--c-charcoal); }
.gate__screen { display: grid; gap: var(--s-2); }
.gate__screen[hidden] { display: none; }
.gate__title { font-size: 1.5rem; padding-right: var(--s-5); }
.gate__lead { color: var(--c-text-muted); }
.gate__alt { text-align: center; color: var(--c-text-muted); font-size: var(--fs-base); }
/* "OTP has been sent to your email" + the address on its own line + Wrong email? Change */
.gate__sent { display: grid; gap: 4px; }
.gate__email { font-weight: 700; color: var(--c-text); overflow-wrap: anywhere; }
/* sign-in: "We couldn't find this email" notice with its Sign up button */
.gate__notice {
  display: grid;
  gap: var(--s-2);
  padding: var(--s-2);
  background: var(--c-surface);
  border-left: 4px solid var(--c-red-text);
  border-radius: var(--radius-sm);
}
.gate__notice[hidden] { display: none; }
.gate__notice-text { font-weight: 700; color: var(--c-text); }
.gate__dev {
  font-size: var(--fs-sm);
  color: #7A5B00;
  background: #FFF6D6;
  border: 1px dashed #D9B45A;
  border-radius: var(--radius-sm);
  padding: var(--s-1) var(--s-2);
}
.gate__form-error:empty { display: none; }

@media (min-width: 640px) {
  .gate {
    width: min(440px, calc(100vw - 2 * var(--gutter)));
    margin: auto;              /* centred modal */
    border-radius: var(--radius-lg);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
  }
  .gate__panel { padding: var(--s-5) var(--s-4) var(--s-4); }
}

/* Fields ------------------------------------------------------------------- */
.field { display: grid; gap: 4px; }
.field__label { font-weight: 700; font-size: var(--fs-base); }
.field__input {
  width: 100%;
  min-height: 48px;
  padding: 0.5rem 0.75rem;
  font: inherit;
  font-size: 1rem;             /* 16px: iOS does not zoom */
  color: var(--c-text);
  background: var(--c-white);
  border: 1px solid #B9C0C8;
  border-radius: var(--radius-sm);
}
.field__input:focus { outline: 2px solid var(--c-focus); outline-offset: 1px; border-color: var(--c-focus); }
.field__input[aria-invalid="true"] { border-color: var(--c-red-text); }
.field__select { appearance: auto; }
.field__phone { display: flex; }
.field__prefix {
  display: inline-flex;
  align-items: center;
  padding: 0 0.75rem;
  color: var(--c-text-muted);
  background: var(--c-surface);
  border: 1px solid #B9C0C8;
  border-right: 0;
  border-radius: var(--radius-sm) 0 0 var(--radius-sm);
}
.field__phone .field__input { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.field__error { font-size: var(--fs-sm); color: var(--c-red-text); min-height: 0; }
.field__error:empty { display: none; }

/* 6-digit OTP boxes */
.otp { border: 0; padding: 0; margin: 0; min-width: 0; }
.otp__boxes { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: var(--s-1); }
.otp__box {
  width: 100%;
  min-width: 0;
  height: 56px;
  padding: 0;
  font: inherit;
  font-size: 1.5rem;
  text-align: center;
  color: var(--c-text);
  background: var(--c-white);
  border: 1px solid #B9C0C8;
  border-radius: var(--radius-sm);
}
.otp__box:focus { outline: 2px solid var(--c-focus); outline-offset: 1px; border-color: var(--c-focus); }
.otp.is-invalid .otp__box { border-color: var(--c-red-text); }

/* Submit button with spinner, block width */
.btn--block { width: 100%; }
.btn .spinner { display: none; width: 18px; height: 18px; border: 2px solid rgba(255,255,255,0.4); border-top-color: #fff; border-radius: 50%; animation: gate-spin 0.7s linear infinite; }
.btn.is-loading { pointer-events: none; opacity: 0.85; }
.btn.is-loading .spinner { display: inline-block; }
@keyframes gate-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .btn .spinner { animation-duration: 1.5s; } }

/* Sticky sign-up bar: phones + tablets, signed out only ------------------- */
.signup-bar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-2);
  min-height: 64px;
  padding: var(--s-1) var(--gutter);
  padding-bottom: max(var(--s-1), env(safe-area-inset-bottom));
  background: var(--c-charcoal);
  color: var(--c-white);
  box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.2);
}
.signup-bar { gap: var(--s-1); padding-right: calc(56px + var(--s-2) + var(--s-1)); }
.signup-bar .btn { flex: 1 1 0; min-width: 0; white-space: nowrap; }
.btn--on-dark { background: transparent; border-color: var(--c-white); color: var(--c-white); }
.btn--on-dark:hover { background: var(--c-white); border-color: var(--c-white); color: var(--c-charcoal); }
.signup-bar[hidden], .is-signed-in .signup-bar { display: none; }
/* keep content clear of the bar; while the bar is shown the WhatsApp button docks
   inside its right end (the bar reserves that space), so it never floats over the list */
.has-signup-bar main { padding-bottom: 72px; }
.has-signup-bar .whatsapp-fab {
  width: 48px;
  height: 48px;
  right: var(--gutter);
  bottom: calc(8px + env(safe-area-inset-bottom, 0px));
  box-shadow: none;
}
.has-signup-bar .whatsapp-fab svg { width: 26px; height: 26px; }
@media (min-width: 960px) {
  .signup-bar { display: none; }
  .has-signup-bar main { padding-bottom: 0; }
  .has-signup-bar .whatsapp-fab { width: 56px; height: 56px; right: var(--s-2); bottom: var(--s-2); box-shadow: var(--shadow-float); }
}

/* Toast ------------------------------------------------------------------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: var(--s-3);
  z-index: 60;
  transform: translate(-50%, 16px);
  max-width: calc(100vw - 2 * var(--gutter));
  padding: var(--s-1) var(--s-2);
  font-weight: 700;
  color: var(--c-white);
  background: var(--c-slate);
  border-radius: var(--radius);
  box-shadow: var(--shadow-float);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--ease), transform var(--ease);
}
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }
.has-signup-bar .toast { bottom: calc(72px + var(--s-2)); }
@media (min-width: 960px) { .has-signup-bar .toast { bottom: var(--s-3); } }

/* honeypot field: off-screen, not display:none (some bots skip hidden fields) */
.gate__hp { position: absolute; left: -9999px; top: auto; width: 1px; height: 1px; overflow: hidden; }

/* "No OTP yet?" help on the OTP screen */
.gate__nocode { margin: var(--s-2, 1rem) 0 0; padding: 0.75rem 1rem; background: var(--c-surface, #F5F6F7); border-radius: 6px; font-size: var(--fs-sm, 0.875rem); color: var(--c-text-muted, #5B6370); }
.gate__nocode[hidden] { display: none; }
.gate__nocode-text { margin: 0 0 0.25rem; }
.gate__nocode.is-strong { border-left: 4px solid var(--c-red-text, #D92B2B); color: var(--c-text, #22262B); }
.gate__nocode.is-strong .gate__nocode-text { font-weight: 700; }
