/* ===== نظام ديكور لاب - الهوية البصرية =====
   فحمي #2B2A28 | أسود #1A1917 | بيج #D9CDB8 | ذهبي هادئ #B49A5E | كريمي #F7F3EA */
@font-face { font-family: 'Cairo'; src: url('../fonts/Cairo-Regular.ttf') format('truetype'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Cairo'; src: url('../fonts/Cairo-SemiBold.ttf') format('truetype'); font-weight: 600; font-display: swap; }
@font-face { font-family: 'Cairo'; src: url('../fonts/Cairo-Bold.ttf') format('truetype'); font-weight: 700; font-display: swap; }
@font-face { font-family: 'Cairo'; src: url('../fonts/Cairo-ExtraBold.ttf') format('truetype'); font-weight: 800; font-display: swap; }
:root {
    --charcoal: #2b2a28;
    --black: #1a1917;
    --beige: #d9cdb8;
    --beige-light: #e8dfce;
    --gold: #b49a5e;
    --gold-soft: #c9b183;
    --cream: #f7f3ea;
    --paper: #fffdf8;
    --line: #ddd3c0;
    --muted: #7a746a;
    --red: #c0392b;
    --orange: #e67e22;
    --yellow: #e6c229;
    --yellow-dark: #b8860b;
    --green: #2e7d32;
    --green-light: #8bc34a;
    --gray: #9e9e9e;
    --radius: 10px;
    --shadow: 0 1px 3px rgba(26,25,23,.08), 0 4px 14px rgba(26,25,23,.05);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: 'Cairo', 'Noto Sans Arabic', 'Segoe UI', Tahoma, sans-serif;
    background: var(--cream);
    color: var(--charcoal);
    font-size: 14.5px;
    line-height: 1.65;
}
a { color: var(--gold); text-decoration: none; }
a:hover { color: #94793f; }

/* ---------- شاشة الدخول ---------- */
.login-body { background: linear-gradient(160deg, var(--charcoal) 0%, var(--black) 60%, #23221f 100%); min-height: 100vh; display: flex; }
.login-wrap { margin: auto; width: 100%; max-width: 420px; padding: 20px; }
.login-card { background: var(--paper); border-radius: 14px; padding: 30px 28px; box-shadow: 0 12px 44px rgba(0,0,0,.4); }
/* ---------- شعار الشركة ---------- */
.brand-logo {
    width: 44px; height: 44px; border-radius: 50%; object-fit: cover;
    border: 1px solid rgba(180,154,94,.55); background: #f7f3ea; flex: 0 0 auto;
}
.login-logo {
    width: 74px; height: 74px; border-radius: 50%; object-fit: cover;
    border: 2px solid var(--gold); background: #f7f3ea; display: block; margin: 0 auto 8px;
}
/* تثبيت أبعاد شعار صفحات الدخول والتثبيت ومنع تمدده بالحجم الأصلي */
body.login-body .login-card .login-brand img.login-logo {
    display: block !important;
    width: 74px !important;
    height: 74px !important;
    min-width: 74px !important;
    min-height: 74px !important;
    max-width: 74px !important;
    max-height: 74px !important;
    object-fit: contain !important;
    object-position: center !important;
    flex: 0 0 74px !important;
    margin: 0 auto 8px !important;
}

.print-only { display: none; }

.login-brand { text-align: center; margin-bottom: 18px; }
.login-brand .brand-name { font-size: 26px; font-weight: 800; color: var(--charcoal); display: block; }
.login-brand .brand-sub { color: var(--muted); font-size: 12.5px; }
.login-card .field { margin-bottom: 14px; }
.btn-block { width: 100%; padding: 11px; font-size: 15px; }
.login-note { color: var(--muted); font-size: 11.8px; margin-top: 14px; line-height: 1.7; }

.demo-banner {
    background: repeating-linear-gradient(45deg, #8a6d1f, #8a6d1f 14px, #a3872c 14px, #a3872c 28px);
    color: #fff; text-align: center; padding: 6px 10px; font-weight: 700; font-size: 13.5px;
}

.app { display: flex; min-height: 100vh; }

/* ---------- القائمة الجانبية اليمنى ---------- */
.sidebar {
    width: 268px; min-width: 268px;
    background: linear-gradient(180deg, var(--charcoal), var(--black));
    color: var(--beige-light);
    display: flex; flex-direction: column;
    position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.sidebar-head { padding: 14px 16px 10px; border-bottom: 1px solid rgba(217,205,184,.15); }
.brand { display: flex; align-items: center; gap: 10px; }
.brand .brand-name { display: block; font-size: 19px; font-weight: 800; color: var(--gold-soft); letter-spacing: .5px; }
.brand .brand-sub { display: block; font-size: 11px; color: var(--beige); opacity: .85; }
.menu-toggle { display: none; }

.nav { padding: 8px 0 30px; }
.nav-group { margin-bottom: 2px; }
.nav-group-toggle {
    width: 100%; text-align: right; background: none; border: 0; cursor: pointer;
    color: var(--beige-light); font-family: inherit; font-size: 14.5px; font-weight: 700;
    padding: 10px 16px; display: flex; justify-content: space-between; align-items: center;
}
.nav-group-toggle:hover { color: var(--gold-soft); background: rgba(255,255,255,.04); }
.nav-group-toggle .arrow { font-size: 11px; transition: transform .15s; color: var(--gold); }
.nav-group.open .nav-group-toggle .arrow { transform: rotate(180deg); }
.nav-items { display: none; }
.nav-group.open .nav-items { display: block; }
.nav-item {
    display: block; padding: 7px 28px 7px 12px; color: var(--beige);
    font-size: 13.5px; border-right: 3px solid transparent;
}
.nav-item:hover { color: #fff; background: rgba(255,255,255,.05); }
.nav-item.active {
    color: var(--gold-soft); background: rgba(180,154,94,.14);
    border-right-color: var(--gold); font-weight: 700;
}

/* ---------- الشريط العلوي ---------- */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
    background: var(--paper); border-bottom: 1px solid var(--line);
    display: flex; justify-content: space-between; align-items: center;
    padding: 10px 22px; position: sticky; top: 0; z-index: 50;
}
.topbar-title { font-weight: 800; font-size: 16.5px; color: var(--black); }
.topbar-left { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.user-chip { text-align: left; line-height: 1.25; }
.user-name { display: block; font-weight: 700; font-size: 13px; }
.user-role { display: block; font-size: 11.5px; color: var(--muted); }
.bell { font-weight: 700; padding: 6px 12px; border-radius: 8px; background: var(--beige-light); color: var(--charcoal); }
.bell-on { background: var(--gold); color: #fff; }

.content { padding: 20px 22px 40px; flex: 1; }
.footer { text-align: center; color: var(--muted); font-size: 12px; padding: 12px; border-top: 1px solid var(--line); background: var(--paper); }

/* ---------- العناصر العامة ---------- */
.page-title { font-size: 20px; font-weight: 800; margin: 0 0 4px; color: var(--black); }
.page-sub { color: var(--muted); font-size: 13px; margin: 0 0 16px; }
.card {
    background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius);
    box-shadow: var(--shadow); padding: 16px 18px; margin-bottom: 16px;
}
.card-title { font-weight: 800; font-size: 15.5px; margin: 0 0 12px; color: var(--black); }
.grid { display: grid; gap: 14px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.kpi { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi .kpi-label { color: var(--muted); font-size: 12.5px; }
.kpi .kpi-value { font-size: 21px; font-weight: 800; color: var(--black); }
.kpi .kpi-extra { font-size: 12px; color: var(--gold); font-weight: 700; }
.kpi.kpi-accent { border-top: 3px solid var(--gold); }

/* ---------- الأزرار ---------- */
.btn {
    display: inline-block; border: 1px solid var(--gold); background: var(--gold); color: #fff;
    padding: 8px 18px; border-radius: 8px; cursor: pointer; font-family: inherit; font-size: 13.5px;
    font-weight: 700; transition: background .15s;
}
.btn:hover { background: #94793f; border-color: #94793f; color: #fff; }
.btn-outline { background: transparent; color: var(--gold); }
.btn-outline:hover { background: rgba(180,154,94,.12); color: var(--gold); }
.btn-dark { background: var(--charcoal); border-color: var(--charcoal); }
.btn-dark:hover { background: var(--black); }
.btn-danger { background: var(--red); border-color: var(--red); }
.btn-danger:hover { background: #96271b; }
.btn-sm { padding: 4px 12px; font-size: 12.5px; }
.btn-ghost { background: var(--beige-light); border-color: var(--beige-light); color: var(--charcoal); }
.btn-ghost:hover { background: var(--beige); color: var(--black); }
.btn[disabled] { opacity: .55; cursor: not-allowed; }

/* ---------- الجداول ---------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; background: var(--paper); }
table.data th {
    background: var(--charcoal); color: #fff; font-weight: 700; font-size: 12.8px;
    padding: 9px 10px; text-align: right; white-space: nowrap; position: sticky; top: 0;
}
table.data td { padding: 8px 10px; border-bottom: 1px solid var(--line); font-size: 13.2px; vertical-align: middle; }
table.data tr:nth-child(even) td { background: #faf7f0; }
table.data tr:hover td { background: #f3ecdd; }
table.data td.num, table.data th.num { text-align: left; font-variant-numeric: tabular-nums; direction: ltr; text-align: right; }
table.data .row-total td { background: var(--beige-light) !important; font-weight: 800; }
table.totals td { padding: 6px 10px; font-size: 13.5px; }
table.totals .grand td { font-weight: 800; border-top: 2px solid var(--gold); font-size: 14.5px; }

/* ---------- الشارات ---------- */
.badge { display: inline-block; padding: 2px 10px; border-radius: 20px; font-size: 11.8px; font-weight: 700; white-space: nowrap; }
.badge-gray { background: #e8e6e2; color: #5d5a55; }
.badge-yellow { background: #fdf3c7; color: #7a6410; }
.badge-warn { background: #f3e3b3; color: #7a5a08; }
.badge-green { background: #ddefdd; color: #1e5e21; }
.badge-red { background: #f6d5d0; color: #8c2318; }
.badge-gold { background: #efe4c8; color: #7a6420; }

/* ---------- النماذج ---------- */
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px 16px; }
.form-grid .full { grid-column: 1 / -1; }
.field label { display: block; font-weight: 700; font-size: 12.8px; margin-bottom: 4px; color: var(--charcoal); }
.field .req { color: var(--red); }
input[type=text], input[type=number], input[type=date], input[type=password], input[type=email], select, textarea {
    width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px;
    font-family: inherit; font-size: 13.5px; background: #fff; color: var(--charcoal);
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(180,154,94,.35); border-color: var(--gold); }
textarea { min-height: 74px; resize: vertical; }
.help { color: var(--muted); font-size: 11.8px; margin-top: 3px; }

.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; margin-bottom: 14px; }
.filters .field { min-width: 160px; }

/* ---------- الرسائل ---------- */
.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; font-weight: 700; font-size: 13.5px; }
.flash-success { background: #ddefdd; color: #1e5e21; border: 1px solid #b5d6b6; }
.flash-error { background: #f6d5d0; color: #8c2318; border: 1px solid #e6b1aa; }
.flash-info { background: #efe4c8; color: #6b5518; border: 1px solid #dcc998; }

/* ---------- دوائر الإنجاز ---------- */
.donut { display: inline-block; vertical-align: middle; }
.donut-link { cursor: pointer; }
.donut-link:hover circle:first-of-type { stroke: var(--beige); }

/* ---------- لوحة المشاريع بالمراحل ---------- */
.stages-flow { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin: 8px 0; }
.stage-chip {
    border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; text-align: center;
    font-size: 11.8px; background: #faf7f0; color: var(--muted);
}
.stage-chip.done { background: #ddefdd; color: #1e5e21; border-color: #b5d6b6; font-weight: 700; }
.stage-chip.current { background: var(--gold); color: #fff; border-color: var(--gold); font-weight: 800; }

/* ---------- التنبيهات ---------- */
.alert-row { border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px; margin-bottom: 8px; background: var(--paper); }
.alert-row.sev-critical { border-right: 4px solid var(--red); }
.alert-row.sev-warning { border-right: 4px solid var(--orange); }
.alert-row.sev-info { border-right: 4px solid var(--gold); }
.alert-meta { color: var(--muted); font-size: 12px; }

/* ---------- التقارير ---------- */
.report-head { display: flex; justify-content: space-between; align-items: flex-start; flex-wrap: wrap; gap: 10px; margin-bottom: 12px; }
.no-print { }
.print-only { display: none; }

/* ============ الطباعة الموحدة (A4 طولي/عرضي) ============ */
/* حاوية صفحات الطباعة: على الشاشة خارج الحقل لقياس دقيق، وعند الطباعة تصير هي المستند */
#dlPrintPages { position: absolute; top: 0; right: -9999px; width: 210mm; direction: rtl; }
#dlPrintPages .dl-page {
    width: 210mm; height: 292mm; box-sizing: border-box; position: relative;
    padding: 10mm 12mm 16mm; background: #fff; overflow: hidden;
    font-size: 11.5pt; color: #1a1917;
}
#dlPrintPages .dl-page-head { border-bottom: 2px solid #b49a5e; padding-bottom: 2mm; margin-bottom: 4mm; }
#dlPrintPages .dl-page-head .print-head { display: flex; align-items: center; gap: 12px; }
#dlPrintPages .dl-page-head .print-head img { width: 58px; height: 58px; border-radius: 50%; object-fit: cover; border: 1px solid #b49a5e; }
#dlPrintPages .dl-page-head .print-head .p-company { font-size: 14pt; font-weight: 800; color: #1a1917; }
#dlPrintPages .dl-page-head .print-head .p-meta { font-size: 9.5pt; color: #7a746a; }
#dlPrintPages .dl-page-head .print-head .p-period:not(:empty) { display: inline-block; margin-left: 8px; font-weight: 700; color: #6b5518; }
#dlPrintPages .dl-page-head .ph-compact {
    display: flex; justify-content: space-between; align-items: center;
    font-size: 9.5pt; color: #7a746a; font-weight: 700;
}
#dlPrintPages .dl-page-foot {
    position: absolute; bottom: 6mm; right: 12mm; left: 12mm;
    display: flex; justify-content: space-between; align-items: center;
    border-top: 0.5mm solid #d9cdb8; padding-top: 1.5mm;
    font-size: 8.5pt; color: #7a746a;
}
#dlPrintPages table.data { width: 100%; border-collapse: collapse; }
#dlPrintPages table.data th {
    background: #efeadf !important; color: #1a1917 !important; font-weight: 700;
    font-size: 10pt; padding: 5px 7px; border: 0.2mm solid #c9bfa8; text-align: right;
    -webkit-print-color-adjust: exact; print-color-adjust: exact;
}
#dlPrintPages table.data td { padding: 4px 7px; border: 0.2mm solid #ddd3c0; font-size: 9.8pt; }
#dlPrintPages table.data tr:nth-child(even) td { background: #faf7f0; }
#dlPrintPages table.totals td { padding: 4px 7px; font-size: 10pt; }
#dlPrintPages .card, #dlPrintPages .kpi { box-shadow: none; border: 0.3mm solid #ddd3c0; border-radius: 2mm; margin-bottom: 4mm; padding: 4mm; background: #fff; }
#dlPrintPages h2.page-title { font-size: 14pt; }
#dlPrintPages h3.card-title { font-size: 12pt; }

@media print {
    /* إخفاء كل عناصر الواجهة غير المطلوبة للطباعة */
    body { background: #fff; }
    .sidebar, .topbar, .footer, .no-print, .demo-banner, .filters, .btn, .pagination, .menu-toggle,
    .flash, .attach-list form, form.no-print, form.filters, input, select, textarea, button { display: none !important; }
    .app { display: block; }
    .content { padding: 0; }

    /* الوضع العادي: طباعة مباشرة للمحتوى بهوامش A4 */
    @page { size: A4 portrait; margin: 12mm; }
    body.print-landscape { }
    .print-only { display: block !important; margin-bottom: 14px; border-bottom: 2px solid var(--gold); padding-bottom: 10px; }
    .print-only .print-head { display: flex; align-items: center; gap: 12px; }
    .print-only img { width: 64px; height: 64px; border-radius: 50%; object-fit: cover; }
    .print-only .p-company { font-size: 18px; font-weight: 800; color: #1a1917; }
    .print-only .p-meta { font-size: 11.5px; color: #7a746a; }
    .print-only .p-period:not(:empty) { display: inline-block; margin-left: 8px; font-weight: 700; color: #6b5518; }

    .card { box-shadow: none; border: none; padding: 0; margin-bottom: 14px; page-break-inside: avoid; }
    table.data { width: 100%; border-collapse: collapse; }
    table.data thead { display: table-header-group; }
    table.data th { background: #efeadf !important; color: #1a1917 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    table.data tr { page-break-inside: avoid; }
    table.data td, table.data th { word-break: normal; overflow-wrap: anywhere; }
    h2.page-title, h3.card-title { page-break-after: avoid; }
    tr, td, th, img { page-break-inside: avoid; }

    /* وضع ترقيم الصفحات: عند الضغط على زر الطباعة تُبنى صفحات A4 ثابتة برأس وتذييل موحدين */
    body.dl-paging > *:not(#dlPrintPages) { display: none !important; }
    body.dl-paging #dlPrintPages { position: static; width: auto; display: block !important; }
    body.dl-paging .dl-page { page-break-after: always; page-break-inside: avoid; }
    body.dl-paging .dl-page:last-child { page-break-after: auto; }
    body.dl-paging .dl-page .dl-page-foot { display: flex !important; }
}

/* ---------- استجابة الجوال ---------- */
@media (max-width: 1080px) {
    .grid-4 { grid-template-columns: repeat(2, 1fr); }
    .grid-3 { grid-template-columns: repeat(2, 1fr); }
    .stages-flow { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 860px) {
    .sidebar {
        position: fixed; right: -290px; transition: right .25s ease; z-index: 100; height: 100vh;
        box-shadow: -4px 0 18px rgba(0,0,0,.25);
    }
    .sidebar.open { right: 0; }
    .topbar .menu-toggle {
        display: inline-block; background: var(--charcoal); color: var(--beige-light);
        border: 1px solid var(--charcoal); border-radius: 8px; padding: 6px 14px; font-family: inherit; font-weight: 700; cursor: pointer;
    }
    .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
    .form-grid { grid-template-columns: 1fr; }
    .content { padding: 14px; }
    .topbar { flex-wrap: wrap; gap: 8px; }
}
.pagination { margin-top: 12px; display: flex; gap: 6px; flex-wrap: wrap; }
.pg-link, .pg-current { padding: 4px 11px; border-radius: 6px; border: 1px solid var(--line); background: var(--paper); font-size: 13px; }
.pg-current { background: var(--gold); color: #fff; border-color: var(--gold); font-weight: 700; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mt { margin-top: 14px; }
.mb0 { margin-bottom: 0; }
.flex-between { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.attach-list { margin: 6px 0 0; padding: 0; list-style: none; }
.attach-list li { padding: 3px 0; font-size: 12.8px; }


/* إصلاح ظهور شعار الطباعة بحجم الصورة الأصلي داخل لوحة الإدارة */
@media screen {
    .print-only { display: none !important; visibility: hidden !important; }
    .print-only img { width: 64px !important; height: 64px !important; max-width: 64px !important; max-height: 64px !important; object-fit: contain !important; }
}
@media print {
    .print-only { display: block !important; visibility: visible !important; }
    .print-only img { width: 64px !important; height: 64px !important; max-width: 64px !important; max-height: 64px !important; object-fit: contain !important; }
}

/* تبديل مستوى العرض: يلتف الزر في الشاشات الضيقة دون تجاوز عرض الصفحة */
.topbar-right { display:flex; align-items:center; gap:10px; min-width:0; flex-wrap:wrap; }
@media (max-width: 760px) {
    .topbar { gap:8px; padding:10px 12px; flex-wrap:wrap; }
    .topbar-right, .topbar-left { min-width:0; max-width:100%; }
    .topbar-title { font-size:14px; }
}


/* محدد الفرع الحالي في الشريط العلوي */
.branch-switch-form{display:flex;align-items:center;gap:6px;flex-wrap:wrap;margin:0;padding:0}
.branch-switch-label,.branch-current-label{font-size:12px;color:var(--muted,#777);white-space:nowrap}
.branch-switch-form select{min-width:150px;max-width:220px;height:34px;padding:5px 9px;border:1px solid var(--border,#ddd);border-radius:8px;background:#fff;color:inherit;font:inherit;font-size:12px}
@media(max-width:700px){.branch-switch-form{width:100%;order:3}.branch-switch-form select{flex:1;min-width:110px;max-width:none}}
