/* نظام إدارة مزارع الدواجن — RTL بلا أي مكتبات خارجية */
:root {
    --bg: #f4f6f8;
    --panel: #ffffff;
    --ink: #0f172a;
    --muted: #64748b;
    --line: #e2e8f0;
    --brand: #0f766e;
    --brand-2: #115e59;
    --brand-soft: #ccfbf1;
    --warn: #b45309;
    --warn-soft: #fef3c7;
    --bad: #b91c1c;
    --bad-soft: #fee2e2;
    --good: #15803d;
    --good-soft: #dcfce7;
    --radius: 14px;
    --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 8px 24px rgba(15, 23, 42, .05);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: "Segoe UI", Tahoma, "Noto Naskh Arabic", Arial, sans-serif;
    font-size: 15px;
    line-height: 1.65;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0 0 .4rem; line-height: 1.35; font-weight: 700; }
h1 { font-size: 1.25rem; }
h3 { font-size: 1.02rem; }
p { margin: .35rem 0; }
code { background: #f1f5f9; padding: .05rem .3rem; border-radius: 6px; font-size: .85em; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.ok { color: var(--good); }
.bad { color: var(--bad); }
.inline { display: inline-flex; gap: .4rem; align-items: center; margin: 0; }
.row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.row.space { justify-content: space-between; }
.num { text-align: left; font-variant-numeric: tabular-nums; direction: ltr; }

/* ---------- الهيكل ---------- */
.app { display: flex; min-height: 100vh; }

.sidebar {
    width: 250px;
    flex: 0 0 250px;
    background: #0b3b39;
    color: #e6fffb;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}

.brand { display: flex; gap: .6rem; align-items: center; padding: 1rem .9rem; border-bottom: 1px solid rgba(255,255,255,.08); }
.brand-mark { font-size: 1.5rem; }
.brand strong { display: block; font-size: .98rem; }
.brand small { display: block; font-size: .72rem; opacity: .75; }

.nav { padding: .5rem .4rem 1rem; display: flex; flex-direction: column; gap: 1px; }
.nav-section { font-size: .7rem; letter-spacing: .03em; opacity: .55; padding: .7rem .7rem .25rem; }
.nav-link {
    display: flex; align-items: center; gap: .55rem;
    padding: .5rem .7rem; border-radius: 9px;
    color: #d7fbf6; font-size: .88rem; text-decoration: none;
}
.nav-link:hover { background: rgba(255,255,255,.08); text-decoration: none; }
.nav-link.active { background: #ffffff; color: var(--brand-2); font-weight: 700; }
.sidebar-foot { margin-top: auto; padding: .8rem; font-size: .74rem; opacity: .7; border-top: 1px solid rgba(255,255,255,.08); }
.sidebar-foot .small { font-size: .7rem; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
    display: flex; align-items: center; gap: .75rem;
    padding: .7rem 1.1rem; background: var(--panel);
    border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20;
}
.topbar-title h1 { margin: 0; font-size: 1.05rem; }
.topbar-actions { margin-inline-start: auto; display: flex; align-items: center; gap: .6rem; }
.user-chip { display: flex; flex-direction: column; font-size: .82rem; line-height: 1.2; }
.user-chip small { color: var(--muted); font-size: .7rem; }
.sync-pill { background: var(--warn-soft); color: var(--warn); border-radius: 999px; padding: .15rem .55rem; font-size: .72rem; }
.icon-btn { display: none; background: none; border: 1px solid var(--line); border-radius: 9px; padding: .25rem .5rem; font-size: 1.1rem; cursor: pointer; }

.content { padding: 1rem 1.1rem 2rem; display: flex; flex-direction: column; gap: .85rem; max-width: 1500px; width: 100%; }

/* ---------- البطاقات والمؤشرات ---------- */
.card {
    background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
    padding: .9rem 1rem; box-shadow: var(--shadow);
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: .6rem; margin-bottom: .55rem; flex-wrap: wrap; }
.card-head h3 { margin: 0; }

.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(165px, 1fr)); gap: .7rem; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: .7rem .8rem; box-shadow: var(--shadow); }
.stat-label { font-size: .74rem; color: var(--muted); }
.stat-value { font-size: 1.15rem; font-weight: 800; font-variant-numeric: tabular-nums; direction: ltr; text-align: right; }
.stat-hint { font-size: .7rem; color: var(--muted); }
.stat.good .stat-value { color: var(--good); }
.stat.bad .stat-value { color: var(--bad); }
.stat.warn .stat-value { color: var(--warn); }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(330px, 1fr)); gap: .85rem; }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: .6rem; }
.grid-4 { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .6rem; }
.aging-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: .5rem; }
.meta > div { display: flex; flex-direction: column; font-size: .85rem; }
.meta span { font-size: .72rem; color: var(--muted); }
.memo { background: #f8fafc; border-radius: 10px; padding: .45rem .6rem; }

.spark { width: 100%; height: 80px; display: block; margin-top: .4rem; }
.spark-labels { display: flex; justify-content: space-between; font-size: .68rem; color: var(--muted); }
.section-title { font-size: .9rem; color: var(--brand-2); border-bottom: 2px solid var(--brand-soft); padding-bottom: .2rem; margin-bottom: .4rem; }
.bullets { margin: .3rem 0 0; padding-inline-start: 1.1rem; font-size: .88rem; }
.bullets li { margin-bottom: .25rem; }

/* ---------- الجداول ---------- */
.table-wrap { overflow-x: auto; border-radius: 10px; }
.tbl { width: 100%; border-collapse: collapse; font-size: .86rem; background: var(--panel); }
.tbl th, .tbl td { padding: .45rem .55rem; border-bottom: 1px solid var(--line); text-align: right; vertical-align: middle; }
.tbl thead th { background: #f1f5f9; font-size: .78rem; color: #334155; font-weight: 700; white-space: nowrap; }
.tbl tbody tr:hover { background: #f8fafc; }
.tbl tfoot th { background: #f8fafc; }
.tbl .num { text-align: left; }
.tbl input, .tbl select { min-width: 90px; }
.empty { color: var(--muted); text-align: center; padding: 1rem; background: #f8fafc; border-radius: 10px; font-size: .88rem; }
.totals { display: flex; gap: 1rem; flex-wrap: wrap; padding-top: .55rem; border-top: 1px dashed var(--line); font-size: .86rem; }
.pager { display: flex; gap: .25rem; margin-top: .6rem; flex-wrap: wrap; }
.page { padding: .2rem .55rem; border: 1px solid var(--line); border-radius: 8px; font-size: .82rem; }
.page.active { background: var(--brand); color: #fff; border-color: var(--brand); }

/* ---------- النماذج ---------- */
.field { display: flex; flex-direction: column; gap: .2rem; font-size: .82rem; min-width: 0; }
.field > span { color: #334155; font-weight: 600; font-size: .78rem; }
.field small { color: var(--muted); font-size: .7rem; }
input, select, textarea {
    font: inherit; padding: .42rem .55rem; border: 1px solid #cbd5e1; border-radius: 9px;
    background: #fff; color: var(--ink); width: 100%; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }
input.narrow { width: 6.5rem; }
.stack { display: flex; flex-direction: column; gap: .55rem; }
.filters { display: flex; gap: .5rem; flex-wrap: wrap; align-items: flex-end; margin-bottom: .6rem; }
.filters .field { min-width: 140px; }
.check { display: inline-flex; gap: .35rem; align-items: center; font-size: .82rem; }
.check input { width: auto; }

/* ---------- الأزرار والشارات ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .3rem;
    padding: .42rem .8rem; border-radius: 10px; border: 1px solid #cbd5e1;
    background: #fff; color: var(--ink); font-size: .84rem; cursor: pointer; text-decoration: none;
}
.btn:hover { background: #f8fafc; text-decoration: none; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 700; }
.btn-primary:hover { background: var(--brand-2); }
.btn-ghost { background: transparent; }
.btn-danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn-sm { padding: .25rem .55rem; font-size: .78rem; }
.btn-block { width: 100%; }
.badge { display: inline-block; padding: .1rem .5rem; border-radius: 999px; font-size: .72rem; font-weight: 700; }
.badge-good { background: var(--good-soft); color: var(--good); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-bad { background: var(--bad-soft); color: var(--bad); }
.badge-muted { background: #e2e8f0; color: #475569; }

.alert { padding: .55rem .8rem; border-radius: 10px; font-size: .87rem; border: 1px solid transparent; }
.alert-success { background: var(--good-soft); border-color: #86efac; color: #14532d; }
.alert-error { background: var(--bad-soft); border-color: #fca5a5; color: #7f1d1d; }
.alert-info { background: #e0f2fe; border-color: #bae6fd; color: #075985; }

.result-box { margin-top: .6rem; padding: .7rem .9rem; border-radius: 12px; background: #f1f5f9; display: flex; flex-direction: column; gap: .1rem; }
.result-box b { font-size: 1.3rem; direction: ltr; text-align: right; }
.result-box.good { background: var(--good-soft); }
.result-box.bad { background: var(--bad-soft); }

.tabs { display: flex; gap: .35rem; flex-wrap: wrap; margin-bottom: .7rem; }
.tab { padding: .3rem .75rem; border: 1px solid var(--line); border-radius: 999px; font-size: .82rem; background: #fff; color: var(--ink); }
.tab:hover { text-decoration: none; background: #f1f5f9; }
.tab.active { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 700; }

/* ---------- ميزان المراجعة الثلاثي ---------- */
.tb-3 thead th { text-align: center; vertical-align: middle; }
.tb-3 thead tr:first-child th[colspan] { background: #dbeafe; color: #1e3a8a; }
.tb-3 tbody td:first-child, .tb-3 tbody td:nth-child(2) { text-align: right; white-space: nowrap; }
.tb-3 tfoot th { background: #e2e8f0; text-align: center; }
.tb-3 tfoot th.num { text-align: left; }

/* ---------- فواصل مجموعات الجداول: خط ثقيل بين الفئات وخط خفيف بين التقسيمات ---------- */
.tbl--grouped thead tr:first-child th {
    background: #e8eef7; color: #1e3a8a; text-align: center; vertical-align: middle;
    border-bottom: 2px solid #94a3b8;
}
.tbl--grouped thead tr:first-child th.grp-start { border-inline-start: 2px solid #64748b; }
.tbl--grouped thead tr:nth-child(2) th {
    background: #f8fafc; color: #475569; font-size: .74rem; font-weight: 600; text-align: center;
}
.tbl--grouped thead tr:nth-child(2) th.grp-sub-start { border-inline-start: 2px solid #64748b; }
.tbl--grouped thead tr:nth-child(2) th.sub { border-inline-start: 1px dashed #cbd5e1; }
.tbl--grouped tbody td.grp-start,
.tbl--grouped tfoot th.grp-start { border-inline-start: 2px solid #94a3b8; }
.tbl--grouped tbody td.sub,
.tbl--grouped tfoot th.sub { border-inline-start: 1px dashed #cbd5e1; }
.tbl--grouped tbody tr:first-child td { border-top: 1px solid var(--line); }
.tbl--grouped tfoot th { background: #e2e8f0; font-weight: 700; border-top: 2px solid #64748b; }
@media print {
    .tbl--grouped thead tr:first-child th { background: #e8eef7 !important; }
}

/* ---------- المصادقة ---------- */
.auth-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 1.2rem; background: linear-gradient(160deg, #0b3b39, #0f766e 55%, #115e59); }
.auth-card { background: #fff; border-radius: 18px; padding: 1.5rem; width: 100%; max-width: 470px; box-shadow: 0 20px 50px rgba(2, 44, 42, .35); }
.auth-card.center { text-align: center; }
.auth-brand { display: flex; gap: .6rem; align-items: center; margin-bottom: 1rem; }
.auth-brand small { display: block; color: var(--muted); font-size: .72rem; }
.auth-foot { margin-top: 1rem; font-size: .72rem; color: var(--muted); text-align: center; }
.checks { list-style: none; padding: 0; margin: .5rem 0; font-size: .84rem; }
.checks li { padding: .25rem .1rem; }
.checks li.ok { color: var(--good); }
.checks li.bad { color: var(--bad); }
.error-code { font-size: 3rem; font-weight: 800; color: var(--bad); }

/* ---------- التصدير والفروع وشبكة الإنتاج ---------- */
.export-bar { display: flex; gap: .35rem; align-items: center; flex-wrap: wrap; margin: .35rem 0 .7rem; }
/* شريط الفرز */
.branch-switch { margin: 0; }
.branch-switch select { min-width: 150px; padding: .3rem .5rem; font-size: .8rem; }
.branch-switch select:focus { outline: 2px solid var(--brand-soft); }

/* البحث الشامل ومبدّل اللغة وأدوات الفرز */
.topbar-search { margin: 0; }
.topbar-search input {
    width: 180px; padding: .38rem .75rem; border: 1px solid var(--line); border-radius: 999px;
    background: #fff; font-size: .8rem; font-family: inherit;
}
.topbar-search input:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }
.lang-switch { display: flex; gap: .1rem; padding: .15rem; border: 1px solid var(--line); border-radius: 999px; background: #fff; }
.lang-opt { padding: .18rem .55rem; border-radius: 999px; font-size: .72rem; color: var(--muted); line-height: 1.6; }
.lang-opt:hover { text-decoration: none; background: #f1f5f9; }
.lang-opt.active { background: var(--brand); color: #fff; font-weight: 700; }
.sort-row { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; margin: 0 0 .6rem; }
.sort-row .sort-label { font-size: .78rem; color: var(--muted); }
.sort-row .tab { display: inline-flex; align-items: center; gap: .25rem; }
.search-results { display: grid; gap: 1rem; }
.search-group { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: .9rem 1rem; }
.search-group h3 { margin: 0 0 .6rem; font-size: .95rem; display: flex; align-items: center; gap: .4rem; }
.search-group h3 .count { font-size: .75rem; color: var(--muted); font-weight: 400; }
.search-hit { display: flex; align-items: center; justify-content: space-between; gap: .8rem; padding: .45rem 0; border-top: 1px dashed var(--line); }
.search-hit:first-of-type { border-top: 0; }
.search-hit .meta { color: var(--muted); font-size: .78rem; }
.integrity-summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: .8rem; margin-bottom: 1rem; }
.integrity-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem 1rem; box-shadow: var(--shadow); }
.integrity-card b { display: block; font-size: 1.35rem; }
.integrity-card.bad b { color: var(--bad); }
.integrity-card.good b { color: var(--good); }
.integrity-table th:last-child { min-width: 155px; }
.integrity-row { cursor: pointer; transition: background .15s ease; }
.integrity-row:hover td { background: #f0fdfa; }
.integrity-row.is-bad td:first-child { border-inline-start: 3px solid var(--bad); }
.integrity-row:focus-visible { outline: 2px solid var(--brand); outline-offset: -2px; }
.integrity-target { font-weight: 600; display: inline-flex; align-items: center; gap: .3rem; }
.integrity-jump { display: inline-flex; align-items: center; gap: .25rem; white-space: nowrap; font-size: .8rem; }

/* تمييز القسم المقصود عند الانتقال من صفحة سلامة البيانات */
.pulse-highlight {
    position: relative;
    z-index: 1;
    scroll-margin-top: 84px;
    animation: pfm-pulse 1.15s ease-in-out 4;
}
@keyframes pfm-pulse {
    0%, 100% { background-color: transparent; box-shadow: 0 0 0 0 rgba(15, 118, 110, 0); }
    35% { background-color: #ccfbf1; box-shadow: 0 0 0 5px rgba(15, 118, 110, .28); }
    65% { background-color: #ccfbf1; box-shadow: 0 0 0 2px rgba(15, 118, 110, .48); }
}
.tbl tbody tr.pulse-highlight td { animation: pfm-pulse 1.15s ease-in-out 4; }
html[data-theme="dark"] .integrity-row:hover td { background: #0f2f2c; }
html[data-theme="dark"] .tbl tbody tr.pulse-highlight td { animation-name: pfm-pulse-dark; }
html[data-theme="dark"] .pulse-highlight {
    animation-name: pfm-pulse-dark;
}
@keyframes pfm-pulse-dark {
    0%, 100% { background-color: transparent; box-shadow: 0 0 0 0 rgba(94, 234, 212, 0); }
    35% { background-color: #134e4a; box-shadow: 0 0 0 5px rgba(94, 234, 212, .32); }
    65% { background-color: #134e4a; box-shadow: 0 0 0 2px rgba(94, 234, 212, .52); }
}
@media (prefers-reduced-motion: reduce) {
    .pulse-highlight {
        animation: none;
        background-color: var(--brand-soft);
        outline: 3px solid var(--brand);
        outline-offset: 2px;
    }
    .tbl tbody tr.pulse-highlight td { animation: none; background-color: var(--brand-soft); }
}
@media (max-width: 900px) {
    .topbar-search input { width: 120px; }
}
.branch-edit { border: 1px solid var(--line); border-radius: 10px; padding: .45rem .7rem; margin-bottom: .5rem; background: #f8fafc; }
.branch-edit summary { cursor: pointer; font-size: .9rem; }
.branch-edit[open] { background: #fff; }
.grid-table { font-size: .74rem; white-space: nowrap; }
.grid-table th, .grid-table td { padding: .28rem .4rem; text-align: center; }
.table-wrap.wide { overflow-x: auto; }
.table-wrap.wide .grid-table { min-width: 1500px; }
@media print {
    .grid-table { font-size: 6.8pt; white-space: normal; }
    .table-wrap.wide .grid-table { min-width: none; }
    @page { size: A3 landscape; margin: 6mm; }
}

/* ---------- الفاتورة ---------- */
.toolbar { display: flex; gap: .5rem; align-items: center; margin-bottom: .6rem; }
.invoice-print { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 1.2rem; box-shadow: var(--shadow); max-width: 900px; }
.inv-head { display: flex; justify-content: space-between; gap: 1rem; border-bottom: 2px solid var(--brand); padding-bottom: .7rem; margin-bottom: .7rem; }
.inv-head h2 { color: var(--brand-2); }
.inv-meta { text-align: left; font-size: .85rem; }
.inv-title { font-weight: 800; color: var(--brand); font-size: 1.05rem; }
.inv-parties { display: flex; gap: 2rem; margin-bottom: .7rem; font-size: .88rem; }
.inv-parties > div { display: flex; flex-direction: column; }
.inv-lines { margin-bottom: .8rem; }
.inv-totals { margin-inline-start: auto; width: min(340px, 100%); display: flex; flex-direction: column; gap: .2rem; font-size: .88rem; }
.inv-totals > div { display: flex; justify-content: space-between; border-bottom: 1px dotted var(--line); padding: .15rem 0; }
.inv-totals .grand { font-weight: 800; font-size: 1.05rem; color: var(--brand-2); border-bottom: 2px solid var(--brand); }
.inv-foot { margin-top: 1.2rem; border-top: 1px dashed var(--line); padding-top: .6rem; }
.signatures { display: flex; justify-content: space-between; margin-top: 1.6rem; font-size: .82rem; color: #334155; }

/* ---------- استجابة الشاشات ---------- */
@media (max-width: 980px) {
    .sidebar { position: fixed; inset-inline-start: 0; top: 0; z-index: 50; transform: translateX(100%); transition: transform .2s ease; }
    .sidebar.open { transform: translateX(0); }
    .icon-btn { display: inline-flex; }
    .content { padding: .8rem .7rem 2rem; }
    .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
    .topbar { padding: .6rem .7rem; }
    .inv-head { flex-direction: column; }
    .inv-meta { text-align: right; }
}

@media (max-width: 520px) {
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .user-chip { display: none; }
}

/* ---------- الطباعة ---------- */
@media print {
    body { background: #fff; }
    .sidebar, .topbar, .no-print, .toolbar, .alert { display: none !important; }
    .main { display: block; }
    .content { padding: 0; max-width: none; }
    .card, .invoice-print { box-shadow: none; border: none; padding: 0; }
    .invoice-print { max-width: none; }
    .tbl thead th { background: #f1f5f9 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    a { color: #000; text-decoration: none; }
    @page { margin: 12mm; }
}


/* ---------- تعليمات وتلميحات ---------- */
.help {
    display: inline-flex; align-items: center; justify-content: center;
    width: 1.05rem; height: 1.05rem; border-radius: 50%;
    background: var(--brand-soft); color: var(--brand-2);
    font-size: .72rem; font-weight: 800; cursor: help; position: relative;
    vertical-align: middle; margin-inline-start: .3rem; user-select: none;
}
.help::after {
    content: attr(data-tip);
    position: absolute; left: 50%; bottom: 140%; transform: translateX(-50%);
    background: #0f172a; color: #f8fafc; padding: .45rem .6rem; border-radius: 8px;
    font-size: .74rem; font-weight: 400; line-height: 1.55; text-align: right;
    width: max-content; max-width: 280px; white-space: normal;
    box-shadow: 0 10px 26px rgba(2, 6, 23, .35);
    opacity: 0; visibility: hidden; transition: opacity .15s ease; z-index: 80; pointer-events: none;
}
.help::before {
    content: ''; position: absolute; left: 50%; bottom: 125%; transform: translateX(-50%);
    border: 6px solid transparent; border-top-color: #0f172a;
    opacity: 0; visibility: hidden; transition: opacity .15s ease; z-index: 81; pointer-events: none;
}
.help:hover::after, .help:focus::after, .help:hover::before, .help:focus::before {
    opacity: 1; visibility: visible;
}

/* ---------- الوضع الداكن ---------- */
.theme-toggle { display: inline-flex; align-items: center; justify-content: center; }
html[data-theme="dark"] {
    color-scheme: dark;
    --bg: #0b1220; --panel: #111a2b; --ink: #e2e8f0; --muted: #94a3b8; --line: #22304a;
    --brand: #2dd4bf; --brand-2: #5eead4; --brand-soft: #134e4a;
    --warn: #fbbf24; --warn-soft: #3f3013; --bad: #f87171; --bad-soft: #40191b;
    --good: #4ade80; --good-soft: #0f3524;
    --shadow: 0 1px 2px rgba(0, 0, 0, .5), 0 10px 30px rgba(0, 0, 0, .35);
}
html[data-theme="dark"] body { background: var(--bg); color: var(--ink); }
html[data-theme="dark"] .sidebar { background: #071b1a; }
html[data-theme="dark"] .nav-link { color: #c7f5ee; }
html[data-theme="dark"] .nav-link.active { background: #0f2a28; color: #5eead4; }
html[data-theme="dark"] .theme-toggle { border-color: #334155; color: #e2e8f0; background: #16233a; }
html[data-theme="dark"] code,
html[data-theme="dark"] .memo,
html[data-theme="dark"] .empty,
html[data-theme="dark"] .result-box { background: #16233a; }
html[data-theme="dark"] .tbl thead th { background: #16233a; color: #cbd5e1; }
html[data-theme="dark"] .tbl tbody tr:hover { background: #152035; }
html[data-theme="dark"] .tbl tfoot th { background: #16233a; }
html[data-theme="dark"] .tbl--grouped thead tr:first-child th,
html[data-theme="dark"] .tb-3 thead tr:first-child th[colspan] { background: #1b2b47; color: #93c5fd; }
html[data-theme="dark"] .tbl--grouped thead tr:nth-child(2) th { background: #152035; color: #cbd5e1; }
html[data-theme="dark"] .tbl--grouped tfoot th,
html[data-theme="dark"] .tb-3 tfoot th { background: #1b2b47; }
html[data-theme="dark"] .tbl--grouped tbody td.grp-start,
html[data-theme="dark"] .tbl--grouped thead tr:first-child th.grp-start,
html[data-theme="dark"] .tbl--grouped thead tr:nth-child(2) th.grp-sub-start { border-inline-start-color: #475569; }
html[data-theme="dark"] .tbl--grouped tbody td.sub,
html[data-theme="dark"] .tbl--grouped thead tr:nth-child(2) th.sub { border-inline-start-color: #334155; }
html[data-theme="dark"] input, html[data-theme="dark"] select, html[data-theme="dark"] textarea {
    background: #0e1a2c; color: var(--ink); border-color: #2a3a55;
}
html[data-theme="dark"] .btn { background: #16233a; color: var(--ink); border-color: #2a3a55; }
html[data-theme="dark"] .btn:hover { background: #1c2c46; }
html[data-theme="dark"] .btn-primary { background: var(--brand); border-color: var(--brand); color: #042f2e; }
html[data-theme="dark"] .btn-danger { background: var(--bad); border-color: var(--bad); color: #2a0a0a; }
html[data-theme="dark"] .tab,
html[data-theme="dark"] .lang-switch,
html[data-theme="dark"] .page { background: #16233a; color: var(--ink); border-color: #2a3a55; }
html[data-theme="dark"] .tab:hover,
html[data-theme="dark"] .lang-opt:hover { background: #1c2c46; }
html[data-theme="dark"] .branch-edit[open],
html[data-theme="dark"] .invoice-print,
html[data-theme="dark"] .auth-card,
html[data-theme="dark"] .topbar-search input,
html[data-theme="dark"] .branch-switch select { background: #111a2b; color: var(--ink); }
html[data-theme="dark"] .badge-muted { background: #25324a; color: #cbd5e1; }
html[data-theme="dark"] .sync-pill { background: #3f3013; color: #fbbf24; }
html[data-theme="dark"] .section-title { color: #5eead4; border-bottom-color: #134e4a; }
html[data-theme="dark"] .auth-body { background: linear-gradient(160deg, #04100f, #07211f 55%, #062b28); }
html[data-theme="dark"] .help { background: #134e4a; color: #5eead4; }
@media print {
    html[data-theme="dark"] body,
    html[data-theme="dark"] .card,
    html[data-theme="dark"] .invoice-print { background: #fff !important; color: #000 !important; }
}



/* سجل العمليات: شارات ونوع الحذف وفرق الحقول */
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.nowrap { white-space: nowrap; }
.audit-op {
    display: inline-block; padding: .12rem .55rem; border-radius: 999px;
    font-size: .72rem; font-weight: 800; background: var(--surface-2, #e2e8f0); color: #334155;
}
.audit-op.op-create { background: #dcfce7; color: #166534; }
.audit-op.op-update, .audit-op.op-post { background: #dbeafe; color: #1d4ed8; }
.audit-op.op-delete { background: #fee2e2; color: #b91c1c; }
.audit-op.op-close { background: #fef3c7; color: #b45309; }
.audit-op.op-export, .audit-op.op-import { background: #ede9fe; color: #5b21b6; }
.audit-op.op-auth, .audit-op.op-sync, .audit-op.op-system { background: #e2e8f0; color: #334155; }
.audit-filters { margin-bottom: .8rem; }
.audit-meta { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: .6rem 1rem; margin: .4rem 0 1rem; }
.audit-meta > div {
    display: flex; flex-direction: column; gap: .15rem;
    background: var(--surface-2, #f8fafc); border: 1px solid var(--line, #e2e8f0);
    border-radius: 10px; padding: .5rem .65rem;
}
.diff-table .diff-old { background: #fef2f2; color: #7f1d1d; }
.diff-table .diff-new { background: #ecfdf5; color: #065f46; }
.audit-json-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: .8rem; margin-top: .8rem; }
.json-box {
    background: #0f172a; color: #e2e8f0; padding: .7rem; border-radius: 10px;
    overflow: auto; max-height: 320px; font-size: .75rem; text-align: left; direction: ltr;
}
html[data-theme="dark"] .audit-meta > div { background: #1b2436; border-color: #2a3550; }
html[data-theme="dark"] .audit-op { filter: brightness(.92); }
html[data-theme="dark"] .diff-table .diff-old { background: #3b1d1d; color: #fecaca; }
html[data-theme="dark"] .diff-table .diff-new { background: #123327; color: #bbf7d0; }

/* جدول نصوص الواجهة القابلة للتعديل */
.translations-table td { vertical-align: middle; }
.translations-table input {
    width: 100%; min-width: 130px; padding: .32rem .45rem;
    font-size: .82rem; border-radius: 8px;
}
.translations-table td:first-child { max-width: 260px; overflow-wrap: anywhere; }
.translations-table .badge { font-size: .68rem; }

/* ================= استجابة كاملة لكل أحجام الشاشات ================= */
html { -webkit-text-size-adjust: 100%; }
img, svg { max-width: 100%; }
body.nav-open { overflow: hidden; }
button, .btn, .tab, .page, .nav-link { touch-action: manipulation; }

/* أهداف لمس مريحة على الأجهزة اللمسية */
@media (pointer: coarse) {
    .btn, .tab, .page, .nav-link { min-height: 42px; }
    .icon-btn { min-width: 42px; min-height: 42px; }
}

/* درج القائمة والطبقة المعتمة خلفه */
.nav-backdrop {
    position: fixed; inset: 0; z-index: 45;
    background: rgba(2, 6, 23, .48);
    -webkit-backdrop-filter: blur(1px); backdrop-filter: blur(1px);
}
.sidebar-close {
    display: none; position: absolute; inset-inline-end: .55rem; top: .55rem;
    width: 38px; height: 38px; border-radius: 10px; cursor: pointer;
    border: 1px solid rgba(255, 255, 255, .25);
    background: rgba(255, 255, 255, .08); color: #e6fffb; font-size: 1rem;
    align-items: center; justify-content: center;
}
.sidebar-close:hover { background: rgba(255, 255, 255, .18); }

/* شاشات متوسطة (لابتوب صغير / تابلت أفقي) */
@media (max-width: 1200px) {
    .content { padding: .85rem .85rem 1.8rem; }
    .card { padding: .85rem .9rem; }
    .stats-grid { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
}

/* شاشات كبيرة جداً: توسيط المحتوى وزيادة كثافة المؤشرات */
@media (min-width: 1600px) {
    .content { max-width: 1560px; margin-inline: auto; }
    .sidebar { width: 268px; flex: 0 0 268px; }
    .stats-grid { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
}

/* تابلت عمودي وموبايل كبير: قائمة منزلقة */
@media (max-width: 980px) {
    .sidebar {
        position: fixed; inset-inline-start: 0; top: 0; bottom: 0;
        width: min(86vw, 320px); flex-basis: auto;
        height: 100vh; height: 100dvh;
        transform: translateX(100%); transition: transform .22s ease;
        z-index: 50; box-shadow: 0 0 40px rgba(2, 6, 23, .35); overflow-y: auto;
    }
    [dir="ltr"] .sidebar { transform: translateX(-100%); }
    .sidebar.open, [dir="ltr"] .sidebar.open { transform: translateX(0); }
    .sidebar-close { display: inline-flex; }
    .brand { padding-inline-end: 3.2rem; }
    .icon-btn { display: inline-flex; align-items: center; justify-content: center; }
    .content { padding: .8rem .7rem 2rem; }
    .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
    .topbar { padding: .6rem .7rem; }
    .inv-head { flex-direction: column; }
    .inv-meta { text-align: right; }
    .user-chip { display: none; }
    .nav-link { padding: .58rem .7rem; }
}

/* موبايل: شريط علوي من صفّين + جداول تمريرية + نماذج كاملة العرض */
@media (max-width: 760px) {
    .topbar { flex-wrap: wrap; row-gap: .45rem; }
    .topbar-title { order: 1; flex: 1 1 40%; min-width: 0; }
    .topbar-title h1 { font-size: .98rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .topbar-title > .muted { display: none; }
    #menuToggle { order: 0; }
    .topbar-actions { order: 2; flex: 1 1 100%; margin-inline-start: 0; gap: .4rem; flex-wrap: wrap; }
    .topbar-search { order: -1; flex: 1 1 100%; }
    .topbar-search input { width: 100%; }
    .branch-switch { flex: 1 1 100%; display: flex; order: 1; }
    .branch-switch select { width: 100%; min-width: 0; }
    .lang-switch { flex: 0 0 auto; order: 2; }
    .topbar-actions > .btn, .topbar-actions > .icon-btn { order: 0; }
    .topbar-actions .inline { order: 3; margin-inline-start: auto; }

    .content { padding: .7rem .6rem calc(1.8rem + env(safe-area-inset-bottom)); gap: .7rem; }
    .topbar { padding-top: calc(.6rem + env(safe-area-inset-top)); }
    .card { padding: .75rem .7rem; border-radius: 12px; }
    .card-head { gap: .4rem; }
    .card-head h3 { font-size: .98rem; }

    .stats-grid { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
    .aging-grid { grid-template-columns: repeat(2, 1fr); }
    .integrity-summary { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }

    .filters { gap: .45rem; }
    .filters .field { flex: 1 1 100%; min-width: 0; }
    .filters .btn { flex: 1 1 auto; }
    input, select, textarea { font-size: 16px; }
    .btn { padding: .5rem .75rem; }
    .btn-sm { padding: .42rem .6rem; }
    .export-bar .btn, .toolbar .btn, .sort-row .tab { flex: 1 1 auto; justify-content: center; }
    .toolbar { flex-wrap: wrap; }

    .table-wrap { -webkit-overflow-scrolling: touch; }
    .tbl { font-size: .82rem; }
    .tbl th, .tbl td { padding: .4rem .45rem; }
    .tbl thead th { font-size: .74rem; }
    .tbl input, .tbl select { min-width: 76px; }
    .tbl td { overflow-wrap: anywhere; }
    .grid-table { font-size: .7rem; }
    .grid-table th, .grid-table td { padding: .25rem .3rem; }

    .inv-parties { flex-direction: column; gap: .5rem; }
    .inv-totals { width: 100%; }
    .signatures { flex-wrap: wrap; gap: 1rem; }
    .invoice-print { padding: .8rem; border-radius: 12px; }

    .audit-meta { grid-template-columns: 1fr 1fr; gap: .45rem; }
    .audit-json-grid { grid-template-columns: 1fr; }
    .audit-op { font-size: .68rem; }
    .pager { overflow-x: auto; }
    .search-hit { flex-direction: column; align-items: flex-start; gap: .2rem; }
}

/* هواتف صغيرة */
@media (max-width: 480px) {
    body { font-size: 14px; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .stat-value { font-size: 1.02rem; overflow-wrap: anywhere; }
    .card-head { flex-wrap: wrap; }
    .audit-meta { grid-template-columns: 1fr; }
    .topbar-title h1 { font-size: .92rem; }
    .topbar-actions .btn { padding: .38rem .5rem; font-size: .78rem; }
    .lang-opt { padding: .15rem .45rem; }
    .help::after { left: auto; right: 0; transform: none; max-width: 76vw; }
    .help::before { left: auto; right: .3rem; transform: none; }
    .inv-head h2 { font-size: 1rem; }
    .inv-totals .grand { overflow-wrap: anywhere; }
    .signatures { font-size: .76rem; }
}

/* جوال أفقي (ارتفاع قصير) */
@media (max-height: 520px) and (orientation: landscape) {
    .sidebar { width: min(70vw, 300px); }
    .nav-link { padding-block: .45rem; }
    .nav-section { padding-top: .45rem; }
}

/* الطباعة: إخفاء عناصر التنقل مهما كان حجم الشاشة */
@media print {
    .nav-backdrop, .sidebar-close { display: none !important; }
    .table-wrap { overflow: visible; }
    .tbl th, .tbl td { padding: 2mm 1.5mm; }
}


/* ---------- نوافذ التعديل المنبثقة ---------- */
dialog.modal {
    width: min(940px, 96vw);
    max-width: min(940px, 96vw);
    max-height: 92dvh;
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--ink);
    margin: auto;
    overflow: visible;
}
dialog.modal.modal-sm {
    width: min(520px, 96vw);
    max-width: min(520px, 96vw);
}



dialog.modal::backdrop {
    background: rgba(15, 23, 42, .55);
    backdrop-filter: blur(2px);
}

.modal-box {
    display: flex;
    flex-direction: column;
    max-height: 92dvh;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 16px;
    box-shadow: 0 25px 60px rgba(2, 6, 23, .35);
    overflow: hidden;
    animation: modal-in .16s ease-out;
}

@keyframes modal-in {
    from { opacity: 0; transform: translateY(8px) scale(.99); }
    to { opacity: 1; transform: none; }
}

.modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
    padding: .8rem 1rem;
    border-bottom: 1px solid var(--line);
    background: var(--panel);
    position: sticky;
    top: 0;
    z-index: 2;
}

.modal-head h3 { margin: 0; }

.modal-close {
    flex: 0 0 auto;
    width: 2rem;
    height: 2rem;
    border-radius: 9px;
    border: 1px solid var(--line);
    background: transparent;
    color: var(--muted);
    font-size: 1.25rem;
    line-height: 1;
    cursor: pointer;
}

.modal-close:hover { background: var(--bg); color: var(--ink); }

.modal-body {
    padding: 1rem;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.modal-body > .card {
    border: 0;
    box-shadow: none;
    padding: 0;
    border-radius: 0;
    background: transparent;
}

.modal-body > form.card { padding: 0; }

.modal-body .card-head a.btn-ghost[href]:not([data-modal]) { display: none; }

@media (max-width: 640px) {
    dialog.modal {
        width: 100vw;
        max-width: 100vw;
        max-height: 95dvh;
        margin: auto 0 0;
    }
    .modal-box {
        max-height: 95dvh;
        border-radius: 16px 16px 0 0;
    }
    .modal-body { padding: .8rem; }
}

@media print {
    dialog.modal { display: none !important; }
}

/* ==========================================================================
   واجهة v2 — تنقل واضح، مساحة عمل موحدة، وإجراءات سريعة
   ========================================================================== */
:root {
    --radius-lg: 18px;
    --shadow-lg: 0 18px 45px rgba(15, 23, 42, .12);
    --nav-bg: #07312f;
    --nav-ink: #d9fffb;
}
[hidden] { display: none !important; }

.skip-link {
    position: fixed; inset-inline-start: 1rem; top: -60px; z-index: 200;
    background: #fff; color: var(--brand-2); padding: .55rem .9rem;
    border-radius: 0 0 10px 10px; box-shadow: var(--shadow-lg); font-weight: 700;
}
.skip-link:focus { top: 0; }

.sidebar {
    background: linear-gradient(180deg, #07312f 0%, #0b3b39 55%, #0a3533 100%);
    box-shadow: inset -1px 0 0 rgba(255, 255, 255, .06);
}
.brand { padding: 1.05rem .9rem; }
.brand-mark {
    width: 38px; height: 38px; display: inline-flex; align-items: center; justify-content: center;
    background: rgba(255, 255, 255, .1); border: 1px solid rgba(255, 255, 255, .12);
    border-radius: 12px; font-size: 1.25rem;
}
.sidebar-quick {
    display: flex; align-items: center; gap: .5rem; margin: .55rem .55rem .15rem;
    padding: .5rem .65rem; border-radius: 11px; font-size: .82rem; font-weight: 700;
    color: #052e2b; background: #99f6e4; box-shadow: 0 6px 18px rgba(0, 0, 0, .18);
}
.sidebar-quick:hover { background: #ccfbf1; text-decoration: none; }
.sidebar-quick-plus {
    width: 20px; height: 20px; border-radius: 6px; display: inline-flex;
    align-items: center; justify-content: center; background: #0f766e; color: #fff;
}
.sidebar-quick kbd { margin-inline-start: auto; font-size: .65rem; opacity: .55; background: rgba(0,0,0,.08); }
.sidebar-help { display: block; color: #ccfbf1; margin-bottom: .4rem; font-weight: 600; }
.sidebar-help:hover { color: #fff; }

.nav { padding: .35rem .4rem 1rem; gap: .1rem; }
.nav-link-dashboard { margin-bottom: .15rem; font-weight: 700; }
.nav-group { border-radius: 10px; }
.nav-group > summary.nav-section {
    list-style: none; cursor: pointer; display: flex; align-items: center; gap: .4rem;
    padding: .62rem .65rem .35rem; margin: 0; opacity: .78; user-select: none;
    font-size: .7rem; font-weight: 700; letter-spacing: .04em;
}
.nav-group > summary.nav-section::-webkit-details-marker { display: none; }
.nav-group > summary.nav-section:hover { opacity: 1; color: #fff; }
.nav-group[open] > summary.nav-section { opacity: .95; }
.nav-chevron {
    margin-inline-start: auto; font-size: .8rem; line-height: 1;
    transition: transform .18s ease; transform: rotate(0deg);
}
.nav-group[open] .nav-chevron { transform: rotate(180deg); }
.nav-items { display: flex; flex-direction: column; gap: 1px; }
.nav-link {
    border-inline-start: 3px solid transparent;
    padding: .48rem .65rem; border-radius: 8px;
}
.nav-link svg { flex: 0 0 auto; opacity: .9; }
.nav-link.active {
    background: rgba(255, 255, 255, .97); color: #0f3d3a;
    border-inline-start-color: #2dd4bf; box-shadow: 0 4px 12px rgba(0, 0, 0, .16);
}
.nav-link.active svg { opacity: 1; }
.sidebar-foot { padding: .75rem .8rem; }

.topbar {
    background: rgba(255, 255, 255, .9);
    -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(226, 232, 240, .9);
}
.topbar-title { min-width: 0; }
.topbar-title h1 { font-size: 1.02rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.crumbs {
    display: flex; align-items: center; gap: .35rem; color: var(--muted);
    font-size: .68rem; line-height: 1.5; margin-bottom: .05rem;
}
.crumbs a { color: var(--muted); }
.crumbs span:last-child { color: var(--ink); font-weight: 600; }
.topbar-search {
    display: flex; align-items: center; gap: .35rem; margin: 0;
    padding: .3rem .65rem; border: 1px solid var(--line); border-radius: 999px;
    background: #f8fafc; color: var(--muted);
}
.topbar-search input {
    width: 170px; border: 0; padding: 0; background: transparent; font-size: .8rem;
}
.topbar-search input:focus { outline: none; }
.topbar-search:focus-within { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.command-toggle {
    display: inline-flex; width: auto; font-size: .7rem; font-weight: 700;
    align-items: center; justify-content: center; color: var(--muted);
    border-color: var(--line); background: #fff; padding: .3rem .5rem;
}
.quick-menu { position: relative; }
.quick-menu-panel {
    position: absolute; inset-inline-end: 0; top: calc(100% + .45rem);
    width: 250px; background: #fff; border: 1px solid var(--line);
    border-radius: 14px; box-shadow: var(--shadow-lg); padding: .4rem;
    z-index: 80;
}
.quick-menu-head {
    font-size: .68rem; color: var(--muted); font-weight: 700;
    padding: .3rem .5rem .4rem; border-bottom: 1px solid var(--line); margin-bottom: .25rem;
}
.quick-menu-panel a {
    display: flex; align-items: center; gap: .5rem; padding: .45rem .5rem;
    border-radius: 8px; color: var(--ink); font-size: .82rem;
}
.quick-menu-panel a:hover { background: #f1f5f9; text-decoration: none; }
.quick-menu-icon {
    width: 25px; height: 25px; display: inline-flex; align-items: center; justify-content: center;
    border-radius: 7px; background: var(--brand-soft); color: var(--brand-2);
}

.page-head {
    display: flex; align-items: center; justify-content: space-between; gap: .8rem;
    padding: .1rem .05rem .1rem; flex-wrap: wrap;
}
.page-head-text { min-width: 0; }
.page-eyebrow {
    display: block; color: var(--brand-2); font-size: .68rem; font-weight: 800;
    letter-spacing: .04em; text-transform: uppercase; margin-bottom: .1rem;
}
.page-hint { margin: 0; color: var(--muted); font-size: .82rem; max-width: 75ch; }
.page-head-actions { display: flex; align-items: center; gap: .35rem; flex-wrap: wrap; }

/* ---------- لوحة الأوامر ---------- */
.command-overlay {
    position: fixed; inset: 0; z-index: 120; padding: 9vh 1rem 1rem;
    background: rgba(2, 6, 23, .55); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px);
    display: flex; align-items: flex-start; justify-content: center;
}
.command-box {
    width: min(680px, 100%); background: #fff; border: 1px solid var(--line);
    border-radius: 18px; box-shadow: var(--shadow-lg); overflow: hidden;
}
.command-input-wrap {
    display: flex; align-items: center; gap: .55rem; padding: .8rem .9rem;
    border-bottom: 1px solid var(--line); color: var(--muted);
}
.command-input-wrap input {
    flex: 1; border: 0; background: transparent; font-size: 1rem; font-family: inherit;
}
.command-input-wrap input:focus { outline: none; }
.command-input-wrap kbd {
    font-size: .65rem; color: var(--muted); border: 1px solid var(--line);
    padding: .1rem .3rem; border-radius: 5px; background: #f8fafc;
}
.command-list { max-height: 55vh; overflow-y: auto; padding: .35rem; }
.command-list a {
    display: flex; justify-content: space-between; align-items: center; gap: .6rem;
    padding: .55rem .65rem; border-radius: 9px; color: var(--ink); font-size: .88rem;
}
.command-list a:hover, .command-list a:focus {
    background: var(--brand-soft); color: var(--brand-2); text-decoration: none;
}
.command-list small { color: var(--muted); font-size: .68rem; }
.command-empty { text-align: center; color: var(--muted); padding: .9rem; font-size: .84rem; }

/* ---------- تنقل الجوال ---------- */
.mobile-nav { display: none; }
.mobile-nav a {
    position: relative; color: #0f172a; font-size: .72rem;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .05rem;
}
.mobile-nav a.active { color: var(--brand); font-weight: 800; }
.mobile-nav a > span { font-size: 1.1rem; line-height: 1; }
.mobile-nav .mobile-fab {
    width: 52px; height: 52px; border-radius: 50%; background: var(--brand);
    color: #fff; font-size: 1.6rem; line-height: 1; box-shadow: 0 8px 22px rgba(15, 118, 110, .45);
    margin-top: -24px; border: 4px solid #fff; align-self: start;
}
.mobile-nav .mobile-fab:hover { background: var(--brand-2); text-decoration: none; }

/* ---------- مساحة العمل: خط سير العمل ---------- */
.workflow-strip {
    display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: .55rem;
}
.workflow-step {
    position: relative; display: flex; flex-direction: column; gap: .2rem;
    background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
    padding: .7rem .8rem; box-shadow: var(--shadow); color: var(--ink);
    transition: transform .16s ease, box-shadow .16s ease, border-color .16s ease;
}
.workflow-step:hover {
    transform: translateY(-2px); box-shadow: var(--shadow-lg); border-color: #99f6e4;
    text-decoration: none;
}
.workflow-step b { font-size: .88rem; }
.workflow-step small { color: var(--muted); font-size: .7rem; line-height: 1.45; }
.workflow-step .step-no {
    width: 24px; height: 24px; border-radius: 8px; display: inline-flex;
    align-items: center; justify-content: center; font-size: .72rem; font-weight: 800;
    background: var(--brand-soft); color: var(--brand-2);
}
.workflow-step:not(:last-child)::after {
    content: "←"; position: absolute; inset-inline-end: -.5rem; top: 50%;
    transform: translateY(-50%); color: #94a3b8; font-size: .85rem; z-index: 2;
}
[dir="ltr"] .workflow-step:not(:last-child)::after { content: "→"; }


/* ---------- البطاقة الترحيبية ---------- */
.hero {
    position: relative; overflow: hidden; color: #ecfeff;
    background: linear-gradient(135deg, #0b3b39 0%, #0f766e 58%, #0d9488 100%);
    border-radius: var(--radius-lg); padding: 1.1rem 1.2rem; box-shadow: var(--shadow-lg);
}
.hero::after {
    content: ""; position: absolute; width: 260px; height: 260px; border-radius: 50%;
    background: rgba(255, 255, 255, .08); inset-inline-end: -80px; top: -110px;
}
.hero h2 { color: #fff; font-size: 1.15rem; margin-bottom: .2rem; }
.hero p { color: #ccfbf1; margin: 0; font-size: .84rem; max-width: 70ch; }
.hero-actions { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .8rem; position: relative; z-index: 1; }
.hero-actions .btn { background: rgba(255, 255, 255, .12); border-color: rgba(255, 255, 255, .28); color: #fff; }
.hero-actions .btn:hover { background: rgba(255, 255, 255, .22); }
.hero-actions .btn-primary { background: #fff; border-color: #fff; color: #0b3b39; }

/* ---------- تحسينات البطاقات والجداول والنماذج ---------- */
.card {
    border-radius: var(--radius-lg);
    box-shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 10px 28px rgba(15, 23, 42, .045);
}
.card-head { padding-bottom: .45rem; border-bottom: 1px solid #f1f5f9; }
.card-head h3 { font-size: .98rem; }
.stat {
    border-radius: 14px; padding: .75rem .85rem;
    transition: transform .16s ease, box-shadow .16s ease;
}
.stat:hover { transform: translateY(-1px); box-shadow: var(--shadow-lg); }
.stat-value { font-size: 1.2rem; }

.tbl { border-collapse: separate; border-spacing: 0; }
.tbl thead th { background: #f8fafc; color: #475569; font-size: .73rem; }
.tbl tbody tr:hover td { background: #f8fafc; }
.tbl tbody td:first-child { font-weight: 600; }
.table-wrap { border-radius: 12px; }
.totals {
    display: flex; justify-content: flex-end; gap: .4rem; margin: .45rem 0 0;
    font-size: .82rem; color: var(--muted);
}
.totals b { color: var(--ink); }

.field > span { color: #334155; }
.field input, .field select, .field textarea { width: 100%; }
.field input:focus, .field select:focus, .field textarea:focus {
    outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft);
}
.check { display: inline-flex; align-items: center; gap: .35rem; font-size: .8rem; color: var(--muted); }
.stack { gap: .7rem; }
.filters.card { padding: .7rem .8rem; }
.empty {
    border: 1px dashed var(--line); background: #fbfdff;
    padding: 1.1rem; border-radius: 12px;
}
.badge { padding: .16rem .55rem; }
.btn { transition: background .15s ease, transform .12s ease, box-shadow .15s ease; }
.btn:active { transform: translateY(1px); }
.btn:focus-visible, .icon-btn:focus-visible, .nav-link:focus-visible, .tab:focus-visible {
    outline: 3px solid var(--brand-soft); outline-offset: 2px;
}
/* ---------- استجابة واجهة v2 ---------- */
@media (max-width: 1200px) {
    .topbar-search input { width: 130px; }
    .workflow-strip { gap: .45rem; }
    .workflow-step { padding: .6rem .65rem; }
}

@media (max-width: 980px) {
    .mobile-nav {
        position: fixed; inset-inline: 0; bottom: 0; z-index: 55;
        display: grid; grid-template-columns: repeat(5, minmax(0, 1fr));
        align-items: end; gap: .1rem;
        background: rgba(255, 255, 255, .97);
        -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
        border-top: 1px solid var(--line);
        padding: .35rem .4rem calc(.35rem + env(safe-area-inset-bottom));
        box-shadow: 0 -10px 30px rgba(15, 23, 42, .12);
    }
    .content { padding-bottom: calc(5.5rem + env(safe-area-inset-bottom)); }
    .page-head { align-items: flex-start; }
    .page-head-actions { width: 100%; justify-content: flex-start; }
    .topbar { gap: .5rem; }
    .quick-menu-panel { position: fixed; inset-inline: .7rem; top: 5.3rem; width: auto; }
}

@media (max-width: 760px) {
    .workflow-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .workflow-step:not(:last-child)::after { display: none; }
    .workflow-step:last-child { grid-column: span 2; }
    .hero { padding: .9rem; }
    .hero h2 { font-size: 1.02rem; }
    .page-head-actions .btn { flex: 1 1 auto; }
    .crumbs { display: none; }
    .topbar-title h1 { font-size: .95rem; }
    .command-overlay { padding-top: 4vh; }
    .command-box { border-radius: 14px; }
    .mobile-nav .mobile-fab { width: 48px; height: 48px; }
}

@media (max-width: 480px) {
    .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .workflow-strip { grid-template-columns: 1fr; }
    .workflow-step:last-child { grid-column: auto; }
    .hero-actions .btn { flex: 1 1 100%; }
    .page-hint { font-size: .78rem; }
    .quick-menu-toggle { padding-inline: .55rem; }
}

/* ---------- الوضع الداكن ---------- */
html[data-theme="dark"] .topbar,
html[data-theme="dark"] .quick-menu-panel,
html[data-theme="dark"] .command-box,
html[data-theme="dark"] .mobile-nav {
    background: #0f172a; color: #e2e8f0; border-color: #263449;
}
html[data-theme="dark"] .topbar-search,
html[data-theme="dark"] .command-input-wrap kbd {
    background: #111c30; border-color: #263449; color: #cbd5e1;
}
html[data-theme="dark"] .topbar-search input { color: #e2e8f0; }
html[data-theme="dark"] .quick-menu-panel a,
html[data-theme="dark"] .command-list a { color: #e2e8f0; }
html[data-theme="dark"] .quick-menu-panel a:hover,
html[data-theme="dark"] .command-list a:hover { background: #1e293b; }
html[data-theme="dark"] .quick-menu-head { color: #94a3b8; border-color: #263449; }
html[data-theme="dark"] .quick-menu-icon { background: #134e4a; color: #99f6e4; }
html[data-theme="dark"] .tbl thead th { background: #111c30; color: #94a3b8; }
html[data-theme="dark"] .tbl tbody tr:hover td { background: #142033; }
html[data-theme="dark"] .empty { background: #111c30; border-color: #334155; }
html[data-theme="dark"] .card-head { border-color: #1e293b; }
html[data-theme="dark"] .mobile-nav a { color: #cbd5e1; }
html[data-theme="dark"] .mobile-nav a.active { color: #5eead4; }
html[data-theme="dark"] .mobile-nav .mobile-fab { border-color: #0f172a; }
html[data-theme="dark"] .field > span { color: #cbd5e1; }
html[data-theme="dark"] .crumbs span:last-child { color: #e2e8f0; }
html[data-theme="dark"] .totals b { color: #e2e8f0; }

/* ---------- الطباعة ---------- */
@media print {
    .mobile-nav, .command-overlay, .quick-menu, .command-toggle, .page-head-actions, .skip-link { display: none !important; }
    .page-head { border: 0; padding: 0 0 .5rem; }
    .page-hint { color: #334155; }
    .content { padding-bottom: 0; }
}

.hero-kicker {
    display: inline-flex; align-items: center; gap: .35rem; color: #99f6e4;
    font-size: .7rem; font-weight: 800; letter-spacing: .04em; margin-bottom: .25rem;
    position: relative; z-index: 1;
}
.section-head {
    display: flex; align-items: flex-end; justify-content: space-between;
    gap: .6rem; flex-wrap: wrap; margin-top: .15rem;
}
.section-head h2 { margin: 0; font-size: 1rem; }
.section-head p { margin: 0; }
body.command-open { overflow: hidden; }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .01ms !important;
        scroll-behavior: auto !important;
    }
}

.icon-btn { align-items: center; justify-content: center; min-width: 34px; }
