/* ==========================================================================
   AtVITE shared sign-in pop-up
   --------------------------------------------------------------------------
   The pop-up mirrors the app's own sign-in card: a dark slate card, centred
   logo, icon-led fields, remember-me row and the QR / create-account actions.
   It is rendered by assets/auth-modal.js outside the React tree so it looks
   and behaves the same in the SPA shell, embedded module iframes and
   standalone section pages.

   The card is intentionally dark in both themes, exactly like the full
   sign-in page. Values are plain CSS (not Tailwind utilities) because module
   pages do not load the SPA's compiled utility stylesheet.
   ========================================================================== */

:root {
  --am-acc: #6366f1;          /* brand-500 */
  --am-acc-strong: #4f46e5;   /* brand-600 */
  --am-acc-soft: #818cf8;     /* brand-400 */
  --am-card: #ffffff;         /* slate-50 */
  --am-field: #f8fafc;        /* slate-50 input */
  --am-line: #e2e8f0;         /* slate-200 */
  --am-line-2: #cbd5e1;       /* slate-300 */
  --am-text: #0f172a;         /* slate-900 */
  --am-title: #020617;        /* slate-950 */
  --am-muted: #475569;        /* slate-600 */
  --am-dim: #64748b;          /* slate-500 */
  --am-placeholder: #94a3b8;  /* slate-400 */
  --am-danger: #dc2626;       /* red-600 */
  --am-danger-bg: rgba(239, 68, 68, .08);
  --am-danger-line: rgba(239, 68, 68, .22);
  --am-ok: #059669;           /* emerald-600 */
  --am-ok-bg: rgba(16, 185, 129, .08);
  --am-ok-line: rgba(16, 185, 129, .22);
  --am-backdrop: rgba(15, 23, 42, .55);
  --am-shadow: 0 25px 50px -12px rgba(15, 23, 42, .25), 0 8px 24px rgba(15, 23, 42, .12);
}

.dark {
  --am-card: #0f172a;         /* slate-900 */
  --am-field: #020617;        /* slate-950 */
  --am-line: #1e293b;         /* slate-800 */
  --am-line-2: #334155;       /* slate-700 */
  --am-text: #e2e8f0;         /* slate-200 */
  --am-title: #f1f5f9;        /* slate-100 */
  --am-muted: #94a3b8;        /* slate-400 */
  --am-dim: #64748b;         /* slate-500 */
  --am-placeholder: #475569;  /* slate-600 */
  --am-danger: #fb7185;       /* rose-400 */
  --am-danger-bg: rgba(244, 63, 94, .10);
  --am-danger-line: rgba(244, 63, 94, .20);
  --am-ok: #34d399;           /* emerald-400 */
  --am-ok-bg: rgba(16, 185, 129, .10);
  --am-ok-line: rgba(16, 185, 129, .20);
  --am-backdrop: rgba(2, 6, 23, .72);
  --am-shadow: 0 25px 50px -12px rgba(0, 0, 0, .60), 0 8px 24px rgba(0, 0, 0, .35);
}

html.am-lock {
  overflow: hidden !important;
}

/* --------------------------------------------------------------- backdrop */

.am-overlay {
  position: fixed;
  inset: 0;
  z-index: 2147483000;
  display: grid;
  place-items: center;
  padding: 22px 16px;
  background:
    radial-gradient(900px 460px at 18% 0%, rgba(99, 102, 241, .18), transparent 66%),
    radial-gradient(760px 420px at 88% 100%, rgba(139, 92, 246, .14), transparent 70%),
    var(--am-backdrop);
  -webkit-backdrop-filter: blur(10px) saturate(120%);
  backdrop-filter: blur(10px) saturate(120%);
  animation: am-fade .18s ease-out both;
  overflow: auto;
  overscroll-behavior: contain;
}

.am-overlay[hidden] { display: none !important; }

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

.am-card {
  position: relative;
  width: min(476px, 100%);
  margin: auto;
  padding: 32px;
  border: 1px solid var(--am-line);
  border-radius: 16px;
  background: var(--am-card);
  color: var(--am-text);
  box-shadow: var(--am-shadow);
  animation: am-rise .24s cubic-bezier(.2, .8, .2, 1) both;
  color-scheme: light;
}

.dark .am-card { color-scheme: dark; }

.am-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 30px;
  height: 30px;
  display: inline-grid;
  place-items: center;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--am-muted);
  cursor: pointer;
  transition: background .15s ease, color .15s ease;
}
.am-close:hover { background: var(--am-line); color: var(--am-title); }
.am-close svg { width: 16px; height: 16px; }

/* ------------------------------------------------------------ brand header */

.am-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
  text-align: center;
}

.am-logo {
  display: block;
  width: 44px;
  height: 44px;
  object-fit: contain;
  border-radius: 10px;
}

.am-title {
  margin: 0;
  font-size: 20px;
  line-height: 1.3;
  font-weight: 700;
  letter-spacing: -.01em;
  color: var(--am-title);
  text-align: center;
}

/* ------------------------------------------------------------------- alert */

.am-alert {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 0 0 16px;
  padding: 10px 12px;
  border: 1px solid var(--am-danger-line);
  border-radius: 8px;
  background: var(--am-danger-bg);
  color: var(--am-danger);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.5;
}
.am-alert svg { width: 15px; height: 15px; flex: 0 0 auto; margin-top: 1px; }
.am-alert[hidden] { display: none !important; }
.am-alert.ok {
  border-color: var(--am-ok-line);
  background: var(--am-ok-bg);
  color: var(--am-ok);
}
.am-alert a { color: inherit; font-weight: 700; }

/* ------------------------------------------------------------------- steps */

.am-step {
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.am-step[hidden] { display: none !important; }

.am-step-desc {
  margin: 0;
  text-align: center;
  font-size: 12px;
  line-height: 1.55;
  color: var(--am-muted);
}

.am-step-note {
  margin: 0;
  padding: 10px 12px;
  border: 1px solid var(--am-line);
  border-radius: 8px;
  background: var(--am-field);
  color: var(--am-muted);
  font-size: 11px;
  line-height: 1.55;
}
.am-step-note b { color: var(--am-text); }

/* ------------------------------------------------------------------- form */

.am-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.am-field { margin: 0; }

.am-control {
  position: relative;
  display: flex;
  align-items: center;
}
.am-control > svg.am-field-icon {
  position: absolute;
  left: 12px;
  width: 16px;
  height: 16px;
  color: var(--am-muted);
  pointer-events: none;
  transition: color .15s ease;
}
.am-control:focus-within > svg.am-field-icon { color: var(--am-acc); }

.am-control input {
  width: 100%;
  height: 38px;
  box-sizing: border-box;
  padding: 0 38px 0 36px;
  border: 1px solid var(--am-line);
  border-radius: 8px;
  background: var(--am-field);
  color: var(--am-text);
  font: inherit;
  font-size: 12px;
  line-height: 1.4;
  outline: 0;
  transition: border-color .15s ease;
}
.am-control input::placeholder { color: var(--am-placeholder); opacity: 1; }
.am-control input:focus { border-color: var(--am-acc); }
.am-control input:disabled { opacity: .6; }
.am-control input:-webkit-autofill,
.am-control input:-webkit-autofill:hover,
.am-control input:-webkit-autofill:focus {
  -webkit-text-fill-color: var(--am-text);
  caret-color: var(--am-text);
  box-shadow: 0 0 0 1000px var(--am-field) inset;
  transition: background-color 9999s ease-out 0s;
}

.am-password-toggle {
  position: absolute;
  right: 6px;
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--am-muted);
  cursor: pointer;
  transition: color .15s ease, background .15s ease;
}
.am-password-toggle:hover { color: var(--am-text); background: var(--am-line); }
.am-password-toggle svg { width: 16px; height: 16px; }

/* -------------------------------------------------------------- meta row */

.am-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0;
}

.am-check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  font-weight: 500;
  color: var(--am-muted);
  cursor: pointer;
  user-select: none;
}
.am-check input {
  appearance: none;
  width: 14px;
  height: 14px;
  margin: 0;
  border: 1px solid var(--am-line-2);
  border-radius: 3px;
  background: var(--am-field);
  cursor: pointer;
  position: relative;
  flex: 0 0 auto;
  transition: background .14s ease, border-color .14s ease;
}
.am-check input:checked {
  background: var(--am-acc);
  border-color: var(--am-acc);
}
.am-check input:checked::after {
  content: "";
  position: absolute;
  left: 4px;
  top: 1px;
  width: 3px;
  height: 7px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}
.am-check input:focus-visible { outline: 2px solid var(--am-acc-soft); outline-offset: 2px; }

.am-label-link {
  border: 0;
  padding: 0;
  background: none;
  color: var(--am-acc-soft);
  font: inherit;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
}
.am-label-link:hover { text-decoration: underline; }
.am-forgot { flex: 0 0 auto; }

/* ---------------------------------------------------------------- buttons */

.am-submit {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  height: 38px;
  margin: 0;
  border: 0;
  border-radius: 8px;
  background: var(--am-acc-strong);
  color: #fff;
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .01em;
  cursor: pointer;
  transition: background .15s ease, opacity .15s ease;
}
.am-submit:hover { background: var(--am-acc); }
.am-submit:active { transform: translateY(.5px); }
.am-submit:disabled { opacity: .5; cursor: default; transform: none; }
.am-submit svg { width: 16px; height: 16px; }

.am-spinner {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .35);
  border-top-color: #fff;
  animation: am-spin .7s linear infinite;
}

.am-secondary {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 38px;
  box-sizing: border-box;
  padding: 0 12px;
  border: 1px solid var(--am-line-2);
  border-radius: 8px;
  background: var(--am-line);
  color: var(--am-text);
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease, color .15s ease;
}
.am-secondary:hover { background: var(--am-line-2); }
.am-secondary:disabled { opacity: .5; cursor: default; }

.am-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0;
  color: var(--am-dim);
  font-size: 11px;
  font-weight: 500;
}
.am-divider::before,
.am-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--am-line);
}

/* ------------------------------------------------------------------- legal */

.am-legal {
  margin: 0;
  text-align: center;
  font-size: 10px;
  line-height: 1.6;
  color: var(--am-placeholder);
}
.am-inline-link {
  border: 0;
  padding: 0;
  background: none;
  color: var(--am-muted);
  font: inherit;
  text-decoration: none;
  cursor: pointer;
}
.am-inline-link:hover { text-decoration: underline; color: var(--am-text); }

/* -------------------------------------------------------------------- 2FA */

.am-totp-input {
  text-align: center;
  letter-spacing: .38em;
  font-size: 18px !important;
  font-weight: 700;
  padding-left: 34px !important;
  padding-right: 34px !important;
  font-variant-numeric: tabular-nums;
}

.am-back {
  align-self: center;
  margin: 0;
  border: 0;
  background: none;
  padding: 0;
  color: var(--am-dim);
  font: inherit;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
}
.am-back:hover { color: var(--am-muted); text-decoration: underline; }

/* --------------------------------------------------------------------- QR */

.am-qr-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.am-qr-canvas {
  display: block;
  width: 192px;
  height: 192px;
  background: #fff;
  border-radius: 12px;
}
.am-qr-canvas[hidden] { display: none !important; }

.am-qr-status {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 10px;
  color: var(--am-dim);
}
.am-qr-status[hidden] { display: none !important; }
.am-qr-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--am-acc);
  animation: am-pulse 1.4s ease-in-out infinite;
}

.am-qr-expired {
  padding: 16px;
  border: 1px solid var(--am-danger-line);
  border-radius: 12px;
  background: var(--am-danger-bg);
  text-align: center;
}
.am-qr-expired[hidden] { display: none !important; }
.am-qr-expired p {
  margin: 0 0 12px;
  color: var(--am-danger);
  font-size: 12px;
  line-height: 1.5;
}
.am-qr-retry {
  padding: 8px 16px;
  border: 0;
  border-radius: 8px;
  background: var(--am-acc-strong);
  color: #fff;
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: background .15s ease;
}
.am-qr-retry:hover { background: var(--am-acc); }

.am-qr-confirmed {
  padding: 16px;
  border: 1px solid var(--am-ok-line);
  border-radius: 12px;
  background: var(--am-ok-bg);
  text-align: center;
}
.am-qr-confirmed[hidden] { display: none !important; }
.am-qr-confirmed p {
  margin: 0;
  color: var(--am-ok);
  font-size: 12px;
  font-weight: 700;
}

/* --------------------------------------------------------------- animation */

@keyframes am-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes am-rise {
  from { opacity: 0; transform: translateY(10px) scale(.985); }
  to { opacity: 1; transform: none; }
}
@keyframes am-spin { to { transform: rotate(360deg); } }
@keyframes am-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: .45; transform: scale(.8); }
}

/* ------------------------------------------------------------------ mobile */

@media (max-width: 520px) {
  .am-overlay { padding: 12px; align-items: start; }
  .am-card { padding: 26px 20px 22px; border-radius: 14px; }
  .am-title { font-size: 19px; }
  .am-brand { gap: 10px; margin-bottom: 18px; }
  .am-close { top: 8px; right: 8px; }
  .am-step { gap: 18px; }
  .am-qr-canvas { width: 176px; height: 176px; }
}

@media (max-height: 680px) {
  .am-overlay { align-items: start; }
}

@media (prefers-reduced-motion: reduce) {
  .am-overlay, .am-card, .am-spinner, .am-qr-dot { animation: none !important; }
  .am-submit, .am-close, .am-secondary, .am-control input, .am-qr-retry { transition: none !important; }
}
