/* ============================================================
   أداة التقارير المحاسبية — الطبقة الهيكلية الأساسية (RTL عربي)
   تُحمَّل أولاً قبل theme.css — تحدد التخطيط والبنية الأساسية.
   ============================================================ */

:root {
  --bg: #f4f6fa;
  --panel: #ffffff;
  --ink: #1f2937;
  --muted: #6b7280;
  --brand: #1f4e79;
  --brand2: #2d6da3;
  --ok: #15803d;
  --bad: #b91c1c;
  --warn: #b45309;
  --line: #e2e8f0;
}

*, *::before, *::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Cairo", "Segoe UI", Tahoma, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.55;
  font-variant-numeric: tabular-nums;
}

a {
  color: var(--brand2);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

/* ---------- الترويسة (هيكل أساسي) ---------- */
header {
  background: var(--brand);
  color: #fff;
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 10px 20px;
  flex-wrap: wrap;
}
header .brand {
  font-size: 16px;
  font-weight: 700;
}
header nav {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}
header nav a {
  color: #dbeafe;
  padding: 7px 14px;
  border-radius: 8px;
  font-weight: 600;
}
header nav a:hover {
  background: rgba(255, 255, 255, 0.12);
  text-decoration: none;
}
header nav a.active {
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
}

.conn {
  margin-inline-start: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
}
.dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex: none;
}
.dot.ok { background: #4ade80; }
.dot.bad { background: #f87171; }
.conn a { color: #fde68a; }

main {
  max-width: 1560px;
  margin: 24px auto;
  padding: 0 16px;
}

/* ---------- البطاقات والشبكات ---------- */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 18px 20px;
  margin-bottom: 18px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}
.card h2 {
  margin: 0 0 12px;
  font-size: 16px;
  color: var(--brand);
}

.grid {
  display: grid;
  gap: 18px;
}
.grid.cols2 {
  grid-template-columns: 1fr 2fr;
}
@media (max-width: 900px) {
  .grid.cols2 {
    grid-template-columns: 1fr;
  }
}

/* ---------- رسائل التنبيه ---------- */
.flash {
  padding: 11px 16px;
  border-radius: 10px;
  margin-bottom: 14px;
  white-space: pre-wrap;
}
.flash.ok {
  background: #ecfdf5;
  color: #065f46;
  border: 1px solid #a7f3d0;
}
.flash.err {
  background: #fef2f2;
  color: #7f1d1d;
  border: 1px solid #fecaca;
}

/* ---------- النماذج وحقول الإدخال ---------- */
label {
  font-weight: 600;
  display: block;
  margin: 10px 0 5px;
}
input[type=text],
input[type=password],
input[type=number],
input[type=email],
input[type=date],
input[type=datetime-local],
input[type=search],
select,
textarea {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  font-family: inherit;
  font-size: 14px;
  background: var(--panel);
  color: var(--ink);
}
textarea.sql {
  font-family: Consolas, "Courier New", monospace;
  direction: ltr;
  text-align: left;
  min-height: 180px;
  font-size: 13px;
  line-height: 1.55;
  tab-size: 2;
}
form.inline {
  display: inline;
}
.hint {
  color: var(--muted);
  font-size: 12px;
  margin-top: 4px;
}

/* ---------- الأزرار ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--brand2);
  color: #fff;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px 18px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  margin-top: 8px;
  transition: background 0.15s ease, transform 0.12s ease;
}
.btn:hover {
  background: var(--brand);
  text-decoration: none;
}
.btn.small {
  padding: 4px 10px;
  font-size: 12px;
  margin-top: 0;
}
.btn.red { background: var(--bad); }
.btn.red:hover { background: #7f1d1d; }
.btn.gray { background: #64748b; }
.btn.gray:hover { background: #334155; }
.btn.green { background: var(--ok); }

/* ---------- الجداول ---------- */
table.data {
  width: 100%;
  border-collapse: collapse;
  background: var(--panel);
  font-size: 13px;
}
table.data th,
table.data td {
  border: 1px solid var(--line);
  padding: 8px 12px;
  text-align: right;
}
table.data th {
  background: #eef2f7;
  color: var(--brand);
  position: sticky;
  top: 0;
  z-index: 2;
  white-space: nowrap;
}
/* الأرقام المالية: اتجاه LTR لصياغة الرقم مع محاذاة يميناً وثبات عرض الخانات */
table.data td.r {
  direction: ltr;
  text-align: right;
  font-family: Consolas, "Courier New", monospace;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
table.data tfoot td {
  background: #f8fafc;
  font-weight: 700;
}
.scroll {
  max-height: 68vh;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
}

/* ---------- الشارات والنصوص المساعدة ---------- */
.tag {
  display: inline-block;
  background: #e0e7ff;
  color: #3730a3;
  border-radius: 99px;
  padding: 2px 10px;
  font-size: 11px;
  font-weight: 700;
}
.tag.warn { background: #fef3c7; color: #92400e; }
.tag.ok { background: #d1fae5; color: #065f46; }

.badge {
  display: inline-block;
  min-width: 26px;
  text-align: center;
  background: #eef2f7;
  color: var(--brand);
  border: 1px solid var(--line);
  border-radius: 99px;
  padding: 2px 10px;
  font-weight: 800;
}

.muted { color: var(--muted); font-size: 12px; }
.co { color: var(--muted); }
.empty { padding: 28px 16px; text-align: center; color: var(--muted); }
code.ltr { direction: ltr; unicode-bidi: embed; }

/* ---------- تسجيل الدخول ---------- */
.login-box {
  max-width: 420px;
  margin: 80px auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 34px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.08);
}
.login-box h1 {
  font-size: 20px;
  color: var(--brand);
  text-align: center;
  margin: 0 0 20px;
}

/* ---------- أشرطة الأدوات وقوائم SQL والترقيم ---------- */
.bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.sql-item {
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}
.sql-item:last-child {
  border-bottom: none;
}
.sql-item div:first-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.pager {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 14px;
  justify-content: center;
  flex-wrap: wrap;
}

/* ---------- لوحة المؤشرات — الصفحة الرئيسية ---------- */
.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  flex-wrap: wrap;
  margin: 4px 0 18px;
}
.page-head h2 {
  margin: 0 0 4px;
  font-size: 20px;
  color: var(--brand);
}
.page-head .sub {
  color: var(--muted);
  font-size: 13px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin: 14px 0 22px;
}
@media (max-width: 980px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 520px) {
  .kpi-grid { grid-template-columns: 1fr; }
}

.kpi-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px 18px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}
.kpi-card .label {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
}
.kpi-card .value {
  font-size: 24px;
  font-weight: 800;
  color: var(--brand);
  line-height: 1.25;
}
.kpi-card.warn .value { color: var(--bad); }
.kpi-card .hint { margin-top: 6px; }

.section-title {
  font-size: 14.5px;
  font-weight: 700;
  color: var(--brand);
  margin: 0 0 10px;
}

.perf-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin-bottom: 22px;
}
@media (max-width: 980px) {
  .perf-grid { grid-template-columns: 1fr; }
}
.perf-grid .card { margin-bottom: 0; }

.report-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}
@media (max-width: 980px) {
  .report-grid { grid-template-columns: 1fr; }
}
.report-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
}
.report-item .t { font-weight: 700; font-size: 13.5px; }
.report-item .d { color: var(--muted); font-size: 12px; margin-top: 2px; }

/* زر تبديل الثيم (أساسي) */
.theme-toggle {
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 8px;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
}
.theme-toggle:hover { background: rgba(255, 255, 255, 0.25); }

/* ---------- الطباعة / حفظ PDF ---------- */
@media print {
  header, .theme-toggle, .flash, form.bar, .btn, nav, .pager {
    display: none !important;
  }
  body {
    background: #fff !important;
    color: #000 !important;
  }
  main {
    max-width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
  }
  .card, .kpi-card {
    box-shadow: none !important;
    border: 1px solid #cbd5e1 !important;
    break-inside: avoid;
    page-break-inside: avoid;
  }
  .scroll {
    max-height: none !important;
    overflow: visible !important;
    border: none !important;
  }
  table.data {
    font-size: 11px;
  }
  table.data thead {
    display: table-header-group;
  }
  table.data tr {
    break-inside: avoid;
    page-break-inside: avoid;
  }
  .kpi-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  canvas {
    max-height: 200px !important;
  }
  a {
    color: #000 !important;
    text-decoration: none !important;
  }
  .page-head .sub {
    color: #444 !important;
  }
}