/* ============================================================
 * BALIVI Auth Modal — Production CSS
 * Glassmorphism, premium SaaS, mobile-first, accessible
 *
 * Aligned with HTML conventions in auth-modal.php:
 *   - .auth-backdrop.open / .auth-modal.open (state classes)
 *   - .auth-view.active (current view)
 *   - .auth-field-error.visible / .auth-notice.visible
 *   - .auth-pw-strength + .auth-pw-strength-bar + .auth-pw-strength-fill
 *   - .auth-toast.visible (toast notifications)
 *   - .invalid (input error state)
 *   - .loading (submit button)
 * ============================================================ */

:root {
  --auth-primary: #0F172A;
  --auth-primary-hover: #1E293B;
  --auth-accent: #1A56DB;
  --auth-success: #059669;
  --auth-error: #DC2626;
  --auth-warning: #D97706;
  --auth-text: #0F172A;
  --auth-text-light: #64748B;
  --auth-text-muted: #94A3B8;
  --auth-bg: #FFFFFF;
  --auth-border: #E2E8F0;
  --auth-border-hover: #CBD5E1;
  --auth-input-bg: #FAFBFC;
  --auth-radius: 16px;
  --auth-radius-sm: 10px;
  --auth-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.15);
  --auth-shadow-lg: 0 35px 60px -15px rgba(15, 23, 42, 0.25);
  --auth-font-display: 'Playfair Display', Georgia, serif;
  --auth-font-body: 'Plus Jakarta Sans', 'DM Sans', system-ui, -apple-system, sans-serif;
  --auth-ease: cubic-bezier(0.16, 1, 0.3, 1);
}

/* ── Backdrop ── */
.auth-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 9998;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s var(--auth-ease), visibility 0.25s;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  overflow-y: auto;
}

.auth-backdrop.open {
  opacity: 1;
  visibility: visible;
}

/* Hide modal root entirely when aria-hidden */
#auth-modal-root[aria-hidden="true"] .auth-backdrop:not(.open) {
  pointer-events: none;
}

/* ── Modal ── */
.auth-modal {
  position: relative;
  background: var(--auth-bg);
  border-radius: var(--auth-radius);
  width: 100%;
  max-width: 440px;
  padding: 0;
  box-shadow: var(--auth-shadow-lg);
  overflow: hidden;
  transform: translateY(20px) scale(0.96);
  opacity: 0;
  transition: transform 0.35s var(--auth-ease), opacity 0.25s ease;
  font-family: var(--auth-font-body);
  color: var(--auth-text);
  margin: auto;
  -webkit-font-smoothing: antialiased;
  z-index: 9999;
}

.auth-modal.open {
  transform: translateY(0) scale(1);
  opacity: 1;
}

/* Subtle glassmorphism gradient overlay */
.auth-modal::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.92) 0%, rgba(248, 250, 252, 0.85) 100%);
  pointer-events: none;
  z-index: 0;
}

.auth-modal > * {
  position: relative;
  z-index: 1;
}

/* ── Close Button ── */
.auth-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(241, 245, 249, 0.75);
  border: none;
  cursor: pointer;
  color: var(--auth-text-light);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  z-index: 10;
  padding: 0;
}

.auth-close:hover {
  background: #E2E8F0;
  color: var(--auth-text);
  transform: rotate(90deg);
}

.auth-close:focus-visible {
  outline: 2px solid var(--auth-accent);
  outline-offset: 2px;
}

/* ── Header ── */
.auth-head {
  padding: 36px 32px 20px;
  text-align: center;
}

.auth-logo {
  font-family: var(--auth-font-display);
  font-size: 22px;
  font-weight: 700;
  color: var(--auth-primary);
  margin: 0 0 14px;
  letter-spacing: -0.5px;
}

.auth-title {
  font-family: var(--auth-font-display);
  font-size: 24px;
  font-weight: 700;
  margin: 0 0 6px;
  color: var(--auth-primary);
  letter-spacing: -0.3px;
}

.auth-subtitle {
  font-size: 14px;
  color: var(--auth-text-light);
  margin: 0;
  line-height: 1.5;
}

/* ── Body ── */
.auth-body {
  padding: 0 32px 32px;
}

/* ── Inline Notice (success/error/info) ── */
.auth-notice {
  display: none;
  padding: 11px 14px;
  border-radius: var(--auth-radius-sm);
  font-size: 13px;
  margin-bottom: 16px;
  line-height: 1.4;
  border-left: 3px solid;
}

.auth-notice.visible { display: block; }
.auth-notice.success { background: rgba(5, 150, 105, 0.08); color: #065F46; border-color: var(--auth-success); }
.auth-notice.error   { background: rgba(220, 38, 38, 0.08); color: #991B1B; border-color: var(--auth-error); }
.auth-notice.info    { background: rgba(26, 86, 219, 0.08); color: #1E40AF; border-color: var(--auth-accent); }

/* ── View toggle ── */
.auth-view { display: none; }
.auth-view.active {
  display: block;
  animation: authFadeIn 0.3s var(--auth-ease);
}

@keyframes authFadeIn {
  from { opacity: 0; transform: translateX(8px); }
  to { opacity: 1; transform: translateX(0); }
}

/* ── Google Sign-In Button ── */
.auth-google-btn {
  width: 100%;
  padding: 12px 16px;
  background: #FFFFFF;
  border: 1.5px solid var(--auth-border);
  border-radius: var(--auth-radius-sm);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  color: var(--auth-text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  transition: all 0.2s ease;
  margin-bottom: 16px;
}

.auth-google-btn:hover {
  border-color: var(--auth-border-hover);
  background: #F8FAFC;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.auth-google-btn:active { transform: translateY(0); }

.auth-google-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.auth-google-btn svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

/* ── Divider ── */
.auth-divider {
  display: flex;
  align-items: center;
  text-align: center;
  margin: 18px 0;
  color: var(--auth-text-muted);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.auth-divider::before,
.auth-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--auth-border);
}

.auth-divider::before { margin-right: 12px; }
.auth-divider::after { margin-left: 12px; }

/* ── Form ── */
.auth-field {
  margin-bottom: 14px;
}

.auth-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--auth-text);
  margin-bottom: 6px;
}

.auth-input-wrap {
  position: relative;
}

.auth-input {
  width: 100%;
  padding: 12px 14px;
  background: var(--auth-input-bg);
  border: 1.5px solid var(--auth-border);
  border-radius: var(--auth-radius-sm);
  font-family: inherit;
  font-size: 14px;
  color: var(--auth-text);
  transition: all 0.2s ease;
  box-sizing: border-box;
  outline: none;
}

.auth-input::placeholder { color: var(--auth-text-muted); }

.auth-input:focus {
  background: #FFFFFF;
  border-color: var(--auth-accent);
  box-shadow: 0 0 0 4px rgba(26, 86, 219, 0.08);
}

.auth-input.invalid {
  border-color: var(--auth-error);
  background: rgba(220, 38, 38, 0.03);
}

.auth-input.invalid:focus {
  box-shadow: 0 0 0 4px rgba(220, 38, 38, 0.08);
}

.auth-input[data-pw] {
  padding-right: 44px;
}

/* ── Password Toggle Button ── */
.auth-pw-toggle {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  width: 32px;
  height: 32px;
  cursor: pointer;
  color: var(--auth-text-light);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  transition: all 0.15s ease;
  padding: 0;
}

.auth-pw-toggle:hover {
  background: #F1F5F9;
  color: var(--auth-text);
}

.auth-pw-toggle:focus-visible {
  outline: 2px solid var(--auth-accent);
  outline-offset: 1px;
}

.auth-pw-toggle svg {
  width: 18px;
  height: 18px;
}

/* ── Inline field error ── */
.auth-field-error {
  display: none;
  font-size: 11.5px;
  color: var(--auth-error);
  margin-top: 4px;
  line-height: 1.4;
  font-weight: 500;
}

.auth-field-error.visible { display: block; }

/* ── Password Strength Meter ── */
.auth-pw-strength {
  margin-top: 8px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.auth-pw-strength-bar {
  flex: 1;
  height: 4px;
  background: var(--auth-border);
  border-radius: 2px;
  overflow: hidden;
}

.auth-pw-strength-fill {
  height: 100%;
  width: 0%;
  background: var(--auth-error);
  transition: width 0.3s ease, background 0.3s ease;
  border-radius: 2px;
}

.auth-pw-strength-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--auth-text-muted);
  min-width: 70px;
  text-align: right;
}

/* ── Row (remember + forgot link) ── */
.auth-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 6px 0 18px;
  font-size: 13px;
  gap: 8px;
  flex-wrap: wrap;
}

.auth-checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  cursor: pointer;
  color: var(--auth-text-light);
  user-select: none;
  font-size: 13px;
}

.auth-checkbox-label input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--auth-accent);
  cursor: pointer;
  margin: 0;
}

.auth-link {
  color: var(--auth-accent);
  text-decoration: none;
  font-weight: 600;
  cursor: pointer;
  background: none;
  border: none;
  padding: 0;
  font-family: inherit;
  font-size: inherit;
  transition: opacity 0.15s ease;
}

.auth-link:hover { opacity: 0.75; text-decoration: underline; }
.auth-link:focus-visible {
  outline: 2px solid var(--auth-accent);
  outline-offset: 2px;
  border-radius: 2px;
}

/* ── Submit Button ── */
.auth-submit {
  width: 100%;
  padding: 13px 20px;
  background: var(--auth-primary);
  color: #FFFFFF;
  border: none;
  border-radius: var(--auth-radius-sm);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.auth-submit:hover:not(:disabled) {
  background: var(--auth-primary-hover);
  transform: translateY(-1px);
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.25);
}

.auth-submit:active:not(:disabled) { transform: translateY(0); }

.auth-submit:disabled {
  opacity: 0.65;
  cursor: not-allowed;
}

.auth-spinner {
  display: none;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: #FFFFFF;
  border-radius: 50%;
  animation: authSpin 0.6s linear infinite;
}

.auth-submit.loading .auth-spinner { display: inline-block; }
.auth-submit.loading .auth-submit-text { opacity: 0.7; }

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

/* ── Footer (switch view link) ── */
.auth-footer {
  text-align: center;
  padding-top: 18px;
  margin-top: 4px;
  border-top: 1px solid var(--auth-border);
  font-size: 13px;
  color: var(--auth-text-light);
}

/* ── Toast Container + Toasts ── */
.auth-toast-container {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 10000;
  max-width: calc(100vw - 32px);
  width: auto;
  pointer-events: none;
}

.auth-toast {
  background: var(--auth-primary);
  color: #FFFFFF;
  padding: 12px 20px;
  border-radius: 10px;
  font-size: 13.5px;
  font-weight: 500;
  font-family: var(--auth-font-body);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
  opacity: 0;
  transform: translateY(20px);
  transition: all 0.35s var(--auth-ease);
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 220px;
  max-width: 360px;
}

.auth-toast.visible {
  opacity: 1;
  transform: translateY(0);
}

.auth-toast.success { background: var(--auth-success); }
.auth-toast.error { background: var(--auth-error); }
.auth-toast.info { background: var(--auth-accent); }

/* ── Mobile (bottom-sheet style) ── */
@media (max-width: 640px) {
  .auth-backdrop {
    align-items: flex-end;
    padding: 0;
  }

  .auth-modal {
    max-width: 100%;
    border-radius: 20px 20px 0 0;
    transform: translateY(100%);
    transition: transform 0.4s var(--auth-ease), opacity 0.25s;
    max-height: 92vh;
    overflow-y: auto;
  }

  .auth-modal.open {
    transform: translateY(0);
  }

  .auth-head { padding: 32px 24px 16px; }
  .auth-body { padding: 0 24px 28px; }

  .auth-toast-container {
    bottom: 16px;
    left: 16px;
    right: 16px;
    transform: none;
    max-width: none;
    width: auto;
  }

  .auth-toast {
    min-width: 0;
    max-width: none;
    width: 100%;
    box-sizing: border-box;
  }
}

/* ── Reduced Motion ── */
@media (prefers-reduced-motion: reduce) {
  .auth-backdrop,
  .auth-modal,
  .auth-view,
  .auth-close,
  .auth-submit,
  .auth-google-btn,
  .auth-toast,
  .auth-pw-strength-fill {
    transition-duration: 0.1s !important;
    animation-duration: 0.1s !important;
  }
  .auth-modal { transform: none !important; }
}

/* ── Focus management ── */
.auth-modal *:focus-visible {
  outline: 2px solid var(--auth-accent);
  outline-offset: 2px;
}
.auth-input:focus-visible { outline: none; /* using box-shadow instead */ }

/* ════════════════════════════════════════════════════════════
 * Slide CAPTCHA — Shopee-style verification slider
 * ════════════════════════════════════════════════════════════ */
.auth-slider {
  margin: 14px 0 16px;
}

.auth-slider-track {
  position: relative;
  height: 46px;
  background: #F1F5F9;
  border: 1.5px solid #E2E8F0;
  border-radius: 10px;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  transition: border-color .2s, background .2s;
}

.auth-slider-track:hover { border-color: #CBD5E1; }

.auth-slider-fill {
  position: absolute;
  top: 0; left: 0; bottom: 0;
  width: 0;
  background: linear-gradient(90deg, rgba(26,86,219,.15), rgba(26,86,219,.35));
  transition: width .12s ease-out, background .3s ease;
  pointer-events: none;
}

.auth-slider-label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  color: #64748B;
  pointer-events: none;
  transition: opacity .2s, color .3s;
  letter-spacing: .01em;
}

.auth-slider-handle {
  position: absolute;
  top: 3px; left: 3px;
  width: 38px;
  height: 38px;
  background: #fff;
  border: 1.5px solid #E2E8F0;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #1A56DB;
  cursor: grab;
  transition: box-shadow .2s, background .25s, transform .12s ease-out;
  box-shadow: 0 2px 6px rgba(15,23,42,.08);
  z-index: 2;
  touch-action: none;
}

.auth-slider-handle:hover { box-shadow: 0 4px 12px rgba(15,23,42,.15); }
.auth-slider-handle:active { cursor: grabbing; }
.auth-slider-handle:focus-visible { outline: 2px solid #1A56DB; outline-offset: 2px; }

/* Dragging state */
.auth-slider.is-dragging .auth-slider-handle {
  transition: background .25s ease;
}
.auth-slider.is-dragging .auth-slider-label {
  opacity: .45;
}

/* Success state */
.auth-slider.is-verified .auth-slider-track {
  background: #DCFCE7;
  border-color: #86EFAC;
}
.auth-slider.is-verified .auth-slider-fill {
  background: linear-gradient(90deg, rgba(34,197,94,.2), rgba(34,197,94,.45));
  width: 100% !important;
}
.auth-slider.is-verified .auth-slider-label {
  opacity: 1;
  color: #15803D;
  font-weight: 700;
}
.auth-slider.is-verified .auth-slider-handle {
  background: #22C55E;
  border-color: #16A34A;
  color: #fff;
  box-shadow: 0 4px 14px rgba(34,197,94,.4);
}
.auth-slider.is-verified .auth-slider-handle [data-slider-icon] { display: none; }
.auth-slider.is-verified .auth-slider-handle::after {
  content: '';
  width: 12px;
  height: 6px;
  border: 2.5px solid #fff;
  border-top: 0;
  border-right: 0;
  transform: rotate(-45deg) translate(2px, -1px);
  animation: authCheckIn .3s ease-out;
}
@keyframes authCheckIn {
  from { opacity: 0; transform: rotate(-45deg) translate(2px,-1px) scale(.4); }
  to   { opacity: 1; transform: rotate(-45deg) translate(2px,-1px) scale(1); }
}

/* Error / Reset state (shake) */
.auth-slider.is-error .auth-slider-track {
  animation: authShake .35s ease-out;
  border-color: #FCA5A5;
  background: #FEF2F2;
}
.auth-slider.is-error .auth-slider-label { color: #DC2626; font-weight: 700; }
@keyframes authShake {
  0%, 100% { transform: translateX(0); }
  20%      { transform: translateX(-6px); }
  40%      { transform: translateX(6px); }
  60%      { transform: translateX(-4px); }
  80%      { transform: translateX(4px); }
}

/* Mobile compactness */
@media (max-width: 480px) {
  .auth-slider-track { height: 44px; }
  .auth-slider-handle { width: 36px; height: 36px; }
  .auth-slider-label { font-size: 12.5px; }
}
