.phone-country-field {
  position: relative;
  width: 100%;
  min-width: 0;
  z-index: 20;
}

.phone-country-group {
  display: grid;
  grid-template-columns: minmax(130px, 155px) minmax(0, 1fr);
  align-items: stretch;
  width: 100%;
  min-height: 46px;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  background: #ffffff;
  overflow: visible;
  direction: ltr;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
  box-sizing: border-box;
}

.phone-country-group:focus-within {
  border-color: #3b82f6;
  box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.1);
}

.phone-country-picker {
  position: relative;
  display: grid;
  grid-template-columns: 44px minmax(50px, 1fr) 22px;
  align-items: center;
  min-width: 0;
  min-height: 46px;
  border-right: 1px solid #cbd5e1;
  background: #ffffff;
  direction: ltr;
  cursor: pointer;
}

.phone-country-flag {
  display: block;
  width: 24px;
  height: 18px;
  object-fit: cover;
  justify-self: center;
  align-self: center;
  border-radius: 2px;
  box-shadow: 0 0 0 1px rgba(15, 23, 42, 0.08);
}

.phone-country-code {
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  min-width: 0;
  height: 100%;
  color: #0f172a;
  font-size: 14px;
  font-weight: 800;
  white-space: nowrap;
}

.phone-country-picker::after {
  content: "";
  width: 8px;
  height: 8px;
  border-right: 2px solid #0f172a;
  border-bottom: 2px solid #0f172a;
  transform: rotate(45deg);
  justify-self: center;
  margin-top: -4px;
  pointer-events: none;
}

.phone-country-select {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.phone-country-number {
  width: 100%;
  min-width: 0;
  min-height: 46px;
  padding: 12px 14px;
  border: 0;
  border-radius: 0 10px 10px 0;
  background: #ffffff;
  color: #0f172a;
  font-size: 14px;
  line-height: 1.4;
  box-sizing: border-box;
  outline: none;
  direction: ltr;
  text-align: left;
}

.phone-country-number::placeholder {
  color: #94a3b8;
}

.phone-country-dropdown {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 8px);
  z-index: 10000;
  display: none;
  width: 100%;
  max-width: min(100%, calc(100vw - 24px));
  padding: 14px;
  border: 1px solid #e2e8f0;
  border-radius: 18px;
  background: #ffffff;
  box-shadow: 0 18px 45px rgba(15, 23, 42, 0.18);
  direction: ltr;
  box-sizing: border-box;
}

.phone-country-dropdown.is-open {
  display: block;
  z-index: 10000;
}

.phone-country-search {
  width: 100%;
  min-height: 42px;
  margin-bottom: 12px;
  padding: 10px 16px;
  border: 0;
  border-radius: 999px;
  background: #f8fafc;
  color: #0f172a;
  font-size: 14px;
  outline: none;
  direction: rtl;
  text-align: right;
}

.phone-country-list {
  max-height: 280px;
  overflow-y: auto;
  padding: 4px 0;
}

.phone-country-option {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  align-items: center;
  width: 100%;
  gap: 12px;
  padding: 10px 12px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: #0f172a;
  cursor: pointer;
  text-align: left;
  font-size: 15px;
  transition: background 0.15s ease;
}

.phone-country-option:hover,
.phone-country-option.is-selected {
  background: #f1f5f9;
}

.phone-country-option.is-selected::after {
  content: "✓";
  color: #0f172a;
  font-weight: 900;
}

.phone-country-option img {
  width: 30px;
  height: 22px;
  object-fit: cover;
  border-radius: 3px;
  box-shadow: 0 0 0 1px rgba(15, 23, 42, 0.08);
}

.phone-country-option-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.phone-country-option-code {
  color: #475569;
  font-weight: 800;
  direction: ltr;
}

.phone-country-error {
  display: none;
  margin-top: 6px;
  color: #ef4444;
  font-size: 12.5px;
  font-weight: 600;
}

.phone-country-field.has-error .phone-country-group {
  border-color: #ef4444;
}

.phone-country-field.has-error .phone-country-error {
  display: block;
}

@media (max-width: 520px) {
  .phone-country-group {
    grid-template-columns: minmax(104px, 126px) minmax(0, 1fr);
    min-height: 44px;
  }

  .phone-country-picker {
    grid-template-columns: 34px minmax(42px, 1fr) 18px;
    min-height: 44px;
  }

  .phone-country-flag {
    width: 21px;
    height: 15px;
  }

  .phone-country-code,
  .phone-country-number {
    font-size: 13.5px;
  }

  .phone-country-number {
    padding-inline: 10px;
    min-height: 44px;
  }

  .phone-country-dropdown {
    left: 50%;
    right: auto;
    width: calc(100vw - 24px);
    max-width: 360px;
    padding: 12px;
    transform: translateX(-50%);
  }

  .phone-country-list {
    max-height: min(280px, 48vh);
  }

  .phone-country-option {
    grid-template-columns: 36px minmax(0, 1fr) auto;
    gap: 8px;
    padding: 9px 10px;
    font-size: 14px;
  }

  .phone-country-option img {
    width: 28px;
    height: 20px;
  }
}

@media (max-width: 414px) {
  .phone-country-group {
    grid-template-columns: minmax(98px, 118px) minmax(0, 1fr);
    min-height: 42px;
  }

  .phone-country-picker {
    grid-template-columns: 30px minmax(38px, 1fr) 16px;
    min-height: 42px;
  }

  .phone-country-flag {
    width: 20px;
    height: 14px;
  }

  .phone-country-code,
  .phone-country-number {
    font-size: 12.5px;
  }

  .phone-country-number {
    min-height: 42px;
    padding-inline: 8px;
  }

  .phone-country-dropdown {
    width: calc(100vw - 20px);
    max-width: 340px;
    padding: 10px;
    border-radius: 14px;
  }

  .phone-country-search {
    min-height: 38px;
    font-size: 13px;
    margin-bottom: 8px;
  }

  .phone-country-list {
    max-height: min(260px, 46vh);
  }

  .phone-country-option {
    grid-template-columns: 32px minmax(0, 1fr) auto;
    gap: 7px;
    padding: 8px;
    font-size: 13px;
  }

  .phone-country-option img {
    width: 25px;
    height: 18px;
  }
}

@media (max-width: 360px) {
  .phone-country-group {
    grid-template-columns: minmax(90px, 104px) minmax(0, 1fr);
  }

  .phone-country-picker {
    grid-template-columns: 28px minmax(34px, 1fr) 14px;
  }

  .phone-country-code,
  .phone-country-number {
    font-size: 12px;
  }

  .phone-country-number {
    padding-inline: 7px;
  }

  .phone-country-dropdown {
    width: calc(100vw - 16px);
    max-width: 320px;
  }
}
