/**
 * FieldsPlus – phone number field
 * @author drek124 <https://github.com/drek124>
 * @license GPL-2.0-or-later
 *
 * Colours come from the template: Bootstrap variables when it has them (Cassiopeia, Atum…), otherwise
 * the field's own text colour, the accent the script reads from the template's focus style, and the
 * background behind the field (light or dark, whatever the site uses).
 */
:root {
  --fp-bg: var(--bs-body-bg, #fff);
  --fp-text: var(--bs-body-color, #212529);
  --fp-accent: var(--bs-primary, var(--fp-template-accent, #0d6efd));
  --fp-danger: var(--bs-danger, #dc3545);
  --fp-radius: var(--bs-border-radius, .375rem);
}

/* Derived from the text colour where they are used, so they suit light and dark templates alike. */
.fp-phone,
.fp-cc-panel {
  --fp-muted: color-mix(in srgb, currentColor 58%, transparent);
  --fp-border: color-mix(in srgb, currentColor 14%, transparent);
  --fp-border-strong: color-mix(in srgb, currentColor 26%, transparent);
  --fp-ring: color-mix(in srgb, var(--fp-accent) 22%, transparent);
  --fp-tint: color-mix(in srgb, var(--fp-accent) 9%, var(--fp-bg));
}

/* ---------- Country code + number ---------- */
.fp-phone { display: flex; align-items: stretch; gap: 8px; width: 100%; max-width: 100%; }
.fp-phone-cc { position: relative; flex: 0 0 auto; }
.fp-phone-num { position: relative; flex: 1 1 auto; min-width: 0; }
.fp-phone-num .fp-phone-input { width: 100%; max-width: 100%; }

.fp-phone .fp-phone-face {
  display: flex;
  align-items: center;
  gap: 7px;
  width: auto;
  height: 100%;
  min-height: calc(1.5em + .75rem + 2px);
  padding-block: 0;
  padding-inline: 12px 10px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  background-image: none;
  pointer-events: none;
}

.fp-phone-flag {
  font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", "Twemoji Mozilla", sans-serif;
  font-size: 19px;
  line-height: 1;
}

.fp-phone-flag.is-code,
.fp-cc-flag.is-code {
  color: var(--fp-muted);
  border: 1px solid var(--fp-border);
  font-family: inherit;
  font-weight: 700;
}

.fp-phone-flag.is-code { padding: 3px 5px; border-radius: 5px; font-size: 11px; letter-spacing: .04em; }

.fp-phone-dial { font-weight: 550; direction: ltr; unicode-bidi: isolate; }
.fp-phone-caret { flex: none; width: 14px; height: 14px; color: var(--fp-muted); transition: color .2s, transform .2s; }

/* Without JavaScript the real (native) select sits invisibly on top of the face. */
.fp-phone .fp-phone-select {
  position: absolute;
  inset: 0;
  z-index: 2;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  color: var(--fp-text);
  background: var(--fp-bg);
  border: 0;
  opacity: 0;
  font-size: 16px;
  cursor: pointer;
}

.fp-phone-cc:hover .fp-phone-face { border-color: var(--fp-border-strong); }

.fp-phone-cc:focus-within .fp-phone-face,
.fp-phone.is-picking .fp-phone-face {
  border-color: var(--fp-accent);
  outline: 0;
  box-shadow: 0 0 0 .25rem var(--fp-ring);
}

.fp-phone-cc:focus-within .fp-phone-caret,
.fp-phone.is-picking .fp-phone-caret { color: var(--fp-accent); }
.fp-phone.is-picking .fp-phone-caret { transform: rotate(180deg); }

/* With JavaScript: the face is a button opening the searchable list; the select is only submitted. */
.fp-phone .fp-phone-cc.is-enhanced .fp-phone-select { display: none; }
.fp-phone .fp-phone-cc.is-enhanced .fp-phone-face { pointer-events: auto; cursor: pointer; text-align: start; }

/* Invalid (Joomla's validator marks the number input) */
.fp-phone:has(.fp-phone-input.invalid) .fp-phone-face,
.fp-phone.is-invalid .fp-phone-face,
.fp-phone.is-invalid .fp-phone-input { border-color: var(--fp-danger); }

.fp-phone-error { margin-top: .3rem; color: var(--fp-danger); font-size: .875em; }

/* Disabled / read-only */
.fp-phone.is-disabled .fp-phone-face { pointer-events: none; opacity: .65; }
.fp-phone.is-disabled .fp-phone-select { pointer-events: none; }

/* Numbers are typed left-to-right, but stay aligned with right-to-left layouts. */
.fp-phone .fp-phone-input { direction: ltr; }
[dir="rtl"] .fp-phone .fp-phone-input { text-align: right; }
[dir="rtl"] .fp-phone .fp-phone-input:placeholder-shown { direction: rtl; }

/* Flag emoji on systems without them (Windows): Twemoji Country Flags, see fonts/TwemojiCountryFlags-LICENSE.md */
@font-face {
  font-family: "Twemoji Country Flags";
  src: url("../fonts/TwemojiCountryFlags.woff2") format("woff2");
  unicode-range: U+1F1E6-1F1FF, U+1F3F4, U+E0062-E0063, U+E0065, U+E0067, U+E006C, U+E006E, U+E0073-E0074, U+E0077, U+E007F;
  font-display: swap;
}

.fp-flagfont .fp-phone-flag,
.fp-flagfont .fp-cc-flag,
.fp-flagfont.fp-cc-panel .fp-cc-flag { font-family: "Twemoji Country Flags", "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif; }

/* ---------- Country list (attached to <body>) ---------- */
.fp-cc-panel {
  position: fixed;
  z-index: 1080;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  color: var(--fp-text);
  background: var(--fp-bg);
  border: 1px solid var(--fp-border-strong);
  border-radius: calc(var(--fp-radius) + 6px);
  box-shadow: 0 2px 6px rgba(15, 23, 42, .06), 0 24px 60px -16px rgba(15, 23, 42, .38);
  font-family: inherit;
  font-size: 1rem;
  text-align: start;
  animation: fpCcIn .16s cubic-bezier(.2, .8, .2, 1);
}

.fp-cc-panel.is-up { animation-name: fpCcUp; }
/* .is-dark is set by the script from the actual background, on any template. */
.fp-cc-panel { color-scheme: light; }
.fp-cc-panel.is-dark { color-scheme: dark; box-shadow: 0 0 0 1px rgba(255, 255, 255, .04), 0 24px 60px -12px rgba(0, 0, 0, .75); }

.fp-cc-search { display: flex; flex: none; align-items: center; gap: 9px; padding: 6px 14px; border-bottom: 1px solid var(--fp-border); }
.fp-cc-search svg { flex: none; width: 16px; height: 16px; color: var(--fp-muted); }

.fp-cc-panel .fp-cc-input {
  flex: 1;
  min-width: 0;
  height: 38px;
  margin: 0;
  padding: 0;
  color: var(--fp-text);
  background: transparent;
  border: 0;
  outline: 0;
  box-shadow: none;
  font: inherit;
  font-size: 16px;
}

.fp-cc-panel .fp-cc-input::placeholder { color: var(--fp-muted); opacity: .8; }

.fp-cc-panel .fp-cc-list {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  margin: 0;
  padding: 6px;
  overflow-y: auto;
  overscroll-behavior: contain;
  list-style: none;
  scrollbar-width: thin;
  scrollbar-color: var(--fp-border-strong) transparent;
}

.fp-cc-item {
  display: flex;
  align-items: center;
  gap: 11px;
  margin: 0;
  padding: 8px 10px;
  border-radius: var(--fp-radius);
  cursor: pointer;
  font-size: 14.5px;
  line-height: 1.3;
}

.fp-cc-item[hidden] { display: none; }
.fp-cc-item.is-active { background: var(--fp-tint); }
.fp-cc-item[aria-selected="true"] { color: var(--fp-accent); font-weight: 650; }

.fp-cc-flag {
  flex: none;
  width: 24px;
  font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", "Twemoji Mozilla", sans-serif;
  font-size: 19px;
  line-height: 1;
  text-align: center;
}

.fp-cc-flag.is-code { padding: 3px 0; border-radius: 4px; font-size: 10px; letter-spacing: .03em; }

.fp-cc-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fp-cc-dial { flex: none; color: var(--fp-muted); font-variant-numeric: tabular-nums; font-weight: 500; direction: ltr; unicode-bidi: isolate; }
.fp-cc-empty { padding: 22px 14px; color: var(--fp-muted); font-size: 14px; text-align: center; }

@keyframes fpCcIn { from { opacity: 0; transform: translateY(-6px) scale(.98); } }
@keyframes fpCcUp { from { opacity: 0; transform: translateY(6px) scale(.98); } }

@media (prefers-reduced-motion: reduce) {
  .fp-cc-panel { animation: none; }
  .fp-phone-caret { transition: none; }
}
