/* ═══════════════════════════════════════════════════
   نظام المساعدة السياقية - PageHelp (تصميم عام)
   القائمة الجانبية: يمين (RTL) ← درج المساعدة: يسار
   ═══════════════════════════════════════════════════ */

/* ── الخلفية المعتمة ── */
.page-help-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 10050;
    animation: helpFadeIn 0.2s ease;
    cursor: pointer;
}

/* ── الدرج الجانبي ── */
.page-help-drawer {
    position: fixed;
    top: 0;
    bottom: 0;
    width: 440px;
    max-width: 90vw;
    background: #ffffff;
    background: var(--bg-primary, #ffffff);
    z-index: 10051;
    display: flex;
    flex-direction: column;
    direction: rtl;
    overflow: hidden;
}

/* في RTL: القائمة يمين → الدرج يسار */
html[dir="rtl"] .page-help-drawer {
    left: 0;
    right: auto;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.15);
    transform: translateX(-100%);
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

html[dir="rtl"] .page-help-drawer.open {
    transform: translateX(0);
}

/* في LTR: القائمة يسار → الدرج يمين */
html[dir="ltr"] .page-help-drawer {
    right: 0;
    left: auto;
    box-shadow: -4px 0 24px rgba(0, 0, 0, 0.15);
    transform: translateX(100%);
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

html[dir="ltr"] .page-help-drawer.open {
    transform: translateX(0);
}

/* ── رأس الدرج ── */
.help-drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color, #e5e7eb);
    background: var(--bg-secondary, #f8f9fa);
    flex-shrink: 0;
}

.help-title-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.help-title-icon {
    font-size: 28px;
    color: var(--primary-color, #2563eb);
}

.help-drawer-header h3 {
    margin: 0;
    font-size: 17px;
    font-weight: 700;
    color: var(--text-primary, #1e293b);
}

.help-close-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 6px;
    border-radius: 8px;
    color: var(--text-secondary, #64748b);
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.help-close-btn:hover {
    background: var(--hover-bg, #f1f5f9);
    color: var(--text-primary, #1e293b);
}

/* ── محتوى الدرج ── */
.help-drawer-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px;
    scroll-behavior: smooth;
}

/* ── شارة القسم ── */
.help-section-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    background: rgba(37, 99, 235, 0.08);
    border: 1px solid rgba(37, 99, 235, 0.2);
    border-radius: 20px;
    font-size: 12px;
    color: var(--primary-color, #2563eb);
    margin-bottom: 16px;
}

.help-section-badge .material-icons {
    font-size: 14px;
}

/* ── أقسام المساعدة ── */
.help-section {
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid rgba(229, 231, 235, 0.5);
}

.help-section:last-child {
    border-bottom: none;
}

.help-section-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
}

.help-section-header .material-icons {
    font-size: 20px;
    color: var(--primary-color, #2563eb);
}

.help-section-header h4 {
    margin: 0;
    font-size: 14px;
    font-weight: 700;
    color: var(--text-primary, #1e293b);
}

/* ── أدوات التعديل ── */
.help-edit-inline {
    display: flex;
    align-items: center;
    gap: 10px;
}

.help-edit-inline h3 {
    margin: 0;
}

.help-edit-btn {
    border: none;
    background: transparent;
    padding: 4px;
    cursor: pointer;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease;
}

.help-edit-btn:hover {
    background: rgba(37, 99, 235, 0.08);
}

.help-edit-btn .material-icons {
    font-size: 18px;
    color: var(--primary-color, #2563eb);
}

.help-edit-textarea {
    width: 100%;
    min-height: 84px;
    resize: vertical;
    border: 1px solid rgba(148, 163, 184, 0.6);
    border-radius: 10px;
    padding: 10px 12px;
    font-family: inherit;
    font-size: 13px;
    line-height: 1.7;
    color: var(--text-primary, #1e293b);
    background: #fff;
}

.help-edit-input {
    width: 100%;
    border: 1px solid rgba(148, 163, 184, 0.6);
    border-radius: 10px;
    padding: 8px 10px;
    font-family: inherit;
    font-size: 13px;
    color: var(--text-primary, #1e293b);
    background: #fff;
}

.help-edit-actions {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

.help-edit-save,
.help-edit-cancel {
    border: 1px solid rgba(148, 163, 184, 0.6);
    background: #fff;
    padding: 6px 10px;
    border-radius: 10px;
    cursor: pointer;
    font-size: 12.5px;
}

.help-edit-save {
    border-color: rgba(34, 197, 94, 0.5);
    color: #166534;
}

.help-edit-cancel {
    border-color: rgba(239, 68, 68, 0.4);
    color: #991b1b;
}

.help-loading,
.help-error,
.help-empty {
    padding: 10px 12px;
    border-radius: 10px;
    background: var(--bg-secondary, #f8f9fa);
    color: var(--text-secondary, #475569);
    font-size: 13px;
}

.help-error {
    background: #fef2f2;
    color: #991b1b;
}

/* ── الوصف ── */
.help-description {
    font-size: 13.5px;
    line-height: 1.8;
    color: var(--text-secondary, #475569);
    margin: 0;
    text-align: justify;
}

/* ── خطوات الاستخدام ── */
.help-steps {
    margin: 0;
    padding-right: 20px;
    padding-left: 0;
    list-style: none;
    counter-reset: step;
}

.help-steps li {
    position: relative;
    padding: 6px 32px 6px 0;
    font-size: 13px;
    line-height: 1.7;
    color: var(--text-secondary, #475569);
    counter-increment: step;
}

.help-steps li::before {
    content: counter(step);
    position: absolute;
    right: 0;
    top: 7px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--primary-color, #2563eb);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ── المتطلبات المسبقة ── */
.help-prerequisites {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.prereq-item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 8px;
    background: var(--bg-secondary, #f8f9fa);
    border-right: 3px solid transparent;
}

.prereq-item.required {
    border-right-color: #ef4444;
    background: #fef2f2;
}

.prereq-item.recommended {
    border-right-color: #f59e0b;
    background: #fffbeb;
}

.prereq-item.optional {
    border-right-color: #3b82f6;
    background: #eff6ff;
}

.badge-required {
    font-size: 10px;
    padding: 2px 8px;
    border-radius: 10px;
    background: #ef4444;
    color: #fff;
    font-weight: 700;
    white-space: nowrap;
}

.badge-recommended {
    font-size: 10px;
    padding: 2px 8px;
    border-radius: 10px;
    background: #f59e0b;
    color: #fff;
    font-weight: 700;
    white-space: nowrap;
}

.badge-optional {
    font-size: 10px;
    padding: 2px 8px;
    border-radius: 10px;
    background: #3b82f6;
    color: #fff;
    font-weight: 700;
    white-space: nowrap;
}

.prereq-content {
    flex: 1;
}

.prereq-desc {
    font-size: 13px;
    color: var(--text-primary, #1e293b);
    margin-bottom: 4px;
}

.prereq-link {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    color: var(--primary-color, #2563eb);
    text-decoration: none;
    transition: opacity 0.2s;
}

.prereq-link:hover {
    opacity: 0.8;
    text-decoration: underline;
}

.prereq-link .material-icons {
    font-size: 14px;
}

/* ── الشاشات المرتبطة ── */
.help-related-screens {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.related-screen-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 10px;
    background: var(--bg-secondary, #f8f9fa);
    border: 1px solid var(--border-color, #e5e7eb);
    text-decoration: none;
    color: inherit;
    transition: all 0.2s;
    cursor: pointer;
}

.related-screen-card:hover {
    background: var(--hover-bg, #f1f5f9);
    border-color: rgba(37, 99, 235, 0.3);
    transform: translateX(2px);
}

.rs-icon-wrap {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: rgba(37, 99, 235, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.rs-icon-wrap .material-icons {
    font-size: 18px;
    color: var(--primary-color, #2563eb);
}

.rs-content {
    flex: 1;
    min-width: 0;
}

.rs-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary, #1e293b);
    margin-bottom: 2px;
}

.rs-relation {
    margin-bottom: 2px;
}

.rs-relation-badge {
    font-size: 10px;
    padding: 1px 6px;
    border-radius: 8px;
    font-weight: 600;
}

.rs-relation-badge.rel-source  { background: #dbeafe; color: #1d4ed8; }
.rs-relation-badge.rel-target  { background: #dcfce7; color: #166534; }
.rs-relation-badge.rel-settings { background: #fef3c7; color: #92400e; }
.rs-relation-badge.rel-report  { background: #f3e8ff; color: #7c3aed; }
.rs-relation-badge.rel-child   { background: #e0e7ff; color: #4338ca; }
.rs-relation-badge.rel-parent  { background: #fce7f3; color: #be185d; }
.rs-relation-badge.rel-related { background: #f1f5f9; color: #475569; }

.rs-desc {
    font-size: 11.5px;
    color: var(--text-muted, #94a3b8);
    line-height: 1.4;
}

.rs-arrow {
    font-size: 18px;
    color: var(--text-muted, #94a3b8);
    flex-shrink: 0;
}

/* ── الصلاحيات ── */
.help-permissions {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.perm-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-radius: 8px;
    background: var(--bg-secondary, #f8f9fa);
}

.perm-item.primary {
    background: #eff6ff;
    border: 1px solid #bfdbfe;
}

.perm-icon {
    font-size: 18px;
    color: var(--text-muted, #94a3b8);
}

.perm-item.primary .perm-icon {
    color: var(--primary-color, #2563eb);
}

.perm-content {
    flex: 1;
}

.perm-desc {
    font-size: 13px;
    color: var(--text-primary, #1e293b);
}

.perm-key {
    font-size: 10.5px;
    color: var(--text-muted, #94a3b8);
    background: var(--bg-primary, #ffffff);
    padding: 1px 6px;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    direction: ltr;
    display: inline-block;
}

.perm-primary-badge {
    font-size: 10px;
    padding: 2px 8px;
    border-radius: 10px;
    background: var(--primary-color, #2563eb);
    color: #fff;
    font-weight: 700;
}

/* ── النصائح ── */
.help-tips {
    list-style: none;
    margin: 0;
    padding: 0;
}

.help-tips li {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 6px 0;
    font-size: 13px;
    color: var(--text-secondary, #475569);
    line-height: 1.6;
}

.tip-icon {
    font-size: 16px;
    color: #f59e0b;
    flex-shrink: 0;
    margin-top: 2px;
}

/* ── الأسئلة الشائعة ── */
.help-faqs {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.faq-item {
    border-radius: 8px;
    background: var(--bg-secondary, #f8f9fa);
    overflow: hidden;
}

.faq-item summary {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary, #1e293b);
    list-style: none;
    user-select: none;
    transition: background 0.2s;
}

.faq-item summary::-webkit-details-marker {
    display: none;
}

.faq-item summary:hover {
    background: var(--hover-bg, #f1f5f9);
}

.faq-item summary .material-icons {
    font-size: 16px;
    color: var(--primary-color, #2563eb);
}

.faq-answer {
    padding: 0 12px 12px 12px;
    font-size: 12.5px;
    line-height: 1.7;
    color: var(--text-secondary, #475569);
    border-top: 1px solid var(--border-color, #e5e7eb);
    padding-top: 10px;
}

/* ── التذييل ── */
.help-drawer-footer {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 20px;
    border-top: 1px solid var(--border-color, #e5e7eb);
    background: var(--bg-secondary, #f8f9fa);
    font-size: 11px;
    color: var(--text-muted, #94a3b8);
    flex-shrink: 0;
}

.help-drawer-footer .material-icons {
    font-size: 14px;
    color: var(--primary-color, #2563eb);
}

/* ── الأنيميشن ── */
@keyframes helpFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ── زر المساعدة في الهيدر ── */
.page-help-btn {
    position: relative;
}

.page-help-btn .material-icons {
    transition: transform 0.3s;
}

.page-help-btn:hover .material-icons {
    transform: rotate(15deg);
}

/* ── الاستجابة للشاشات الصغيرة ── */
@media (max-width: 480px) {
    .page-help-drawer {
        width: 100vw !important;
        max-width: 100vw !important;
    }
}
