/**
 * AllTurko Modern Language Switcher
 * A sleek, animated language toggle with professional micro-interactions
 * Version: 3.0
 */

/* ========================================
   CSS Custom Properties (Theme Variables)
   ======================================== */
:root {
    --lang-primary: #CB0000;
    --lang-primary-rgb: 203, 0, 0;
    --lang-dark: #1e1e1e;
    --lang-light: #ffffff;
    --lang-gray: #6b7280;
    --lang-border: rgba(0, 0, 0, 0.08);
    --lang-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
    --lang-shadow-hover: 0 8px 30px rgba(0, 0, 0, 0.12);
    --lang-transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    --lang-transition-fast: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    --lang-backdrop: rgba(255, 255, 255, 0.95);
}

/* ========================================
   Language Switcher Container
   ======================================== */
.mil-lang-switcher {
    position: relative;
    display: flex;
    align-items: center;
    background: var(--lang-backdrop);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: 50px;
    padding: 4px;
    gap: 0;
    box-shadow: var(--lang-shadow);
    border: 1px solid var(--lang-border);
    z-index: 9999;
    pointer-events: auto;
    overflow: hidden;
}

/* Animated sliding background indicator */
.mil-lang-switcher::before {
    content: '';
    position: absolute;
    top: 4px;
    left: 4px;
    width: calc(50% - 4px);
    height: calc(100% - 8px);
    background: linear-gradient(135deg, var(--lang-primary) 0%, #a00000 100%);
    border-radius: 50px;
    transition: transform 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    z-index: 1;
    box-shadow: 0 2px 10px rgba(var(--lang-primary-rgb), 0.4);
}

/* Slide indicator to right when second language is active */
.mil-lang-switcher[data-active="en"]::before,
.mil-lang-switcher:has(.mil-lang-btn:last-child.active)::before {
    transform: translateX(100%);
}

/* ========================================
   Language Button
   ======================================== */
.mil-lang-btn {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 12px;
    min-width: 60px;
    border-radius: 50px;
    text-decoration: none !important;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--lang-dark);
    background: transparent;
    border: none;
    cursor: pointer;
    transition: var(--lang-transition-fast);
    z-index: 2;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

/* Active state - white text on red background */
.mil-lang-btn.active {
    color: var(--lang-light);
}

.mil-lang-btn.active .mil-lang-code {
    color: var(--lang-light);
}

/* Hover state for inactive buttons */
.mil-lang-btn:not(.active):hover {
    background: rgba(var(--lang-primary-rgb), 0.08);
}

.mil-lang-btn:not(.active):hover .mil-lang-code {
    color: var(--lang-primary);
}

/* ========================================
   Flag Icon
   ======================================== */
.mil-lang-flag {
    width: 18px;
    height: 13px;
    border-radius: 2px;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
    flex-shrink: 0;
    transition: var(--lang-transition-fast);
    position: relative;
}

.mil-lang-flag img,
.mil-lang-flag svg {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: cover;
}

/* Flag hover animation */
.mil-lang-btn:hover .mil-lang-flag {
    transform: scale(1.1) rotate(-2deg);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

/* Active flag glow effect */
.mil-lang-btn.active .mil-lang-flag {
    box-shadow: 0 2px 10px rgba(255, 255, 255, 0.3);
}

/* ========================================
   Language Code Text
   ======================================== */
.mil-lang-code {
    font-family: 'Outfit', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-weight: 700;
    font-size: 10px;
    letter-spacing: 0.8px;
    transition: var(--lang-transition-fast);
    color: var(--lang-dark);
}

/* ========================================
   Frame Top Positioning
   ======================================== */
.mil-frame-top {
    position: relative;
}

.mil-frame-top .mil-lang-switcher {
    position: absolute;
    right: 90px;
    top: 50%;
    transform: translateY(-50%);
}

/* Entrance animation */
.mil-frame .mil-frame-top .mil-lang-switcher {
    animation: langSwitcherEntrance 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) 0.5s both;
}

@keyframes langSwitcherEntrance {
    from {
        opacity: 0;
        transform: translateY(-50%) scale(0.8);
    }
    to {
        opacity: 1;
        transform: translateY(-50%) scale(1);
    }
}

/* ========================================
   Hide Language Switcher in Menu Overlay
   ======================================== */
.mil-menu-frame .mil-lang-switcher {
    display: none !important;
}

/* ========================================
   Hover Effects & Micro-interactions
   ======================================== */

/* Container glow on hover */
.mil-lang-switcher:hover {
    box-shadow: var(--lang-shadow-hover);
    border-color: rgba(var(--lang-primary-rgb), 0.15);
}

/* Ripple effect on click */
.mil-lang-btn::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    background: rgba(var(--lang-primary-rgb), 0.3);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    transition: width 0.4s ease, height 0.4s ease, opacity 0.4s ease;
    opacity: 0;
    z-index: -1;
}

.mil-lang-btn:active::after {
    width: 120px;
    height: 120px;
    opacity: 0;
    transition: 0s;
}

/* ========================================
   Loading State Animation
   ======================================== */
.mil-lang-btn.loading {
    pointer-events: none;
}

.mil-lang-btn.loading .mil-lang-flag {
    animation: flagPulse 0.8s ease-in-out infinite;
}

@keyframes flagPulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(0.95); opacity: 0.7; }
}

/* ========================================
   Tooltip on Hover (Optional)
   ======================================== */
.mil-lang-btn[data-tooltip]::before {
    content: attr(data-tooltip);
    position: absolute;
    bottom: calc(100% + 12px);
    left: 50%;
    transform: translateX(-50%) translateY(5px);
    padding: 6px 12px;
    background: var(--lang-dark);
    color: var(--lang-light);
    font-size: 11px;
    font-weight: 500;
    letter-spacing: 0.5px;
    border-radius: 6px;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: var(--lang-transition-fast);
    z-index: 10;
}

.mil-lang-btn[data-tooltip]:hover::before {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
}

/* Tooltip arrow */
.mil-lang-btn[data-tooltip]::after {
    content: '';
    position: absolute;
    bottom: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-top-color: var(--lang-dark);
    opacity: 0;
    visibility: hidden;
    transition: var(--lang-transition-fast);
    z-index: 10;
}

/* ========================================
   Responsive Design - Large Desktop
   ======================================== */
@media (min-width: 1201px) {
    .mil-frame-top .mil-lang-switcher {
        right: 90px;
    }
}

/* ========================================
   Responsive Design - Desktop/Tablet
   ======================================== */
@media (max-width: 1200px) {
    .mil-frame-top .mil-lang-switcher {
        right: 80px;
    }

    .mil-lang-switcher {
        padding: 3px;
    }

    .mil-lang-btn {
        padding: 6px 10px;
        min-width: 55px;
        gap: 5px;
    }

    .mil-lang-flag {
        width: 18px;
        height: 13px;
    }

    .mil-lang-code {
        font-size: 10px;
        letter-spacing: 0.5px;
    }
}

/* ========================================
   Responsive Design - Tablet
   ======================================== */
@media (max-width: 992px) {
    .mil-frame-top .mil-lang-switcher {
        right: 70px;
    }
}

/* ========================================
   Responsive Design - Mobile
   ======================================== */
@media (max-width: 768px) {
    .mil-frame-top .mil-lang-switcher {
        right: 60px;
    }

    .mil-lang-switcher {
        padding: 2px;
        border-radius: 30px;
    }

    .mil-lang-switcher::before {
        top: 2px;
        left: 2px;
        height: calc(100% - 4px);
        width: calc(50% - 2px);
        border-radius: 30px;
    }

    .mil-lang-btn {
        padding: 6px 8px;
        min-width: auto;
        gap: 0;
    }

    /* Hide text on mobile, show only flags */
    .mil-lang-code {
        display: none;
    }

    .mil-lang-flag {
        width: 20px;
        height: 14px;
        border-radius: 3px;
    }
}

/* ========================================
   Responsive Design - Small Mobile
   ======================================== */
@media (max-width: 480px) {
    .mil-frame-top .mil-lang-switcher {
        right: 55px;
    }

    .mil-lang-switcher {
        padding: 2px;
    }

    .mil-lang-switcher::before {
        top: 2px;
        left: 2px;
        height: calc(100% - 4px);
        width: calc(50% - 2px);
    }

    .mil-lang-btn {
        padding: 5px 7px;
    }

    .mil-lang-flag {
        width: 18px;
        height: 13px;
    }
}

/* ========================================
   Accessibility
   ======================================== */
.mil-lang-btn:focus {
    outline: none;
}

.mil-lang-btn:focus-visible {
    outline: 2px solid var(--lang-primary);
    outline-offset: 3px;
}

/* Screen reader only text */
.mil-lang-sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Reduced motion preference */
@media (prefers-reduced-motion: reduce) {
    .mil-lang-switcher,
    .mil-lang-switcher::before,
    .mil-lang-btn,
    .mil-lang-flag,
    .mil-lang-code {
        transition: none;
        animation: none;
    }
}

/* ========================================
   High Contrast Mode
   ======================================== */
@media (prefers-contrast: high) {
    .mil-lang-switcher {
        border-width: 2px;
        border-color: var(--lang-dark);
    }

    .mil-lang-btn.active {
        outline: 2px solid var(--lang-light);
        outline-offset: -2px;
    }
}

/* ========================================
   Print Styles
   ======================================== */
@media print {
    .mil-lang-switcher {
        display: none !important;
    }
}

/* ========================================
   Scrolled State (when header is sticky)
   ======================================== */
.mil-frame.mil-scrolled .mil-lang-switcher {
    box-shadow: 0 2px 15px rgba(0, 0, 0, 0.1);
}

/* ========================================
   Alternative Compact Mode
   For very tight spaces, add class .mil-lang-compact
   ======================================== */
.mil-lang-switcher.mil-lang-compact {
    padding: 2px;
}

.mil-lang-compact .mil-lang-btn {
    padding: 6px 10px;
    min-width: 50px;
    gap: 4px;
}

.mil-lang-compact .mil-lang-flag {
    width: 18px;
    height: 13px;
}

.mil-lang-compact .mil-lang-code {
    font-size: 10px;
}

/* ========================================
   Initial Loading State
   Shows a skeleton loader before JS initializes
   ======================================== */
.mil-lang-switcher:empty::after {
    content: '';
    display: flex;
    width: 110px;
    height: 30px;
    background: linear-gradient(90deg,
        rgba(0,0,0,0.04) 0%,
        rgba(0,0,0,0.08) 50%,
        rgba(0,0,0,0.04) 100%);
    background-size: 200% 100%;
    border-radius: 50px;
    animation: langSkeletonPulse 1.5s ease-in-out infinite;
}

@keyframes langSkeletonPulse {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.mil-menu-frame .mil-lang-switcher:empty::after {
    background: linear-gradient(90deg,
        rgba(255,255,255,0.05) 0%,
        rgba(255,255,255,0.1) 50%,
        rgba(255,255,255,0.05) 100%);
    background-size: 200% 100%;
}

@media (max-width: 768px) {
    .mil-lang-switcher:empty::after {
        width: 70px;
        height: 26px;
    }
}
