.site-header {
  background-color: var(--primary-color);
  color: var(--white);
  padding: 1rem 0;
  box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}
.header-inner {
  display: grid;
  grid-template-columns: auto auto minmax(0, 1fr);
  align-items: center;
  position: relative;
  column-gap: 10px;
}
.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
  grid-column: 1;
  justify-self: start;
}
.logo-container {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    justify-self: start;
    min-width: 0;
    grid-column: 2;
}
.logo {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--white);
    text-decoration: none;
    letter-spacing: -0.5px;
    display: flex;
    align-items: center;
}
.header-right {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 15px;
  grid-column: 3;
  justify-self: end;
  min-width: 0;
}
.menu-icon {
  background: none;
  border: none;
  color: var(--white);
  cursor: pointer;
  padding: 5px;
}

.share-buttons {
  display: flex;
  gap: 12px;
  align-items: center;
}
.share-icon {
  color: var(--white);
  opacity: 0.8;
  transition: opacity 0.2s, transform 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.share-icon:hover {
  opacity: 1;
  transform: scale(1.1);
}
/* Language Switcher */
.language-switcher select {
    background: rgba(255,255,255,0.2);
    color: var(--white);
    border: 1px solid rgba(255, 255, 255, 0.5);
    padding: 6px 10px;
    border-radius: 4px;
    font-size: 0.9rem;
    cursor: pointer;
    outline: none;
    font-weight: 600;
}
.language-switcher select option {
    background: var(--white);
    color: var(--text-color);
}
/* Sidebar Menu Styles */
.mobile-menu {
    position: fixed;
    top: 0;
    left: -320px;
    width: 280px;
    height: 100vh;
    background: var(--white);
    box-shadow: 2px 0 10px rgba(0,0,0,0.15);
    z-index: 9999;
    transition: left 0.3s ease;
    overflow-y: auto;
}
.mobile-menu.active {
    left: 0;
}
.mobile-menu-inner {
    padding: 1.5rem;
}
.mobile-menu-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 1rem;
}
.close-btn {
    background: none;
    border: none;
    font-size: 2rem;
    cursor: pointer;
    color: var(--text-color);
}
.mobile-menu-list {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
}
.mobile-menu-list a {
    text-decoration: none;
    color: var(--text-color);
    font-size: 1rem;
    padding: 0.5rem 0;
    transition: color 0.2s;
    border-bottom: 1px dashed var(--border-color);
}
.mobile-menu-list a:hover {
    color: var(--primary-color);
}


/* Search UI */
.search-container {
    position: relative;
    margin-right: 15px;
}

.search-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.search-icon {
    position: absolute;
    left: 10px;
    color: var(--text-color);
    opacity: 0.6;
}

#site-search-input {
    padding: 8px 12px 8px 34px;
    border-radius: 20px;
    border: 1px solid var(--border-color);
    background: #f4f4f4;
    font-size: 0.9rem;
    width: 180px;
    transition: width 0.3s ease, border-color 0.3s ease, background 0.3s ease;
    outline: none;
}

#site-search-input:focus {
    width: 250px;
    background: #fff;
    border-color: var(--primary-color);
}

.search-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 8px;
    width: 320px;
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
    z-index: 1000;
    max-height: 400px;
    overflow-y: auto;
    opacity: 1;
    transform: translateY(0);
    transition: opacity 0.2s, transform 0.2s;
}

.search-dropdown.hidden {
    opacity: 0;
    transform: translateY(-10px);
    pointer-events: none;
}

.search-results-list {
    display: flex;
    flex-direction: column;
}

.search-result-item {
    padding: 12px 15px;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background 0.2s;
}

.search-result-item:last-child {
    border-bottom: none;
}

.search-result-item:hover {
    background: #f4f4f4;
}

.search-result-face {
    font-size: 1.2rem;
    font-weight: 500;
    color: var(--text-color);
}

.search-result-category {
    font-size: 0.8rem;
    color: #666;
    background: #eee;
    padding: 2px 6px;
    border-radius: 4px;
}

.search-empty {
    padding: 20px;
    text-align: center;
    color: #666;
    font-size: 0.9rem;
}

/* Custom Language Selector */
.custom-lang-selector {
    position: relative;
    display: inline-block;
}
.lang-selector-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.5);
    padding: 6px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    font-family: inherit;
    color: var(--white);
    font-weight: 500;
}
.lang-selector-btn * {
    pointer-events: none;
}
.lang-selector-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}
.lang-selector-btn .chevron {
    transition: transform 0.2s;
}
.lang-selector-btn[aria-expanded="true"] .chevron {
    transform: rotate(180deg);
}
.lang-flag img {
    border-radius: 2px;
    vertical-align: middle;
}
.lang-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 5px;
    background: #fff;
    border: 1px solid #eee;
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    min-width: 120px;
    z-index: 1000;
}
.lang-dropdown.hidden {
    display: none;
}
.lang-option {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    color: var(--text-color);
    text-decoration: none;
    font-size: 14px;
    transition: background 0.2s;
}
.lang-option:hover {
    background: #f5f5f5;
}
.lang-option.active {
    background: var(--primary-color);
    color: #fff;
}

/* Responsive header and single language switcher placement */
@media (max-width: 768px) {
    .header-inner {
        grid-template-columns: auto auto minmax(0, 1fr);
        width: 100%;
        padding: 0 5px;
        min-height: 40px;
        column-gap: 8px;
    }

    .logo-container {
        grid-column: 2;
        justify-self: start;
        min-width: 0;
    }

    .logo {
        font-size: 1.4rem;
        white-space: nowrap;
        text-align: left;
    }

    .header-right {
        grid-column: 3;
        justify-self: end;
        gap: 0;
        min-width: 0;
    }

    .search-container {
        margin-right: 0;
        min-width: 0;
    }

    #site-search-input {
        width: 120px;
        max-width: 100%;
        padding: 6px 10px 6px 30px;
        font-size: 0.9rem;
    }

    #site-search-input:focus {
        width: 150px;
    }

    .search-icon {
        color: var(--text-color);
        opacity: 0.6;
        left: 10px;
        top: 50%;
        transform: translateY(-50%);
        pointer-events: none;
        width: 16px;
        height: 16px;
        margin-top: 1px;
    }

    .search-dropdown {
        width: min(280px, calc(100vw - 20px));
        right: -10px;
    }

    /* The SAME language-switcher element is moved into the mobile menu by JS. */
    .mobile-menu-language {
        display: block;
        width: 100%;
        margin-bottom: 1rem;
        padding-bottom: 1rem;
        border-bottom: 1px solid var(--border-color);
        position: static;
    }

    .mobile-menu-language .header-lang,
    .mobile-menu-language .custom-lang-selector {
        width: 100%;
        position: relative;
    }

    .mobile-menu-language .lang-selector-btn {
        width: 100%;
        justify-content: flex-start;
        padding: 9px 10px;
        gap: 8px;
        color: var(--text-color);
        background: #fff;
        border: 1px solid var(--border-color);
        border-radius: 6px;
    }

    .mobile-menu-language .lang-selector-btn .lang-name {
        display: inline;
        color: var(--text-color);
    }

    .mobile-menu-language .lang-dropdown {
        left: 0;
        right: auto;
        width: 100%;
        z-index: 10002;
    }

    /* Full-width mobile drawer. */
    .mobile-menu {
        width: 100vw;
        max-width: 100%;
        left: -100vw;
        height: 100dvh;
        overflow-x: clip;
    }

    .mobile-menu.active {
        left: 0;
    }

    .mobile-menu-inner {
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
        padding: 1.25rem;
    }
}

@media (min-width: 769px) {
    .site-header {
        position: relative;
    }

    .header-inner {
        width: 100%;
        max-width: 1200px;
        margin-left: auto;
        margin-right: auto;
        position: relative;
        overflow: visible;
    }

    .header-right {
        display: flex;
        align-items: center;
        justify-content: flex-end;
        gap: 12px;
        min-width: 0;
        padding-right: 0;
        position: relative;
    }

    .header-right .search-container {
        flex: 0 1 auto;
        margin-right: 0;
    }

    /* The single switcher is physically moved into .header-right on desktop. */
    .header-right .mobile-menu-language {
        display: block;
        width: auto;
        margin: 0;
        padding: 0;
        border: 0;
        position: relative;
        flex: 0 0 auto;
    }

    .header-right .mobile-menu-language .header-lang,
    .header-right .mobile-menu-language .custom-lang-selector {
        position: relative;
        width: auto;
    }

    .header-right .mobile-menu-language .lang-selector-btn {
        width: auto;
        white-space: nowrap;
    }
}

/* Single language switcher: no duplicate desktop/mobile component. */
.header-lang,
.custom-lang-selector {
    position: relative;
    z-index: 10001;
}

/* Prevent any viewport-edge positioning from older builds. */
@media (min-width: 769px) {
    .mobile-menu-language {
        right: auto !important;
        top: auto !important;
        transform: none !important;
    }
}


/* v33 FINAL: keep desktop switcher inside the 1200px header and move the same
   element into the mobile menu via JS. Never position it against the viewport. */
@media (min-width: 769px) {
    .site-header .header-inner {
        width: 100%;
        max-width: 1200px;
        margin-left: auto;
        margin-right: auto;
        box-sizing: border-box;
        overflow: visible;
    }
    .header-right {
        display: flex;
        align-items: center;
        justify-content: flex-end;
        gap: 12px;
        min-width: 0;
        box-sizing: border-box;
    }
    .header-right .search-container {
        flex: 0 1 auto;
        margin-right: 0;
    }
    .header-right .mobile-menu-language {
        display: block !important;
        visibility: visible !important;
        position: relative !important;
        inset: auto !important;
        transform: none !important;
        width: auto;
        margin: 0;
        padding: 0;
        flex: 0 0 auto;
    }
}

@media (max-width: 768px) {
    html, body {
        width: 100%;
        max-width: 100%;
        overflow-x: clip !important;
    }
    .mobile-menu {
        width: 100% !important;
        max-width: 100% !important;
        left: -100% !important;
        right: auto !important;
        box-sizing: border-box;
        overflow-x: clip !important;
    }
    .mobile-menu.active {
        left: 0 !important;
    }
    .mobile-menu-inner {
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
    }
    .mobile-menu-language-slot {
        display: block;
        width: 100%;
        height: 0;
    }
}


/* v34 FINAL: separate desktop/mobile language switchers.
   Both use the same .header-lang-switcher class and data-* behavior. */
.header-lang-switcher { box-sizing: border-box; }
.header-lang-switcher .custom-lang-selector { position: relative; }
.language-switcher-desktop { display: flex; align-items: center; flex: 0 0 auto; }
.language-switcher-mobile { display: none; }

@media (min-width: 769px) {
  .site-header .header-inner {
    width: 100%; max-width: 1200px; margin: 0 auto;
    box-sizing: border-box; overflow: visible;
  }
  .site-header .header-right {
    display: flex; align-items: center; justify-content: flex-end;
    gap: 12px; min-width: 0; box-sizing: border-box;
  }
  .site-header .header-right .search-container {
    flex: 0 1 auto; margin: 0;
  }
  .site-header .language-switcher-desktop {
    display: flex !important; visibility: visible !important;
    position: relative !important; inset: auto !important;
    width: auto; margin: 0; padding: 0;
    flex: 0 0 auto; transform: none !important;
  }
  .site-header .language-switcher-desktop .custom-lang-selector { width: auto; }
  .site-header .language-switcher-mobile { display: none !important; }
}

@media (max-width: 768px) {
  .site-header .language-switcher-desktop { display: none !important; }
  .site-header .language-switcher-mobile {
    display: block !important; width: 100%; margin: 0 0 1rem;
    padding: 0 0 1rem; border-bottom: 1px solid var(--border-color);
    position: static !important;
  }
  .site-header .language-switcher-mobile .custom-lang-selector,
  .site-header .language-switcher-mobile .header-lang { width: 100%; }
  .site-header .language-switcher-mobile .lang-selector-btn {
    width: 100%; justify-content: flex-start;
  }
  .site-header .language-switcher-mobile .lang-dropdown {
    left: 0; right: auto; width: 100%; z-index: 10002;
  }
  .mobile-menu {
    width: 100%; max-width: 100%; left: -100%; right: auto;
    box-sizing: border-box; overflow-x: clip;
  }
  .mobile-menu.active { left: 0; }
}


/* v35 FINAL: Mobile language switcher button visibility.
   The mobile component uses .language-switcher-mobile, so these rules
   intentionally target that component instead of the old .mobile-menu-language. */
@media (max-width: 768px) {
  .site-header .language-switcher-mobile .lang-selector-btn {
    color: #111 !important;
    background: #fff !important;
    border: 1px solid #222 !important;
    border-radius: 6px !important;
    box-shadow: none !important;
  }

  .site-header .language-switcher-mobile .lang-selector-btn .lang-name,
  .site-header .language-switcher-mobile .lang-selector-btn .chevron {
    color: #111 !important;
  }

  .site-header .language-switcher-mobile .lang-selector-btn .lang-flag {
    display: inline-flex !important;
    align-items: center;
  }

  .site-header .language-switcher-mobile .lang-selector-btn .lang-flag img {
    display: block !important;
  }

  .site-header .language-switcher-mobile .lang-dropdown {
    border: 1px solid #d1d5db !important;
    background: #fff !important;
  }
}

/* v38: search results must always render ABOVE the sticky copy bar. */
.site-header {
  position: relative;
  z-index: 2000;
}
.search-container {
  position: relative;
  z-index: 2001;
}
.search-dropdown {
  z-index: 2100 !important;
}
