/* ============================================
   LANGUAGE SWITCHER - PROFESSIONAL DESIGN SYSTEM
   Modern, accessible, mobile-first implementation
   Version: 2.0
   ============================================ */

/* ===== CSS VARIABLES - DESIGN TOKENS ===== */
:root {
    /* Primary Colors */
    --ls-primary: #3b82f6;
    --ls-primary-hover: #2563eb;
    --ls-primary-light: #eff6ff;
    --ls-primary-dark: #1e40af;

    /* Neutral Colors */
    --ls-gray-50: #f9fafb;
    --ls-gray-100: #f3f4f6;
    --ls-gray-200: #e5e7eb;
    --ls-gray-300: #d1d5db;
    --ls-gray-400: #9ca3af;
    --ls-gray-500: #6b7280;
    --ls-gray-600: #4b5563;
    --ls-gray-700: #374151;
    --ls-gray-800: #1f2937;
    --ls-gray-900: #111827;

    /* Semantic Colors */
    --ls-bg-white: #ffffff;
    --ls-text-primary: #111827;
    --ls-text-secondary: #6b7280;
    --ls-border: #e5e7eb;
    --ls-border-hover: #d1d5db;
    --ls-border-focus: #3b82f6;

    /* Spacing System (based on 4px grid) */
    --ls-space-1: 0.25rem;   /* 4px */
    --ls-space-2: 0.5rem;    /* 8px */
    --ls-space-3: 0.75rem;   /* 12px */
    --ls-space-4: 1rem;      /* 16px */
    --ls-space-5: 1.25rem;   /* 20px */
    --ls-space-6: 1.5rem;    /* 24px */
    --ls-gap: 0.375rem;      /* 6px - gap between segments */

    /* Typography */
    --ls-font-size-sm: 0.8125rem;  /* 13px */
    --ls-font-size-base: 0.875rem; /* 14px */
    --ls-font-size-md: 1rem;       /* 16px */
    --ls-font-size-lg: 1.125rem;   /* 18px */
    --ls-font-weight-normal: 500;
    --ls-font-weight-medium: 600;
    --ls-font-weight-bold: 700;

    /* Icon Sizes */
    --ls-icon-sm: 1rem;       /* 16px */
    --ls-icon-base: 1.125rem; /* 18px */
    --ls-icon-md: 1.25rem;    /* 20px */
    --ls-icon-lg: 1.75rem;    /* 28px */

    /* Border Radius */
    --ls-radius-sm: 0.375rem;  /* 6px */
    --ls-radius-md: 0.5rem;    /* 8px */
    --ls-radius-lg: 0.75rem;   /* 12px */
    --ls-radius-xl: 1rem;      /* 16px */
    --ls-radius-2xl: 1.5rem;   /* 24px */

    /* Shadows */
    --ls-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --ls-shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --ls-shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --ls-shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);

    /* Transitions */
    --ls-transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
    --ls-transition-base: 200ms cubic-bezier(0.4, 0, 0.2, 1);
    --ls-transition-slow: 300ms cubic-bezier(0.4, 0, 0.2, 1);
    --ls-transition-smooth: 300ms cubic-bezier(0.4, 0.0, 0.2, 1);

    /* Touch Targets (minimum size for accessibility) */
    --ls-touch-target: 48px;
    --ls-touch-target-sm: 44px;

    /* Z-index Scale */
    --ls-z-dropdown: 1000;
    --ls-z-modal-backdrop: 2000;
    --ls-z-modal: 2001;

    /* Customizable Theme Colors (can be overridden inline) */
    --ls-segment-primary: var(--ls-primary);
    --ls-segment-bg: var(--ls-gray-100);
    --ls-segment-text: var(--ls-gray-700);
    --ls-segment-active-text: #ffffff;
}

/* Support for reduced motion accessibility */
@media (prefers-reduced-motion: reduce) {
    :root {
        --ls-transition-fast: 50ms linear;
        --ls-transition-base: 50ms linear;
        --ls-transition-slow: 50ms linear;
        --ls-transition-smooth: 50ms linear;
    }
}

/* ===== BASE COMPONENT STYLES ===== */
.language-switcher-minimal {
    position: relative;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ===== DESKTOP BUTTON ===== */
.language-button {
    display: inline-flex;
    align-items: center;
    gap: var(--ls-space-2);
    padding: var(--ls-space-2) var(--ls-space-3);
    min-height: var(--ls-touch-target-sm);
    background: var(--ls-bg-white);
    border: 1px solid var(--ls-border);
    border-radius: var(--ls-radius-md);
    color: var(--ls-gray-700);
    font-size: var(--ls-font-size-base);
    font-weight: var(--ls-font-weight-normal);
    cursor: pointer;
    transition: all var(--ls-transition-base);
    letter-spacing: 0.01em;
}

.language-button:hover {
    background: var(--ls-gray-50);
    border-color: var(--ls-border-hover);
    transform: translateY(-1px);
    box-shadow: var(--ls-shadow-sm);
}

.language-button:focus {
    outline: none;
    border-color: var(--ls-border-focus);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

.language-button:active {
    transform: translateY(0);
}

.language-icon {
    font-size: var(--ls-icon-base);
    line-height: 1;
    /* Flag-icons sizing */
    width: var(--ls-icon-base);
    height: var(--ls-icon-base);
    display: inline-block;
}

.language-name {
    color: var(--ls-text-primary);
    font-weight: var(--ls-font-weight-medium);
}

.chevron {
    width: var(--ls-icon-sm);
    height: var(--ls-icon-sm);
    color: var(--ls-gray-400);
    transition: transform var(--ls-transition-base), color var(--ls-transition-base);
}

.chevron.rotate {
    transform: rotate(180deg);
    color: var(--ls-primary);
}

/* ===== DESKTOP DROPDOWN ===== */
.language-dropdown-container {
    position: relative;
}

.language-dropdown {
    position: absolute;
    top: calc(100% + var(--ls-space-2));
    left: 0;
    min-width: 12rem;
    max-width: 18rem;
    max-height: 24rem;
    overflow-y: auto;
    background: var(--ls-bg-white);
    border: 1px solid var(--ls-border);
    border-radius: var(--ls-radius-lg);
    box-shadow: var(--ls-shadow-xl);
    z-index: var(--ls-z-dropdown);
    animation: fadeInScale 200ms var(--ls-transition-base) backwards;
}

/* CRITICAL FIX: Support for left-aligned dropdown (when near right edge) */
.language-dropdown.align-left {
    right: auto;
    left: 0;
}

@keyframes fadeInScale {
    from {
        opacity: 0;
        transform: scale(0.96) translateY(-8px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

/* ===== SEARCH INPUT (Unified for both desktop & mobile) ===== */
.language-search {
    padding: var(--ls-space-3);
    border-bottom: 1px solid var(--ls-gray-100);
    background: var(--ls-gray-50);
}

.language-search-input,
.mobile-search-input {
    width: 100%;
    padding: var(--ls-space-2) var(--ls-space-3);
    background: var(--ls-bg-white);
    border: 1px solid var(--ls-border);
    border-radius: var(--ls-radius-md);
    font-size: var(--ls-font-size-base);
    color: var(--ls-text-primary);
    transition: all var(--ls-transition-base);
}

.language-search-input::placeholder,
.mobile-search-input::placeholder {
    color: var(--ls-gray-400);
}

.language-search-input:focus,
.mobile-search-input:focus {
    outline: none;
    border-color: var(--ls-border-focus);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* ===== DROPDOWN LIST ITEMS ===== */
.language-list {
    padding: var(--ls-space-2);
    max-height: 18rem;
    overflow-y: auto;
}

.language-item {
    display: flex;
    align-items: center;
    gap: var(--ls-space-3);
    padding: var(--ls-space-2) var(--ls-space-3);
    min-height: var(--ls-touch-target);
    background: transparent;
    border: none;
    border-radius: var(--ls-radius-md);
    color: var(--ls-text-primary);
    font-size: var(--ls-font-size-base);
    cursor: pointer;
    transition: all var(--ls-transition-fast);
    text-align: left;
    width: 100%;
}

.language-item:hover {
    background: var(--ls-gray-50);
    transform: translateX(2px);
}

.language-item:active {
    transform: scale(0.98);
    background: var(--ls-gray-100);
}

.language-item.active {
    background: var(--ls-primary-light);
    color: var(--ls-primary-dark);
    font-weight: var(--ls-font-weight-medium);
}

/* UNIFIED FOCUS STYLE */
.language-item:focus-visible {
    outline: 2px solid var(--ls-primary);
    outline-offset: -2px;
}

.language-flag {
    font-size: var(--ls-icon-md);
    line-height: 1;
    flex-shrink: 0;
    /* Flag-icons sizing */
    width: var(--ls-icon-md);
    height: var(--ls-icon-md);
    display: inline-block;
}

.language-text {
    flex: 1;
    overflow: hidden;
}

.language-item-name {
    font-size: var(--ls-font-size-base);
    font-weight: var(--ls-font-weight-medium);
    color: var(--ls-text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.language-item.active .language-item-name {
    color: var(--ls-primary-dark);
}

.language-check {
    width: var(--ls-icon-md);
    height: var(--ls-icon-md);
    color: var(--ls-primary);
    flex-shrink: 0;
}

/* ===== MOBILE BUTTON ===== */
.language-button-mobile {
    display: inline-flex;
    align-items: center;
    gap: var(--ls-space-2);
    padding: var(--ls-space-2) var(--ls-space-3);
    min-height: var(--ls-touch-target-sm);
    background: var(--ls-bg-white);
    border: 1px solid var(--ls-border);
    border-radius: var(--ls-radius-md);
    color: var(--ls-gray-700);
    font-size: var(--ls-font-size-base);
    font-weight: var(--ls-font-weight-normal);
    cursor: pointer;
    transition: all var(--ls-transition-base);
    -webkit-tap-highlight-color: transparent;
}

.language-button-mobile:active {
    transform: scale(0.97);
    background: var(--ls-gray-50);
}

/* ===== MOBILE BOTTOM SHEET ===== */
.mobile-sheet-container {
    position: fixed;
    inset: 0;
    z-index: var(--ls-z-modal-backdrop);
    animation: fadeIn 300ms ease-out;
}

.mobile-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.mobile-sheet {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    max-height: 85vh;
    background: var(--ls-bg-white);
    border-radius: var(--ls-radius-2xl) var(--ls-radius-2xl) 0 0;
    box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.15);
    z-index: var(--ls-z-modal);
    animation: slideUp 300ms cubic-bezier(0.4, 0.0, 0.2, 1);
    display: flex;
    flex-direction: column;
    /* CRITICAL FIX: Safe area support for notched devices (iPhone X+) */
    padding-bottom: max(var(--ls-space-4), env(safe-area-inset-bottom));
}

@keyframes slideUp {
    from {
        transform: translateY(100%);
    }
    to {
        transform: translateY(0);
    }
}

/* Additional safe area support for iOS */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    .mobile-sheet {
        padding-bottom: calc(var(--ls-space-4) + env(safe-area-inset-bottom));
    }
}

.mobile-sheet-header {
    padding: var(--ls-space-4) var(--ls-space-4) var(--ls-space-3);
    border-bottom: 1px solid var(--ls-gray-100);
    flex-shrink: 0;
}

.mobile-sheet-handle {
    width: 40px;
    height: 4px;
    background: var(--ls-gray-300);
    border-radius: 2px;
    margin: var(--ls-space-3) auto var(--ls-space-2);
    cursor: grab;
    touch-action: none;
}

.mobile-sheet-handle:active {
    cursor: grabbing;
    background: var(--ls-gray-400);
}

.mobile-sheet-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.mobile-sheet-title {
    font-size: var(--ls-font-size-lg);
    font-weight: var(--ls-font-weight-bold);
    color: var(--ls-text-primary);
}

.mobile-sheet-close {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--ls-gray-100);
    border: none;
    border-radius: 50%;
    color: var(--ls-gray-600);
    cursor: pointer;
    transition: all var(--ls-transition-fast);
    -webkit-tap-highlight-color: transparent;
}

.mobile-sheet-close:active {
    transform: scale(0.92);
    background: var(--ls-gray-200);
}

.mobile-sheet-close svg {
    width: var(--ls-icon-md);
    height: var(--ls-icon-md);
}

.mobile-search {
    padding: 0 var(--ls-space-4) var(--ls-space-3);
    flex-shrink: 0;
}

.mobile-sheet-content {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.mobile-language-item {
    display: flex;
    align-items: center;
    gap: var(--ls-space-4);
    padding: var(--ls-space-3) var(--ls-space-4);
    min-height: 60px;
    background: transparent;
    border: none;
    border-radius: var(--ls-radius-lg);
    cursor: pointer;
    transition: all var(--ls-transition-fast);
    text-align: left;
    width: 100%;
    -webkit-tap-highlight-color: transparent;
}

.mobile-language-item:hover {
    background: var(--ls-gray-50);
}

.mobile-language-item:active {
    background: var(--ls-gray-100);
    transform: scale(0.98);
}

.mobile-language-item.active {
    background: var(--ls-primary-light);
}

.mobile-language-flag {
    font-size: var(--ls-icon-lg);
    line-height: 1;
    flex-shrink: 0;
    /* Flag-icons sizing */
    width: var(--ls-icon-lg);
    height: var(--ls-icon-lg);
    display: inline-block;
}

.mobile-language-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
    overflow: hidden;
}

.mobile-language-name {
    font-size: var(--ls-font-size-md);
    font-weight: var(--ls-font-weight-medium);
    color: var(--ls-text-primary);
}

.mobile-language-item.active .mobile-language-name {
    color: var(--ls-primary-dark);
}

.mobile-language-name-en {
    font-size: var(--ls-font-size-sm);
    color: var(--ls-text-secondary);
}

.mobile-language-check {
    width: var(--ls-icon-md);
    height: var(--ls-icon-md);
    color: var(--ls-primary);
    flex-shrink: 0;
}

/* ===== SEGMENTED CONTROL - PROFESSIONAL DESIGN ===== */
.language-segmented-control {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: var(--ls-gap);
    padding: var(--ls-space-1);
    background: var(--ls-segment-bg);
    border-radius: var(--ls-radius-md);
    border: 1px solid var(--ls-border);
    box-shadow: var(--ls-shadow-sm);
    /* CRITICAL FIX: Prevent overflow on small screens */
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none; /* Firefox */
}

.language-segmented-control::-webkit-scrollbar {
    display: none; /* Chrome, Safari */
}

.segment-slider {
    position: absolute;
    top: 0;
    height: 100%;
    background: var(--ls-segment-primary);
    border-radius: var(--ls-radius-sm);
    transition: left var(--ls-transition-smooth), width var(--ls-transition-smooth);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12), 0 1px 3px rgba(0, 0, 0, 0.08);
    z-index: 0;
    pointer-events: none;
    will-change: left, width;
    box-sizing: border-box;
    /* Width and left position set via inline styles */
}

.segment-item {
    position: relative;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--ls-space-2);
    padding: var(--ls-space-2) var(--ls-space-4);
    background: transparent;
    border: none;
    border-radius: var(--ls-radius-sm);
    color: var(--ls-segment-text);
    font-size: var(--ls-font-size-base);
    font-weight: var(--ls-font-weight-medium);
    cursor: pointer;
    transition: color var(--ls-transition-base), transform var(--ls-transition-fast);
    white-space: nowrap;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    flex: 1; /* Equal width segments */
    box-sizing: border-box;
}

.segment-item.active {
    color: var(--ls-segment-active-text);
}

.segment-item:hover:not(.active) {
    background: rgba(0, 0, 0, 0.03);
}

.segment-item:active {
    transform: scale(0.97);
}

/* UNIFIED FOCUS STYLE */
.segment-item:focus-visible {
    outline: 2px solid var(--ls-primary);
    outline-offset: 2px;
}

.segment-flag {
    font-size: var(--ls-icon-base);
    line-height: 1;
    display: inline-block;
    /* Flag-icons sizing */
    width: var(--ls-icon-base);
    height: var(--ls-icon-base);
}

.segment-code {
    font-family: 'SF Pro Text', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* ===== SIMPLE SEGMENTED CONTROL - MODERN & CLEAN ===== */
.language-segmented-simple {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px;
    background: #f1f5f9;
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.segment-simple-item {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    background: transparent;
    border: none;
    border-radius: 8px;
    color: #64748b;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    user-select: none;
}

.segment-simple-item:hover:not(.active) {
    background: rgba(255, 255, 255, 0.5);
    color: #475569;
}

.segment-simple-item.active {
    background: white;
    color: #3b82f6;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1), 0 1px 3px rgba(0, 0, 0, 0.06);
}

.segment-simple-item:active {
    transform: scale(0.97);
}

.segment-simple-item .fi {
    font-size: 18px;
    line-height: 1;
}

.segment-simple-item:focus-visible {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
}

/* ===== iOS-STYLE SEGMENTED CONTROL WITH SLIDING PILL ===== */
.language-segmented-ios {
    position: relative;
    display: inline-flex;
    align-items: center;
    padding: 2px;
    background: rgba(0, 0, 0, 0.06);
    border-radius: 10px;
    opacity: 0;
    transition: none;
}

.language-segmented-ios[data-ready="true"] {
    opacity: 1;
    transition: opacity 0.15s ease;
}

.segment-pill {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 80px;
    height: calc(100% - 4px);
    background: white;
    border-radius: 8px;
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.12), 0 1px 1px rgba(0, 0, 0, 0.04);
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1), width 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: none;
    z-index: 0;
    opacity: 0;
}

.segment-pill.positioned {
    opacity: 1;
}

.segment-ios-item {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 16px;
    background: transparent;
    border: none;
    color: rgba(0, 0, 0, 0.5);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: color 0.2s ease;
    white-space: nowrap;
    user-select: none;
    z-index: 1;
    min-width: 70px;
}

.segment-ios-item:hover {
    color: rgba(0, 0, 0, 0.7);
}

.segment-ios-item.active {
    color: rgba(0, 0, 0, 0.9);
}

.segment-ios-item .fi {
    font-size: 16px;
    line-height: 1;
}

.segment-ios-item:focus-visible {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
    border-radius: 8px;
}
    letter-spacing: 0.025em;
    font-weight: var(--ls-font-weight-medium);
}

/* ===== RESPONSIVE BREAKPOINTS ===== */
@media (max-width: 640px) {
    .language-button,
    .language-segmented-control {
        display: none;
    }
}

@media (min-width: 641px) {
    .language-button-mobile {
        display: none;
    }
}

/* ===== ACCESSIBILITY ===== */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .language-button,
    .language-item,
    .mobile-language-item,
    .segment-item {
        border: 1px solid currentColor;
    }

    .segment-slider {
        outline: 2px solid currentColor;
    }
}

/* ===== DARK MODE SUPPORT ===== */
@media (prefers-color-scheme: dark) {
    :root {
        --ls-bg-white: #1f2937;
        --ls-text-primary: #f9fafb;
        --ls-text-secondary: #9ca3af;
        --ls-border: #374151;
        --ls-border-hover: #4b5563;
        --ls-gray-50: #111827;
        --ls-gray-100: #1f2937;
        --ls-gray-200: #374151;
        --ls-gray-300: #4b5563;
        --ls-gray-400: #6b7280;
        --ls-gray-500: #9ca3af;
        --ls-gray-600: #d1d5db;
        --ls-gray-700: #d1d5db;
        --ls-gray-800: #e5e7eb;
        --ls-gray-900: #f3f4f6;
        --ls-primary-light: #1e3a8a;
        --ls-shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -1px rgba(0, 0, 0, 0.2);
        --ls-shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.3), 0 4px 6px -2px rgba(0, 0, 0, 0.2);
        --ls-shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.3), 0 10px 10px -5px rgba(0, 0, 0, 0.2);
    }

    /* Dark mode specific adjustments */
    .language-dropdown,
    .language-modal,
    .mobile-sheet {
        border-color: var(--ls-gray-600);
    }

    .language-modal-overlay {
        background: rgba(0, 0, 0, 0.7);
    }

    .mobile-backdrop {
        background: rgba(0, 0, 0, 0.6);
    }

    .language-segmented-ios {
        background: rgba(255, 255, 255, 0.08);
    }

    .segment-pill {
        background: rgba(255, 255, 255, 0.15);
    }

    .segment-ios-item {
        color: rgba(255, 255, 255, 0.6);
    }

    .segment-ios-item:hover {
        color: rgba(255, 255, 255, 0.8);
    }

    .segment-ios-item.active {
        color: rgba(255, 255, 255, 0.95);
    }
}

/* Manual dark mode class support (for frameworks that don't use prefers-color-scheme) */
.dark .language-switcher-minimal,
[data-theme="dark"] .language-switcher-minimal {
    --ls-bg-white: #1f2937;
    --ls-text-primary: #f9fafb;
    --ls-text-secondary: #9ca3af;
    --ls-border: #374151;
    --ls-border-hover: #4b5563;
    --ls-gray-50: #111827;
    --ls-gray-100: #1f2937;
    --ls-gray-200: #374151;
    --ls-gray-300: #4b5563;
    --ls-gray-400: #6b7280;
    --ls-gray-500: #9ca3af;
    --ls-gray-600: #d1d5db;
    --ls-gray-700: #d1d5db;
    --ls-primary-light: #1e3a8a;
}

.dark .language-dropdown,
.dark .language-modal,
.dark .mobile-sheet,
[data-theme="dark"] .language-dropdown,
[data-theme="dark"] .language-modal,
[data-theme="dark"] .mobile-sheet {
    border-color: #4b5563;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.4), 0 10px 10px -5px rgba(0, 0, 0, 0.3);
}

.dark .language-modal-overlay,
[data-theme="dark"] .language-modal-overlay {
    background: rgba(0, 0, 0, 0.7);
}

.dark .mobile-backdrop,
[data-theme="dark"] .mobile-backdrop {
    background: rgba(0, 0, 0, 0.6);
}

.dark .language-segmented-ios,
[data-theme="dark"] .language-segmented-ios {
    background: rgba(255, 255, 255, 0.08);
}

.dark .segment-pill,
[data-theme="dark"] .segment-pill {
    background: rgba(255, 255, 255, 0.15);
}

.dark .segment-ios-item,
[data-theme="dark"] .segment-ios-item {
    color: rgba(255, 255, 255, 0.6);
}

.dark .segment-ios-item:hover,
[data-theme="dark"] .segment-ios-item:hover {
    color: rgba(255, 255, 255, 0.8);
}

.dark .segment-ios-item.active,
[data-theme="dark"] .segment-ios-item.active {
    color: rgba(255, 255, 255, 0.95);
}

/* ============================================
   PATTERN B: GRID MODAL
   Full-screen modal with language grid layout
   ============================================ */

/* Modal Overlay (Backdrop) */
.language-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: var(--ls-z-modal-backdrop);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--ls-space-4);
    animation: fadeIn var(--ls-transition-base);
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Modal Container */
.language-modal {
    background: var(--ls-bg-white);
    border-radius: var(--ls-radius-xl);
    box-shadow: var(--ls-shadow-xl);
    max-width: 56rem; /* 896px */
    max-height: 90vh;
    width: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: slideUp var(--ls-transition-smooth);
    z-index: var(--ls-z-modal);
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Modal Header */
.language-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--ls-space-5) var(--ls-space-6);
    border-bottom: 1px solid var(--ls-border);
}

.language-modal-title {
    font-size: var(--ls-font-size-lg);
    font-weight: var(--ls-font-weight-bold);
    color: var(--ls-text-primary);
    display: flex;
    align-items: center;
    gap: var(--ls-space-3);
    margin: 0;
}

.language-modal-title i {
    color: var(--ls-primary);
    font-size: 1.5rem;
}

.language-modal-close {
    width: 2.5rem;
    height: 2.5rem;
    border-radius: var(--ls-radius-md);
    border: none;
    background: transparent;
    color: var(--ls-gray-500);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--ls-transition-fast);
}

.language-modal-close:hover {
    background: var(--ls-gray-100);
    color: var(--ls-gray-700);
}

.language-modal-close svg {
    width: 1.25rem;
    height: 1.25rem;
}

/* Modal Search */
.language-modal-search {
    display: flex;
    align-items: center;
    gap: var(--ls-space-3);
    padding: var(--ls-space-4) var(--ls-space-6);
    border-bottom: 1px solid var(--ls-border);
    background: var(--ls-gray-50);
}

.language-modal-search i {
    color: var(--ls-gray-400);
    font-size: var(--ls-icon-base);
}

.language-modal-search-input {
    flex: 1;
    padding: var(--ls-space-2) 0;
    border: none;
    background: transparent;
    font-size: var(--ls-font-size-base);
    color: var(--ls-text-primary);
    outline: none;
}

.language-modal-search-input::placeholder {
    color: var(--ls-gray-400);
}

/* Language Grid */
.language-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr));
    gap: var(--ls-space-3);
    padding: var(--ls-space-6);
    overflow-y: auto;
    max-height: calc(90vh - 12rem);
}

/* Language Card */
.language-card {
    display: flex;
    align-items: center;
    gap: var(--ls-space-3);
    padding: var(--ls-space-4);
    border: 1px solid var(--ls-border);
    border-radius: var(--ls-radius-md);
    background: var(--ls-bg-white);
    cursor: pointer;
    transition: all var(--ls-transition-fast);
    position: relative;
    min-height: var(--ls-touch-target);
}

.language-card:hover {
    border-color: var(--ls-primary);
    background: var(--ls-primary-light);
    transform: translateY(-1px);
    box-shadow: var(--ls-shadow-md);
}

.language-card.active {
    border-color: var(--ls-primary);
    background: var(--ls-primary-light);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.language-card-flag {
    width: 2rem;
    height: 2rem;
    flex-shrink: 0;
    border-radius: var(--ls-radius-sm);
}

.language-card-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.language-card-native {
    font-size: var(--ls-font-size-base);
    font-weight: var(--ls-font-weight-medium);
    color: var(--ls-text-primary);
}

.language-card-english {
    font-size: var(--ls-font-size-sm);
    color: var(--ls-text-secondary);
}

.language-card-check {
    width: var(--ls-icon-base);
    height: var(--ls-icon-base);
    color: var(--ls-primary);
    flex-shrink: 0;
}

/* Responsive Grid */
@media (max-width: 48rem) {
    .language-grid {
        grid-template-columns: repeat(auto-fill, minmax(10rem, 1fr));
        padding: var(--ls-space-4);
    }

    .language-modal {
        max-width: 100%;
        max-height: 100vh;
        border-radius: 0;
    }
}

/* ============================================
   PATTERN C: HYBRID MODE
   Pills for primary languages + dropdown for overflow
   ============================================ */

.language-hybrid-container {
    position: relative;
    display: inline-flex;
    align-items: center;
}

/* Language Pills Container */
.language-pills {
    display: flex;
    align-items: center;
    gap: var(--ls-space-2);
    flex-wrap: wrap;
}

/* Individual Language Pill */
.language-pill {
    display: inline-flex;
    align-items: center;
    gap: var(--ls-space-2);
    padding: var(--ls-space-2) var(--ls-space-4);
    border: 1px solid var(--ls-border);
    border-radius: var(--ls-radius-2xl); /* Pill shape */
    background: var(--ls-bg-white);
    color: var(--ls-text-primary);
    font-size: var(--ls-font-size-base);
    font-weight: var(--ls-font-weight-medium);
    cursor: pointer;
    transition: all var(--ls-transition-fast);
    white-space: nowrap;
    min-height: var(--ls-touch-target-sm);
}

.language-pill:hover {
    border-color: var(--ls-primary);
    background: var(--ls-primary-light);
    transform: translateY(-1px);
}

.language-pill.active {
    background: var(--ls-primary);
    color: white;
    border-color: var(--ls-primary);
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.25);
}

.language-pill.active .pill-flag {
    filter: brightness(1.2);
}

/* Pill Flag */
.pill-flag {
    width: var(--ls-icon-base);
    height: var(--ls-icon-base);
    border-radius: var(--ls-radius-sm);
}

.pill-text {
    line-height: 1;
}

/* More Languages Pill */
.language-pill-more {
    background: var(--ls-gray-100);
    border-color: var(--ls-border);
    color: var(--ls-gray-700);
}

.language-pill-more:hover {
    background: var(--ls-gray-200);
    transform: translateY(-1px);
}

.language-pill-more i {
    font-size: var(--ls-icon-base);
}

/* Hybrid Dropdown (positioned relative to pill container) */
.language-dropdown-hybrid {
    position: absolute;
    top: calc(100% + var(--ls-space-2));
    right: 0;
    min-width: 16rem;
}

/* Button Style Variants */
.language-button-pill {
    display: inline-flex;
    align-items: center;
    gap: var(--ls-space-2);
    padding: var(--ls-space-2) var(--ls-space-4);
    border: 1px solid var(--ls-border);
    border-radius: var(--ls-radius-2xl);
    background: var(--ls-bg-white);
    color: var(--ls-text-primary);
    font-size: var(--ls-font-size-base);
    font-weight: var(--ls-font-weight-medium);
    cursor: pointer;
    transition: all var(--ls-transition-fast);
}

.language-button-pill:hover {
    border-color: var(--ls-primary);
    background: var(--ls-primary-light);
}

.language-button-minimal {
    display: inline-flex;
    align-items: center;
    gap: var(--ls-space-2);
    padding: var(--ls-space-2);
    border: none;
    background: transparent;
    color: var(--ls-text-primary);
    font-size: var(--ls-font-size-base);
    cursor: pointer;
    transition: all var(--ls-transition-fast);
}

.language-button-minimal:hover {
    background: var(--ls-gray-100);
    border-radius: var(--ls-radius-md);
}

.language-button-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.5rem;
    height: 2.5rem;
    border: 1px solid var(--ls-border);
    border-radius: var(--ls-radius-md);
    background: var(--ls-bg-white);
    color: var(--ls-text-primary);
    cursor: pointer;
    transition: all var(--ls-transition-fast);
}

.language-button-icon:hover {
    border-color: var(--ls-primary);
    background: var(--ls-primary-light);
}

/* Outline Button Style */
.language-button-outline {
    display: inline-flex;
    align-items: center;
    gap: var(--ls-space-2);
    padding: var(--ls-space-2) var(--ls-space-3);
    min-height: var(--ls-touch-target-sm);
    background: transparent;
    border: 2px solid var(--ls-gray-400);
    border-radius: var(--ls-radius-md);
    color: var(--ls-text-primary);
    font-size: var(--ls-font-size-base);
    font-weight: var(--ls-font-weight-medium);
    cursor: pointer;
    transition: all var(--ls-transition-base);
}

.language-button-outline:hover {
    border-color: var(--ls-primary);
    color: var(--ls-primary);
    background: var(--ls-primary-light);
}

.language-button-outline:focus {
    outline: none;
    border-color: var(--ls-border-focus);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

/* Ghost Button Style */
.language-button-ghost {
    display: inline-flex;
    align-items: center;
    gap: var(--ls-space-2);
    padding: var(--ls-space-2) var(--ls-space-3);
    min-height: var(--ls-touch-target-sm);
    background: transparent;
    border: none;
    border-radius: var(--ls-radius-md);
    color: var(--ls-gray-600);
    font-size: var(--ls-font-size-base);
    font-weight: var(--ls-font-weight-normal);
    cursor: pointer;
    transition: all var(--ls-transition-base);
}

.language-button-ghost:hover {
    background: var(--ls-gray-100);
    color: var(--ls-text-primary);
}

.language-button-ghost:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

/* ===== BUTTON SIZE VARIANTS ===== */

/* Small Button */
.language-button-sm,
.language-button-pill.language-button-sm,
.language-button-minimal.language-button-sm,
.language-button-outline.language-button-sm,
.language-button-ghost.language-button-sm {
    min-height: 36px;
    padding: var(--ls-space-1) var(--ls-space-2);
    font-size: var(--ls-font-size-sm);
    gap: var(--ls-space-1);
}

.language-button-icon.language-button-sm {
    width: 2rem;
    height: 2rem;
}

.language-button-sm .language-icon,
.language-button-sm .language-flag {
    font-size: 0.875rem;
    width: 0.875rem;
    height: 0.875rem;
}

.language-button-sm .chevron {
    width: 0.75rem;
    height: 0.75rem;
}

/* Large Button */
.language-button-lg,
.language-button-pill.language-button-lg,
.language-button-minimal.language-button-lg,
.language-button-outline.language-button-lg,
.language-button-ghost.language-button-lg {
    min-height: 52px;
    padding: var(--ls-space-3) var(--ls-space-5);
    font-size: var(--ls-font-size-md);
    gap: var(--ls-space-3);
}

.language-button-icon.language-button-lg {
    width: 3rem;
    height: 3rem;
}

.language-button-lg .language-icon,
.language-button-lg .language-flag {
    font-size: 1.25rem;
    width: 1.25rem;
    height: 1.25rem;
}

.language-button-lg .language-name {
    font-size: var(--ls-font-size-md);
}

.language-button-lg .chevron {
    width: 1.25rem;
    height: 1.25rem;
}

/* Mobile Responsive Adjustments for New Patterns */
@media (max-width: 48rem) {
    .language-pills {
        width: 100%;
        justify-content: center;
    }

    .language-hybrid-container {
        width: 100%;
    }

    .language-dropdown-hybrid {
        right: auto;
        left: 50%;
        transform: translateX(-50%);
    }
}

/* ============================================
   RTL (RIGHT-TO-LEFT) LANGUAGE SUPPORT
   Proper layout for Arabic, Hebrew, Persian, etc.
   ============================================ */

/* RTL Layout Base - Applied via dir="rtl" */
[dir="rtl"] {
    text-align: right;
}

/* Dropdown positioning for RTL */
[dir="rtl"].language-dropdown,
.rtl-layout.language-dropdown {
    left: auto;
    right: 0;
}

/* Flip flex items for RTL */
[dir="rtl"] .language-item,
[dir="rtl"] .mobile-language-item,
.rtl-layout .language-item,
.rtl-layout .mobile-language-item {
    flex-direction: row-reverse;
    text-align: right;
}

/* Flip hover transform for RTL */
[dir="rtl"] .language-item:hover,
.rtl-layout .language-item:hover {
    transform: translateX(-2px);
}

/* RTL Modal header */
[dir="rtl"] .language-modal-header,
[dir="rtl"] .mobile-sheet-header,
.rtl-layout .language-modal-header,
.rtl-layout .mobile-sheet-header {
    flex-direction: row-reverse;
}

/* RTL Modal title icon positioning */
[dir="rtl"] .language-modal-title,
.rtl-layout .language-modal-title {
    flex-direction: row-reverse;
}

/* RTL Search input alignment */
[dir="rtl"] .language-search-input,
[dir="rtl"] .mobile-search-input,
[dir="rtl"] .language-modal-search-input,
.rtl-layout .language-search-input,
.rtl-layout .mobile-search-input,
.rtl-layout .language-modal-search-input {
    text-align: right;
    direction: rtl;
}

/* RTL Search container */
[dir="rtl"] .language-modal-search,
.rtl-layout .language-modal-search {
    flex-direction: row-reverse;
}

/* RTL Language card layout */
[dir="rtl"] .language-card,
.rtl-layout .language-card {
    flex-direction: row-reverse;
}

/* RTL Language card info */
[dir="rtl"] .language-card-info,
[dir="rtl"] .mobile-language-info,
.rtl-layout .language-card-info,
.rtl-layout .mobile-language-info {
    align-items: flex-end;
    text-align: right;
}

/* RTL Chevron flip */
[dir="rtl"] .chevron,
.rtl-layout .chevron {
    transform: scaleX(-1);
}

[dir="rtl"] .chevron.rotate,
.rtl-layout .chevron.rotate {
    transform: scaleX(-1) rotate(180deg);
}

/* RTL Hybrid pills */
[dir="rtl"] .language-pills,
.rtl-layout .language-pills {
    flex-direction: row-reverse;
}

/* RTL Hybrid dropdown positioning */
[dir="rtl"] .language-dropdown-hybrid,
.rtl-layout .language-dropdown-hybrid {
    right: auto;
    left: 0;
}

/* RTL Mobile sheet close button */
[dir="rtl"] .mobile-sheet-close,
.rtl-layout .mobile-sheet-close {
    order: -1;
}

/* Individual RTL language names need proper alignment */
.language-item .language-text[dir="rtl"],
.mobile-language-item .mobile-language-name[dir="rtl"] {
    text-align: right;
    direction: rtl;
}

/* ============================================
   SUGGESTION BANNER
   Auto-detect language suggestion UI
   ============================================ */

.language-suggestion-banner {
    display: flex;
    align-items: center;
    gap: var(--ls-space-3);
    padding: var(--ls-space-3) var(--ls-space-4);
    background: linear-gradient(135deg, var(--ls-primary-light) 0%, rgba(59, 130, 246, 0.1) 100%);
    border: 1px solid rgba(59, 130, 246, 0.2);
    border-radius: var(--ls-radius-lg);
    margin-bottom: var(--ls-space-3);
    animation: slideDown 0.3s ease-out;
}

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

.language-suggestion-icon {
    flex-shrink: 0;
    width: 2rem;
    height: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--ls-primary);
    color: white;
    border-radius: var(--ls-radius-md);
    font-size: var(--ls-icon-base);
}

.language-suggestion-content {
    flex: 1;
    min-width: 0;
}

.language-suggestion-text {
    font-size: var(--ls-font-size-sm);
    color: var(--ls-text-primary);
    margin: 0;
}

.language-suggestion-text strong {
    color: var(--ls-primary-dark);
}

.language-suggestion-actions {
    display: flex;
    gap: var(--ls-space-2);
    flex-shrink: 0;
}

.language-suggestion-accept {
    padding: var(--ls-space-1) var(--ls-space-3);
    background: var(--ls-primary);
    color: white;
    border: none;
    border-radius: var(--ls-radius-md);
    font-size: var(--ls-font-size-sm);
    font-weight: var(--ls-font-weight-medium);
    cursor: pointer;
    transition: all var(--ls-transition-fast);
}

.language-suggestion-accept:hover {
    background: var(--ls-primary-hover);
    transform: translateY(-1px);
}

.language-suggestion-dismiss {
    padding: var(--ls-space-1);
    background: transparent;
    border: none;
    color: var(--ls-gray-500);
    cursor: pointer;
    border-radius: var(--ls-radius-sm);
    transition: all var(--ls-transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
}

.language-suggestion-dismiss:hover {
    background: var(--ls-gray-200);
    color: var(--ls-gray-700);
}

.language-suggestion-dismiss svg {
    width: 1rem;
    height: 1rem;
}

/* Mobile suggestion banner */
@media (max-width: 640px) {
    .language-suggestion-banner {
        flex-wrap: wrap;
        padding: var(--ls-space-3);
    }

    .language-suggestion-content {
        width: 100%;
        order: 2;
        margin-top: var(--ls-space-2);
    }

    .language-suggestion-icon {
        order: 1;
    }

    .language-suggestion-actions {
        order: 3;
        width: 100%;
        margin-top: var(--ls-space-2);
    }

    .language-suggestion-accept {
        flex: 1;
    }
}

/* ============================================
   RECENT LANGUAGES SECTION
   Shows recently used languages at top of list
   ============================================ */

.language-recent-section {
    padding: var(--ls-space-2) var(--ls-space-3);
    border-bottom: 1px solid var(--ls-gray-100);
}

.language-recent-header {
    display: flex;
    align-items: center;
    gap: var(--ls-space-2);
    margin-bottom: var(--ls-space-2);
}

.language-recent-icon {
    font-size: var(--ls-font-size-sm);
    color: var(--ls-gray-400);
}

.language-recent-title {
    font-size: var(--ls-font-size-sm);
    font-weight: var(--ls-font-weight-medium);
    color: var(--ls-gray-500);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.language-recent-list {
    display: flex;
    flex-wrap: wrap;
    gap: var(--ls-space-2);
}

.language-recent-item {
    display: inline-flex;
    align-items: center;
    gap: var(--ls-space-2);
    padding: var(--ls-space-1) var(--ls-space-2);
    background: var(--ls-gray-50);
    border: 1px solid var(--ls-gray-200);
    border-radius: var(--ls-radius-2xl);
    font-size: var(--ls-font-size-sm);
    color: var(--ls-text-primary);
    cursor: pointer;
    transition: all var(--ls-transition-fast);
}

.language-recent-item:hover {
    background: var(--ls-primary-light);
    border-color: var(--ls-primary);
    color: var(--ls-primary-dark);
}

.language-recent-item.active {
    background: var(--ls-primary);
    border-color: var(--ls-primary);
    color: white;
}

.language-recent-item .fi {
    font-size: 1rem;
}

/* ============================================
   FULL-SCREEN MOBILE PICKER OPTION
   For when you want the picker to take full screen
   ============================================ */

.mobile-sheet.full-screen {
    max-height: 100vh;
    height: 100vh;
    border-radius: 0;
    padding-top: env(safe-area-inset-top, 0);
}

.mobile-sheet.full-screen .mobile-sheet-handle {
    display: none;
}

.mobile-sheet.full-screen .mobile-sheet-header {
    padding-top: var(--ls-space-5);
}

.mobile-sheet.full-screen .mobile-sheet-content {
    max-height: none;
}

/* ============================================
   IMPROVED MOBILE SHEET TRANSITIONS
   Smoother animations for mobile
   ============================================ */

.mobile-sheet {
    /* Add will-change for smoother animations */
    will-change: transform;
    /* Improve touch response */
    touch-action: pan-y;
}

.mobile-backdrop {
    will-change: opacity;
    transition: opacity 0.3s ease;
}

/* Closing animation */
.mobile-sheet-container.closing .mobile-sheet {
    animation: slideDown 0.2s ease-out forwards;
}

.mobile-sheet-container.closing .mobile-backdrop {
    animation: fadeOut 0.2s ease-out forwards;
}

@keyframes fadeOut {
    from { opacity: 1; }
    to { opacity: 0; }
}

/* ============================================
   HAPTIC FEEDBACK VISUAL CUE
   Visual feedback when haptic is triggered
   ============================================ */

.language-item.haptic-feedback,
.mobile-language-item.haptic-feedback,
.segment-ios-item.haptic-feedback {
    animation: hapticPulse 0.15s ease-out;
}

@keyframes hapticPulse {
    0% { transform: scale(1); }
    50% { transform: scale(0.97); }
    100% { transform: scale(1); }
}
