/* DriveX ERP — الهوية البصرية حسب القسم 8 من وثيقة النظام */
:root {
    --bg: #eef3fb;
    --card: #ffffff;
    --text: #172033;
    --muted: #6b7280;
    --primary: #233f93;
    --primary-dark: #1b337a;
    --primary-light: #3f66d6;
    --accent: #f4c21c;
    --accent-light: #fff3bf;
    --success: #18a85a;
    --danger: #d94c4c;
    --border: #d9e3f0;
    --sidebar: linear-gradient(180deg, #1d3f87, #163573);
    --active: linear-gradient(90deg, #2f5bd6, #3c78e8);
    --radius: 14px;
    --shadow: 0 4px 18px rgba(23, 32, 51, .07);
    --topbar-h: 64px;
    --sidebar-w: 250px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; } /* السمة hidden تتغلب على أي display في الأصناف */
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    font-family: 'Cairo', Tahoma, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    line-height: 1.6;
}
a { color: var(--primary); text-decoration: none; }
img { max-width: 100%; }
h1, h2, h3 { margin: 0; line-height: 1.3; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }

/* ── الشريط العلوي ───────────────────────── */
.topbar {
    position: sticky; top: 0; z-index: 40;
    height: var(--topbar-h);
    display: flex; align-items: center; gap: 12px;
    padding: 0 16px;
    background: var(--primary);
    color: #fff;
    box-shadow: 0 2px 10px rgba(0, 0, 0, .15);
}
.brand { display: flex; align-items: center; gap: 8px; color: #fff; flex-shrink: 0; }
.brand img { height: 42px; width: auto; background: #fff; border-radius: 10px; padding: 3px 8px; }
.brand-name { font-weight: 800; font-size: 15px; white-space: nowrap; }

.mainnav { display: flex; gap: 2px; overflow-x: auto; flex: 1; scrollbar-width: none; }
.mainnav::-webkit-scrollbar { display: none; }
.mainnav a {
    display: flex; align-items: center; gap: 6px;
    color: #dbe5ff; padding: 8px 10px; border-radius: 10px;
    white-space: nowrap; font-size: 14px; font-weight: 600;
    transition: background .15s;
}
.mainnav a:hover { background: rgba(255, 255, 255, .1); color: #fff; }
.mainnav a.active { background: var(--accent); color: var(--primary-dark); }

.dev-credit { display: none; } /* يظهر في الشاشات الكبيرة فقط حيث للقائمة صف مستقل */
.userbox { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.userbox form { margin: 0; }
.avatar {
    width: 36px; height: 36px; border-radius: 50%;
    display: grid; place-items: center;
    background: var(--accent); color: var(--primary-dark); font-weight: 800;
}
.uname { display: flex; flex-direction: column; font-size: 13px; font-weight: 700; line-height: 1.2; }
.uname small { color: #c3d0f5; font-weight: 400; }

.icon-btn {
    width: 40px; height: 40px; border: 0; border-radius: 10px;
    background: rgba(255, 255, 255, .12); color: #fff;
    font-size: 20px; cursor: pointer; display: grid; place-items: center;
}
.icon-btn:hover { background: rgba(255, 255, 255, .22); }

/* على الشاشات الكبيرة: صف مستقل للقائمة حتى تظهر جميع الأقسام بلا تمرير أفقي. */
@media (min-width: 1201px) {
    :root { --topbar-h: 112px; }
    .topbar {
        height: auto; min-height: var(--topbar-h); padding: 8px 16px 6px;
        display: grid; grid-template-columns: auto auto 1fr;
        grid-template-areas: "toggle brand user" "nav nav nav";
        align-items: center; row-gap: 4px;
    }
    .topbar > .sidebar-toggle { grid-area: toggle; justify-self: start; }    .topbar > .brand { grid-area: brand; justify-self: start; }
    .topbar > .mainnav {
        grid-area: nav; width: 100%; min-width: 0; flex: none;
        justify-content: center; flex-wrap: wrap; overflow: visible; scrollbar-width: auto;
    }
    .topbar > .userbox { grid-area: user; justify-self: end; }
    .mainnav .lbl { display: inline; }
    /* في منتصف الصف الأول فوق القوائم */
    .dev-credit { display: block; position: absolute; top: 18px; left: 50%; transform: translateX(-50%);
        color: #c9d6ff; font-size: 13px; white-space: nowrap; pointer-events: none; }
}

/* ── الهيكل واللوحة الجانبية ──────────────── */
.shell { display: flex; min-height: calc(100vh - var(--topbar-h)); }
.sidebar {
    width: var(--sidebar-w); flex-shrink: 0;
    background: var(--sidebar); color: #fff;
    padding: 16px 12px;
    position: sticky; top: var(--topbar-h);
    height: calc(100vh - var(--topbar-h)); overflow-y: auto;
    transition: margin .25s ease, transform .25s ease;
}
body.sidebar-collapsed .sidebar { margin-inline-start: calc(var(--sidebar-w) * -1); }
.sidebar-head { font-weight: 800; font-size: 16px; padding: 6px 10px 14px; border-bottom: 1px solid rgba(255,255,255,.15); margin-bottom: 10px; }
.sidebar ul { list-style: none; margin: 0; padding: 0; }
.sidebar li a, .sidebar-sections a {
    display: block; color: #dbe5ff; padding: 10px 12px; border-radius: 10px; margin-bottom: 4px; font-size: 14px;
}
.sidebar li a:hover, .sidebar-sections a:hover { background: rgba(255,255,255,.08); color: #fff; }
.sidebar li a.active, .sidebar-sections a.active { background: var(--active); color: #fff; font-weight: 700; }
.sidebar-sections { display: none; margin-top: 14px; border-top: 1px solid rgba(255,255,255,.15); padding-top: 10px; }
.sidebar-sub { font-size: 12px; color: #9fb3e8; padding: 0 12px 6px; }
.backdrop { display: none; }

.content { flex: 1; min-width: 0; padding: 24px; }

/* ── عناصر عامة ─────────────────────────── */
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head h1 { font-size: 24px; color: var(--primary-dark); }
.section-title { font-size: 18px; color: var(--primary-dark); margin: 28px 0 14px; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.card.empty { text-align: center; padding: 48px 20px; }
.card.empty h1 { font-size: 56px; color: var(--primary); }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    border: 0; border-radius: 10px; padding: 10px 18px;
    font: inherit; font-weight: 700; cursor: pointer; min-height: 44px;
}
.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.success { background: var(--success); color: #fff; }
.btn.danger { background: var(--danger); color: #fff; }
.btn.accent { background: var(--accent); color: var(--primary-dark); }
.btn.block { width: 100%; }

.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-weight: 600; margin-bottom: 6px; font-size: 14px; }
.field input, .field select, .field textarea {
    width: 100%; padding: 11px 14px; min-height: 44px;
    border: 1px solid var(--border); border-radius: 10px;
    font: inherit; background: #fbfcfe; color: var(--text);
}
.account-picker { position: relative; }
.account-picker > input[data-source-search] { width: 100%; }
.account-picker-menu { position: absolute; inset-inline-start: 0; min-width: max(100%, 300px); max-width: 90vw; top: calc(100% + 4px); z-index: 1000; max-height: 260px; overflow-y: auto; padding: 5px; background: var(--card); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 12px 28px rgba(23,32,51,.18); }
.account-picker-option { display: block; width: 100%; border: 0; border-radius: 7px; background: transparent; color: var(--text); padding: 8px 10px; text-align: start; font: inherit; cursor: pointer; }
.account-picker-option:hover, .account-picker-option:focus { background: #eef3fb; color: var(--primary-dark); outline: 0; }
.account-picker-option.active, .account-picker-option[aria-selected="true"] { background: #e3ecfa; color: var(--primary-dark); font-weight: 700; }
.account-picker-empty { padding: 8px 10px; color: var(--muted); font-size: 13px; }
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid var(--primary-light); outline-offset: 0; background: #fff; }

.alert { padding: 12px 16px; border-radius: 10px; margin-bottom: 16px; font-weight: 600; }
.alert.success { background: #e6f7ee; color: #0f6d3b; border: 1px solid #b6e6cb; }
.alert.error { background: #fdecec; color: #9b2c2c; border: 1px solid #f5c2c2; }
pre.err { direction: ltr; text-align: left; background: #fdecec; padding: 12px; border-radius: 8px; white-space: pre-wrap; }

/* ── الإحصائيات ─────────────────────────── */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.stat {
    background: var(--card); border-radius: var(--radius); padding: 18px 20px;
    box-shadow: var(--shadow); border: 1px solid var(--border);
    border-inline-start: 5px solid var(--primary);
    display: flex; flex-direction: column; gap: 4px;
}
.stat.accent { border-inline-start-color: var(--accent); }
.stat.success { border-inline-start-color: var(--success); }
.stat.danger { border-inline-start-color: var(--danger); }
.stat-label { color: var(--muted); font-size: 14px; }
.stat-value { font-size: 28px; font-weight: 800; color: var(--primary-dark); }

/* ── الاختصارات ─────────────────────────── */
.shortcuts { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 16px; }
.shortcut {
    background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: var(--shadow); overflow: hidden;
    display: flex; flex-direction: column; color: var(--text);
    transition: transform .15s, box-shadow .15s, border-color .15s;
}
.shortcut:hover { transform: translateY(-3px); box-shadow: 0 10px 26px rgba(35, 63, 147, .16); border-color: var(--primary-light); }
.shortcut-img { aspect-ratio: 4 / 3; display: grid; place-items: center; background: #f6f9ff; padding: 12px; }
.shortcut-img img { max-height: 100%; object-fit: contain; }
.shortcut-label { padding: 12px; text-align: center; font-weight: 700; border-top: 3px solid var(--accent); }

/* ── صفحة الدخول ────────────────────────── */
.login-page { min-height: 100vh; background: radial-gradient(circle at 20% 20%, #3f66d6 0, #233f93 45%, #13295f 100%); }
.login-wrap {
    min-height: 100vh; display: grid; grid-template-columns: 1fr 440px;
    align-items: center; gap: 40px; max-width: 1100px; margin: 0 auto; padding: 24px;
}
.login-hero { color: #fff; text-align: center; }
.login-hero img { max-width: 420px; width: 80%; filter: drop-shadow(0 20px 30px rgba(0,0,0,.35)); }
.login-hero h2 { font-size: 28px; margin-top: 16px; }
.login-hero p { color: #c9d6ff; }
.login-hero .login-credit { margin-top: 18px; font-size: 13px; opacity: .85; }
.login-hero .login-credit a { color: inherit; font-weight: 600; text-decoration: none; }
.login-card { background: var(--card); border-radius: 20px; padding: 32px 28px; box-shadow: 0 20px 50px rgba(0,0,0,.3); }
.login-logo { display: block; width: 100%; max-width: 340px; margin: 0 auto 12px; }
.login-card h1 { font-size: 22px; color: var(--primary-dark); text-align: center; margin-bottom: 20px; }

/* ── لوحي ───────────────────────────────── */
@media (max-width: 1200px) {
    :root { --topbar-h: 64px; }
    .mainnav .lbl { display: none; }
    .mainnav a { padding: 8px 10px; font-size: 18px; }
}
@media (max-width: 992px) {
    .stats { grid-template-columns: repeat(2, 1fr); }
    .mainnav { display: none; }
    .topbar { justify-content: space-between; }
    .sidebar {
        position: fixed; top: var(--topbar-h); right: 0; z-index: 50;
        transform: translateX(100%); margin: 0 !important;
        box-shadow: -8px 0 24px rgba(0,0,0,.25);
    }
    .sidebar-sections { display: block; }
    body.sidebar-open .sidebar { transform: translateX(0); }
    body.sidebar-open .backdrop {
        display: block; position: fixed; inset: var(--topbar-h) 0 0 0; z-index: 45; background: rgba(10, 20, 45, .45);
    }
    .login-wrap { grid-template-columns: 1fr; gap: 20px; }
    .login-hero img { max-width: 260px; }
    .login-hero h2 { font-size: 22px; }
    .login-card { max-width: 440px; width: 100%; margin: 0 auto; }
}
/* ── هاتف ───────────────────────────────── */
@media (max-width: 576px) {
    body { font-size: 14px; }
    .topbar { padding: 0 10px; gap: 8px; }
    .brand img { height: 36px; padding: 2px 6px; }
    .brand-name, .uname { display: none; }
    .content { padding: 16px; }
    .page-head h1 { font-size: 20px; }
    .stats { gap: 10px; }
    .stat { padding: 14px; }
    .stat-value { font-size: 22px; }
    .shortcuts { grid-template-columns: repeat(2, 1fr); gap: 10px; }
    .shortcut-label { padding: 8px; font-size: 13px; }
    .login-hero p:not(.login-credit) { display: none; }
    .login-hero .login-credit { margin-top: 6px; font-size: 12px; }
    .login-hero img { max-width: 150px; }
    .login-hero h2 { font-size: 17px; margin-top: 4px; }
    .login-wrap { gap: 12px; padding: 16px; }
    .login-card { padding: 24px 18px; }
}

/* ── شريط الأدوات والجداول (المرحلة 1) ──── */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; margin-bottom: 16px; }
.toolbar .field { margin: 0; min-width: 180px; flex: 1; max-width: 320px; }
.toolbar .btn { min-height: 44px; }
.btn.ghost { background: #fff; color: var(--primary); border: 1px solid var(--border); }
.btn.ghost:hover { border-color: var(--primary-light); }
.btn.sm { min-height: 34px; padding: 6px 12px; font-size: 13px; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }
.actions form { margin: 0; }

.table-wrap { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 12px 14px; text-align: right; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th { background: #f4f7fd; color: var(--primary-dark); font-size: 13px; font-weight: 700; white-space: nowrap; }
.table th.num { direction: ltr; text-align: left; font-variant-numeric: tabular-nums; }
.table th.center { text-align: center; }
.docno { white-space: nowrap; unicode-bidi: isolate; }
.check-inline { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; font-weight: 600; cursor: pointer; }
.check-inline input { width: 18px; height: 18px; margin: 0; accent-color: var(--primary); }
.auto-number input { background: var(--bg, #f4f7fd); color: var(--primary-dark); font-weight: 700; cursor: not-allowed; }
/* المدين أخضر والدائن أحمر في كل الجداول (يُطبَّق من app.js حسب عنوان العمود) */
.table .dr, .table .dr strong, .table .dr input { color: var(--success); }
.table .cr, .table .cr strong, .table .cr input { color: var(--danger); }
.table th.dr, .table th.cr { font-weight: 800; }
.tb-table thead tr:first-child th[colspan] { border-bottom: 1px solid var(--border); border-inline-start: 1px solid var(--border); }
.table tbody tr:hover { background: #f9fbff; }
.table tbody tr:last-child td { border-bottom: 0; }
.table .num { direction: ltr; text-align: left; font-variant-numeric: tabular-nums; }
.table-empty { text-align: center; padding: 32px; color: var(--muted); }

/* مبلغ + عملة + سعر صرف: أجزاء منفصلة بصرياً (fx_html) — rtl حتى داخل خلايا الأرقام ltr */
.fx { display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; direction: rtl; vertical-align: middle; }
.fx-amount { direction: ltr; font-variant-numeric: tabular-nums; font-weight: 700; }
.fx-cur { padding: 1px 8px; border-radius: 999px; background: #eef2fb; color: var(--primary-dark); font-size: 12px; font-weight: 700; white-space: nowrap; }
.fx-rate { padding: 1px 8px; border-radius: 999px; background: #fff7e0; color: #7a5b00; font-size: 12px; white-space: nowrap; }
.fx-rate b { direction: ltr; unicode-bidi: isolate; font-variant-numeric: tabular-nums; }
.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; background: #eef2fb; color: var(--primary); }
.badge.success { background: #e6f7ee; color: #0f6d3b; }
.badge.danger { background: #fdecec; color: #9b2c2c; }
.badge.accent { background: var(--accent-light); color: #7a5b00; }

.pager { display: flex; gap: 6px; justify-content: center; margin-top: 16px; flex-wrap: wrap; }
.pager a { min-width: 38px; height: 38px; display: grid; place-items: center; border-radius: 10px; background: #fff; border: 1px solid var(--border); font-weight: 700; }
.pager a.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ── النماذج ───────────────────────────── */
.form-card { max-width: 860px; }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0 18px; }
.form-grid .full { grid-column: 1 / -1; }
.form-actions { display: flex; gap: 10px; margin-top: 8px; flex-wrap: wrap; }
.field .hint { display: block; color: var(--muted); font-size: 12px; margin-top: 4px; }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; padding: 6px 0; }
.check input { width: 18px; height: 18px; accent-color: var(--primary); }
.perm-groups { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.perm-group { border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; background: #fbfcfe; }
.perm-group h3 { font-size: 15px; color: var(--primary-dark); margin-bottom: 6px; display: flex; justify-content: space-between; align-items: center; }
.perm-group h3 button { background: none; border: 0; color: var(--primary-light); font: inherit; font-size: 12px; cursor: pointer; }
.logo-preview { max-height: 70px; background: #f4f7fd; border-radius: 10px; padding: 6px 10px; margin-top: 8px; }
code.json { direction: ltr; display: inline-block; font-size: 12px; color: var(--muted); max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

@media (max-width: 768px) {
    .form-grid { grid-template-columns: 1fr; }
    .toolbar .field { max-width: none; min-width: 100%; }
    /* الجداول تتحول إلى بطاقات على الهاتف */
    .table-wrap.stack { background: none; border: 0; box-shadow: none; overflow: visible; }
    .stack table.table, .stack .table tbody, .stack .table tr, .stack .table td { display: block; width: 100%; }
    .stack .table thead { display: none; }
    .stack .table tr { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 12px; padding: 6px 4px; }
    .stack .table td { border: 0; padding: 7px 12px; display: flex; justify-content: space-between; gap: 12px; text-align: left; }
    .stack .table td::before { content: attr(data-label); font-weight: 700; color: var(--muted); font-size: 13px; text-align: right; flex-shrink: 0; }
    .stack .table td.table-empty { justify-content: center; }
    .stack .table td.table-empty::before { content: none; }
    .stack .table td.actions-cell { justify-content: flex-end; }
    .stack .table td.actions-cell::before { content: none; }
}

/* ── المرحلة 2: الحسابات والقيود ─────────── */
.split { display: grid; grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); gap: 18px; align-items: start; }
.card-title { font-size: 17px; color: var(--primary-dark); margin-bottom: 14px; }
.alert.info { background: #eef3ff; color: var(--primary-dark); border: 1px solid #c9d6fb; }
.nowrap { flex-wrap: nowrap; }
.neg { color: var(--danger); }
.stat-value.sm { font-size: 18px; }
.danger-zone { margin-top: 16px; max-width: 860px; display: flex; justify-content: flex-end; }
.meta-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; }
.meta-grid div { display: flex; flex-direction: column; gap: 2px; }
.meta-grid span { color: var(--muted); font-size: 13px; }

.tree-cell { display: inline-flex; align-items: center; gap: 8px; padding-inline-start: calc(var(--depth, 0) * 22px); }
.tree-toggle { width: 24px; height: 24px; border: 0; border-radius: 6px; background: #eef2fb; color: var(--primary); cursor: pointer; transition: transform .15s; }
tr.collapsed .tree-toggle { transform: rotate(90deg); }
.tree-leaf { width: 24px; text-align: center; color: var(--border); }
.acc-code { font-weight: 800; color: var(--primary); direction: ltr; min-width: 38px; }
.tree-root td { background: #f6f9ff; font-weight: 700; }
tr.is-inactive { opacity: .55; }
.tb-table th, .tb-table td { white-space: nowrap; }
/* ميزان المراجعة: التمرير داخل الجدول، والعناوين (صفّان) والمجاميع ثابتة */
.tb-scroll { max-height: calc(100vh - var(--topbar-h) - 190px); min-height: 320px; overflow: auto; }
.tb-scroll thead th { position: sticky; top: 0; z-index: 2; }
.tb-scroll thead tr:first-child th { height: 44px; box-sizing: border-box; }
.tb-scroll thead tr:nth-child(2) th { top: 44px; }
.tb-scroll thead th[rowspan] { z-index: 3; }
.tb-scroll tfoot td { position: sticky; bottom: 0; z-index: 2; }
/* خطوط الشبكة: separate (لا collapse) حتى تبقى حدود العناوين الثابتة ظاهرة أثناء التمرير */
.tb-table { border-collapse: separate; border-spacing: 0; }
.tb-table th, .tb-table td { border-bottom: 1px solid #d5dde9; border-inline-start: 1px solid #d5dde9; }
.tb-table tbody td:first-child, .tb-table tfoot td:first-child, .tb-table thead th[rowspan] { border-inline-start: 0; }
.tb-table thead th { border-bottom-color: #c3cede; }
@media print { .tb-scroll { max-height: none; overflow: visible; } .tb-scroll thead th, .tb-scroll tfoot td { position: static; } }
.table tfoot .totals td { background: #f4f7fd; border-top: 2px solid var(--primary); }
.opening-row td { background: var(--accent-light); }

.lines-wrap { overflow-x: auto; margin: 6px -4px 8px; }
.lines-table td { padding: 6px 4px; }
.lines-table input, .lines-table select {
    width: 100%; padding: 8px 10px; min-height: 40px; border: 1px solid var(--border); border-radius: 8px; font: inherit; background: #fbfcfe;
}
.lines-table input:focus, .lines-table select:focus { outline: 2px solid var(--primary-light); background: #fff; }
.lines-table [data-lyd] { font-weight: 700; color: var(--primary-dark); white-space: nowrap; }
.lines-table input[readonly] { background: #eef2f7; color: var(--muted); }

@media (max-width: 992px) {
    .split { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
    .hide-sm { display: none; }
    .tree-cell { padding-inline-start: calc(var(--depth, 0) * 12px); gap: 5px; }
    .tree-table td, .tree-table th { padding: 10px 8px; font-size: 13px; }
    /* أسطر القيد كبطاقات على الهاتف */
    .lines-wrap { overflow: visible; margin: 0; }
    .lines-table, .lines-table tbody, .lines-table tfoot, .lines-table tr, .lines-table td { display: block; width: 100%; }
    .lines-table thead { display: none; }
    .lines-table tr[data-line] { border: 1px solid var(--border); border-radius: 12px; padding: 8px; margin-bottom: 10px; background: #fbfcfe;
        display: grid; grid-template-columns: 1fr 1fr; gap: 4px 8px; }
    .lines-table tr[data-line] td:first-child, .lines-table tr[data-line] td:nth-child(2) { grid-column: 1 / -1; }
    .lines-table td[data-label]::before { content: attr(data-label); display: block; font-size: 12px; color: var(--muted); font-weight: 700; margin-bottom: 2px; }
    .lines-table tfoot .totals { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
    .lines-table tfoot .totals td:first-child { grid-column: 1 / -1; }
}
@media print {
    .no-print, .toolbar, .pager, .actions-cell { display: none !important; }
    .table-wrap { box-shadow: none; border: 0; }
    .stack table.table { display: table !important; }
    .stack .table tbody { display: table-row-group !important; }
    .stack .table tr { display: table-row !important; }
    .stack .table td { display: table-cell !important; }
    .stack .table thead { display: table-header-group !important; }
    .stack .table td::before { content: none !important; }
}

@media print {
    .topbar, .sidebar, .backdrop { display: none !important; }
    .content { padding: 0; }
    body { background: #fff; }
}

/* ── المرحلة 3 ───────────────────────────── */
.swatch { display: inline-block; width: 22px; height: 22px; border-radius: 6px; border: 1px solid var(--border); vertical-align: middle; }
.status-pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 12px; border-radius: 999px; font-weight: 700; font-size: 13px;
    color: var(--c); background: color-mix(in srgb, var(--c) 12%, white); border: 1px solid color-mix(in srgb, var(--c) 35%, white); }
.status-pill::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--c); }
.field input[type=color] { padding: 4px; height: 44px; }

/* ── المرحلة 4: السيارات والمشتريات ─────────── */
.form-grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.vin { font-family: Consolas, 'Courier New', monospace; letter-spacing: .5px; font-size: 13px; }
.vin-input { font-family: Consolas, 'Courier New', monospace; text-transform: uppercase; letter-spacing: .5px; }
.pos { color: var(--success); }
.row-error td { background: #fff5f5; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: #fff; }
.seg a { padding: 9px 14px; font-weight: 700; color: var(--muted); font-size: 14px; }
.seg a.active { background: var(--primary); color: #fff; }

.car-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.car-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
    overflow: hidden; display: flex; flex-direction: column; color: var(--text); transition: transform .15s, box-shadow .15s; }
.car-card:hover { transform: translateY(-3px); box-shadow: 0 10px 26px rgba(35, 63, 147, .16); }
.car-img { position: relative; aspect-ratio: 16 / 10; background: #f1f5fd; display: grid; place-items: center; overflow: hidden; }
.car-img img { width: 100%; height: 100%; object-fit: cover; }
.car-img img.ph { width: 45%; height: auto; object-fit: contain; opacity: .6; }
.car-img-link { position: absolute; inset: 0; z-index: 1; }
.car-gallery-btn { position: absolute; z-index: 3; top: 50%; transform: translateY(-50%); width: 30px; height: 30px; border: 1px solid rgba(255,255,255,.7); border-radius: 50%; background: rgba(23,32,51,.7); color: #fff; font-size: 24px; line-height: 22px; cursor: pointer; display: grid; place-items: center; padding: 0; }
.car-gallery-btn:hover { background: var(--primary); }
.car-gallery-btn.prev { inset-inline-start: 8px; }
.car-gallery-btn.next { inset-inline-end: 8px; }
.car-gallery-count { position: absolute; z-index: 3; bottom: 8px; inset-inline-end: 8px; padding: 1px 7px; border-radius: 999px; background: rgba(23,32,51,.72); color: #fff; font-size: 11px; direction: ltr; }
.car-status { position: absolute; top: 10px; inset-inline-start: 10px; }
.car-status .status-pill { background: #fff; }
.car-body { padding: 12px 14px; display: flex; flex-direction: column; gap: 4px; }
.car-card > .car-body { color: var(--text); }
.car-table-gallery { position: relative; width: 82px; height: 56px; border-radius: 8px; overflow: hidden; background: #f1f5fd; display: grid; place-items: center; }
.car-table-gallery img { width: 100%; height: 100%; object-fit: cover; }
.car-table-gallery img.ph { width: 55%; height: auto; object-fit: contain; opacity: .6; }
.car-table-gallery .car-gallery-btn { width: 22px; height: 22px; font-size: 18px; line-height: 16px; }
.car-table-gallery .car-gallery-btn.prev { inset-inline-start: 3px; }
.car-table-gallery .car-gallery-btn.next { inset-inline-end: 3px; }
.car-table-gallery .car-gallery-count { bottom: 2px; inset-inline-end: 3px; font-size: 9px; padding: 0 4px; }
.car-meta { display: flex; flex-wrap: wrap; gap: 4px 12px; color: var(--muted); font-size: 13px; }
.car-price { margin-top: 6px; padding-top: 8px; border-top: 1px dashed var(--border); display: flex; justify-content: space-between; align-items: center; }

.car-layout { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(300px, 1fr); gap: 18px; align-items: start; }
.car-side { display: flex; flex-direction: column; gap: 18px; }
.gallery-main { position: relative; aspect-ratio: 16 / 10; background: #f1f5fd; border-radius: 12px; overflow: hidden; display: grid; place-items: center; }
.gallery-main img { width: 100%; height: 100%; object-fit: contain; }
.detail-gallery-btn { position: absolute; z-index: 3; top: 50%; transform: translateY(-50%); width: 38px; height: 38px; border: 1px solid rgba(255,255,255,.8); border-radius: 50%; background: rgba(23,32,51,.72); color: #fff; font-size: 30px; line-height: 27px; cursor: pointer; display: grid; place-items: center; padding: 0; }
.detail-gallery-btn:hover { background: var(--primary); }
.detail-gallery-btn.prev { inset-inline-start: 12px; }
.detail-gallery-btn.next { inset-inline-end: 12px; }
.detail-gallery-count { position: absolute; z-index: 3; bottom: 12px; inset-inline-end: 12px; padding: 2px 9px; border-radius: 999px; background: rgba(23,32,51,.72); color: #fff; font-size: 12px; direction: ltr; }
.gallery-empty { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.gallery-empty img { width: 120px; opacity: .55; }
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; margin-top: 10px; }
.thumb { position: relative; aspect-ratio: 4 / 3; border-radius: 8px; overflow: hidden; border: 2px solid transparent; cursor: pointer; background: #f1f5fd; }
.thumb.is-main { border-color: var(--accent); }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb-actions { position: absolute; top: 3px; inset-inline-end: 3px; display: flex; gap: 3px; }
.thumb-actions form { margin: 0; }
.thumb-actions button { width: 24px; height: 24px; border: 0; border-radius: 6px; background: rgba(0,0,0,.55); color: #fff; cursor: pointer; font-size: 12px; }
.upload-row { display: flex; gap: 8px; align-items: center; margin-top: 12px; flex-wrap: wrap; }
.upload-row input[type=file] { flex: 1; min-width: 200px; }
.specs { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; margin: 0; }
.specs dt { color: var(--muted); font-size: 14px; }
.specs dd { margin: 0; font-weight: 600; text-align: left; }
.specs .total { font-size: 17px; font-weight: 800; color: var(--primary-dark); border-top: 2px solid var(--border); padding-top: 8px; }
.summary-box:empty { display: none; }

.print-header { display: none; }
.print-footer { color: var(--muted); text-align: center; margin-top: 18px; }

@media (max-width: 992px) {
    .form-grid.cols-3 { grid-template-columns: repeat(2, 1fr); }
    .car-layout { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
    .form-grid.cols-3 { grid-template-columns: 1fr; }
    .car-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
    .car-body { padding: 10px; }
    .car-body strong { font-size: 14px; }
    .car-lines tr[data-line] td:nth-child(3), .car-lines tr[data-line] td:nth-child(4) { grid-column: auto; }
}
@media (max-width: 420px) {
    .car-grid { grid-template-columns: 1fr; }
}
@media print {
    .page-head .muted { display: none; }
    .car-layout { grid-template-columns: 1fr 1fr; }
    .thumb-actions, .upload-row { display: none !important; }
}

/* الفلاتر على الهاتف: عمودان، والبحث بعرض كامل */
@media (max-width: 768px) {
    .toolbar { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
    .toolbar .field { min-width: 0; max-width: none; }
    .toolbar .field:first-of-type:has(input:not([type=date])) { grid-column: 1 / -1; }
    .toolbar .field > span { font-size: 12px; margin-bottom: 3px; }
    .toolbar .field input, .toolbar .field select { min-height: 40px; padding: 8px 10px; }
    .toolbar > input[type=hidden] + .field { grid-column: 1 / -1; }
}

/* ── المرحلة 5 ───────────────────────────── */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.chip { background: #fff; border: 1px solid var(--border); border-radius: 999px; padding: 6px 14px; font-size: 13px; box-shadow: var(--shadow); }
.chip strong { color: var(--primary-dark); margin-inline-start: 6px; }
.lines-table input[list] { font-family: Consolas, 'Courier New', monospace; font-size: 13px; }

/* ── المرحلة 6: الشحن والمخازن ───────────── */
.picker { border: 1px solid var(--border); border-radius: 12px; background: #fbfcfe; padding: 12px; }
.picker-head { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.picker-head input[type=search] { flex: 1; min-width: 200px; padding: 9px 12px; border: 1px solid var(--border); border-radius: 10px; font: inherit; }
.picker-group + .picker-group { margin-top: 12px; }
.picker-group-title { font-weight: 700; color: var(--primary-dark); margin-bottom: 6px; }
.picker-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 8px; }
.pick { display: flex; gap: 10px; align-items: flex-start; padding: 10px; border: 1px solid var(--border); border-radius: 10px; background: #fff; cursor: pointer; transition: border-color .15s, background .15s; }
.pick.on { border-color: var(--primary-light); background: #eef3ff; }
.pick input { width: 18px; height: 18px; margin-top: 2px; accent-color: var(--primary); flex-shrink: 0; }
.pick > span { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.pick .vin { font-size: 12px; }
.pick .share { color: var(--success); font-weight: 700; }
.ship-summary { background: var(--accent-light); border-radius: 10px; padding: 10px 14px; margin: 4px 0 8px; }
.ship-summary:empty { display: none; }

.timeline { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; position: relative; }
.tl { display: flex; flex-direction: column; align-items: center; gap: 2px; text-align: center; opacity: .45; position: relative; }
.tl span { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; background: #eef2fb; font-size: 20px; }
.tl.done, .tl.current { opacity: 1; }
.tl.done span { background: #e6f7ee; }
.tl.current span { background: var(--accent-light); box-shadow: 0 0 0 4px rgba(244, 194, 28, .25); }
.tl small { color: var(--muted); }

.wh-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; margin-bottom: 16px; }
.wh-card { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; gap: 3px;
    color: var(--text); box-shadow: var(--shadow); border-inline-start: 5px solid #7c5cd6; }
.wh-card.active { border-color: var(--primary-light); background: #eef3ff; }
.wh-card .num { font-weight: 800; color: var(--primary-dark); }

.bulk-bar { position: sticky; top: calc(var(--topbar-h) + 8px); z-index: 20; display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
    background: var(--primary); color: #fff; padding: 10px 14px; border-radius: 12px; margin-bottom: 10px; box-shadow: var(--shadow); }
.bulk-bar .btn.ghost { background: #fff; }
.bulk-bar .btn.primary { background: var(--accent); color: var(--primary-dark); }

@media (max-width: 768px) {
    .picker-grid { grid-template-columns: 1fr; }
    .timeline { gap: 4px; }
    .tl span { width: 36px; height: 36px; font-size: 16px; }
}

/* ── المرحلة 7: المبيعات والعملاء ─────────── */
button.link { background: none; border: 0; padding: 0; color: var(--primary-light); font: inherit; font-size: 12px; cursor: pointer; text-decoration: underline; }
.sale-summary { background: var(--accent-light); border-radius: 10px; padding: 10px 14px; margin: 6px 0 10px; font-weight: 600; }
.sale-summary:empty { display: none; }
.sale-summary.warn { background: #fdecec; color: #9b2c2c; }
.balance-box { background: #f4f7fd; border-radius: 10px; padding: 10px 14px; }
.balance-box strong { font-size: 20px; color: var(--primary-dark); display: block; }
.return-box { margin-top: 12px; }
.return-box summary { cursor: pointer; font-weight: 700; color: var(--danger); }
.return-box form { margin-top: 12px; }

.aging-bars { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; margin-bottom: 16px; }
.aging-bar { position: relative; overflow: hidden; background: #fff; border: 1px solid var(--border); border-radius: 12px; padding: 12px; display: flex; flex-direction: column; gap: 2px; box-shadow: var(--shadow); }
.aging-bar span { color: var(--muted); font-size: 13px; }
.aging-bar strong { font-size: 18px; color: var(--primary-dark); position: relative; z-index: 1; }
.aging-bar i { position: absolute; bottom: 0; inset-inline-start: 0; height: 5px; background: var(--success); }
.aging-bar.a-d30 i { background: var(--accent); } .aging-bar.a-d60 i { background: #f08c2a; }
.aging-bar.a-d90 i, .aging-bar.a-over i { background: var(--danger); }

/* الفاتورة */
.invoice { padding: 28px; }
.inv-head { display: grid; grid-template-columns: auto 1fr auto; gap: 18px; align-items: center; border-bottom: 3px solid var(--primary); padding-bottom: 14px; }
.inv-head img { height: 64px; }
.inv-logos { display: flex; align-items: center; gap: 10px; }
/* شعار المعرض في منتصف أعلى المطبوعات وفاتورة البيع (2026-12-01) */
.inv-center-logo { display: flex; justify-content: center; margin-bottom: 10px; }
.inv-center-logo img { max-height: 90px; max-width: 240px; width: auto; }
.ph-center-logo { grid-column: 1 / -1; display: flex; justify-content: center; padding-bottom: 6px; }
.ph-center-logo img { max-height: 64px; max-width: 220px; width: auto; }
.inv-company { display: flex; flex-direction: column; font-size: 13px; color: var(--muted); }
.inv-company strong { font-size: 18px; color: var(--primary-dark); }
.inv-title { text-align: left; display: flex; flex-direction: column; }
.inv-title h2 { color: var(--primary); font-size: 24px; }
.inv-parties { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin: 18px 0; }
.inv-parties > div { display: flex; flex-direction: column; gap: 2px; background: #f6f9ff; border-radius: 10px; padding: 12px 14px; }
.inv-table th { background: var(--primary); color: #fff; }
.inv-totals { margin: 16px 0 0 auto; max-width: 380px; display: flex; flex-direction: column; gap: 6px; }
.inv-totals > div { display: flex; justify-content: space-between; gap: 16px; padding: 4px 0; border-bottom: 1px dashed var(--border); }
.inv-totals .grand { font-size: 18px; color: var(--primary-dark); border-bottom: 2px solid var(--primary); }
.inv-sign { display: grid; grid-template-columns: 1fr 1fr; gap: 40px; margin-top: 40px; text-align: center; color: var(--muted); }
.inv-sign span { display: block; border-top: 1px solid var(--text); margin-top: 46px; }

@media (max-width: 768px) {
    .aging-bars { grid-template-columns: repeat(2, 1fr); }
    .invoice { padding: 16px; }
    .inv-head { grid-template-columns: 1fr; text-align: center; }
    .inv-head img { margin: 0 auto; }
    .inv-title { text-align: center; }
    .inv-parties { grid-template-columns: 1fr; }
    .inv-table { font-size: 12px; }
    .inv-table th, .inv-table td { padding: 6px; }
    .inv-totals { max-width: none; }
}
@media print {
    .invoice { box-shadow: none; border: 0; padding: 0; }
    .inv-table th { background: #233f93 !important; color: #fff !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    .aging-bars { grid-template-columns: repeat(5, 1fr); }
}

.inv-table-wrap { overflow-x: auto; margin: 0 -4px; }
.invoice { min-width: 0; overflow: hidden; }
@media print { .inv-table .hide-sm { display: table-cell !important; } }

/* ── المرحلة 8: الخزائن والبنوك ─────────── */
.cash-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 14px; }
.cash-card { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 6px;
    border-inline-start: 5px solid var(--accent); }
.cash-card.bank { border-inline-start-color: var(--primary-light); }
.cash-top { display: flex; justify-content: space-between; gap: 8px; font-weight: 700; }
.cash-amount { font-size: 26px; color: var(--primary-dark); }
.cash-amount small { font-size: 14px; color: var(--muted); }
.stat form { margin-top: 6px; }

/* ── المرحلة 9: التقارير والمخططات ─────────── */
.chart-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin: 16px 0; }
.chart-grid .wide { grid-column: 1 / -1; }
.chart-card { margin: 0; padding: 16px; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.chart-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; color: var(--primary-dark); }
.chart-box { position: relative; width: 100%; }
.chart-table { max-height: 320px; overflow: auto; }
.chart-table .table th, .chart-table .table td { padding: 8px 10px; }
.chart-empty { padding: 40px 0; }
.report-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.report-card { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); color: var(--text);
    display: flex; gap: 14px; align-items: flex-start; transition: transform .15s, border-color .15s; }
.report-card:hover { transform: translateY(-2px); border-color: var(--primary-light); }
.report-card .ico { width: 46px; height: 46px; border-radius: 12px; background: #eef3ff; display: grid; place-items: center; font-size: 22px; flex-shrink: 0; }
.report-card strong { color: var(--primary-dark); display: block; margin-bottom: 2px; }
.report-card small { color: var(--muted); }
.fin { width: 100%; border-collapse: collapse; }
.fin td { padding: 9px 12px; border-bottom: 1px solid var(--border); }
.fin td:last-child { text-align: left; font-variant-numeric: tabular-nums; white-space: nowrap; }
.fin .sub td { padding-inline-start: 28px; color: var(--muted); }
.fin .tot td { font-weight: 800; background: #f4f7fd; }
.fin .grand td { font-weight: 800; font-size: 17px; background: var(--primary); color: #fff; }
.fin-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.kpi-row { display: grid; grid-template-columns: repeat(6, 1fr); gap: 12px; }
.kpi { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.kpi span { color: var(--muted); font-size: 13px; }
.kpi strong { font-size: 22px; color: var(--primary-dark); font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi small { color: var(--muted); font-size: 12px; }
@media (max-width: 1200px) { .kpi-row { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 992px) { .chart-grid, .fin-grid { grid-template-columns: 1fr; } }
@media (max-width: 576px) { .kpi-row { grid-template-columns: repeat(2, 1fr); gap: 8px; } .kpi strong { font-size: 18px; } }
@media print { .chart-grid { grid-template-columns: 1fr 1fr; } .chart-head .link { display: none; } }

.alerts-row { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.alerts-row .alert { margin: 0; display: block; }
a.kpi { color: inherit; transition: border-color .15s; }
a.kpi:hover { border-color: var(--primary-light); }

/* ── المرحلة 10: الطباعة الموحّدة (A4) وقائمة التصدير ───────── */
.export-menu { position: relative; }
.export-menu > summary { list-style: none; cursor: pointer; }
.export-menu > summary::-webkit-details-marker { display: none; }
.export-menu[open] > summary { background: var(--accent-light); }
.export-list { position: absolute; inset-inline-end: 0; top: calc(100% + 6px); z-index: 40; min-width: 210px; display: flex; flex-direction: column;
    background: var(--card); border: 1px solid var(--border); border-radius: 12px; box-shadow: 0 12px 30px rgba(23, 32, 51, .16); padding: 6px; }
.export-list a, .export-list button { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 8px; font: inherit; font-weight: 600;
    color: var(--text); background: none; border: 0; cursor: pointer; text-align: start; width: 100%; }
.export-list a:hover, .export-list button:hover, .export-list a:focus-visible, .export-list button:focus-visible { background: #f1f5fd; color: var(--primary-dark); }
.export-list small { color: var(--muted); font-weight: 400; margin-inline-start: auto; white-space: nowrap; font-size: 12px; }
.export-list { min-width: 250px; }
@media (max-width: 768px) { .export-list { inset-inline-end: auto; inset-inline-start: 0; } }

/* تذييل كل صفحة مطبوعة: اسم النظام والمصمم يميناً، ورقم الصفحة يساراً (طلب المستخدم 2026-11-29) */
@page { size: A4; margin: 12mm 10mm 16mm;
    @bottom-right { content: "DriveX ERP · تم التصميم بواسطة م. سلامة الزياني"; direction: rtl; text-align: right;
                    font-family: Cairo, Arial, sans-serif; font-size: 8.5pt; color: #233f93; }
    @bottom-left { content: "صفحة " counter(page) " من " counter(pages); direction: rtl; text-align: left;
                   font-family: Cairo, Arial, sans-serif; font-size: 8.5pt; color: #6b7280; } }
@media print {
    html, body { background: #fff !important; }
    body { font-size: 11pt; color: #000; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    .shell, .content { display: block !important; padding: 0 !important; margin: 0 !important; max-width: none !important; }
    .page-head, .export-menu, .alert, .btn, button, form.toolbar, details:not([open]) { display: none !important; }
    .print-header { display: grid !important; grid-template-columns: 1.3fr 1fr auto; gap: 14px; align-items: center;
        border-bottom: 2px solid var(--primary); padding-bottom: 8px; margin-bottom: 12px; }
    .ph-company { display: flex; align-items: center; gap: 10px; }
    .ph-company img { height: 48px; width: auto; }
    .ph-company div, .ph-doc, .ph-meta { display: flex; flex-direction: column; gap: 1px; font-size: 9pt; color: #374151; }
    .ph-company strong { font-size: 13pt; color: var(--primary-dark); }
    .ph-doc { text-align: center; }
    .ph-doc strong { font-size: 13pt; color: #000; }
    .ph-meta { text-align: left; }
    .card, .table-wrap, .stat, .chart-card { box-shadow: none !important; border: 1px solid #cfd8e6 !important; break-inside: avoid; }
    .stats { grid-template-columns: repeat(4, 1fr) !important; gap: 8px !important; margin-bottom: 10px; }
    .stat { padding: 8px 10px !important; }
    .table { font-size: 9.5pt; width: 100%; border-collapse: collapse; }
    .table th, .table td { padding: 5px 7px !important; border-bottom: 1px solid #dbe2ec; }
    .table thead { display: table-header-group; }
    .table tfoot { display: table-footer-group; }
    .table tr { break-inside: avoid; }
    .table td.num, .table td .num, .table th.num, .table td > [dir=ltr], .table td:first-child { white-space: nowrap; }
    .table-wrap { overflow: visible !important; }
    /* الطباعة تعتمد على جدول البيانات الفعلي، وليس لقطة canvas للمخطط. */
    .chart-box { display: none !important; }
    .chart-table, .chart-table[hidden] { display: block !important; max-height: none !important; overflow: visible !important; }
    .chart-table table { display: table !important; }
    a { color: inherit !important; text-decoration: none !important; }
    h2, .section-title { break-after: avoid; }
}

/* نافذة الإنشاء السريع (مخزن خارجي من فاتورة الشراء) */
.quick-dialog { border: 0; border-radius: var(--radius); padding: 0; width: min(440px, calc(100vw - 32px)); box-shadow: 0 24px 60px rgba(23, 32, 51, .3); }
.quick-dialog::backdrop { background: rgba(23, 32, 51, .45); }
.quick-form { padding: 22px; display: flex; flex-direction: column; gap: 12px; }
.quick-form h2 { color: var(--primary-dark); font-size: 20px; }
.quick-form .form-actions { margin-top: 4px; }
.field > span .link { margin-inline-start: 8px; font-size: 13px; }

/* هوية النظام الثابتة في الإعدادات */
.brand-fixed { display: flex; align-items: center; gap: 12px; padding: 10px 12px; background: #f6f9ff; border: 1px solid var(--border); border-radius: 10px; }
.brand-fixed img { height: 40px; width: auto; }
.brand-fixed strong { color: var(--primary-dark); }


/* ── تحليل المبيعات (2026-11-29) ───────────────────────── */
.badge.primary { background: #e8eefc; color: var(--primary-dark); }
.hl-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-bottom: 18px; }
@media (max-width: 992px) { .hl-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 576px) { .hl-grid { grid-template-columns: 1fr; } }
.hl-card { display: flex; gap: 12px; align-items: flex-start; background: var(--card); border: 1px solid var(--border); border-inline-start: 4px solid #9fb2dd;
    border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); min-width: 0; }
.hl-card > div { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.hl-card small { color: var(--muted); font-size: 12px; }
.hl-card strong { font-size: 17px; color: var(--primary-dark); line-height: 1.35; overflow-wrap: anywhere; }
.hl-card span { font-size: 12.5px; color: var(--text); }
.hl-ico { font-size: 22px; line-height: 1; flex: none; width: 38px; height: 38px; display: grid; place-items: center; background: #f1f5fd; border-radius: 10px; }
.hl-primary { border-inline-start-color: var(--primary); }
.hl-success { border-inline-start-color: var(--success); }
.hl-accent { border-inline-start-color: var(--accent); }
.hl-danger { border-inline-start-color: var(--danger); }
.table .bar { height: 5px; margin-top: 5px; border-radius: 999px; background: linear-gradient(90deg, var(--primary), #6f8fe0); width: var(--w, 0%); min-width: 4px; }
.table tr.row-best > td { background: #f3fbf6; }
.split-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; margin-bottom: 16px; align-items: start; }
/* الأرقام والتواريخ لا تنكسر في الجداول؛ عمود السيارة في جدولي الأسعار يأخذ المساحة */
.table td.num { white-space: nowrap; }
.split-2 .table td:nth-child(2) { min-width: 150px; }
.table-caption { caption-side: top; text-align: start; font-weight: 800; color: var(--primary-dark); padding: 10px 12px 6px; }
.class-row { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-bottom: 12px; }
.class-card { display: flex; flex-direction: column; gap: 3px; background: var(--card); border: 1px solid var(--border); border-top: 4px solid var(--border);
    border-radius: var(--radius); padding: 10px 12px; box-shadow: var(--shadow); }
.class-card strong { font-size: 22px; color: var(--primary-dark); } .class-card strong small { font-size: 12px; color: var(--muted); }
.class-card .muted { font-size: 12px; }
.class-card.tone-success { border-top-color: var(--success); } .class-card.tone-primary { border-top-color: var(--primary); }
.class-card.tone-accent { border-top-color: var(--accent); } .class-card.tone-danger { border-top-color: var(--danger); }
@media (max-width: 992px) { .split-2 { grid-template-columns: 1fr; } .class-row { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media print {
    .hl-grid { grid-template-columns: repeat(3, minmax(0, 1fr)) !important; gap: 6px !important; }
    .hl-card { box-shadow: none !important; padding: 6px 8px !important; border-radius: 6px !important; break-inside: avoid; }
    .hl-card strong { font-size: 11pt !important; } .hl-card span, .hl-card small { font-size: 8pt !important; }
    .hl-ico { width: 26px; height: 26px; font-size: 15px; }
    .split-2 { grid-template-columns: 1fr !important; gap: 8px !important; } /* جدولا الأسعار تحت بعضهما في A4 */
    .class-row { grid-template-columns: repeat(4, minmax(0, 1fr)) !important; gap: 6px !important; }
    .class-card { box-shadow: none !important; padding: 6px 8px !important; border-radius: 6px !important; }
    .class-card strong { font-size: 13pt !important; }
    .table .bar { print-color-adjust: exact; -webkit-print-color-adjust: exact; }
    /* الجداول العريضة (12+ عموداً) تتسع لعرض A4: خط أصغر وعناوين تلتف وإخفاء الأعمدة الثانوية */
    .table-wide { font-size: 7.5pt !important; }
    .table-wide th, .table-wide td { padding: 3px 4px !important; }
    .table-wide thead th { white-space: normal !important; line-height: 1.2; }
    .table-wide .vin, .table-wide br, .stack .table.table-wide th.no-print-col, .stack .table.table-wide td.no-print-col, .table.table-wide .no-print-col { display: none !important; }
    .table-wide .bar { display: none; }
    .section-title { break-after: avoid; }
}

/* ── القوائم المالية: الميزانية العمومية وقائمة الدخل (2026-12-01) ── */
.fs-checks { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 12px; }
.fs-table { max-width: 860px; }
.fs-table td:first-child { white-space: normal; }
.fs-table td.num, .fs-table th.num { width: 170px; }
.fs-table tr.fs-head td { background: var(--primary); color: #fff; font-weight: 800; font-size: 1.02rem; }
.fs-table tr.fs-sec td { font-weight: 700; color: var(--primary-dark); background: #f3f6fc; }
.fs-table tr.fs-line td:first-child { padding-inline-start: 26px; }
.fs-table tr.fs-acc td { font-size: .84rem; color: var(--muted); }
.fs-table tr.fs-acc td:first-child { padding-inline-start: 46px; }
.fs-table tr.fs-sub td { font-weight: 700; border-top: 1px solid var(--text); }
.fs-table tr.fs-sub2 td { font-weight: 700; border-top: 1px solid var(--text); background: #f8fafd; }
.fs-table tr.fs-total td { font-weight: 800; border-top: 1px solid var(--text); border-bottom: 3px double var(--text); background: #fffbea; }
.fs-table tr.fs-net td { font-size: 1.05rem; }
@media print {
    .fs-table { max-width: none; }
    .fs-table tr.fs-head td { background: #e9eef8 !important; color: #000 !important; print-color-adjust: exact; -webkit-print-color-adjust: exact; }
    .fs-table tr.fs-total td, .fs-table tr.fs-sec td { print-color-adjust: exact; -webkit-print-color-adjust: exact; }
}

/* ── تقرير الميزانية (2026-12-01) ── */
.rpt { display: flex; flex-direction: column; gap: 18px; }
.rpt-cover { text-align: center; padding: 18px 24px 24px; display: flex; flex-direction: column; min-height: 620px; }
/* شعار النظام واسمه ثابتان أعلى الصفحة */
.rpt-system { display: flex; align-items: center; justify-content: center; gap: 12px; padding-bottom: 10px; border-bottom: 1px solid var(--border); }
.rpt-system img { height: 34px; width: auto; }
.rpt-system span { font-weight: 800; color: var(--primary-dark); letter-spacing: .3px; }
/* شعار المعرض واسمه في منتصف الصفحة فوق العنوان */
.rpt-cover-main { flex: 1; display: flex; flex-direction: column; justify-content: center; align-items: center; padding: 24px 0 8px; }
.rpt-company-block { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.rpt-co-logo { max-height: 150px; max-width: 280px; width: auto; }
.rpt-company { margin: 4px 0 0; font-size: 1.7rem; color: var(--primary-dark); }
.rpt-cover-meta { width: 100%; }
.rpt-title { margin: 26px auto; padding: 18px; border-top: 3px solid var(--primary); border-bottom: 3px solid var(--primary); max-width: 560px; }
.rpt-title h1 { margin: 0 0 6px; font-size: 2rem; }
.rpt-cover-meta { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; max-width: 760px; margin: 0 auto; text-align: start; }
.rpt-cover-meta div { border: 1px solid var(--border); border-radius: 10px; padding: 8px 12px; display: flex; flex-direction: column; gap: 2px; }
.rpt-cover-meta span { color: var(--muted); font-size: .8rem; }
.rpt-cover-foot { margin-top: 18px; font-size: .85rem; }
.rpt-page { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.rpt-h { margin: 0 0 14px; padding-bottom: 8px; border-bottom: 2px solid var(--primary); color: var(--primary-dark); font-size: 1.25rem; }
.rpt-h3 { margin: 16px 0 8px; font-size: 1.05rem; color: var(--primary-dark); }
.rpt-kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-bottom: 14px; }
.rpt-kpi { border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; display: flex; flex-direction: column; gap: 2px; }
.rpt-kpi span { color: var(--muted); font-size: .82rem; }
.rpt-kpi strong { font-size: 1.15rem; direction: ltr; text-align: end; }
.rpt-delta { font-weight: 700; } .rpt-delta.up { color: var(--success); } .rpt-delta.down { color: var(--danger); }
.rpt .neg { color: var(--danger); }
.rpt-text { line-height: 1.9; margin-top: 12px; padding: 12px 16px; background: #f6f8fd; border-inline-start: 4px solid var(--primary-light); border-radius: 8px; }
.rpt-text p { margin: 0 0 6px; } .rpt-text p:last-child { margin: 0; }
.rpt-charts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin: 14px 0; }
.rpt-charts.one { grid-template-columns: 1fr; }
.rpt-note { margin-top: 10px; padding: 10px 14px; border: 1px dashed var(--accent); background: var(--accent-light); border-radius: 8px; line-height: 1.8; }
.rpt-note-edit { margin-top: 10px; } .rpt-note-edit textarea { width: 100%; }
.rpt-print-only { display: none; }
.rpt-signs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 24px; margin-top: 40px; }
.rpt-signs div { display: flex; flex-direction: column; gap: 34px; text-align: center; }
.rpt-signs i { border-bottom: 1px solid var(--text); }
.rpt-save { position: sticky; bottom: 10px; display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 14px;
            padding: 10px 14px; background: var(--card); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); }
.rpt-watermark { position: fixed; inset: 40% 0 auto 0; text-align: center; font-size: 64px; font-weight: 800; color: rgba(217, 76, 76, .10);
                 transform: rotate(-18deg); pointer-events: none; z-index: 5; }
@media (max-width: 768px) { .rpt-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } .rpt-charts { grid-template-columns: 1fr; } .rpt-signs { grid-template-columns: 1fr; } }
@media print {
    .rpt { gap: 0; }
    .rpt-cover { min-height: 255mm; border: none !important; box-shadow: none !important; padding: 0 !important; }
    .rpt-page { break-before: page; border: none !important; box-shadow: none !important; padding: 0 !important; }
    .rpt-kpis { grid-template-columns: repeat(4, minmax(0, 1fr)) !important; }
    .rpt-charts { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; break-inside: avoid; }
    .rpt-charts.one { grid-template-columns: 1fr !important; }
    .rpt-text, .rpt-note, .rpt-kpi, .rpt-signs { break-inside: avoid; print-color-adjust: exact; -webkit-print-color-adjust: exact; }
    .rpt-print-only { display: block !important; }
    .rpt-signs { grid-template-columns: repeat(3, 1fr) !important; }
    .rpt-watermark { position: fixed; color: rgba(217, 76, 76, .14) !important; print-color-adjust: exact; -webkit-print-color-adjust: exact; }
    .rpt .chart-head button { display: none; }
}

/* ════════════════════════════════════════════════════════════════
   طباعة موحّدة ومتناسقة (2026-11-29، طلب المستخدم): نفس الخط والمقاسات والحدود
   للفواتير والتقارير والجداول. تأتي آخر الملف لتتقدم على قواعد الشاشات الضيقة
   (عرض A4 المطبوع ≈ 720px فتنطبق عليه قواعد max-width: 768/992).
   ════════════════════════════════════════════════════════════════ */
@media print {
    body { font-size: 10pt !important; line-height: 1.45; }
    h1 { font-size: 15pt !important; }
    h2, h3, .card-title, .section-title { font-size: 11.5pt !important; margin: 8px 0 6px !important; color: #1b2f6b !important; }
    .muted, small, .hint { font-size: 8.5pt !important; }

    /* الترويسة: ثلاثة أعمدة ثابتة؛ اسم المعرض في سطر واحد، وعنوان المستند في الوسط */
    .print-header { grid-template-columns: minmax(0, 1.25fr) minmax(0, 1.5fr) minmax(0, 1fr) !important; gap: 10px !important; }
    /* الشعار عريض: اسم المعرض تحته في نفس العمود حتى لا يتداخل مع عنوان المستند */
    .ph-company { min-width: 0; flex-direction: column !important; align-items: flex-start !important; gap: 3px !important; }
    .ph-company img { height: 34px !important; max-width: 100%; flex: none; }
    .ph-center-logo { grid-column: 1 / -1 !important; }
    .ph-center-logo img { height: auto !important; max-height: 62px !important; max-width: 220px !important; }
    .inv-center-logo img { max-height: 80px !important; }
    .ph-company div { min-width: 0; max-width: 100%; }
    .ph-company strong { font-size: 10.5pt !important; line-height: 1.3; overflow-wrap: anywhere; }
    .ph-doc strong { font-size: 12.5pt !important; line-height: 1.3; }
    .ph-company div, .ph-doc, .ph-meta { font-size: 8.5pt !important; }

    /* البطاقات والمؤشرات: أعمدة ثابتة وارتفاعات متساوية وحواف موحّدة */
    .card, .table-wrap, .stat, .kpi, .chart-card { border-radius: 6px !important; box-shadow: none !important; }
    .card { padding: 10px 12px !important; margin-bottom: 8px !important; }
    .stats { grid-template-columns: repeat(4, minmax(0, 1fr)) !important; gap: 8px !important; align-items: stretch; }
    .kpi-row { grid-template-columns: repeat(3, minmax(0, 1fr)) !important; gap: 8px !important; align-items: stretch; margin-bottom: 10px !important; }
    .stat, .kpi { padding: 7px 10px !important; height: 100%; border: 1px solid #cfd8e6 !important; background: #fff !important; }
    .stat-label, .kpi span { font-size: 8.5pt !important; }
    .stat-value, .stat-value.sm, .kpi strong { font-size: 13pt !important; line-height: 1.3; }
    .kpi small { font-size: 8pt !important; }
    .chart-grid { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; gap: 8px !important; margin: 8px 0 !important; align-items: stretch; }
    .chart-card { padding: 8px 10px !important; height: 100%; }

    /* الجداول: خط واحد، حشوة واحدة، شبكة حدود رفيعة، أعمدة الأرقام بعرض محتواها ولا تنكسر */
    .table { font-size: 9pt !important; border: 1px solid #cfd8e6 !important; }
    .table th, .table td { padding: 4px 6px !important; border: 1px solid #dbe2ec !important; vertical-align: middle !important; line-height: 1.35; }
    .table thead th { background: #eef3fb !important; color: #1b2f6b !important; font-weight: 700; white-space: nowrap; }
    .table tbody tr:nth-child(even) > td { background: #fafcff !important; }
    .table tfoot td, .table tr.totals td { background: #f2f6fc !important; font-weight: 700; border-top: 1.5px solid #233f93 !important; }
    .table th.num, .table td.num { width: 1%; white-space: nowrap; }
    .docno { white-space: nowrap; }

    /* بيانات المستند (الشراء والمصاريف والشحن): ثلاثة أعمدة متساوية */
    .meta-grid { grid-template-columns: repeat(3, minmax(0, 1fr)) !important; gap: 4px 14px !important; }
    .meta-grid > div { padding: 4px 0; border-bottom: 1px dotted #dbe2ec; min-width: 0; }
    .meta-grid span { font-size: 8.5pt !important; }

    /* فاتورة البيع: خانات الأطراف بعرض وارتفاع متساويين، والإجماليات بمقاس ثابت */
    .inv-head img { height: 52px !important; }
    .inv-parties { grid-template-columns: repeat(3, minmax(0, 1fr)) !important; gap: 8px !important; margin: 10px 0 !important; align-items: stretch; }
    .inv-parties > div { padding: 8px 10px !important; border: 1px solid #dbe2ec; background: #f8faff !important; border-radius: 6px !important; min-width: 0; }
    .inv-table { font-size: 9pt !important; }
    .inv-table th, .inv-table td { padding: 5px 6px !important; border: 1px solid #dbe2ec; }
    .inv-totals { max-width: 330px !important; gap: 2px !important; }
    .inv-totals > div { padding: 3px 0 !important; }
    .inv-totals .grand { font-size: 12pt !important; }
    .inv-sign { margin-top: 26px !important; }
    .inv-sign span { margin-top: 34px !important; }

    /* بطاقات السيارات: ثلاث في الصف وصورة بارتفاع ثابت */
    .car-grid { grid-template-columns: repeat(3, minmax(0, 1fr)) !important; gap: 8px !important; }
    .car-card { break-inside: avoid; box-shadow: none !important; border-radius: 6px !important; }
    .car-img { aspect-ratio: auto !important; height: 90px; }
    .car-gallery-btn, .car-gallery-count { display: none !important; }
    .car-body { padding: 6px 8px !important; font-size: 9pt; }
}

/* ── مرفقات المستندات ── */
.att-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.att-item { border: 1px solid var(--border, #ddd); border-radius: 10px; padding: 8px; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.att-thumb { display: flex; align-items: center; justify-content: center; height: 120px; background: rgba(127,127,127,.08); border-radius: 8px; overflow: hidden; }
.att-thumb img { max-width: 100%; max-height: 100%; object-fit: contain; }
.att-pdf { font-weight: 800; font-size: 22px; color: #c0392b; }
.att-name { font-weight: 600; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-actions { display: flex; gap: 6px; }
.att-clip { font-size: 12px; color: var(--muted); margin-inline-start: 4px; white-space: nowrap; }
.att-viewer { border: 0; border-radius: var(--radius); padding: 0; width: min(1100px, calc(100vw - 24px)); height: calc(100vh - 40px); box-shadow: 0 24px 60px rgba(23, 32, 51, .3); }
.att-viewer[open] { display: flex; flex-direction: column; }
.att-viewer::backdrop { background: rgba(23, 32, 51, .6); }
.att-viewer-head { display: flex; align-items: center; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.att-viewer-head strong { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-viewer-body { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; background: rgba(127,127,127,.08); }
.att-viewer-body img { max-width: 100%; max-height: 100%; object-fit: contain; }
.att-viewer-body iframe { width: 100%; height: 100%; border: 0; background: #fff; }

/* ── جرد المخازن ── */
.text-danger { color: var(--danger); }
.st-table .st-check { text-align: center; }
.st-table .st-check input { width: 22px; height: 22px; }
.st-table tr.st-ok td { background: rgba(46, 160, 67, .08); }
.st-table .st-note { width: 100%; min-width: 0; }
.st-box { display: inline-block; width: 20px; height: 20px; border: 1.5px solid var(--text); border-radius: 4px; line-height: 18px; text-align: center; font-weight: 700; }
.st-box.st-no { color: var(--danger); }
.print-only-block { display: none; }
@media print {
    .print-only-block { display: grid !important; }
    .st-table tr.st-ok td { background: none; }
    .st-table .st-note { border: 0 !important; padding: 0 !important; background: none !important; box-shadow: none !important; outline: 0; appearance: none; }
}
/* أعمدة ثابتة لورقة الجرد (الشاشة والطباعة): ت - السيارة - الهيكل - اللون - موجودة - غير موجودة - ملاحظات */
.st-table { table-layout: fixed; width: 100%; font-size: 14px; }
.st-table col.c-no { width: 5%; }
.st-table col.c-car { width: 27%; }
.st-table col.c-vin { width: 21%; }
.st-table col.c-color { width: 11%; }
.st-table col.c-found { width: 8%; }
.st-table col.c-note { width: 20%; }
.st-table td, .st-table th { overflow-wrap: anywhere; vertical-align: middle; padding: 9px 8px; }
.st-table th { white-space: normal !important; line-height: 1.3; font-size: 13.5px; font-weight: 700; overflow-wrap: normal; word-break: keep-all; }
.st-table th.st-check, .st-table .st-no { text-align: center; }
.st-table td.st-no { font-weight: 600; color: var(--muted, #6b7280); }
.st-table td.vin { white-space: nowrap; font-size: 14px; font-family: ui-monospace, Consolas, monospace; letter-spacing: .3px; }
@media print {
    .st-meta { display: grid !important; grid-template-columns: repeat(5, 1fr) !important; gap: 6px 14px !important; padding: 8px 12px !important; box-shadow: none !important; }
    .st-meta > div { padding: 2px 0 !important; border: 0 !important; }
    .st-table { font-size: 12px; border: 1px solid #555 !important; border-collapse: collapse !important; }
    .st-table th, .st-table td { padding: 7px 6px !important; border: 1px solid #999 !important; height: 30px; }
    .st-table th { font-size: 12px; }
    .st-table th, .st-table td, .st-table td.vin { text-align: center !important; } /* ورقة الجرد المطبوعة: العناوين والنصوص في المنتصف */
    .st-table .st-note { text-align: center; }
    .st-table thead th { background: #eef2f8 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    .st-table tbody tr { break-inside: avoid; }
    .st-table td.vin { font-size: 12px; }
    .st-table td.st-no { color: #000; }
    .st-table .st-check input { width: 16px; height: 16px; }
    .st-table .st-box { width: 16px; height: 16px; line-height: 14px; font-size: 12px; }
}
.st-table col.c-vin2 { width: 22%; }
.st-table col.c-car2 { width: 28%; }
.st-table col.c-sys { width: 20%; }
.st-table col.c-note2 { width: 26%; }
.st-table tr.st-miss td { background: rgba(217, 76, 76, .07); }
.st-extras-title { margin-top: 22px; }
.st-table tr.print-only-row { display: none; }
@media print {
    .st-table tr.print-only-row { display: table-row !important; }
    .st-table tr.st-miss td { background: none; }
    .st-extras-title { margin-top: 14px; font-size: 14px; }
}

/* ── الأستاذ الرئيسي والمساعد ── */
.ledger-sec { margin-top: 18px; break-inside: auto; }
.ledger-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 15px; margin: 0 0 8px; }
.ledger-close { margin-inline-start: auto; font-weight: 400; font-size: 13px; color: var(--muted); }
.ledger-table tr.ledger-open td { background: rgba(127,127,127,.06); font-weight: 600; }
.ledger-table td small, .table td small { color: var(--muted); }
.ledger-grand { display: flex; gap: 22px; align-items: center; flex-wrap: wrap; margin-top: 18px; }
.ledger-shortcuts { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin: -6px 0 14px; }
@media print {
    .ledger-sec { margin-top: 12px; }
    .ledger-head { break-after: avoid; font-size: 13px; }
    .ledger-table { font-size: 11px; }
    .ledger-table th, .ledger-table td { padding: 4px 6px !important; }
}

/* شريط المسودة غير المحفوظة */
.draft-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.draft-bar .draft-actions { display: flex; gap: 6px; }

/* سداد فاتورة البيع: الأجزاء والملخص */
.card-subtitle { font-size: 15px; margin: 14px 0 6px; color: var(--primary); }
.pay-summary { display: flex; flex-wrap: wrap; gap: 8px 24px; background: var(--accent-light); border-radius: 10px; padding: 10px 14px; margin: 12px 0; }
.pay-summary.warn { background: #fdecec; color: #9b2c2c; }

/* طباعة كشف حساب العميل: عرض أعمدة ثابت، عناوين واضحة، والنصوص في المنتصف */
@media print {
    .cs-table { table-layout: fixed; width: 100%; font-size: 12px; border: 1px solid #555 !important; border-collapse: collapse !important; }
    .cs-table th, .cs-table td { text-align: center !important; vertical-align: middle; padding: 6px 5px !important; border: 1px solid #999 !important; overflow-wrap: anywhere; }
    .cs-table th { font-size: 12px; font-weight: 700; white-space: normal !important; line-height: 1.3; word-break: keep-all; overflow-wrap: normal;
        background: #eef2f8 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    .cs-table td.num { white-space: nowrap; }
    .cs-table tbody tr { break-inside: avoid; }
    .cs-table .badge { background: none !important; color: #000 !important; border: 0; padding: 0; font-weight: 600; }
    .cs-table a { color: #000; text-decoration: none; }
    .cs-table .opening-row td { background: #f6f7f9 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
