/* ==========================================================================
   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: 9999;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  padding: env(safe-area-inset-top, 0) env(safe-area-inset-right, 0) env(safe-area-inset-bottom, 0) env(safe-area-inset-left, 0);
}

.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);
  /* White surface so the paper-filled inputs (same tone as the old panel)
     read as a visible rounded field. */
  background: var(--background-default);
  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 — full width, no prefix */
.auth-modal__phone-field {
  display: flex;
  align-items: center;
}

.auth-modal__phone-input {
  flex: 1;
  width: 100%;
  border-radius: 16px;
}

/* 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;
}

/* OTP submit loading: spinner while verifying, WP login and page reload */
.auth-modal__submit.is-loading {
  position: relative;
}

.auth-modal__submit.is-loading:disabled {
  opacity: 1;
  cursor: progress;
}

.auth-modal__submit.is-loading::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 16px;
  height: 16px;
  margin: -8px 0 0 -8px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: auth-modal-spin 0.7s linear infinite;
}

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

/* 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;
}

/* Shop auto-inject wrapper: anchors the user-menu dropdown when the
   button is moved into a block-theme header with no blog-style container. */
.bapet-shop-auth-slot {
  position: relative;
  display: inline-flex;
  align-items: center;
}

/* Woodmart header tools: behave like a native tools element so the
   button aligns with cart/account icons in the header row. */
.wd-header-my-account .bapet-shop-auth-slot {
  display: inline-flex;
  align-items: center;
  height: 100%;
}

/* Header avatar — scoped above theme button resets (e.g. Woodmart
   `:is(.btn,.button,button,...)`) so the mag look survives. */
.auth-modal,
.bapet-shop-auth-slot,
button.site-header__avatar-btn {
  text-transform: none;
  letter-spacing: normal;
}

button.site-header__avatar-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: var(--radius-pill);
  background: transparent;
  box-shadow: none;
  font-size: inherit;
  font-weight: inherit;
  color: inherit;
  cursor: pointer;
  flex-shrink: 0;
  transition: background var(--transition), transform var(--transition);
}

button.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. */
button.site-header__avatar-btn--cta {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 120px;
  height: 40px;
  min-height: 0;
  padding: 0 12px;
  border: 0;
  border-radius: var(--radius-lg);
  background: var(--tertiary-main);
  box-shadow: none;
  color: var(--tertiary-contrast);
  font-family: var(--font-family);
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: none;
  letter-spacing: normal;
  cursor: pointer;
  transition: background-color var(--transition), color var(--transition);
}

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

/* 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);
}

/* Tablet: center modal, avoid bottom toolbar (z-index 350) and sticky header */
@media (min-width: 768px) and (max-width: 1024px) {
  .auth-modal__backdrop {
    align-items: center;
    padding-bottom: max(env(safe-area-inset-bottom, 0), 70px); /* toolbar height ~55px + gap */
  }
  .auth-modal__panel {
    margin-bottom: 0;
    max-height: 80vh;
  }
  /* Tablet: icon-only login button to save space */
  button.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);
  }
  /* But on my-account page, keep full button with text */
  .bapet-shop-auth-myaccount .site-header__avatar-btn--cta {
    min-width: 0;
    width: 100%;
    max-width: 280px;
    padding: 0 24px;
    gap: 12px;
    height: 56px;
    font-size: 1rem;
    font-weight: 600;
  }
  .bapet-shop-auth-myaccount .site-header__avatar-label {
    display: inline-block;
  }
}

/* Mobile: full-width modal panel, above everything */
@media (max-width: 767px) {
  .auth-modal__backdrop {
    align-items: stretch;
    justify-content: stretch;
    padding: 0;
  }
  .auth-modal__panel {
    max-width: 100%;
    max-height: 100vh;
    height: 100vh;
    margin: 0;
    border-radius: 0;
    border: none;
    box-shadow: none;
    display: flex;
    flex-direction: column;
  }
  .auth-modal__header {
    padding: 32px 20px 24px;
    flex-shrink: 0;
  }
  .auth-modal__body {
    padding: 0 20px 16px;
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .auth-modal__close {
    top: 16px;
    right: 16px;
    z-index: 10;
  }

  /* OTP: shrink boxes to fit narrow viewports (e.g. 360px) */
  .auth-modal__otp-field {
    gap: 6px;
  }
  .auth-modal__otp-input {
    width: 48px;
    height: 48px;
    font-size: 1.25rem;
  }

  /* Mobile: icon-only login button to save space */
  button.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);
  }
  /* But on my-account page, keep full button with text */
  .bapet-shop-auth-myaccount .site-header__avatar-btn--cta {
    min-width: 0;
    width: 100%;
    max-width: 280px;
    padding: 0 24px;
    gap: 12px;
    height: 52px;
    font-size: 0.9375rem;
    font-weight: 600;
  }
  .bapet-shop-auth-myaccount .site-header__avatar-label {
    display: inline-block;
  }

  /* Phone input: >=16px prevents iOS zoom on focus */
  .auth-modal__input {
    font-size: 1rem !important; /* 16px */
  }
}

/* Ensure inputs are always clickable */
.auth-modal__panel,
.auth-modal__panel * {
  touch-action: manipulation;
}

.auth-modal__backdrop.is-open {
  touch-action: auto;
}



/* Woodmart compat: theme button/input resets outrank plain class
   selectors, so re-assert the mag look with higher specificity. */
.auth-modal button.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;
  min-height: 0;
  box-shadow: none;
  text-transform: none;
  letter-spacing: normal;
}

.auth-modal button.auth-modal__submit:hover:not(:disabled) {
  color: var(--primary-contrast);
}

.auth-modal button.auth-modal__close {
  position: absolute;
  top: 12px;
  right: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  box-shadow: none;
  color: var(--text-secondary);
  text-transform: none;
  letter-spacing: normal;
}

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

.auth-modal button.auth-modal__resend-button,
.auth-modal button.auth-modal__back-button {
  min-height: 0;
  padding: 0;
  border: 0;
  box-shadow: none;
  text-transform: none;
  letter-spacing: normal;
}

.auth-modal input.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;
  min-height: 0;
  max-width: none;
  box-shadow: none;
}

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

.auth-modal input.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;
  min-height: 0;
  max-width: none;
  box-shadow: none;
}

.auth-modal input.auth-modal__input:focus,
.auth-modal input.auth-modal__otp-input:focus {
  box-shadow: 0 0 0 1px var(--tertiary-light);
  border-color: transparent;
}

.auth-modal input.auth-modal__input--error,
.auth-modal input.auth-modal__otp-input--error {
  box-shadow: 0 0 0 1px var(--error-main);
  border-color: transparent;
}

/* My-account page override for logged-out users */
.bapet-shop-auth-myaccount {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  background: var(--default-bg-color);
}
.bapet-shop-auth-myaccount__inner {
  max-width: 360px;
  width: 100%;
  text-align: center;
}
.bapet-shop-auth-myaccount__title {
  margin: 0 0 12px;
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.3;
}
.bapet-shop-auth-myaccount__desc {
  margin: 0 0 28px;
  font-size: 1rem;
  color: var(--text-secondary);
  line-height: 1.6;
}
.bapet-shop-auth-myaccount .site-header__avatar-btn--cta {
  width: 100%;
  max-width: 280px;
  min-width: 0;
  height: 56px;
  padding: 0 24px;
  gap: 12px;
  font-size: 1rem;
  font-weight: 600;
}
.bapet-shop-auth-myaccount .site-header__avatar-label {
  display: inline-block;
}
.bapet-shop-auth-myaccount .site-header__avatar-icon {
  display: inline-block;
  flex-shrink: 0;
}

/* Mobile my-account */
@media (max-width: 767px) {
  .bapet-shop-auth-myaccount__title {
    font-size: 1.5rem;
  }
  .bapet-shop-auth-myaccount .site-header__avatar-btn--cta {
    height: 52px;
    font-size: 0.9375rem;
  }
}
