/* =================================
   ENHANCED TRANSLATE BUTTON STYLES
   ปรับให้เข้ากันกับ index page design
================================= */

/* Language Container - ปรับตำแหน่งให้อยู่ใน header */
.language-container {
    position: relative;
    display: flex;
    align-items: center;
    font-family: 'Arial', sans-serif;
    z-index: 1001; /* ต่ำกว่า modal แต่สูงกว่า header content */
}

/* Language Button - ใช้สไตล์เดียวกับ user-button */
.language-button {
    background: rgba(255, 255, 255, 0.9);
    color: #666;
    border: 1px solid rgba(0, 0, 0, 0.1);
    padding: 10px;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
    text-decoration: none;
    font-size: 1.2rem;
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    backdrop-filter: blur(10px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    margin-left: 0.5rem;
}

.language-button:hover {
    background: rgba(255, 140, 66, 0.1);
    border-color: rgba(255, 140, 66, 0.3);
    color: #ff8c42;
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(255, 140, 66, 0.15);
}

.language-button svg {
    width: 20px;
    height: 20px;
    transition: all 0.3s ease;
}

.language-button:hover svg {
    stroke: #ff8c42;
    transform: rotate(15deg);
}

/* Language Dropdown - ปรับให้เข้ากับ design system */
.language-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    background: white;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
    min-width: 140px;
    display: none;
    opacity: 0;
    transform: translateY(-10px) scale(0.95);
    transition: all 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    border: 1px solid rgba(0, 0, 0, 0.05);
    backdrop-filter: blur(20px);
    overflow: hidden;
    z-index: 1002;
}

.language-dropdown.show {
    display: block;
    opacity: 1;
    transform: translateY(0) scale(1);
}

.language-dropdown::before {
    content: '';
    position: absolute;
    top: -6px;
    right: 20px;
    width: 12px;
    height: 12px;
    background: white;
    border: 1px solid rgba(0, 0, 0, 0.05);
    border-bottom: none;
    border-right: none;
    transform: rotate(45deg);
    z-index: -1;
}

/* Language Options */
.language-option {
    padding: 12px 16px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 14px;
    font-weight: 500;
    color: #333;
    display: flex;
    align-items: center;
    gap: 8px;
    position: relative;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

.language-option:last-child {
    border-bottom: none;
}

.language-option:hover {
    background: rgba(255, 140, 66, 0.08);
    color: #ff8c42;
    padding-left: 20px;
}

.language-option.current {
    background: rgba(255, 140, 66, 0.1);
    color: #ff8c42;
    font-weight: 600;
}

.language-option.current::after {
    content: '✓';
    position: absolute;
    right: 12px;
    color: #ff8c42;
    font-weight: bold;
}

/* Language Option Icons/Flags */
.language-option::before {
    content: '';
    width: 16px;
    height: 16px;
    border-radius: 2px;
    background-size: cover;
    background-position: center;
    flex-shrink: 0;
}

.language-option[data-lang="th"]::before {
    background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 3 2"><rect width="3" height="2" fill="%23ED1C24"/><rect width="3" height="1.5" y="0.25" fill="%23FFFFFF"/><rect width="3" height="1" y="0.5" fill="%23241D4C"/></svg>');
}

.language-option[data-lang="en"]::before {
    background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 60 30"><rect width="60" height="30" fill="%23012169"/><path d="M0,0 L60,30 M60,0 L0,30" stroke="%23FFFFFF" stroke-width="6"/><path d="M0,0 L60,30 M60,0 L0,30" stroke="%23C8102E" stroke-width="4"/><path d="M30,0 L30,30 M0,15 L60,15" stroke="%23FFFFFF" stroke-width="10"/><path d="M30,0 L30,30 M0,15 L60,15" stroke="%23C8102E" stroke-width="6"/></svg>');
}

.language-option[data-lang="lo"]::before {
    background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 3 2"><rect width="3" height="2" fill="%23CE1126"/><rect width="3" height="1" y="0.5" fill="%23002868"/><circle cx="1.5" cy="1" r="0.3" fill="%23FFFFFF"/></svg>');
}

.language-option[data-lang="km"]::before {
    background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 25 15"><rect width="25" height="15" fill="%23032EA1"/><rect width="25" height="5" y="2.5" fill="%23E4002B"/></svg>');
}

.language-option[data-lang="vi"]::before {
    background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 3 2"><rect width="3" height="2" fill="%23DA020E"/><polygon points="1.5,0.6 1.65,1 2,1 1.725,1.2 1.8,1.6 1.5,1.4 1.2,1.6 1.275,1.2 1,1 1.35,1" fill="%23FFFF00"/></svg>');
}

/* Hide Google Translate Elements */
.goog-te-banner-frame, 
.skiptranslate,
#google_translate_element {
    display: none !important;
}

body {
    top: 0 !important;
}

.goog-te-combo {
    display: none !important;
}

/* Loading State */
.language-button.loading {
    pointer-events: none;
    opacity: 0.7;
}

.language-button.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 16px;
    height: 16px;
    margin: -8px 0 0 -8px;
    border: 2px solid rgba(255, 140, 66, 0.3);
    border-top-color: #ff8c42;
    border-radius: 50%;
    animation: translateSpin 0.8s linear infinite;
}

@keyframes translateSpin {
    to { transform: rotate(360deg); }
}

/* Success Animation */
.language-button.success {
    animation: translateSuccess 0.6s ease;
}

@keyframes translateSuccess {
    0% { 
        background: rgba(255, 140, 66, 0.1);
        transform: scale(1); 
    }
    50% { 
        background: rgba(39, 174, 96, 0.2);
        transform: scale(1.1); 
    }
    100% { 
        background: rgba(255, 140, 66, 0.1);
        transform: scale(1); 
    }
}

/* Integration with Header */
.user-section .language-container {
    margin-left: 0.5rem;
}

/* Responsive Design */
@media (max-width: 768px) {
    .language-button {
        width: 44px;
        height: 44px;
        padding: 8px;
        margin-left: 0.3rem;
    }
    
    .language-button svg {
        width: 18px;
        height: 18px;
    }
    
    .language-dropdown {
        min-width: 120px;
        right: -10px;
    }
    
    .language-dropdown::before {
        right: 25px;
    }
    
    .language-option {
        padding: 10px 12px;
        font-size: 13px;
    }
    
    .language-option:hover {
        padding-left: 16px;
    }
}

@media (max-width: 480px) {
    .language-button {
        width: 40px;
        height: 40px;
        padding: 6px;
    }
    
    .language-button svg {
        width: 16px;
        height: 16px;
    }
    
    .language-dropdown {
        min-width: 110px;
        right: -15px;
    }
}

/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
    .language-button {
        background: rgba(45, 45, 45, 0.9);
        color: #e0e0e0;
        border-color: rgba(255, 255, 255, 0.1);
    }
    
    .language-button:hover {
        background: rgba(255, 140, 66, 0.2);
        border-color: rgba(255, 140, 66, 0.4);
    }
    
    .language-dropdown {
        background: #2d2d2d;
        border-color: rgba(255, 255, 255, 0.1);
    }
    
    .language-dropdown::before {
        background: #2d2d2d;
        border-color: rgba(255, 255, 255, 0.1);
    }
    
    .language-option {
        color: #e0e0e0;
        border-bottom-color: rgba(255, 255, 255, 0.05);
    }
    
    .language-option:hover {
        background: rgba(255, 140, 66, 0.15);
    }
}

/* High Contrast Mode */
@media (prefers-contrast: high) {
    .language-button {
        border: 2px solid #333;
    }
    
    .language-dropdown {
        border: 2px solid #333;
    }
    
    .language-option {
        border-bottom: 1px solid #333;
    }
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
    .language-button,
    .language-dropdown,
    .language-option {
        transition: none !important;
        animation: none !important;
    }
    
    .language-button:hover {
        transform: none;
    }
    
    .language-button:hover svg {
        transform: none;
    }
}

/* Print Styles */
@media print {
    .language-container {
        display: none !important;
    }
}

/* Focus States for Accessibility */
.language-button:focus {
    outline: 3px solid rgba(255, 140, 66, 0.5);
    outline-offset: 2px;
}

.language-option:focus {
    outline: 2px solid rgba(255, 140, 66, 0.5);
    outline-offset: -2px;
}

/* Hover Animation Enhancement */
.language-dropdown.show {
    animation: dropdownSlideIn 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

@keyframes dropdownSlideIn {
    0% {
        opacity: 0;
        transform: translateY(-15px) scale(0.9);
    }
    100% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Language Option Stagger Animation */
.language-dropdown.show .language-option {
    animation: optionSlideIn 0.4s ease forwards;
    opacity: 0;
}

.language-dropdown.show .language-option:nth-child(1) { animation-delay: 0.05s; }
.language-dropdown.show .language-option:nth-child(2) { animation-delay: 0.1s; }
.language-dropdown.show .language-option:nth-child(3) { animation-delay: 0.15s; }
.language-dropdown.show .language-option:nth-child(4) { animation-delay: 0.2s; }
.language-dropdown.show .language-option:nth-child(5) { animation-delay: 0.25s; }

@keyframes optionSlideIn {
    0% {
        opacity: 0;
        transform: translateX(-10px);
    }
    100% {
        opacity: 1;
        transform: translateX(0);
    }
}

/* =================================
   INTEGRATION HELPERS
================================= */

/* เมื่อใช้ใน header navigation */
.header .user-section .language-container {
    margin: 0;
}

/* เมื่อต้องการใช้เป็น fixed position (backup) */
.language-container.fixed {
    position: fixed;
    top: 100px; /* ให้อยู่ใต้ header */
    right: 20px;
    z-index: 1001;
}

/* Mobile Navigation Integration */
@media (max-width: 768px) {
    .nav-container {
        position: relative;
    }
    
    .user-section {
        gap: 0.3rem;
    }
}

/* =================================
   PERFORMANCE OPTIMIZATIONS
================================= */

/* GPU Acceleration */
.language-button,
.language-dropdown {
    will-change: transform, opacity;
    transform: translateZ(0);
}

/* Optimize repaints */
.language-option:hover {
    will-change: background-color, padding-left;
}

/* =================================
   UTILITIES
================================= */

/* Screen reader only */
.language-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;
}