/* =========================================================
   نظام إدارة العملاء — الستايل الأساسي (عربي / RTL)
   ========================================================= */

@font-face {
    font-family: 'Cairo';
    src: url('../fonts/Cairo-Regular.ttf') format('truetype-variations');
    font-weight: 200 1000;
    font-display: swap;
}

:root {
    --app-font: 'Cairo', 'Segoe UI', Tahoma, 'Dubai', Arial, sans-serif;

    --brand: #1d4ed8;
    --brand-dark: #1e3a8a;
    --brand-light: #eff6ff;

    --sidebar-width: 260px;
    --sidebar-collapsed: 76px;
    --topbar-height: 62px;

    --surface: #ffffff;
    --body-bg: #f2f5fa;
    --border: #e3e8f0;
    --text-muted: #6b7280;

    --radius: 12px;
    --shadow-sm: 0 1px 2px rgba(16, 24, 40, .05);
    --shadow: 0 4px 16px rgba(16, 24, 40, .07);

    /* ألوان حالات إضافية غير موجودة في بوتستراب */
    --bs-purple-bg: #f3e8ff;  --bs-purple-fg: #6b21a8;
    --bs-teal-bg:   #ccfbf1;  --bs-teal-fg:   #0f766e;
    --bs-indigo-bg: #e0e7ff;  --bs-indigo-fg: #3730a3;
    --bs-orange-bg: #ffedd5;  --bs-orange-fg: #9a3412;
}

* { scrollbar-width: thin; }

body {
    font-family: var(--app-font);
    background: var(--body-bg);
    color: #111827;
    font-size: .92rem;
    overflow-x: hidden;
}

a { text-decoration: none; }

/* ===================== القائمة الجانبية ===================== */

.app-sidebar {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: var(--sidebar-width);
    background: #0f172a;
    color: #cbd5e1;
    z-index: 1045;
    display: flex;
    flex-direction: column;
    transition: transform .25s ease, width .25s ease;
}

.app-sidebar .sidebar-brand {
    height: var(--topbar-height);
    display: flex;
    align-items: center;
    gap: .6rem;
    padding: 0 1.1rem;
    border-bottom: 1px solid rgba(255, 255, 255, .08);
    flex-shrink: 0;
}

.app-sidebar .sidebar-brand .logo {
    width: 36px;
    height: 36px;
    border-radius: 9px;
    background: var(--brand);
    color: #fff;
    display: grid;
    place-items: center;
    font-size: 1.15rem;
    flex-shrink: 0;
}

.app-sidebar .sidebar-brand .title {
    font-weight: 700;
    color: #fff;
    font-size: .98rem;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
}

.app-sidebar .sidebar-nav {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: .75rem .6rem 1.5rem;
}

.app-sidebar .nav-section {
    font-size: .7rem;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: .04em;
    padding: 1rem .75rem .35rem;
    white-space: nowrap;
}

.app-sidebar .nav-link {
    display: flex;
    align-items: center;
    gap: .7rem;
    padding: .6rem .75rem;
    border-radius: 9px;
    color: #cbd5e1;
    font-size: .875rem;
    margin-bottom: .15rem;
    white-space: nowrap;
    transition: background .15s, color .15s;
}

.app-sidebar .nav-link i { font-size: 1.05rem; width: 20px; text-align: center; flex-shrink: 0; }
.app-sidebar .nav-link:hover { background: rgba(255, 255, 255, .07); color: #fff; }
.app-sidebar .nav-link.active { background: var(--brand); color: #fff; font-weight: 600; }
.app-sidebar .nav-link .badge { margin-inline-start: auto; }

/* الوضع المطوي على الشاشات الكبيرة */
body.sidebar-collapsed .app-sidebar { width: var(--sidebar-collapsed); }
body.sidebar-collapsed .app-sidebar .title,
body.sidebar-collapsed .app-sidebar .nav-link span,
body.sidebar-collapsed .app-sidebar .nav-section { display: none; }
body.sidebar-collapsed .app-sidebar .nav-link { justify-content: center; padding-inline: .5rem; }
body.sidebar-collapsed .app-sidebar .sidebar-brand { justify-content: center; padding-inline: 0; }
body.sidebar-collapsed .app-main { margin-right: var(--sidebar-collapsed); }

/* ===================== المحتوى والشريط العلوي ===================== */

.app-main {
    margin-right: var(--sidebar-width);
    min-height: 100vh;
    transition: margin .25s ease;
    display: flex;
    flex-direction: column;
    /* يمنع الجداول العريضة من توسيع الصفحة أفقيًا بدل التمرير داخل الجدول */
    min-width: 0;
    max-width: 100%;
    overflow-x: hidden;
}

.app-topbar {
    height: var(--topbar-height);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: 0 1rem;
    position: sticky;
    top: 0;
    z-index: 1020;
}

.app-content { padding: 1.25rem; flex: 1; min-width: 0; max-width: 100%; }

/* كل عنصر داخل المحتوى محصور بعرض الصفحة، والتمرير الأفقي يبقى داخل الجدول */
.app-content > * { max-width: 100%; }
.card > .table-responsive { overflow-x: auto; max-width: 100%; }

.topbar-search { max-width: 340px; flex: 1; }
.topbar-search .form-control { background: var(--body-bg); border-color: transparent; }
.topbar-search .form-control:focus { background: #fff; }

.btn-icon {
    width: 38px;
    height: 38px;
    display: inline-grid;
    place-items: center;
    border-radius: 9px;
    border: 1px solid var(--border);
    background: #fff;
    color: #374151;
    flex-shrink: 0;
}

.btn-icon:hover { background: var(--brand-light); color: var(--brand); }

.avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--brand);
    color: #fff;
    display: grid;
    place-items: center;
    font-weight: 600;
    font-size: .8rem;
    flex-shrink: 0;
}

.avatar-sm { width: 28px; height: 28px; font-size: .7rem; }
.avatar-lg { width: 64px; height: 64px; font-size: 1.4rem; }

/* شارة عدد التنبيهات */
.notif-dot {
    position: absolute;
    top: 2px;
    inset-inline-end: 2px;
    min-width: 17px;
    height: 17px;
    padding: 0 4px;
    border-radius: 9px;
    background: #ef4444;
    color: #fff;
    font-size: .62rem;
    display: grid;
    place-items: center;
    font-weight: 700;
}

.notif-list { width: 360px; max-height: 420px; overflow-y: auto; padding: 0; }
.notif-item { display: flex; gap: .7rem; padding: .7rem .9rem; border-bottom: 1px solid var(--border); color: inherit; }
.notif-item:hover { background: var(--brand-light); }
.notif-item.unread { background: #f8fbff; }
.notif-item .icon { width: 34px; height: 34px; border-radius: 8px; display: grid; place-items: center; flex-shrink: 0; }

/* ===================== البطاقات ===================== */

.card {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}

.card-header {
    background: #fff;
    border-bottom: 1px solid var(--border);
    padding: .85rem 1.1rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: .5rem;
    flex-wrap: wrap;
    border-radius: var(--radius) var(--radius) 0 0 !important;
}

.card-header .header-actions { margin-inline-start: auto; display: flex; gap: .5rem; flex-wrap: wrap; }

/* بطاقة مؤشر في لوحة المعلومات */
.stat-card {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    display: flex;
    align-items: center;
    gap: .85rem;
    height: 100%;
    transition: transform .15s, box-shadow .15s;
}

.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.stat-card .icon { width: 46px; height: 46px; border-radius: 11px; display: grid; place-items: center; font-size: 1.3rem; flex-shrink: 0; }
.stat-card .value { font-size: 1.5rem; font-weight: 700; line-height: 1.1; }
.stat-card .label { color: var(--text-muted); font-size: .8rem; }

/* ===================== الجداول ===================== */

.table { --bs-table-hover-bg: var(--brand-light); margin-bottom: 0; }
.table > :not(caption) > * > * { padding: .7rem .75rem; vertical-align: middle; }
.table thead th { background: #f8fafc; color: #475569; font-weight: 600; font-size: .8rem; white-space: nowrap; border-bottom: 1px solid var(--border); }

div.dt-container { padding: .9rem 1.1rem; }
div.dt-container .dt-length, div.dt-container .dt-search { margin-bottom: .75rem; }
div.dt-container .dt-search input, div.dt-container .dt-length select { border-radius: 8px; border: 1px solid var(--border); padding: .3rem .6rem; }
div.dt-container .dt-info { color: var(--text-muted); font-size: .82rem; }
div.dt-container .dt-paging .page-link { border-radius: 8px !important; margin: 0 2px; border-color: var(--border); }
table.dataTable > tbody > tr > td { white-space: nowrap; }
table.dataTable.wrap-cells > tbody > tr > td { white-space: normal; }

/* عمود الإجراءات يبقى مثبتًا في نهاية الصف عند التمرير الأفقي */
table.sticky-actions > thead > tr > th:last-child,
table.sticky-actions > tbody > tr > td:last-child {
    position: sticky;
    left: 0;
    z-index: 2;
    background: #fff;
    box-shadow: 4px 0 6px -4px rgba(16, 24, 40, .18);
}

table.sticky-actions > thead > tr > th:last-child { background: #f8fafc; z-index: 3; }
table.sticky-actions > tbody > tr:hover > td:last-child { background: var(--brand-light); }

/* الجدول يتحول إلى بطاقات على الجوال */
.table-responsive { border-radius: 0 0 var(--radius) var(--radius); }

/* ===================== الشارات والحالات ===================== */

.badge-status {
    display: inline-flex;
    align-items: center;
    gap: .3rem;
    padding: .3rem .6rem;
    border-radius: 20px;
    font-size: .74rem;
    font-weight: 600;
    white-space: nowrap;
}

.badge-status.s-primary   { background: #dbeafe; color: #1e40af; }
.badge-status.s-secondary { background: #e5e7eb; color: #374151; }
.badge-status.s-success   { background: #dcfce7; color: #166534; }
.badge-status.s-danger    { background: #fee2e2; color: #991b1b; }
.badge-status.s-warning   { background: #fef3c7; color: #92400e; }
.badge-status.s-info      { background: #cffafe; color: #155e75; }
.badge-status.s-dark      { background: #d1d5db; color: #1f2937; }
.badge-status.s-purple    { background: var(--bs-purple-bg); color: var(--bs-purple-fg); }
.badge-status.s-teal      { background: var(--bs-teal-bg);   color: var(--bs-teal-fg); }
.badge-status.s-indigo    { background: var(--bs-indigo-bg); color: var(--bs-indigo-fg); }
.badge-status.s-orange    { background: var(--bs-orange-bg); color: var(--bs-orange-fg); }

.soft-primary   { background: #dbeafe; color: #1e40af; }
.soft-success   { background: #dcfce7; color: #166534; }
.soft-danger    { background: #fee2e2; color: #991b1b; }
.soft-warning   { background: #fef3c7; color: #92400e; }
.soft-info      { background: #cffafe; color: #155e75; }
.soft-secondary { background: #e5e7eb; color: #374151; }
.soft-purple    { background: var(--bs-purple-bg); color: var(--bs-purple-fg); }
.soft-teal      { background: var(--bs-teal-bg);   color: var(--bs-teal-fg); }
.soft-indigo    { background: var(--bs-indigo-bg); color: var(--bs-indigo-fg); }
.soft-orange    { background: var(--bs-orange-bg); color: var(--bs-orange-fg); }
.soft-dark      { background: #d1d5db; color: #1f2937; }

/* ===================== ملف العميل ===================== */

.profile-header {
    background: linear-gradient(135deg, var(--brand-dark), var(--brand));
    color: #fff;
    border-radius: var(--radius);
    padding: 1.25rem;
}

.profile-header .avatar { background: rgba(255, 255, 255, .2); width: 60px; height: 60px; font-size: 1.3rem; }

.nav-profile {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: .35rem;
    display: flex;
    gap: .25rem;
    overflow-x: auto;
    flex-wrap: nowrap;
}

.nav-profile .nav-link {
    white-space: nowrap;
    border-radius: 8px;
    color: #475569;
    font-size: .85rem;
    padding: .5rem .85rem;
    display: flex;
    align-items: center;
    gap: .4rem;
}

.nav-profile .nav-link:hover { background: var(--brand-light); color: var(--brand); }
.nav-profile .nav-link.active { background: var(--brand); color: #fff; }

/* قائمة البيانات (مفتاح / قيمة) */
.data-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: .9rem; }
.data-item .k { color: var(--text-muted); font-size: .76rem; margin-bottom: .15rem; }
.data-item .v { font-weight: 600; word-break: break-word; }

/* الخط الزمني لسجل الإجراءات */
.timeline { position: relative; padding-inline-start: 1.6rem; }
.timeline::before { content: ''; position: absolute; inset-inline-start: 7px; top: 6px; bottom: 6px; width: 2px; background: var(--border); }
.timeline-item { position: relative; padding-bottom: 1.1rem; }
.timeline-item::before {
    content: '';
    position: absolute;
    inset-inline-start: -1.6rem;
    top: 5px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #fff;
    border: 3px solid var(--brand);
    transform: translateX(50%);
}
.timeline-item.tl-success::before { border-color: #16a34a; }
.timeline-item.tl-danger::before  { border-color: #dc2626; }
.timeline-item.tl-warning::before { border-color: #d97706; }
.timeline-item.tl-info::before    { border-color: #0891b2; }

/* بطاقة ملاحظة */
.note-card { border: 1px solid var(--border); border-radius: 10px; padding: .85rem; background: #fff; }
.note-card + .note-card { margin-top: .7rem; }

/* بطاقة مستند */
.doc-card { border: 1px solid var(--border); border-radius: 10px; padding: .85rem; background: #fff; height: 100%; display: flex; flex-direction: column; }
.doc-card .doc-icon { font-size: 1.7rem; color: var(--brand); }

/* ===================== نماذج ===================== */

.form-label { font-weight: 600; font-size: .82rem; margin-bottom: .3rem; color: #374151; }
.form-control, .form-select { border-radius: 9px; border-color: var(--border); font-size: .875rem; padding: .5rem .75rem; }
.form-control:focus, .form-select:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(29, 78, 216, .1); }
.required::after { content: ' *'; color: #dc2626; }

.select2-container--bootstrap-5 .select2-selection { border-radius: 9px !important; border-color: var(--border) !important; }

/* جدول بنود عرض السعر */
.items-table td { vertical-align: middle; }
.items-table .form-control { min-width: 90px; }

/* شريط التقدم للأهداف */
.goal-progress { height: 8px; border-radius: 8px; }

/* ===================== الاستجابة للشاشات ===================== */

@media (max-width: 991.98px) {
    .app-sidebar { transform: translateX(100%); box-shadow: -6px 0 24px rgba(0, 0, 0, .18); }
    body.sidebar-open .app-sidebar { transform: translateX(0); }
    .app-main { margin-right: 0 !important; }
    body.sidebar-collapsed .app-sidebar { width: var(--sidebar-width); }
    body.sidebar-collapsed .app-sidebar .title,
    body.sidebar-collapsed .app-sidebar .nav-link span,
    body.sidebar-collapsed .app-sidebar .nav-section { display: block; }
    body.sidebar-collapsed .app-sidebar .nav-link { justify-content: flex-start; padding-inline: .75rem; }

    .sidebar-backdrop {
        position: fixed;
        inset: 0;
        background: rgba(15, 23, 42, .5);
        z-index: 1040;
        display: none;
    }
    body.sidebar-open .sidebar-backdrop { display: block; }
}

@media (max-width: 767.98px) {
    .app-content { padding: .85rem; }
    .topbar-search { display: none; }
    .stat-card { padding: .8rem; }
    .stat-card .value { font-size: 1.25rem; }
    .stat-card .icon { width: 40px; height: 40px; font-size: 1.1rem; }
    .card-header { padding: .7rem .85rem; }
    .card-header .header-actions { width: 100%; margin-inline-start: 0; }
    div.dt-container { padding: .7rem .5rem; }
    .notif-list { width: calc(100vw - 2rem); }
    .data-list { grid-template-columns: 1fr 1fr; }
    .profile-header { padding: 1rem; }
    h1, .h1 { font-size: 1.4rem; }
    .btn { font-size: .84rem; }
}

@media (max-width: 575.98px) {
    .data-list { grid-template-columns: 1fr; }
    .page-title { font-size: 1.15rem; }
}

/* ===================== طباعة ===================== */

@media print {
    .app-sidebar, .app-topbar, .no-print, .btn { display: none !important; }
    .app-main { margin: 0 !important; }
    .app-content { padding: 0; }
    .card { border: none; box-shadow: none; }
}
