/* ==========================================================================
 * Waghor Aquarium Centralized SSO — Client Auth SDK Stylesheet
 * Light-mode Navy-Blue formal theme with strict .waghor-auth-* isolation.
 * Safe against Tailwind Preflight, global input/button resets, iOS PWA
 * safe-area insets, high z-index modals, and A4 print stylesheets.
 * ========================================================================== */

:root {
  --waghor-navy-950: #071527;
  --waghor-navy-900: #0f2744;
  --waghor-navy-800: #1e3a5f;
  --waghor-accent: #1d4ed8;
  --waghor-accent-hover: #1e40af;
  --waghor-canvas: #f8fafc;
  --waghor-surface: #ffffff;
  --waghor-border: #cbd5e1;
  --waghor-border-light: #e2e8f0;
  --waghor-ink: #0f172a;
  --waghor-muted: #475569;
  --waghor-danger: #be123c;
  --waghor-danger-bg: #fff1f2;
  --waghor-danger-border: #fecdd3;
  --waghor-font-sans: "IBM Plex Sans Thai", "Anuphan", "Sarabun", "Noto Sans Thai", "Prompt", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

/* Body scroll lock when mandatory modal or unauthorized screen is visible */
body.waghor-auth-locked {
  overflow: hidden !important;
  overscroll-behavior: none;
}

/* Defensive box-sizing & typography scope */
.waghor-auth-overlay,
.waghor-auth-overlay *,
.waghor-auth-overlay *::before,
.waghor-auth-overlay *::after,
.waghor-auth-badge,
.waghor-auth-badge *,
.waghor-auth-badge *::before,
.waghor-auth-badge *::after,
.waghor-auth-floating,
.waghor-auth-floating *,
.waghor-auth-floating *::before,
.waghor-auth-floating *::after {
  box-sizing: border-box;
  font-family: var(--waghor-font-sans);
}

/* Blocking full-screen overlay (z-index above all app overlays at 9999) */
.waghor-auth-overlay {
  position: fixed;
  inset: 0;
  z-index: 20000;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  padding:
    max(16px, env(safe-area-inset-top, 0px))
    max(16px, env(safe-area-inset-right, 0px))
    max(16px, env(safe-area-inset-bottom, 0px))
    max(16px, env(safe-area-inset-left, 0px));
  background: rgba(15, 39, 68, 0.78);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  overflow-y: auto;
  overscroll-behavior: contain;
  color: var(--waghor-ink);
  font-size: 16px;
  line-height: 1.5;
  text-align: left;
}

/* Modal Card */
.waghor-auth-card {
  width: 100%;
  max-width: 420px;
  margin: auto;
  padding: 0;
  background: var(--waghor-surface);
  border: 1px solid var(--waghor-border-light);
  border-radius: 16px;
  box-shadow: 0 24px 56px rgba(7, 21, 39, 0.34);
  overflow: hidden;
  color: var(--waghor-ink);
}

/* Formal Navy-Blue Header */
.waghor-auth-header {
  margin: 0;
  padding: 22px 24px 20px;
  background: linear-gradient(135deg, var(--waghor-navy-900) 0%, var(--waghor-navy-800) 100%);
  color: #ffffff;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.waghor-auth-brand-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0;
  padding: 0;
}

.waghor-auth-brand-icon {
  flex: 0 0 42px;
  width: 42px;
  height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.22);
  color: #ffffff;
}

.waghor-auth-brand-icon--danger {
  background: var(--waghor-danger-bg);
  border-color: var(--waghor-danger-border);
  color: var(--waghor-danger);
  width: 48px;
  height: 48px;
  flex: 0 0 48px;
  margin: 0 auto 12px;
  display: flex;
}

.waghor-auth-title {
  margin: 0;
  padding: 0;
  font-size: 19px;
  font-weight: 700;
  line-height: 1.3;
  color: #ffffff;
}

.waghor-auth-subtitle {
  margin: 2px 0 0;
  padding: 0;
  font-size: 13px;
  font-weight: 400;
  line-height: 1.4;
  color: #cbd5e1;
}

/* Card Body */
.waghor-auth-body {
  margin: 0;
  padding: 22px 24px 24px;
  background: var(--waghor-surface);
}

/* Informational Reason Banner (e.g. session expired / forceRelogin reason) */
.waghor-auth-reason {
  margin: 0 0 14px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid #bfdbfe;
  background: #eff6ff;
  color: var(--waghor-navy-900);
  font-size: 13.5px;
  font-weight: 500;
  line-height: 1.45;
}

/* Error Alert */
.waghor-auth-error {
  margin: 0 0 14px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--waghor-danger-border);
  background: var(--waghor-danger-bg);
  color: var(--waghor-danger);
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1.45;
}

.waghor-auth-hidden {
  display: none !important;
}

/* Form Elements (explicitly overriding Tailwind Preflight & global app CSS) */
.waghor-auth-form {
  display: block;
  margin: 0;
  padding: 0;
}

.waghor-auth-field {
  margin: 0 0 16px;
  padding: 0;
}

.waghor-auth-label {
  display: block;
  margin: 0 0 6px;
  padding: 0;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.4;
  color: var(--waghor-navy-900);
}

.waghor-auth-input {
  display: block;
  width: 100%;
  min-height: 44px;
  margin: 0;
  padding: 10px 14px;
  border: 1.5px solid var(--waghor-border);
  border-radius: 10px;
  background: var(--waghor-surface);
  color: var(--waghor-ink);
  font-size: 16px;
  font-weight: 500;
  line-height: 1.4;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  user-select: text !important;
  -webkit-user-select: text !important;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.waghor-auth-input::placeholder {
  color: #94a3b8;
  opacity: 1;
}

.waghor-auth-input:focus {
  border-color: var(--waghor-accent);
  box-shadow: 0 0 0 3px rgba(29, 78, 216, 0.16);
}

.waghor-auth-input:disabled {
  background: #f1f5f9;
  color: #64748b;
  cursor: not-allowed;
}

/* PIN Wrapper + Show/Hide Toggle */
.waghor-auth-pin-wrap {
  position: relative;
  display: flex;
  align-items: center;
  margin: 0;
  padding: 0;
}

.waghor-auth-pin-wrap .waghor-auth-input {
  padding-right: 52px;
}

.waghor-auth-pin-toggle {
  position: absolute;
  right: 2px;
  top: 50%;
  transform: translateY(-50%);
  min-width: 44px;
  min-height: 44px;
  margin: 0;
  padding: 0 10px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--waghor-muted);
  font-size: 13px;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.waghor-auth-pin-toggle:hover:not(:disabled) {
  color: var(--waghor-navy-900);
  background: #f1f5f9;
}

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

/* Action Buttons */
.waghor-auth-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 6px 0 0;
  padding: 0;
}

.waghor-auth-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 44px;
  margin: 0;
  padding: 11px 16px;
  border: 1.5px solid transparent;
  border-radius: 10px;
  font-size: 15.5px;
  font-weight: 600;
  line-height: 1.3;
  text-decoration: none;
  text-align: center;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}

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

.waghor-auth-btn--primary {
  background: var(--waghor-navy-900);
  border-color: var(--waghor-navy-900);
  color: #ffffff;
}

.waghor-auth-btn--primary:hover:not(:disabled) {
  background: var(--waghor-accent);
  border-color: var(--waghor-accent);
}

.waghor-auth-btn--primary:disabled {
  background: #64748b;
  border-color: #64748b;
  color: #f8fafc;
  cursor: wait;
}

.waghor-auth-btn--secondary {
  background: var(--waghor-canvas);
  border-color: var(--waghor-border);
  color: var(--waghor-navy-900);
}

.waghor-auth-btn--secondary:hover:not(:disabled) {
  background: #e2e8f0;
  border-color: #94a3b8;
}

.waghor-auth-footer-note {
  margin: 14px 0 0;
  padding: 12px 0 0;
  border-top: 1px solid var(--waghor-border-light);
  font-size: 12.5px;
  line-height: 1.45;
  color: var(--waghor-muted);
  text-align: center;
}

/* Unauthorized Screen */
.waghor-auth-unauth-box {
  margin: 0;
  padding: 4px 0 0;
  text-align: center;
}

.waghor-auth-unauth-heading {
  margin: 0 0 8px;
  padding: 0;
  font-size: 20px;
  font-weight: 700;
  line-height: 1.35;
  color: var(--waghor-danger);
}

.waghor-auth-unauth-desc {
  margin: 0 0 16px;
  padding: 0;
  font-size: 14.5px;
  line-height: 1.55;
  color: var(--waghor-muted);
}

.waghor-auth-user-summary {
  margin: 0 0 18px;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--waghor-border-light);
  background: var(--waghor-canvas);
  text-align: left;
}

.waghor-auth-user-summary-name {
  margin: 0;
  padding: 0;
  font-size: 15px;
  font-weight: 700;
  color: var(--waghor-navy-900);
}

.waghor-auth-user-summary-meta {
  margin: 2px 0 0;
  padding: 0;
  font-size: 13px;
  color: var(--waghor-muted);
}

/* Compact User Badge (inline in header or floating) */
.waghor-auth-floating {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 12px);
  right: calc(env(safe-area-inset-right, 0px) + 12px);
  z-index: 15000;
  margin: 0;
  padding: 0;
  max-width: calc(100vw - 24px - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px));
}

.waghor-auth-badge {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  max-width: 100%;
  margin: 0;
  padding: 4px 6px 4px 12px;
  border: 1px solid var(--waghor-border);
  border-radius: 9999px;
  background: var(--waghor-surface);
  color: var(--waghor-navy-900);
  box-shadow: 0 2px 8px rgba(15, 39, 68, 0.08);
  font-size: 13px;
  line-height: 1.3;
}

.waghor-auth-badge-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
  margin: 0;
  padding: 0;
}

.waghor-auth-badge-name {
  margin: 0;
  padding: 0;
  font-size: 13.5px;
  font-weight: 700;
  line-height: 1.25;
  color: var(--waghor-navy-900);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 180px;
}

.waghor-auth-badge-role {
  margin: 0;
  padding: 0;
  font-size: 11.5px;
  font-weight: 500;
  line-height: 1.2;
  color: var(--waghor-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 180px;
}

.waghor-auth-badge-logout {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  margin: 0;
  padding: 6px 12px;
  border: 1px solid var(--waghor-danger-border);
  border-radius: 9999px;
  background: var(--waghor-danger-bg);
  color: var(--waghor-danger);
  font-size: 12.5px;
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.waghor-auth-badge-logout:hover {
  background: var(--waghor-danger);
  border-color: var(--waghor-danger);
  color: #ffffff;
}

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

/* Mobile & iOS PWA Standalone Adjustments */
@media (max-width: 480px) {
  .waghor-auth-card {
    border-radius: 14px;
  }

  .waghor-auth-header {
    padding: 18px 18px 16px;
  }

  .waghor-auth-body {
    padding: 18px;
  }

  .waghor-auth-badge {
    gap: 8px;
    padding: 4px 4px 4px 10px;
  }

  .waghor-auth-badge-name,
  .waghor-auth-badge-role {
    max-width: 130px;
  }

  .waghor-auth-badge-logout {
    padding: 6px 10px;
    font-size: 12px;
  }
}

@media (display-mode: standalone) {
  .waghor-auth-overlay {
    padding-top: max(20px, env(safe-area-inset-top, 0px));
    padding-bottom: max(20px, env(safe-area-inset-bottom, 0px));
  }
}

/* Hide SDK UI completely in A4/PDF print layouts */
@media print {
  .waghor-auth-overlay,
  .waghor-auth-badge,
  .waghor-auth-floating {
    display: none !important;
  }
}

/* Respect user reduced motion preference */
@media (prefers-reduced-motion: reduce) {
  .waghor-auth-overlay,
  .waghor-auth-card,
  .waghor-auth-btn,
  .waghor-auth-input,
  .waghor-auth-badge,
  .waghor-auth-badge-logout {
    transition: none !important;
    animation: none !important;
  }
}

/* === Biometric (Face ID / Touch ID) Controls === */
.waghor-auth-bio-wrap {
  margin-bottom: 14px;
}

.waghor-auth-bio-btn {
  width: 100%;
  min-height: 46px;
  padding: 10px 14px;
  border: 0;
  border-radius: 10px;
  background: linear-gradient(135deg, #059669, #047857);
  color: #ffffff;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(4, 120, 87, 0.25);
  transition: opacity 0.15s ease, transform 0.1s ease;
}

.waghor-auth-bio-btn:hover {
  opacity: 0.94;
}

.waghor-auth-bio-btn:disabled {
  opacity: 0.65;
  cursor: not-allowed;
}

.waghor-auth-bio-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  color: #64748b;
  font-size: 12px;
}

.waghor-auth-bio-divider::before,
.waghor-auth-bio-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: #e2e8f0;
}

.waghor-auth-badge-bio {
  padding: 4px 9px;
  border-radius: 999px;
  border: 1px solid #cbd5e1;
  background: #f8fafc;
  color: #0f294a;
  font-family: inherit;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.waghor-auth-badge-bio-active {
  border-color: #6ee7b7;
  background: #ecfdf5;
  color: #047857;
}
