/**
 * Appx Smart Phone Input Component Styles
 * Full RTL/LTR Direction Support, High-Resolution Flag Icons & Native Appx CRM Design
 */

/* Phone Input Unified Container */
.appx-phone-container {
    position: relative;
    display: flex !important;
    align-items: stretch !important;
    width: 100% !important;
    box-sizing: border-box !important;
    margin-bottom: 0;
}

/* Hide original inputs securely without breaking form submission or validation */
input.appx-phone-original-input {
    position: absolute !important;
    opacity: 0 !important;
    pointer-events: none !important;
    height: 0 !important;
    width: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    border: none !important;
    z-index: -1 !important;
}

/* Country Button Addon */
.appx-phone-container .appx-country-addon {
    position: relative;
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

/* Country Selector Button */
.appx-phone-container .appx-country-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 36px;
    padding: 6px 10px;
    font-size: 13px;
    font-weight: 500;
    color: #334155;
    background-color: #f8fafc;
    border: 1px solid #cbd5e1;
    transition: all 0.15s ease-in-out;
    outline: none !important;
    user-select: none;
    cursor: pointer;
    box-sizing: border-box;
}

.appx-phone-container .appx-country-btn:hover,
.appx-phone-container .appx-country-btn:focus,
.appx-phone-container .appx-country-addon.open .appx-country-btn {
    background-color: #f1f5f9;
    border-color: #94a3b8;
    color: #0f172a;
}

/* Graphic Flag Images */
.appx-flag {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    flex-shrink: 0;
}

.appx-flag-img,
.appx-flag .fi,
.appx-item-flag .fi,
.appx-flag-icon {
    width: 20px !important;
    height: 15px !important;
    line-height: 15px !important;
    object-fit: cover !important;
    border-radius: 2px !important;
    box-shadow: 0 0 1px rgba(0, 0, 0, 0.35) !important;
    display: inline-block !important;
    vertical-align: middle !important;
    background-size: cover !important;
    background-position: center !important;
    background-repeat: no-repeat !important;
    flex-shrink: 0;
}

.appx-flag-fallback {
    font-size: 11px !important;
    font-weight: 700 !important;
    line-height: 1 !important;
    color: #475569 !important;
    letter-spacing: 0.5px !important;
    display: inline-block !important;
}

.appx-country-btn .appx-code {
    font-size: 12.5px;
    font-weight: 600;
    font-family: Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
    color: #1e293b;
    letter-spacing: 0.2px;
    direction: ltr !important;
    unicode-bidi: isolate !important;
    display: inline-block;
}

.appx-country-btn .appx-caret {
    display: inline-block;
    width: 0;
    height: 0;
    margin-left: 2px;
    margin-right: 2px;
    vertical-align: middle;
    border-top: 4px dashed;
    border-top: 4px solid \9;
    border-right: 4px solid transparent;
    border-left: 4px solid transparent;
    color: #64748b;
    transition: transform 0.2s ease;
}

.appx-phone-container .appx-country-addon.open .appx-caret {
    transform: rotate(180deg);
}

/* Number Input Field */
.appx-phone-container .appx-phone-number-field {
    height: 36px !important;
    font-size: 13.5px !important;
    font-family: Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace, inherit !important;
    color: #1e293b !important;
    background-color: #ffffff !important;
    border: 1px solid #cbd5e1 !important;
    padding: 6px 12px !important;
    width: 100% !important;
    letter-spacing: 0.8px !important;
    transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out !important;
    box-sizing: border-box !important;
}

.appx-phone-container .appx-phone-number-field:focus {
    border-color: #03a9f4 !important;
    box-shadow: 0 0 0 2px rgba(3, 169, 244, 0.15) !important;
    outline: 0 !important;
    z-index: 2 !important;
}

/* =========================================================
   RTL SYSTEM ORIENTATION (Arabic System Flow)
   ========================================================= */
.appx-phone-container[data-dir="rtl"] {
    direction: rtl !important;
    flex-direction: row !important;
}

/* In RTL: Country Button on RIGHT (start) */
.appx-phone-container[data-dir="rtl"] .appx-country-addon {
    order: 1 !important;
}

.appx-phone-container[data-dir="rtl"] .appx-country-btn {
    border-radius: 0 4px 4px 0 !important;
    border-left: none !important;
    border-right: 1px solid #cbd5e1 !important;
    direction: rtl !important;
}

/* In RTL Button: Flag on right, Code in middle, Caret on left */
.appx-phone-container[data-dir="rtl"] .appx-country-btn .appx-flag {
    order: 1 !important;
}

.appx-phone-container[data-dir="rtl"] .appx-country-btn .appx-code {
    order: 2 !important;
    direction: ltr !important;
    unicode-bidi: isolate !important;
}

.appx-phone-container[data-dir="rtl"] .appx-country-btn .appx-caret {
    order: 3 !important;
}

/* In RTL: Number Input on LEFT (end) */
.appx-phone-container[data-dir="rtl"] .appx-phone-number-field {
    order: 2 !important;
    border-radius: 4px 0 0 4px !important;
    border-right: 1px solid #cbd5e1 !important;
    border-left: 1px solid #cbd5e1 !important;
    direction: ltr !important;
    text-align: right !important;
    unicode-bidi: plaintext !important;
    padding-right: 12px !important;
    padding-left: 12px !important;
}

/* In RTL: Dropdown menu alignment */
.appx-phone-container[data-dir="rtl"] .appx-country-dropdown-menu {
    left: auto !important;
    right: 0 !important;
    text-align: right !important;
    direction: rtl !important;
}

.appx-phone-container[data-dir="rtl"] .appx-dropdown-search-wrapper .appx-search-icon {
    right: 10px !important;
    left: auto !important;
}

.appx-phone-container[data-dir="rtl"] .appx-dropdown-search-wrapper input.appx-search-input {
    padding-right: 30px !important;
    padding-left: 28px !important;
    text-align: right !important;
    direction: rtl !important;
}

.appx-phone-container[data-dir="rtl"] .appx-dropdown-search-wrapper .appx-clear-btn {
    left: 8px !important;
    right: auto !important;
}

/* =========================================================
   LTR SYSTEM ORIENTATION (English System Flow)
   ========================================================= */
.appx-phone-container[data-dir="ltr"] {
    direction: ltr !important;
    flex-direction: row !important;
}

/* In LTR: Country Button on LEFT (start) */
.appx-phone-container[data-dir="ltr"] .appx-country-addon {
    order: 1 !important;
}

.appx-phone-container[data-dir="ltr"] .appx-country-btn {
    border-radius: 4px 0 0 4px !important;
    border-right: none !important;
    border-left: 1px solid #cbd5e1 !important;
    direction: ltr !important;
}

/* In LTR Button: Flag on left, Code in middle, Caret on right */
.appx-phone-container[data-dir="ltr"] .appx-country-btn .appx-flag {
    order: 1 !important;
}

.appx-phone-container[data-dir="ltr"] .appx-country-btn .appx-code {
    order: 2 !important;
    direction: ltr !important;
}

.appx-phone-container[data-dir="ltr"] .appx-country-btn .appx-caret {
    order: 3 !important;
}

/* In LTR: Number Input on RIGHT (end) */
.appx-phone-container[data-dir="ltr"] .appx-phone-number-field {
    order: 2 !important;
    border-radius: 0 4px 4px 0 !important;
    border-left: 1px solid #cbd5e1 !important;
    border-right: 1px solid #cbd5e1 !important;
    direction: ltr !important;
    text-align: left !important;
    padding-left: 12px !important;
    padding-right: 12px !important;
}

.appx-phone-container[data-dir="ltr"] .appx-country-dropdown-menu {
    left: 0 !important;
    right: auto !important;
    text-align: left !important;
    direction: ltr !important;
}

.appx-phone-container[data-dir="ltr"] .appx-dropdown-search-wrapper .appx-search-icon {
    left: 10px !important;
    right: auto !important;
}

.appx-phone-container[data-dir="ltr"] .appx-dropdown-search-wrapper input.appx-search-input {
    padding-left: 30px !important;
    padding-right: 28px !important;
    text-align: left !important;
    direction: ltr !important;
}

.appx-phone-container[data-dir="ltr"] .appx-dropdown-search-wrapper .appx-clear-btn {
    right: 8px !important;
    left: auto !important;
}

/* Error States */
.appx-phone-container.has-error .appx-phone-number-field,
.appx-phone-container.has-error .appx-country-btn {
    border-color: #ef4444 !important;
}

.appx-phone-container.has-error .appx-phone-number-field:focus {
    box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.2) !important;
}

/* Country Searchable Dropdown */
.appx-country-dropdown-menu {
    position: absolute;
    top: 100%;
    z-index: 1060;
    display: none;
    min-width: 330px;
    max-width: 380px;
    padding: 0;
    margin: 4px 0 0;
    font-size: 13px;
    list-style: none;
    background-color: #ffffff;
    background-clip: padding-box;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
}

.appx-country-addon.open .appx-country-dropdown-menu {
    display: block;
    animation: appxDropdownFadeIn 0.15s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes appxDropdownFadeIn {
    from {
        opacity: 0;
        transform: translateY(-6px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Dropdown Search Box */
.appx-dropdown-search-box {
    position: sticky;
    top: 0;
    background: #ffffff;
    padding: 8px 10px;
    border-bottom: 1px solid #f1f5f9;
    border-radius: 6px 6px 0 0;
    z-index: 10;
}

.appx-dropdown-search-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.appx-dropdown-search-wrapper .appx-search-icon {
    position: absolute;
    font-size: 12px;
    color: #94a3b8;
    pointer-events: none;
}

.appx-dropdown-search-wrapper input.appx-search-input {
    width: 100%;
    height: 32px;
    font-size: 12.5px;
    color: #1e293b;
    background-color: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 4px;
    outline: none;
    transition: all 0.15s ease;
}

.appx-dropdown-search-wrapper input.appx-search-input:focus {
    background-color: #ffffff;
    border-color: #03a9f4;
    box-shadow: 0 0 0 2px rgba(3, 169, 244, 0.1);
}

.appx-dropdown-search-wrapper .appx-clear-btn {
    position: absolute;
    background: none;
    border: none;
    font-size: 16px;
    line-height: 1;
    color: #94a3b8;
    cursor: pointer;
    padding: 2px 4px;
}

.appx-dropdown-search-wrapper .appx-clear-btn:hover {
    color: #475569;
}

/* Country Scrollable List */
.appx-country-list {
    max-height: 240px;
    overflow-y: auto;
    overflow-x: hidden;
    margin: 0;
    padding: 4px 0;
    list-style: none;
    scroll-behavior: smooth;
}

.appx-country-list::-webkit-scrollbar {
    width: 6px;
}
.appx-country-list::-webkit-scrollbar-track {
    background: #f8fafc;
}
.appx-country-list::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}
.appx-country-list::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* Country List Item */
.appx-country-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 7px 12px;
    font-size: 12.5px;
    color: #334155;
    cursor: pointer;
    transition: background-color 0.1s ease;
    user-select: none;
    gap: 8px;
}

.appx-country-item:hover,
.appx-country-item.is-focused {
    background-color: #f1f5f9;
    color: #0f172a;
}

.appx-country-item.is-selected {
    background-color: #e0f2fe;
    color: #0369a1;
    font-weight: 600;
}

.appx-country-item .appx-item-main {
    display: flex;
    align-items: center;
    gap: 8px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    flex-grow: 1;
}

.appx-country-item .appx-item-flag {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    flex-shrink: 0;
}

.appx-country-item .appx-item-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.appx-country-item .appx-item-code {
    font-family: Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
    font-size: 11.5px;
    font-weight: 600;
    color: #64748b;
    background: #f8fafc;
    padding: 2px 6px;
    border-radius: 3px;
    border: 1px solid #e2e8f0;
    flex-shrink: 0;
    direction: ltr !important;
}

.appx-country-item.is-selected .appx-item-code {
    background: #bae6fd;
    color: #0369a1;
    border-color: #7dd3fc;
}

/* Empty search result */
.appx-country-empty {
    padding: 16px 12px;
    text-align: center;
    color: #94a3b8;
    font-size: 12px;
}

/* =========================================================
   Login View Phone/Email Switcher Tabs
   ========================================================= */
.appx-login-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
}

.appx-login-tabs[data-dir="rtl"] {
    direction: rtl;
}

.appx-login-tabs .appx-login-tab-btn {
    flex: 1;
    padding: 8px 12px;
    font-size: 13px;
    font-weight: 600;
    color: #64748b;
    background: #f8fafc;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s ease-in-out;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    outline: none !important;
}

.appx-login-tabs .appx-login-tab-btn:hover {
    background: #f1f5f9;
    color: #1e293b;
    border-color: #94a3b8;
}

.appx-login-tabs .appx-login-tab-btn.active {
    background: #0284c7;
    color: #ffffff;
    border-color: #0284c7;
    box-shadow: 0 1px 3px rgba(2, 132, 199, 0.3);
}

.appx-login-tabs .appx-login-tab-btn i {
    font-size: 14px;
}
