/*
 * PROJECT: Wolf IPTV
 * FILE: wolf_iptv/assets/css/wolf-phone.css
 *
 * ═══════════════════════════════════════════════════════════════════════════
 *  Wolf Phone Input styles (intl-tel-input v28 customizations) — M5.3
 * ═══════════════════════════════════════════════════════════════════════════
 *
 *  استُخرج من wolf-foundation.css (كان اسمه الأصلي iti-overrides.css) واتنقل
 *  لملف مستقل عشان نقدر نحمّله DEFERRED (غير render-blocking) مع الـ vendor CSS.
 *
 *  ترتيب التحميل الحرج (محفوظ في head.php):
 *     1. intlTelInput.min.css   (vendor base)
 *     2. wolf-phone.css         (تعديلاتنا — لازم تيجي بعد الـ vendor في ترتيب
 *                                الوثيقة عشان الـ 19 قاعدة .iti__ العارية تكسب)
 *
 *  آمن للتأجيل: حقل التليفون موجود في مودال مخفي (.is-active يظهر عند الفتح)،
 *  فمفيش FOUC وقت التحميل الأولي.
 *
 *  @since 2026-07-10 — M5.3 (Performance · non-blocking CSS)
 */

/*
 * PROJECT: Wolf IPTV
 * FILE: wolf_iptv/assets/css/core/iti-overrides.css
 *
 * ═══════════════════════════════════════════════════════════════════════════
 *  Wolf Core — intl-tel-input v28 customizations
 *  VERSION: 3.0.0 (2026-06-10 Hotfix 002 — defensive flex layout)
 * ═══════════════════════════════════════════════════════════════════════════
 *
 *  Hotfix 002 fixes (over Hotfix 001):
 *  ─────────────────────────────────────────────────────────────────────
 *  [BUG 1] Flag sprite broken — was setting `.iti__flag { width: 22px }`
 *          but the sprite uses `background-position: calc(offset * 20px)`.
 *          Overriding width broke the sprite math → "tiny flag" look.
 *          FIX: don't override flag width/height. Let vendor's 20px work.
 *
 *  [BUG 2] "Black box" around flag — caused by box-shadow on the flag
 *          combined with brand-faint background.
 *          FIX: removed box-shadow on flag.
 *
 *  [BUG 3] Country pill separated from input — `.iti__country-container`
 *          has `position: absolute; left: 0` from vendor. My non-!important
 *          override didn't always win.
 *          FIX: `position: static !important` + explicit `order: 1/2`.
 *
 *  [BUG 4] Dropdown clipped — `.input-wrap { overflow: hidden }` from base
 *          cuts off the dropdown that pops below.
 *          FIX: `overflow: visible` on `.input-wrap--phone`.
 *
 *  ─────────────────────────────────────────────────────────────────────
 *  Markup contract (after PHP renders + intl-tel-input init):
 *  ─────────────────────────────────────────────────────────────────────
 *      <div class="input-wrap input-wrap--phone" dir="ltr">
 *          <div class="iti iti--separate-dial-code iti--allow-dropdown">
 *              <div class="iti__country-container">
 *                  <button class="iti__selected-country" type="button">
 *                      <div class="iti__selected-country-primary">
 *                          <div class="iti__flag iti__sa"></div>
 *                          <div class="iti__arrow"></div>
 *                      </div>
 *                      <div class="iti__selected-dial-code">+966</div>
 *                  </button>
 *                  <div class="iti__dropdown-content"> ... country list ... </div>
 *              </div>
 *              <input class="iti__tel-input input--phone" ...>
 *          </div>
 *      </div>
 *
 *  ─────────────────────────────────────────────────────────────────────
 *  Visual target (matches design lines 1462-1487):
 *  ─────────────────────────────────────────────────────────────────────
 *  In LTR direction (forced via dir="ltr" attribute on .input-wrap--phone):
 *
 *    [ 🇸🇦 ▼ +966 ][ 50 123 4567 .................................. ]
 *     ↑                ↑
 *     country pill     phone input
 *     (brand-faint)    (transparent, flex: 1)
 *
 *  In RTL form context, the parent direction is RTL but the input-wrap is
 *  forced to LTR — so the pill appears on the LEFT visually, matching design.
 * ═══════════════════════════════════════════════════════════════════════════
 */


/* ═══════════════════════════════════════════════════════════════════════
   1. CONTAINER — make .iti truly flex, allow dropdown to escape
   ═══════════════════════════════════════════════════════════════════════ */

.input-wrap--phone {
    /* Force LTR direction so the library renders correctly */
    direction: ltr;

    /* CRITICAL: override .input-wrap { overflow: hidden } from base —
       otherwise the dropdown popup gets clipped */
    overflow: visible;
}

.input-wrap--phone .iti {
    /* Flag asset paths (v28) */
    --iti-path-flags-1x: url('/assets/vendor/intl-tel-input/img/flags.webp');
    --iti-path-flags-2x: url('/assets/vendor/intl-tel-input/img/flags@2x.webp');

    /* Wolf theme tokens for vendor internals */
    --iti-border-color:    var(--border);
    --iti-dropdown-bg:     var(--surface);
    --iti-hover-color:     var(--surface-2);

    /* Defeat vendor's `display: inline-block` — we need flex */
    display: flex !important;
    align-items: stretch;
    width: 100%;
    height: 100%;
    position: relative;  /* keep as positioning context for dropdown */
}


/* ═══════════════════════════════════════════════════════════════════════
   2. COUNTRY CONTAINER — defeat absolute positioning, use flex order
   ═══════════════════════════════════════════════════════════════════════ */

/* CRITICAL: vendor sets `position: absolute; top:0; bottom:0; left:0` —
   that takes the country container OUT of the flex flow. We need it IN. */
.input-wrap--phone .iti__country-container {
    position: static !important;
    inset: auto !important;            /* unset top/bottom/left/right */
    height: 100%;
    flex-shrink: 0;
    order: 1;                          /* visual: left side in LTR */
    padding: 0 !important;             /* remove vendor's border-width padding */
}


/* ═══════════════════════════════════════════════════════════════════════
   3. SELECTED COUNTRY (the visible pill) — match design's .country-selector
   ═══════════════════════════════════════════════════════════════════════ */

.input-wrap--phone .iti__selected-country,
.input-wrap--phone button.iti__selected-country {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 0 12px;
    height: 100%;
    background: var(--brand-faint);
    border: none;
    border-right: 1px solid var(--border);  /* visual separator from input */
    cursor: pointer;
    transition: background 0.2s ease;

    /* Defeat vendor's z-index: 1 — we don't need positioning hacks */
    z-index: auto;
}

.input-wrap--phone .iti__selected-country:hover,
.input-wrap--phone button.iti__selected-country:hover {
    background: var(--brand-tint);
}

.input-wrap--phone .iti__selected-country:focus-visible,
.input-wrap--phone button.iti__selected-country:focus-visible {
    background: var(--brand-tint);
    outline: 2px solid var(--brand);
    outline-offset: -2px;
}

/* Inner container that vendor uses (flag + arrow) */
.input-wrap--phone .iti__selected-country-primary {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 0;
    height: 100%;
}

/* Dial code (+966) — match design's .country-selector .code */
.input-wrap--phone .iti__selected-dial-code {
    font-family: var(--font-mono);
    font-size: 12px;
    font-weight: 800;
    color: var(--text);
    letter-spacing: 0.3px;
    margin-left: 4px;   /* keep vendor's spacing */
}


/* ═══════════════════════════════════════════════════════════════════════
   4. FLAG — DO NOT override width/height (preserves sprite math)
   ═══════════════════════════════════════════════════════════════════════ */

/* Vendor's flag rule uses width:20px + background-position:calc(offset*20px).
   Overriding width breaks the sprite. We ONLY add a subtle border-radius. */
.input-wrap--phone .iti__flag {
    border-radius: 2px;
    flex-shrink: 0;
}


/* ═══════════════════════════════════════════════════════════════════════
   5. ARROW (chevron) — tint only, don't change geometry
   ═══════════════════════════════════════════════════════════════════════ */

/* Vendor draws the arrow with `border-right + border-bottom` rotated 45deg.
   We only adjust the border colors to match our theme. */
.input-wrap--phone .iti__arrow {
    border-right-color: var(--text-muted);
    border-bottom-color: var(--text-muted);
    transition: transform 0.2s ease;
    flex-shrink: 0;
}

.input-wrap--phone .iti__arrow--up {
    border-right-color: var(--brand);
    border-bottom-color: var(--brand);
}


/* ═══════════════════════════════════════════════════════════════════════
   6. PHONE INPUT — fill remaining space, defeat library's dynamic padding
   ═══════════════════════════════════════════════════════════════════════ */

.input-wrap--phone .iti__tel-input,
.input-wrap--phone input.iti__tel-input,
.input-wrap--phone input.input--phone {
    flex: 1;
    background: transparent !important;
    border: none !important;
    outline: none !important;
    min-width: 0 !important;           /* CRITICAL: defeat vendor's `input.iti__tel-input[type=tel] { min-width: 100% }` (specificity 0,3,1) which forces the input to 100% width and overflows the flex row → box escapes the modal + selected-country button vanishes */
    order: 2;                          /* visual: right side in LTR */

    /* CRITICAL: defeat library's dynamic padding-left (calculated from
       country container width). We've put country in-flow, so no extra
       padding needed. */
    padding: 0 var(--sp-4) !important;
    margin: 0 !important;

    /* Match design typography (full-home.html line 1462-1469) */
    direction: ltr;
    text-align: left;
    font-family: var(--font-mono);
    font-size: 14.5px;
    letter-spacing: 0.4px;
    color: var(--text);
    font-weight: 600;

    /* Defeat vendor's z-index/position quirks */
    position: relative;
    z-index: auto;
}

.input-wrap--phone .iti__tel-input::placeholder,
.input-wrap--phone input.input--phone::placeholder {
    color: var(--text-muted);
    font-family: var(--font-mono);
    letter-spacing: 0.4px;
    font-weight: 500;
}


/* ═══════════════════════════════════════════════════════════════════════
   7. ERROR STATE
   ═══════════════════════════════════════════════════════════════════════ */

.input-wrap--phone.has-error .iti__selected-country {
    background: var(--danger-tint, rgba(220, 38, 38, 0.12));
}


/* ═══════════════════════════════════════════════════════════════════════
   8. DROPDOWN POPUP — Wolf-themed with custom scrollbar
   ═══════════════════════════════════════════════════════════════════════ */

.iti__dropdown-content {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    box-shadow:
        0 10px 30px rgba(0, 0, 0, 0.40),
        0 2px 8px rgba(0, 0, 0, 0.20);
    overflow: hidden;
    margin-top: 4px;
}

.iti__country-list {
    /* Force LTR — keeps scrollbar on the RIGHT side regardless of page direction */
    direction: ltr;
    text-align: left;
    background: var(--surface);
    max-height: 280px;
    overflow-y: auto;
    padding: 4px 0;
    margin: 0;
    list-style: none;
}

.iti__country {
    color: var(--text);
    padding: 8px 14px;
    font-size: 13.5px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s ease;
    display: flex;
    align-items: center;
    gap: 10px;
    border: none;
}

.iti__country .iti__flag {
    /* DO NOT override width/height — preserve sprite */
    border-radius: 2px;
    flex-shrink: 0;
}

.iti__country-name {
    color: var(--text);
    flex: 1;
}

.iti__dial-code {
    color: var(--text-muted);
    font-family: var(--font-mono);
    font-size: 12px;
    font-weight: 700;
}

.iti__country:hover,
.iti__country.iti__highlight {
    background: var(--brand-faint);
}

.iti__country.iti__highlight .iti__dial-code {
    color: var(--brand-soft);
}

.iti__country[aria-selected="true"] {
    background: var(--brand-tint);
    color: var(--text);
    font-weight: 700;
}

.iti__divider {
    border-bottom: 1px solid var(--border);
    margin: 4px 0;
    height: 1px;
    padding: 0;
}


/* ═══════════════════════════════════════════════════════════════════════
   9. COUNTRY SEARCH (if enabled later)
   ═══════════════════════════════════════════════════════════════════════ */

.iti__search-input {
    background: var(--bg);
    color: var(--text);
    border: none;
    border-bottom: 1px solid var(--border);
    padding: 10px 14px;
    font-size: 13.5px;
    font-family: inherit;
    width: 100%;
    outline: none;
}

.iti__search-input::placeholder {
    color: var(--text-muted);
}

.iti__search-input:focus {
    border-bottom-color: var(--brand);
    background: var(--surface);
}


/* ═══════════════════════════════════════════════════════════════════════
   10. CUSTOM SCROLLBAR — Wolf-themed
   ═══════════════════════════════════════════════════════════════════════ */

.iti__country-list::-webkit-scrollbar {
    width: 6px;
}

.iti__country-list::-webkit-scrollbar-track {
    background: transparent;
}

.iti__country-list::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
    transition: background 0.2s ease;
}

.iti__country-list::-webkit-scrollbar-thumb:hover {
    background: var(--brand-soft);
}

/* Firefox */
.iti__country-list {
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}


/* ═══════════════════════════════════════════════════════════════════════
   11. FULLSCREEN POPUP (mobile) — Wolf theming
   ═══════════════════════════════════════════════════════════════════════ */

.iti--fullscreen-popup .iti__dropdown-content {
    background: var(--surface);
    border-radius: 0;
}

.iti--fullscreen-popup .iti__country {
    padding: 14px 18px;
    font-size: 15px;
}
