/* Translation dropdown - FIXED VERSION */
.translation-dropdown {
    position: relative;
    display: inline-block;
}

.translation-popup {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    /* Use your CSS variables with explicit fallbacks */
    background: var(--page-background-color, #F9F8F5) !important;
    border: 1px solid var(--border-color);
    border-radius: var(--size-8);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    width: 180px;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px);
    transition: all 0.25s ease;
    z-index: 999999;
    /* Ensure the popup covers everything behind it */
    isolation: isolate;
}

/* Dark theme override */
[data-theme="dark"] .translation-popup {
    background: var(--page-background-color, #1F1F1F) !important;
    border-color: var(--border-color, #3C3B39);
}

.translation-popup.active {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.translation-popup::before {
    content: '';
    position: absolute;
    top: -6px;
    right: 16px;
    width: 12px;
    height: 12px;
    /* Match the background with fallbacks */
    background: var(--page-background-color, #F9F8F5) !important;
    border: 1px solid var(--border-color);
    border-bottom: none;
    border-right: none;
    border-top-left-radius: 2px; /* Add rounded corner to match dropdown */
    transform: rotate(45deg);
    z-index: 1;
}

/* Dark theme arrow */
[data-theme="dark"] .translation-popup::before {
    background: var(--page-background-color, #1F1F1F) !important;
    border-color: var(--border-color, #3C3B39);
}

.language-list {
    list-style: none;
    margin: 0;
    padding: 0.5rem 0;
    /* Ensure the list has solid background */
    background: inherit;
    position: relative;
    z-index: 2;
}

.language-item {
    margin: 0;
}

.language-button {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: none;
    background: none;
    color: var(--text-color-main);
    font-family: var(--font-ui);
    font-size: 0.9rem;
    text-align: left;
    cursor: pointer;
    transition: all 0.2s ease;
    border-radius: 4px;
    margin: 1px 0;
    /* Ensure buttons are opaque */
    position: relative;
}

.language-button:hover {
    background: #EAE0C8;
    color: var(--text-color-dark);
}

.language-button.active {
    background: var(--accent-color);
    color: white;
}

.language-flag {
    font-size: 1.2em;
    min-width: 20px;
}

.language-name {
    flex: 1;
}

/* Alternative solution: Add an overlay to block content behind */
.translation-popup::after {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: -1;
    background: rgba(0, 0, 0, 0.1);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
}

.translation-popup.active::after {
    opacity: 1;
    pointer-events: auto;
}

/* Loading state */
.translation-loading {
    position: fixed;
    top: 80px;
    right: 20px;
    background: var(--accent-color);
    color: white;
    padding: 0.75rem 1rem;
    border-radius: var(--size-8);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    font-size: 0.9rem;
    z-index: 1002;
    opacity: 0;
    transform: translateX(100%);
    transition: all 0.3s ease;
}

.translation-loading.show {
    opacity: 1;
    transform: translateX(0);
}

/* Mobile responsiveness */
@media (max-width: 768px) {
    .translation-popup {
        right: -1rem;
        left: -1rem;
        min-width: auto;
    }
}

/* Additional fix: Ensure home template header styling doesn't interfere */
.home-template .translation-popup {
    background: #1a1a1a !important; /* Force dark background for home template */
}

/* Light theme override for non-home templates */
body:not(.home-template) .translation-popup {
    background: #ffffff !important;
}

[data-theme="light"] body:not(.home-template) .translation-popup {
    background: #ffffff !important;
}

[data-theme="dark"] .translation-popup {
    background: #1a1a1a !important;
}