/**
 * CloudOpsGPT Portal — unified customer auth
 * Single visual authority for Login / Signup / Forgot / Verify / Reset
 * K4-WEB-UX-AUTH-ENTERPRISE-UNIFY-01 + K4-WEB-UX-AUTH-VISUAL-POLISH-FREEZE-01
 */

/* ——— Standalone page shell ——— */
.auth-shell {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 1.25rem 1rem 2rem;
  background: var(--website-bg);
}

.auth-shell .auth-panel {
  width: min(100%, 480px);
}

/* ——— Panel (modal inner + standalone card) ——— */
.auth-panel {
  background: var(--website-surface);
  border: 1px solid var(--website-border);
  border-radius: var(--website-radius-lg);
  padding: 1.5rem;
  color: var(--website-text);
  box-shadow: none;
}

.auth-panel__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.auth-panel__header-text {
  flex: 1;
  min-width: 0;
}

.auth-panel__title {
  margin: 0;
  font-size: 1.75rem;
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.02em;
  color: var(--website-text);
}

.auth-panel__subtitle {
  margin: 0.3rem 0 0;
  font-size: 0.9375rem;
  line-height: 1.45;
  color: var(--website-text-secondary);
}

.auth-panel__subtitle--lead {
  margin-top: 0.75rem;
  font-size: 1.0625rem;
  font-weight: 600;
  color: var(--website-text);
}

.auth-panel__hint {
  margin: 1rem 0 0;
  font-size: 0.875rem;
  line-height: 1.45;
  color: var(--website-text-muted);
  text-align: center;
}

.auth-panel__close {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.75rem;
  height: 2.75rem;
  min-width: 2.75rem;
  min-height: 2.75rem;
  padding: 0;
  border: none;
  border-radius: var(--website-radius-sm);
  background: transparent;
  color: var(--website-text-muted);
  opacity: 0.72;
  cursor: pointer;
}

.auth-panel__close:hover {
  color: var(--website-text-secondary);
  opacity: 1;
  background: var(--website-surface-subtle);
}

.auth-panel__close:focus-visible {
  outline: 2px solid var(--website-focus);
  outline-offset: 2px;
  opacity: 1;
}

.auth-panel__close svg {
  width: 1.125rem;
  height: 1.125rem;
}

/* ——— Form ——— */
.auth-form {
  display: flex;
  flex-direction: column;
  gap: 0.8125rem;
}

.auth-form--signup {
  gap: 0.6875rem;
}

.auth-form__row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6875rem;
}

.auth-field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.auth-form--signup .auth-field {
  gap: 0.25rem;
}

.auth-field__label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--website-text);
}

.auth-field__control {
  box-sizing: border-box;
  width: 100%;
  min-height: 2.875rem;
  padding: 0.625rem 0.85rem;
  border: 1px solid var(--website-border);
  border-radius: var(--website-radius-sm);
  background: var(--website-surface);
  color: var(--website-text);
  font: inherit;
  font-size: 1rem;
  line-height: 1.35;
  transition: border-color 0.12s var(--website-ease);
}

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

.auth-field__control:focus {
  outline: none;
}

.auth-field__control:focus-visible {
  outline: none;
  border-color: var(--website-border);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--website-focus) 38%, transparent);
}

.auth-field__password {
  position: relative;
}

.auth-field__password .auth-field__control {
  padding-right: 3rem;
}

.auth-field__toggle {
  position: absolute;
  right: 0.2rem;
  top: 50%;
  transform: translateY(-50%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.75rem;
  height: 2.75rem;
  min-width: 2.75rem;
  min-height: 2.75rem;
  padding: 0;
  border: none;
  border-radius: var(--website-radius-sm);
  background: transparent;
  color: var(--website-text-secondary);
  cursor: pointer;
}

.auth-field__toggle:hover {
  color: var(--website-text);
}

.auth-field__toggle:focus-visible {
  outline: 2px solid var(--website-focus);
  outline-offset: 1px;
}

.auth-field__toggle svg {
  width: 1.0625rem;
  height: 1.0625rem;
}

.auth-field__hint {
  margin: 0.125rem 0 0;
  font-size: 0.75rem;
  line-height: 1.4;
  color: var(--website-text-muted);
}

.auth-field__hint ul {
  margin: 0.2rem 0 0;
  padding-left: 1.1rem;
}

.auth-field__error {
  margin: 0;
  font-size: 0.8125rem;
  color: var(--website-danger);
}

/* ——— Actions row (remember / forgot) ——— */
.auth-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.375rem 0.75rem;
}

.auth-actions__remember {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  min-height: 2.75rem;
  font-size: 0.875rem;
  color: var(--website-text-secondary);
  cursor: pointer;
}

.auth-actions__remember input[type="checkbox"] {
  width: 1rem;
  height: 1rem;
  margin: 0;
  accent-color: var(--website-brand);
}

.auth-actions .auth-link {
  font-weight: 400;
}

.auth-link {
  border: none;
  background: none;
  padding: 0;
  font: inherit;
  font-size: 0.875rem;
  font-weight: 400;
  color: var(--website-link);
  cursor: pointer;
  text-decoration: none;
}

.auth-link:hover {
  color: var(--website-brand-hover);
  text-decoration: underline;
}

.auth-link:focus-visible {
  outline: 2px solid var(--website-focus);
  outline-offset: 2px;
  border-radius: 2px;
}

.auth-link:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  text-decoration: none;
}

.auth-footer .auth-link {
  font-weight: 500;
}

/* ——— Terms ——— */
.auth-terms {
  display: flex;
  align-items: baseline;
  gap: 0.4375rem;
  font-size: 0.8125rem;
  line-height: 1.4;
  color: var(--website-text-secondary);
  cursor: pointer;
}

.auth-terms input[type="checkbox"] {
  width: 1rem;
  height: 1rem;
  margin: 0;
  flex-shrink: 0;
  accent-color: var(--website-brand);
  align-self: baseline;
  transform: translateY(0.125rem);
}

.auth-terms a {
  color: var(--website-link);
  font-weight: 400;
  text-decoration: none;
}

.auth-terms a:hover {
  color: var(--website-brand-hover);
  text-decoration: underline;
}

.auth-terms a:focus-visible {
  outline: 2px solid var(--website-focus);
  outline-offset: 2px;
  border-radius: 2px;
}

/* ——— Primary submit (uses .btn where linked) ——— */
.auth-form .btn--primary {
  min-height: 2.875rem;
  margin-top: 0.125rem;
  box-shadow: none;
  transform: none;
  background: var(--website-brand);
  border-color: var(--website-brand);
  color: var(--website-on-brand);
  font-weight: 600;
}

.auth-form .btn--primary:hover {
  transform: none;
  background: var(--website-brand-hover);
  border-color: var(--website-brand-hover);
}

.auth-form .btn--primary:focus-visible {
  outline: 2px solid var(--website-text);
  outline-offset: 2px;
}

.auth-form .btn--primary:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.auth-form--signup .btn--primary {
  margin-top: 0.0625rem;
}

/* ——— Alerts ——— */
.auth-alert {
  border-radius: var(--website-radius-sm);
  padding: 0.6875rem 0.8125rem;
  font-size: 0.875rem;
  line-height: 1.45;
  margin-bottom: 0.625rem;
}

.auth-alert--error {
  background: rgba(215, 0, 21, 0.06);
  border: 1px solid rgba(215, 0, 21, 0.15);
  color: var(--website-danger);
}

.auth-alert--success {
  background: rgba(36, 138, 61, 0.08);
  border: 1px solid rgba(36, 138, 61, 0.2);
  color: var(--website-success);
}

.auth-alert--info {
  background: rgba(0, 119, 237, 0.06);
  border: 1px solid rgba(0, 119, 237, 0.12);
  color: var(--website-text-secondary);
}

.auth-alert strong {
  display: block;
  font-weight: 600;
  color: inherit;
}

.auth-alert p {
  margin: 0.3rem 0 0;
}

/* ——— Footer ——— */
.auth-footer {
  margin-top: 0.875rem;
  text-align: center;
  font-size: 0.875rem;
  color: var(--website-text-secondary);
}

#signupModal .auth-footer {
  margin-top: 0.75rem;
}

/* ——— Modal overlay shell ——— */
#loginModal,
#signupModal,
#forgotPasswordModal {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  overflow-y: auto;
  background: color-mix(in srgb, var(--website-bg) 88%, transparent);
  backdrop-filter: blur(8px);
}

#loginModal:not(.hidden),
#signupModal:not(.hidden),
#forgotPasswordModal:not(.hidden) {
  display: flex !important;
}

#loginModal.hidden,
#signupModal.hidden,
#forgotPasswordModal.hidden {
  display: none !important;
}

#loginModal > .auth-panel,
#signupModal > .auth-panel,
#forgotPasswordModal > .auth-panel {
  width: min(100%, 480px);
  max-height: min(92vh, 720px);
  overflow-y: auto;
  margin: auto;
}

#signupModal > .auth-panel {
  max-height: min(94vh, 780px);
}

#signupModal .auth-panel__header {
  margin-bottom: 0.8125rem;
}

/* ——— Verify / reset standalone states ——— */
.auth-state--center {
  text-align: center;
}

.auth-state .auth-panel__title {
  font-size: 1.25rem;
}

.auth-spinner {
  width: 2rem;
  height: 2rem;
  margin: 0 auto 1rem;
  border: 3px solid var(--website-border);
  border-top-color: var(--website-brand);
  border-radius: 50%;
  animation: auth-portal-spin 0.8s linear infinite;
}

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

.auth-icon {
  width: 2.75rem;
  height: 2.75rem;
  margin: 0 auto 0.875rem;
  border-radius: 999px;
  display: grid;
  place-items: center;
  font-size: 1.25rem;
  font-weight: 700;
}

.auth-icon--success {
  background: rgba(36, 138, 61, 0.12);
  color: var(--website-success);
}

.auth-icon--info {
  background: rgba(0, 119, 237, 0.1);
  color: var(--website-brand);
}

.auth-icon--error {
  background: rgba(215, 0, 21, 0.08);
  color: var(--website-danger);
}

.auth-verify-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.75rem;
  margin-top: 1.125rem;
  padding-top: 1rem;
  border-top: 1px solid var(--website-border);
}

.auth-verify-actions__link {
  font-size: 0.9375rem;
  font-weight: 500;
  line-height: 1.35;
  text-decoration: none;
  padding: 0.125rem 0;
}

.auth-verify-actions__link:hover {
  text-decoration: none;
  color: var(--website-brand-hover);
}

.auth-verify-feedback {
  margin: 0.75rem 0 0;
  font-size: 0.875rem;
  line-height: 1.45;
}

.auth-verify-feedback--success {
  color: var(--website-success);
}

.auth-verify-feedback--error {
  color: var(--website-danger);
}

/* ——— Post-signup / verification state polish (AUTH-2D) ——— */
#signupModal > .auth-panel:has(#signupVerifyView:not(.hidden)),
.auth-shell .auth-panel:has(.auth-state--check-email),
.auth-shell .auth-panel:has(.auth-state--verified) {
  width: min(100%, 38.75rem);
}

#signupModal > .auth-panel:has(#signupVerifyView:not(.hidden)) {
  padding: 1.375rem 1.5rem 1.5rem;
}

.auth-state--check-email .auth-panel__header--check-email {
  margin-bottom: 0.875rem;
}

.auth-state--check-email .auth-panel__title {
  font-size: 1.9375rem;
  font-weight: 700;
  line-height: 1.2;
}

.auth-check-email__body {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.auth-check-email__intro,
.auth-check-email__detail,
.auth-state--check-email .auth-panel__subtitle {
  margin: 0;
  font-size: 1rem;
  line-height: 1.45;
  color: var(--website-text-secondary);
}

.auth-check-email__email {
  margin: 0.125rem 0 0.625rem;
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.45;
  color: var(--website-text);
  word-break: break-word;
}

.auth-state--check-email .auth-verify-actions {
  margin-top: 1.125rem;
}

.auth-state--verified {
  padding: 1.75rem 0.25rem 2rem;
}

.auth-state--verified .auth-icon {
  width: 3.625rem;
  height: 3.625rem;
  margin: 0 auto 1.25rem;
  font-size: 1.375rem;
}

.auth-state--verified .auth-panel__title {
  font-size: 1.6875rem;
  font-weight: 700;
  line-height: 1.2;
}

.auth-state--verified .auth-panel__subtitle--lead {
  margin-top: 1rem;
  font-size: 1.3125rem;
  font-weight: 600;
  line-height: 1.3;
  color: var(--website-text);
}

.auth-state--verified__copy,
.auth-state--verified .auth-panel__subtitle:not(.auth-panel__subtitle--lead) {
  margin-top: 1rem;
  font-size: 1rem;
  line-height: 1.45;
  color: var(--website-text-secondary);
}

.auth-state--verified .btn--verify-continue {
  display: inline-flex;
  width: min(100%, 22.5rem);
  min-height: 3.25rem;
  margin-top: 1.625rem;
  border-radius: 0.5rem;
  box-shadow: none;
  transform: none;
  font-size: 1rem;
  font-weight: 600;
}

.auth-state--verified .btn--verify-continue:hover,
.auth-state--verified .btn--verify-continue:active {
  transform: none;
  box-shadow: none;
}

.auth-state--verified .auth-panel__hint {
  margin-top: 1.375rem;
  font-size: 0.9375rem;
  line-height: 1.45;
  color: var(--website-text-muted);
}

.hidden {
  display: none !important;
}

/* ——— Profile dropdown (post-login, light) ——— */
#userProfileDropdown {
  position: fixed;
  top: calc(var(--website-header-h) + 0.5rem);
  right: 1rem;
  z-index: 9998;
  width: min(16rem, calc(100vw - 2rem));
  background: var(--website-surface);
  border: 1px solid var(--website-border);
  border-radius: var(--website-radius-lg);
  box-shadow: 0 12px 32px rgba(17, 24, 39, 0.08);
  padding: 0.75rem;
}

#userProfileDropdown.hidden {
  display: none !important;
}

#userProfileDropdown a,
#userProfileDropdown button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.5rem 0.75rem;
  border: none;
  border-radius: var(--website-radius-sm);
  background: transparent;
  color: var(--website-text-secondary);
  text-decoration: none;
  font-size: 0.875rem;
  cursor: pointer;
}

#userProfileDropdown a:hover,
#userProfileDropdown button:hover {
  background: var(--website-surface-subtle);
  color: var(--website-text);
}

#userProfileDropdown #logoutBtn {
  color: var(--website-danger);
}

@media (max-width: 767px) {
  .auth-panel {
    padding: 1.25rem;
  }

  #signupModal > .auth-panel:has(#signupVerifyView:not(.hidden)) {
    padding: 1.25rem;
  }

  .auth-state--check-email .auth-panel__title {
    font-size: 1.875rem;
  }

  .auth-state--verified {
    padding: 1.5rem 0 1.75rem;
  }

  .auth-state--verified .auth-panel__title {
    font-size: 1.625rem;
  }

  .auth-form__row {
    grid-template-columns: 1fr;
  }

  #loginModal,
  #signupModal,
  #forgotPasswordModal {
    padding: 0.75rem;
  }
}

@media (max-width: 480px) {
  .auth-panel__title {
    font-size: 1.5rem;
  }
}
