/* ═══════════════════════════════════════════════════════════
   نظام إدارة خدمة العملاء — Custom Stylesheet
   Bootstrap 5 RTL + IBM Plex Sans Arabic
   ═══════════════════════════════════════════════════════════ */

/* ── Variables ─────────────────────────────────────────────── */
:root {
    --sidebar-width: 260px;
    --sidebar-collapsed-width: 64px;
    --header-height: 60px;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --sidebar-bg: #0f172a;
    --sidebar-text: #94a3b8;
    --sidebar-text-hover: #f1f5f9;
    --sidebar-active-bg: rgba(37, 99, 235, 0.18);
    --sidebar-active-text: #60a5fa;
    --sidebar-brand-bg: #1e293b;
    --header-bg: #ffffff;
    --header-border: #e2e8f0;
    --content-bg: #f8fafc;
    --footer-bg: #ffffff;
    --footer-border: #e2e8f0;
    --card-shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
    --transition: all 0.22s ease;
}

/* ── Base ───────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

html { font-size: 15px; scroll-behavior: smooth; }

body {
    font-family: 'IBM Plex Sans Arabic', 'Segoe UI', system-ui, sans-serif;
    direction: rtl;
    background: var(--content-bg);
    color: #1e293b;
}

/* ── Layout ─────────────────────────────────────────────────── */
.crm-body {
    display: flex;
    min-height: 100vh;
    overflow-x: hidden;
}

/* ── Sidebar ─────────────────────────────────────────────────── */
.crm-sidebar {
    width: var(--sidebar-width);
    min-height: 100vh;
    background: var(--sidebar-bg);
    position: fixed;
    top: 0;
    right: 0;
    z-index: 1050;
    display: flex;
    flex-direction: column;
    transition: var(--transition);
    overflow: hidden;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.85rem 1.25rem;
    background: var(--sidebar-brand-bg);
    color: #f1f5f9;
    min-height: var(--header-height);
    border-bottom: 1px solid rgba(255,255,255,.07);
    white-space: nowrap;
    overflow: hidden;
    text-decoration: none;
}

/* ── شعار الـ Sidebar ───────────────────────────────────────────── */
.sidebar-logo-img {
    width: auto;
    height: 48px;
    flex-shrink: 0;
    object-fit: contain;
    opacity: 0.95;
    transition: opacity .2s;
}
.sidebar-brand:hover .sidebar-logo-img { opacity: 1; }

.sidebar-brand-text {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
    overflow: hidden;
}
.sidebar-brand-name {
    font-size: 1.3rem;
    font-weight: 700;
    color: #f1f5f9;
    letter-spacing: .01em;
    margin-bottom: 0.4rem;
}
.sidebar-brand-sub {
    font-size: 0.9rem;
    color: #94a3b8;
    font-weight: 400;
}

.sidebar-collapsed .sidebar-brand-text { display: none; }

.sidebar-brand-icon {
    font-size: 1.5rem;
    color: #60a5fa;
    flex-shrink: 0;
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 0.75rem 0;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,.1) transparent;
}

.nav-section-label {
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #475569;
    padding: 1rem 1.25rem 0.25rem;
    white-space: nowrap;
    overflow: hidden;
}

.sidebar-nav .nav-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 1.25rem;
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 0.9rem;
    border-radius: 0;
    transition: var(--transition);
    white-space: nowrap;
    overflow: hidden;
}

.sidebar-nav .nav-link i {
    font-size: 1.05rem;
    flex-shrink: 0;
    width: 1.2rem;
    text-align: center;
}

.sidebar-nav .nav-link:hover {
    background: rgba(255,255,255,.06);
    color: var(--sidebar-text-hover);
}

.sidebar-nav .nav-link.active {
    background: var(--sidebar-active-bg);
    color: var(--sidebar-active-text);
    font-weight: 600;
    border-right: 3px solid var(--sidebar-active-text);
}

/* Sidebar Collapsed */
.sidebar-collapsed .crm-sidebar {
    width: var(--sidebar-collapsed-width);
}

.sidebar-collapsed .sidebar-brand-text,
.sidebar-collapsed .nav-section-label,
.sidebar-collapsed .sidebar-nav .nav-link span {
    display: none;
}

.sidebar-collapsed .sidebar-nav .nav-link {
    justify-content: center;
    padding: 0.7rem;
}

/* ── Main Content ────────────────────────────────────────────── */
.crm-main {
    margin-right: var(--sidebar-width);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    transition: var(--transition);
}

.sidebar-collapsed .crm-main {
    margin-right: var(--sidebar-collapsed-width);
}

/* ── Header ──────────────────────────────────────────────────── */
.crm-header {
    height: var(--header-height);
    background: var(--header-bg);
    border-bottom: 1px solid var(--header-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.25rem;
    position: sticky;
    top: 0;
    z-index: 1000;
    gap: 1rem;
}

.header-start, .header-end {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.sidebar-toggle {
    background: none;
    border: none;
    font-size: 1.4rem;
    color: #64748b;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    border-radius: 6px;
    transition: var(--transition);
    line-height: 1;
}

.sidebar-toggle:hover {
    background: #f1f5f9;
    color: #1e293b;
}

.header-icon-btn {
    position: relative;
    background: none;
    border: none;
    font-size: 1.2rem;
    color: #64748b;
    cursor: pointer;
    padding: 0.35rem 0.5rem;
    border-radius: 8px;
    transition: var(--transition);
    line-height: 1;
}

.header-icon-btn:hover {
    background: #f1f5f9;
    color: #1e293b;
}

.notif-badge {
    position: absolute;
    top: 2px;
    left: 2px;
    background: #ef4444;
    color: white;
    font-size: 0.65rem;
    font-weight: 700;
    min-width: 17px;
    height: 17px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 2px;
}

.user-menu-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.3rem 0.5rem;
    border-radius: 8px;
    transition: var(--transition);
}

.user-menu-btn:hover { background: #f1f5f9; }

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
}

.user-avatar-fallback {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    font-size: 0.85rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
}

.user-name {
    font-size: 0.875rem;
    font-weight: 500;
    color: #374151;
    max-width: 130px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ── Notifications Dropdown ────────────────────────────────── */
.notif-dropdown {
    width: 320px;
    padding: 0;
    border: 1px solid #e2e8f0;
    box-shadow: 0 10px 40px rgba(0,0,0,.12);
    border-radius: 12px;
    overflow: hidden;
}

.notif-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.85rem 1rem;
    border-bottom: 1px solid #f1f5f9;
    background: #fafafa;
}

.notif-list { max-height: 350px; overflow-y: auto; }

.notif-item {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid #f8fafc;
    transition: background 0.15s;
    cursor: pointer;
    text-decoration: none;
    color: inherit;
}

.notif-item:hover { background: #f8fafc; }
.notif-item.unread { background: #eff6ff; }
.notif-item.unread:hover { background: #dbeafe; }

/* ── Content ─────────────────────────────────────────────────── */
.crm-content {
    flex: 1;
    padding: 1.5rem;
}

/* ── Footer ──────────────────────────────────────────────────── */
.crm-footer {
    background: var(--footer-bg);
    border-top: 1px solid var(--footer-border);
    padding: 0.75rem 1.5rem;
    font-size: 0.8rem;
    color: #94a3b8;
    text-align: center;
}

/* ── Cards ───────────────────────────────────────────────────── */
.card {
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    box-shadow: var(--card-shadow);
}

.card-header {
    background: transparent;
    border-bottom: 1px solid #f1f5f9;
    font-weight: 600;
    padding: 1rem 1.25rem;
}

/* ── Stat Cards ──────────────────────────────────────────────── */
.stat-card {
    border-radius: 12px;
    padding: 1.25rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    border: none;
    box-shadow: var(--card-shadow);
}

.stat-card-icon {
    width: 52px;
    height: 52px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    flex-shrink: 0;
}

.stat-card-value {
    font-size: 1.75rem;
    font-weight: 700;
    line-height: 1;
}

.stat-card-label {
    font-size: 0.82rem;
    color: #64748b;
    margin-top: 2px;
}

/* ── Tables ──────────────────────────────────────────────────── */
.table thead th {
    background: #f8fafc;
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #64748b;
    border-bottom: 2px solid #e2e8f0;
    padding: 0.75rem 1rem;
    white-space: nowrap;
}

.table tbody td {
    padding: 0.75rem 1rem;
    vertical-align: middle;
    border-bottom: 1px solid #f1f5f9;
}

.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover td { background: #f8fafc; }

/* ── Badges ──────────────────────────────────────────────────── */
.badge { font-size: 0.72rem; font-weight: 600; padding: 0.3em 0.6em; border-radius: 6px; }

/* ── Page Header ─────────────────────────────────────────────── */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.page-header h1, .page-header h2 {
    font-size: 1.4rem;
    font-weight: 700;
    margin: 0;
    color: #0f172a;
}

/* ── Buttons ─────────────────────────────────────────────────── */
.btn { font-size: 0.875rem; font-weight: 500; border-radius: 8px; }
.btn-primary { background: var(--primary); border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }

/* ── Forms ───────────────────────────────────────────────────── */
.form-control, .form-select {
    border-radius: 8px;
    border-color: #d1d5db;
    font-size: 0.9rem;
}

.form-control:focus, .form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,.15);
}

.form-label { font-size: 0.875rem; font-weight: 500; color: #374151; margin-bottom: 0.35rem; }

/* ── Login Page ───────────────────────────────────────────────── */
.login-body {
    min-height: 100vh;
    background: linear-gradient(135deg, #0f172a 0%, #1e3a5f 60%, #1e40af 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.login-card {
    background: white;
    border-radius: 16px;
    box-shadow: 0 25px 60px rgba(0,0,0,.3);
    width: 100%;
    max-width: 420px;
    padding: 2.5rem 2rem;
}

.login-logo {
    text-align: center;
    margin-bottom: 1.75rem;
}

/* ── شعار صفحة الدخول ────────────────────────────────────────── */
.login-logo-img-wrap {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 260px;
    height: 130px;
    margin-bottom: 1rem;
}
.login-logo-img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.login-logo-icon {
    width: 64px;
    height: 64px;
    background: linear-gradient(135deg, var(--primary), #7c3aed);
    border-radius: 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    color: white;
    margin-bottom: 0.75rem;
}

.login-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: #0f172a;
    margin-bottom: 0.15rem;
}
.login-subtitle {
    font-size: 0.82rem;
    color: #64748b;
}

.login-subtitle {
    font-size: 0.85rem;
    color: #64748b;
}

/* ── Error Pages ──────────────────────────────────────────────── */
.error-page { padding: 4rem 1rem; }

/* ── Article Content (TinyMCE output) ────────────────────────── */
.article-content { direction: rtl; }
.article-content h1,.article-content h2,.article-content h3,.article-content h4 { font-weight: 700; margin-top: 1.4em; margin-bottom: .5em; }
.article-content h1 { font-size: 1.6rem; }
.article-content h2 { font-size: 1.35rem; }
.article-content h3 { font-size: 1.15rem; }
.article-content p { margin-bottom: .9em; }
.article-content img { max-width: 100%; height: auto; border-radius: 8px; margin: 8px 0; box-shadow: 0 2px 8px rgba(0,0,0,.08); }
.article-content iframe { max-width: 100%; border-radius: 8px; }
.article-content table { width: 100%; border-collapse: collapse; margin: 16px 0; }
.article-content table td, .article-content table th { border: 1px solid #e2e8f0; padding: 8px 12px; }
.article-content table th { background: #f8fafc; font-weight: 600; }
.article-content blockquote { border-right: 4px solid #2563eb; padding: 8px 16px; background: #eff6ff; margin: 16px 0; border-radius: 0 8px 8px 0; color: #1e40af; }
.article-content pre { background: #1e293b; color: #e2e8f0; padding: 16px; border-radius: 8px; overflow-x: auto; direction: ltr; }
.article-content code { background: #f1f5f9; padding: 2px 6px; border-radius: 4px; font-size: .875em; direction: ltr; }
.article-content ul, .article-content ol { padding-right: 1.5rem; margin-bottom: .9em; }
.article-content a { color: #2563eb; }
.article-content a:hover { text-decoration: underline; }

/* ── Validation Summary — hide when no errors ────────────────── */
.validation-summary-valid { display: none !important; }

/* ── TinyMCE Editor Container ────────────────────────────────── */
.tox-tinymce { border-radius: 8px !important; border-color: #d1d5db !important; }
.tox .tox-toolbar__primary { background: #f8fafc !important; border-bottom: 1px solid #e2e8f0 !important; }
.tox-statusbar { border-top: 1px solid #e2e8f0 !important; }

/* ── TinyMCE Content Display ─────────────────────────────────── */
.tinymce-content { line-height: 1.75; }
.tinymce-content p { margin-bottom: 0.6em; }
.tinymce-content p:last-child { margin-bottom: 0; }
.tinymce-content ul, .tinymce-content ol { padding-right: 1.5rem; margin-bottom: 0.6em; }
.tinymce-content img { max-width: 100%; height: auto; border-radius: 6px; }
.tinymce-content blockquote { border-right: 4px solid #2563eb; padding: 6px 14px; background: #eff6ff; margin: 10px 0; border-radius: 0 6px 6px 0; color: #1e40af; }
.tinymce-content pre { background: #1e293b; color: #e2e8f0; padding: 12px; border-radius: 6px; overflow-x: auto; direction: ltr; font-size: 0.85em; }
.tinymce-content h1, .tinymce-content h2, .tinymce-content h3 { font-weight: 700; margin: 0.8em 0 0.4em; }

/* ── Responsive ───────────────────────────────────────────────── */
@media (max-width: 768px) {
    .crm-sidebar {
        transform: translateX(100%);
        width: var(--sidebar-width);
    }

    .crm-sidebar.mobile-open {
        transform: translateX(0);
    }

    .crm-main {
        margin-right: 0;
    }

    .sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,.5);
        z-index: 1040;
    }

    .sidebar-overlay.active { display: block; }
}

/* ── Scrollbar ────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* ── Utilities ────────────────────────────────────────────────── */
.cursor-pointer { cursor: pointer; }
.text-truncate-2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.font-monospace { font-family: 'Courier New', monospace !important; }

/* ── Header Search ────────────────────────────────────────────── */
.header-search .form-control:focus { box-shadow: none; border-color: #d1d5db; background: white !important; }
.header-search .input-group-text { border-color: #e2e8f0; }

/* ── Print styles ─────────────────────────────────────────────── */
@media print {
    .crm-sidebar, .crm-header, .crm-footer, .btn, form[method="post"] { display: none !important; }
    .crm-main { margin-right: 0 !important; }
    .crm-content { padding: 0 !important; }
    .card { border: 1px solid #ddd !important; box-shadow: none !important; }
}

/* ── Dashboard ────────────────────────────────────────────────── */
.hover-bg:hover { background: #f8fafc; }

.progress { border-radius: 6px; background: #f1f5f9; }
.progress-bar { border-radius: 6px; transition: width 0.6s ease; }

/* stat-card clickable */
a.stat-card:hover { box-shadow: 0 4px 12px rgba(0,0,0,.12); transform: translateY(-1px); transition: var(--transition); }

/* inline number ring (decorative) */
.ring-stat {
    width: 64px; height: 64px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.2rem; font-weight: 700;
    border: 3px solid currentColor;
    flex-shrink: 0;
}

/* Month stats divider fix on mobile */
@media (max-width: 767px) {
    .border-end { border-right: none !important; border-bottom: 1px solid #e2e8f0; padding-bottom: 1rem; margin-bottom: 1rem; }
}
