/* Shared phone field: flag+dial picker + national number as one input group. */
.phone-input {
  --phone-focus: #6366f1;
  /* Prefer portal / Bootstrap input tokens so tenant + marketing match neighbours. */
  --phone-border: var(--border, var(--bs-border-color, rgba(14, 16, 34, 0.12)));
  --phone-bg: var(--surface, var(--bs-body-bg, #fff));
  --phone-text: var(--text-main, var(--bs-body-color, #0e1022));
  --phone-muted: var(--text-muted, var(--bs-secondary-color, #5b6172));
  --phone-control-height: calc(1.5em + 0.75rem + 2px);
  --phone-radius: 0.375rem;
  position: relative;
  min-width: 0;
  width: 100%;
}
.mk-field .phone-input,
.shop-signup .phone-input {
  --phone-border: rgba(14, 16, 34, 0.08);
  --phone-bg: #fff;
  --phone-text: #0e1022;
  --phone-muted: #5b6172;
  --phone-control-height: 40px;
  /* Match neighbouring .mk-field inputs (8px). */
  --phone-radius: 8px;
}
/* Tenant dark mode sets html[data-theme="dark"] and --surface/--border — not
   Bootstrap --bs-body-bg (which stays white). Prefer portal tokens. */
html[data-theme="dark"] .phone-input,
[data-bs-theme="dark"] .phone-input {
  --phone-bg: var(--surface, #1e293b);
  --phone-border: var(--border, #334155);
  --phone-text: var(--text-main, #f1f5f9);
  --phone-muted: var(--text-muted, #94a3b8);
}
.form-control-sm ~ .phone-input,
.phone-input:has(.form-control-sm),
.phone-input .form-control-sm.phone-national {
  --phone-control-height: calc(1.5em + 0.5rem + 2px);
}
.phone-row {
  display: flex;
  align-items: stretch;
  min-width: 0;
  width: 100%;
  height: var(--phone-control-height);
  min-height: var(--phone-control-height);
  border: 1px solid var(--phone-border);
  border-radius: var(--phone-radius);
  background: var(--phone-bg);
  /* Keep the row unclipped so children paint; the country list uses fixed positioning. */
}
.phone-row:focus-within {
  border-color: var(--phone-focus);
  box-shadow: 0 0 0 0.25rem rgba(99, 102, 241, 0.25);
}
.phone-country-wrap {
  position: relative;
  flex: 0 0 110px;
  max-width: 110px;
  min-width: 96px;
  border-inline-end: 1px solid var(--phone-border);
  border-start-start-radius: inherit;
  border-end-start-radius: inherit;
}
.phone-country-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  width: 100%;
  height: 100%;
  min-height: 0;
  margin: 0;
  padding: 0.25rem 0.35rem;
  border: 0;
  border-start-start-radius: inherit;
  border-end-start-radius: inherit;
  background: transparent;
  color: var(--phone-text);
  font-size: inherit;
  line-height: 1.2;
  cursor: pointer;
  white-space: nowrap;
}
.phone-country-btn:focus-visible {
  outline: 2px solid var(--phone-focus);
  outline-offset: -2px;
}
.phone-country-btn-flag {
  font-size: 1.05rem;
  line-height: 1;
}
.phone-country-btn-dial {
  font-variant-numeric: tabular-nums;
  direction: ltr;
  unicode-bidi: isolate;
}
.phone-country-btn-caret {
  font-size: 0.65rem;
  opacity: 0.7;
  margin-inline-start: 0.1rem;
}
/* Open list is position:fixed and may mount under <body>, so theme tokens must
   live on the panel itself (not only on .phone-input). JS also copies computed
   tokens from the closed row when opening. */
.phone-country-panel {
  --phone-focus: #6366f1;
  --phone-border: var(--border, var(--bs-border-color, rgba(14, 16, 34, 0.12)));
  --phone-bg: var(--surface, var(--bs-body-bg, #fff));
  --phone-text: var(--text-main, var(--bs-body-color, #0e1022));
  --phone-muted: var(--text-muted, var(--bs-secondary-color, #5b6172));
  position: fixed;
  z-index: 2000;
  width: min(20rem, 85vw);
  max-height: min(16rem, 70vh);
  /* Grid keeps search and options in separate rows so the search never
     covers option 0 (sticky-inside-scroll failed on the home lead form). */
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  border: 1px solid var(--phone-border);
  border-radius: 0.5rem;
  background: var(--phone-bg);
  color: var(--phone-text);
  box-shadow: 0 10px 28px rgba(14, 16, 34, 0.18);
  overflow: hidden;
}
html[data-theme="dark"] .phone-country-panel,
[data-bs-theme="dark"] .phone-country-panel {
  --phone-bg: var(--surface, #1e293b);
  --phone-border: var(--border, #334155);
  --phone-text: var(--text-main, #f1f5f9);
  --phone-muted: var(--text-muted, #94a3b8);
}
.phone-country-panel[hidden] {
  display: none !important;
}
.phone-country-search {
  position: relative;
  z-index: 1;
  grid-row: 1;
  width: 100%;
  min-height: 2.5rem;
  margin: 0;
  border: 0;
  border-block-end: 1px solid var(--phone-border);
  border-radius: 0;
  padding: 0.55rem 0.7rem;
  font-size: inherit;
  /* Opaque — never inherit a transparent body background. */
  background: var(--phone-bg, #fff);
  color: var(--phone-text, #0e1022);
  box-sizing: border-box;
}
html[data-theme="dark"] .phone-country-search,
[data-bs-theme="dark"] .phone-country-search {
  background: var(--phone-bg, #1e293b);
  color: var(--phone-text, #f1f5f9);
}
.phone-country-search:focus {
  outline: 2px solid var(--phone-focus);
  outline-offset: -2px;
}
.phone-country-list {
  list-style: none;
  margin: 0;
  padding: 0.25rem 0;
  overflow-x: hidden;
  overflow-y: auto;
  max-height: 12.5rem;
  grid-row: 2;
  min-height: 0;
  -webkit-overflow-scrolling: touch;
}
.phone-country-option {
  display: flex;
  align-items: flex-start;
  gap: 0.45rem;
  width: 100%;
  min-height: 2.25rem;
  margin: 0;
  padding: 0.45rem 0.7rem;
  border: 0;
  background: transparent;
  color: var(--phone-text);
  text-align: start;
  font-size: inherit;
  line-height: 1.25;
  cursor: pointer;
}
.phone-country-option:hover,
.phone-country-option:focus,
.phone-country-option.is-active,
.phone-country-option[aria-selected="true"] {
  background: rgba(99, 102, 241, 0.1);
  outline: none;
}
html[data-theme="dark"] .phone-country-option:hover,
html[data-theme="dark"] .phone-country-option:focus,
html[data-theme="dark"] .phone-country-option.is-active,
html[data-theme="dark"] .phone-country-option[aria-selected="true"],
[data-bs-theme="dark"] .phone-country-option:hover,
[data-bs-theme="dark"] .phone-country-option:focus,
[data-bs-theme="dark"] .phone-country-option.is-active,
[data-bs-theme="dark"] .phone-country-option[aria-selected="true"] {
  background: rgba(99, 102, 241, 0.22);
}
.phone-country-option-dial {
  flex: 0 0 auto;
  min-width: 2.6rem;
  direction: ltr;
  unicode-bidi: isolate;
  color: var(--phone-muted);
  font-variant-numeric: tabular-nums;
  padding-block-start: 0.05rem;
}
.phone-country-option-name {
  flex: 1 1 auto;
  min-width: 0;
  white-space: normal;
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
}
.phone-national {
  flex: 1 1 auto !important;
  width: 0 !important;
  min-width: 0 !important;
  height: 100% !important;
  min-height: 0 !important;
  margin: 0 !important;
  border: 0 !important;
  border-radius: 0 !important;
  border-start-end-radius: inherit !important;
  border-end-end-radius: inherit !important;
  box-shadow: none !important;
  background: transparent !important;
  direction: ltr !important;
  text-align: left !important;
  font-size: inherit !important;
  line-height: inherit !important;
  padding: 0.375rem 0.75rem !important;
  color: var(--phone-text) !important;
}
.phone-national:focus {
  outline: none !important;
  box-shadow: none !important;
}
.phone-error {
  color: #b42318;
  font-size: 0.82rem;
  margin-block-start: 0.3rem;
}
.phone-warning {
  color: #946200;
  font-size: 0.82rem;
}
.phone-row:has(.phone-national[aria-invalid="true"]) {
  border-color: #b42318;
}
@media (max-width: 576px) {
  .phone-country-search,
  .phone-national,
  .phone-country-btn {
    font-size: 16px !important;
  }
  .phone-country-option {
    min-height: 44px;
    padding-block: 0.65rem;
  }
}
@media (pointer: coarse) {
  .phone-country-option {
    min-height: 44px;
    padding-block: 0.65rem;
  }
}
@media (max-width: 360px) {
  .phone-country-wrap {
    flex-basis: 100px;
    max-width: 100px;
    min-width: 92px;
  }
  .phone-country-btn {
    padding-inline: 0.25rem;
  }
}
