/* MWS Global Phone Country Selector
   Uses the existing MWS dialog visual language and works in Dark/Light + all accent themes. */

.mws-phone-control {
  position: relative;
  display: block;
  width: 100%;
  min-width: 0;
}

.mws-phone-control > .mws-phone-input {
  width: 100%;
  min-height: 48px;
  padding-inline-start: 118px !important;
}

.mws-phone-prefix {
  position: absolute;
  z-index: 3;
  top: 50%;
  left: 7px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 98px;
  max-width: 106px;
  min-height: 36px;
  padding: 6px 9px;
  border: 1px solid color-mix(in srgb, rgba(var(--mws-primary-rgb, var(--primary-rgb, 139,92,246)), .22) 42%, rgba(255,255,255,.12));
  border-radius: 12px;
  outline: 0;
  color: var(--mws-text, var(--text, #f8f7ff));
  background:
    linear-gradient(145deg, rgba(255,255,255,.12), rgba(255,255,255,.04)),
    rgba(19, 16, 32, .44);
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,.12),
    0 10px 28px rgba(0,0,0,.18);
  -webkit-backdrop-filter: blur(16px) saturate(140%);
  backdrop-filter: blur(16px) saturate(140%);
  font: inherit;
  line-height: 1;
  cursor: pointer;
  transform: translateY(-50%);
  transition: border-color .16s ease, background .16s ease, box-shadow .16s ease, transform .16s ease;
}

.mws-phone-prefix:hover,
.mws-phone-prefix:focus-visible {
  border-color: rgba(var(--mws-primary-rgb, var(--primary-rgb, 139,92,246)), .52);
  background:
    linear-gradient(145deg, rgba(255,255,255,.14), rgba(255,255,255,.06)),
    rgba(var(--mws-primary-rgb, var(--primary-rgb, 139,92,246)), .12);
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,.14),
    0 0 0 3px rgba(var(--mws-primary-rgb, var(--primary-rgb, 139,92,246)), .10),
    0 14px 36px rgba(0,0,0,.22);
}

.mws-phone-prefix:active { transform: translateY(-50%) scale(.985); }

.mws-phone-prefix-flag,
.mws-phone-country-flag {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  overflow: hidden;
  border-radius: 5px;
  background: rgba(255,255,255,.08);
  box-shadow: 0 0 0 1px rgba(255,255,255,.09);
}

.mws-phone-prefix-flag { width: 24px; height: 18px; }
.mws-phone-country-flag { width: 30px; height: 22px; border-radius: 6px; }

.mws-phone-prefix-flag img,
.mws-phone-country-flag img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.mws-phone-prefix-flag.is-emoji,
.mws-phone-country-flag.is-emoji {
  overflow: visible;
  background: transparent;
  box-shadow: none;
  font-size: 1.15rem;
}

.mws-phone-prefix-code {
  min-width: 0;
  color: inherit;
  font-size: .72rem;
  font-weight: 850;
  letter-spacing: -.01em;
  white-space: nowrap;
}

.mws-phone-prefix-chevron {
  width: 7px;
  height: 7px;
  margin-left: auto;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  opacity: .64;
  transform: translateY(-2px) rotate(45deg);
}

.mws-phone-dialog {
  width: clamp(320px, 92vw, 640px);
  max-height: min(760px, calc(100dvh - 32px));
  overflow: hidden;
  border: 1px solid rgba(var(--mws-primary-rgb, var(--primary-rgb, 139,92,246)), .22);
  background:
    radial-gradient(circle at 100% 0%, rgba(var(--mws-primary-rgb, var(--primary-rgb, 139,92,246)), .13), transparent 34%),
    linear-gradient(155deg, rgba(255,255,255,.11), rgba(255,255,255,.04) 34%, transparent 70%),
    rgba(17, 13, 30, .68);
  box-shadow:
    0 36px 96px rgba(0, 0, 0, .44),
    inset 0 1px 0 rgba(255,255,255,.12);
  -webkit-backdrop-filter: blur(24px) saturate(150%);
  backdrop-filter: blur(24px) saturate(150%);
}

.mws-phone-dialog-icon svg {
  width: 24px;
  height: 24px;
}

.mws-phone-search-wrap {
  position: relative;
  grid-column: 1 / -1;
  margin-top: 4px;
}

.mws-phone-search-wrap .mws-phone-search {
  min-height: 48px;
  padding-inline: 42px 12px;
  border-radius: 14px;
  background:
    linear-gradient(155deg, rgba(255,255,255,.10), rgba(255,255,255,.04)),
    rgba(255,255,255,.035);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.08);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
}

.mws-phone-search-icon {
  position: absolute;
  z-index: 2;
  top: 50%;
  left: 13px;
  display: grid;
  width: 18px;
  height: 18px;
  place-items: center;
  color: var(--mws-notify-muted, var(--mws-text-muted, var(--muted, rgba(248,247,255,.62))));
  transform: translateY(-50%);
  pointer-events: none;
}

.mws-phone-search-icon svg {
  width: 17px;
  height: 17px;
  stroke: currentColor;
  stroke-width: 1.8;
}

.mws-phone-country-list {
  grid-column: 1 / -1;
  display: grid;
  gap: 7px;
  max-height: min(430px, 52dvh);
  margin-top: 2px;
  padding: 8px;
  overflow: auto;
  overscroll-behavior: contain;
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 16px;
  background:
    linear-gradient(155deg, rgba(255,255,255,.08), rgba(255,255,255,.03)),
    rgba(255,255,255,.03);
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,.06),
    0 8px 24px rgba(0,0,0,.12);
  -webkit-backdrop-filter: blur(18px) saturate(130%);
  backdrop-filter: blur(18px) saturate(130%);
  scrollbar-width: thin;
  scrollbar-color: rgba(var(--mws-primary-rgb, var(--primary-rgb, 139,92,246)), .42) transparent;
}

.mws-phone-country-option {
  position: relative;
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 11px;
  width: 100%;
  min-height: 54px;
  padding: 9px 11px;
  border: 1px solid rgba(255,255,255,.05);
  border-radius: 14px;
  outline: 0;
  color: var(--mws-notify-text, var(--mws-text, var(--text, #f8f7ff)));
  background:
    linear-gradient(145deg, rgba(255,255,255,.09), rgba(255,255,255,.03)),
    rgba(255,255,255,.018);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.05);
  font: inherit;
  text-align: left;
  cursor: pointer;
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  transition: background .14s ease, border-color .14s ease, transform .14s ease, box-shadow .14s ease;
}

.mws-phone-country-option:hover,
.mws-phone-country-option:focus-visible {
  border-color: rgba(var(--mws-primary-rgb, var(--primary-rgb, 139,92,246)), .24);
  background:
    linear-gradient(145deg, rgba(255,255,255,.11), rgba(255,255,255,.04)),
    rgba(var(--mws-primary-rgb, var(--primary-rgb, 139,92,246)), .10);
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,.08),
    0 10px 22px rgba(0,0,0,.12);
}

.mws-phone-country-option:active { transform: scale(.994); }

.mws-phone-country-option.is-selected {
  border-color: rgba(var(--mws-primary-rgb, var(--primary-rgb, 139,92,246)), .36);
  background:
    linear-gradient(145deg, rgba(255,255,255,.12), rgba(255,255,255,.05)),
    rgba(var(--mws-primary-rgb, var(--primary-rgb, 139,92,246)), .15);
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,.10),
    0 12px 28px rgba(var(--mws-primary-rgb, var(--primary-rgb, 139,92,246)), .10);
}

.mws-phone-country-copy {
  display: grid;
  min-width: 0;
  gap: 2px;
}

.mws-phone-country-copy strong {
  overflow: hidden;
  color: inherit;
  font-size: .80rem;
  font-weight: 800;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mws-phone-country-copy small {
  color: var(--mws-notify-muted, var(--mws-text-muted, var(--muted, rgba(248,247,255,.60))));
  font-size: .62rem;
  font-weight: 800;
  letter-spacing: .08em;
}

.mws-phone-country-dial {
  color: var(--mws-notify-muted, var(--mws-text-muted, var(--muted, rgba(248,247,255,.68))));
  font-size: .76rem;
  font-weight: 850;
  white-space: nowrap;
}

.mws-phone-country-check {
  display: grid;
  width: 25px;
  height: 25px;
  place-items: center;
  border-radius: 8px;
  color: #fff;
  background: rgb(var(--mws-primary-rgb, var(--primary-rgb, 139,92,246)));
  font-size: .72rem;
  font-weight: 950;
  box-shadow: 0 7px 20px rgba(var(--mws-primary-rgb, var(--primary-rgb, 139,92,246)), .20);
}

.mws-phone-empty {
  grid-column: 1 / -1;
  padding: 24px 12px 12px;
  color: var(--mws-notify-muted, var(--mws-text-muted, var(--muted, rgba(248,247,255,.62))));
  font-size: .76rem;
  text-align: center;
}

html[data-theme="light"] .mws-phone-prefix {
  background:
    linear-gradient(145deg, rgba(255,255,255,.92), rgba(255,255,255,.66)),
    rgba(255,255,255,.72);
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,.92),
    0 10px 30px rgba(61, 39, 107, .10);
}

html[data-theme="light"] .mws-phone-dialog {
  background:
    radial-gradient(circle at 100% 0%, rgba(var(--mws-primary-rgb, var(--primary-rgb, 139,92,246)), .10), transparent 36%),
    linear-gradient(155deg, rgba(255,255,255,.92), rgba(255,255,255,.78) 36%, rgba(255,255,255,.72) 100%),
    rgba(255,255,255,.76);
  box-shadow:
    0 34px 84px rgba(49, 27, 78, .18),
    inset 0 1px 0 rgba(255,255,255,.92);
}

html[data-theme="light"] .mws-phone-country-list,
html[data-theme="light"] .mws-phone-search-wrap .mws-phone-search,
html[data-theme="light"] .mws-phone-country-option {
  box-shadow: inset 0 1px 0 rgba(255,255,255,.88);
}

@media (max-width: 920px) {
  .mws-phone-dialog {
    width: min(92vw, 580px);
    max-height: min(80dvh, calc(100dvh - 28px));
  }

  .mws-phone-country-list {
    max-height: min(48dvh, 420px);
  }
}

@media (max-width: 560px) {
  .mws-phone-control > .mws-phone-input {
    min-height: 46px;
    padding-inline-start: 102px !important;
  }

  .mws-phone-prefix {
    left: 6px;
    min-width: 86px;
    max-width: 92px;
    min-height: 34px;
    padding-inline: 7px;
    border-radius: 11px;
  }

  .mws-phone-prefix-flag { width: 22px; height: 16px; }

  .mws-phone-dialog {
    width: 100%;
    max-height: calc(100dvh - 12px);
    border-radius: 20px;
  }

  .mws-phone-search-wrap .mws-phone-search {
    min-height: 46px;
    border-radius: 13px;
  }

  .mws-phone-country-list {
    gap: 6px;
    max-height: min(54dvh, 480px);
    padding: 7px;
    border-radius: 15px;
  }

  .mws-phone-country-option {
    grid-template-columns: 28px minmax(0, 1fr) auto;
    min-height: 50px;
    gap: 10px;
    padding: 8px 10px;
  }

  .mws-phone-country-check {
    display: none;
  }

  .mws-phone-country-copy strong {
    font-size: .77rem;
  }

  .mws-phone-country-dial {
    font-size: .72rem;
  }
}

@media (max-width: 380px) {
  .mws-phone-control > .mws-phone-input { padding-inline-start: 98px !important; }
  .mws-phone-prefix {
    min-width: 82px;
    max-width: 88px;
    gap: 6px;
  }
  .mws-phone-prefix-code {
    font-size: .68rem;
  }
  .mws-phone-country-option {
    grid-template-columns: 26px minmax(0, 1fr) auto;
    gap: 8px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .mws-phone-prefix,
  .mws-phone-country-option { transition: none !important; }
}
