/* ===== Site header ===== */
.site-header,
.site-mobile-menu {
    --sh-bg: rgba(255, 255, 255, 0.85);
    --sh-surface: #ffffff;
    --sh-surface-2: #f3f2f8;
    --sh-border: rgba(16, 12, 40, 0.08);
    --sh-text: #1f1d2b;
    --sh-muted: #6b6880;
    --sh-accent: var(--color-primary, #49108b);
}

body.active-dark-mode .site-header,
body.active-dark-mode .site-mobile-menu {
    --sh-bg: rgba(22, 22, 28, 0.85);
    --sh-surface: #1d1d24;
    --sh-surface-2: #26262f;
    --sh-border: rgba(255, 255, 255, 0.08);
    --sh-text: #f3f3f6;
    --sh-muted: #a3a1b3;
    --sh-accent: #a98bf5;
}

/* The theme sets body { overflow: hidden }, which makes body a scroll container
   and stops position: sticky from working. clip still prevents sideways overflow. */
body {
    overflow: visible;
    overflow-x: clip;
}

.site-header {
    position: sticky;
    z-index: 100;
    top: 0;
    border-bottom: 1px solid var(--sh-border);
    background: var(--sh-bg);
    -webkit-backdrop-filter: saturate(180%) blur(14px);
    backdrop-filter: saturate(180%) blur(14px);
}

.site-header ul,
.site-mobile-menu ul {
    margin: 0;
    padding: 0;
    list-style: none;
}

.site-header li,
.site-mobile-menu li {
    margin: 0;
}

.site-header-bar {
    display: flex;
    align-items: center;
    gap: 16px;
    height: 64px;
}

/* ----- Logo (switches with the theme) ----- */
.site-header-logo {
    display: inline-flex;
    flex: none;
    align-items: center;
}

.site-header-logo img {
    width: auto;
    height: 36px;
}

.site-header-logo-dark,
body.active-dark-mode .site-header-logo-light {
    display: none;
}

body.active-dark-mode .site-header-logo-dark {
    display: block;
}

/* ----- Navigation (desktop only) ----- */
.site-header-nav {
    display: none;
}

.site-header-nav ul {
    display: flex;
    align-items: center;
    gap: 2px;
}

.site-header-nav a {
    position: relative;
    display: block;
    padding: 8px 12px;
    border-radius: 10px;
    color: var(--sh-muted);
    font-size: 15px;
    font-weight: 600;
    white-space: nowrap;
    transition: color 0.2s ease, background-color 0.2s ease;
}

.site-header-nav a:hover {
    background: var(--sh-surface-2);
    color: var(--sh-text);
}

.site-header-nav a.is-active {
    color: var(--sh-accent);
}

.site-header-nav a.is-active::after {
    content: '';
    position: absolute;
    right: 12px;
    bottom: -11px;
    left: 12px;
    height: 3px;
    border-radius: 3px 3px 0 0;
    background: var(--sh-accent);
}

/* ----- Actions ----- */
.site-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-right: auto; /* RTL: push to the left edge */
}

.site-header-icon {
    display: inline-flex;
    flex: none;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    border: 1px solid var(--sh-border);
    border-radius: 12px;
    background: var(--sh-surface);
    color: var(--sh-text);
    font-size: 16px;
    cursor: pointer;
    transition: border-color 0.2s ease, color 0.2s ease, background-color 0.2s ease;
}

.site-header-icon:hover {
    border-color: var(--sh-accent);
    color: var(--sh-accent);
}

.site-header a:focus-visible,
.site-header button:focus-visible,
.site-header input:focus-visible,
.site-mobile-menu a:focus-visible,
.site-mobile-menu button:focus-visible,
.site-mobile-menu input:focus-visible {
    outline: 3px solid color-mix(in srgb, var(--sh-accent) 45%, transparent);
    outline-offset: 2px;
}

/* Theme toggle: show only the action for the other mode */
.site-header-theme ul {
    display: flex;
}

.site-header-theme-to-light,
body.active-dark-mode .site-header-theme-to-dark {
    display: none;
}

body.active-dark-mode .site-header-theme-to-light {
    display: block;
}

/* Search */
.site-header-search {
    position: relative;
}

.site-header-search-form {
    position: absolute;
    top: calc(100% + 12px);
    left: 0;
    display: none;
    align-items: center;
    width: min(360px, calc(100vw - 32px));
    padding: 6px;
    border: 1px solid var(--sh-border);
    border-radius: 14px;
    background: var(--sh-surface);
    box-shadow: 0 16px 32px rgba(16, 12, 40, 0.12);
}

.site-header-search-form.open {
    display: flex;
}

.site-header-search-form input {
    flex: 1;
    min-width: 0;
    height: 40px;
    padding: 0 12px;
    border: 0;
    background: transparent;
    color: var(--sh-text);
    font-size: 14px;
}

/* No focus ring on the search fields: they are focused on open, so the ring always showed */
.site-header .site-header-search-form input:focus,
.site-header .site-header-search-form input:focus-visible,
.site-mobile-menu .site-mobile-menu-search input:focus,
.site-mobile-menu .site-mobile-menu-search input:focus-visible {
    outline: none;
    box-shadow: none;
}

.site-header-search-form input::placeholder {
    color: var(--sh-muted);
}

.site-header-search-form button {
    display: inline-flex;
    flex: none;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: 0;
    border-radius: 10px;
    background: var(--sh-accent);
    color: #fff;
    cursor: pointer;
}

/* Account */
.site-header-login,
.site-header-account {
    display: inline-flex;
    flex: none;
    align-items: center;
    gap: 8px;
    height: 40px;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 700;
    white-space: nowrap;
}

.site-header-login {
    padding: 0 16px;
    background: var(--sh-accent);
}

.site-header .site-header-login,
.site-mobile-menu .site-header-login {
    color: #fff;
}

body.active-dark-mode .site-header-login {
    background: #6d3fd1;
}

.site-header-login:hover {
    filter: brightness(1.1);
}

.site-header-account {
    padding: 0 6px 0 12px;
    border: 1px solid var(--sh-border);
    background: var(--sh-surface);
}

.site-header .site-header-account,
.site-mobile-menu .site-header-account {
    color: var(--sh-text);
}

.site-header-account:hover {
    border-color: var(--sh-accent);
}

.site-header-account img {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    object-fit: cover;
}

/* Phones: login becomes an icon button */
@media (max-width: 575px) {
    .site-header-bar {
        gap: 10px;
        height: 60px;
    }

    .site-header-logo img {
        height: 32px;
    }

    .site-header-actions {
        gap: 6px;
    }

    .site-header .site-header-login,
    .site-header .site-header-account {
        justify-content: center;
        width: 40px;
        padding: 0;
    }

    .site-header .site-header-login span,
    .site-header .site-header-account span {
        display: none;
    }

    .site-header-search-form {
        position: fixed;
        top: 68px;
        right: 16px;
        left: 16px;
        width: auto;
    }
}

/* ----- Desktop: full navigation and an inline search field ----- */
@media (min-width: 1200px) {
    .site-header-bar {
        height: 72px;
        gap: 24px;
    }

    .site-header-nav {
        display: block;
    }

    .site-header-nav a.is-active::after {
        bottom: -15px;
    }

    .site-header-burger {
        display: none;
    }

    .site-header-search .search-button-toggle {
        display: none;
    }

    .site-header-search-form {
        position: static;
        display: flex;
        width: 220px;
        padding: 0 4px 0 0;
        border-radius: 12px;
        background: var(--sh-surface-2);
        box-shadow: none;
        transition: width 0.25s ease, border-color 0.2s ease;
    }

    .site-header-search-form:focus-within {
        width: 280px;
        border-color: var(--sh-accent);
        background: var(--sh-surface);
    }

    .site-header-search-form input {
        height: 40px;
    }

    .site-header-search-form button {
        width: 32px;
        height: 32px;
        margin-left: 4px;
        background: transparent;
        color: var(--sh-muted);
    }
}

/* ===== Mobile menu panel (opened by main.js via body.popup-mobile-menu-show) ===== */
.site-mobile-menu .inner {
    display: flex;
    flex-direction: column;
    gap: 16px;
    box-sizing: border-box;
    padding: 20px;
    overflow-y: auto;
    background: var(--sh-surface);
}

.site-mobile-menu .mobile-menu-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--sh-border);
}

.site-mobile-menu-search {
    display: flex;
    align-items: center;
    padding: 4px;
    border: 1px solid var(--sh-border);
    border-radius: 12px;
    background: var(--sh-surface-2);
}

.site-mobile-menu-search input {
    flex: 1;
    min-width: 0;
    height: 40px;
    padding: 0 10px;
    border: 0;
    background: transparent;
    color: var(--sh-text);
    font-size: 14px;
}

.site-mobile-menu-search button {
    width: 40px;
    height: 40px;
    border: 0;
    border-radius: 10px;
    background: var(--sh-accent);
    color: #fff;
}

.site-mobile-menu-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.site-mobile-menu-list a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border-radius: 12px;
    color: var(--sh-text);
    font-size: 15px;
    font-weight: 600;
}

.site-mobile-menu-list a i {
    width: 20px;
    color: var(--sh-muted);
    text-align: center;
}

.site-mobile-menu-list a:hover {
    background: var(--sh-surface-2);
}

.site-mobile-menu-list a.is-active {
    background: color-mix(in srgb, var(--sh-accent) 10%, transparent);
    color: var(--sh-accent);
}

.site-mobile-menu-list a.is-active i {
    color: var(--sh-accent);
}

.site-mobile-menu-footer {
    margin-top: auto;
    padding-top: 12px;
    border-top: 1px solid var(--sh-border);
}

.site-mobile-menu-login {
    justify-content: center;
    width: 100%;
}

@media (prefers-reduced-motion: reduce) {
    .site-header-nav a,
    .site-header-icon,
    .site-header-search-form {
        transition: none;
    }
}

/* ===== PWA install banner ===== */
.pwa-install {
    --pi-surface: #ffffff;
    --pi-border: rgba(16, 12, 40, 0.1);
    --pi-text: #1f1d2b;
    --pi-muted: #6b6880;
    --pi-accent: var(--color-primary, #49108b);
    position: fixed;
    z-index: 1000;
    right: 16px;
    bottom: calc(16px + env(safe-area-inset-bottom));
    left: 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    max-width: 480px;
    margin: 0 auto;
    padding: 12px;
    border: 1px solid var(--pi-border);
    border-radius: 18px;
    background: var(--pi-surface);
    box-shadow: 0 20px 40px rgba(16, 12, 40, 0.18);
    opacity: 0;
    transform: translateY(16px);
    transition: opacity 0.25s ease, transform 0.25s ease;
}

body.active-dark-mode .pwa-install {
    --pi-surface: #1d1d24;
    --pi-border: rgba(255, 255, 255, 0.1);
    --pi-text: #f3f3f6;
    --pi-muted: #a3a1b3;
    --pi-accent: #6d3fd1;
}

.pwa-install[hidden] {
    display: none;
}

.pwa-install.is-visible {
    opacity: 1;
    transform: none;
}

.pwa-install-icon {
    flex: none;
    width: 48px;
    height: 48px;
    border-radius: 12px;
}

.pwa-install-body {
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.pwa-install-body strong {
    color: var(--pi-text);
    font-size: 14px;
}

.pwa-install-body span {
    color: var(--pi-muted);
    font-size: 12px;
    line-height: 1.7;
}

.pwa-install-actions {
    display: flex;
    flex: none;
    align-items: center;
    gap: 4px;
}

.pwa-install-btn {
    padding: 8px 16px;
    border: 0;
    border-radius: 10px;
    background: var(--pi-accent);
    color: #fff;
    font: inherit;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
}

.pwa-install-close {
    width: 32px;
    height: 32px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--pi-muted);
    cursor: pointer;
}

.pwa-install button:focus-visible {
    outline: 3px solid color-mix(in srgb, var(--pi-accent) 45%, transparent);
    outline-offset: 2px;
}

/* Installed app (standalone): leave room for the notch / status bar */
@media (display-mode: standalone) {
    .site-header {
        padding-top: env(safe-area-inset-top);
    }
}

@media (prefers-reduced-motion: reduce) {
    .pwa-install {
        transition: none;
    }
}
