/* ============================================================================
   SKUBIQ — shared phone input / dialling-code combobox
   ----------------------------------------------------------------------------
   Pairs with static/js/sk-phone.js. Loaded on every page so the component is
   available wherever a phone field appears.

   THE WHITE-POPUP FIX
   The country-code field used to be a native <select>. Its option list is drawn
   by the operating system, not by us, so none of this could be reached: on the
   dark register pop-up the OS sheet came up as a white panel and stayed that
   way until the pointer happened to be over it. The component now keeps the
   <select> for form submission and paints its own listbox, which is why every
   colour below is set explicitly — nothing is inherited from the browser.

   Z-INDEX: the panel is position:fixed and painted into the top layer, above
   Bootstrap's .modal (z-index 1055) and its backdrop (1050). It has to clear
   both or it disappears behind the dialog it belongs to.
   ========================================================================= */

/* ── The native select, kept for form submission only ───────────────── */
.sk-combo-native {
  /* Visually gone but still submitted and still readable by a form post.
     `clip-path` rather than display:none — display:none on a form control does
     NOT stop it being submitted, but keeping it rendered-but-clipped means a
     screen reader that ignores aria-hidden still finds the right value. */
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.sk-combo {
  position: relative;
  flex: 0 0 auto;
}

/* ── Trigger button ─────────────────────────────────────────────────── */
.sk-combo-btn {
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  min-width: 0;
  padding: 10px 12px;
  font: inherit;
  font-size: .95rem;
  text-align: left;
  color: inherit;
  /* Explicit, so the trigger matches the field it sits in rather than
     inheriting whatever the surface behind it happens to be. */
  background: rgba(255, 255, 255, .06);
  border: 1px solid rgba(255, 255, 255, .18);
  border-radius: 6px;
  cursor: pointer;
  transition: border-color .15s ease, background-color .15s ease;
}
.sk-combo-btn:hover,
.sk-combo.is-open .sk-combo-btn {
  border-color: var(--sk-red, #EB0B1F);
  background: rgba(255, 255, 255, .10);
}
.sk-combo-btn:focus-visible {
  outline: 2px solid var(--sk-red, #EB0B1F);
  outline-offset: 2px;
}
.sk-combo-value {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sk-combo-caret {
  flex: 0 0 auto;
  font-size: .8rem;
  opacity: .7;
  transition: transform .15s ease;
}
.sk-combo.is-open .sk-combo-caret { transform: rotate(180deg); }

/* ── The panel ──────────────────────────────────────────────────────── */
.sk-combo-panel {
  position: fixed;
  z-index: 1090;                /* above .modal (1055) and .modal-backdrop (1050) */
  /* Explicit background + opaque. This is the fix: the popup is now ours to
     paint, so it can never come up as a blank white sheet. */
  background: #14100f;
  border: 1px solid rgba(255, 255, 255, .16);
  border-radius: 8px;
  box-shadow: 0 18px 44px rgba(0, 0, 0, .55);
  overflow: hidden;
}
.sk-combo-panel[hidden] { display: none; }

/* Light-surface variant, for the app pages where the field sits on white.
   Set by the parent form via .sk-auth-wrap / .card. */
.sk-auth-wrap .sk-combo-panel,
.bg-light .sk-combo-panel {
  background: #fff;
  border-color: #d9d9d9;
  box-shadow: 0 14px 34px rgba(0, 0, 0, .18);
}
.sk-auth-wrap .sk-combo-btn,
.bg-light .sk-combo-btn {
  background: #fff;
  border-color: #ccc;
  color: var(--sk-ink, #2A2424);
}
.sk-auth-wrap .sk-combo-opt,
.bg-light .sk-combo-opt { color: #1f1f24; }
.sk-auth-wrap .sk-combo-opt.is-active,
.bg-light .sk-combo-opt.is-active { background: #f1f3f5; color: #0A0A0A; }
.sk-auth-wrap .sk-combo-opt.is-selected,
.bg-light .sk-combo-opt.is-selected { color: var(--sk-red, #EB0B1F); }
.sk-auth-wrap .sk-combo-search,
.bg-light .sk-combo-search { color: #1f1f24; background: #fff; }
.sk-auth-wrap .sk-combo-search::placeholder,
.bg-light .sk-combo-search::placeholder { color: #6b6b6b; }
.sk-auth-wrap .sk-combo-searchwrap,
.bg-light .sk-combo-searchwrap { border-bottom-color: #e2e8f0; }

/* ── Search ─────────────────────────────────────────────────────────── */
.sk-combo-searchwrap {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-bottom: 1px solid rgba(255, 255, 255, .12);
}
.sk-combo-searchwrap .bi { opacity: .6; font-size: .85rem; }
.sk-combo-search {
  flex: 1 1 auto;
  min-width: 0;
  border: 0;
  background: transparent;
  color: #fff;
  font: inherit;
  font-size: .92rem;
  line-height: 1.35;
  padding: 2px 0;
}
.sk-combo-search:focus { outline: none; }

/* ── List ───────────────────────────────────────────────────────────── */
.sk-combo-list {
  margin: 0;
  padding: 4px;
  list-style: none;
  max-height: 260px;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.sk-combo-opt {
  padding: 7px 10px;
  border-radius: 5px;
  font-size: .92rem;
  /* Explicit: the panel can be mounted inside a modal body or a Bootstrap card
     with its own generous line-height, and inheriting it made every row ~50px
     tall — which pushed the list past its max-height and made the whole panel
     taller than the space available beside the button. */
  line-height: 1.35;
  color: rgba(255, 255, 255, .86);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sk-combo-opt.is-active {
  background: rgba(255, 255, 255, .12);
  color: #fff;
}
.sk-combo-opt.is-selected { color: var(--sk-red, #EB0B1F); }
.sk-combo-opt:hover { background: rgba(255, 255, 255, .12); }
.sk-combo-none {
  padding: 10px;
  font-size: .88rem;
  color: rgba(255, 255, 255, .5);
  text-align: center;
}

/* ── Phone row + inline error ───────────────────────────────────────── */
/* One connected control on every page that uses [data-sk-phone]: the
   .input-group on register, the .sk-phone row in the demo and product modal.
   A plain wrapper (profile, checkout) has no country box, so the join rules
   below never touch it. */

/* Field metrics. Light by default, matching .form-control in style.css.
   :where() keeps these at zero specificity so a surface can override them. */
:where([data-sk-phone]) {
  --sk-phone-border-color: #dedede;
  --sk-phone-radius: .6rem;
  --sk-phone-pad: .55rem .85rem;
  --sk-phone-size: 1rem;
  --sk-phone-text: var(--sk-ink, #2A2424);
  --sk-phone-autofill: #fff;
  --sk-phone-focus: #2A2424;
  --sk-phone-glow: rgba(42, 36, 36, .10);
  --sk-phone-error: #dc3545;
}

/* Row layout. nowrap keeps both boxes on one line down to 360px. */
.sk-phone[data-sk-phone],
.input-group[data-sk-phone] {
  display: flex;
  flex-wrap: nowrap;
  align-items: stretch;
  gap: 8px;
  width: 100%;
  position: relative;
}

/* Country box takes 20% of the row, the number box 80%; the 8px gap is split out of both. */
[data-sk-phone] > .sk-combo {
  flex: 0 0 calc(20% - 4px);
  width: calc(20% - 4px);
  min-width: 0;
}
[data-sk-phone] > .sk-combo > .sk-combo-btn {
  position: relative;
  height: 100%;
  padding: var(--sk-phone-pad);
  font-size: var(--sk-phone-size);
  line-height: 1.5;
  border: 1.5px solid var(--sk-phone-border-color);
  border-radius: var(--sk-phone-radius);
}
[data-sk-phone] > .sk-combo > .sk-combo-btn:hover,
[data-sk-phone] > .sk-combo.is-open > .sk-combo-btn {
  border-color: var(--sk-phone-focus);
}
[data-sk-phone] > .sk-combo > .sk-combo-btn:focus {
  border-color: var(--sk-phone-focus);
  box-shadow: 0 0 0 .2rem var(--sk-phone-glow);
  z-index: 2;
}
[data-sk-phone] > .sk-combo > .sk-combo-btn:focus-visible {
  outline-color: var(--sk-phone-focus);
}
[data-sk-phone]:has(> .is-invalid) > .sk-combo > .sk-combo-btn {
  border-color: var(--sk-phone-error);
}

/* Number box: fills the rest of the row, joined to the country box. */
[data-sk-phone] > .sk-combo + [data-sk-phone-input] {
  flex: 0 0 calc(80% - 4px);
  width: calc(80% - 4px);
  min-width: 0;
  margin-left: 0;
  border-color: var(--sk-phone-border-color);
  border-radius: var(--sk-phone-radius);
  font-size: var(--sk-phone-size);
}
[data-sk-phone] > .sk-combo + [data-sk-phone-input]:focus {
  position: relative;
  z-index: 2;
  border-color: var(--sk-phone-focus);
  box-shadow: 0 0 0 .2rem var(--sk-phone-glow);
}
[data-sk-phone] > .sk-combo + [data-sk-phone-input].is-invalid {
  border-color: var(--sk-phone-error);
}

/* The hidden native select must stay out of the row. Bootstrap's input-group
   rules otherwise make it a flex item and reserve an empty gap. */
[data-sk-phone] > .sk-combo-native {
  position: absolute;
  flex: 0 0 auto;
  width: 1px;
  max-width: none;
}

/* Browser autofill paints a blue-grey background. Replace it with the field's
   own background and keep the text in the site's ink colour. */
[data-sk-phone-input]:-webkit-autofill,
[data-sk-phone-input]:-webkit-autofill:hover,
[data-sk-phone-input]:-webkit-autofill:focus {
  -webkit-box-shadow: 0 0 0 1000px var(--sk-phone-autofill) inset;
  box-shadow: 0 0 0 1000px var(--sk-phone-autofill) inset;
  -webkit-text-fill-color: var(--sk-phone-text);
  caret-color: var(--sk-phone-text);
}

/* Dark surfaces: the demo modal and the product modal. */
.sk-demo-phone[data-sk-phone],
.sk-modal-body [data-sk-phone] {
  --sk-phone-border-color: rgba(255, 255, 255, .14);
  --sk-phone-text: #fff;
  --sk-phone-autofill: #1d1a19;
  --sk-phone-focus: rgba(255, 255, 255, .55);
  --sk-phone-error: var(--red, #EB0B1F);
  --sk-phone-glow: rgba(255, 255, 255, .12);
}
.sk-demo-phone[data-sk-phone] {
  --sk-phone-radius: 0;
  --sk-phone-pad: 6px 9px;
  --sk-phone-size: .84rem;
}

/* `position:relative` is what turns "position this above the panel's opener"
   into a local offset; the panel itself is position:fixed and therefore not
   affected. */
.sk-field, .sk-phone { position: relative; }

.sk-field-error {
  display: block;
  margin-top: 6px;
  color: #ff6b6b;
  font-size: .8rem;
  line-height: 1.4;
}
.sk-field-error[hidden] { display: none; }
.sk-auth-wrap .sk-field-error, .card .sk-field-error { color: #c0392b; }
