/* ============================================================
   أفق ERP — نظام التصميم الموحد (RTL، خط Cairo، بدون أيقونات)
   ============================================================ */
:root {
  --navy: #163a5f;
  --navy-dark: #0f2a46;
  --navy-darker: #0b1f33;
  --accent: #c9a227;
  --bg: #f0f3f8;
  --card: #ffffff;
  --border: #dbe2ec;
  --text: #1c2b3a;
  --muted: #67778c;
  --success: #1e7d4f;
  --success-bg: #e2f3ea;
  --danger: #b23a3a;
  --danger-bg: #fbe7e7;
  --warn: #b97d10;
  --warn-bg: #fdf3df;
  --info: #2b6cb0;
  --info-bg: #e3eefb;
  --radius: 8px;
}
* { box-sizing: border-box; }
html { font-size: 15px; }
body {
  font-family: 'Cairo', 'Segoe UI', Tahoma, sans-serif;
  background: var(--bg);
  color: var(--text);
  margin: 0;
  line-height: 1.65;
}
a { color: var(--info); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0 0 .5rem 0; font-weight: 700; }
h2 { font-size: 1.25rem; color: var(--navy); }
h3 { font-size: 1.05rem; color: var(--navy); }
.muted { color: var(--muted); font-size: .9rem; }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }

/* الشريط العلوي */
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  background: linear-gradient(135deg, var(--navy-dark), var(--navy));
  color: #fff; padding: 0 14px; height: 52px;
  position: sticky; top: 0; z-index: 40;
}
.topbar-right, .topbar-left { display: flex; align-items: center; gap: 12px; }
.brand { font-size: 1.25rem; font-weight: 800; letter-spacing: .5px; }
.brand span { color: var(--accent); }
.sidebar-toggle {
  background: rgba(255,255,255,.12); color: #fff; border: none; border-radius: 6px;
  padding: 5px 12px; cursor: pointer; font-family: inherit; font-size: .85rem;
}
.sidebar-toggle:hover { background: rgba(255,255,255,.22); }
.company-switch { display: flex; align-items: center; gap: 6px; color: #dbe6f3; font-size: .85rem; }
.company-switch select { background: rgba(255,255,255,.1); color: #fff; border: 1px solid rgba(255,255,255,.3); border-radius: 6px; padding: 4px 8px; font-family: inherit; }
.company-switch select option { color: #1c2b3a; }
.current-company { font-size: .9rem; color: #dbe6f3; }
.user-box { display: flex; align-items: center; gap: 10px; }
.user-name { font-size: .88rem; }

/* شعار الديمو */
.demo-banner {
  background: var(--warn-bg); color: #7a5205; text-align: center;
  padding: 7px 12px; font-weight: 700; font-size: .92rem; border-bottom: 2px solid var(--accent);
  display: flex; justify-content: center; gap: 14px; align-items: center;
}
.demo-exit { color: var(--danger); font-weight: 700; background: #fff; padding: 2px 12px; border-radius: 6px; border: 1px solid var(--danger); }

/* الهيكل */
.app-shell { display: flex; min-height: calc(100vh - 52px - 34px); }
.content { flex: 1; padding: 18px 22px; min-width: 0; }
.content-full { padding-top: 24px; }

/* القائمة الجانبية */
.sidebar {
  width: 250px; background: var(--navy-darker); color: #c6d3e3;
  padding: 0 0 40px 0; flex-shrink: 0; transition: width .18s ease;
}
.sidebar-user { padding: 14px 16px; border-bottom: 1px solid rgba(255,255,255,.08); }
.su-name { font-weight: 700; color: #fff; font-size: .95rem; }
.su-company { font-size: .8rem; color: #8fa3bd; }
.menu-group { border-bottom: 1px solid rgba(255,255,255,.06); }
.menu-group-head {
  width: 100%; text-align: right; background: none; border: none; color: #d5e0ef;
  padding: 11px 16px; font-family: inherit; font-size: .95rem; font-weight: 700; cursor: pointer;
  display: flex; justify-content: space-between; align-items: center;
}
.menu-group-head:hover { background: rgba(255,255,255,.06); }
.menu-arrow { font-size: .8rem; transition: transform .15s; color: var(--accent); }
.menu-group.open .menu-arrow { transform: rotate(180deg); }
.menu-items { display: none; padding: 2px 0 8px 0; }
.menu-group.open .menu-items, .menu-group.active .menu-items { display: block; }
.menu-item {
  display: block; padding: 7px 26px; color: #b9c7d9; font-size: .88rem;
  border-right: 3px solid transparent;
}
.menu-item:hover { color: #fff; background: rgba(255,255,255,.05); text-decoration: none; }
.menu-item.current { color: #fff; background: rgba(201,162,39,.15); border-right-color: var(--accent); }
body.sidebar-collapsed .sidebar { width: 0; overflow: hidden; padding: 0; }

/* البطاقات */
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  margin-bottom: 16px; box-shadow: 0 1px 3px rgba(16,42,70,.06);
}
.card-head {
  padding: 12px 16px; border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px;
}
.card-head h3 { margin: 0; }
.card-body { padding: 14px 16px; }
.card-body.p0 { padding: 0; }

/* شريط الأدوات والفلاتر */
.page-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; flex-wrap: wrap; gap: 10px; }
.breadcrumbs { font-size: .82rem; color: var(--muted); margin-bottom: 4px; }
.breadcrumbs a { color: var(--info); }
.list-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; flex-wrap: wrap; gap: 8px; }
.list-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.list-total { font-size: .85rem; color: var(--muted); }
.filter-bar {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end;
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 12px; margin-bottom: 12px;
}
.filter-item { display: flex; flex-direction: column; gap: 3px; }
.filter-item label { font-size: .78rem; color: var(--muted); font-weight: 700; }
.filter-search input { min-width: 220px; }
.filter-submit { flex-direction: row; gap: 6px; align-items: center; }

/* النماذج */
label.f { display: block; font-size: .82rem; font-weight: 700; color: #384c63; margin-bottom: 4px; }
label.f .req { color: var(--danger); }
input[type=text], input[type=number], input[type=date], input[type=email], input[type=password], input[type=search], select, textarea {
  font-family: inherit; font-size: .92rem; padding: 7px 10px;
  border: 1px solid #b9c6d8; border-radius: 6px; background: #fff; color: var(--text); width: 100%;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--navy); box-shadow: 0 0 0 2px rgba(22,58,95,.12); }
input[type=checkbox] { width: auto; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.form-grid-3 { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
.form-actions { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.inline-form { display: inline; }
.att-form { margin-top: 10px; }
.att-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.att-row input[type=file] { flex: 1; min-width: 200px; }
.att-row input[type=text] { flex: 1; min-width: 160px; }

/* الأزرار */
.btn {
  display: inline-block; font-family: inherit; font-size: .9rem; font-weight: 700;
  padding: 7px 16px; border-radius: 6px; border: 1px solid transparent; cursor: pointer;
  text-decoration: none; transition: all .12s; line-height: 1.4;
}
.btn:hover { text-decoration: none; filter: brightness(.94); }
.btn-primary { background: var(--navy); color: #fff; }
.btn-accent { background: var(--accent); color: #3a2c00; }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-outline { background: #fff; color: var(--navy); border-color: #b9c6d8; }
.btn-outline:hover { border-color: var(--navy); }
.btn-sm { font-size: .8rem; padding: 4px 10px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* الجداول */
.table-wrap { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: .88rem; }
table.tbl th {
  background: #eef2f8; color: var(--navy); font-weight: 700; text-align: right;
  padding: 9px 10px; border-bottom: 2px solid var(--navy); white-space: nowrap; position: sticky; top: 0;
}
table.tbl td { padding: 7px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.tbl tbody tr:hover { background: #f6f9fd; }
table.tbl .cell-num, td.cell-num { text-align: left; direction: ltr; font-variant-numeric: tabular-nums; }
table.tbl .empty-row { text-align: center; color: var(--muted); padding: 26px; }
table.tbl .col-actions { white-space: nowrap; text-align: left; width: 1%; }
table.tbl .col-actions .btn { margin: 1px 2px; }
.tbl-link { font-weight: 700; }
.sort-link { color: var(--navy); font-weight: 700; }

/* شارات الحالات */
.badge {
  display: inline-block; padding: 2px 10px; border-radius: 20px; font-size: .76rem; font-weight: 700;
}
.st-draft { background: #edf0f5; color: #5b6b80; }
.st-posted { background: var(--success-bg); color: var(--success); }
.st-paid { background: #e1f0e7; color: var(--success); }
.st-partial { background: var(--warn-bg); color: var(--warn); }
.st-void { background: var(--danger-bg); color: var(--danger); }
.st-info { background: var(--info-bg); color: var(--info); }
.st-warn { background: var(--warn-bg); color: var(--warn); }
.st-other { background: #edf0f5; color: #5b6b80; }

/* رسائل الفلاش */
.flash { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 12px; font-size: .9rem; border: 1px solid; }
.flash-title { font-weight: 700; margin-bottom: 2px; }
.flash-success { background: var(--success-bg); border-color: #9fd8b8; color: #14532d; }
.flash-error { background: var(--danger-bg); border-color: #e8a8a8; color: #7f1d1d; }
.flash-info { background: var(--info-bg); border-color: #a6c8ee; color: #1e3a5f; }
.flash-warning { background: var(--warn-bg); border-color: #ecc777; color: #713f12; }

/* لوحة القيادة */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; border-right: 4px solid var(--navy);
}
.kpi .kpi-title { font-size: .82rem; color: var(--muted); font-weight: 700; }
.kpi .kpi-value { font-size: 1.35rem; font-weight: 800; color: var(--navy); direction: ltr; text-align: right; }
.kpi .kpi-note { font-size: .75rem; color: var(--muted); }
.kpi.k-green { border-right-color: var(--success); }
.kpi.k-green .kpi-value { color: var(--success); }
.kpi.k-red { border-right-color: var(--danger); }
.kpi.k-red .kpi-value { color: var(--danger); }
.kpi.k-gold { border-right-color: var(--accent); }
.kpi.k-gold .kpi-value { color: #8a6d0b; }
.dash-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 1100px) { .dash-cols { grid-template-columns: 1fr; } }

/* الترقيم */
.pagination { display: flex; gap: 5px; margin-top: 12px; align-items: center; flex-wrap: wrap; }
.pg { padding: 5px 11px; background: #fff; border: 1px solid var(--border); border-radius: 6px; font-size: .85rem; color: var(--navy); }
.pg.active { background: var(--navy); color: #fff; border-color: var(--navy); }
.pg:hover { border-color: var(--navy); text-decoration: none; }
.pg-info { font-size: .8rem; color: var(--muted); margin-right: 8px; }

/* شبكة عرض المستندات */
.doc-head-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px 20px; }
.ig-row { display: flex; gap: 8px; font-size: .9rem; padding: 3px 0; }
.ig-l { color: var(--muted); font-weight: 700; min-width: 110px; }

/* محرر أسطر المستندات */
.lines-editor table.tbl { font-size: .85rem; }
.lines-editor input, .lines-editor select { padding: 5px 7px; font-size: .85rem; }
.lines-editor .qty-in { width: 80px; }
.lines-editor .price-in { width: 105px; }
.lines-editor .desc-in { min-width: 170px; }
.lines-editor td { padding: 4px 5px; }
.line-total-cell { font-weight: 700; direction: ltr; text-align: left; white-space: nowrap; }
.doc-totals { margin-top: 12px; display: flex; justify-content: flex-end; }
.doc-totals table { min-width: 300px; font-size: .95rem; }
.doc-totals td { padding: 5px 10px; }
.doc-totals .tt-l { color: var(--muted); font-weight: 700; }
.doc-totals .tt-v { text-align: left; direction: ltr; font-weight: 700; font-variant-numeric: tabular-nums; }
.doc-totals .grand td { font-size: 1.1rem; background: #eef2f8; border-top: 2px solid var(--navy); }

/* شجرة دليل الحسابات */
.tree { font-size: .9rem; }
.tree-node { margin: 0; padding: 0; list-style: none; }
.tree-row { display: flex; align-items: center; gap: 6px; padding: 5px 8px; border-bottom: 1px solid #eef1f6; }
.tree-row:hover { background: #f6f9fd; }
.tree-row .code { direction: ltr; font-weight: 700; color: var(--navy); min-width: 90px; font-variant-numeric: tabular-nums; }
.tree-row.group > .code { color: var(--accent); }
.tree-row .bal { margin-right: auto; direction: ltr; font-variant-numeric: tabular-nums; }
.tree-children { margin-right: 26px; padding-right: 10px; border-right: 1px dashed #c3cfdf; }

/* صفحة الخطأ */
.error-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.error-box { background: #fff; border: 1px solid var(--border); border-radius: 10px; padding: 40px 50px; text-align: center; max-width: 460px; }
.error-code { font-size: 3rem; font-weight: 800; color: var(--accent); }
.error-box h1 { color: var(--navy); }
.error-actions { display: flex; gap: 8px; justify-content: center; margin-top: 18px; }

/* تسجيل الدخول */
.login-wrap { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: linear-gradient(140deg, var(--navy-darker), var(--navy)); }
.login-box { background: #fff; border-radius: 12px; padding: 34px 38px; width: 380px; box-shadow: 0 10px 40px rgba(0,0,0,.35); }
.login-brand { text-align: center; font-size: 1.7rem; font-weight: 800; color: var(--navy); margin-bottom: 2px; }
.login-brand span { color: var(--accent); }
.login-sub { text-align: center; color: var(--muted); font-size: .85rem; margin-bottom: 22px; }
.login-box .form-group { margin-bottom: 14px; }
.login-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 18px; }

/* التذييل */
.app-footer { text-align: center; padding: 8px; color: var(--muted); font-size: .78rem; border-top: 1px solid var(--border); background: #fff; }

/* الاستجابة للشاشات */
@media (max-width: 900px) {
  .app-shell { flex-direction: column; }
  .sidebar { width: 100% !important; max-height: 300px; overflow-y: auto; }
  body.sidebar-collapsed .sidebar { display: none; }
  .content { padding: 12px; }
  .topbar { height: auto; flex-wrap: wrap; padding: 8px 12px; }
  .form-grid { grid-template-columns: 1fr; }
}
@media print {
  .topbar, .sidebar, .app-footer, .filter-bar, .list-actions, .pagination, .btn, .col-actions, .demo-banner { display: none !important; }
  body { background: #fff; }
  .content { padding: 0; }
  .card, .table-wrap { border: none; box-shadow: none; }
  table.tbl th { background: #eef2f8 !important; color: #163a5f !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* ===== إضافات النظام الموحدة ===== */
.form-grid .fg-item { display: flex; flex-direction: column; gap: 4px; }
.form-grid .fg-item label.f { font-weight: 700; font-size: .86rem; color: var(--navy); }
.form-grid .fg-item input, .form-grid .fg-item select, .form-grid .fg-item textarea {
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; font-family: inherit; font-size: .92rem;
  background: #fff; color: var(--text); width: 100%;
}
.form-grid .fg-item input:focus, .form-grid .fg-item select:focus, .form-grid .fg-item textarea:focus {
  outline: 2px solid rgba(22,58,95,.25); border-color: var(--navy);
}
.form-grid .fg-wide { grid-column: 1 / -1; }
.fg-hint { font-size: .78rem; }
.req { color: var(--danger); }
.chk { display: flex; align-items: center; gap: 6px; font-size: .9rem; padding-top: 6px; cursor: pointer; }
.chk input { width: 16px; height: 16px; accent-color: var(--navy); }
.chk-inline { display: inline-flex; margin-inline-end: 16px; padding-top: 0; }
.status-btns { display: inline-flex; gap: 6px; flex-wrap: wrap; }
.kpi-link { display: block; color: inherit; transition: transform .12s ease, box-shadow .12s ease; }
.kpi-link:hover { transform: translateY(-2px); box-shadow: 0 4px 14px rgba(15,42,70,.14); text-decoration: none; }
.hidden { display: none !important; }
.demo-mode .content::after { content: ''; }
.muted-row { background: #f6f8fb; }
.row-active { background: #eef4fb; }
.acc-tree td.acc-code { font-family: 'Cairo', monospace; direction: ltr; text-align: left; white-space: nowrap; }
.acc-tree td.acc-name { white-space: nowrap; }
.acc-tree tr.d1 td.acc-code { padding-inline-start: 10px; }
.lines-editor input, .lines-editor select {
  width: 100%; padding: 6px 8px; border: 1px solid var(--border); border-radius: 5px;
  font-family: inherit; font-size: .9rem; background: #fff;
}
.lines-editor td { vertical-align: middle; }
.lines-editor tfoot td { background: #f0f4f9; font-weight: 700; }
.cnt-input { width: 120px; padding: 6px 8px; border: 1px solid var(--border); border-radius: 5px; font-family: inherit; }
.att-form { margin-bottom: 10px; }
.att-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 6px; }
.att-row input, .att-row select { padding: 7px 9px; border: 1px solid var(--border); border-radius: 6px; font-family: inherit; }
.ig-row { margin-bottom: 4px; }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.page-head h2 { margin: 0; }
.inline-form { display: inline-block; margin: 0 2px; }
.install-body .login-box { max-width: 480px; }

/* ===== تلميحات الشرح — مرور الماوس + بديل لمسي عبر الضغط المطول ===== */
[data-tip] { position: relative; }
[data-tip]:hover::after, [data-tip].tip-open::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 6px);
  right: 50%;
  transform: translateX(50%);
  background: var(--navy-dark);
  color: #fff;
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 12px;
  line-height: 1.6;
  white-space: normal;
  width: max-content;
  max-width: 280px;
  z-index: 3000;
  pointer-events: none;
  box-shadow: 0 4px 12px rgba(11, 31, 51, .28);
  text-align: right;
}
[data-tip]:hover::before, [data-tip].tip-open::before {
  content: '';
  position: absolute;
  bottom: calc(100% + 1px);
  right: 50%;
  transform: translateX(50%);
  border: 5px solid transparent;
  border-top-color: var(--navy-dark);
  z-index: 3001;
  pointer-events: none;
}

/* إنشاء حساب المدير الأول في المُثبّت وصفحة الإنشاء الأول */
.admin-setup-title { font-weight: 700; font-size: 1.05rem; color: var(--primary, #14532d); margin: 14px 0 6px; border-top: 1px solid var(--border, #e2e8f0); padding-top: 14px; }
.pw-hint { font-size: 0.78rem; color: var(--muted, #64748b); margin-top: 4px; line-height: 1.6; }
.pw-meter { height: 6px; background: var(--border, #e2e8f0); border-radius: 4px; margin-top: 6px; overflow: hidden; }
.pw-meter-bar { height: 100%; width: 0; border-radius: 4px; transition: width .25s ease, background .25s ease; background: #dc2626; }
.pw-meter-bar.weak { background: #dc2626; }
.pw-meter-bar.ok { background: #d97706; }
.pw-meter-bar.strong { background: #16a34a; }

/* التحليلات المتقدمة — مخطط أعمدة CSS خالص بلا مكتبات خارجية */
.chart-box { display: flex; align-items: flex-end; gap: 10px; height: 180px; padding: 10px 4px 0; overflow-x: auto; }
.chart-col { flex: 1 1 0; min-width: 42px; display: flex; flex-direction: column; height: 100%; }
.chart-bars { flex: 1; display: flex; align-items: flex-end; justify-content: center; gap: 4px; }
.chart-bar { width: 14px; min-height: 2px; border-radius: 3px 3px 0 0; }
.chart-bar-sales { background: var(--primary, #166534); }
.chart-bar-purch { background: #94a3b8; }
.chart-label { text-align: center; font-size: 0.72rem; color: var(--muted, #64748b); padding-top: 6px; white-space: nowrap; }
.chart-legend { display: flex; gap: 18px; margin: 10px 4px; font-size: 0.82rem; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.legend-swatch { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.legend-sales { background: var(--primary, #166534); }
.legend-purch { background: #94a3b8; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 900px) { .two-col { grid-template-columns: 1fr; } }
.total-row { font-weight: 700; background: var(--surface-2, #f8fafc); }
