/**
 * أنماط الهيدر والشريط العلوي - تصميم جديد
 *
 * @package Nadiim
 * @since 1.0.0
 */

/* ==========================================
   متغيرات CSS
   ========================================== */

:root {
    --topbar-bg: #F6F9F7;
    --topbar-color: #339063;
    --topbar-font-size: 14px;
    --topbar-align: center;
    --topbar-height: 42px;

    --header-bg: #FFFFFF;
    --header-color: #1C2D27;
    --header-link-color: #1C2D27;
    --header-link-hover: #339063;
    --header-border: rgba(0, 0, 0, 0.06);
    --header-height: 80px;
    --header-logo-width: 180px;
}

/* ==========================================
   الشريط العلوي (Top Bar)
   ========================================== */

.site-topbar {
    background-color: var(--topbar-bg);
    color: var(--topbar-color);
    height: var(--topbar-height);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    z-index: 999;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.site-topbar .container {
    width: 100%;
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 24px;
}

.topbar-inner {
    display: block;
    text-align: var(--topbar-align);
    width: 100%;
}

.topbar-icon {
    font-size: 18px;
    line-height: 1;
    display: inline-block;
    margin-left: 8px;
}

.topbar-content {
    font-size: var(--topbar-font-size);
    line-height: 1.5;
    display: inline-block;
    overflow: hidden;
    vertical-align: middle;
}

/* ==========================================
   الهيدر الرئيسي - تصميم جديد
   ========================================== */

.site-header {
    background-color: var(--header-bg);
    color: var(--header-color);
    border-bottom: 1px solid var(--header-border);
    position: relative;
    z-index: 998;
    transition: all 0.3s ease;
}

.header-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 24px;
}

.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--header-height);
    position: relative;
}

/* ─────────────────────────────────────
   زر القائمة للموبايل
   ───────────────────────────────────── */

.mobile-menu-toggle {
    display: none; /* يظهر فقط في الشاشات الصغيرة */
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    width: 44px;
    height: 44px;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    transition: all 0.3s ease;
}

.mobile-menu-toggle i {
    font-size: 24px;
    color: var(--header-color);
    transition: all 0.3s ease;
}

.mobile-menu-toggle:hover {
    background-color: rgba(51, 144, 99, 0.1);
}

.mobile-menu-toggle:hover i {
    color: var(--header-link-hover);
}

.mobile-menu-toggle[aria-expanded="true"] i {
    transform: rotate(90deg);
}

/* ─────────────────────────────────────
   الشعار
   ───────────────────────────────────── */

.site-branding {
    flex-shrink: 0;
}

.site-branding a {
    display: inline-block;
    text-decoration: none;
    line-height: 0;
}

.custom-logo {
    max-width: var(--header-logo-width);
    height: auto;
    display: block;
    transition: all 0.3s ease;
}

.site-title {
    margin: 0;
    font-size: 28px;
    font-weight: 700;
    color: var(--header-color);
    line-height: 1.2;
}

/* ─────────────────────────────────────
   القائمة الرئيسية
   ───────────────────────────────────── */

.main-navigation {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.primary-menu {
    display: flex;
    list-style: none;
    margin: 0;
    padding: 0;
    gap: 10px;
    align-items: center;
}

.primary-menu > li {
    position: relative;
}

.primary-menu > li > a {
    display: block;
    padding: 12px 18px;
    color: var(--header-link-color);
    text-decoration: none;
    font-weight: 600;
    font-size: 17px;
    transition: all 0.3s ease;
    border-radius: 8px;
    position: relative;
}

.primary-menu > li > a:hover {
    color: #ffffff;
    background-color: var(--header-link-hover);
    transform: translateY(-2px);
}

.primary-menu > li.current-menu-item > a,
.primary-menu > li.current_page_item > a {
    color: #ffffff;
    background-color: var(--header-link-hover);
}

/* القوائم الفرعية */
.primary-menu .sub-menu {
    position: absolute;
    top: 100%;
    right: 0;
    background-color: var(--header-bg);
    border: 1px solid var(--header-border);
    border-radius: 8px;
    padding: 8px 0;
    min-width: 220px;
    list-style: none;
    margin: 0;
    opacity: 0;
    visibility: hidden;
    transform: translateY(10px);
    transition: all 0.3s ease;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
    z-index: 1000;
}

.primary-menu li:hover > .sub-menu {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.primary-menu .sub-menu li a {
    display: block;
    padding: 10px 20px;
    color: var(--header-link-color);
    text-decoration: none;
    font-size: 15px;
    transition: all 0.2s ease;
}

.primary-menu .sub-menu li a:hover {
    background-color: rgba(51, 144, 99, 0.08);
    color: var(--header-link-hover);
    padding-right: 25px;
}

/* ─────────────────────────────────────
   زر إغلاق القائمة (مخفي في الشاشات الكبيرة)
   ───────────────────────────────────── */

.mobile-menu-close {
    display: none; /* مخفي افتراضياً في الشاشات الكبيرة */
}

/* ─────────────────────────────────────
   البحث
   ───────────────────────────────────── */

.header-search {
    flex-shrink: 0;
}

.search-toggle {
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.3s ease;
}

.search-toggle i {
    font-size: 20px;
    color: var(--header-color);
    transition: all 0.3s ease;
}

.search-toggle:hover {
    background-color: rgba(51, 144, 99, 0.1);
}

.search-toggle:hover i {
    color: var(--header-link-hover);
}

/* ─────────────────────────────────────
   نافذة البحث المنبثقة
   ───────────────────────────────────── */

.search-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 9999;
    display: none;
    align-items: flex-start;
    justify-content: center;
    padding-top: 100px;
}

.search-modal.is-active {
    display: flex;
}

.search-modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.8);
    animation: fadeIn 0.3s ease;
}

.search-modal-content {
    position: relative;
    width: 100%;
    max-width: 700px;
    background-color: var(--header-bg);
    border-radius: 16px;
    padding: 40px;
    animation: slideDown 0.3s ease;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.search-modal-header {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 20px;
}

.search-close {
    background: none;
    border: none;
    cursor: pointer;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s ease;
}

.search-close i {
    font-size: 28px;
    color: var(--header-color);
}

.search-close:hover {
    background-color: rgba(0, 0, 0, 0.05);
    transform: rotate(90deg);
}

.search-form-inner {
    display: flex;
    align-items: center;
    background-color: rgba(0, 0, 0, 0.05);
    padding: 15px 25px;
    border-radius: 50px;
    gap: 15px;
    transition: all 0.2s ease;
}

.search-form-inner:focus-within {
    background-color: rgba(51, 144, 99, 0.1);
    box-shadow: 0 0 0 3px rgba(51, 144, 99, 0.2);
}

.search-icon {
    font-size: 20px;
    color: var(--header-color);
    opacity: 0.6;
}

.search-field {
    flex: 1;
    border: none;
    background: none;
    font-size: 18px;
    padding: 0;
    outline: none;
    color: var(--header-color);
}

.search-field::placeholder {
    color: var(--header-color);
    opacity: 0.6;
}

.search-submit {
    background-color: var(--header-link-hover);
    color: #ffffff;
    border: none;
    padding: 12px 30px;
    border-radius: 50px;
    cursor: pointer;
    font-weight: 600;
    font-size: 16px;
    transition: all 0.2s ease;
}

.search-submit:hover {
    background-color: #2a7a51;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(51, 144, 99, 0.3);
}

/* ─────────────────────────────────────
   الهيدر الثابت (Sticky)
   ───────────────────────────────────── */

.header-sticky {
    position: sticky;
    top: 0;
}

.header-sticky.is-stuck {
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
}

.header-sticky.is-stuck .header-inner {
    height: 65px;
}

.header-sticky.is-stuck .custom-logo {
    max-width: calc(var(--header-logo-width) * 0.85);
}

/* ==========================================
   Responsive Design
   ========================================== */

/* Desktop Large (> 1400px) */
@media screen and (min-width: 1401px) {
    .header-container {
        max-width: 1600px;
    }

    .primary-menu {
        gap: 15px;
    }
}

/* Tablet & Small Desktop (768px - 1024px) */
@media screen and (max-width: 1024px) {
    :root {
        --header-height: 70px;
        --header-logo-width: 160px;
    }

    .header-container {
        padding: 0 20px;
    }

    .primary-menu {
        gap: 8px;
    }

    .primary-menu > li > a {
        font-size: 16px;
        padding: 10px 15px;
    }
}

/* Mobile (≤ 768px) */
@media screen and (max-width: 768px) {
    :root {
        --header-height: 70px;
        --header-logo-width: 140px;
    }

    /* خفض z-index للـ topbar في الموبايل */
    .site-topbar {
        z-index: 1;
    }

    /* زيادة z-index للهيدر في الموبايل */
    .site-header {
        z-index: 999998;
    }

    /* إظهار زر القائمة */
    .mobile-menu-toggle {
        display: flex;
        order: 1; /* على اليمين */
    }

    /* الشعار في المنتصف */
    .site-branding {
        order: 2;
        position: absolute;
        left: 50%;
        transform: translateX(-50%);
    }

    /* البحث على اليسار */
    .header-search {
        order: 3;
    }

    /* القائمة overlay كامل */
    .main-navigation {
        position: fixed;
        top: 0;
        right: -100%;
        width: 300px;
        height: 100vh;
        background-color: var(--header-bg);
        box-shadow: -5px 0 20px rgba(0, 0, 0, 0.1);
        transition: right 0.3s ease;
        z-index: 999999; /* قيمة عالية جداً لتظهر فوق كل شيء بما في ذلك topbar */
        padding: 70px 0 20px 0; /* إضافة padding-top لتجنب اختفاء العناصر تحت زر الإغلاق */
        overflow-y: auto;
        display: block !important; /* تأكد من أن القائمة معروضة */
    }

    .main-navigation.is-active {
        right: 0 !important; /* تأكد من أن القائمة تظهر */
    }

    /* زر إغلاق القائمة في الموبايل */
    .mobile-menu-close {
        display: flex; /* يظهر في الموبايل فقط */
        background: none;
        border: none;
        padding: 0;
        cursor: pointer;
        width: 44px;
        height: 44px;
        align-items: center;
        justify-content: center;
        border-radius: 50%;
        position: absolute;
        top: 15px;
        right: 15px; /* على اليمين ليكون داخل القائمة */
        transition: all 0.3s ease;
        z-index: 1000000; /* أعلى من القائمة */
    }

    .mobile-menu-close i {
        font-size: 24px;
        color: var(--header-color);
    }

    .mobile-menu-close:hover {
        background-color: rgba(51, 144, 99, 0.1);
    }

    .mobile-menu-close:hover i {
        color: var(--header-link-hover);
    }

    /* التأكد من أن القائمة مرئية */
    .main-navigation ul,
    .main-navigation .primary-menu {
        display: flex !important;
        flex-direction: column;
    }

    .primary-menu {
        flex-direction: column;
        gap: 0;
        width: 100%;
    }

    .primary-menu > li {
        width: 100%;
        border-bottom: 1px solid rgba(0, 0, 0, 0.05);
    }

    .primary-menu > li:last-child {
        border-bottom: none;
    }

    .primary-menu > li > a {
        padding: 16px 24px;
        font-size: 16px;
        border-radius: 0;
        text-align: right;
    }

    .primary-menu > li > a:hover {
        transform: none;
        background-color: rgba(51, 144, 99, 0.1);
    }

    /* القوائم الفرعية في الموبايل */
    .primary-menu .sub-menu {
        position: static;
        opacity: 1;
        visibility: visible;
        transform: none;
        border: none;
        border-radius: 0;
        box-shadow: none;
        background-color: rgba(0, 0, 0, 0.03);
        max-height: 0;
        overflow: hidden;
        transition: max-height 0.3s ease;
        padding: 0;
    }

    .primary-menu li.menu-item-has-children.is-open > .sub-menu {
        max-height: 500px;
        padding: 8px 0;
    }

    .primary-menu .sub-menu li a {
        padding: 12px 24px 12px 40px;
        font-size: 15px;
    }

    .primary-menu .sub-menu li a:hover {
        padding-right: 24px;
        padding-left: 45px;
    }

    /* البحث في الموبايل */
    .search-modal-content {
        margin: 0 20px;
        padding: 30px 20px;
    }

    .search-form-inner {
        flex-direction: column;
        gap: 15px;
    }

    .search-submit {
        width: 100%;
        padding: 14px;
    }
}

/* Small Mobile (≤ 480px) */
@media screen and (max-width: 480px) {
    :root {
        --header-height: 65px;
        --header-logo-width: 120px;
    }

    .header-container {
        padding: 0 16px;
    }

    .mobile-menu-toggle,
    .search-toggle {
        width: 40px;
        height: 40px;
    }

    .mobile-menu-toggle i {
        font-size: 22px;
    }

    .search-toggle i {
        font-size: 18px;
    }

    .main-navigation {
        width: 280px;
    }
}

/* Extra Small Mobile (≤ 360px) */
@media screen and (max-width: 360px) {
    :root {
        --header-height: 60px;
        --header-logo-width: 100px;
    }

    .header-container {
        padding: 0 12px;
    }

    .mobile-menu-toggle,
    .search-toggle {
        width: 36px;
        height: 36px;
    }

    .mobile-menu-toggle i {
        font-size: 20px;
    }

    .main-navigation {
        width: 260px;
    }
}

/* ==========================================
   Animations
   ========================================== */

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ==========================================
   Accessibility
   ========================================== */

.screen-reader-text {
    border: 0;
    clip: rect(1px, 1px, 1px, 1px);
    clip-path: inset(50%);
    height: 1px;
    margin: -1px;
    overflow: hidden;
    padding: 0;
    position: absolute;
    width: 1px;
    word-wrap: normal !important;
}

a:focus,
button:focus,
input:focus {
    outline: 2px solid var(--header-link-hover);
    outline-offset: 2px;
}
