/* ===== Mobile Header ===== */

/* Mobile Menu Toggle */
.mobile-menu-toggle {
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    width: 38px;
    height: 38px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    z-index: 1001;
    border-radius: 999px;
    transition: background 0.15s;
    -webkit-tap-highlight-color: transparent;
}
.mobile-menu-toggle:hover,
.mobile-menu-toggle:active { background: var(--bg-2, #f1f5f9); }

.hamburger-line {
    width: 17px;
    height: 2px;
    background: var(--fg-0, #0f172a);
    margin: 2px 0;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border-radius: 2px;
}
.mobile-menu-toggle.active .hamburger-line:nth-child(1) { transform: rotate(45deg) translate(4px, 5px); }
.mobile-menu-toggle.active .hamburger-line:nth-child(2) { opacity: 0; transform: scaleX(0); }
.mobile-menu-toggle.active .hamburger-line:nth-child(3) { transform: rotate(-45deg) translate(5px, -5px); }

/* Mobile Navigation Backdrop */
.mobile-navigation-backdrop {
    position: fixed;
    top: 55px;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s;
    z-index: 998;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}
.mobile-navigation-backdrop.active {
    opacity: 1;
    visibility: visible;
}

/* Mobile Navigation Drawer */
.mobile-navigation {
    position: fixed;
    top: 55px;
    left: 0;
    right: 0;
    max-height: calc(100vh - 55px);
    max-height: calc(100dvh - 55px);
    background: var(--bg-0, #ffffff);
    border-bottom: 1px solid var(--border, #e2e8f0);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.12);
    transform: translateY(-100%);
    opacity: 0;
    visibility: hidden;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1),
                opacity 0.25s,
                visibility 0.3s;
    z-index: 999;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}
.mobile-navigation.active {
    transform: translateY(0);
    opacity: 1;
    visibility: visible;
}

.mobile-nav-content { padding: 0; }

/* Mobile Search */
.mobile-search {
    padding: 0.75rem;
    background: var(--bg-1, #f8fafc);
    border-bottom: 1px solid var(--border, #e2e8f0);
}
.mobile-search .search-form {
    display: flex;
    align-items: center;
    background: var(--bg-0, #ffffff);
    border: 1px solid var(--border, #e2e8f0);
    border-radius: var(--radius-lg, 12px);
    overflow: hidden;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.mobile-search .search-form:focus-within {
    border-color: var(--red-500, #dc2626);
    box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.08);
}
.mobile-search .search-input-icon {
    margin-left: 0.75rem;
    color: var(--fg-3, #94a3b8);
    flex-shrink: 0;
}
.mobile-search .search-field {
    flex: 1;
    padding: 0.75rem 0.5rem;
    border: none;
    background: transparent;
    font-size: 1rem;
    color: var(--fg-0, #0f172a);
    outline: none;
    min-width: 0;
}
.mobile-search .search-field::placeholder { color: var(--fg-3, #94a3b8); }
.mobile-search .search-submit {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.75rem 0.9rem;
    background: var(--red-500, #dc2626);
    color: #fff;
    border: none;
    cursor: pointer;
    transition: background 0.15s;
    -webkit-tap-highlight-color: transparent;
}
.mobile-search .search-submit:active { background: var(--red-700, #991b1b); }

/* Mobile Menu Links */
.mobile-nav-menu {
    list-style: none;
    margin: 0;
    padding: 0.25rem 0;
}
.mobile-nav-menu li {
    margin: 0 0.5rem;
}
.mobile-nav-menu a {
    display: flex;
    align-items: center;
    padding: 0.75rem 0.65rem;
    color: var(--fg-0, #0f172a);
    font-size: 0.9375rem;
    font-weight: 500;
    transition: background 0.15s, color 0.15s;
    text-decoration: none;
    min-height: 48px;
    -webkit-tap-highlight-color: transparent;
    border-radius: var(--radius, 8px);
}
.mobile-nav-menu a:active {
    background: var(--bg-2, #f1f5f9);
    color: var(--red-500, #dc2626);
}
.mobile-nav-menu li.current-menu-item a,
.mobile-nav-menu li.current_page_item a {
    color: var(--red-500, #dc2626);
    font-weight: 600;
    background: rgba(220, 38, 38, 0.06);
}

/* Mobile Theme Row */
.mobile-theme-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.65rem 1rem;
    border-top: 1px solid var(--border, #e2e8f0);
    border-bottom: 1px solid var(--border, #e2e8f0);
    background: var(--bg-1, #f8fafc);
}
.mobile-theme-label {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--fg-2, #64748b);
}
.mobile-theme-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    -webkit-tap-highlight-color: transparent;
}

/* Toggle switch */
.mobile-theme-switch {
    display: flex;
    align-items: center;
    width: 44px;
    height: 24px;
    background: var(--bg-3, #e2e8f0);
    border-radius: 999px;
    padding: 2px;
    transition: background 0.25s;
    position: relative;
}
.mobile-theme-switch.active {
    background: var(--red-500, #dc2626);
}
.mobile-theme-switch-thumb {
    width: 20px;
    height: 20px;
    background: #fff;
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(0,0,0,0.15);
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}
.mobile-theme-switch.active .mobile-theme-switch-thumb {
    transform: translateX(20px);
}

/* Mobile Nav Footer */
.mobile-nav-footer {
    padding: 0.85rem 1rem;
    border-top: 1px solid var(--border, #e2e8f0);
    background: var(--bg-1, #f8fafc);
}

.mobile-user-info {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-bottom: 0.65rem;
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--fg-0, #0f172a);
}
.mobile-user-info .user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
}

.mobile-user-links {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}
.mobile-user-links a {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.4rem 0.75rem;
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--fg-1, #334155);
    background: var(--bg-0, #ffffff);
    border: 1px solid var(--border, #e2e8f0);
    border-radius: 999px;
    transition: all 0.15s;
    text-decoration: none;
    min-height: 36px;
    -webkit-tap-highlight-color: transparent;
}
.mobile-user-links a:active {
    background: var(--bg-2, #f1f5f9);
    color: var(--fg-0);
}
.mobile-user-links .logout-link {
    color: var(--red-500, #dc2626);
    border-color: var(--red-500, #dc2626);
}
.mobile-user-links .logout-link:active {
    background: var(--red-500, #dc2626);
    color: #fff;
}

.mobile-auth-buttons {
    display: flex;
    gap: 0.5rem;
}
.btn-mobile-login {
    flex: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.6rem 1rem;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--fg-0, #0f172a);
    background: var(--bg-0, #ffffff);
    border: 1px solid var(--border, #e2e8f0);
    border-radius: var(--radius-lg, 12px);
    transition: all 0.15s;
    text-decoration: none;
    min-height: 44px;
    -webkit-tap-highlight-color: transparent;
}
.btn-mobile-login:active { background: var(--bg-2, #f1f5f9); color: var(--fg-0); }

.btn-mobile-register {
    flex: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.6rem 1rem;
    font-size: 0.875rem;
    font-weight: 600;
    color: #fff;
    background: var(--red-500, #dc2626);
    border-radius: var(--radius-lg, 12px);
    transition: background 0.15s;
    text-decoration: none;
    min-height: 44px;
    -webkit-tap-highlight-color: transparent;
}
.btn-mobile-register:active { background: var(--red-700, #991b1b); color: #fff; }

/* Desktop: hide mobile-only elements */
@media (min-width: 769px) {
    .mobile-menu-toggle,
    .mobile-navigation,
    .mobile-navigation-backdrop { display: none !important; }
}

/* Mobile: show mobile elements */
@media (max-width: 768px) {
    .mobile-menu-toggle { display: flex; }

    .header-right {
        display: flex;
        align-items: center;
        gap: 0.25rem;
    }

    .header-right .theme-toggle,
    .header-right .search-toggle {
        width: 36px;
        height: 36px;
        -webkit-tap-highlight-color: transparent;
    }
}

/* Dark Mode */
[data-theme="dark"] .hamburger-line { background: var(--fg-0, #f8fafc); }
[data-theme="dark"] .mobile-navigation { background: var(--bg-0, #0f172a); border-bottom-color: var(--border, #334155); box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4); }
[data-theme="dark"] .mobile-nav-menu a { color: var(--fg-0, #f8fafc); }
[data-theme="dark"] .mobile-nav-menu a:active { background: var(--bg-2, #334155); }
[data-theme="dark"] .mobile-search { background: var(--bg-1, #1e293b); border-bottom-color: var(--border, #334155); }
[data-theme="dark"] .mobile-search .search-form { background: var(--bg-2, #334155); border-color: var(--border, #334155); }
[data-theme="dark"] .mobile-search .search-field { color: var(--fg-0, #f8fafc); }
[data-theme="dark"] .mobile-nav-footer { background: var(--bg-1, #1e293b); border-top-color: var(--border, #334155); }
[data-theme="dark"] .mobile-user-links a { background: var(--bg-2, #334155); border-color: var(--border, #334155); color: var(--fg-0, #f8fafc); }
[data-theme="dark"] .btn-mobile-login { background: var(--bg-2, #334155); border-color: var(--border, #334155); color: var(--fg-0, #f8fafc); }
[data-theme="dark"] .mobile-theme-row { background: var(--bg-1, #1e293b); border-bottom-color: var(--border, #334155); border-top-color: var(--border, #334155); }
[data-theme="dark"] .mobile-theme-switch { background: var(--bg-3, #475569); }
[data-theme="dark"] .mobile-navigation-backdrop { background: rgba(0, 0, 0, 0.6); }
[data-theme="dark"] .search-overlay-backdrop { background: rgba(0, 0, 0, 0.6); }

/* Body scroll lock */
body.menu-open { overflow: hidden; position: fixed; width: 100%; }

/* Focus & accessibility */
.mobile-menu-toggle:focus-visible,
.search-toggle:focus-visible,
.theme-toggle:focus-visible,
.mobile-theme-toggle:focus-visible {
    outline: 2px solid var(--red-500, #dc2626);
    outline-offset: 2px;
}

/* Safe area for notched phones */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    .mobile-nav-footer {
        padding-bottom: calc(0.85rem + env(safe-area-inset-bottom));
    }
}
