:root {
  --primary: #0e7490;
  --primary-dark: #155e75;
  --primary-soft: #e0f2f7;
  --accent: #c2410c;
  --bg: #f3f5f8;
  --surface: #ffffff;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --muted: #64748b;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --success: #15803d;
  --success-soft: #dcfce7;
  --warning: #b45309;
  --warning-soft: #fef3c7;
  --sidebar: #0f2b38;
  --sidebar-text: #c7d6de;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .08);
  --topbar-h: 54px;
}

* { box-sizing: border-box; }
html { font-size: 14.5px; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: "Segoe UI", Tahoma, "Noto Sans Arabic", Arial, sans-serif;
  line-height: 1.5; -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; cursor: pointer; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; font-weight: 700; }
svg.icon { width: 18px; height: 18px; flex-shrink: 0; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------------- التخطيط العام ---------------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 238px; flex-shrink: 0; background: var(--sidebar); color: var(--sidebar-text);
  position: sticky; top: 0; height: 100vh; overflow-y: auto; padding-bottom: 24px;
  scrollbar-width: thin; scrollbar-color: #29495a transparent;
}
.brand { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 18px 12px 12px; color: #fff; text-align: center; }
.brand .logo { width: 84px; height: 104px; flex-shrink: 0; }
.brand .sub { font-size: 11.5px; color: #8fb1c1; font-weight: 400; }
.menu-section { padding: 14px 18px 4px; font-size: 11.5px; color: #7f9fae; letter-spacing: .3px; }
.menu a {
  display: flex; align-items: center; gap: 10px; padding: 7px 16px; margin: 1px 8px; border-radius: 8px;
  color: var(--sidebar-text); font-size: 13.8px; text-decoration: none;
}
.menu a:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.menu a.active { background: var(--primary); color: #fff; }
.menu a .icon { opacity: .9; width: 17px; height: 17px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
/* نسخة قديمة نُقلت بياناتها إلى البرنامج المثبت: شريط تنبيه ثابت أسفل الشاشة */
.moved-banner {
  position: fixed; inset-inline: 0; bottom: 0; z-index: 900; display: flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 38px; padding: 8px 16px; background: #fef3c7; color: #92400e; border-top: 1px solid #f59e0b; font-size: 13.5px; font-weight: 600; text-align: center;
}
.moved-banner .icon { width: 17px; height: 17px; flex-shrink: 0; }
body.has-moved-banner { padding-bottom: 40px; }
body.has-moved-banner .sidebar { height: calc(100vh - 40px); }
body.has-moved-banner .toasts { bottom: 58px; }
@media print { .moved-banner { display: none !important; } body.has-moved-banner { padding-bottom: 0; } }
.topbar {
  height: var(--topbar-h); background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px; padding: 0 18px; position: sticky; top: 0; z-index: 30;
}
.topbar .company { font-weight: 700; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.topbar .spacer { flex: 1; }
.topbar .quick { display: flex; gap: 6px; }
.content { padding: 18px 22px 60px; max-width: 1500px; width: 100%; }
.btn.menu-toggle { display: none; } /* «.btn» بعدها كان يظهره على الحاسوب حيث القائمة ظاهرة دائماً */

/* ---------------- رأس الصفحة ---------------- */
.page-head { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head .titles { flex: 1; min-width: 200px; }
.page-head h1 { font-size: 21px; }
.page-head .subtitle { color: var(--muted); font-size: 13px; margin-top: 2px; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.crumbs { font-size: 12.5px; color: var(--muted); margin-bottom: 3px; }

/* ---------------- الأزرار ---------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 36px; padding: 0 14px;
  border-radius: 8px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font: inherit; font-size: 13.8px; cursor: pointer; white-space: nowrap; text-decoration: none !important;
}
.btn:hover { background: #f8fafc; border-color: #94a3b8; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-danger { color: var(--danger); border-color: #fca5a5; }
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn-success { background: var(--success); border-color: var(--success); color: #fff; }
.btn-success:hover { background: #166534; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: #eef2f6; border-color: transparent; }
.btn-sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn-icon { width: 32px; height: 32px; padding: 0; }
.btn .icon { width: 16px; height: 16px; }

/* ---------------- البطاقات ---------------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.card-head h3 { font-size: 15px; flex: 1; }
.card-body { padding: 14px 16px; }
.card + .card, .card + .grid2, .grid2 + .card, .cards + .card, .card + .cards, .grid2 + .grid2 { margin-top: 16px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
/* البطاقة التي فيها جدول عريض تمرّر الجدول داخلها بدل أن تعرّض الصفحة كلها (كانت تسبب تمريراً أفقياً على الهاتف) */
.grid2 > *, .grid3 > * { min-width: 0; }
/* 180: خمس بطاقات تبقى في صف واحد حتى شاشة 1280 (بـ210 كانت الخامسة تنزل وحدها إلى صف ثانٍ) */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; }
.kpi { padding: 14px 16px; }
.kpi .label { color: var(--muted); font-size: 12.8px; display: flex; align-items: center; gap: 6px; }
.kpi .value { font-size: 21px; font-weight: 700; margin-top: 4px; direction: ltr; text-align: right; font-variant-numeric: tabular-nums; }
.kpi .value.small { font-size: 16px; }
.kpi .sub { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.kpi-lines div { display: flex; justify-content: space-between; gap: 8px; font-variant-numeric: tabular-nums; }
.kpi-lines .amt { direction: ltr; unicode-bidi: isolate; font-weight: 600; }
@media (max-width: 1440px) { .kpi .value { font-size: 19px; } } /* مبلغ كبير يتسع في بطاقة ضيقة */

/* ---------------- النماذج ---------------- */
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px 16px; }
.form-grid .span2 { grid-column: span 2; }
.form-grid .span-all { grid-column: 1 / -1; }
.field label { display: block; font-size: 12.8px; color: var(--muted); margin-bottom: 4px; font-weight: 500; }
.field .hint { font-size: 12px; color: var(--muted); margin-top: 3px; }
.input, select.input, textarea.input {
  width: 100%; height: 36px; border: 1px solid var(--border-strong); border-radius: 8px; padding: 0 10px;
  font: inherit; font-size: 14px; color: var(--text); background: #fff; outline: none;
}
textarea.input { height: auto; min-height: 64px; padding: 8px 10px; resize: vertical; }
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(14, 116, 144, .15); }
.input.invalid { border-color: var(--danger); background: #fff7f7; }
.input.num { direction: ltr; text-align: left; font-variant-numeric: tabular-nums; }
.input[readonly] { background: #f8fafc; }
.date-wrap { position: relative; display: flex; align-items: center; min-width: 140px; }
.date-wrap .date-text { direction: ltr; text-align: right; padding-inline-end: 10px; padding-inline-start: 34px; font-variant-numeric: tabular-nums; }
.date-btn { position: absolute; left: 4px; width: 28px; height: 28px; border: 0; background: transparent; color: var(--muted); cursor: pointer; display: grid; place-items: center; border-radius: 6px; }
.date-btn:hover { background: #eef2f6; color: var(--primary); }
.date-btn:disabled { cursor: default; opacity: .5; }
.date-native { position: absolute; left: 0; bottom: 0; width: 1px; height: 1px; opacity: 0; pointer-events: none; border: 0; padding: 0; }
.checkbox { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; user-select: none; font-size: 13.8px; }
.checkbox input { width: 16px; height: 16px; accent-color: var(--primary); }
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin-bottom: 14px; }
.filters .field { min-width: 150px; }
.filters .grow { flex: 1; min-width: 220px; }
.form-actions { display: flex; gap: 8px; justify-content: flex-start; align-items: center; margin-top: 16px; flex-wrap: wrap; }
.seg { display: inline-flex; flex-shrink: 0; border: 1px solid var(--border-strong); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: #fff; padding: 0 12px; height: 34px; font: inherit; font-size: 13.5px; cursor: pointer; white-space: nowrap; border-inline-start: 1px solid var(--border); }
.seg button:first-child { border-inline-start: 0; }
.seg button.on { background: var(--primary); color: #fff; }

/* ---------------- القائمة المنسدلة الذكية ---------------- */
.combo { position: relative; }
.combo-list {
  position: fixed; z-index: 1000; background: #fff; border: 1px solid var(--border-strong); border-radius: 8px;
  box-shadow: 0 10px 30px rgba(15, 23, 42, .18); max-height: 320px; overflow-y: auto; min-width: 240px;
}
.combo-item { padding: 7px 11px; cursor: pointer; display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.combo-item:hover, .combo-item.active { background: var(--primary-soft); }
.combo-item .sub { color: var(--muted); font-size: 12px; white-space: nowrap; }
.combo-item.create { color: var(--primary); font-weight: 600; border-top: 1px solid var(--border); }
.combo-empty { padding: 10px; color: var(--muted); font-size: 13px; }

/* ---------------- الجداول ---------------- */
.table-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13.8px; }
.tbl th {
  background: #f1f5f9; color: #334155; font-weight: 600; text-align: right; padding: 8px 10px;
  border-bottom: 1px solid var(--border-strong); white-space: nowrap; font-size: 13px;
}
.card .tbl th:first-child { border-start-start-radius: 0; }
.tbl td { padding: 7px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl tbody tr:hover td { background: #f8fbfd; }
.tbl tbody tr.clickable { cursor: pointer; }
.tbl tfoot td { font-weight: 700; background: #f8fafc; border-top: 2px solid var(--border-strong); }
/* isolate: المبلغ داخل نص عربي (عنصر سطري) يبقى «4,000.00 €» ولا ينقلب إلى «€ 4,000.00» */
.tbl .num, .num { text-align: left; direction: ltr; unicode-bidi: isolate; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tbl th.num { text-align: left; }
.tbl .center { text-align: center; }
.tbl .muted, .muted { color: var(--muted); }
.tbl .nowrap { white-space: nowrap; }
.tbl tr.group td { background: #f8fafc; font-weight: 600; }
.tbl tr.level-0 td { font-weight: 700; background: #eef4f7; }
.tbl tr.total td { font-weight: 700; background: #eef4f7; }
.tbl tr.grand td { font-weight: 800; background: #dff0f5; font-size: 14.5px; }
.tbl .indent { display: inline-block; }
.neg { color: var(--danger); }
.pos { color: var(--success); }
.empty { text-align: center; color: var(--muted); padding: 30px 10px !important; }
.tbl td .actions { display: flex; gap: 4px; justify-content: flex-end; }

/* جدول الإدخال (القيود والفواتير) */
.grid-table { width: 100%; border-collapse: separate; border-spacing: 0; }
.grid-table th { background: #f1f5f9; font-size: 12.8px; color: #334155; font-weight: 600; padding: 7px 6px; text-align: right; border-bottom: 1px solid var(--border-strong); }
.grid-table td { padding: 3px 4px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.grid-table .input { height: 34px; border-color: #dbe3ea; }
.grid-table .rowno { color: var(--muted); font-size: 12px; text-align: center; width: 28px; }
.grid-table tfoot td { padding: 8px 6px; font-weight: 700; background: #f8fafc; }
/* عنوان العمود بمحاذاة محتواه في أي جدول (تضبطه alignTableHeads تلقائياً، أو الكود مباشرة) */
table th.num { text-align: left; }
table th.center { text-align: center; }
.diff-ok { color: var(--success); font-weight: 700; }
.diff-bad { color: var(--danger); font-weight: 700; }

/* ---------------- شارات وتبويبات ---------------- */
.badge { display: inline-block; padding: 1px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: #e2e8f0; color: #334155; white-space: nowrap; }
.badge-green { background: var(--success-soft); color: var(--success); }
.badge-amber { background: var(--warning-soft); color: var(--warning); }
.badge-red { background: var(--danger-soft); color: var(--danger); }
.badge-blue { background: #dbeafe; color: #1d4ed8; }
.badge-teal { background: var(--primary-soft); color: var(--primary-dark); }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 14px; flex-wrap: wrap; }
.tab { padding: 8px 14px; cursor: pointer; border-bottom: 2px solid transparent; color: var(--muted); font-weight: 500; margin-bottom: -1px; user-select: none; }
.tab:hover { color: var(--text); }
.tab.active { border-color: var(--primary); color: var(--primary); font-weight: 700; }

/* ---------------- تنبيهات ---------------- */
.alert { padding: 10px 14px; border-radius: 9px; border: 1px solid; font-size: 13.8px; display: flex; gap: 10px; align-items: flex-start; margin-bottom: 14px; }
.alert-warn { background: var(--warning-soft); border-color: #fcd34d; color: #78350f; }
.alert-info { background: #eff6ff; border-color: #bfdbfe; color: #1e3a8a; }
.alert-danger { background: var(--danger-soft); border-color: #fca5a5; color: #7f1d1d; }
.alert-ok { background: var(--success-soft); border-color: #86efac; color: #14532d; }

.toasts { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 2000; align-items: center; }
.toast { background: #0f172a; color: #fff; padding: 10px 18px; border-radius: 9px; box-shadow: 0 10px 25px rgba(0,0,0,.25); font-size: 14px; max-width: 640px; animation: toastIn .18s ease-out; }
.toast.error { background: #991b1b; }
.toast.ok { background: #166534; }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.modal-back { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); z-index: 900; display: grid; grid-template-columns: minmax(0, 1fr); place-items: center; padding: 20px; }
.modal { background: #fff; border-radius: 12px; width: 560px; max-width: 100%; max-height: calc(100vh - 40px); display: flex; flex-direction: column; box-shadow: 0 25px 60px rgba(0,0,0,.3); }
.modal.wide { width: 920px; }
.modal-head { padding: 14px 18px; border-bottom: 1px solid var(--border); display: flex; align-items: center; }
.modal-head h3 { flex: 1; font-size: 16px; }
.modal-body { padding: 16px 18px; overflow-y: auto; }
.modal-foot { padding: 12px 18px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-start; }
/* ضغطة خارج نافذة فيها بيانات لم تُحفظ: تهتز بدل أن تُغلق */
.modal.attn { animation: modal-attn .32s ease-in-out; }
@keyframes modal-attn { 0%, 100% { transform: none; } 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
@media (prefers-reduced-motion: reduce) { .modal.attn { animation: none; box-shadow: 0 0 0 3px var(--warning), 0 25px 60px rgba(0,0,0,.3); } }

.offline { position: fixed; top: 0; left: 0; right: 0; background: #991b1b; color: #fff; padding: 10px; text-align: center; z-index: 3000; font-weight: 600; }
.loading { color: var(--muted); padding: 40px; text-align: center; }
.loading-mark { display: block; width: 104px; height: 130px; margin: 16vh auto 16px; animation: mark-in .6s ease-out both; }
@keyframes mark-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .loading-mark { animation: none; } }

/* ---------------- مكونات خاصة ---------------- */
.entry-block { border: 1px solid var(--border); border-radius: 9px; margin-bottom: 10px; background: #fff; overflow: hidden; }
.entry-block .eh { display: flex; gap: 12px; align-items: center; padding: 7px 12px; background: #f8fafc; border-bottom: 1px solid var(--border); font-size: 13.5px; flex-wrap: wrap; }
.entry-block .eh .no { font-weight: 700; color: var(--primary-dark); }
.entry-block .eh .desc { flex: 1; color: #334155; }
/* fixed: الأعمدة بالعرض نفسه في كل القيود (كان عمود المدين والدائن ينتقل من قيد لآخر حسب طول الأسماء) */
.entry-block table { width: 100%; border-collapse: collapse; font-size: 13.5px; table-layout: fixed; }
.entry-block td { padding: 4px 12px; border-bottom: 1px dashed #edf2f7; overflow-wrap: anywhere; }
.entry-block tr:last-child td { border-bottom: 0; }
.entry-block .credit-acc { padding-inline-start: 46px; }

.bar-chart { display: flex; align-items: flex-end; gap: 14px; height: 190px; padding: 10px 6px 0; border-bottom: 1px solid var(--border); }
.bar-group { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; min-width: 0; }
.bars { display: flex; gap: 3px; align-items: flex-end; height: 100%; width: 100%; justify-content: center; }
.bar { width: 30%; max-width: 22px; border-radius: 4px 4px 0 0; min-height: 2px; }
.bar.rev { background: #0e7490; }
.bar.exp { background: #f59e0b; }
.bar.net { background: #16a34a; }
.bar.net.loss { background: #dc2626; }
.bar-label { font-size: 11.5px; color: var(--muted); text-align: center; line-height: 1.25; }
.legend { display: flex; gap: 14px; font-size: 12.5px; color: var(--muted); margin-top: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-inline-end: 4px; }

.att { width: 44px; height: 32px; border-radius: 7px; border: 1px solid var(--border-strong); background: #fff; cursor: pointer; font: inherit; font-weight: 700; }
.att.full { background: #dcfce7; border-color: #86efac; color: #166534; }
.att.half { background: #fef3c7; border-color: #fcd34d; color: #92400e; }
.att.absent { background: #fee2e2; border-color: #fca5a5; color: #991b1b; }
.att.extra { background: #dbeafe; border-color: #93c5fd; color: #1e40af; }
.att:disabled { cursor: default; opacity: .85; }

.company-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.company-card { padding: 16px; cursor: pointer; transition: border-color .15s, transform .15s; }
.company-card:hover { border-color: var(--primary); transform: translateY(-1px); }
.company-card h3 { font-size: 16px; margin-bottom: 6px; }
.welcome { max-width: 1100px; margin: 0 auto; padding: 36px 20px; }
.welcome-head { display: flex; align-items: center; gap: 14px; margin-bottom: 24px; }
.welcome-head .logo { width: 54px; height: 54px; flex-shrink: 0; filter: drop-shadow(0 3px 8px rgba(11, 74, 94, .28)); }

.statement-head { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 14px; }
.stat { background: #f8fafc; border: 1px solid var(--border); border-radius: 9px; padding: 10px 12px; }
.stat .l { font-size: 12.5px; color: var(--muted); }
.stat .v { font-size: 17px; font-weight: 700; direction: ltr; text-align: right; font-variant-numeric: tabular-nums; }

.span-all:has(> .voucher-info:empty) { display: none; }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 6px 12px; font-size: 14px; }
.kv .k { color: var(--muted); }
.help-list { margin: 0; padding-inline-start: 20px; }
.help-list li { margin-bottom: 4px; }
.print-only { display: none; }
.inline-actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.mt { margin-top: 14px; }
.mb { margin-bottom: 14px; }
/* داخل الشبكات تأتي المسافة بين البطاقات من gap وحده: هامش علوي على بطاقة (من «.card + .card» أو «.mt») كان ينزلها
   ويقصّرها عن جاراتها في الصف نفسه، فتبدو البطاقة الأولى (على اليمين) أكبر منها. :nth-child(n) يرفع الأولوية فوق القاعدتين */
:is(.grid2, .grid3, .cards, .company-grid, .statement-head, .ai-page-grid, .ai-modes) > :nth-child(n) { margin-block: 0; }
.right { margin-inline-start: auto; }
.w100 { width: 100%; }

@media (max-width: 1000px) {
  .grid2, .grid3 { grid-template-columns: 1fr; }
  /* القائمة الجانبية تُخفى تماماً وتظهر بزر القائمة (حتى لا تسبب تمريراً أفقياً) */
  .sidebar { display: none; position: fixed; inset-inline-start: 0; top: 0; z-index: 50; box-shadow: 0 0 40px rgba(0, 0, 0, .35); }
  .sidebar.open { display: block; }
  .btn.menu-toggle { display: inline-flex; }
  .content { padding: 14px; }
  .topbar { gap: 6px; padding: 0 10px; }
  .topbar .quick, .topbar .company .badge, .topbar .company .icon { display: none; }
  .topbar .company { min-width: 0; flex: 1; }
  #company-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .topbar .switch-company { padding: 0 8px; }
  .page-head h1 { font-size: 19px; }
}
@media (max-width: 600px) {
  .form-grid .span2 { grid-column: auto; }
  .kv { grid-template-columns: 1fr; }
}

/* ---------------- الطباعة ---------------- */
@media print {
  @page { size: A4; margin: 12mm; }
  html { font-size: 12px; }
  body { background: #fff; }
  .sidebar, .topbar, .no-print, .filters, .page-head .actions, .tabs, .form-actions, .toasts { display: none !important; }
  .print-only { display: block !important; }
  .content { padding: 0; max-width: none; }
  .card { box-shadow: none; border: 0; }
  .card-head { padding: 6px 0; }
  .card-body { padding: 6px 0; }
  .tbl th { position: static; background: #eef2f6 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .tbl td, .tbl th { padding: 4px 6px; }
  .tbl tr { break-inside: avoid; }
  .print-header { display: flex !important; justify-content: space-between; align-items: flex-end; border-bottom: 2px solid #0f172a; padding-bottom: 6px; margin-bottom: 10px; }
  .print-header .co { font-size: 16px; font-weight: 800; }
  .print-footer { display: block !important; margin-top: 16px; font-size: 11px; color: #64748b; }
  a { color: inherit; text-decoration: none; }
}

/* ---------------- تسجيل الدخول ---------------- */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 20px;
  background: radial-gradient(circle at 20% 10%, #d7eef4 0, transparent 40%), radial-gradient(circle at 90% 90%, #fde7d3 0, transparent 35%), var(--bg); }
.login-card { width: 420px; max-width: 100%; padding: 26px 26px 20px; }
.login-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.login-head .logo { width: 54px; height: 54px; flex-shrink: 0; filter: drop-shadow(0 3px 8px rgba(11, 74, 94, .28)); }
.login-head h1 { font-size: 22px; }
.login-form { display: flex; flex-direction: column; gap: 12px; }
.login-form .input { height: 40px; font-size: 15px; }

/* ---------------- قائمة المستخدم ---------------- */
.user-btn { gap: 6px; max-width: 200px; }
.user-btn .user-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-pop { position: fixed; z-index: 1200; min-width: 230px; padding: 6px 0; box-shadow: 0 12px 30px rgba(15, 23, 42, .2); }
.menu-btn { display: flex; align-items: center; gap: 8px; width: 100%; padding: 8px 14px; border: 0; background: none; font: inherit;
  font-size: 14px; color: var(--text); cursor: pointer; text-align: right; text-decoration: none !important; }
.menu-btn:hover { background: #f1f5f9; }
.menu-btn.danger { color: var(--danger); }

/* ---------------- مصفوفة الصلاحيات ---------------- */
.perm-company { padding: 10px 12px; margin-bottom: 10px; box-shadow: none; }
.perm-company.on { border-color: var(--primary); background: #fbfeff; }
.perm-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; justify-content: space-between; }
.perm-table { margin-top: 8px; font-size: 13.5px; }
.perm-table td, .perm-table th { padding: 5px 8px; }
.perm-table input { width: 17px; height: 17px; accent-color: var(--primary); cursor: pointer; }
.lock-note { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12.5px; }
.num-preview { direction: ltr; unicode-bidi: plaintext; font-variant-numeric: tabular-nums; color: var(--text); font-weight: 600; }
.ot-col { background: #fffbeb; }
.payroll-table thead th.ot-col { background: #fef3c7; }
.ot-rate { min-width: 74px; height: 30px; padding: 0 6px; font-variant-numeric: tabular-nums; }
/* سجل الدوام: 18 عموداً. أضيق ليتسع كاملاً على الشاشات الشائعة، و«العامل» و«الصافي» ثابتان على الطرفين فيبقيان
   ظاهرين إذا لزم التمرير الأفقي (شاشة 1366) */
.payroll-table th, .payroll-table td { padding: 6px 5px; }
.payroll-table th, .payroll-table th.num { white-space: normal; line-height: 1.3; } /* العنوان الطويل ينكسر بدل أن يعرّض عموده */
.payroll-table .day-name { font-size: 12px; }
.payroll-table .att { width: 38px; }
.payroll-table .worker-name { min-width: 92px; }
.payroll-table .sticky-start, .payroll-table .sticky-end { position: sticky; z-index: 1; background: var(--surface); }
/* يمين ويسار صريحان (الواجهة عربية دائماً): خانة «الصافي» رقمية باتجاه ltr فكان inset-inline-end يثبّتها يميناً */
.payroll-table .sticky-start { right: 0; box-shadow: inset 1px 0 0 var(--border); }
.payroll-table .sticky-end { left: 0; box-shadow: inset -1px 0 0 var(--border); }
.payroll-table thead .sticky-start, .payroll-table thead .sticky-end { background: #f1f5f9; }
.payroll-table tfoot .sticky-start, .payroll-table tfoot .sticky-end { background: #f8fafc; }
.payroll-table tbody tr:hover .sticky-start, .payroll-table tbody tr:hover .sticky-end { background: #f8fbfd; }
.week-title { font-weight: 700; font-size: 16px; white-space: nowrap; }
.vat-col { background: #f5f3ff; }

/* ---------------- شريط سعر الصرف الرسمي اليومي ---------------- */
.rate-bar { background: #eff6ff; border-bottom: 1px solid #bfdbfe; color: #1e3a8a; padding: 8px 22px; font-size: 13.5px; }
.rate-bar.warn { background: var(--warning-soft); border-color: #fcd34d; color: #78350f; }
.rate-bar .rate-main { display: flex; gap: 10px; align-items: flex-start; max-width: 1500px; }
.rate-bar .rate-main > .icon { flex: none; margin-top: 2px; }
.rate-bar .rate-text { flex: 1; min-width: 0; }
.rate-bar .rate-title { font-weight: 700; display: inline; margin-inline-end: 8px; }
.rate-bar .rate-pairs { display: inline-flex; flex-wrap: wrap; gap: 4px 18px; }
.rate-bar .rate-pair b { font-size: 14.5px; unicode-bidi: isolate; }
.rate-bar .rate-pair small { opacity: .8; font-size: 12px; }
.rate-bar .rate-note { font-size: 12.5px; margin-top: 3px; opacity: .9; }
.rate-bar .rate-actions { display: flex; gap: 6px; flex-wrap: wrap; flex: none; }
.rate-bar.compact { padding-top: 5px; padding-bottom: 5px; }
.rate-bar.ok { background: var(--success-soft); border-color: #86efac; color: #14532d; }
.rate-bar .rate-note a { color: inherit; text-decoration: underline; font-weight: 600; }
.rate-bar .rate-done { display: inline-flex; align-items: center; gap: 4px; font-weight: 700; font-size: 12.5px; white-space: nowrap; align-self: center; }
.rate-confirm { overflow-x: auto; }
.rate-confirm .alert { margin-bottom: 10px; }
.rate-confirm-table td { vertical-align: middle; }
.rate-confirm-table .input { width: 150px; }
.rate-confirm-note { font-size: 12.5px; margin-top: 8px; }
.rate-confirm-done { display: flex; gap: 6px; align-items: center; color: var(--success); font-weight: 600; margin-top: 10px; }
@media (max-width: 760px) {
  .rate-bar { padding: 8px 12px; }
  .rate-bar .rate-main { flex-wrap: wrap; }
  .rate-bar .rate-text { flex-basis: calc(100% - 30px); }
  .rate-bar .rate-actions { width: 100%; }
}
@media (max-width: 640px) {
  .rate-confirm-table, .rate-confirm-table tbody, .rate-confirm-table tr, .rate-confirm-table td { display: block; width: auto; }
  .rate-confirm-table thead { display: none; }
  .rate-confirm-table tr { border-bottom: 1px solid var(--border); padding: 8px 0; }
  .rate-confirm-table td { border: 0; padding: 2px 0; }
  .rate-confirm-table td:first-child { font-weight: 700; }
  .rate-confirm-table td:nth-child(2)::before { content: 'الرسمي: '; color: var(--muted); }
  .rate-confirm-table td:nth-child(3)::before { content: 'المعتمد الآن: '; color: var(--muted); }
  .rate-confirm-table .input { width: 100%; margin-top: 4px; }
}
@media print { .rate-bar { display: none !important; } }
.rate-chart-box { margin-bottom: 12px; }
.rate-chart { width: 100%; height: auto; max-height: 240px; direction: ltr; }
.rate-chart .grid { stroke: var(--border); stroke-width: 1; }
.rate-chart .axis { fill: var(--muted); font-size: 11px; font-family: inherit; }
.rate-chart .line-official { fill: none; stroke: var(--primary); stroke-width: 2; }
.rate-chart .dot-manual { fill: #f59e0b; stroke: #fff; stroke-width: 1; }

/* ---------------- الذكاء الاصطناعي: الزر العائم والمحادثة وقسمه ---------------- */
:root {
  --ai-1: #0ea5b7; --ai-2: #6366f1; --ai-3: #a855f7;
  --ai-grad: linear-gradient(135deg, var(--ai-1) 0%, var(--ai-2) 55%, var(--ai-3) 100%);
  --ai-soft: #f5f3ff;
}
@keyframes ai-spin { to { transform: rotate(360deg); } }
@keyframes ai-shimmer { to { background-position: -300% 0; } }
@keyframes ai-float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }
@keyframes ai-pop { from { opacity: 0; transform: translateY(14px) scale(.96); } to { opacity: 1; transform: none; } }
@keyframes ai-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes ai-card-in { from { opacity: 0; transform: scale(.94) translateY(4px); } to { opacity: 1; transform: none; } }
@keyframes ai-sweep { from { transform: translateX(-120%); } to { transform: translateX(120%); } }
@keyframes ai-pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, .5); } 50% { box-shadow: 0 0 0 7px rgba(239, 68, 68, 0); } }
@keyframes ai-dot { 0%, 100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, .45); } 50% { box-shadow: 0 0 0 5px rgba(34, 197, 94, 0); } }

.menu-section.ai-menu { display: flex; align-items: center; gap: 6px; color: #c4b5fd; }
.menu-section.ai-menu .icon { width: 13px; height: 13px; color: #a78bfa; }
/* زر المساعد في الشريط العلوي: كان زراً عائماً أسفل اليسار فيغطي عمود المبالغ في الجداول وأزرار الصفحات */
.ai-fab {
  position: relative; display: inline-flex; align-items: center; gap: 7px; height: 32px; padding: 0 13px 0 11px; border: 0;
  border-radius: 999px; cursor: pointer; color: #fff; font: inherit; font-size: 13.5px; font-weight: 700; white-space: nowrap;
  background: var(--ai-grad); box-shadow: 0 4px 12px rgba(99, 102, 241, .32); transition: box-shadow .15s, transform .15s;
}
.ai-fab:hover { transform: translateY(-1px); box-shadow: 0 6px 16px rgba(99, 102, 241, .45); }
.ai-fab:focus-visible { outline: 3px solid #c7d2fe; outline-offset: 2px; }
.ai-fab.on { box-shadow: 0 0 0 3px rgba(99, 102, 241, .22), 0 4px 12px rgba(99, 102, 241, .32); }
.ai-fab-ic { position: relative; display: grid; place-items: center; }
.ai-fab-ic .icon { width: 17px; height: 17px; }
.ai-fab-ring { position: absolute; inset: -4px; border-radius: 50%; border: 2px solid transparent; pointer-events: none; }
.ai-fab.busy .ai-fab-ring { border-top-color: #fff; border-inline-end-color: rgba(255, 255, 255, .6); animation: ai-spin .9s linear infinite; }
.ai-fab-dot { position: absolute; top: -3px; inset-inline-end: -2px; width: 12px; height: 12px; border-radius: 50%; background: #f43f5e; border: 2px solid #fff; display: none; }
.ai-fab.unread .ai-fab-dot { display: block; }

/* النافذة: تحت الشريط العلوي على اليسار، فتبقى القائمة الجانبية متاحة للتنقل والنافذة مفتوحة.
   تحت النوافذ المنبثقة (900): نافذة تأكيد من المساعد تظهر فوقه */
.ai-dock { position: fixed; z-index: 850; top: calc(var(--topbar-h) + 8px); inset-inline-end: 18px; }
.ai-panel {
  position: absolute; top: 0; inset-inline-end: 0; width: 450px; height: min(720px, calc(100vh - var(--topbar-h) - 24px));
  background: var(--surface); border-radius: 20px; display: flex; flex-direction: column; overflow: hidden;
  box-shadow: 0 30px 80px rgba(15, 23, 42, .3), 0 0 0 1px rgba(15, 23, 42, .06); transform-origin: top left;
  animation: ai-drop .22s cubic-bezier(.2, .9, .3, 1.15);
}
@keyframes ai-drop { from { opacity: 0; transform: translateY(-10px) scale(.97); } to { opacity: 1; transform: none; } }
.ai-panel[hidden] { display: none; }
.ai-panel-head { position: relative; display: flex; align-items: center; gap: 10px; padding: 12px 12px 12px 10px; color: #fff; background: var(--ai-grad); }
.ai-panel-head::after { content: ''; position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(circle at 15% -40%, rgba(255, 255, 255, .35), transparent 55%), radial-gradient(circle at 95% 140%, rgba(255, 255, 255, .18), transparent 50%); }
.ai-panel-titles { min-width: 0; }
.ai-panel-title { font-weight: 800; font-size: 15.5px; letter-spacing: .2px; }
.ai-panel-sub { display: flex; align-items: center; gap: 8px; font-size: 12px; opacity: .95; min-width: 0; }
.ai-sub-co { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ai-panel-sub .ai-mode { background: rgba(255, 255, 255, .2); color: #fff; }
.ai-head-btns { margin-inline-start: auto; display: flex; gap: 1px; position: relative; z-index: 1; }
.ai-head-btn { width: 32px; height: 32px; border-radius: 9px; border: 0; background: transparent; color: #fff; cursor: pointer; display: grid; place-items: center; }
.ai-head-btn:hover { background: rgba(255, 255, 255, .2); }
.ai-head-btn .icon { width: 17px; height: 17px; }
.ai-panel-body { flex: 1; min-height: 0; display: flex; }
.ai-panel-body > .ai-chat { flex: 1; }
.ai-orb { width: 56px; height: 56px; border-radius: 50%; display: grid; place-items: center; color: #fff; background: var(--ai-grad);
  box-shadow: 0 10px 26px rgba(99, 102, 241, .4), inset 0 0 0 1px rgba(255, 255, 255, .25); flex-shrink: 0; }
.ai-orb.sm { width: 36px; height: 36px; background: rgba(255, 255, 255, .2); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .4); position: relative; z-index: 1; }
.ai-orb.sm .icon { width: 19px; height: 19px; }
.ai-orb.dim { filter: grayscale(.7); opacity: .65; }
.ai-history { position: absolute; top: 60px; inset-inline-end: 10px; width: 310px; max-height: 380px; overflow-y: auto; z-index: 5;
  background: #fff; border-radius: 14px; padding: 6px; box-shadow: 0 18px 45px rgba(15, 23, 42, .28); animation: ai-pop .16s ease-out; }
.ai-history[hidden] { display: none; }
.ai-history-item { display: flex; justify-content: space-between; align-items: center; gap: 10px; width: 100%; border: 0; background: none;
  padding: 8px 10px; border-radius: 9px; cursor: pointer; font: inherit; text-align: start; color: var(--text); }
.ai-history-item:hover, .ai-history-item.on { background: var(--ai-soft); }
.ai-history-title { display: flex; align-items: center; gap: 4px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13.5px; }
.ai-history-title .icon { width: 13px; height: 13px; color: #7c3aed; }
.ai-history-when { color: var(--muted); font-size: 11.5px; white-space: nowrap; }
.ai-history-all { display: block; text-align: center; padding: 9px; font-size: 13px; font-weight: 600; border-top: 1px solid var(--border); margin-top: 4px; }
.ai-history-empty { padding: 14px; color: var(--muted); text-align: center; font-size: 13px; }

/* المحادثة */
.ai-chat { position: relative; display: flex; flex-direction: column; min-height: 0; background: linear-gradient(180deg, #fbfbff 0%, #f5f7fb 100%); }
.ai-chat.drop::after { content: 'أفلت الصورة أو الملف هنا'; position: absolute; inset: 8px; z-index: 3; display: grid; place-items: center;
  border: 2px dashed var(--ai-2); border-radius: 16px; background: rgba(238, 242, 255, .9); color: var(--ai-2); font-weight: 800; font-size: 15px; }
.ai-scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 16px 14px 10px; scrollbar-width: thin; }
.ai-list { display: flex; flex-direction: column; gap: 14px; }
.ai-msg { display: flex; gap: 9px; align-items: flex-start; }
.ai-msg.fresh { animation: ai-in .25s ease-out; }
.ai-msg.user { justify-content: flex-end; }
.ai-msg.user .ai-bubble { max-width: 86%; padding: 9px 13px; border-radius: 16px; border-end-end-radius: 5px; color: #fff; background: var(--ai-grad);
  box-shadow: 0 6px 16px rgba(99, 102, 241, .25); }
.ai-user-text { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.65; }
.ai-user-ctx { display: flex; align-items: center; gap: 4px; margin-top: 5px; font-size: 11.5px; opacity: .85; }
.ai-user-ctx .icon { width: 12px; height: 12px; }
.ai-avatar { width: 30px; height: 30px; border-radius: 50%; flex-shrink: 0; display: grid; place-items: center; color: #fff; background: var(--ai-grad);
  box-shadow: 0 4px 12px rgba(99, 102, 241, .35); }
.ai-avatar .icon { width: 16px; height: 16px; }
.ai-msg.ai .ai-bubble { flex: 1; min-width: 0; padding: 11px 14px; border-radius: 16px; border-start-start-radius: 5px; background: #fff;
  border: 1px solid #e8e9f5; box-shadow: 0 2px 12px rgba(15, 23, 42, .05); }
.ai-msg.ai.error .ai-avatar { background: var(--danger); box-shadow: none; }
.ai-text { line-height: 1.8; }
.ai-text:empty { display: none; }
.ai-live { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 700; margin-bottom: 4px; }
.ai-live[hidden] { display: none; }
.ai-live-text { background: linear-gradient(90deg, var(--ai-2), var(--ai-3), var(--ai-1), var(--ai-2)); background-size: 300% 100%;
  -webkit-background-clip: text; background-clip: text; color: transparent; animation: ai-shimmer 2.6s linear infinite; }
.ai-spinner { width: 15px; height: 15px; border-radius: 50%; border: 2px solid rgba(99, 102, 241, .22); border-top-color: var(--ai-2);
  animation: ai-spin .8s linear infinite; flex-shrink: 0; display: inline-block; }
.ai-steps-box { margin-bottom: 8px; font-size: 12.8px; }
.ai-steps-box[hidden] { display: none; }
.ai-steps-box summary { cursor: pointer; color: #64748b; font-weight: 600; list-style: none; display: flex; align-items: center; gap: 6px; user-select: none; }
.ai-steps-box summary::-webkit-details-marker { display: none; }
.ai-steps-box summary::before { content: '◂'; font-size: 11px; transition: transform .15s; display: inline-block; }
.ai-steps-box[open] summary::before { transform: rotate(-90deg); }
.ai-steps { list-style: none; margin: 6px 0 0; padding: 0; padding-inline-start: 10px; border-inline-start: 2px solid #e5e7f5; display: flex; flex-direction: column; gap: 5px; }
.ai-steps li { color: #475569; line-height: 1.55; animation: ai-in .2s ease-out; }
.ai-step-ic { display: inline-grid; place-items: center; width: 15px; height: 15px; vertical-align: -3px; margin-inline-end: 6px; border-radius: 50%; font-size: 9.5px; font-weight: 900; }
.ai-steps li.run .ai-step-ic { border: 2px solid rgba(99, 102, 241, .22); border-top-color: var(--ai-2); animation: ai-spin .8s linear infinite; }
.ai-steps li.ok .ai-step-ic { background: #dcfce7; color: #16a34a; }
.ai-steps li.ok .ai-step-ic::before { content: '✓'; }
.ai-steps li.bad .ai-step-ic { background: #fee2e2; color: #dc2626; }
.ai-steps li.bad .ai-step-ic::before { content: '✕'; }
.ai-steps li.k-write .ai-step-label { color: #6d28d9; font-weight: 700; }
.ai-steps li.k-memory .ai-step-label { color: #7c3aed; }
.ai-step-args { color: #94a3b8; }
.ai-step-args code { font-size: 11px; }
.ai-step-err { color: var(--danger); font-size: 12px; margin-top: 1px; }
.ai-step-note { color: #16a34a; font-size: 12px; margin-top: 1px; }
.ai-cards { display: flex; flex-direction: column; gap: 8px; margin: 2px 0 10px; }
.ai-cards:empty { display: none; }
.ai-card { position: relative; overflow: hidden; display: flex; flex-wrap: wrap; align-items: flex-start; gap: 10px; padding: 10px 12px 10px 12px;
  padding-inline-start: 15px; border-radius: 13px; border: 1px solid #ddd6fe; background: linear-gradient(135deg, #faf5ff 0%, #eef2ff 100%); }
.ai-card::before { content: ''; position: absolute; inset-inline-start: 0; top: 0; bottom: 0; width: 4px; background: var(--ai-grad); }
.ai-card.fresh { animation: ai-card-in .38s cubic-bezier(.2, .9, .3, 1.3); }
.ai-card.fresh.s-done::after { content: ''; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(105deg, transparent 35%, rgba(255, 255, 255, .85) 50%, transparent 65%); animation: ai-sweep 1.2s .2s ease-out both; }
.ai-card.s-done { border-color: #bbf7d0; background: linear-gradient(135deg, #f0fdf4 0%, #ecfeff 100%); }
.ai-card.s-done::before { background: linear-gradient(180deg, #22c55e, #0ea5b7); }
.ai-card.s-proposed { border-color: #fde68a; background: linear-gradient(135deg, #fffbeb 0%, #fff7ed 100%); }
.ai-card.s-proposed::before { background: linear-gradient(180deg, #f59e0b, #f97316); }
.ai-card.s-undone { border-color: var(--border); background: #f8fafc; }
.ai-card.s-undone::before { background: #cbd5e1; }
.ai-card.s-undone .ai-card-sum { text-decoration: line-through; color: var(--muted); }
.ai-card.s-rejected { border-color: #fecaca; background: #fff; opacity: .75; }
.ai-card.s-rejected::before { background: #fca5a5; }
.ai-card-ic { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: #fff; color: var(--ai-2);
  box-shadow: 0 2px 8px rgba(15, 23, 42, .08); flex-shrink: 0; }
.ai-card.s-done .ai-card-ic { color: #16a34a; }
.ai-card.s-proposed .ai-card-ic { color: #d97706; }
.ai-card-main { flex: 1; min-width: 180px; }
.ai-card-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 13.5px; }
.ai-card-no { margin-inline-start: auto; color: #94a3b8; font-size: 11.5px; font-variant-numeric: tabular-nums; }
.ai-card-sum { margin-top: 3px; font-size: 13.3px; line-height: 1.65; color: #1e293b; overflow-wrap: anywhere; }
.ai-card-note { margin-top: 2px; font-size: 12px; color: var(--muted); }
.ai-card-btns { display: flex; flex-wrap: wrap; gap: 6px; align-self: center; }
.ai-card-btns .btn { background: rgba(255, 255, 255, .85); }
.ai-card-btns .btn-primary { background: var(--primary); }
.ai-meta { display: flex; align-items: center; gap: 6px; margin-top: 8px; font-size: 11.5px; color: #94a3b8; }
.ai-meta:empty { display: none; }
.ai-meta .grow { flex: 1; }
.ai-mini { width: 27px; height: 27px; border: 0; border-radius: 8px; background: transparent; color: var(--muted); cursor: pointer; display: grid; place-items: center; }
.ai-mini:hover { background: #eef2f6; color: var(--text); }
.ai-mini.danger:hover { background: var(--danger-soft); color: var(--danger); }
.ai-mini .icon { width: 15px; height: 15px; }
.ai-extra:empty { display: none; }
.ai-error { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-top: 6px; padding: 8px 10px; border-radius: 10px; font-size: 13px;
  color: #991b1b; background: #fef2f2; border: 1px solid #fecaca; }
.ai-error > span { flex: 1; min-width: 180px; }
.ai-stopped { display: flex; align-items: center; gap: 6px; margin-top: 6px; font-size: 12.5px; color: var(--muted); }
.ai-stopped .icon { width: 13px; height: 13px; }
/* النموذج المختار مشغول أو لا يرد فأكمل غيره */
.ai-notices:empty { display: none; }
.ai-notices { display: flex; flex-direction: column; gap: 4px; margin-bottom: 6px; }
.ai-notice { display: flex; align-items: flex-start; gap: 6px; padding: 5px 9px; border-radius: 8px; font-size: 12px; line-height: 1.6;
  color: #92400e; background: #fffbeb; border: 1px solid #fde68a; }
.ai-notice .icon { width: 13px; height: 13px; flex-shrink: 0; margin-top: 3px; }
.ai-note { align-self: center; display: flex; align-items: center; gap: 6px; max-width: 94%; padding: 5px 12px; border-radius: 999px;
  font-size: 12px; color: #4338ca; background: #eef2ff; border: 1px solid #e0e7ff; }
.ai-note .icon { width: 14px; height: 14px; flex-shrink: 0; }
.ai-empty { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 24px 6px 8px; text-align: center; }
.ai-empty .ai-orb { width: 66px; height: 66px; animation: ai-float 4s ease-in-out infinite; }
.ai-empty .ai-orb .icon { width: 31px; height: 31px; }
.ai-empty h3 { margin: 8px 0 0; font-size: 19px; background: var(--ai-grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.ai-empty p { max-width: 470px; margin: 2px 0 6px; color: var(--muted); font-size: 13.3px; line-height: 1.75; }
.ai-chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 7px; margin-top: 4px; }
.ai-chip { display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border: 1px solid #e0e7ff; border-radius: 999px; background: #fff;
  color: #334155; font: inherit; font-size: 12.8px; cursor: pointer; text-align: start; transition: border-color .15s, color .15s, transform .15s, box-shadow .15s; }
.ai-chip:hover { border-color: var(--ai-2); color: var(--ai-2); transform: translateY(-1px); box-shadow: 0 5px 14px rgba(99, 102, 241, .16); }
.ai-chip .icon { width: 14px; height: 14px; color: var(--ai-2); }
.ai-chip.do { border-color: #fde68a; background: #fffdf5; }
.ai-chip.do .icon { color: #f59e0b; }
.ai-tip { display: flex; align-items: center; gap: 6px; margin-top: 12px; font-size: 12px; color: var(--muted); }
.ai-tip .icon { width: 14px; height: 14px; }
.ai-composer { padding: 8px 12px 10px; border-top: 1px solid #eceef6; background: rgba(255, 255, 255, .94); }
.ai-composer-top { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 6px; }
.ai-composer-top:not(:has(> :not([hidden]))) { display: none; }
.ai-ctx { display: inline-flex; align-items: center; gap: 5px; max-width: 100%; padding: 3px 10px; border: 1px dashed #c7d2fe; border-radius: 999px;
  background: #eef2ff; color: #4338ca; font: inherit; font-size: 12px; cursor: pointer; }
.ai-ctx[hidden] { display: none; }
.ai-ctx span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ai-ctx .icon { width: 13px; height: 13px; flex-shrink: 0; }
.ai-ctx.off { background: #f8fafc; border-color: var(--border); color: var(--muted); }
.ai-ctx.off span { text-decoration: line-through; }
.ai-box { display: flex; align-items: flex-end; gap: 3px; padding: 5px; background: #fff; border: 1.5px solid #e0e7ff; border-radius: 17px;
  transition: border-color .15s, box-shadow .15s; }
.ai-box:focus-within { border-color: var(--ai-2); box-shadow: 0 0 0 4px rgba(99, 102, 241, .12); }
.ai-composer.off .ai-box { opacity: .55; }
.ai-composer.off .ai-send { box-shadow: none; filter: grayscale(.6); }
.ai-input { flex: 1; min-width: 0; max-height: 220px; padding: 7px 6px; border: 0; outline: 0; resize: none; background: transparent;
  font: inherit; font-size: 14px; line-height: 1.6; color: var(--text); }
.ai-input:placeholder-shown { direction: rtl; unicode-bidi: isolate; }   /* فارغ: النص الإرشادي والمؤشر من اليمين؛ ومع الكتابة يتبع dir=auto اتجاه النص */
.ai-tool-btn { width: 36px; height: 36px; flex-shrink: 0; display: grid; place-items: center; border: 0; border-radius: 11px; background: transparent;
  color: #64748b; cursor: pointer; }
.ai-tool-btn:hover { background: #f1f5f9; color: var(--ai-2); }
.ai-mic.on { color: #fff; background: #ef4444; animation: ai-pulse 1.2s ease-in-out infinite; }
.ai-send { width: 38px; height: 38px; flex-shrink: 0; display: grid; place-items: center; border: 0; border-radius: 12px; color: #fff; cursor: pointer;
  background: var(--ai-grad); box-shadow: 0 5px 14px rgba(99, 102, 241, .35); transition: transform .12s; }
.ai-send:hover { transform: scale(1.06); }
.ai-send .icon { width: 18px; height: 18px; }
.ai-send:not(.stop) .icon { transform: scaleX(-1); }
.ai-send.stop { background: #0f172a; box-shadow: none; }
.ai-hint { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 4px; margin-top: 6px; font-size: 11.3px; color: #94a3b8; }
.ai-mode { display: inline-flex; align-items: center; gap: 4px; padding: 1px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 700; white-space: nowrap; }
.ai-mode .icon { width: 12px; height: 12px; }
.ai-mode.m-auto { background: #dcfce7; color: #15803d; }
.ai-mode.m-confirm { background: #fef3c7; color: #b45309; }
.ai-mode.m-off { background: #e2e8f0; color: #475569; }
.ai-files { display: flex; flex-wrap: wrap; gap: 6px; }
.ai-files[hidden] { display: none; }
.ai-file { display: inline-flex; align-items: center; gap: 6px; max-width: 220px; padding: 3px; padding-inline-end: 8px; border: 1px solid #e2e8f0;
  border-radius: 10px; background: #fff; font-size: 12px; }
.ai-file img { width: 34px; height: 34px; object-fit: cover; border-radius: 7px; }
.ai-file-ic { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 7px; background: #eef2ff; color: var(--ai-2); }
.ai-file-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ai-file-x { width: 20px; height: 20px; display: grid; place-items: center; border: 0; border-radius: 50%; background: transparent; color: var(--muted); cursor: pointer; }
.ai-file-x:hover { background: var(--danger-soft); color: var(--danger); }
.ai-file-x .icon { width: 13px; height: 13px; }
.ai-files.in-msg { margin-bottom: 6px; }
.ai-files.in-msg .ai-file { background: rgba(255, 255, 255, .16); border-color: rgba(255, 255, 255, .35); color: #fff; }
.ai-files.in-msg .ai-file img { width: 72px; height: 72px; }
.ai-files.in-msg .ai-file-ic { background: rgba(255, 255, 255, .2); color: #fff; }

/* قسم الذكاء الاصطناعي */
.ai-state { display: inline-flex; align-items: center; gap: 7px; padding: 5px 11px; border-radius: 999px; font-size: 12.5px; font-weight: 700; background: #f1f5f9; color: #475569; }
.ai-state i { width: 8px; height: 8px; border-radius: 50%; background: #94a3b8; }
.ai-state.on { background: #dcfce7; color: #166534; }
.ai-state.on i { background: #22c55e; animation: ai-dot 2s infinite; }
.ai-state.off { background: #fef3c7; color: #92400e; }
.ai-state.off i { background: #f59e0b; }
.ai-page-grid { display: grid; grid-template-columns: 310px minmax(0, 1fr); gap: 14px; height: calc(100vh - 335px); min-height: 460px; }
.ai-convs { display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.ai-convs-head { display: flex; flex-direction: column; gap: 8px; padding: 10px; border-bottom: 1px solid var(--border); }
.ai-conv-list { flex: 1; overflow-y: auto; padding: 6px; scrollbar-width: thin; }
.ai-conv { position: relative; padding: 9px 10px; border: 1px solid transparent; border-radius: 11px; cursor: pointer; outline: none; }
.ai-conv:hover, .ai-conv:focus-visible { background: #f8fafc; }
.ai-conv.on { background: var(--ai-soft); border-color: #ddd6fe; }
.ai-conv-title { display: flex; align-items: center; gap: 4px; font-weight: 700; font-size: 13.5px; padding-inline-end: 4px; }
.ai-conv-title span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ai-conv-title .icon { width: 13px; height: 13px; color: #7c3aed; flex-shrink: 0; }
.ai-conv-snippet { margin-top: 2px; font-size: 12.3px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.ai-conv-meta { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; font-size: 11.5px; color: #94a3b8; }
.ai-conv-acts { display: inline-flex; align-items: center; gap: 2px; color: #7c3aed; font-weight: 600; }
.ai-conv-acts .icon { width: 11px; height: 11px; }
.ai-conv-tools { position: absolute; top: 5px; inset-inline-end: 5px; display: none; gap: 1px; padding: 2px; border-radius: 9px; background: #fff; box-shadow: 0 2px 8px rgba(15, 23, 42, .12); }
.ai-conv:hover .ai-conv-tools, .ai-conv:focus-within .ai-conv-tools { display: flex; }
.ai-conv:hover .ai-conv-title, .ai-conv:focus-within .ai-conv-title { padding-inline-end: 90px; } /* العنوان يُختصر ولا تغطيه الأزرار */
.ai-conv-empty { padding: 30px 10px; text-align: center; color: var(--muted); font-size: 13px; }
.ai-page-main { display: flex; min-height: 0; overflow: hidden; }
.ai-page-main > .ai-chat { flex: 1; }
.ai-v-page .ai-scroll { padding: 20px 24px 10px; }
.ai-v-page .ai-list, .ai-v-page .ai-box, .ai-v-page .ai-composer-top, .ai-v-page .ai-hint { width: 100%; max-width: 920px; margin-inline: auto; }
.ai-v-page .ai-composer { padding: 10px 24px 12px; }
.ai-modes { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px; }
.ai-mode-card { padding: 12px; border: 1.5px solid var(--border); border-radius: 13px; background: #fff; font: inherit; text-align: start; cursor: pointer;
  transition: border-color .15s, background .15s, box-shadow .15s; color: var(--text); }
.ai-mode-card:hover { border-color: #c7d2fe; }
.ai-mode-card.on { border-color: var(--ai-2); background: var(--ai-soft); box-shadow: 0 0 0 3px rgba(99, 102, 241, .12); }
.ai-mode-card-head { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; }
.ai-mode-card-head .icon { color: var(--ai-2); }
.ai-mode-card-text { font-size: 12.8px; line-height: 1.65; color: var(--muted); }
.ai-mem-add { display: flex; align-items: flex-start; gap: 8px; }
.ai-mem-add textarea { flex: 1; }
.ai-mem-list { display: flex; flex-direction: column; gap: 8px; }
.ai-mem { display: flex; align-items: flex-start; gap: 10px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 11px; background: #fff; }
.ai-mem-ic { width: 32px; height: 32px; display: grid; place-items: center; flex-shrink: 0; border-radius: 9px; background: var(--ai-soft); color: #7c3aed; }
.ai-mem-main { flex: 1; min-width: 0; }
.ai-mem-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.ai-mem-meta { margin-top: 3px; font-size: 11.5px; color: var(--muted); }
.ai-mem-btns { display: flex; gap: 2px; }
.ai-struck { text-decoration: line-through; color: var(--muted); }
/* سجل أخطاء الذكاء الاصطناعي وتشخيص الاتصال */
.ai-log-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 12px; }
.ai-log-tools input[type=search] { flex: 1; min-width: 200px; }
.ai-log-tools .ai-log-source { width: auto; min-width: 150px; }
.ai-log-list { display: flex; flex-direction: column; gap: 6px; }
.ai-log { border: 1px solid var(--border); border-inline-start: 3px solid var(--border-strong); border-radius: 10px; background: #fff; }
.ai-log.lv-error { border-inline-start-color: var(--danger); }
.ai-log.lv-warning { border-inline-start-color: var(--warning); }
.ai-log.lv-info { border-inline-start-color: var(--success); }
.ai-log.focus { box-shadow: 0 0 0 3px rgba(220, 38, 38, .14); }
.ai-log > summary { display: flex; align-items: center; gap: 8px; padding: 9px 12px; cursor: pointer; list-style: none; font-size: 13px; }
.ai-log > summary::-webkit-details-marker { display: none; }
.ai-log > summary:hover { background: #f8fafc; border-radius: 10px; }
.ai-log-when, .ai-log-src { color: var(--muted); font-size: 12px; white-space: nowrap; }
.ai-log-when { min-width: 74px; }
.ai-log-msg { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ai-log[open] .ai-log-msg { white-space: normal; }
.ai-log-code { padding: 1px 6px; border-radius: 6px; background: #f1f5f9; color: #475569; font-size: 11px; white-space: nowrap; }
.ai-log-body { padding: 2px 12px 12px; border-top: 1px dashed var(--border); }
.ai-log-detail { margin: 10px 0 0; padding: 10px 12px; max-height: 320px; overflow: auto; border-radius: 8px; background: #0f172a; color: #e2e8f0;
  font-size: 12px; line-height: 1.6; white-space: pre-wrap; overflow-wrap: anywhere; text-align: left; }
.ai-log-data { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 4px 14px; margin: 10px 0 0; font-size: 12.5px; }
.ai-log-data dt { color: var(--muted); }
.ai-log-data dd { margin: 0; overflow-wrap: anywhere; }
.ai-log-data.env { padding-top: 8px; border-top: 1px dashed var(--border); }
.ai-log-foot { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-top: 10px; font-size: 12px; }
.ai-log-foot .grow { flex: 1; }
.ai-kpi-bad .value { color: var(--danger); }
.ai-diag-wait { display: flex; align-items: center; gap: 8px; padding: 8px 0; color: var(--muted); }
.ai-diag-steps { display: flex; flex-direction: column; gap: 9px; margin: 12px 0 0; padding: 0; list-style: none; }
.ai-diag-steps li { display: flex; align-items: flex-start; gap: 10px; }
.ai-diag-ic { width: 24px; height: 24px; flex-shrink: 0; display: grid; place-items: center; border-radius: 50%; background: #e2e8f0; color: var(--muted); }
.ai-diag-ic .icon { width: 14px; height: 14px; }
.st-ok .ai-diag-ic { background: var(--success-soft); color: var(--success); }
.st-fail .ai-diag-ic { background: var(--danger-soft); color: var(--danger); }
.ai-diag-main { flex: 1; min-width: 0; font-size: 13px; }
.ai-diag-label { display: flex; align-items: baseline; flex-wrap: wrap; gap: 8px; }
.st-skip .ai-diag-label b { color: var(--muted); font-weight: 600; }
.ai-diag-ms { color: var(--muted); font-size: 11.5px; }
.ai-diag-msg { margin-top: 2px; color: var(--danger); }
.ai-diag-detail { margin-top: 2px; color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.ai-diag .ai-log-data.env { margin-top: 12px; }
.ai-test-detail { display: block; margin-top: 6px; padding: 6px 8px; border-radius: 6px; background: rgba(255, 255, 255, .65); font-size: 12px;
  white-space: pre-wrap; overflow-wrap: anywhere; text-align: left; }
.ai-test-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.ai-test-working { margin-top: 8px; font-weight: 700; color: var(--success); }
.ai-diag .ai-test-actions { margin: 0 0 4px; }
.ai-diag-models { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0 0; padding: 0; list-style: none; }
.ai-diag-models li { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px 3px 7px; border-radius: 999px; font-size: 11.5px;
  border: 1px solid var(--border); background: #f8fafc; color: var(--muted); }
.ai-diag-models li code { font-size: 11.5px; color: var(--text); }
.ai-diag-models li .icon { width: 12px; height: 12px; }
.ai-diag-models li.ok { border-color: #bbf7d0; background: var(--success-soft); color: #166534; }
.ai-diag-models li.ok .icon { color: var(--success); }
.ai-diag-models li.bad .icon { color: var(--danger); }
@media (max-width: 640px) {
  .ai-log > summary { flex-wrap: wrap; }
  .ai-log-msg { flex-basis: 100%; white-space: normal; }
  .ai-log-data { grid-template-columns: 1fr; }
}
@media (max-width: 1000px) {
  .ai-page-grid { grid-template-columns: 1fr; height: auto; }
  .ai-convs { max-height: 280px; }
  .ai-page-main { height: calc(100vh - 120px); min-height: 460px; }
}
@media (max-width: 640px) {
  .ai-panel { position: fixed; inset: 0; width: auto; height: auto; border-radius: 0; animation: none; }
  .ai-fab { padding: 0 9px; }
  .ai-fab-text { display: none; }
  .ai-v-page .ai-scroll, .ai-v-page .ai-composer { padding-inline: 10px; }
}
@media (prefers-reduced-motion: reduce) {
  .ai-fab.busy .ai-fab-ring, .ai-empty .ai-orb, .ai-live-text, .ai-panel, .ai-msg, .ai-card.fresh, .ai-card.fresh::after { animation: none !important; }
}
@media print { .ai-dock { display: none !important; } .ai-composer, .ai-meta, .ai-avatar, .ai-convs, .ai-card-btns { display: none !important; } }

/* نص الأجوبة (Markdown) */
.md { line-height: 1.75; overflow-wrap: anywhere; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 8px; }
.md h4 { font-size: 15.5px; margin: 14px 0 6px; }
.md h5 { font-size: 14.5px; margin: 12px 0 4px; }
.md ul, .md ol { margin: 0 0 8px; padding-inline-start: 22px; }
.md li { margin: 2px 0; }
.md code { padding: 1px 5px; border-radius: 5px; background: #f1f5f9; font-family: Consolas, "Courier New", monospace; font-size: 12.8px; unicode-bidi: isolate; }
.md pre { margin: 0 0 8px; padding: 10px 12px; border-radius: 8px; background: #0f172a; color: #e2e8f0; overflow-x: auto; text-align: left; }
.md pre code { padding: 0; background: none; color: inherit; }
.md blockquote { margin: 0 0 8px; padding: 2px 12px; border-inline-start: 3px solid var(--border-strong); color: var(--muted); }
.md hr { border: 0; border-top: 1px solid var(--border); margin: 12px 0; }
.md .table-wrap { margin: 6px 0 10px; border: 1px solid var(--border); border-radius: 8px; }
.md .tbl { font-size: 13px; }
.md .tbl th { white-space: normal; }
