/**
 * Language Switcher Styles
 * Hadassa Ebenezer Ministries
 * Provides consistent styling for language selection UI across all pages
 */

/* ===== Language Switcher Container ===== */
.language-switcher {
    position: relative;
    display: inline-block;
    z-index: 1000;
}

/* ===== Language Button ===== */
.language-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background-color: #FFFFFF;
    border: 1px solid #D1D1D6;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    color: #1D1D1F;
    transition: all 0.2s ease;
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

.language-btn:hover {
    background-color: #F5F5F7;
    border-color: #004799;
}

.language-btn:active {
    transform: scale(0.98);
}

.language-btn:focus {
    outline: none;
    border-color: #004799;
    box-shadow: 0 0 0 3px rgba(0, 71, 153, 0.1);
}

/* Flag Icon */
.current-flag {
    width: 20px;
    height: 15px;
    object-fit: cover;
    border-radius: 2px;
}

/* Current Language Text */
#currentLang {
    font-size: 14px;
    font-weight: 500;
    color: #1D1D1F;
}

/* Chevron Icon */
.language-btn .fa-chevron-down {
    font-size: 10px;
    color: #86868B;
    transition: transform 0.2s ease;
}

.language-btn:hover .fa-chevron-down {
    color: #004799;
}

/* ===== Language Dropdown ===== */
.language-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    background-color: #FFFFFF;
    border: 1px solid #D1D1D6;
    border-radius: 12px;
    min-width: 180px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.12), 0 4px 8px rgba(0, 0, 0, 0.08);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all 0.2s ease;
    overflow: hidden;
    z-index: 10000; /* Ensure dropdown appears above all other elements */
}

.language-dropdown.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

/* ===== Language Options ===== */
.language-option {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    cursor: pointer;
    transition: all 0.15s ease;
    font-size: 14px;
    font-weight: 400;
    color: #1D1D1F;
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

.language-option:hover {
    background-color: #F5F5F7;
}

.language-option:active {
    background-color: #E8E8ED;
}

.language-option.active {
    background-color: #EBF4FF;
    color: #004799;
    font-weight: 600;
}

.language-option.active::before {
    content: "✓";
    position: absolute;
    right: 16px;
    font-size: 14px;
    color: #004799;
    font-weight: bold;
}

.language-option img {
    width: 20px;
    height: 15px;
    object-fit: cover;
    border-radius: 2px;
}

.language-option span {
    flex: 1;
}

/* Divider between options (optional) */
.language-option:not(:last-child) {
    border-bottom: 1px solid #F5F5F7;
}

/* ===== Loading State ===== */
body.i18n-loading .language-btn {
    pointer-events: none;
    opacity: 0.6;
}

body.i18n-loading .language-btn::after {
    content: "";
    position: absolute;
    top: 50%;
    right: 12px;
    width: 12px;
    height: 12px;
    margin-top: -6px;
    border: 2px solid #D1D1D6;
    border-top-color: #004799;
    border-radius: 50%;
    animation: spinner 0.6s linear infinite;
}

@keyframes spinner {
    to {
        transform: rotate(360deg);
    }
}

/* ===== Responsive Design ===== */

/* Desktop - In Navbar */
@media (min-width: 992px) {
    .language-switcher {
        margin-left: 16px;
    }
}

/* Mobile - In Offcanvas Menu */
@media (max-width: 991px) {
    .language-switcher {
        width: 100%;
        margin-top: 16px;
        padding: 0 16px;
    }

    .language-btn {
        width: 100%;
        justify-content: space-between;
        padding: 12px 16px;
    }

    .language-dropdown {
        right: 16px;
        left: 16px;
        width: calc(100% - 32px);
    }
}

/* ===== Dark Mode Support (Optional) ===== */
@media (prefers-color-scheme: dark) {
    .language-btn {
        background-color: #1C1C1E;
        border-color: #38383A;
        color: #F5F5F7;
    }

    .language-btn:hover {
        background-color: #2C2C2E;
        border-color: #0A84FF;
    }

    #currentLang {
        color: #F5F5F7;
    }

    .language-dropdown {
        background-color: #1C1C1E;
        border-color: #38383A;
        box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5), 0 4px 8px rgba(0, 0, 0, 0.3);
    }

    .language-option {
        color: #F5F5F7;
    }

    .language-option:hover {
        background-color: #2C2C2E;
    }

    .language-option.active {
        background-color: #1A3A5C;
        color: #0A84FF;
    }

    .language-option.active::before {
        color: #0A84FF;
    }

    .language-option:not(:last-child) {
        border-bottom-color: #38383A;
    }
}

/* ===== Accessibility ===== */

/* Focus visible for keyboard navigation */
.language-option:focus {
    outline: 2px solid #004799;
    outline-offset: -2px;
    background-color: #F5F5F7;
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    .language-btn,
    .language-dropdown,
    .language-option,
    .language-btn .fa-chevron-down {
        transition: none;
    }

    body.i18n-loading .language-btn::after {
        animation: none;
    }
}

/* High contrast mode */
@media (prefers-contrast: high) {
    .language-btn {
        border-width: 2px;
    }

    .language-option.active {
        outline: 2px solid #004799;
    }
}

/* ===== Integration with Navbar ===== */

/* When placed in navbar utility bar */
.utility-bar .language-switcher {
    margin-left: 20px;
}

/* When placed in main navbar */
.navbar .language-switcher {
    order: 10; /* Place after other nav items */
}

/* When placed in Bootstrap offcanvas */
.offcanvas-body .language-switcher {
    margin-top: 24px;
    padding-top: 24px;
    border-top: 1px solid #D1D1D6;
}

/* ===== Additional States ===== */

/* Disabled state */
.language-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

/* Error state (if translation loading fails) */
.language-switcher.error .language-btn {
    border-color: #FF3B30;
    color: #FF3B30;
}

/* Success state (after successful language change) */
.language-switcher.success .language-btn {
    border-color: #34C759;
}

.language-switcher.success .language-btn::before {
    content: "✓";
    margin-right: 4px;
    color: #34C759;
    animation: fadeOut 2s forwards;
}

@keyframes fadeOut {
    0%, 70% {
        opacity: 1;
    }
    100% {
        opacity: 0;
    }
}
