/*
 * Hosted login pages — one design for every tenant.
 *
 * Every tenant's sign-in, sign-up, code, consent, passkey, reset and error
 * page loads this file. Each template used to carry its own copy of the CSS,
 * twelve to three hundred and forty lines apiece and no two identical, which is
 * why the pages read as fourteen different products. The look is defined here
 * once; the only thing that changes per tenant is the logo in the template.
 *
 * Actions are near-black rather than a brand colour. The pages sit beside
 * whatever logo a tenant uploads, and a fixed accent colour clashes with most
 * of them — an orange logo over a blue button is the case that prompted this.
 * Near-black sits comfortably beside any mark, and leaves the logo as the one
 * branded thing on the page.
 */

:root {
  --aa-bg: #f5f6f8;
  --aa-surface: #ffffff;
  --aa-border: #e4e7ec;
  --aa-border-strong: #d0d5dd;
  --aa-ink: #101828;
  --aa-ink-2: #475467;
  --aa-ink-3: #667085;
  --aa-placeholder: #98a2b3;
  --aa-action: #101828;
  --aa-action-hover: #1d2939;
  --aa-focus: rgba(16, 24, 40, 0.14);
  --aa-danger: #b42318;
  --aa-danger-bg: #fef3f2;
  --aa-danger-border: #fecdca;
  --aa-success: #067647;
  --aa-radius: 10px;
  --aa-control-h: 44px;
}

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

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

body {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
  background: var(--aa-bg);
  color: var(--aa-ink);
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
    'Helvetica Neue', Arial, sans-serif;
  font-size: 0.9375rem;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* --- The card ------------------------------------------------------------ */

.login-wrap {
  width: 100%;
  max-width: 400px;
  padding: 2rem 2.25rem 2.25rem;
  background: var(--aa-surface);
  border: 1px solid var(--aa-border);
  border-radius: 16px;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 12px 32px -12px rgba(16, 24, 40, 0.12);
}

.logo-wrap {
  display: flex;
  justify-content: center;
  margin-bottom: 1.25rem;
}

/* With the name under it, the logo and the name are one unit and sit closer;
   the heading keeps its distance from both. */
.logo-wrap:has(+ .brand-name) {
  margin-bottom: 0.875rem;
}

/* Whatever the tenant uploaded, held to one footprint so a wide wordmark and a
   square icon both sit well rather than one dwarfing the heading. */
.logo-wrap img {
  display: block;
  max-width: 180px;
  max-height: 52px;
  width: auto;
  height: auto;
  object-fit: contain;
}

/*
 * The tenant, above the heading that says what this page is.
 *
 * Every page used to lead with the tenant's name in the h2 and nothing else,
 * so all nine looked alike above the form and none of them answered "am I
 * signing in or signing up". The brand is already carried by the logo and the
 * address bar, so it takes the small line and the task takes the heading.
 */
.brand-name {
  margin-bottom: 0.25rem;
  text-align: center;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--aa-ink-3);
}

h2 {
  margin-bottom: 1.5rem;
  font-size: 1.375rem;
  font-weight: 650;
  letter-spacing: -0.015em;
  line-height: 1.25;
  text-align: center;
  color: var(--aa-ink);
  overflow-wrap: anywhere;
}

/* The heading is sometimes wrapped in a flex row that carries its own spacing.
   Not `h2.mb-3`: there the class *is* the heading's spacing — on consent and
   passkey — and zeroing it pressed the heading into the greeting under it. */
.d-flex > h2 {
  margin-bottom: 0;
}

/* The last block in a form carries no trailing space; the card's own padding
   ends the page. Consent wraps its buttons in a spaced block, which left a gap
   under them. */
form > .mb-3:last-child {
  margin-bottom: 0;
}

p {
  color: var(--aa-ink-2);
  font-size: 0.875rem;
}

p + p {
  margin-top: 0.375rem;
}

p strong,
p span {
  color: var(--aa-ink);
  font-weight: 600;
}

ul {
  color: var(--aa-ink-2);
  font-size: 0.875rem;
}

a {
  color: var(--aa-ink);
  font-weight: 600;
  text-decoration: underline;
  text-decoration-color: var(--aa-border-strong);
  text-underline-offset: 3px;
  transition: text-decoration-color 0.15s ease;
}

a:hover {
  text-decoration-color: currentColor;
}

/* --- Small utilities the templates already use --------------------------- */

.d-flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.justify-content-center { justify-content: center; }
.justify-content-end { justify-content: flex-end; }
.justify-content-between { justify-content: space-between; align-items: center; gap: 0.5rem; }
/* A link row loses its right-hand sign-up link when sign-up is closed; the
   link left behind sits centred rather than hanging on the left. */
.justify-content-between:has(> :only-child) { justify-content: center; }
.mb-3 { margin-bottom: 1.5rem; }
.mt-15 { margin-top: 0.75rem; }

/* --- Fields -------------------------------------------------------------- */

.form-group {
  margin-bottom: 1rem;
}

label {
  display: block;
  margin-bottom: 0.375rem;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--aa-ink);
}

.form-control {
  display: block;
  width: 100%;
  height: var(--aa-control-h);
  padding: 0 0.875rem;
  background: var(--aa-surface);
  border: 1px solid var(--aa-border-strong);
  border-radius: var(--aa-radius);
  color: var(--aa-ink);
  font: inherit;
  font-size: 0.9375rem;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  -webkit-appearance: none;
  appearance: none;
}

.form-control::placeholder {
  color: var(--aa-placeholder);
}

.form-control:hover {
  border-color: #b3bac5;
}

.form-control:focus {
  outline: none;
  border-color: var(--aa-ink);
  box-shadow: 0 0 0 4px var(--aa-focus);
}

.form-control[readonly] {
  background: var(--aa-bg);
  color: var(--aa-ink-2);
}

/* A field with the show-password eye inside its right edge. */
.input-with-icon {
  position: relative;
}

.input-with-icon .form-control {
  padding-right: 2.75rem;
}

.input-with-icon span {
  position: absolute;
  top: 0;
  right: 0;
  width: 44px;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--aa-ink-3);
  cursor: pointer;
  border-radius: 0 var(--aa-radius) var(--aa-radius) 0;
}

.input-with-icon span:hover svg path {
  fill: var(--aa-ink);
}

.input-with-icon.active svg path {
  fill: var(--aa-ink);
}

.form-group-inline {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.form-group-inline label,
.forgot-password {
  margin: 0;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--aa-ink-2);
}

.form-group-inline label a,
a.forgot-password {
  font-weight: 600;
  color: var(--aa-ink);
}

/* --- Messages ------------------------------------------------------------ */

/* Always in the markup, shown only when the server put a message in it. */
.error {
  display: none;
  margin-bottom: 1rem;
  padding: 0.625rem 0.75rem;
  background: var(--aa-danger-bg);
  border: 1px solid var(--aa-danger-border);
  border-radius: var(--aa-radius);
  color: var(--aa-danger);
  font-size: 0.8125rem;
  font-weight: 500;
  overflow-wrap: anywhere;
}

.error:not(:empty) {
  display: block;
}

.code-sent-note,
.verify-email-note {
  margin: -0.75rem 0 0.15rem;
  /* Left, not centred: everything under these notes shares one left edge, and
     a note that wraps to a second line is the only thing that breaks it. */
  text-align: left;
  color: var(--aa-ink-2);
}

/*
 * The address, on its own line under the sentence that introduces it.
 *
 * Inline, it broke the sentence across three ragged lines, and a long address
 * left a one word orphan after it. On its own line it wraps into itself
 * instead, and `anywhere` keeps an address with no spaces inside the card.
 */
.code-sent-email {
  margin: 0 0 1.25rem;
  text-align: left;
  font-weight: 600;
  overflow-wrap: anywhere;
  color: var(--aa-ink);
}

.mt-15:empty {
  display: none;
}

/* Password rules, written into the page by its own script as they are met. */
#passwordErrors {
  margin-top: 0.5rem;
}

#passwordErrors div {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.125rem 0;
  font-size: 0.8125rem;
}

#passwordErrors div::before {
  content: '';
  flex: 0 0 auto;
  width: 0.875rem;
  height: 0.875rem;
  background-position: center;
  background-repeat: no-repeat;
  background-size: contain;
}

.passed { color: var(--aa-success); }
.failed { color: var(--aa-danger); }

.passed::before {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%23067647'%3E%3Cpath fill-rule='evenodd' d='M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z' clip-rule='evenodd'/%3E%3C/svg%3E");
}

.failed::before {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%23b42318'%3E%3Cpath fill-rule='evenodd' d='M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z' clip-rule='evenodd'/%3E%3C/svg%3E");
}

/* --- Buttons ------------------------------------------------------------- */

button {
  font: inherit;
}

.primary-btn {
  margin-top: 0.25rem;
}

.primary-btn a {
  display: block;
  text-decoration: none;
}

.primary-btn button,
.btn-wrapper .fill-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
  height: var(--aa-control-h);
  padding: 0 1.25rem;
  background: var(--aa-action);
  border: 1px solid var(--aa-action);
  border-radius: var(--aa-radius);
  color: #ffffff;
  font-size: 0.9375rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.08);
  transition: background-color 0.15s ease, transform 0.05s ease, box-shadow 0.15s ease;
}

.primary-btn button:hover,
.btn-wrapper .fill-btn:hover {
  background: var(--aa-action-hover);
}

.primary-btn button:active,
.btn-wrapper button:active {
  transform: translateY(1px);
}

/* The secondary action: social sign-in, "deny", "skip", send a code instead. */
.btn-wrapper {
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
}

.btn-wrapper button,
.btn-wrapper .deny-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.625rem;
  width: 100%;
  height: var(--aa-control-h);
  padding: 0 1.25rem;
  background: var(--aa-surface);
  border: 1px solid var(--aa-border-strong);
  border-radius: var(--aa-radius);
  color: var(--aa-ink);
  font-size: 0.9375rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
  transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.05s ease;
}

.btn-wrapper button:hover,
.btn-wrapper .deny-button:hover {
  background: #f9fafb;
  border-color: #b3bac5;
}

.btn-wrapper button img {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

button:focus-visible,
a:focus-visible {
  outline: none;
  box-shadow: 0 0 0 4px var(--aa-focus);
}

.primary-btn button:focus-visible,
.btn-wrapper .fill-btn:focus-visible {
  box-shadow: 0 0 0 2px var(--aa-surface), 0 0 0 4px var(--aa-ink);
}

/* A button that reads as a link — "resend code". */
.link-button {
  padding: 0;
  background: none;
  border: none;
  color: var(--aa-ink);
  font-size: 0.875rem;
  font-weight: 600;
  text-decoration: underline;
  text-decoration-color: var(--aa-border-strong);
  text-underline-offset: 3px;
  cursor: pointer;
}

.link-button:hover {
  text-decoration-color: currentColor;
}

/* --- Alternatives: "or continue with" ------------------------------------ */

.social-login {
  margin-top: 1.5rem;
}

/*
 * A second block straight after the first is one more alternative, not a new
 * section: it drops its "or continue with" heading, so all that is left is a
 * button, and 1.5rem left it floating away from the button above it. Same gap
 * as two buttons inside one wrapper, so the alternatives read as one stack
 * however they are split up.
 */
.social-login + .social-login {
  margin-top: 0.625rem;
}

.social-login > p {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
  color: var(--aa-ink-3);
  font-size: 0.8125rem;
}

.social-login > p::before,
.social-login > p::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--aa-border);
}

.social-login > p span {
  color: var(--aa-ink-3);
  font-weight: 500;
}

.social-login form + form {
  margin-top: 0.625rem;
}

.social-login .btn-wrapper button span {
  color: var(--aa-ink);
  font-weight: 600;
}

/* --- Footer, and the terminal states ------------------------------------- */

.footer {
  margin-top: 1.25rem;
  text-align: center;
}

.footer p {
  color: var(--aa-ink-2);
  font-size: 0.875rem;
}

.success-card {
  text-align: center;
}

.success-card h2 {
  margin-bottom: 0.5rem;
}

.success-card p {
  margin-bottom: 1.5rem;
}

/* --- While a submitted form is on its way ------------------------------- */

/* See /js/form-pending.js. The button keeps its label and gains a spinner, so a
   slow sign-in reads as working rather than as a page that ignored the click. */
button.aa-pending {
  cursor: progress;
  opacity: 0.85;
}

button.aa-pending::after {
  content: '';
  width: 1em;
  height: 1em;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: aa-spin 0.7s linear infinite;
}

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

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
  }
  button.aa-pending::after {
    animation-duration: 2s;
  }
}

/* --- Phones -------------------------------------------------------------- */

/* The card becomes the page: a bordered box inside a phone screen spends a
   fifth of its width on margins and reads as a dialog floating over nothing. */
@media (max-width: 480px) {
  body {
    align-items: flex-start;
    padding: 0;
    background: var(--aa-surface);
  }
  .login-wrap {
    max-width: none;
    min-height: 100vh;
    min-height: 100dvh;
    padding: 2rem 1.25rem 2rem;
    border: none;
    border-radius: 0;
    box-shadow: none;
  }
}

/* Sign in with WhatsApp (whatsapp.hbs): steps, the Open WhatsApp button, a
   QR code for computers only, and the waiting line. */
.wa-steps { margin: 0 0 1rem; padding-left: 1.25rem; text-align: left; }
.wa-steps li { margin: 0.25rem 0; }
/* The main action, in WhatsApp's green, sized like the primary button. */
.primary-btn a.wa-open {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  height: var(--aa-control-h);
  padding: 0 1.25rem;
  background: #25D366;
  border-radius: var(--aa-radius);
  color: #ffffff;
  font-size: 0.9375rem;
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.08);
}
.primary-btn a.wa-open:hover { background: #1ebe5b; }
/* White glyph on the green button; the green file is for the login button. */
.wa-open img { width: 20px; height: 20px; filter: brightness(0) invert(1); }
/* The QR code is for a computer; on a phone the button opens WhatsApp. */
.wa-qr { display: none; margin: 1.25rem auto 0; text-align: center; }
.wa-qr svg { width: 180px; height: 180px; background: #fff; border-radius: 8px; }
.wa-qr p { font-size: 0.85rem; margin-top: 0.5rem; }
@media (min-width: 768px) and (hover: hover) { .wa-qr { display: block; } }
.wa-status { display: flex; align-items: center; justify-content: center; gap: 0.5rem; margin-top: 1.25rem; font-size: 0.9rem; }
.wa-dot { width: 8px; height: 8px; border-radius: 50%; background: #25D366; animation: wa-pulse 1.2s ease-in-out infinite; }
@keyframes wa-pulse { 50% { opacity: 0.3; } }
.wa-expired { display: none; }
