/* ---------------------------------------------------------
   HEADER LAYOUT (Left - Center - Right)
   --------------------------------------------------------- */
/* Global Box Sizing for Header Elements to prevent overflow */
.pe-header, .pe-header * {
    box-sizing: border-box;
}

.pe-header { 
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-color); 
    padding: 15px 0; 
    position: relative; 
    width: 100%;
    z-index: 900; 
    transition: background 0.3s ease, transform 0.3s ease;
}

/* --- Floating/Sticky State --- */
.pe-header.pe-floating {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    border-bottom: 1px solid var(--border-color);
    box-shadow: 0 4px 20px var(--shadow-color);
    animation: peSlideDown 0.3s ease-out forwards;
    background: rgba(255, 255, 255, 0.95); /* Slight transparency */
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}
[data-theme="dark"] .pe-header.pe-floating {
    background: rgba(30, 41, 59, 0.95); /* Dark mode transparency */
}

@keyframes peSlideDown {
    from { transform: translateY(-100%); }
    to { transform: translateY(0); }
}

.pe-nav-flex { 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    height: 100%; 
}

/* 1. Logo */
.pe-logo { 
    font-weight: 900; 
    font-size: 1.4rem; 
    letter-spacing: -1px; 
    z-index: 20;
    flex-shrink: 0;
    line-height: 1;
    display: flex; 
    align-items: center;
}
.pe-logo a { color: var(--text-main); text-decoration: none; }

/* 2. Menu (Desktop) */
.pe-main-menu { 
    flex: 1; 
    display: flex; 
    justify-content: center; 
}

.pe-nav-list { 
    display: flex; 
    align-items: center;
    gap: 30px; 
    list-style: none; 
    margin: 0; 
    padding: 0; 
}

.pe-nav-list li a { 
    color: var(--text-muted); 
    font-weight: 600; 
    font-size: 0.95rem; 
    text-decoration: none; 
    transition: color 0.2s;
}

.pe-nav-list li a:hover,
.pe-nav-list li.current-menu-item > a { 
    color: var(--primary); 
}

.pe-drawer-close { display: none; } 

/* 3. Actions (Right) */
.pe-header-actions { 
    display: flex; 
    justify-content: flex-end; 
    align-items: center; 
    gap: 8px; 
    z-index: 21; 
    height: 100%;
}

.pe-icon-btn { 
    background: transparent; 
    border: none; 
    color: var(--text-muted); 
    cursor: pointer; 
    padding: 8px; 
    border-radius: 50%;
    display: flex; 
    align-items: center; 
    justify-content: center;
    transition: 0.2s;
    line-height: 0; 
}
.pe-icon-btn svg {
    display: block; 
    width: 20px;
    height: 20px;
}
.pe-icon-btn:hover { 
    background: var(--bg-subtle); 
    color: var(--primary); 
}

/* 4. Hamburger (Mobile Only) */
.pe-mobile-toggle { 
    display: none; 
    background: none; 
    border: none; 
    cursor: pointer; 
    flex-direction: column; 
    justify-content: center;
    gap: 5px; 
    padding: 5px;
    z-index: 21;
}
.pe-bar { 
    width: 24px; 
    height: 2px; 
    background: var(--text-main); 
    transition: 0.3s;
}

/* ---------------------------------------------------------
   SEARCH OVERLAY
   --------------------------------------------------------- */
.pe-search-overlay {
    position: absolute;
    top: 100%;
    left: 0;
    width: 100%;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
    padding: 20px 0;
    display: none;
    z-index: 1000;
    box-shadow: 0 10px 30px var(--shadow-color);
    box-sizing: border-box; /* Fixes overflow issue */
}

.pe-search-overlay.active { 
    display: block; 
    animation: slideDown 0.2s ease-out; 
}
@keyframes slideDown { 
    from { opacity:0; transform:translateY(-10px); } 
    to { opacity:1; transform:translateY(0); } 
}

/* Container for Form + Close Button */
.pe-search-container {
    display: flex;
    align-items: center;
    gap: 15px;
    max-width: 700px;
    margin: 0 auto;
    width: 100%; /* Ensure it fits within parent */
}

.pe-search-form-header {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-grow: 1;
    width: 100%;
}

.pe-header-search-input {
    flex: 1;
    padding: 0 20px;
    border-radius: 50px;
    border: 1px solid var(--border-color);
    background: var(--bg-body);
    color: var(--text-main);
    font-size: 1rem;
    outline: none;
    height: 48px; 
    width: 100%;
}

.pe-btn-search-go {
    background: var(--primary);
    color: white;
    border: none;
    padding: 0 24px;
    border-radius: 50px;
    cursor: pointer;
    font-weight: 600;
    height: 48px; 
    flex-shrink: 0;
}

.pe-search-close {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    padding: 8px;
    transition: color 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    height: 48px;
    width: 48px;
}
.pe-search-close:hover {
    color: var(--text-main);
    background: var(--bg-subtle);
}

/* ---------------------------------------------------------
   MOBILE RESPONSIVE (Max Width 768px)
   --------------------------------------------------------- */
@media (max-width: 768px) {
    .pe-nav-flex { position: relative; justify-content: space-between; height: auto; }
    .pe-mobile-toggle { display: flex; }
    .pe-logo { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: auto; max-width: calc(100% - 110px); text-align: center; }
    .pe-logo a { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .site-title { font-size: 1.2rem; }
    .pe-main-menu { position: fixed; top: 0; left: 0; bottom: 0; width: 80%; max-width: 300px; background: var(--bg-surface); flex-direction: column; justify-content: flex-start; padding: 60px 20px 20px 20px; box-shadow: 2px 0 20px var(--shadow-color); z-index: 999; transform: translateX(-100%); transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1); visibility: hidden; }
    .pe-main-menu.active { transform: translateX(0); visibility: visible; }
    .pe-nav-list { flex-direction: column; gap: 0; width: 100%; }
    .pe-nav-list li a { display: block; padding: 15px 0; border-bottom: 1px solid var(--border-color); font-size: 1.1rem; }
    .pe-drawer-close { display: block; position: absolute; top: 15px; right: 15px; background: none; border: none; font-size: 2rem; color: var(--text-muted); cursor: pointer; }

    /* --- FIXED MOBILE SEARCH OVERLAY --- */
    .pe-search-overlay {
        width: 100vw; /* Force viewport width */
        max-width: 100%;
        left: 0;
        right: 0;
    }

    .pe-search-container {
        flex-direction: column; 
        gap: 15px;
        width: 100%;
    }

    .pe-search-form-header {
        width: 100%;
        gap: 10px; 
        display: flex;
        justify-content: space-between;
    }

    .pe-header-search-input {
        width: auto; /* Let flex handle width */
        flex: 1;
        min-width: 0; /* Prevents overflow */
        font-size: 16px; 
    }

    .pe-btn-search-go {
        padding: 0 20px; 
        width: auto;
        flex-shrink: 0;
    }

    /* Close button moved visually below the form */
    .pe-search-close {
        order: 2; /* Ensures it sits below the form */
        margin: 0 auto;
        width: 44px;
        height: 44px;
        background: var(--bg-subtle); /* FIX: Use theme variable for visibility in light/dark mode */
        border-radius: 50%;
    }
}