/* =========================================================
   التنسيقات العامة للبرنامج — نموذج (ج) شريط الموديولات
   كل الألوان هنا بس، وأي موديول يستخدم المتغيرات دي
   ========================================================= */
:root {
  /* شريط الموديولات */
  --rail-bg: #20242c;
  --rail-text: #f1f3f6;
  --rail-muted: #9aa1ae;
  --rail-hover: #2c313b;

  /* اللون الأساسي */
  --accent: #2f63d0;
  --accent-hover: #2552b3;
  --accent-text: #ffffff;
  --accent-soft: #e7eefc;

  /* الصفحة */
  --page: #f4f5f8;
  --surface: #ffffff;
  --surface-alt: #f6f7f9;
  --hover: #f2f4f7;
  --line: #e3e6ec;
  --text: #1c2230;
  --muted: #646c7d;

  /* ألوان الحالات */
  --success: #1d7a4b;  --success-soft: #e3f3ea;
  --danger: #b3321f;   --danger-soft: #f8e6e1;
  --warning: #a86a00;  --warning-soft: #fbf0d9;

  --font: "IBM Plex Sans Arabic", Tahoma, "Segoe UI", sans-serif;
  --font-display: "Readex Pro", "IBM Plex Sans Arabic", Tahoma, sans-serif;
  --font-mono: ui-monospace, Consolas, "Courier New", monospace;

  --radius: 6px;
  --rail-w: 72px;
  --panel-w: 220px;
  --topbar-h: 56px;
  color-scheme: light;
}

/* الوضع الليلي: نفس المتغيرات بقيم غامقة */
:root[data-theme="dark"] {
  --rail-bg: #14171d;
  --rail-text: #e9ecf1;
  --rail-muted: #8e96a5;
  --rail-hover: #232831;

  --accent: #5b8def;
  --accent-hover: #79a2f3;
  --accent-text: #ffffff;
  --accent-soft: #1d2b47;

  --page: #101318;
  --surface: #191d24;
  --surface-alt: #1f242c;
  --hover: #232933;
  --line: #2c323d;
  --text: #e6e9ef;
  --muted: #9aa3b2;

  --success: #4cc38a;  --success-soft: #16342a;
  --danger: #f07863;   --danger-soft: #3c201b;
  --warning: #e2b04a;  --warning-soft: #372d15;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.6;
  color: var(--text);
  background: var(--page);
}
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
svg { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

/* ---------------- الهيكل ---------------- */
.app { display: flex; height: 100%; }

.rail {
  width: var(--rail-w); flex: none;
  background: var(--rail-bg); color: var(--rail-muted);
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 12px 0; overflow-y: auto;
}
.rail-logo {
  width: 38px; height: 38px; border-radius: 9px;
  background: var(--accent); color: var(--accent-text);
  display: grid; place-items: center;
  font-family: var(--font-display); font-weight: 700; font-size: 17px;
  margin-bottom: 10px; flex: none;
}
.rail-btn {
  width: 60px; padding: 8px 0; border: 0; border-radius: 8px;
  background: none; color: var(--rail-muted);
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  font-size: 11px;
}
.rail-btn:hover { background: var(--rail-hover); color: var(--rail-text); }
a.rail-btn, a.btn { text-decoration: none; }
.rail-spacer { flex: 1; min-height: 8px; }
.rail-sep { width: 32px; height: 1px; background: var(--rail-hover); margin: 4px 0; flex: none; }
.rail-btn.is-active { background: var(--accent); color: var(--accent-text); }
.rail-btn svg { width: 20px; height: 20px; }

.panel {
  width: var(--panel-w); flex: none;
  background: var(--surface); border-left: 1px solid var(--line);
  overflow-y: auto; padding-bottom: 16px;
}
.panel-title { font-family: var(--font-display); font-size: 15px; font-weight: 600; margin: 0; padding: 18px 18px 10px; }
.panel-section { padding: 14px 18px 4px; font-size: 11.5px; font-weight: 600; color: var(--muted); letter-spacing: .02em; }
.panel-item {
  display: flex; justify-content: space-between; align-items: center;
  margin: 1px 10px; padding: 7px 10px; border-radius: var(--radius);
  color: var(--muted); text-decoration: none;
}
.panel-item:hover { background: var(--hover); color: var(--text); }
.panel-item.is-active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.panel-item.is-soon { opacity: .55; cursor: default; }
.panel-item.is-soon:hover { background: none; color: var(--muted); }
.panel-item small { font-size: 10.5px; padding: 0 6px; border-radius: 4px; background: var(--surface-alt); border: 1px solid var(--line); }
.panel-backdrop { display: none; }
.app.is-home .panel, .app.is-home .menu-btn, .app.is-home .crumbs .sep { display: none !important; }

/* ---------------- الشاشة الرئيسية ---------------- */
.home { display: flex; flex-direction: column; gap: 22px; max-width: 1100px; }
.home-hello h2 { font-family: var(--font-display); font-size: 22px; font-weight: 600; margin: 0; }
.home-hello p { margin: 2px 0 0; color: var(--muted); }
.home-info { display: flex; flex-wrap: wrap; gap: 8px; }
.home-section h3 { font-family: var(--font-display); font-size: 15px; font-weight: 600; margin: 0 0 10px; }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 14px 16px; }
.stat b { display: block; font-family: var(--font-display); font-size: 24px; font-weight: 600; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: 13px; }
.shortcuts { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.shortcut-group { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 14px 16px; }
.shortcut-group h4 { display: flex; align-items: center; gap: 8px; margin: 0 0 8px; font-size: 14px; font-weight: 600; }
.shortcut-group h4 svg { color: var(--accent); }
.shortcut-group ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.shortcut-group a { display: block; padding: 5px 8px; border-radius: var(--radius); color: var(--text); text-decoration: none; }
.shortcut-group a:hover { background: var(--accent-soft); color: var(--accent); }
.shortcut-group .is-soon { display: block; padding: 5px 8px; color: var(--muted); opacity: .6; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: var(--topbar-h); flex: none;
  background: var(--surface); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 12px; padding: 0 20px;
}
.crumbs { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.crumbs span { color: var(--muted); font-size: 13px; white-space: nowrap; }
.crumbs h1 { font-family: var(--font-display); font-size: 17px; font-weight: 600; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-end { margin-inline-start: auto; display: flex; align-items: center; gap: 10px; }
.chip { font-size: 12px; padding: 3px 12px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); font-weight: 500; white-space: nowrap; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%; border: 0;
  background: var(--accent); color: var(--accent-text); font-weight: 700;
}
.user-menu { position: relative; }
.dropdown {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 50;
  min-width: 190px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 8px; box-shadow: 0 8px 24px rgba(20, 28, 45, .12); padding: 6px;
}
.dropdown-head { padding: 6px 10px 8px; border-bottom: 1px solid var(--line); margin-bottom: 4px; display: flex; flex-direction: column; }
.dropdown-head small { color: var(--muted); }
.dropdown button { display: block; width: 100%; text-align: right; border: 0; background: none; padding: 7px 10px; border-radius: var(--radius); }
.dropdown button:hover { background: var(--hover); }

.content { flex: 1; overflow: auto; padding: 20px; }
.icon-btn { border: 0; background: none; padding: 6px; border-radius: var(--radius); display: inline-grid; place-items: center; }
.icon-btn:hover { background: var(--hover); }
.menu-btn { display: none; }

/* ---------------- مكونات عامة ---------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 7px 14px; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--surface); font-weight: 500; white-space: nowrap;
}
.btn:hover { background: var(--hover); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-danger-fill, .btn-danger-fill:hover { background: var(--danger); border-color: var(--danger); }
.btn-block { width: 100%; }
.btn svg { width: 16px; height: 16px; }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 14px; }
.toolbar .spacer { flex: 1; }
.toolbar .sep { width: 1px; height: 24px; background: var(--line); }

.input, .field input, .field select, .field textarea {
  width: 100%; padding: 7px 11px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface);
}
.input:focus, .field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field input:read-only { background: var(--surface-alt); color: var(--muted); }
.field { display: flex; flex-direction: column; gap: 4px; }
.field > span { font-size: 12.5px; font-weight: 500; color: var(--muted); }
.field .req { color: var(--danger); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.form-grid .full { grid-column: 1 / -1; }
.check { display: flex; align-items: center; gap: 8px; }
.segmented { display: flex; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.segmented label { flex: 1; text-align: center; padding: 6px; cursor: pointer; border-inline-start: 1px solid var(--line); }
.segmented label:first-child { border-inline-start: 0; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented label:has(input:checked) { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.segmented.is-locked { background: var(--surface-alt); }
.segmented.is-locked label { cursor: not-allowed; color: var(--muted); }
.segmented.is-locked label:has(input:checked) { background: var(--line); color: var(--text); }
.field select:disabled { background: var(--surface-alt); color: var(--text); cursor: not-allowed; opacity: 1; }
.form-error { background: var(--danger-soft); color: var(--danger); padding: 8px 12px; border-radius: var(--radius); font-size: 13px; }
.form-hint { font-size: 12px; color: var(--muted); }

.table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; overflow: auto; }
.table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.table th {
  position: sticky; top: 0; z-index: 1;
  background: var(--surface-alt); text-align: right; font-weight: 600; font-size: 12.5px; color: var(--muted);
  padding: 9px 12px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
.table td { padding: 8px 12px; border-bottom: 1px solid var(--line); }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--hover); }
.table tbody tr.is-selected td { background: var(--accent-soft); }
.num, .code { font-family: var(--font-mono); direction: ltr; text-align: right; }
.code { color: var(--muted); }

.tag { display: inline-block; font-size: 11.5px; padding: 1px 8px; border-radius: 4px; background: var(--surface-alt); color: var(--muted); border: 1px solid var(--line); white-space: nowrap; }
.tag-success { background: var(--success-soft); color: var(--success); border-color: transparent; }
.tag-danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.tag-warning { background: var(--warning-soft); color: var(--warning); border-color: transparent; }
.tag-accent { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

.empty {
  border: 1px dashed var(--line); border-radius: 8px; background: var(--surface);
  padding: 40px 20px; text-align: center; color: var(--muted);
}
.loading { padding: 40px; text-align: center; color: var(--muted); }

/* النوافذ */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100; background: rgba(20, 26, 38, .45);
  display: flex; align-items: flex-start; justify-content: center; padding: 60px 16px; overflow-y: auto;
}
.modal { background: var(--surface); border-radius: 10px; width: 100%; max-width: 560px; box-shadow: 0 20px 50px rgba(20, 28, 45, .25); }
.modal.modal-sm { max-width: 400px; }
.modal-head { display: flex; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; font-family: var(--font-display); font-size: 16px; font-weight: 600; }
.modal-head .icon-btn { margin-inline-start: auto; }
.modal-body { padding: 18px; display: flex; flex-direction: column; gap: 12px; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-start; padding: 12px 18px; border-top: 1px solid var(--line); background: var(--surface-alt); border-radius: 0 0 10px 10px; }

/* الرسائل */
.toasts { position: fixed; top: calc(var(--topbar-h) + 12px); left: 20px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.login-page .toasts { top: 20px; }
.toast {
  background: var(--rail-bg); color: var(--rail-text); padding: 10px 16px; border-radius: 8px;
  box-shadow: 0 8px 24px rgba(20, 28, 45, .2); max-width: 360px; border-inline-start: 4px solid var(--accent);
}
.toast-success { border-inline-start-color: #3fbf7f; }
.toast-error { border-inline-start-color: #ef6b55; }

/* ---------------- صفحة الدخول ---------------- */
.login-page { display: grid; place-items: center; padding: 16px; background: var(--rail-bg); }
.login-box {
  width: 100%; max-width: 380px; background: var(--surface); border-radius: 12px;
  padding: 28px; display: flex; flex-direction: column; gap: 14px;
}
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
.login-brand .rail-logo { margin: 0; }
.login-brand h1 { font-family: var(--font-display); font-size: 19px; margin: 0; }

/* ---------------- الشاشات الصغيرة ---------------- */
@media (max-width: 900px) {
  .menu-btn { display: inline-grid; }
  .panel {
    position: fixed; top: 0; bottom: 0; right: var(--rail-w); z-index: 60;
    transform: translateX(calc(100% + var(--rail-w))); transition: transform .2s;
    box-shadow: -8px 0 24px rgba(20, 28, 45, .15);
  }
  .app.panel-open .panel { transform: none; }
  .app.panel-open .panel-backdrop { display: block; position: fixed; inset: 0; z-index: 55; background: rgba(20, 26, 38, .35); }
  .content { padding: 14px; }
  .topbar { padding: 0 12px; }
  .topbar .chip { display: none; }
  .form-grid { grid-template-columns: 1fr; }
}
@media (max-width: 520px) {
  :root { --rail-w: 60px; }
  .rail-btn { width: 52px; font-size: 10px; }
}
@media (prefers-reduced-motion: reduce) {
  .panel { transition: none; }
}
.table tbody tr.is-stopped td { color: var(--muted); }

/* سنة العمل */
.year-select {
  display: inline-flex; align-items: center; gap: 6px; padding: 2px 4px 2px 10px;
  border: 1px solid var(--line); border-radius: 99px; background: var(--surface); font-size: 12px; color: var(--muted);
}
.year-select select { border: 0; background: none; font-weight: 600; color: var(--text); padding: 2px 4px; cursor: pointer; }
.year-select select:focus { outline: none; }
.chip-warning { background: var(--warning-soft); color: var(--warning); text-decoration: none; }

/* الإكمال التلقائي */
.ac-menu {
  position: fixed; z-index: 150; max-height: 280px; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 10px 28px rgba(20, 28, 45, .16); padding: 4px; direction: rtl;
}
.ac-item { padding: 7px 10px; border-radius: var(--radius); cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ac-item:hover { background: var(--hover); }
.ac-item.is-active { background: var(--accent-soft); color: var(--accent); }
.ac-empty { padding: 7px 10px; color: var(--muted); font-size: 12.5px; }

/* تنبيه داخل الصفحة */
.notice { background: var(--warning-soft); color: var(--warning); border-radius: 8px; padding: 10px 14px; margin-bottom: 14px; font-weight: 500; }

/* صفوف القوائم القابلة للتحديد */
[data-rows] tr[data-key] { cursor: pointer; user-select: none; }

/* نافذة كبيرة وجدول الصلاحيات */
.modal.modal-lg { max-width: 860px; }
.perm-wrap { max-height: 360px; }
.perm-table td, .perm-table th { text-align: center; padding: 6px 8px; }
.perm-table td:first-child, .perm-table th:first-child { text-align: right; }
.perm-table tr.perm-module td { background: var(--surface-alt); font-weight: 600; color: var(--accent); text-align: right; }
.perm-table input { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }

/* إدارة النظام */
.admin-shell { display: flex; flex-direction: column; height: 100%; }
.admin-logo { width: 32px; height: 32px; font-size: 15px; margin: 0; }
.admin-shell .crumbs { align-items: center; gap: 12px; }
.check-list { display: flex; flex-wrap: wrap; gap: 8px 18px; padding: 8px 0; }
.form-section { font-weight: 600; color: var(--accent); border-top: 1px solid var(--line); padding-top: 12px; margin-top: 4px; }

/* نموذج في صفحة كاملة (زي بيانات الشركة) */
.card-form { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 18px; max-width: 860px; }
.logo-box { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 6px 0; }
.logo-box img { max-height: 64px; max-width: 200px; border: 1px solid var(--line); border-radius: 6px; padding: 4px; background: #fff; }
.logo-box label.btn { cursor: pointer; }
.table th.num { font-family: var(--font); direction: rtl; text-align: left; }
/* في التقارير: المبلغ تحت عنوان عموده (على الشمال زي الطباعة) */
.rp-table td.num { text-align: left; white-space: nowrap; }
.rp-word { font-family: var(--font); }

/* سجل العمليات */
tr.audit-has-details { cursor: pointer; }
tr.audit-changed td { background: var(--warning-soft); }
/* فلاتر الصفحات (التقارير وسجل العمليات) */
.rp-filters { align-items: flex-end; }
.rp-f { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }
.rp-f .input { width: auto; min-width: 140px; }

/* شاشة الإقفال */
.closing { display: flex; flex-direction: column; gap: 18px; max-width: 900px; }
.closing-box { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 16px 18px; display: flex; flex-direction: column; gap: 10px; }
.closing-title { margin: 0; font-family: var(--font-display); font-size: 16px; font-weight: 600; }
.closing-actions { margin: 0; }
.notice ul { margin: 6px 0 0; padding-inline-start: 20px; }
.notice-ok { background: var(--success-soft); color: var(--success); }
.toast { white-space: pre-line; }

/* تبويبات */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; flex-wrap: wrap; }
.tab-btn { background: none; border: 0; border-bottom: 2px solid transparent; padding: 10px 16px; font: inherit; font-weight: 500; color: var(--muted); cursor: pointer; margin-bottom: -1px; }
.tab-btn:hover { color: var(--text); }
.tab-btn.is-active { color: var(--accent); border-bottom-color: var(--accent); }

/* شيك فات ميعاد استحقاقه */
.is-overdue { color: var(--danger); font-weight: 600; }

/* تنبيه انتهاء الاشتراك */
.expiry-bar { background: var(--warning-soft); color: var(--warning); padding: 8px 20px; font-weight: 500; text-align: center; }
.msettings-brackets { max-width: 420px; margin: 4px 0 8px; }
