/* ═══════════════════════════════════════════
   Phone Country Input — searchable dial codes
   Variants: website | dashboard | profile
═══════════════════════════════════════════ */

[x-cloak] {
  display: none !important;
}

.pci {
  position: relative;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  z-index: 1;
}

.pci:has(.pci__row--open) {
  z-index: 30;
}

.pci__row {
  display: flex;
  align-items: stretch;
  gap: 0;
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--color-border, rgba(255, 255, 255, 0.12));
  border-radius: 10px;
  background: var(--color-bg-input, rgba(30, 30, 30, 0.85));
  overflow: hidden;
  transition:
    border-color 0.18s ease,
    box-shadow 0.18s ease;
}

.pci__row:hover {
  border-color: var(--color-border, rgba(255, 255, 255, 0.22));
}

.pci__row--open,
.pci__row:focus-within {
  border-color: var(--color-primary, #d4921a);
  box-shadow: 0 0 0 1px rgba(212, 146, 26, 0.35);
}

.pci__row--disabled {
  opacity: 0.65;
  pointer-events: none;
}

.pci__trigger {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  min-width: 108px;
  padding: 0 12px;
  border: 0;
  border-inline-end: 1px solid var(--color-border-faint, rgba(255, 255, 255, 0.08));
  background: transparent;
  color: var(--color-text-primary, #fff);
  cursor: pointer;
  font: inherit;
  transition: background 0.15s ease;
}

.pci__trigger:hover {
  background: rgba(255, 255, 255, 0.04);
}

.pci__trigger:focus-visible {
  outline: none;
  background: rgba(212, 146, 26, 0.1);
}

.pci__flag {
  font-size: 18px;
  line-height: 1;
}

.pci__dial {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.01em;
  font-variant-numeric: tabular-nums;
}

.pci__chevron {
  display: inline-flex;
  margin-inline-start: auto;
  color: var(--color-text-muted, rgba(255, 255, 255, 0.55));
  transition: transform 0.18s ease;
}

.pci__chevron svg {
  width: 14px;
  height: 14px;
}

.pci__row--open .pci__chevron {
  transform: rotate(180deg);
  color: var(--color-primary, #d4921a);
}

.pci__national {
  flex: 1;
  min-width: 0;
  height: 48px;
  padding: 0 14px;
  border: 0;
  background: transparent;
  color: var(--color-text-primary, #fff);
  font: inherit;
  font-size: 14px;
  outline: none;
}

.pci__national::placeholder {
  color: var(--color-text-muted, rgba(255, 255, 255, 0.4));
}

.pci__dropdown {
  position: absolute;
  z-index: 10070;
  top: calc(100% + 8px);
  inset-inline-start: 0;
  width: min(100%, 360px);
  max-width: calc(100vw - 24px);
  border: 1px solid var(--color-border, rgba(255, 255, 255, 0.12));
  border-radius: 14px;
  /* Opaque panel — never use translucent --color-surface-panel tokens here */
  background: var(--color-bg-elevated, #1a1a1a);
  box-shadow:
    0 18px 48px rgba(0, 0, 0, 0.45),
    0 0 0 1px rgba(212, 146, 26, 0.08);
  overflow: hidden;
  transform-origin: top center;
}

.pci__search {
  position: relative;
  padding: 12px;
  border-bottom: 1px solid var(--color-border-faint, rgba(255, 255, 255, 0.08));
  background: linear-gradient(
    180deg,
    color-mix(in srgb, var(--color-primary, #d4921a) 10%, var(--color-bg-elevated, #1a1a1a)),
    var(--color-bg-elevated, #1a1a1a) 90%
  );
}

.pci__search-icon {
  position: absolute;
  inset-inline-start: 22px;
  top: 50%;
  width: 16px;
  height: 16px;
  transform: translateY(-50%);
  color: var(--color-text-muted, rgba(255, 255, 255, 0.45));
  pointer-events: none;
}

.pci__search-input {
  width: 100%;
  height: 40px;
  padding-inline: 38px 12px;
  border: 1px solid var(--color-border, rgba(255, 255, 255, 0.12));
  border-radius: 10px;
  background: var(--color-bg-input, #121212);
  color: var(--color-text-primary, #fff);
  font: inherit;
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.pci__search-input:focus {
  border-color: var(--color-primary, #d4921a);
  box-shadow: 0 0 0 1px rgba(212, 146, 26, 0.28);
}

.pci__list {
  max-height: 280px;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 6px;
  scrollbar-width: thin;
  scrollbar-color: rgba(212, 146, 26, 0.45) transparent;
}

.pci__section-label {
  padding: 8px 10px 4px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--color-primary, #d4921a);
}

.pci__section-label--gap {
  margin-top: 6px;
  padding-top: 10px;
  border-top: 1px solid var(--color-border-faint, rgba(255, 255, 255, 0.08));
}

.pci__option {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--color-text-primary, #fff);
  font: inherit;
  font-size: 13px;
  text-align: start;
  cursor: pointer;
  transition: background 0.12s ease, transform 0.12s ease;
}

.pci__option:hover,
.pci__option--active {
  background: rgba(212, 146, 26, 0.12);
}

.pci__option--selected {
  background: rgba(212, 146, 26, 0.18);
}

.pci__option--selected .pci__option-dial {
  color: var(--color-primary, #d4921a);
  font-weight: 700;
}

.pci__option-flag {
  font-size: 18px;
  line-height: 1;
  flex-shrink: 0;
}

.pci__option-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pci__option-dial {
  flex-shrink: 0;
  color: var(--color-text-secondary, rgba(255, 255, 255, 0.55));
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.pci__empty {
  padding: 28px 16px;
  text-align: center;
  color: var(--color-text-muted, rgba(255, 255, 255, 0.45));
  font-size: 13px;
}

/* Motion */
.pci-enter {
  transition: opacity 0.16s ease, transform 0.18s cubic-bezier(0.2, 0.9, 0.3, 1);
}
.pci-enter-start {
  opacity: 0;
  transform: translateY(-6px) scale(0.98);
}
.pci-enter-end {
  opacity: 1;
  transform: translateY(0) scale(1);
}
.pci-leave {
  transition: opacity 0.12s ease, transform 0.12s ease;
}
.pci-leave-start {
  opacity: 1;
  transform: translateY(0) scale(1);
}
.pci-leave-end {
  opacity: 0;
  transform: translateY(-4px) scale(0.98);
}

/* ── Dashboard (Metronic) variant ── */
.pci--dashboard .pci__row {
  min-height: 44px;
  border-radius: 0.475rem;
  background: var(--kt-input-bg, #f9f9f9);
  border-color: var(--kt-input-border-color, #e4e6ef);
  box-shadow: none;
}

.pci--dashboard .pci__row:hover,
.pci--dashboard .pci__row--open,
.pci--dashboard .pci__row:focus-within {
  border-color: var(--kt-primary, #009ef7);
  box-shadow: none;
}

.pci--dashboard .pci__trigger {
  color: var(--kt-gray-800, #252f4a);
  border-inline-end-color: var(--kt-gray-200, #eff2f5);
}

.pci--dashboard .pci__national {
  height: 44px;
  color: var(--kt-gray-800, #252f4a);
}

.pci--dashboard .pci__national::placeholder {
  color: var(--kt-gray-500, #a1a5b7);
}

.pci--dashboard .pci__dropdown {
  border-radius: 0.625rem;
  background: #fff;
  border-color: var(--kt-gray-200, #eff2f5);
  box-shadow: 0 10px 30px rgba(24, 28, 50, 0.18);
}

.pci--dashboard .pci__search {
  background: #f9f9f9;
}

.pci--dashboard .pci__search-input {
  background: #fff;
  color: var(--kt-gray-800, #252f4a);
  border-color: var(--kt-gray-300, #e1e3ea);
}

.pci--dashboard .pci__section-label {
  color: var(--kt-primary, #009ef7);
}

.pci--dashboard .pci__option {
  color: var(--kt-gray-800, #252f4a);
}

.pci--dashboard .pci__option:hover,
.pci--dashboard .pci__option--active,
.pci--dashboard .pci__option--selected {
  background: rgba(0, 158, 247, 0.08);
}

.pci--dashboard .pci__option-dial {
  color: var(--kt-gray-500, #a1a5b7);
}

.pci--dashboard .pci__option--selected .pci__option-dial {
  color: var(--kt-primary, #009ef7);
}

.pci--dashboard .pci__empty {
  color: var(--kt-gray-500, #a1a5b7);
}

/* ── Profile / user-dashboard variant ── */
.pci--profile .pci__row {
  background: var(--card, #1c1c1c);
  border-color: transparent;
}

.pci--profile .pci__row:hover,
.pci--profile .pci__row--open,
.pci--profile .pci__row:focus-within {
  border-color: var(--border, rgba(255, 255, 255, 0.15));
}

/* Light theme */
[data-theme="light"] .pci:not(.pci--dashboard) .pci__row {
  background: var(--color-bg-input, #fff);
  border-color: var(--color-border, #e5e5e5);
}

[data-theme="light"] .pci:not(.pci--dashboard) .pci__trigger,
[data-theme="light"] .pci:not(.pci--dashboard) .pci__national,
[data-theme="light"] .pci:not(.pci--dashboard) .pci__option {
  color: var(--color-text-primary, #1a1a1a);
}

[data-theme="light"] .pci:not(.pci--dashboard) .pci__dropdown {
  background: #fff;
  border-color: #e8e8e8;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.12);
}

[data-theme="light"] .pci:not(.pci--dashboard) .pci__search {
  background: linear-gradient(180deg, rgba(212, 146, 26, 0.08), #fff 90%);
}

[data-theme="light"] .pci:not(.pci--dashboard) .pci__search-input {
  background: #fff;
  color: #1a1a1a;
  border-color: #e5e5e5;
}

[data-theme="light"] .pci:not(.pci--dashboard) .pci__option-dial {
  color: #777;
}

@media (prefers-reduced-motion: reduce) {
  .pci-enter,
  .pci-leave,
  .pci__chevron,
  .pci__option {
    transition: none !important;
  }
}

/* Sheet chrome — hidden on desktop anchored dropdown */
.pci__backdrop,
.pci__sheet-grab,
.pci__sheet-header {
  display: none;
}

html.pci-sheet-open body {
  overflow: hidden;
}

/* Sticky checkout CTAs create a higher stacking context than the in-form
   picker; hide them while the country sheet is open so options stay tappable. */
html.pci-sheet-open .checkout-step-actions--sticky,
html.pci-sheet-open .checkout-step-actions--sticky-self {
  visibility: hidden;
  pointer-events: none;
}

@media (max-width: 640px) {
  /* Escape ancestor stacking contexts (checkout-field z-index:1) so the
     fixed sheet paints above sticky Place order (z-index:120). */
  .pci:has(.pci__row--open),
  .checkout-field:has(.pci__row--open) {
    z-index: 10080;
  }

  .pci__backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 10065;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
  }

  .pci__dropdown {
    position: fixed;
    z-index: 10070;
    top: auto;
    bottom: 0;
    inset-inline: 0;
    width: 100%;
    max-width: none;
    max-height: min(78dvh, 640px);
    border-radius: 20px 20px 0 0;
    border-bottom: 0;
    background: var(--color-bg-elevated, #1a1a1a);
    /* Important: Alpine x-show toggles display; keep flex when shown via media query after Alpine clears inline none */
    display: flex;
    flex-direction: column;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.4);
    transform-origin: bottom center;
  }

  /* When Alpine has not yet hydrated / x-cloak removed inconsistently, never leave a 0-size sheet */
  .pci__dropdown[style*="display: none"],
  .pci__dropdown[x-cloak] {
    display: none !important;
  }

  .pci__sheet-grab {
    display: block;
    width: 40px;
    height: 4px;
    margin: 10px auto 4px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.22);
    flex-shrink: 0;
  }

  .pci__sheet-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 4px 16px 10px;
    border-bottom: 1px solid var(--color-border-faint, rgba(255, 255, 255, 0.08));
    background: var(--color-bg-elevated, #1a1a1a);
    flex-shrink: 0;
  }

  .pci__search {
    flex-shrink: 0;
    background: var(--color-bg-elevated, #1a1a1a);
  }

  .pci__list {
    flex: 1;
    max-height: none;
    min-height: 0;
    background: var(--color-bg-elevated, #1a1a1a);
  }

  .pci__sheet-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--color-text-primary, #fff);
  }

  .pci__sheet-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: var(--color-text-muted, rgba(255, 255, 255, 0.65));
    cursor: pointer;
  }

  .pci__sheet-close svg {
    width: 18px;
    height: 18px;
  }

  .pci__trigger {
    min-width: 104px;
    min-height: 48px;
  }

  .pci__national {
    min-height: 48px;
    font-size: 16px; /* prevent iOS zoom on focus */
  }

  [data-theme="light"] .pci__sheet-grab {
    background: rgba(0, 0, 0, 0.18);
  }

  [data-theme="light"] .pci__dropdown,
  [data-theme="light"] .pci__sheet-header,
  [data-theme="light"] .pci__search,
  [data-theme="light"] .pci__list {
    background: #fff;
  }

  [data-theme="light"] .pci__sheet-title {
    color: #1a1a1a;
  }

  [data-theme="light"] .pci__sheet-close {
    color: #666;
  }

  .pci--dashboard .pci__sheet-title {
    color: var(--kt-gray-800, #252f4a);
  }
}

@media (max-width: 480px) {
  .pci__trigger {
    min-width: 96px;
    padding: 0 10px;
  }
}
