/* =========================================================
   [1] تنسيقات عامة للصفحة
   - ضبط الارتفاع الأساسي
   - إزالة padding/margin الافتراضي
========================================================= */
html,
body {
    height: 100%;
    padding: 0;
    margin: 0;
}

body {
    background-color: #f8f9fa;
    padding-top: 60px !important;
    /* قيمة افتراضية عامة قبل تفعيل layout الإدارة */
}

body.guest-layout {
    padding-top: 0 !important;
}

/* =========================================================
   [2] الخطوط
========================================================= */
@font-face {
    font-family: 'Tajawal';
    src: url('../fonts/Tajawal/Tajawal-Regular.ttf') format('truetype');
}

@font-face {
    font-family: 'Tajawal';
    src: url('../fonts/Tajawal/Tajawal-Bold.ttf') format('truetype');
    font-weight: bold;
}

@font-face {
    font-family: 'Rubik';
    src: url('../fonts/rubik/Rubik-Regular.ttf') format('truetype');
}

/* =========================================================
   [3] عناصر مشتركة
   - أيقونات الهيدر
   - فقاعات الأيقونات
   - أنيميشن زر القائمة
========================================================= */
.icon-bubble {
    width: 32px;
    height: 32px;
    border-radius: 9999px;
    background-color: #dbeafe;
    color: #2563eb;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
}

.notify-badge-small {
    width: 14px;
    height: 14px;
    font-size: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #0d6efd;
    color: #fff;
    border-radius: 50%;
    position: absolute;
    top: 0;
    left: 100%;
    transform: translate(-73%, -13%);
}

/* حالة زر القائمة عند فتح السايدبار */
.sidebar-open {
    background-color: #d6b2b212 !important;
}

.icon-bubble.active {
    background-color: #dc3545 !important;
}

.icon-red {
    color: #ffffff !important;
}

.icon-rotate {
    animation: rotateIcon 0.3s ease;
}

@keyframes rotateIcon {
    from {
        transform: rotate(0deg);
        opacity: 0.5;
    }

    to {
        transform: rotate(180deg);
        opacity: 1;
    }
}

/* =========================================================
   [4] الهيدر الرئيسي
   - هيدر ثابت بالأعلى
   - لا نغيّر المنطق، فقط نحافظ على التنسيق
========================================================= */
#main-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 999;
    background-color: #fff;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
    padding: 12px 20px;
    min-height: 74px;
}

#main-header .navbar-brand.brand-link {
    display: flex;
    align-items: center;
    gap: 10px;
}

#main-header .img-logo {
    width: 35px;
    height: 35px;
    object-fit: contain;
    margin-right: 0;
    flex-shrink: 0;
}

#main-header .brand-text-wrap {
    line-height: 1.1;
}

#main-header .textlogo {
    font-size: 1.1rem;
    font-weight: 800;
    margin: 0;
    color: #1f2937;
    font-family: 'Tajawal', sans-serif;
}

#main-header .text-span {
    font-size: 0.7rem;
    margin-top: 4px;
    color: #6b7280 !important;
    font-family: 'Rubik', sans-serif;
    font-weight: 500;
    direction: ltr;
}

#main-header .img-profile {
    width: 30px;
    height: 30px;
    max-height: 100%;
    max-width: 100%;
    object-fit: cover;
    border-radius: 50%;
    cursor: pointer;
    pointer-events: none;
    user-select: none;
}

/* =========================================================
   [5] أسهم القوائم الداخلية Submenu
   - دوران مرن حسب aria-expanded
========================================================= */
.arrow-icon,
.arrow-icon2 {
    transition: transform 0.3s ease;
}

[aria-expanded="true"] .arrow-icon {
    transform: rotate(90deg);
}

[aria-expanded="true"] .arrow-icon2 {
    transform: rotate(-90deg);
}

[aria-expanded="false"] .arrow-icon2 {
    transform: rotate(0deg);
}

/* =========================================================
   [6] السايدبار - الشكل العام
   الهيكل المعتمد:
   #sidebar
   ├─ .sidebar-header
   ├─ .sidebar-content  => هو الوحيد الذي يعمل scroll
   └─ .Footer-bar       => يثبت بالأسفل بـ flex فقط
========================================================= */
#sidebar {
    margin-top: 0;
    padding: 0;
    background-color: #fff;
    box-shadow: -2px 0 8px rgba(0, 0, 0, 0.05);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: calc(100vh - 74px);
    height: calc(100vh - 74px);
}

#sidebar .sidebar-header {
    flex-shrink: 0;
    background-color: #fff;
}

/* منطقة القوائم فقط هي التي تتحمل التمرير */
#sidebar .sidebar-content {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
}

/* صورة المستخدم داخل السايدبار */
#sidebar .img-profile {
    width: 30px;
    height: 30px;
    max-height: 100%;
    max-width: 100%;
    object-fit: cover;
    border-radius: 50%;
    cursor: pointer;
    pointer-events: none;
    user-select: none;
}

/* خلفية الأزرار الفرعية */
#sidebar .bg-gainsboro {
    background-color: #f5f5f4;
}

.btn.bg-gainsboro:hover,
.btn.bg-gainsboro:active,
.btn.bg-gainsboro:focus-within {
    background-color: #dee2e6 !important;
}

/* =========================================================
   [7] روابط السايدبار
   - تنسيق عام للروابط
   - الحفاظ على active state من Laravel كما هو
========================================================= */
#sidebar a {
    color: inherit;
    text-decoration: none;
    border-bottom: 0;
}

#sidebar a:hover {
    text-decoration: none;
}

.sidebar-link,
.sidebar-sublink {
    display: flex;
    align-items: center;
    text-decoration: none;
    border-radius: 0.5rem;
    transition: background-color 0.2s ease, color 0.2s ease;
}

.sidebar-link {
    padding: 0.6rem 0.75rem;
}

.sidebar-sublink {
    padding: 0.5rem 0.75rem;
    color: #6c757d;
}

.sidebar-link:not(.active):hover,
.sidebar-sublink:not(.active):hover {
    background-color: #eef2f7;
}

/* =========================================================
   [8] أزرار collapse داخل السايدبار
========================================================= */
.sidebar-collapse-btn {
    background-color: #f5f5f4;
    border: 0;
    border-radius: 0.5rem;
    color: #595454;
    text-align: inherit;
    box-shadow: none !important;
}

.sidebar-collapse-btn:hover {
    background-color: #eef2f7;
}

.sidebar-collapse-btn:focus,
.sidebar-collapse-btn:active {
    box-shadow: none !important;
    outline: none !important;
}

.submenu-list {
    padding-right: 1rem;
    padding-left: 0;
}

/* =========================================================
   [9] الفوتر الداخلي للسايدبار
   - يبقى دائمًا أسفل السايدبار
   - بدون fixed وبدون sticky
========================================================= */
#sidebar .Footer-bar {
    margin-top: auto;
    flex-shrink: 0;
    padding: 12px;
    border-top: 1px solid #dee2e6;
    background-color: #fff;
}

#sidebar .Footer-bar a,
#sidebar .Footer-bar button {
    border-radius: 10px;
}

#sidebar .Footer-bar .dropdown-item {
    padding: 10px 12px;
    white-space: normal;
}

#sidebar .Footer-bar ul {
    margin: 0;
    padding: 0;
}

#sidebar .Footer-bar li {
    list-style: none;
}

#sidebar .Footer-bar form {
    margin: 0;
}

.sidebar-user-box {
    padding: 0.5rem;
}

.sidebar-logout-btn {
    width: 100%;
    border: 0;
    background: #f8f9fa;
    border-radius: 10px;
    padding: 12px 14px;
    text-align: right;
    justify-content: flex-start;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.sidebar-logout-btn:hover {
    background: #eceff1;
}

.sidebar-logout-btn i {
    flex-shrink: 0;
}

/* =========================================================
   [10] حالات قديمة تم الإبقاء عليها للتوافق
   - حتى لا ينكسر أي كود قديم يعتمد عليها
========================================================= */
.sidebar-collapsed {
    margin-right: 0 !important;
}

.sidebar-active {
    margin-right: 0 !important;
    transform: translateX(0);
}

/* =========================================================
   [11] الفوتر الرئيسي للصفحة
========================================================= */
#main-footer {
    background-color: #ffffff;
    padding: 15px;
    text-align: center;
    font-size: 14px;
    color: #777;
    border-top: 1px solid #dee2e6;
    margin-top: auto;
}

/* =========================================================
   [12] Layout الإدارة
   - ضبط الصفحة بالكامل تحت الهيدر
   - منع تداخل المحتوى مع الهيدر
========================================================= */
body.admin-layout-body {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background-color: #f8f9fa;
    margin: 0;
    padding-top: 74px !important;
    /* نفس ارتفاع الهيدر في الديسكتوب */
}

.admin-page-wrap {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: calc(100vh - 74px);
}

.admin-content-wrap {
    flex: 1;
}

.admin-main-row {
    min-height: 100%;
}

.admin-main-content {
    display: flex;
    flex-direction: column;
}

/* =========================================================
   [13] الشاشات المتوسطة والموبايل
   - السايدبار يعمل off-canvas
   - الظهور يتم عبر class active
========================================================= */
@media (max-width: 768px) {
    body.admin-layout-body {
        padding-top: 64px !important;
    }

    .admin-page-wrap {
        min-height: calc(100vh - 64px);
    }

    #main-header {
        padding: 8px 12px;
        min-height: 64px;
    }

    #main-header .brand-box {
        display: flex;
        align-items: center;
        flex: 1;
    }

    #main-header .navbar-brand.brand-link {
        display: inline-flex;
        align-items: center;
        gap: 6px;
        flex: 0 0 auto;
    }

    #main-header .img-logo {
        width: 34px;
        height: 34px;
        flex-shrink: 0;
    }

    #main-header .brand-text-wrap {
        display: flex;
        flex-direction: column;
        line-height: 1.05;
    }

    #main-header .textlogo {
        font-size: 0.95rem;
        margin: 0;
        white-space: nowrap;
    }

    #main-header .text-span {
        font-size: 0.52rem;
        white-space: nowrap;
    }

    #toggleSidebarBtn {
        padding: 0;
        margin: 0 0 0 10px !important;
        flex-shrink: 0;
    }

    #toggleSidebarBtn .icon-bubble {
        width: 28px;
        height: 28px;
        font-size: 12px;
    }

    #sidebar {
        position: fixed;
        top: 64px;
        right: 0;
        width: min(320px, 100%);
        max-width: 100%;
        min-height: calc(100vh - 64px);
        height: calc(100vh - 64px);
        background-color: #fff;
        z-index: 1050;
        border-left: 1px solid #e9ecef;
        box-shadow: -4px 0 14px rgba(0, 0, 0, 0.08);
        transform: translateX(100%);
        transition: transform 0.3s ease;
    }

    #sidebar.active {
        transform: translateX(0);
    }

    #sidebar .sidebar-content {
        flex: 1 1 auto;
        min-height: 0;
        overflow-y: auto;
        overflow-x: hidden;
    }

    #sidebar .Footer-bar {
        margin-top: auto;
        background-color: #fff;
    }
}

/* =========================================================
   [14] الشاشات الصغيرة جدًا
========================================================= */
@media (max-width: 420px) {
    body.admin-layout-body {
        padding-top: 60px !important;
    }

    #main-header {
        padding: 8px 10px;
        min-height: 60px;
    }

    .admin-page-wrap {
        min-height: calc(100vh - 60px);
    }

    #main-header .img-logo {
        width: 30px;
        height: 30px;
    }

    #main-header .textlogo {
        font-size: 0.82rem;
    }

    #main-header .text-span {
        font-size: 0.48rem;
    }

    #sidebar {
        top: 60px;
        min-height: calc(100vh - 60px);
        height: calc(100vh - 60px);
    }
}