/* Unified Connect — AUTHENTICATION UI · SHARED BASE LAYER
 * ============================================================
 * The ONE shared stylesheet for the authentication component.
 *
 * Architecture (two layers only):
 *   1. assets/css/auth-base.css      → design tokens, internal reset,
 *                                      direction, shared component
 *                                      primitives (form/inputs/buttons/
 *                                      methods/messages/spinner), a11y.
 *   2. templates/{id}/style.css       → the ACTIVE template's COMPLETE
 *                                      visual design (layout, surfaces,
 *                                      theming, responsive, dark mode).
 *                                      Loaded via wp_enqueue_style() for
 *                                      the active template only.
 *
 * Isolation: EVERY selector is scoped under `.uc-auth` (specificity
 * ≥ (0,2,0)). The widget root carries BOTH `id="uc-auth"` (JS boot
 * contract) and `class="uc-auth"` (CSS contract) — these must never
 * be separated, or the whole component loses its styling.
 *
 * No global element selectors: body/html/header/footer/form/input/
 * button are NEVER styled directly. Theme rules like
 * `button{background:white;color:white}` cannot win against the
 * scoped, token-driven declarations below.
 *
 * Direction: the `dir` attribute is set by the renderer from
 * is_rtl(); logical properties (margin-inline, inset-inline,
 * text-align:start) carry RTL/LTR without duplicated rules.
 * ============================================================ */

/* ======================== 1. TOKENS ======================== */
.uc-auth {
  /* Templates override these via --uc-tpl-* custom properties on the
     template root element (values inherit down into .uc-auth). */
  --uc-primary: var(--uc-tpl-primary-color, #b0004a);
  --uc-primary-hover: var(--uc-tpl-primary-hover, #8f003c);
  --uc-primary-active: var(--uc-tpl-primary-active, #6d002e);
  --uc-primary-text: #ffffff;
  --uc-primary-soft: color-mix(in srgb, var(--uc-primary) 8%, transparent);
  --uc-primary-soft-strong: color-mix(in srgb, var(--uc-primary) 16%, transparent);
  --uc-bg: var(--uc-tpl-surface, #ffffff);
  --uc-surface-2: #f8fafc;
  --uc-text: var(--uc-tpl-text-color, #1f2937);
  --uc-muted: var(--uc-tpl-muted-color, #6b7280);
  --uc-border: var(--uc-tpl-border-color, #d8dee6);
  --uc-border-strong: var(--uc-tpl-border-strong, #b6bfcc);
  --uc-error: #b91c1c;
  --uc-error-bg: #fef2f2;
  --uc-error-border: #fecaca;
  --uc-success: #15803d;
  --uc-success-bg: #f0fdf4;
  --uc-success-border: #bbf7d0;
  --uc-warning: #b45309;
  --uc-warning-bg: #fffbeb;
  --uc-warning-border: #fde68a;
  --uc-radius: var(--uc-tpl-border-radius, 14px);
  --uc-radius-sm: max(8px, calc(var(--uc-radius) - 4px));
  --uc-input-h: 48px;
  --uc-btn-h: 50px;
  --uc-focus-ring: 0 0 0 3px var(--uc-primary-soft-strong);
  --uc-focus-ring-error: 0 0 0 3px rgba(185, 28, 28, 0.14);
  --uc-transition: 160ms ease;
  --uc-shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
  --uc-shadow-md: 0 1px 3px rgba(16, 24, 40, 0.08), 0 8px 28px rgba(16, 24, 40, 0.07);

  max-width: 420px;
  margin: 0 auto;
  padding: 16px;
  font-family: Vazirmatn, Tahoma, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.7;
  color: var(--uc-text);
  text-align: start;
  box-sizing: border-box;
  -webkit-font-smoothing: antialiased;
}

/* ================= 2. INTERNAL COMPONENT RESET =================
 * Scoped — never touches the surrounding WordPress site. */
.uc-auth *,
.uc-auth *::before,
.uc-auth *::after { box-sizing: border-box; }

.uc-auth button,
.uc-auth input,
.uc-auth select,
.uc-auth textarea {
  font-family: inherit;
  font-size: 100%;
  line-height: inherit;
  margin: 0;
}

.uc-auth img { max-width: 100%; height: auto; }

/* ======================== 3. DIRECTION ======================== */
.uc-auth[dir="rtl"] { direction: rtl; text-align: right; }
.uc-auth[dir="ltr"] { direction: ltr; text-align: left; }

/* ================== 4. FORM PRIMITIVES ================== */
.uc-auth .uc-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: 100%;
  margin: 0;
  padding: 0;
}

.uc-auth .uc-auth__field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.uc-auth .uc-auth__actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 4px;
}

.uc-auth .uc-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--uc-text);
  line-height: 1.5;
}

.uc-auth .uc-field-help {
  font-size: 12px;
  color: var(--uc-muted);
  line-height: 1.6;
}

.uc-auth .uc-field-error {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--uc-error);
  line-height: 1.6;
}

/* ================== 5. INPUT PRIMITIVES ================== */
.uc-auth .uc-input {
  width: 100%;
  min-height: var(--uc-input-h);
  padding: 11px 14px;
  font-size: 15px;
  font-family: inherit;
  color: var(--uc-text);
  background: var(--uc-bg);
  border: 1px solid var(--uc-border);
  border-radius: var(--uc-radius-sm);
  outline: none;
  transition: border-color var(--uc-transition), box-shadow var(--uc-transition), background var(--uc-transition);
}

.uc-auth .uc-input::placeholder { color: #9ca3af; opacity: 1; }
.uc-auth .uc-input:hover:not(:disabled):not(:focus) { border-color: var(--uc-border-strong); }
.uc-auth .uc-input:focus {
  border-color: var(--uc-primary);
  box-shadow: var(--uc-focus-ring);
}
.uc-auth .uc-input:disabled { background: var(--uc-surface-2); color: #9ca3af; cursor: not-allowed; }
.uc-auth .uc-input--error { border-color: var(--uc-error); }
.uc-auth .uc-input--error:focus { box-shadow: var(--uc-focus-ring-error); }
.uc-auth .uc-input--valid { border-color: var(--uc-success); }

/* OTP — single real input styled as segmented digit boxes.
 * --uc-otp-n (digit count) is a dynamic CSS variable set by auth.js. */
.uc-auth .uc-input--otp {
  text-align: center;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: 0;
  direction: ltr;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-variant-numeric: tabular-nums;
  caret-color: var(--uc-primary);
  padding-inline: 8px;
  background-image: repeating-linear-gradient(
    to right,
    var(--uc-border) 0,
    var(--uc-border) 1px,
    transparent 1px,
    transparent calc(100% / var(--uc-otp-n, 6))
  );
  background-position: bottom 0 left 0;
  background-size: 100% 2px;
  background-repeat: no-repeat;
  border-bottom-width: 2px;
  border-bottom-color: var(--uc-border);
}
.uc-auth .uc-input--otp:focus {
  background-image: repeating-linear-gradient(
    to right,
    var(--uc-primary) 0,
    var(--uc-primary) 1px,
    transparent 1px,
    transparent calc(100% / var(--uc-otp-n, 6))
  );
}

/* ================== 6. BUTTON SYSTEM ==================
 * Scoped + token-driven: the primary button stays visible even when
 * the surrounding theme ships `button { background:white; color:white }`. */
.uc-auth .uc-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 11px 18px;
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  line-height: 1.4;
  color: var(--uc-text);
  background: var(--uc-bg);
  border: 1px solid var(--uc-border);
  border-radius: var(--uc-radius-sm);
  cursor: pointer;
  text-decoration: none;
  text-align: center;
  transition: background var(--uc-transition), border-color var(--uc-transition),
    box-shadow var(--uc-transition), transform 120ms ease, opacity var(--uc-transition);
}
.uc-auth .uc-btn:hover:not(:disabled) { border-color: var(--uc-border-strong); background: var(--uc-surface-2); }
.uc-auth .uc-btn:focus-visible { outline: none; box-shadow: var(--uc-focus-ring); border-color: var(--uc-primary); }
.uc-auth .uc-btn:active:not(:disabled) { transform: translateY(1px); }
.uc-auth .uc-btn:disabled { opacity: 0.6; cursor: not-allowed; }

.uc-auth .uc-btn--primary {
  background: var(--uc-primary);
  border-color: var(--uc-primary);
  color: var(--uc-primary-text);
  min-height: var(--uc-btn-h);
  font-size: 15.5px;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.12);
}
.uc-auth .uc-btn--primary:hover:not(:disabled) {
  background: var(--uc-primary-hover);
  border-color: var(--uc-primary-hover);
  color: var(--uc-primary-text);
}
.uc-auth .uc-btn--primary:focus-visible {
  outline: 2px solid var(--uc-primary);
  outline-offset: 2px;
  box-shadow: var(--uc-focus-ring);
}
.uc-auth .uc-btn--primary:active:not(:disabled) {
  background: var(--uc-primary-active);
  border-color: var(--uc-primary-active);
  color: var(--uc-primary-text);
}
.uc-auth .uc-btn--primary:disabled {
  background: var(--uc-primary);
  border-color: var(--uc-primary);
  color: var(--uc-primary-text);
  opacity: 0.55;
}
.uc-auth .uc-btn--primary.is-busy {
  background: var(--uc-primary-hover);
  border-color: var(--uc-primary-hover);
  color: var(--uc-primary-text);
  cursor: wait;
}

.uc-auth .uc-btn--secondary { background: var(--uc-bg); color: var(--uc-text); }
.uc-auth .uc-btn--ghost {
  background: transparent;
  border-color: transparent;
  color: var(--uc-primary);
}
.uc-auth .uc-btn--ghost:hover:not(:disabled) { background: var(--uc-primary-soft); border-color: transparent; }

.uc-auth .uc-btn--block { width: 100%; }

.uc-auth .uc-btn--toggle {
  background: transparent;
  color: var(--uc-primary);
  border: none;
  min-height: 0;
  padding: 4px 8px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.uc-auth .uc-btn--toggle:hover { text-decoration: underline; background: transparent; }
.uc-auth .uc-btn--toggle:focus-visible { box-shadow: var(--uc-focus-ring); border-radius: 6px; }

/* ================= 7. METHOD SELECTION CARDS ================= */
.uc-auth .uc-methods { display: flex; flex-direction: column; gap: 10px; }

.uc-auth .uc-method {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 62px;
  padding: 11px 14px;
  text-align: start;
  font-family: inherit;
  font-size: 14px;
  background: var(--uc-bg);
  color: var(--uc-text);
  border: 1px solid var(--uc-border);
  border-radius: var(--uc-radius-sm);
  cursor: pointer;
  transition: border-color var(--uc-transition), background var(--uc-transition),
    box-shadow var(--uc-transition), transform 120ms ease;
}
.uc-auth .uc-method:hover:not(:disabled) {
  border-color: var(--uc-primary);
  background: var(--uc-primary-soft);
}
.uc-auth .uc-method:focus-visible { outline: none; box-shadow: var(--uc-focus-ring); border-color: var(--uc-primary); }
.uc-auth .uc-method:active:not(:disabled) { transform: scale(0.992); background: var(--uc-primary-soft-strong); }
.uc-auth .uc-method:disabled { opacity: 0.6; cursor: not-allowed; }

.uc-auth .uc-method__icon {
  flex: 0 0 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  border-radius: 12px;
  background: var(--uc-primary-soft);
  color: var(--uc-primary);
}
.uc-auth .uc-method__body { display: flex; flex-direction: column; gap: 1px; min-width: 0; flex: 1; }
.uc-auth .uc-method__title { font-size: 14px; font-weight: 700; line-height: 1.5; }
.uc-auth .uc-method__desc { font-size: 12px; color: var(--uc-muted); line-height: 1.6; }
.uc-auth .uc-method__arrow {
  flex: 0 0 auto;
  font-size: 16px;
  color: var(--uc-muted);
  transition: color var(--uc-transition), transform var(--uc-transition);
}
.uc-auth .uc-method:hover .uc-method__arrow { color: var(--uc-primary); }
.uc-auth[dir="rtl"] .uc-method__arrow { transform: scaleX(-1); }
.uc-auth[dir="rtl"] .uc-method:hover .uc-method__arrow { transform: scaleX(-1) translateX(-2px); }
.uc-auth[dir="ltr"] .uc-method:hover .uc-method__arrow { transform: translateX(2px); }

/* ================= 8. PASSWORD WRAP ================= */
.uc-auth .uc-pass-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--uc-border);
  border-radius: var(--uc-radius-sm);
  background: var(--uc-bg);
  padding-inline-end: 8px;
  transition: border-color var(--uc-transition), box-shadow var(--uc-transition);
}
.uc-auth .uc-pass-wrap:focus-within {
  border-color: var(--uc-primary);
  box-shadow: var(--uc-focus-ring);
}
.uc-auth .uc-pass-wrap .uc-input {
  border: none;
  box-shadow: none;
  background: transparent;
  flex: 1;
  min-width: 0;
}

/* ================= 9. CHECKBOX ================= */
.uc-auth .uc-check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--uc-muted);
  cursor: pointer;
}
.uc-auth .uc-check input { width: 17px; height: 17px; accent-color: var(--uc-primary); cursor: pointer; }

/* ================= 10. FEEDBACK & UTILITIES ================= */
.uc-auth .uc-msg {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: var(--uc-radius-sm);
  font-size: 13px;
  line-height: 1.7;
  animation: uc-msg-in var(--uc-transition);
}
@keyframes uc-msg-in { from { opacity: 0; transform: translateY(-3px); } to { opacity: 1; transform: none; } }
.uc-auth .uc-msg--error { background: var(--uc-error-bg); color: var(--uc-error); border: 1px solid var(--uc-error-border); }
.uc-auth .uc-msg--success { background: var(--uc-success-bg); color: var(--uc-success); border: 1px solid var(--uc-success-border); }
.uc-auth .uc-msg--warning { background: var(--uc-warning-bg); color: var(--uc-warning); border: 1px solid var(--uc-warning-border); }

.uc-auth .uc-status { margin: 0 0 10px; font-size: 13px; color: var(--uc-muted); line-height: 1.8; }
.uc-auth .uc-status bdi { font-weight: 600; color: var(--uc-text); }

.uc-auth .uc-timer { font-size: 13px; color: var(--uc-muted); font-variant-numeric: tabular-nums; }
.uc-auth .uc-resend {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 10px 0 0;
}

.uc-auth .uc-alt { margin: 16px 0 0; font-size: 13px; color: var(--uc-muted); text-align: center; }

.uc-auth .uc-link {
  color: var(--uc-primary);
  text-decoration: none;
  font-weight: 600;
  background: none;
  border: none;
  padding: 4px 6px;
  margin: -4px -6px;
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  border-radius: 6px;
  transition: color var(--uc-transition), text-decoration-color var(--uc-transition);
}
.uc-auth .uc-link:hover { text-decoration: underline; text-decoration-thickness: 1.5px; text-underline-offset: 3px; }
.uc-auth .uc-link:focus-visible { outline: none; box-shadow: var(--uc-focus-ring); }

.uc-auth .uc-spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  vertical-align: -2px;
  animation: uc-spin 0.7s linear infinite;
}
@keyframes uc-spin { to { transform: rotate(360deg); } }

/* ================= 11. LOGGED-IN NOTICE ================= */
.uc-auth--logged-in {
  max-width: 420px;
  margin: 0 auto;
  padding: 20px;
  text-align: center;
  font-family: Vazirmatn, Tahoma, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.7;
  color: var(--uc-text);
  background: var(--uc-bg);
  border: 1px solid var(--uc-border);
  border-radius: var(--uc-radius);
  box-shadow: var(--uc-shadow-sm);
}

/* ================= 12. ACCESSIBILITY ================= */
@media (prefers-reduced-motion: reduce) {
  .uc-auth *,
  .uc-auth *::before,
  .uc-auth *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ============================================================
 * Standalone rendering mode (plugin-owned document shell).
 * Scoped to body.uc-standalone-auth — never affects the theme.
 * ============================================================ */
.uc-standalone-auth {
  margin: 0;
  padding: 0;
  min-height: 100vh;
  background: var(--uc-bg, #f6f7f9);
  color: var(--uc-text, #1f2937);
  font-family: Vazirmatn, Tahoma, Arial, sans-serif;
}

.uc-standalone-auth__main {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.uc-standalone-auth--fullwidth .uc-standalone-auth__main {
  padding: 0;
}
.uc-standalone-auth--fullwidth .uc-standalone-auth__main > .uc-auth-template {
  width: 100%;
  max-width: none;
}
