/* =============================================
   MAGIC NAVBAR - تصميم احترافي مع تأثيرات متقدمة
   ============================================= */

:root {
    --magic-nav-height: 70px;
    /* القيمة الوحيدة المطلوبة */
}

/* === الشريط العلوي الأساسي === */
.creative-navbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: var(--magic-nav-height);
    background: var(--nav-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border-color-light);
    border-radius: 0;
    box-shadow: var(--shadow-md);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 40px;
    z-index: 1000;
    opacity: 0;
    transform: translateY(-100px);
    animation: slideDownFade 1s cubic-bezier(0.19, 1, 0.22, 1) forwards;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}


/* 1. الهوية (الشعار) */
.school-branding {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-main);
    z-index: 1002;
    opacity: 0;
    animation: fadeIn 0.8s ease forwards 0.5s;
    flex-shrink: 0;
    min-width: 0;
    max-width: clamp(180px, 28vw, 440px);
}

.school-name {
    min-width: 0;
    max-width: 100%;
}

.logo-icon {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, var(--primary-grad), var(--secondary-grad));
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    color: var(--text-white);
    font-size: 1.1rem;
    box-shadow: 0 4px 10px var(--accent-shadow);
}

.school-name h2 {
    font-size: 1rem;
    font-weight: 800;
    margin: 0;
    color: var(--text-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

.school-name span {
    font-size: 0.7rem;
    color: var(--text-light);
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

/* 2. الحاوية الكبرى للقائمة والأزرار */
.nav-container {
    display: flex;
    align-items: center;
    flex-grow: 1;
    justify-content: space-between;
}

/* Wrapper للقائمة والمؤشر */
.nav-links-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    margin: 0 auto;
}

/* القائمة */
.nav-links {
    display: flex;
    list-style: none;
    position: relative;
    margin: 0;
    padding: 0;
}

.nav-links li {
    position: relative;
    padding: 0 15px;
    height: 45px;
    z-index: 2;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    white-space: nowrap;
    opacity: 0;
    transform: translateY(-20px);
    animation: itemEntrance 0.5s ease forwards;
    /* إزالة أي outline أو border غير مرغوب */
    outline: none;
    border: none;
}

.nav-links li:nth-child(2) {
    animation-delay: 0.6s;
}

.nav-links li:nth-child(3) {
    animation-delay: 0.7s;
}

.nav-links li:nth-child(4) {
    animation-delay: 0.8s;
}

.nav-links li:nth-child(5) {
    animation-delay: 0.9s;
}

.nav-links li:nth-child(6) {
    animation-delay: 1.0s;
}

.nav-links li:nth-child(7) {
    animation-delay: 1.1s;
}

.nav-links li a {
    text-decoration: none;
    color: var(--text-light);
    font-weight: 600;
    font-size: 1rem;
    display: flex;
    gap: 8px;
    align-items: center;
    width: 100%;
    justify-content: center;
    height: 100%;
    transition: 0.3s;
    /* إزالة أي outline أو border غير مرغوب */
    outline: none;
    border: none;
    box-shadow: none;
}

.nav-links li.active a {
    color: var(--text-white);
}

/* المؤشر (الكبسولة) */
.indicator {
    position: absolute;
    top: 0;
    left: 0;
    height: 45px;
    background: linear-gradient(90deg, var(--primary-grad), var(--secondary-grad));
    border-radius: 30px;
    opacity: 0;
    transform: scale(0.9);
    z-index: 1;
    box-shadow: 0 4px 15px var(--accent-shadow);
    pointer-events: none;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    /* التأكد من عدم وجود border أو outline */
    border: none;
    outline: none;
    /* تحسين border-radius لضمان الحواف المنحنية */
    -webkit-border-radius: 30px;
    -moz-border-radius: 30px;
    overflow: hidden;
}

/* الأزرار (Actions) */
.nav-actions {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-shrink: 0;
}

.action-btn {
    width: 40px;
    height: 40px;
    min-width: 40px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1rem;
    transition: width 0.3s, height 0.3s, border-radius 0.3s, background-color 0.3s, transform 0.3s;
    background: transparent;
    color: var(--text-main);
    border: 1px solid var(--border-color-light);
    flex-shrink: 0;
    opacity: 0;
    transform: translateY(-20px);
    animation: itemEntrance 0.5s ease forwards 1.3s;
    text-decoration: none;
}

.action-btn i {
    /* Enhanced transition for transform + color */
    transition: transform 0.35s cubic-bezier(0.68, -0.55, 0.27, 1.55),
        color 0.35s ease;
    /* display: inline-block is REQUIRED for transform to work on inline elements */
    display: inline-block;
}

.action-btn.admin-btn {
    background: linear-gradient(135deg, var(--danger-color), var(--danger-color-hover));
    color: var(--text-white);
    border: none;
    box-shadow: 0 4px 10px rgba(var(--danger-color-rgb), 0.2);
    animation-delay: 1.4s;
}

.action-btn:hover {
    transform: translateY(-2px) scale(1.05);
}

/* زر الهامبرغر */
.hamburger {
    display: none;
    flex-direction: column;
    gap: 5px;
    cursor: pointer;
    z-index: 1002;
    padding: 5px;
    opacity: 0;
    animation: fadeIn 0.8s ease forwards 1s;
}

.hamburger span {
    width: 25px;
    height: 3px;
    background: var(--text-main);
    border-radius: 5px;
    transition: 0.3s;
}

@keyframes slideDownFade {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes itemEntrance {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

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

/* خلفية التعتيم */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(var(--black-rgb), 0.35);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 998;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.28s ease, visibility 0.28s ease;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.overlay.active {
    opacity: 1;
    visibility: visible;
}

/* =========================================
   Mobile Styles
========================================= */
@media (max-width: 992px) {
    .creative-navbar {
        padding: 0 15px;
    }

    .hamburger {
        display: flex;
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
        min-width: 44px;
        min-height: 44px;
        align-items: center;
        justify-content: center;
    }

    /* انزلاق بـ transform فقط (GPU) — كان right يتغير دون transition فيسبب قفزات */
    .nav-container {
        position: fixed;
        top: 0;
        /* يبقى من جهة اليمين (الهامبرغر) بغض النظر عن dir للصفحة */
        right: 0;
        left: auto;
        width: min(280px, 88vw);
        max-width: 100%;
        height: 100dvh;
        height: 100svh;
        background: var(--sidebar-bg);
        backdrop-filter: blur(25px);
        -webkit-backdrop-filter: blur(25px);
        flex-direction: column;
        justify-content: flex-start;
        align-items: flex-start;
        padding: calc(var(--magic-nav-height, 70px) + 12px) 20px max(20px, env(safe-area-inset-bottom, 0px)) 24px;
        border-radius: 24px 0 0 24px;
        transition: transform 0.32s cubic-bezier(0.25, 0.8, 0.25, 1);
        z-index: 999;
        box-shadow: -4px 0 24px rgba(var(--black-rgb), 0.12);
        border-left: 1px solid var(--border-color-light);
        transform: translateX(100%);
        visibility: visible;
    }

    .nav-container.active {
        transform: translateX(0);
    }

    .nav-links {
        flex-direction: column;
        width: 100%;
        margin: 0;
        gap: 15px;
    }

    .nav-links li {
        width: 100%;
        padding: 0;
        min-height: 48px;
        height: auto;
        justify-content: flex-start;
        opacity: 1;
        transform: none;
        animation: none;
    }

    .nav-links li a {
        justify-content: flex-start;
        align-items: center;
        gap: 0.65rem;
        padding-block: 12px;
        padding-inline: 14px 12px;
        font-size: 1.05rem;
        width: 100%;
        min-height: 48px;
        border-radius: 14px;
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
        cursor: pointer;
    }

    /* المؤشر: إخفاء كامل على الموبايل (تجنب وميض مع JS) */
    .indicator {
        display: none;
    }

    .nav-links li.active a {
        color: var(--primary-grad);
        font-weight: 800;
        background: rgba(var(--primary-color-rgb), 0.1);
    }

    .nav-actions {
        width: 100%;
        margin-top: auto;
        flex-direction: row;
        justify-content: space-between;
        padding-top: 20px;
        border-top: 1px solid var(--border-color);
    }

    .action-btn {
        width: 48%;
        min-height: 48px;
        height: auto;
        border-radius: 15px;
        gap: 10px;
        font-weight: 700;
        opacity: 1;
        transform: none;
        animation: none;
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
    }

    .action-btn::after {
        font-size: 0.9rem;
    }

    .theme-btn::after {
        content: 'المظهر';
    }

    .admin-btn::after {
        content: 'الإدارة';
    }

    .hamburger.active span:nth-child(1) {
        transform: rotate(45deg) translate(5px, 6px);
    }

    .hamburger.active span:nth-child(2) {
        opacity: 0;
    }

    .hamburger.active span:nth-child(3) {
        transform: rotate(-45deg) translate(5px, -6px);
    }
}

@media (max-width: 992px) and (prefers-reduced-motion: reduce) {
    .nav-container {
        transition: none;
    }

    .overlay {
        transition: opacity 0.12s ease, visibility 0.12s ease;
    }
}

/* ⚡ FIXED MOBILE NAVBAR: Native App Feel */
@media (max-width: 768px) {
    .creative-navbar {
        top: 0;
        width: 100%;
        border-radius: 0;
        padding: 0 20px;
        background: rgba(var(--white-rgb), 0.95);
        /* More solid for app feel */
    }

    [data-theme="dark"] .creative-navbar {
        background: rgba(var(--black-rgb), 0.95);
    }

    .school-name span {
        display: none;
    }
}

@media (max-width: 1200px) {
    .school-branding {
        max-width: clamp(150px, 24vw, 300px);
    }
}

/* ===== الثيم الليلي للنافبار ===== */
body.theme-night .creative-navbar {
    background: var(--nav-bg);
    border-bottom: 1px solid var(--border-color-light);
    box-shadow: var(--shadow-md);
}

body.theme-night .school-branding {
    color: var(--text-main);
}

body.theme-night .school-name h2 {
    color: var(--text-main);
}

body.theme-night .school-name span {
    color: var(--text-light);
}

body.theme-night .nav-links li a {
    color: var(--text-light);
}

body.theme-night .nav-links li.active a {
    color: var(--text-white);
}

body.theme-night .indicator {
    background: linear-gradient(90deg, var(--primary-color), var(--secondary-color));
    box-shadow: 0 4px 15px rgba(var(--primary-color-rgb), 0.4);
}

body.theme-night .action-btn {
    color: var(--text-main);
    border-color: var(--border-color-light);
}

body.theme-night .action-btn:hover {
    background: rgba(var(--primary-color-rgb), 0.2);
}

body.theme-night .hamburger span {
    background: var(--text-main);
}

body.theme-night .overlay {
    background: var(--overlay-bg);
}

@media (max-width: 992px) {
    body.theme-night .nav-container {
        background: var(--sidebar-bg);
        border: 1px solid var(--border-color-light);
        box-shadow: var(--shadow-lg);
    }

    body.theme-night .nav-links li.active a {
        color: var(--primary-light);
    }

    body.theme-night .nav-actions {
        border-top: 1px solid var(--border-color-light);
    }
}