/* =========================================================
   RadPlus App Shell — الـ Sidebar والشريط العلوي يبانوا قطعة واحدة
   - الشكل الأصلي زي ما هو؛ التعديل بس في نقطة التقائهم
   - شكل فقط: لا يغيّر الأماكن أو الأبعاد أو أي وظيفة
   ========================================================= */

/* 1) ظل الـ Sidebar كان نازل على الشريط العلوي فبيبان كأنه راكب فوقه */
html body:not(#rp-shell) .sidebar,
html[dir="rtl"] body:not(#rp-shell) .sidebar,
html[dir="ltr"] body:not(#rp-shell) .sidebar {
    box-shadow: none !important;
}

/* 2) طرف الشريط اللي جنب الـ Sidebar بنفس لون أول الـ Sidebar
      عشان مايبقاش فيه خط فاصل بينهم */
html[dir="rtl"] body:not(#rp-shell) .topbar {
    background: linear-gradient(90deg, #00a7ff 0%, #1a76d1 100%) !important;
}

html[dir="ltr"] body:not(#rp-shell) .topbar {
    background: linear-gradient(270deg, #00a7ff 0%, #1a76d1 100%) !important;
}

/* 3) في أغلب الصفحات الشريط فوق الـ Sidebar في الطبقات، فظله بيقع على أول الـ Sidebar.
      بنقص الظل من الجنبين بس (من تحت مفتوح عشان قائمة المستخدم ماتتقصش) */
html body:not(#rp-shell) .topbar {
    clip-path: inset(0 0 -100vh 0);
}

/* =========================================================
   زرار اسم المستخدم + القائمة اللي جواه
   ========================================================= */

html body:not(#rp-shell) .topbar .user-menu-toggle {
    display: inline-flex !important;
    align-items: center !important;
    gap: 8px !important;
    height: 36px !important;
    padding: 0 12px !important;
    padding-inline-start: 4px !important;
    background: #ffffff !important;
    border: 1px solid rgba(255, 255, 255, .7) !important;
    border-radius: 12px !important;
    box-shadow: 0 2px 8px rgba(10, 60, 130, .18) !important;
    color: #0f172a !important;
    font-size: 14px !important;
    line-height: 1 !important;
    cursor: pointer;
    transition: background .15s ease, box-shadow .15s ease !important;
}

/* أيقونة الشخص */
html body:not(#rp-shell) .topbar .user-menu-toggle::before {
    content: "\f007";
    font-family: var(--fa-family-classic, "Font Awesome 7 Free"), "Font Awesome 5 Free";
    font-weight: 900;
    display: grid;
    place-items: center;
    width: 28px;
    height: 28px;
    flex: 0 0 28px;
    border-radius: 9px;
    background: linear-gradient(135deg, #00a7ff 0%, #1a76d1 100%);
    color: #ffffff;
    font-size: 12px;
}

html body:not(#rp-shell) .topbar .user-menu-toggle:hover {
    background: #f5f9ff !important;
    box-shadow: 0 4px 12px rgba(10, 60, 130, .22) !important;
}

html body:not(#rp-shell) .topbar .user-menu-toggle .hello-text {
    color: #64748b !important;
    font-size: 12.5px !important;
    font-weight: 500 !important;
}

html body:not(#rp-shell) .topbar .user-menu-toggle .user-name {
    color: #0f172a !important;
    font-size: 14px !important;
    font-weight: 700 !important;
}

html body:not(#rp-shell) .topbar .user-menu-toggle > i {
    color: #94a3b8 !important;
    font-size: 11px !important;
    margin-inline-start: 2px;
    transition: transform .18s ease !important;
}

/* السهم يلف لما القائمة تفتح */
html body:not(#rp-shell) .topbar .user-menu:has(.user-menu-dropdown.show) .user-menu-toggle > i {
    transform: rotate(180deg);
}

/* القائمة */
html body:not(#rp-shell) .topbar .user-menu-dropdown {
    min-width: 220px !important;
    margin-top: 8px !important;
    padding: 6px !important;
    background: #ffffff !important;
    border: 1px solid #e3ecf7 !important;
    border-radius: 14px !important;
    box-shadow: 0 18px 40px -10px rgba(15, 40, 80, .30) !important;
    color: #1f2937 !important;
}

html body:not(#rp-shell) .topbar .user-menu-dropdown.show {
    animation: rpShellMenuIn .14s ease-out;
}

@keyframes rpShellMenuIn {
    from {
        opacity: 0;
        transform: translateY(-4px);
    }

    to {
        opacity: 1;
        transform: none;
    }
}

html body:not(#rp-shell) .topbar .user-menu-item {
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    gap: 10px !important;
    width: 100% !important;
    padding: 7px 8px !important;
    margin: 0 !important;
    border: 0 !important;
    border-radius: 10px !important;
    background: transparent !important;
    color: #1f2937 !important;
    font-size: 13.5px !important;
    font-weight: 600 !important;
    text-align: start !important;
    text-decoration: none !important;
    cursor: pointer;
    transition: background .12s ease !important;
}

html body:not(#rp-shell) .topbar .user-menu-item > i {
    display: grid !important;
    place-items: center !important;
    flex: 0 0 30px !important;
    width: 30px !important;
    height: 30px !important;
    margin: 0 !important;
    border-radius: 9px !important;
    background: #eef5ff !important;
    color: #1a76d1 !important;
    font-size: 13px !important;
}

html body:not(#rp-shell) .topbar .user-menu-item:hover {
    background: #f3f8ff !important;
}

/* تسجيل الخروج: أحمر ومفصول بخط */
html body:not(#rp-shell) .topbar .user-menu-item.user-menu-logout {
    position: relative;
    margin-top: 9px !important;
    color: #b91c1c !important;
}

html body:not(#rp-shell) .topbar .user-menu-item.user-menu-logout::before {
    content: "";
    position: absolute;
    top: -5px;
    inset-inline: 6px;
    height: 1px;
    background: #edf2f7;
}

html body:not(#rp-shell) .topbar .user-menu-item.user-menu-logout > i {
    background: #fef2f2 !important;
    color: #dc2626 !important;
}

html body:not(#rp-shell) .topbar .user-menu-item.user-menu-logout:hover {
    background: #fef2f2 !important;
}

/* =========================================================
   زرار الفرع + القائمة اللي جواه
   ========================================================= */

html body:not(#rp-shell) .topbar :is(#branch-switcher, .topbar-branch-wrapper) {
    display: flex !important;
    align-items: center !important;
    gap: 8px !important;
    min-width: 0 !important;
}

html body:not(#rp-shell) .topbar :is(#branch-switcher > label, .topbar-branch-label) {
    margin: 0 !important;
    color: rgba(255, 255, 255, .92) !important;
    font-size: 12.5px !important;
    font-weight: 600 !important;
    white-space: nowrap;
}

html body:not(#rp-shell) .topbar :is(#branch-switcher, .topbar-branch-wrapper) select {
    -webkit-appearance: none !important;
    appearance: none !important;
    height: 36px !important;
    min-width: 210px !important;
    padding: 0 12px !important;
    padding-inline-end: 34px !important;
    background-color: #ffffff !important;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%2394a3b8' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m3 6 5 5 5-5'/%3e%3c/svg%3e") !important;
    background-repeat: no-repeat !important;
    background-size: 12px 12px !important;
    background-position: left 12px center !important;
    border: 1px solid rgba(255, 255, 255, .7) !important;
    border-radius: 12px !important;
    box-shadow: 0 2px 8px rgba(10, 60, 130, .18) !important;
    color: #0f172a !important;
    font-size: 13.5px !important;
    font-weight: 600 !important;
    cursor: pointer;
    outline: none !important;
    transition: background-color .15s ease, box-shadow .15s ease !important;
}

html[dir="ltr"] body:not(#rp-shell) .topbar :is(#branch-switcher, .topbar-branch-wrapper) select {
    background-position: right 12px center !important;
}

html body:not(#rp-shell) .topbar :is(#branch-switcher, .topbar-branch-wrapper) select:hover {
    background-color: #f5f9ff !important;
}

html body:not(#rp-shell) .topbar :is(#branch-switcher, .topbar-branch-wrapper) select:focus-visible {
    box-shadow: 0 0 0 3px rgba(255, 255, 255, .55), 0 2px 8px rgba(10, 60, 130, .18) !important;
}

html body:not(#rp-shell) .topbar :is(#branch-switcher, .topbar-branch-wrapper) select:disabled {
    opacity: .7;
    cursor: default;
}

/* قائمة الفروع نفسها (Chrome 135+). المتصفحات الأقدم بتعرض القائمة العادية */
@supports (appearance: base-select) {

    html body:not(#rp-shell) .topbar :is(#branch-switcher, .topbar-branch-wrapper) select,
    html body:not(#rp-shell) .topbar :is(#branch-switcher, .topbar-branch-wrapper) select::picker(select) {
        appearance: base-select !important;
    }

    html body:not(#rp-shell) .topbar :is(#branch-switcher, .topbar-branch-wrapper) select {
        display: inline-flex !important;
        align-items: center !important;
        background-image: none !important;
        padding-inline-end: 10px !important;
    }

    html body:not(#rp-shell) .topbar :is(#branch-switcher, .topbar-branch-wrapper) select::picker-icon {
        color: #94a3b8;
        font-size: 11px;
        transition: rotate .18s ease;
    }

    html body:not(#rp-shell) .topbar :is(#branch-switcher, .topbar-branch-wrapper) select:open::picker-icon {
        rotate: 180deg;
    }

    html body:not(#rp-shell) .topbar :is(#branch-switcher, .topbar-branch-wrapper) select::picker(select) {
        margin-block: 8px;
        padding: 6px;
        min-width: anchor-size(width);
        max-height: min(380px, 70vh);
        overflow-y: auto;
        background: #ffffff;
        border: 1px solid #e3ecf7;
        border-radius: 14px;
        box-shadow: 0 18px 40px -10px rgba(15, 40, 80, .30);
        scrollbar-width: thin;
        scrollbar-color: #cbd5e1 transparent;
    }

    html body:not(#rp-shell) .topbar :is(#branch-switcher, .topbar-branch-wrapper) select option {
        display: flex;
        align-items: center;
        gap: 8px;
        padding: 8px 10px;
        border-radius: 9px;
        color: #1f2937;
        font-size: 13.5px;
        font-weight: 600;
        cursor: pointer;
    }

    html body:not(#rp-shell) .topbar :is(#branch-switcher, .topbar-branch-wrapper) select option:hover,
    html body:not(#rp-shell) .topbar :is(#branch-switcher, .topbar-branch-wrapper) select option:focus-visible {
        background: #f3f8ff;
        outline: none;
    }

    html body:not(#rp-shell) .topbar :is(#branch-switcher, .topbar-branch-wrapper) select option:checked {
        background: #eef5ff;
        color: #1a76d1;
        font-weight: 700;
    }

    html body:not(#rp-shell) .topbar :is(#branch-switcher, .topbar-branch-wrapper) select option::checkmark {
        color: #1a76d1;
    }
}

/* =========================================================
   قائمة الكليك اليمين (الحجوزات + دليل المرضى)
   مهم: مانلمسش display للعناصر — الـ JS بيخفي/يظهر كل عنصر حسب حالة الحجز
   ========================================================= */

html body:not(#rp-shell) #context-menu {
    min-width: 240px !important;
    padding: 6px !important;
    background: #ffffff !important;
    border: 1px solid #e3ecf7 !important;
    border-radius: 14px !important;
    box-shadow: 0 18px 40px -10px rgba(15, 40, 80, .30) !important;
    color: #1f2937 !important;
    scrollbar-width: thin;
    scrollbar-color: #cbd5e1 transparent;
    animation: rpShellMenuIn .12s ease-out;
}

html body:not(#rp-shell) #context-menu .context-menu-item {
    position: relative;
    align-items: center !important;
    gap: 10px !important;
    margin: 0 !important;
    padding: 6px 8px !important;
    border: 0 !important;
    border-radius: 10px !important;
    background: transparent !important;
    color: #1f2937 !important;
    font-size: 13.5px !important;
    font-weight: 600 !important;
    line-height: 1.35 !important;
    white-space: nowrap;
    cursor: pointer;
    transition: background .12s ease !important;
}

html body:not(#rp-shell) #context-menu .context-menu-item:hover {
    background: #f3f8ff !important;
}

/* الأيقونات في مربع ملوّن */
html body:not(#rp-shell) #context-menu .context-menu-item > i {
    display: grid !important;
    place-items: center !important;
    flex: 0 0 30px !important;
    width: 30px !important;
    height: 30px !important;
    margin: 0 !important;
    border-radius: 9px !important;
    background: #eef5ff !important;
    color: #1a76d1 !important;
    font-size: 13px !important;
}

/* حالات الحجز */
html body:not(#rp-shell) #context-menu .context-menu-item[data-action="arrived"] > i {
    background: #ecfdf5 !important;
    color: #059669 !important;
}

html body:not(#rp-shell) #context-menu .context-menu-item[data-action="cancelled"] {
    color: #b91c1c !important;
}

html body:not(#rp-shell) #context-menu .context-menu-item[data-action="cancelled"] > i {
    background: #fef2f2 !important;
    color: #dc2626 !important;
}

html body:not(#rp-shell) #context-menu .context-menu-item[data-action="cancelled"]:hover {
    background: #fef2f2 !important;
}

/* الإيصالات */
html body:not(#rp-shell) #context-menu .context-menu-item:is([data-action="receipt"], [data-action="print-patient-receipt"], [data-action="print-day-receipts"]) > i {
    background: #fff7ed !important;
    color: #ea580c !important;
}

/* تتبّع الحالة */
html body:not(#rp-shell) #context-menu .context-menu-item[data-action="case-timeline"] > i {
    background: #f5f3ff !important;
    color: #7c3aed !important;
}

/* خط فاصل بعد مجموعة حالات الحجز، وقبل تتبّع الحالة */
/* الخط اللي قبل "تتبّع الحالة" يظهر بس لو هي ظاهرة (بتستخبى مع الحجز الملغي) */
html body:not(#rp-shell) #context-menu .context-menu-item[data-action="cancelled"],
html body:not(#rp-shell) #context-menu .context-menu-item[data-action="print-day-receipts"]:has(~ [data-action="case-timeline"]:not([style*="none"])) {
    margin-bottom: 9px !important;
}

html body:not(#rp-shell) #context-menu .context-menu-item[data-action="cancelled"]::after,
html body:not(#rp-shell) #context-menu .context-menu-item[data-action="print-day-receipts"]:has(~ [data-action="case-timeline"]:not([style*="none"]))::after {
    content: "";
    position: absolute;
    bottom: -5px;
    inset-inline: 6px;
    height: 1px;
    background: #edf2f7;
    pointer-events: none;
}

/* =========================================================
   ترتيب الأعمدة بسحب العنوان (static/js/column-order.js)
   ========================================================= */

th.rp-col-dragging {
    opacity: .45;
}

body.rp-col-drag-active,
body.rp-col-drag-active * {
    cursor: grabbing !important;
    user-select: none !important;
}

/* خط أزرق مكان ما العمود هينزل */
html[dir="rtl"] th.rp-col-drop-before,
html[dir="ltr"] th.rp-col-drop-after {
    box-shadow: inset -3px 0 0 #1a76d1 !important;
}

html[dir="rtl"] th.rp-col-drop-after,
html[dir="ltr"] th.rp-col-drop-before {
    box-shadow: inset 3px 0 0 #1a76d1 !important;
}
