:root {
  --brand: #382565;
  --brand-dark: #252655;
  --ink: #1e293b;
  --side-bg: linear-gradient(180deg, #382565 0%, #252655 100%);
  --side-ink: #d3cbea;
  --bg: #f5f4fa;
  --line: #e6e3f0;
  --bs-font-sans-serif: 'Tajawal', 'Segoe UI', Tahoma, Arial, sans-serif;
}
body { background: var(--bg); color: var(--ink); font-family: var(--bs-font-sans-serif); font-size: .95rem; }
.btn-brand { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-brand:hover, .btn-brand:focus { background: var(--brand-dark); border-color: var(--brand-dark); color: #fff; }
.btn-outline-brand { color: var(--brand); border-color: var(--brand); }
.btn-outline-brand:hover { background: var(--brand); color: #fff; }
.text-brand { color: var(--brand) !important; }

/* ===== الهيكل ===== */
.sidebar { width: 250px; min-height: 100vh; background: var(--side-bg); color: var(--side-ink); flex-shrink: 0; }
.sidebar .brand { padding: 1.1rem 1.25rem; color: #fff; font-weight: 700; font-size: 1.05rem; border-bottom: 1px solid rgba(255,255,255,.08); display: flex; gap: .6rem; align-items: center; }
.sidebar .brand i { background: var(--brand); border-radius: 8px; padding: .3rem .45rem; }
.sidebar .nav-link { color: var(--side-ink); padding: .6rem 1.25rem; display: flex; gap: .7rem; align-items: center; border-inline-start: 3px solid transparent; }
.sidebar .nav-link:hover { background: rgba(255,255,255,.05); color: #fff; }
.sidebar .nav-link.active { background: rgba(255,255,255,.14); color: #fff; border-inline-start-color: #c4b5fd; }
.sidebar .nav-title { font-size: .72rem; letter-spacing: .04em; color: #a79dcb; padding: 1rem 1.25rem .3rem; }
.main { min-width: 0; flex: 1; }
.topbar { background: #fff; border-bottom: 1px solid var(--line); padding: .7rem 1.5rem; }
.content { padding: 1.5rem; max-width: 1400px; }
@media (max-width: 991.98px) { .content { padding: 1rem; } .topbar { padding: .6rem 1rem; } }
@media (min-width: 992px) { .sidebar-lg { position: sticky; top: 0; height: 100vh; overflow-y: auto; } }

/* ===== بطاقات ===== */
.card { border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 1px 2px rgba(37,38,85,.05); }
.card-header { background: #fff; border-bottom: 1px solid var(--line); font-weight: 700; border-radius: 12px 12px 0 0 !important; }
.stat { display: flex; gap: .9rem; align-items: center; }
.stat .ico { width: 46px; height: 46px; border-radius: 12px; display: grid; place-items: center; font-size: 1.3rem; background: #ece8f6; color: var(--brand); }
.stat .ico.warn { background: #fff4dc; color: #b7791f; }
.stat .ico.bad { background: #fde8e8; color: #c53030; }
.stat .ico.info { background: #e6effc; color: #2b6cb0; }
.stat .val { font-size: 1.35rem; font-weight: 700; line-height: 1.2; }
.stat .lbl { color: #64748b; font-size: .82rem; }

/* ===== جداول ===== */
.table > :not(caption) > * > * { padding: .7rem .75rem; }
.table thead th { background: #f8f7fc; color: #475569; font-weight: 600; font-size: .82rem; white-space: nowrap; border-bottom: 1px solid var(--line); }
.table-hover tbody tr:hover { background: #f8f7fd; }
.num { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: plaintext; text-align: end; white-space: nowrap; }
.ltr { direction: ltr; unicode-bidi: plaintext; }
.form-label { font-weight: 600; font-size: .85rem; }
.form-control:focus, .form-select:focus { border-color: var(--brand); box-shadow: 0 0 0 .2rem rgba(56,37,101,.16); }
.required::after { content: ' *'; color: #dc2626; }

/* ===== محرر البنود ===== */
.lines-table input, .lines-table select { min-width: 70px; }
.lines-table .c-name { min-width: 220px; }
.lines-table .c-vat { min-width: 170px; }
.totals-box { background: #f8f7fc; border: 1px solid var(--line); border-radius: 10px; padding: 1rem; }
.totals-box .row + .row { margin-top: .35rem; }
.totals-box .grand { font-size: 1.15rem; font-weight: 700; color: var(--brand); border-top: 1px dashed #b9b1d6; padding-top: .5rem; margin-top: .5rem; }

/* ===== الدخول ===== */
.login-wrap { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(160deg, #382565, #252655); padding: 1rem; }
.login-card { width: 100%; max-width: 400px; border-radius: 16px; }

/* ===== صفحة الفاتورة للطباعة ===== */
.doc-page { background: #fff; max-width: 210mm; margin: 1rem auto; padding: 14mm; border: 1px solid var(--line); border-radius: 6px; position: relative; overflow: hidden; }
.doc-page h1 { font-size: 1.5rem; }
.doc-page .party { border: 1px solid #d5dee1; border-radius: 6px; padding: .7rem .9rem; height: 100%; }
.doc-page .party h6 { color: var(--brand); font-size: .8rem; margin-bottom: .4rem; }
.doc-page table.items th { background: #ece8f6 !important; font-size: .78rem; }
.doc-page table.items td, .doc-page table.items th { padding: .45rem .55rem; border: 1px solid #d5dee1; }
.doc-page .sum td { padding: .3rem .6rem; }
.watermark { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; font-size: 6rem; font-weight: 800; color: rgba(56, 37, 101, .07); transform: rotate(-30deg); z-index: 0; }
.doc-page > *:not(.watermark) { position: relative; z-index: 1; }
@media print {
  body { background: #fff; }
  .no-print { display: none !important; }
  .doc-page { border: 0; margin: 0; padding: 0; max-width: none; border-radius: 0; }
  @page { size: A4; margin: 12mm; }
}

/* ===== هوية مجرد مبدعون ===== */
:root { --bs-link-color: #382565; --bs-link-hover-color: #252655; --bs-link-color-rgb: 56,37,101; --bs-link-hover-color-rgb: 37,38,85; }
.btn-primary { --bs-btn-bg: #382565; --bs-btn-border-color: #382565; --bs-btn-hover-bg: #252655; --bs-btn-hover-border-color: #252655; --bs-btn-active-bg: #252655; }
.nav-tabs .nav-link { color: #5b5580; }
.nav-tabs .nav-link.active { color: var(--brand); font-weight: 700; border-bottom-color: #fff; }
.page-link { color: var(--brand); }
.active > .page-link { background: var(--brand); border-color: var(--brand); }
.sidebar .brand { justify-content: center; padding: 1rem; }
.sidebar .brand img { max-width: 100%; max-height: 56px; }
.login-logo { max-width: 260px; width: 100%; margin: 0 auto 1rem; display: block; }

/* ===== رأس الفاتورة ===== */
.doc-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding-bottom: .9rem; border-bottom: 3px solid var(--brand); }
.doc-head .co { display: flex; gap: .9rem; align-items: center; min-width: 0; }
.doc-head .co img { max-height: 64px; max-width: 150px; }
.doc-head .ttl { text-align: end; flex-shrink: 0; }
.doc-head .ttl h1 { color: var(--brand); margin: 0; font-weight: 800; }
.doc-meta { display: flex; flex-wrap: wrap; gap: .5rem; margin: .8rem 0 1rem; }
.doc-meta > div { flex: 1 1 130px; background: #f3f0fa; border-radius: 6px; padding: .4rem .7rem; }
.doc-meta small { display: block; color: #6b6590; font-size: .72rem; }
.doc-meta b { white-space: nowrap; direction: ltr; unicode-bidi: isolate; display: inline-block; }
.num, .ltr { unicode-bidi: isolate; }
.doc-page .party h6 { color: var(--brand); }
.doc-page table.items th { color: #252655; }
@media print {
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

.form-check-input:checked { background-color: var(--brand); border-color: var(--brand); }
.form-check-input:focus { border-color: var(--brand); box-shadow: 0 0 0 .2rem rgba(56,37,101,.16); }
.border-brand { border-color: var(--brand) !important; }

/* ===== تحسين رأس الفاتورة ===== */
.doc-head { align-items: flex-start; }
.doc-head .co { display: block; }
.doc-head .co .co-logo { max-height: 84px; max-width: 240px; display: block; margin-bottom: .35rem; }
.doc-head .ttl h1 { font-size: 1.6rem; }
.doc-head .qr-mini { margin-top: .5rem; display: inline-block; line-height: 0; }
.doc-head .qr-mini svg { width: 108px; height: 108px; }
.doc-page table.items td.num { text-align: end; }

/* ===== الشكل العصري: رأس بيانات المنشأة ===== */
.tpl-modern .doc-head .co-name { font-size: 1.1rem; font-weight: 700; }
.tpl-modern .doc-head .co-lines { font-size: .8rem; color: #4b5563; line-height: 1.7; margin-top: .15rem; }
.tpl-modern .party { border: 1px solid #d5cfe8; border-radius: 6px; padding: .6rem .9rem; }

/* ===== الشكل الكلاسيكي (بسيط) ===== */
.tpl-classic { font-size: .82rem; color: #111; padding: 12mm; }
.tpl-classic .cl-head { display: flex; align-items: flex-start; gap: 1rem; }
.tpl-classic .cl-logo { max-height: 90px; max-width: 150px; object-fit: contain; }
.tpl-classic .cl-co { flex: 1; line-height: 1.7; }
.tpl-classic .cl-co-name { font-weight: 800; font-size: 1.05rem; }
.tpl-classic .cl-title { text-align: end; }
.tpl-classic .cl-title-ar { font-weight: 800; font-size: 1.15rem; }
.tpl-classic .cl-title-en { font-size: .75rem; color: #555; }
.tpl-classic .cl-qr { line-height: 0; margin-top: .4rem; }
.tpl-classic .cl-qr svg { width: 100px; height: 100px; }
.tpl-classic .cl-info { display: flex; justify-content: space-between; gap: 1rem; margin: 1rem 0 .8rem; line-height: 1.8; }
.tpl-classic .cl-num { text-align: start; min-width: 150px; }
.tpl-classic .cl-table { width: 100%; border-collapse: collapse; margin-bottom: .6rem; }
.tpl-classic .cl-table th { background: #ececec; font-weight: 700; padding: .4rem .5rem; text-align: start; border: 0; font-size: .75rem; }
.tpl-classic .cl-table td { padding: .5rem; border-bottom: 1px solid #e2e2e2; vertical-align: top; }
.tpl-classic .cl-table .cl-desc { color: #555; font-size: .75rem; }
.tpl-classic .cl-table .c { text-align: center; }
.tpl-classic .cl-totals { width: 46%; border-collapse: collapse; margin-bottom: 1rem; }
.tpl-classic .cl-totals td { padding: .35rem .6rem; border-bottom: 1px solid #ddd; }
.tpl-classic .cl-totals tr.cl-grand td { font-weight: 800; border-bottom: 2px solid #111; }
.tpl-classic .cl-pay { margin-top: 1.2rem; line-height: 1.8; }
.tpl-classic .cl-pay-h { font-weight: 800; }
.tpl-classic .cl-notes { margin-top: .8rem; }
.tpl-classic .num { text-align: end; }
