:root {
  /* هذه قيم افتراضية احتياطية فقط — تُستبدل فعلياً بالقيم المشتقة من "لون العلامة التجارية"
     في إعدادات المنشأة عبر <style> يُحقن في layouts/base.blade.php (انظر Company::brandColor()) */
  --brand: #382565;
  --brand-dark: #252655;
  --brand-rgb: 56,37,101;
  --brand-ink: #fff;
  --ink: #1e293b;
  --side-bg: linear-gradient(180deg, #382565 0%, #252655 100%);
  --side-ink: #d3cbea;
  --brand-tint: #f5f4f7;
  --brand-tint-border: #dbd8e3;
  --brand-tint-text: #6b6590;
  --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: var(--brand-ink); }
.btn-brand:hover, .btn-brand:focus { background: var(--brand-dark); border-color: var(--brand-dark); color: var(--brand-ink); }
.btn-outline-brand { color: var(--brand); border-color: var(--brand); }
.btn-outline-brand:hover { background: var(--brand); color: var(--brand-ink); }
.text-bg-brand { background: var(--brand); color: var(--brand-ink); }
.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-group-toggle {
    display: flex; align-items: center; justify-content: space-between; width: 100%;
    background: none; border: none; font: inherit; text-align: inherit;
    font-size: .92rem; font-weight: 800; letter-spacing: 0; color: #fff;
    padding: 1.25rem 1.25rem .5rem; cursor: pointer;
}
.sidebar .nav-group-toggle:hover { color: #e4defc; }
.sidebar .nav-group-toggle .chevron { transition: transform .15s ease; font-size: .75rem; color: #a79dcb; }
.sidebar .nav-group-toggle[aria-expanded="false"] .chevron { transform: rotate(-90deg); }
/* الروابط الفرعية داخل مجموعة أصغر وأكثر دخولاً من عنوانها — يعزّز التدرّج البصري بينهما */
.sidebar .nav-group .nav-link { font-size: .85rem; padding-inline-start: 1.7rem; }
.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; } }
@media print {
    .sidebar, .topbar, .no-print { display: none !important; }
    .main, .content { margin: 0 !important; padding: 0 !important; max-width: none !important; }
    body { background: #fff !important; }
}

/* ===== بطاقات ===== */
.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: var(--brand-tint); 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: var(--brand-tint); 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(var(--brand-rgb),.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: var(--brand-tint); 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 var(--brand-tint-border); padding-top: .5rem; margin-top: .5rem; }

/* ===== الدخول ===== */
.login-wrap { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(160deg, var(--brand), var(--brand-dark)); 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 var(--brand-tint-border); 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: var(--brand-tint) !important; font-size: .78rem; }
.doc-page table.items td, .doc-page table.items th { padding: .45rem .55rem; border: 1px solid var(--brand-tint-border); }
.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(var(--brand-rgb),.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; }
  /* "page: doc-a4" تحصر حجم A4 على صفحات المستندات فقط (.doc-page) — بدون هذا، كان تعريف @page هنا
     يتصادم مع @page الخاص بإيصال نقطة البيع الحراري (80مم) لأن app.css يُحمَّل بكل الصفحات، فتفرض
     المتصفح مقاس A4 على الطابعة الحرارية بدل حجم الرول الفعلي. */
  .doc-page { border: 0; margin: 0; padding: 0; max-width: none; border-radius: 0; page: doc-a4; }
  @page doc-a4 { size: A4; margin: 12mm; }
}

/* ===== هوية مجرد مبدعون ===== */
:root { --bs-link-color: var(--brand); --bs-link-hover-color: var(--brand-dark); --bs-link-color-rgb: var(--brand-rgb); --bs-link-hover-color-rgb: var(--brand-rgb); }
.btn-primary { --bs-btn-bg: var(--brand); --bs-btn-border-color: var(--brand); --bs-btn-hover-bg: var(--brand-dark); --bs-btn-hover-border-color: var(--brand-dark); --bs-btn-active-bg: var(--brand-dark); }
.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: var(--brand-tint); border-radius: 6px; padding: .4rem .7rem; }
.doc-meta small { display: block; color: var(--brand-tint-text); 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: var(--brand-dark); }
@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(var(--brand-rgb),.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; }

/* ===== لوحة التحكم ===== */
.kpi { position: relative; overflow: hidden; }
.kpi .lbl { color: #64748b; font-size: .85rem; font-weight: 600; }
.kpi .val { font-size: 1.7rem; font-weight: 800; line-height: 1.25; color: var(--ink); }
.kpi .val small { font-size: .9rem; font-weight: 600; color: #94a3b8; }
.kpi .ico { position: absolute; left: 1rem; top: 1rem; width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; font-size: 1.25rem; background: var(--brand-tint); color: var(--brand); }
.kpi .ico.ok { background: #e3f6ea; color: #1f8f4d; } .kpi .ico.warn { background: #fff4dc; color: #b7791f; } .kpi .ico.bad { background: #fde8e8; color: #c53030; }
.kpi .chg { font-size: .78rem; font-weight: 700; padding: .1rem .5rem; border-radius: 99px; }
.kpi .chg.up { background: #e3f6ea; color: #1f8f4d; } .kpi .chg.down { background: #fde8e8; color: #c53030; } .kpi .chg.flat { background: #eef0f4; color: #64748b; }
.qa { display: grid; grid-template-columns: repeat(3, 1fr); gap: .6rem; }
.qa a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .35rem; padding: .95rem .4rem; border-radius: 14px; border: 1px solid var(--line); background: #fff; color: var(--ink); text-decoration: none; font-size: .8rem; font-weight: 700; text-align: center; transition: all .15s; }
.qa a i { font-size: 1.6rem; color: var(--brand); }
.qa a:hover { border-color: var(--brand); background: var(--brand-tint); transform: translateY(-2px); }
.chart-box { position: relative; height: 320px; }
.chart-box.sm { height: 260px; }
.chart-empty { display: grid; place-items: center; height: 100%; color: #94a3b8; font-size: .9rem; }

/* ===== ملف العميل / المورد ===== */
.profile-head { background: linear-gradient(135deg, #ffffff 0%, var(--brand-tint) 100%); border-inline-start: 4px solid var(--brand); }
.profile-head .avatar { width: 64px; height: 64px; border-radius: 18px; background: linear-gradient(135deg, var(--brand), var(--brand-dark)); color: var(--brand-ink); display: grid; place-items: center; font-size: 1.7rem; font-weight: 800; flex: none; box-shadow: 0 8px 20px rgba(var(--brand-rgb),.25); }
.chips { display: flex; flex-wrap: wrap; gap: .5rem; }
.chip { display: inline-flex; align-items: center; gap: .4rem; padding: .25rem .7rem; border-radius: 99px; background: #fff; border: 1px solid var(--line); color: #475569; font-size: .8rem; text-decoration: none; }
.chip b { color: var(--ink); }
a.chip:hover { border-color: var(--brand); color: var(--brand); }
.chip-warn { background: #fff4dc; border-color: #f5d68a; color: #92600d; }
.chip-wa { background: #e8f8ee; border-color: #b7e4c7; color: #1f8f4d; }
.copy-btn { border: 0; background: transparent; color: #94a3b8; padding: 0 .15rem; line-height: 1; cursor: pointer; }
.copy-btn:hover { color: var(--brand); }
.info-item { display: flex; align-items: flex-start; gap: .8rem; padding: .7rem 0; border-bottom: 1px dashed var(--line); }
.info-item:last-child { border-bottom: 0; }
.info-item .ii { width: 34px; height: 34px; border-radius: 10px; background: #f1eef9; color: var(--brand); display: grid; place-items: center; flex: none; font-size: .95rem; }
.info-item .il { font-size: .74rem; color: #94a3b8; font-weight: 600; }
.info-item .iv { font-weight: 600; color: var(--ink); overflow-wrap: anywhere; }
.info-item .iv.ltr { text-align: right; }

/* ===== القائمة الجانبية في الجوال: عرض مناسب + تمرير كامل + زر إغلاق ===== */
.sidebar .brand { position: relative; }
.sidebar .close-side { position: absolute; inset-inline-end: .6rem; top: .6rem; }
@media (max-width: 991.98px) {
    .sidebar.sidebar-lg { --bs-offcanvas-width: min(290px, 84vw); width: min(290px, 84vw); min-height: 0; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
    .sidebar .nav-link { padding: .8rem 1.25rem; }
    .sidebar nav { padding-bottom: calc(1.5rem + env(safe-area-inset-bottom)); }
    .offcanvas-backdrop { --bs-backdrop-opacity: .55; }
}

/* ===== بحث فوري لاختيار عميل (راجع partials/customer-picker.blade.php) ===== */
.customer-picker { position: relative; }
.customer-picker .cp-menu { position: absolute; z-index: 1055; top: 100%; inset-inline: 0; margin-top: 3px; background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 10px 28px rgba(20,20,40,.14); max-height: 260px; overflow-y: auto; }
.customer-picker .cp-item { padding: .5rem .8rem; cursor: pointer; }
.customer-picker .cp-item:hover { background: var(--brand-tint, #f5f4f7); }
.customer-picker .cp-name { font-weight: 600; font-size: .88rem; color: var(--ink); }
.customer-picker .cp-meta { font-size: .74rem; color: #94a3b8; direction: ltr; text-align: right; }
.customer-picker .cp-empty { padding: .65rem .8rem; color: #94a3b8; font-size: .84rem; text-align: center; }
.customer-picker .cp-cash { font-style: italic; color: #64748b; border-bottom: 1px solid var(--line); }
