/* ==========================================================================
   Auth modal + header avatar
   Design system: paper background, filled inputs (tertiary.light focus ring),
   contained buttons flat with 8% black hover tint.
   ========================================================================== */

/* The actions container holds both the avatar button and the search form.
   It needs position:relative so the logged-in user menu dropdown anchors
   to it rather than the nearest positioned ancestor further away.
   flex-direction: row-reverse so that in RTL the avatar (first DOM child)
   appears on the visual left, before the search form. */
.site-header__actions {
  position: relative;
  flex-direction: row-reverse;
}

.auth-modal__backdrop {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: none;
  align-items: flex-end;
  justify-content: center;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.auth-modal__backdrop.is-open {
  display: flex;
}

.auth-modal__panel {
  position: relative;
  width: 100%;
  max-width: 460px;
  max-height: 90vh;
  margin-bottom: calc(env(safe-area-inset-bottom, 0) + 24px);
  background: var(--background-paper);
  border: 1px solid var(--divider);
  border-radius: var(--radius-lg);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.12);
  overflow-y: auto;
  transform: translateY(20px);
  opacity: 0;
  transition: transform var(--transition), opacity var(--transition);
}

.auth-modal__backdrop.is-open .auth-modal__panel {
  transform: translateY(0);
  opacity: 1;
}

.auth-modal__close {
  position: absolute;
  top: 12px;
  right: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}

.auth-modal__close:hover {
  background: var(--action-hover);
  color: var(--text-primary);
}

.auth-modal__header {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-start;
  padding: 32px 32px 24px;
}

.auth-modal__title {
  margin: 0;
  color: var(--text-primary);
  font-family: var(--font-family);
  font-size: 1.75rem;
  font-weight: 700;
  line-height: var(--line-height);
}

.auth-modal__subtitle {
  margin: 0;
  color: var(--text-secondary);
  font-family: var(--font-family);
  font-size: 0.875rem;
  font-weight: 400;
  line-height: var(--line-height);
}

.auth-modal__body {
  padding: 0 32px 16px;
}

.auth-modal__form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Filled input (Design system §9: paper bg, flat, tertiary.light focus ring) */
.auth-modal__field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.auth-modal__label {
  font-family: var(--font-family);
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-primary);
  line-height: var(--line-height);
}

.auth-modal__input {
  width: 100%;
  height: 48px;
  padding: 0 16px;
  border: 0;
  border-radius: 18px;
  background: var(--background-paper);
  color: var(--text-primary);
  font-family: var(--font-family);
  font-size: 0.875rem;
  font-weight: 500;
  line-height: var(--line-height);
  transition: background var(--transition), box-shadow var(--transition);
}

.auth-modal__input::placeholder {
  color: var(--gray);
}

.auth-modal__input:hover {
  background: color-mix(in srgb, var(--background-paper), #000000 8%);
}

.auth-modal__input:focus {
  outline: 0;
  box-shadow: 0 0 0 1px var(--tertiary-light);
}

.auth-modal__input[dir="ltr"] {
  direction: ltr;
  text-align: left;
}

.auth-modal__input--error {
  box-shadow: 0 0 0 1px var(--error-main);
}

.auth-modal__error-text {
  margin-top: 4px;
  font-family: var(--font-family);
  font-size: 0.625rem;
  font-weight: 400;
  color: var(--error-main);
  line-height: var(--line-height);
}

/* Phone input with 09 prefix */
.auth-modal__phone-field {
  display: flex;
  align-items: center;
  gap: 4px;
  /* row-reverse so that in RTL the prefix (first DOM child) renders on
     the visual left, with the input field to its right. */
  flex-direction: row-reverse;
}

.auth-modal__phone-prefix {
  display: inline-flex;
  align-items: center;
  padding: 0 12px;
  height: 48px;
  border-radius: 16px 0 0 16px;
  background: var(--background-foreground);
  font-family: var(--font-family);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
}

.auth-modal__phone-input {
  flex: 1;
  border-radius: 0 16px 16px 0;
}

/* OTP input: 6 digit boxes */
.auth-modal__otp-field {
  display: flex;
  justify-content: center;
  gap: 8px;
  /* row-reverse so that in RTL the first input box (index 0) renders on
     the visual left, reading left-to-right like a standard OTP field. */
  flex-direction: row-reverse;
}

.auth-modal__otp-input {
  width: 56px;
  height: 56px;
  padding: 0;
  border: 0;
  border-radius: var(--radius-sm);
  background: var(--background-paper);
  color: var(--text-primary);
  font-family: var(--font-family);
  font-size: 1.5rem;
  font-weight: 700;
  text-align: center;
  transition: background var(--transition), box-shadow var(--transition);
}

.auth-modal__otp-input:focus {
  outline: 0;
  box-shadow: 0 0 0 1px var(--tertiary-light);
}

.auth-modal__otp-input--error {
  box-shadow: 0 0 0 1px var(--error-main);
}

.auth-modal__otp-input[type="text"] {
  direction: ltr;
  text-align: center;
}

/* Submit button (contained, flat, primary pink) */
.auth-modal__submit {
  width: 100%;
  height: 48px;
  padding: 0 16px;
  border: 0;
  border-radius: 18px;
  background: var(--primary-main);
  color: var(--primary-contrast);
  font-family: var(--font-family);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background-color var(--transition), color var(--transition);
}

.auth-modal__submit:hover:not(:disabled) {
  background: color-mix(in srgb, var(--primary-main), #000000 8%);
}

.auth-modal__submit:disabled {
  opacity: var(--disabled-opacity);
  cursor: not-allowed;
}

/* Resend link + counter */
.auth-modal__resend {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-family: var(--font-family);
  font-size: 0.8125rem;
  font-weight: 400;
  color: var(--text-secondary);
  line-height: var(--line-height);
}

.auth-modal__resend-button {
  border: 0;
  background: transparent;
  font-family: var(--font-family);
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--primary-dark);
  cursor: pointer;
  transition: color var(--transition);
}

.auth-modal__resend-button:hover {
  color: var(--text-primary);
}

.auth-modal__resend-counter {
  font-variant-numeric: tabular-nums;
}

/* Back to phone link */
.auth-modal__back {
  margin-top: 8px;
  text-align: center;
}

.auth-modal__back-button {
  border: 0;
  background: transparent;
  font-family: var(--font-family);
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--primary-dark);
  cursor: pointer;
  transition: color var(--transition);
}

.auth-modal__back-button:hover {
  color: var(--text-primary);
}

/* Step transition */
.auth-modal__step {
  display: none;
}

.auth-modal__step.is-active {
  display: block;
}

/* Header avatar */
.site-header__avatar-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: var(--radius-pill);
  background: transparent;
  cursor: pointer;
  flex-shrink: 0;
  transition: background var(--transition), transform var(--transition);
}

.site-header__avatar-btn:hover {
  background: var(--action-hover);
  transform: scale(1.04);
}

/* CTA variant for logged-out state: contained button matching Bapet-landing
   NavbarAuth style — tertiary (black) background, white text, no box-shadow. */
.site-header__avatar-btn--cta {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 120px;
  height: 40px;
  padding: 0 12px;
  border: 0;
  border-radius: var(--radius-lg);
  background: var(--tertiary-main);
  color: var(--tertiary-contrast);
  font-family: var(--font-family);
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  transition: background-color var(--transition), color var(--transition);
}

/* Mobile: show only icon, hide text label */
.site-header__avatar-label {
  display: inline-block;
}
.site-header__avatar-icon {
  display: none;
}

@media (max-width: 767px) {
  .site-header__avatar-btn--cta {
    min-width: 40px;
    padding: 0;
    gap: 0;
  }
  .site-header__avatar-label {
    display: none;
  }
  .site-header__avatar-icon {
    display: inline-block;
    flex-shrink: 0;
    color: var(--tertiary-contrast);
  }
}

.site-header__avatar-btn--cta:hover {
  background: color-mix(in srgb, var(--tertiary-main), #000000 8%);
}

.site-header__avatar {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-pill);
  object-fit: cover;
  display: block;
}

.site-header__avatar-label {
  white-space: nowrap;
}

/* User menu dropdown (logged-in state) */
.site-header__user-menu {
  position: absolute;
  top: 100%;
  left: 0;
  z-index: 1000;
  display: none;
  min-width: 180px;
  padding: 8px;
  background: var(--background-paper);
  border: 1px solid var(--divider);
  border-radius: var(--radius-lg);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.12);
}

.site-header__user-menu.is-open {
  display: block;
}

.site-header__user-menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-family);
  font-size: 0.8125rem;
  font-weight: 400;
  text-decoration: none;
  transition: background var(--transition), color var(--transition);
}

.site-header__user-menu-item:hover {
  background: var(--action-hover);
  color: var(--text-primary);
}

.site-header__user-menu-item--logout {
  color: var(--error-main);
}

.site-header__user-menu-item--logout:hover {
  background: color-mix(in srgb, var(--error-light), #000000 8%);
  color: var(--error-main);
}

/* Mobile: full-width modal panel */
@media (max-width: 767px) {
  .auth-modal__panel {
    max-width: 100%;
    max-height: 100vh;
    margin: 0;
    margin-bottom: env(safe-area-inset-bottom, 0);
    border-radius: 0;
    height: 100vh;
  }

  .auth-modal__header {
    padding: 32px 20px 24px;
  }

  .auth-modal__body {
    padding: 0 20px 16px;
  }
}
