/* ========= HEADER STYLES ========= */

.top-header {
    background: #1a1a1a;
    color: white;
    border-bottom: 3px solid #c41e3a;
    position: sticky;
    top: 0;
    z-index: 999;
    overflow: visible;
}

/*
 * نستخدم CSS Grid بدلاً من Flexbox لضمان توزيع صحيح تماماً:
 * - العمود الأول: اللوجو (عرض ثابت)
 * - العمود الثاني: القائمة (يأخذ باقي المساحة)
 * - العمود الثالث: اليوزر/الروابط (عرض ثابت)
 * في RTL: العمود الأول يكون على اليمين
 */
.header-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 20px;
    height: 64px;

    display: grid;
    grid-template-columns: auto 1fr auto auto; /* logo | menu | user | hamburger */
    align-items: center;
    gap: 0;
    overflow: visible;
}

/* ========= LOGO ========= */
.site-logo {
    font-size: 22px;
    font-weight: bold;
    color: #c41e3a;
    cursor: pointer;
    white-space: nowrap;
    display: flex;
    align-items: center;
    text-decoration: none;
    grid-column: 1;
}

.site-logo.logo-image {
    background: none;
    color: transparent;
    font-size: 0;
}

.logo-img {
    height: 48px;
    width: auto;
    max-width: 180px;
    object-fit: contain;
}

/* ========= MENU (Desktop) ========= */
.menu {
    grid-column: 2;
    display: flex;
    justify-content: center;
    overflow: hidden;
    min-width: 0;
}

.menu ul {
    list-style: none;
    display: flex;
    align-items: center;
    gap: 0;
    padding: 0;
    margin: 0;
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    min-width: 0;
}

.menu ul::-webkit-scrollbar {
    display: none;
}

.menu a {
    padding: 0 14px;
    height: 64px;
    line-height: 64px;
    color: rgba(255, 255, 255, 0.85);
    text-decoration: none;
    font-weight: 600;
    font-size: 14px;
    transition: color 0.2s, background 0.2s;
    white-space: nowrap;
    display: block;
}

.menu a:hover {
    color: #c41e3a;
    background: rgba(255, 255, 255, 0.05);
}

/* ========= USER MENU (Grid column 3) ========= */
.user-menu {
    grid-column: 3;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 8px;
}

/* ========= AUTH LINKS (Grid column 3 for guest) ========= */
.auth-links {
    grid-column: 3;
    display: flex;
    gap: 8px;
    align-items: center;
    padding: 0 8px;
}

/* ========= HAMBURGER (Grid column 4 - Mobile Only) ========= */
.hamburger {
    grid-column: 4;
    display: none;
    font-size: 26px;
    color: white;
    cursor: pointer;
    padding: 6px 10px;
    border-radius: 6px;
    transition: background 0.2s;
    line-height: 1;
    align-items: center;
    justify-content: center;
}

.hamburger:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* ========= CREATE NEWS BUTTON ========= */
.create-news-btn {
    background: #c41e3a;
    color: white !important;
    padding: 8px 16px;
    border-radius: 6px;
    text-decoration: none;
    font-weight: 700;
    font-size: 13px;
    transition: background 0.2s, transform 0.2s;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
}

.create-news-btn:hover {
    background: #a01730;
    transform: translateY(-1px);
}

/* ========= USER PROFILE ========= */
.user-profile {
    display: flex;
    align-items: center;
    gap: 8px;
    color: white;
    cursor: pointer;
    padding: 6px 8px;
    border-radius: 8px;
    transition: background 0.2s;
}

.user-profile:hover {
    background: rgba(255, 255, 255, 0.08);
}

.user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: #c41e3a;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 15px;
    flex-shrink: 0;
    overflow: hidden;
    border: 2px solid rgba(255, 255, 255, 0.2);
}

.user-profile #userName {
    font-size: 14px;
    font-weight: 600;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    /*
     * في RTL، بدون direction:ltr، الـ ellipsis يظهر في أول الاسم
     * (يعرض "...habeeb" بدلاً من "Mohamed...")
     * direction:ltr يضمن أن النقاط في آخر الاسم دائماً
     */
    direction: ltr;
    text-align: right;
}

/* ========= AUTH LINKS ========= */
.auth-links a {
    color: white;
    text-decoration: none;
    padding: 7px 16px;
    border: 1.5px solid rgba(255, 255, 255, 0.5);
    border-radius: 6px;
    transition: all 0.2s;
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
}

.auth-links a:hover {
    background: white;
    color: #c41e3a;
    border-color: white;
}

/* ========= PROFILE DROPDOWN ========= */
.user-profile-container {
    position: relative;
}

.profile-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    background: white;
    border-radius: 12px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.15);
    min-width: 220px;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px);
    transition: all 0.25s ease;
    z-index: 1000;
    overflow: hidden;
    border: 1px solid rgba(0, 0, 0, 0.06);
    /* في RTL نفتح الـ dropdown من اليسار (نحو مركز الشاشة) */
    left: 0;
    right: auto;
}

[dir="rtl"] .profile-dropdown {
    left: 0;
    right: auto;
}

.profile-dropdown.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    color: #333;
    text-decoration: none;
    transition: background-color 0.2s, color 0.2s;
    font-size: 14px;
}

.dropdown-item:hover {
    background-color: #fff5f5;
    color: #c41e3a;
}

.dropdown-item i {
    font-size: 16px;
    width: 20px;
    text-align: center;
    color: #c41e3a;
}

.dropdown-item.logout {
    color: #dc3545;
    width: 100%;
    text-align: right;
}

.dropdown-item.logout:hover {
    background-color: #fff0f0;
}

.dropdown-divider {
    height: 1px;
    background-color: #f0f0f0;
    margin: 4px 0;
}

/* ========= Responsive – Tablets (≤1024px) ========= */
@media (max-width: 1024px) {
    .menu a {
        padding: 0 10px;
        font-size: 13px;
    }

    .create-news-btn {
        padding: 6px 12px;
        font-size: 12px;
    }

    .user-profile #userName {
        max-width: 80px;
    }
}

/* ========= Responsive – Mobile (≤900px) ========= */
@media (max-width: 900px) {
    /*
     * على الموبايل نرجع لـ Flexbox لأن Grid لا يدعم
     * تغيير ترتيب العناصر بسهولة
     */
    .header-container {
        display: flex;
        padding: 0 15px;
        gap: 0;
    }

    /* في RTL الـ flex يبدأ من اليمين:
     * order:1 = أقصى اليمين
     * order:2 = الوسط
     * order:3 = أقصى اليسار
     */

    /* اللوجو على اليمين */
    .site-logo {
        order: 1;
        flex: 0 0 auto;
    }

    /* القائمة مخفية تماماً (موبايل) */
    .menu {
        order: 99;
        position: fixed;
        top: 64px;
        right: 0;
        left: 0;
        width: 100%;
        background: #1e1e1e;
        padding: 0;
        display: none;
        flex-direction: column;
        border-top: 2px solid #c41e3a;
        z-index: 998;
        box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
        max-height: calc(100vh - 64px);
        overflow-y: auto;
        overflow-x: hidden;
        min-width: unset;
    }

    .menu.open {
        display: flex;
    }

    .menu ul {
        flex-direction: column;
        width: 100%;
        overflow-x: unset;
    }

    .menu li {
        width: 100%;
        border-bottom: 1px solid rgba(255, 255, 255, 0.07);
    }

    .menu a {
        width: 100%;
        text-align: center;
        height: auto;
        line-height: 1.4;
        padding: 16px 20px;
        font-size: 15px;
    }

    /* اليوزر في الوسط */
    .user-menu {
        order: 2;
        flex: 1;
        justify-content: center;
        padding: 0;
    }

    .auth-links {
        order: 2;
        flex: 1;
        justify-content: center;
        padding: 0;
    }

    .user-profile #userName {
        display: none;
    }

    /* الهامبرجر أقصى اليسار */
    .hamburger {
        display: flex;
        order: 3;
    }

    /* الـ dropdown يفتح في منتصف الشاشة */
    .profile-dropdown {
        position: fixed;
        top: 64px;
        left: 50%;
        right: auto;
        transform: translateX(-50%) translateY(-8px);
        min-width: 220px;
        border-radius: 10px;
    }

    [dir="rtl"] .profile-dropdown {
        left: 50%;
        right: auto;
        transform: translateX(-50%) translateY(-8px);
    }

    .profile-dropdown.show {
        opacity: 1;
        visibility: visible;
        transform: translateX(-50%) translateY(0);
    }

    [dir="rtl"] .profile-dropdown.show {
        transform: translateX(-50%) translateY(0);
    }
}

/* ========= Responsive – Small Mobile (≤480px) ========= */
@media (max-width: 480px) {
    .header-container {
        padding: 0 10px;
        height: 56px;
    }

    .menu {
        top: 56px;
        max-height: calc(100vh - 56px);
    }

    .logo-img {
        height: 36px;
        max-width: 110px;
    }

    .create-news-btn {
        display: none;
    }

    .user-avatar {
        width: 32px;
        height: 32px;
        font-size: 13px;
    }

    .hamburger {
        font-size: 22px;
        padding: 5px 8px;
    }

    .auth-links a {
        padding: 5px 10px;
        font-size: 12px;
    }

    .profile-dropdown {
        top: 56px;
        min-width: 200px;
    }

    [dir="rtl"] .profile-dropdown {
        left: 50%;
        right: auto;
    }
}