/**
 * Modern RTL Sidebar Navigation — پورتال دبیرستان مفید
 * سیستم طراحی ماژولار مبتنی بر Design Tokens، ریسپانسیو و دسترسی‌پذیر
 */

/* ==========================================================================
   ۱. متغیرهای طراحی (Design Tokens)
   ========================================================================== */
:root {
    /* ابعاد سایدبار */
    --sidebar-w-expanded: 275px;
    --sidebar-w-collapsed: 76px;
    --topbar-height: 64px;
    --sidebar-ease: cubic-bezier(0.4, 0, 0.2, 1);
    --sidebar-transition: 0.25s var(--sidebar-ease);

    /* رنگ‌های سایدبار (برندینگ سرمه‌ای و فیروزه‌ای مفید) */
    --sidebar-bg: #0c2340;
    --sidebar-bg-surface: #143258;
    --sidebar-bg-hover: rgba(255, 255, 255, 0.07);
    --sidebar-text: #f1f5f9;
    --sidebar-text-muted: #94a3b8;
    --sidebar-border: rgba(255, 255, 255, 0.08);

    /* آیتم فعال */
    --sidebar-active-bg: rgba(13, 148, 136, 0.22);
    --sidebar-active-border: #14b8a6;
    --sidebar-active-text: #2dd4bf;
    --sidebar-active-glow: rgba(20, 184, 166, 0.25);

    /* نشانگرها (Badges) */
    --badge-danger-bg: #ef4444;
    --badge-danger-text: #ffffff;
    --badge-warning-bg: #f59e0b;
    --badge-warning-text: #1e293b;
    --badge-success-bg: #10b981;
    --badge-success-text: #ffffff;
    --badge-primary-bg: #3b82f6;
    --badge-primary-text: #ffffff;

    /* تاپ‌بار بالای محتوا (هماهنگ با هویت بصری سرمه‌ای مفید) */
    --topbar-bg: #0c2340;
    --topbar-border: rgba(255, 255, 255, 0.08);
    --topbar-text: #ffffff;
}

/* جلوگیری سراسری از اسکرول افقی روی کل صفحه */
html, body {
    width: 100% !important;
    max-width: 100% !important;
    overflow-x: hidden !important;
    margin: 0 !important;
    padding: 0 !important;
    position: relative;
}

/* ==========================================================================
   ۲. ساختار کلی پوسته برنامه (App Shell Layout)
   ========================================================================== */
.app-shell.has-sidebar {
    min-height: 100vh;
    background-color: var(--bg-body, #f8fafc);
    position: relative;
    width: 100% !important;
    max-width: 100% !important;
    overflow-x: hidden;
}

/* محفظه محتوای صفحه — پر کردن قطعی ۱۰۰٪ عرض با پدینگ راست معادل سایدبار */
.app-content-wrapper {
    width: 100% !important;
    max-width: 100% !important;
    min-height: 100vh;
    margin: 0 !important;
    padding-right: var(--sidebar-w-expanded, 275px);
    padding-left: 0 !important;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    transition: padding-right var(--sidebar-transition);
    overflow-x: hidden;
}

.app-shell.sidebar-collapsed .app-content-wrapper {
    padding-right: var(--sidebar-w-collapsed, 76px);
}

/* ==========================================================================
   ۳. نوار ناوبری کناری (Sidebar)
   ========================================================================== */
.app-sidebar {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: var(--sidebar-w-expanded);
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    border-left: 1px solid var(--sidebar-border);
    display: flex;
    flex-direction: column;
    z-index: 1000;
    transition: width var(--sidebar-transition), transform var(--sidebar-transition);
    user-select: none;
    box-shadow: -4px 0 25px rgba(0, 0, 0, 0.15);
    padding-bottom: env(safe-area-inset-bottom, 0);
}

.app-shell.sidebar-collapsed .app-sidebar {
    width: var(--sidebar-w-collapsed);
}

/* --- سربرگ سایدبار --- */
.sidebar-header {
    height: var(--topbar-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.25rem;
    border-bottom: 1px solid var(--sidebar-border);
    flex-shrink: 0;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    text-decoration: none;
    color: inherit;
    min-width: 0;
    overflow: hidden;
}

.sidebar-logo {
    height: 40px;
    width: auto;
    max-width: 44px;
    object-fit: contain;
    filter: drop-shadow(0 2px 6px rgba(0,0,0,0.3));
    flex-shrink: 0;
}

.sidebar-emblem {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: linear-gradient(135deg, #0d9488, #1e3a5f);
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid #f59e0b;
    flex-shrink: 0;
}

.sidebar-brand-text {
    display: flex;
    flex-direction: column;
    transition: opacity var(--sidebar-transition);
    white-space: nowrap;
}

.brand-title {
    font-size: 0.98rem;
    font-weight: 800;
    color: #ffffff;
    letter-spacing: -0.2px;
}

.brand-subtitle {
    font-size: 0.72rem;
    color: var(--sidebar-text-muted);
}

.sidebar-collapse-btn,
.sidebar-close-mobile-btn {
    background: var(--sidebar-bg-surface);
    color: var(--sidebar-text-muted);
    border: 1px solid var(--sidebar-border);
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
}

.sidebar-collapse-btn:hover,
.sidebar-close-mobile-btn:hover {
    color: #ffffff;
    background: rgba(255, 255, 255, 0.12);
}

.sidebar-close-mobile-btn {
    display: none;
}

.app-shell.sidebar-collapsed .icon-collapse-toggle {
    transform: rotate(180deg);
}

/* --- جعبه جستجوی سریع در منو --- */
.sidebar-search-box {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--sidebar-border);
    flex-shrink: 0;
}

.search-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    background: var(--sidebar-bg-surface);
    border: 1px solid var(--sidebar-border);
    border-radius: 8px;
    padding: 0 0.6rem;
    height: 38px;
    transition: border-color 0.2s;
}

.search-input-wrapper:focus-within {
    border-color: var(--teal, #0d9488);
    box-shadow: 0 0 0 2px rgba(13, 148, 136, 0.2);
}

.search-icon {
    display: flex;
    align-items: center;
    color: var(--sidebar-text-muted);
    margin-left: 0.5rem;
    flex-shrink: 0;
}

.sidebar-search-input {
    background: transparent;
    border: none;
    outline: none;
    color: var(--sidebar-text);
    font-family: inherit;
    font-size: 0.85rem;
    width: 100%;
}

.sidebar-search-input::placeholder {
    color: #64748b;
}

.sidebar-search-kbd {
    background: rgba(255, 255, 255, 0.1);
    color: var(--sidebar-text-muted);
    font-size: 0.72rem;
    font-family: monospace;
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    line-height: 1;
}

.sidebar-search-no-result {
    font-size: 0.8rem;
    color: #f87171;
    text-align: center;
    margin-top: 0.5rem;
}

/* --- بخش ناوبری اسکرول‌خور --- */
.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0.75rem 0.6rem;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.15) transparent;
}

.sidebar-nav::-webkit-scrollbar {
    width: 4px;
}
.sidebar-nav::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 4px;
}

.sidebar-nav-group {
    margin-bottom: 1.1rem;
}

.sidebar-group-heading {
    padding: 0.4rem 0.85rem;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    color: #64748b;
    letter-spacing: 0.5px;
}

.sidebar-group-items {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.sidebar-item-wrap {
    position: relative;
}

/* --- آیتم ناوبری --- */
.sidebar-nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.62rem 0.85rem;
    border-radius: 10px;
    color: var(--sidebar-text-muted);
    text-decoration: none;
    font-size: 0.88rem;
    font-weight: 600;
    position: relative;
    transition: background 0.18s, color 0.18s;
    min-height: 44px; /* دسترس‌پذیری لمسی حداقل ۴۴px */
}

.sidebar-nav-item:hover {
    color: #ffffff;
    background: var(--sidebar-bg-hover);
}

.sidebar-nav-item:focus-visible {
    outline: 2px solid var(--teal, #0d9488);
    outline-offset: 1px;
}

/* وضعیت فعال (Active Item) */
.sidebar-nav-item.active {
    color: var(--sidebar-active-text);
    background: var(--sidebar-active-bg);
    font-weight: 700;
}

.sidebar-nav-item.active::before {
    content: '';
    position: absolute;
    right: -0.6rem;
    top: 6px;
    bottom: 6px;
    width: 4px;
    background: var(--sidebar-active-border);
    border-radius: 4px 0 0 4px;
    box-shadow: 0 0 10px var(--sidebar-active-glow);
}

.item-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: transform 0.2s;
}

.sidebar-nav-item:hover .item-icon {
    transform: scale(1.08);
}

.item-title {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: opacity var(--sidebar-transition);
}

/* نشانگرها (Badges) */
.item-badge {
    font-size: 0.72rem;
    font-weight: 800;
    padding: 0.2rem 0.55rem;
    border-radius: 12px;
    line-height: 1;
    white-space: nowrap;
    letter-spacing: -0.2px;
}

.badge-danger {
    background: var(--badge-danger-bg);
    color: var(--badge-danger-text);
    box-shadow: 0 2px 6px rgba(239, 68, 68, 0.4);
}

.badge-warning {
    background: var(--badge-warning-bg);
    color: var(--badge-warning-text);
}

.badge-success {
    background: var(--badge-success-bg);
    color: var(--badge-success-text);
}

.badge-primary {
    background: var(--badge-primary-bg);
    color: var(--badge-primary-text);
}

/* تولتیپ در حالت جمع‌شده */
.item-tooltip {
    display: none;
    position: absolute;
    right: calc(100% + 12px);
    top: 50%;
    transform: translateY(-50%);
    background: #0f172a;
    color: #ffffff;
    font-size: 0.82rem;
    font-weight: 600;
    padding: 0.45rem 0.85rem;
    border-radius: 8px;
    white-space: nowrap;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.35);
    border: 1px solid rgba(255, 255, 255, 0.1);
    z-index: 1100;
    pointer-events: none;
}

.item-tooltip::after {
    content: '';
    position: absolute;
    right: -5px;
    top: 50%;
    transform: translateY(-50%);
    border-width: 5px 0 5px 5px;
    border-style: solid;
    border-color: transparent transparent transparent #0f172a;
}

/* --- بخش پایین سایدبار (پروفایل کاربر و خروج) --- */
.sidebar-footer {
    padding: 0.85rem 1rem;
    border-top: 1px solid var(--sidebar-border);
    flex-shrink: 0;
    background: rgba(0, 0, 0, 0.15);
}

.sidebar-user-card {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 0;
}

.user-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: linear-gradient(135deg, #0d9488, #2563eb);
    color: #ffffff;
    font-weight: 800;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.95rem;
    border: 2px solid rgba(255, 255, 255, 0.2);
    flex-shrink: 0;
}

.user-meta {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: opacity var(--sidebar-transition);
}

.user-name {
    font-size: 0.86rem;
    font-weight: 700;
    color: #ffffff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-role {
    font-size: 0.72rem;
    color: var(--sidebar-text-muted);
    white-space: nowrap;
}

.sidebar-logout-btn {
    width: 34px;
    height: 34px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fca5a5;
    background: rgba(239, 68, 68, 0.12);
    border: 1px solid rgba(239, 68, 68, 0.25);
    transition: all 0.2s;
    flex-shrink: 0;
    text-decoration: none;
}

.sidebar-logout-btn:hover {
    color: #ffffff;
    background: #ef4444;
}

/* ==========================================================================
   ۴. حالت جمع‌شده (Collapsed Sidebar Mode)
   ========================================================================== */
.app-shell.sidebar-collapsed .sidebar-brand-text,
.app-shell.sidebar-collapsed .item-title,
.app-shell.sidebar-collapsed .sidebar-group-heading,
.app-shell.sidebar-collapsed .user-meta,
.app-shell.sidebar-collapsed .sidebar-search-kbd,
.app-shell.sidebar-collapsed .sidebar-search-input {
    display: none !important;
}

.app-shell.sidebar-collapsed .sidebar-header {
    justify-content: center;
    padding: 0;
}

.app-shell.sidebar-collapsed .sidebar-logo {
    display: none;
}

.app-shell.sidebar-collapsed .sidebar-collapse-btn {
    margin: 0 auto;
}

.app-shell.sidebar-collapsed .search-input-wrapper {
    justify-content: center;
    padding: 0;
    cursor: pointer;
}

.app-shell.sidebar-collapsed .search-icon {
    margin: 0;
}

.app-shell.sidebar-collapsed .sidebar-nav-item {
    justify-content: center;
    padding: 0.7rem 0;
}

.app-shell.sidebar-collapsed .sidebar-nav-item:hover .item-tooltip {
    display: block;
}

.app-shell.sidebar-collapsed .item-badge {
    position: absolute;
    top: 4px;
    left: 8px;
    padding: 0.2rem 0.35rem;
    font-size: 0.65rem;
    border-radius: 8px;
}

.app-shell.sidebar-collapsed .sidebar-footer {
    padding: 0.85rem 0.5rem;
}

.app-shell.sidebar-collapsed .sidebar-user-card {
    justify-content: center;
}

.app-shell.sidebar-collapsed .sidebar-logout-btn {
    display: none;
}

/* ==========================================================================
   ۵. نوار بالایی مدرن (App Topbar)
   ========================================================================== */
.app-topbar {
    height: var(--topbar-height, 66px);
    background: linear-gradient(90deg, #091a30 0%, #0c2340 50%, #0e2a4d 100%);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.75rem;
    position: sticky;
    top: 0;
    z-index: 40;
    box-shadow: 0 4px 24px -2px rgba(8, 20, 37, 0.5);
    width: 100%;
    box-sizing: border-box;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    min-width: 0;
}

.topbar-mobile-btn {
    display: inline-flex;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.18);
    width: 40px;
    height: 40px;
    border-radius: 10px;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: #ffffff !important;
    outline: none !important;
    appearance: none !important;
    -webkit-appearance: none !important;
    transition: all 0.2s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    flex-shrink: 0;
    padding: 0;
}

.topbar-mobile-btn svg {
    stroke: #ffffff !important;
    display: block;
    transition: transform 0.2s ease;
}

.topbar-mobile-btn:hover {
    background: rgba(45, 212, 191, 0.2);
    border-color: #2dd4bf;
    color: #2dd4bf !important;
}

.topbar-mobile-btn:hover svg {
    stroke: #2dd4bf !important;
}

.topbar-page-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.topbar-title {
    font-size: 1.05rem;
    font-weight: 800;
    color: #ffffff;
    margin: 0;
    line-height: 1.3;
    display: flex;
    align-items: center;
    gap: 0.45rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.topbar-title .title-accent {
    color: #2dd4bf;
    font-weight: 900;
    text-shadow: 0 0 16px rgba(45, 212, 191, 0.35);
}

.topbar-breadcrumb {
    font-size: 0.76rem;
    color: #94a3b8;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    white-space: nowrap;
}

.topbar-breadcrumb::before {
    content: '';
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #14b8a6;
    box-shadow: 0 0 8px #14b8a6;
    flex-shrink: 0;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-shrink: 0;
}

.topbar-action-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.16);
    padding: 0.5rem 0.95rem;
    border-radius: 10px;
    font-size: 0.84rem;
    font-weight: 600;
    color: #ffffff !important;
    cursor: pointer;
    text-decoration: none !important;
    transition: all 0.22s cubic-bezier(0.4, 0, 0.2, 1);
    white-space: nowrap;
    line-height: 1;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

.topbar-action-btn span {
    color: #ffffff !important;
    font-weight: 700 !important;
    display: inline-block;
    line-height: 1;
}

.topbar-action-btn:hover span {
    color: #ffffff !important;
}

.topbar-action-btn svg {
    stroke: #2dd4bf !important;
    display: inline-block;
    flex-shrink: 0;
    transition: transform 0.22s ease, stroke 0.22s ease;
}

.topbar-action-btn:hover {
    background: rgba(45, 212, 191, 0.16) !important;
    border-color: rgba(45, 212, 191, 0.5) !important;
    color: #ffffff !important;
    box-shadow: 0 4px 14px rgba(45, 212, 191, 0.25);
    transform: translateY(-1px);
}

.topbar-action-btn:hover svg {
    stroke: #5eead4 !important;
    transform: scale(1.12);
}

.topbar-action-btn:active {
    transform: translateY(0);
}

/* ==========================================================================
   ۶. واکنش‌گرایی (Responsive Breakpoints)
   ========================================================================== */

/* موبایل (زیر ۷۶۸px) */
@media (max-width: 768px) {
    .app-content-wrapper {
        padding-right: 0 !important;
        padding-left: 0 !important;
        margin: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
    }

    .app-sidebar {
        position: fixed !important;
        top: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: min(85vw, 300px) !important;
        transform: translateX(100%) !important;
        visibility: hidden !important;
        pointer-events: none !important;
        transition: transform var(--sidebar-transition), visibility var(--sidebar-transition) !important;
        box-shadow: -10px 0 35px rgba(0, 0, 0, 0.4) !important;
        z-index: 10000 !important;
    }

    .app-shell.sidebar-mobile-open .app-sidebar {
        transform: translateX(0) !important;
        visibility: visible !important;
        pointer-events: auto !important;
    }

    .sidebar-collapse-btn {
        display: none !important;
    }

    .sidebar-close-mobile-btn {
        display: flex !important;
    }

    .topbar-mobile-btn {
        display: flex !important;
    }

    .sidebar-backdrop {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(12, 35, 64, 0.7);
        backdrop-filter: blur(4px);
        -webkit-backdrop-filter: blur(4px);
        z-index: 9990;
        animation: fadeIn 0.2s ease-out;
    }

    .app-shell.sidebar-mobile-open .sidebar-backdrop {
        display: block !important;
    }

    .app-topbar {
        padding: 0 0.85rem !important;
        height: 60px !important;
    }

    .topbar-mobile-btn {
        background: #ffffff !important;
        border: 1px solid #ffffff !important;
        color: #0c2340 !important;
        box-shadow: 0 3px 12px rgba(0, 0, 0, 0.35) !important;
    }

    .topbar-mobile-btn svg {
        stroke: #0c2340 !important;
        stroke-width: 2.5 !important;
    }

    .topbar-mobile-btn:hover,
    .topbar-mobile-btn:active {
        background: #f1f5f9 !important;
        border-color: #2dd4bf !important;
    }

    .topbar-mobile-btn:hover svg,
    .topbar-mobile-btn:active svg {
        stroke: #0d9488 !important;
    }
    
    .topbar-breadcrumb {
        display: none !important;
    }

    .topbar-title {
        font-size: 0.92rem !important;
    }

    .topbar-left {
        gap: 0.45rem !important;
    }

    .topbar-action-btn {
        padding: 0 !important;
        width: 38px !important;
        height: 38px !important;
        justify-content: center !important;
        border-radius: 10px !important;
    }

    .topbar-action-btn span {
        display: none !important;
    }

    .topbar-action-btn svg {
        width: 18px !important;
        height: 18px !important;
    }
}

/* ==========================================================================
   ۷. دسترسی‌پذیری و انیمیشن‌های کاربرپسند (Accessibility)
   ========================================================================== */
@media (prefers-reduced-motion: reduce) {
    .app-sidebar,
    .app-content-wrapper,
    .icon-collapse-toggle,
    .item-icon,
    .sidebar-backdrop {
        transition: none !important;
        animation: none !important;
    }
}

/* ==========================================================================
   ۸. یکپارچه‌سازی محتوای اصلی داشبورد و سایدبار (Main Content Integration)
   ========================================================================== */
.app-main {
    flex: 1;
    width: 100%;
    box-sizing: border-box;
    min-height: calc(100vh - var(--topbar-height) - 60px);
}

.main-container {
    width: 100%;
    max-width: 1400px;
    margin: 0 auto;
    padding: 1.8rem 1.5rem 3rem 1.5rem;
    box-sizing: border-box;
}

@media (max-width: 768px) {
    .main-container {
        padding: 1rem 0.85rem 2rem 0.85rem;
    }
}


