.phone-input-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  text-align: center;
}

.phone-input-title {
  color: var(--light-onPrimary);
  font-family: var(--display-display-small-font-family);
  font-size: var(--display-display-small-font-size);
  line-height: var(--display-display-small-line-height);
  font-weight: var(--display-display-small-font-weight);
  font-style: var(--display-display-small-font-style);
}

.text-highlight {
  color: var(--light-tertiary);
  font-family: 'Gentium Book Basic', serif;
  font-size: 40px;
  font-style: italic;
  font-weight: 400;
  line-height: 48px;
  letter-spacing: -1px;
}

.phone-input-layout {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  max-width: 500px;
  min-width: 0;
  padding: 0 24px;
  width: 100%;
  align-self: center;
}

.phone-input-section {
  width: 100%;
  display: flex;
  justify-content: center;
  padding: 24px 0;
  background: transparent;
}

.phone-input-form {
  width: 100%;
  display: flex;
  justify-content: flex-start;
}

.phone-input-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0;
  width: 100%;
  max-width: 100%;
  position: relative;
  z-index: 0;
}

.phone-input-row::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 48px;
  background: linear-gradient(162deg, #444DF3 17.17%, #9730F2 87.07%);
  border-radius: 24px;
  z-index: -1;
}

.phone-input-container {
  flex: 1 1 auto;
  min-width: 0;
  position: relative;
  z-index: 3;
}

.phone-input-wrapper {
  display: flex;
  width: 100%;
  min-width: 0;
  height: 48px;
  padding: 4px 20px 4px 4px;
  align-items: center;
  gap: 0;
  border-radius: 24px;
  border: 3px solid transparent;
  background: var(--light-surface);
  transition: border-color 120ms ease, box-shadow 120ms ease, background 120ms ease;
  overflow: hidden;
  position: relative;
  z-index: 2;
}

.phone-input-wrapper.is-prefix-hidden {
  padding-left: 20px;
}

.phone-input-wrapper:not(.disabled):not(.focused):not(.error):hover {
  border-color: var(--fixed-phoneInputHover);
  background: var(--light-surface);
}

.phone-input-wrapper.focused {
  border-color: var(--fixed-phoneInputFocus);
  box-shadow: 4px 0 32px 0 rgba(0, 0, 0, 0.50);
}

.phone-input-wrapper.error {
  border: 3px solid var(--light-error);
}

.phone-input-wrapper.error.focused {
  border: 3px solid var(--light-error);
}

.phone-input-wrapper.disabled {
  border-color: var(--light-outline);
  background: var(--light-surfaceContainerLow);
  opacity: 1;
  cursor: not-allowed;
}

.phone-input-country-code {
  color: var(--light-onSurface);
  font-family: var(--body-body-large-font-family);
  font-size: var(--body-body-large-font-size);
  font-style: var(--body-body-large-font-style);
  font-weight: var(--body-body-large-font-weight);
  line-height: var(--body-body-large-line-height);
}

.phone-input-field {
  flex: 1 1 0;
  min-width: 0;
  height: 100%;
  background: transparent;
  border: none;
  outline: none;
  color: var(--light-onSurface);
  font-family: var(--body-body-large-font-family);
  font-size: 14px;
  font-style: var(--body-body-large-font-style);
  font-weight: var(--body-body-large-font-weight);
  line-height: 16px;
  margin-left: 8px;
  padding: 0;
}

.phone-input-wrapper.is-prefix-hidden .phone-input-field {
  margin-left: 0;
}

.phone-input-provider-suffix {
  flex: 0 1 auto;
  min-width: 0;
  max-width: 88px;
  margin-left: 8px;
  overflow: hidden;
  white-space: nowrap;
  color: var(--light-onSurfaceVariant);
  text-align: right;
  text-overflow: ellipsis;
  font-family: var(--label-label-large-font-family);
  font-size: var(--label-label-large-font-size);
  font-style: var(--label-label-large-font-style);
  font-weight: var(--label-label-large-font-weight);
  line-height: 16px;
}

.phone-input-provider-suffix[hidden] {
  display: none;
}

.phone-input-field::placeholder {
  color: var(--light-outline);
  font-family: var(--body-body-medium-font-family);
  font-size: var(--body-body-medium-font-size);
  font-style: var(--body-body-medium-font-style);
  font-weight: 600;
  line-height: 16px;
}

.phone-input-error {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  display: inline-flex;
  /* Let the error bubble size itself based on the text (intrinsic width),
     but cap it to the viewport so very long strings don't overflow the page. */
  box-sizing: border-box;
  width: max-content;
  max-width: calc(100vw - 32px);
  padding: 8px 16px;
  align-items: center;
  gap: 4px;
  border-radius: 16px;
  background: var(--light-error);
  /* Allow natural wrapping when the message exceeds the viewport cap. */
  white-space: normal;
  color: var(--light-onPrimary);
  font-family: var(--label-label-large-font-family);
  font-size: var(--label-label-large-font-size);
  font-style: var(--label-label-large-font-style);
  font-weight: var(--label-label-large-medium-font-weight);
  line-height: var(--label-label-large-line-height);
  opacity: 0;
  visibility: visible;
  pointer-events: none;
  transform: translate3d(0, -14px, 0);
  transform-origin: top left;
  will-change: transform;
  z-index: 4;
}

.phone-input-error.is-visible {
  opacity: 1;
  visibility: visible;
  transform: translate3d(0, 0, 0);
  /* Transition only on the visible state so the error appears smoothly
     but disappears instantly when the class is removed. */
  transition: opacity 300ms ease-in-out, transform 300ms ease-in-out;
}

.phone-input-error.is-bouncing {
  animation: phone-input-error-drop-bounce 420ms cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes phone-input-error-drop-bounce {
  0% {
    transform: translate3d(0, -16px, 0);
  }
  58% {
    transform: translate3d(0, 4px, 0);
  }
  78% {
    transform: translate3d(0, -2px, 0);
  }
  90% {
    transform: translate3d(0, 1px, 0);
  }
  100% {
    transform: translate3d(0, 0, 0);
  }
}

@media (min-width: 1080px) {
  .phone-input-layout {
    flex: 1 1 40%;
    min-width: 0;
    justify-content: center;
    padding: 0 24px;
    align-self: center;
  }

  .phone-input-error {
    top: calc(100% + 8px);
    left: 0;
    right: auto;
    order: initial;
    margin-inline: 0;
    text-align: left;
  }
}

@media (max-width: 1081px) {
  .phone-input-layout {
    flex: 1 1 auto;
    min-width: 0;
    max-width: 100%;
    justify-content: center;
    padding: 0 24px;
    align-self: center;
  }

  /* Center the error bubble under the input on narrow screens
      Keep the max-width so it never overflows the container. */
  .phone-input-error {
    position: absolute;
    top: calc(100% + 8px);
    left: 50%;
    right: auto;
    margin-inline: 0;
    max-width: min(calc(100vw - 32px), 100%);
    transform-origin: top center;
    transform: translate3d(-50%, -14px, 0);
    text-align: center;
  }

  .phone-input-error.is-visible {
    transform: translate3d(-50%, 0, 0);
  }

  @keyframes phone-input-error-drop-bounce {
    0% {
      transform: translate3d(-50%, -16px, 0);
    }
    58% {
      transform: translate3d(-50%, 4px, 0);
    }
    78% {
      transform: translate3d(-50%, -2px, 0);
    }
    90% {
      transform: translate3d(-50%, 1px, 0);
    }
    100% {
      transform: translate3d(-50%, 0, 0);
    }
  }
}

@media (prefers-reduced-motion: reduce) {
  .phone-input-error,
  .phone-input-error.is-visible,
  .phone-input-error.is-bouncing {
    animation: none;
    will-change: auto;
    opacity: 1;
    transform: none;
    transition: none;
  }

  .phone-input-error {
    visibility: hidden;
  }

  .phone-input-error.is-visible {
    visibility: visible;
  }
}

/* Country selector menu (anchored below the phone input) */
.phone-country-menu {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  box-sizing: border-box;
  width: auto; 
  max-width: 100%;
  max-height: 400px;
  padding: 8px;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  border-radius: 24px;
  border: 1px solid var(--light-outlineVariant);
  background: var(--light-surface);
  box-shadow: 0 12px 79.4px 0 rgba(0, 0, 0, 0.16);
  overflow: auto;
  z-index: 99999;
}

.phone-country-menu.show {
  display: flex;
}

.phone-country-menu-search {
  box-sizing: border-box;
  display: flex;
  height: 48px;
  padding: 0 16px 0 8px;
  align-items: center;
  gap: 8px;
  align-self: stretch;
  border: 1px solid transparent;
  border-radius: 16px;
  background: var(--light-surfaceContainerLow);
  transition: background-color 120ms ease, border-color 120ms ease;
}

.phone-country-menu-search:hover {
  background: rgba(42, 43, 51, 0.08);
  background: color-mix(
    in srgb,
    var(--light-onSurface, #2A2B33) 8%,
    transparent
  );
}

.phone-country-menu-search:focus-within {
  padding-left: 16px;
  border-color: var(--light-onSurface, #2A2B33);
  background: var(--light-surfaceContainerLow, #F2F3F7);
}

.phone-country-menu-search:focus-within .phone-country-menu-search-icon {
  display: none;
}

.phone-country-menu-search-icon {
  width: 24px;
  height: 24px;
  flex: 0 0 auto;
}

.phone-country-menu-search-input {
  flex: 1 1 auto;
  min-width: 0;
  border: none;
  outline: none;
  background: transparent;
  color: var(--light-onSurface);
  font-family: var(--body-body-medium-font-family);
  font-size: var(--body-body-medium-font-size);
  font-style: var(--body-body-medium-font-style);
  font-weight: var(--body-body-medium-font-weight);
  line-height: 17px;
  letter-spacing: -0.2px;
}

.phone-country-menu-search-input::placeholder {
  color: var(--light-onSurfaceVariant);
  font-family: var(--body-body-medium-font-family);
  font-size: var(--body-body-medium-font-size);
  font-style: var(--body-body-medium-font-style);
  font-weight: var(--body-body-medium-font-weight);
  line-height: 17px;
  letter-spacing: -0.2px;
}

.phone-country-menu-search-input::-webkit-search-cancel-button {
  -webkit-appearance: none;
  appearance: none;
}

.phone-country-menu-list {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.phone-country-menu-status {
  width: 100%;
  text-align: center;
  color: var(--light-onSurfaceVariant);
  padding: 16px 12px;
  font-family: var(--body-body-medium-font-family);
  font-size: var(--body-body-medium-font-size);
  font-style: var(--body-body-medium-font-style);
  font-weight: var(--body-body-medium-font-weight);
  line-height: var(--body-body-medium-line-height);
}

.phone-country-menu-status--not-found {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  padding: 16px 16px;
  text-align: left;
}

.phone-country-menu-status-icon {
  width: 20px;
  height: 20px;
  flex: 0 0 auto;
}

.phone-country-menu-status-text {
  color: var(--light-outline, #9D9FB2);
  font-family: Rubik;
  font-size: 14px;
  font-style: normal;
  font-weight: 400;
  line-height: 16px;
}

.phone-country-menu-shimmer-list {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.phone-country-menu-shimmer {
  width: 100%;
  height: 48px;
  border-radius: 16px;
  background: var(
    --loadingGradient,
    linear-gradient(114deg, #E8E9EC 34.74%, #F9F9FB 71.59%)
  );
}

.phone-country-menu-item {
  -webkit-appearance: none;
  appearance: none;
  outline: none;
  -webkit-tap-highlight-color: transparent;
  position: relative;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border: none;
  border-radius: 16px;
  background: transparent;
  padding: 10px 12px;
  text-align: left;
  cursor: pointer;
  overflow: hidden;
  transition: background-color 120ms ease;
  --md-ripple-hover-color: var(--light-onSurface, #2A2B33);
  --md-ripple-pressed-color: var(--light-onSurface, #2A2B33);
  --md-ripple-hover-opacity: 0.08;
  --md-ripple-pressed-opacity: 0.12;
}

.phone-country-menu-item:hover,
.phone-country-menu-item:focus-visible,
.phone-country-menu-item.is-selected {
  background: var(--light-surfaceContainerLow);
}

.phone-country-menu-item:active {
  background: var(--light-surfaceContainerLow);
}

.phone-country-menu-item:focus-visible {
  outline: 2px solid var(--fixed-phoneInputFocus);
  outline-offset: 2px;
}

.phone-country-menu-item-main {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1 1 auto;
}

.phone-country-menu-item-flag {
  position: relative;
  width: 24px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
}

.phone-country-menu-item-flag-country {
  position: absolute;
  top: 0;
  left: 0;
  width: 20px;
  height: 20px;
  aspect-ratio: 1 / 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border-radius: 999px;
  background: var(--light-surface, #FDFDFF);
  z-index: 1;
}

.phone-country-menu-item-flag-country-image {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: inherit;
  object-fit: cover;
}

/* Same error-icon pattern as the prefix button — fixed 12x12 when the
   country image fails to load, centered by the flex container. */
.phone-country-menu-item-flag-country-image--error {
  width: 12px;
  height: 12px;
  color: var(--dark-onSurface, #ECEDF5);
  object-fit: none;
  border-radius: 0;
}

.phone-country-menu-item-flag-country--loading {
  background: var(
    --loadingGradient,
    linear-gradient(114deg, #E8E9EC 34.74%, #F9F9FB 71.59%)
  );
}

.phone-country-menu-item-flag-country--fallback {
  border: 1px solid var(--light-outlineVariant);
}

.phone-country-menu-item-flag-provider {
  position: absolute;
  right: -3px;
  bottom: -3px;
  width: 16px;
  height: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border-radius: 999px;
  background: var(--light-surface, #FFFFFF);
  z-index: 2;
}

.phone-country-menu-item-flag-provider-image {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: inherit;
  object-fit: contain;
}

/* Same error-icon pattern as the prefix button — fixed 9x9 when the
   provider image fails to load, centered by the flex container. */
.phone-country-menu-item-flag-provider-image--error {
  width: 8px;
  height: 8px;
  color: var(--dark-onSurface, #ECEDF5);
  object-fit: contain;
  border-radius: 0;
}

.phone-country-menu-item-flag-provider--loading {
  border-radius: 14px;
  border: 2px solid var(--light-surface, #FDFDFF);
  background: var(
    --loadingGradient,
    linear-gradient(114deg, #E8E9EC 34.74%, #F9F9FB 71.59%)
  );
}

.phone-country-menu-item-copy {
  min-width: 0;
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
}

.phone-country-menu-item-country {
  color: var(--light-onSurfaceVariant);
  font-family: var(--body-body-medium-font-family);
  font-size: var(--body-body-medium-font-size);
  font-style: var(--body-body-medium-font-style);
  font-weight: var(--body-body-medium-font-weight);
  line-height: 16px;
}

.phone-country-menu-item-provider {
  color: var(--light-onSurface);
  font-family: var(--label-label-large-font-family);
  font-size: var(--label-label-large-font-size);
  font-style: var(--label-label-large-font-style);
  font-weight: var(--label-label-large-font-weight);
  line-height: 16px;
}

.phone-country-menu-item-dial-code {
  color: var(--light-onSurface);
  font-family: var(--body-body-large-font-family);
  font-size: var(--body-body-large-font-size);
  font-style: var(--body-body-large-font-style);
  font-weight: var(--body-body-large-font-weight);
  line-height: var(--body-body-large-line-height);
  white-space: nowrap;
  flex: 0 0 auto;
}
