/* ═══════════════════════════════════════════════════════════════
   نظام الدرع العربي — الواجهة العربية RTL (تصميم v2 المعتمد من المالك 2026-08-10)
   المبادئ: خط عربي مضمّن محليًا · أرقام متساوية العرض · وضع ليلي ·
   كثافة صفوف قابلة للتبديل · تجميد أعمدة الهوية · ذهبيّ بحذر
   ═══════════════════════════════════════════════════════════════ */
:root {
  --brand: #0b6b3a; --brand-d: #085229; --accent: #c9a227; --brand-soft: #0b6b3a12;
  --bg: #f4f6f5; --card: #ffffff; --ink: #141a16; --ink-2: #3d4842; --muted: #6b7772;
  --line: #e3e8e5; --line-2: #eef2f0; --danger: #b3261e; --warn: #9a5b00; --okc: #12652b; --info: #1a4f9c;
  --radius: 14px; --shadow: 0 1px 2px rgba(10, 30, 20, .06), 0 6px 20px rgba(10, 30, 20, .05);
  --sidebar-w: 248px; --row-pad: 11px; --fs-table: 13.5px;
  color-scheme: light;
}
[data-theme="dark"] {
  --brand: #2fa06a; --brand-d: #1e7a4e; --accent: #e0b84a; --brand-soft: #2fa06a1a;
  --bg: #101512; --card: #171f1a; --ink: #e8efea; --ink-2: #c3cfc8; --muted: #8b9a92;
  --line: #26312b; --line-2: #1e2721; --danger: #ef6b62; --warn: #e0a44a; --okc: #54c481; --info: #6ba3ec;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 20px rgba(0, 0, 0, .3);
  color-scheme: dark;
}
[data-tenant="EG"] { --brand: #7a1220; --brand-d: #5a0d17; --accent: #d4a017; --brand-soft: #7a122012; --bg: #f5f3f2; }
[data-theme="dark"][data-tenant="EG"] { --brand: #d06a76; --brand-d: #a94a56; --brand-soft: #d06a761a; --bg: #151011; --card: #1e1719; }
[data-density="compact"] { --row-pad: 6px; --fs-table: 12.8px; }

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: "IBM Plex Sans Arabic", "Segoe UI", Tahoma, "Noto Kufi Arabic", Arial, sans-serif;
  background: var(--bg); color: var(--ink); font-size: 14.5px; direction: rtl;
  -webkit-font-smoothing: antialiased; transition: background .25s, color .25s;
}
/* الأرقام متساوية العرض في كل مكان — تتراصّ الأعمدة الرقمية رأسيًا */
body { font-variant-numeric: tabular-nums; font-feature-settings: "tnum" 1; }
a { color: var(--brand); text-decoration: none; }
h1, h2, h3 { margin: 0 0 .5em; font-weight: 700; }
h1 { font-size: 22px; } h2 { font-size: 18px; } h3 { font-size: 15.5px; }

/* ---------- تخطيط ---------- */
#app { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w); background: linear-gradient(178deg, var(--brand), var(--brand-d));
  color: #fff; position: fixed; inset-inline-start: 0; top: 0; bottom: 0; z-index: 40;
  display: flex; flex-direction: column; transition: transform .25s;
}
.sidebar .logo-box { padding: 16px 14px 10px; background: #ffffff; margin: 12px; border-radius: 12px; text-align: center; }
.sidebar .logo-box img { width: 100%; max-width: 200px; }
.side-nav { flex: 1; overflow-y: auto; padding: 6px 10px 20px; }
.side-nav a {
  display: flex; align-items: center; gap: 10px; color: #ffffffd0; padding: 9px 12px;
  border-radius: 9px; margin-bottom: 1px; font-size: 13.8px; position: relative; transition: background .14s;
}
.side-nav a .ico { width: 21px; text-align: center; font-size: 16px; }
.side-nav a:hover { background: #ffffff16; color: #fff; }
/* التبويب النشط: شريط ذهبي رفيع على الحافة بدل الملء الكامل — أهدأ للعين */
.side-nav a.active { background: #ffffff1f; color: #fff; font-weight: 600; }
.side-nav a.active::before {
  content: ""; position: absolute; inset-inline-start: -10px; top: 7px; bottom: 7px;
  width: 3.5px; border-radius: 0 3px 3px 0; background: var(--accent);
}
.side-nav .sec { font-size: 10.5px; color: #ffffff7a; margin: 15px 12px 5px; letter-spacing: .6px; font-weight: 600; }
.side-foot { padding: 12px 14px; font-size: 11.5px; color: #ffffff99; border-top: 1px solid #ffffff22; }

.main { flex: 1; margin-inline-start: var(--sidebar-w); display: flex; flex-direction: column; min-width: 0; }
.topbar {
  background: var(--card); border-bottom: 1px solid var(--line); padding: 9px 20px;
  display: flex; align-items: center; gap: 12px; position: sticky; top: 0; z-index: 30;
}
.topbar .burger { display: none; }
.topbar .title { font-weight: 700; font-size: 16px; }
.topbar .grow { flex: 1; }
.content { padding: 22px; max-width: 1600px; width: 100%; margin: 0 auto; }
/* بيان القضية: عرض مريح للقراءة بدل امتداد السطر على الشاشة كاملة — بملاحظة المالك 2026-08-12
   (الجداول الطويلة تبقى بكامل العرض لأنها تحتاجه) */
.content.case-view { max-width: 1180px; }
.content.case-view .table-wrap { max-width: none; }
.case-head-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 10px 18px; }
.case-head-grid > div { min-width: 0; }
.case-head-grid label { display: block; font-size: 11.5px; color: var(--muted); margin-bottom: 2px; }

/* ---------- البحث الشامل (Ctrl+K) ---------- */
.gsearch {
  display: flex; align-items: center; gap: 8px; background: var(--bg); border: 1.5px solid var(--line);
  border-radius: 10px; padding: 7px 12px; min-width: 260px; color: var(--muted); font-size: 13.5px;
  cursor: pointer; transition: border-color .15s; font-family: inherit;
}
.gsearch:hover { border-color: var(--brand); }
.gsearch kbd {
  margin-inline-start: auto; background: var(--card); border: 1px solid var(--line);
  border-bottom-width: 2px; border-radius: 5px; padding: 1px 6px; font-size: 10.5px; font-family: inherit;
}
.gs-overlay {
  position: fixed; inset: 0; background: rgba(10, 18, 13, .5); z-index: 200;
  display: flex; align-items: flex-start; justify-content: center; padding: 9vh 16px;
}
.gs-box { background: var(--card); border-radius: 16px; width: 100%; max-width: 640px; box-shadow: 0 24px 70px rgba(0, 0, 0, .35); overflow: hidden; animation: pop .16s ease; }
.gs-box input {
  width: 100%; border: none; border-bottom: 1.5px solid var(--line); border-radius: 0;
  padding: 15px 18px; font-size: 15.5px; background: var(--card); color: var(--ink);
}
.gs-box input:focus { outline: none; border-color: var(--brand); }
.gs-results { max-height: 52vh; overflow-y: auto; padding: 6px; }
.gs-item { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px; cursor: pointer; font-size: 13.5px; }
.gs-item:hover, .gs-item.sel { background: var(--brand-soft); }
.gs-item .ico { font-size: 17px; width: 24px; text-align: center; }
.gs-item .meta { color: var(--muted); font-size: 11.5px; margin-top: 1px; }
.gs-item .tail { margin-inline-start: auto; color: var(--muted); font-size: 11px; white-space: nowrap; }
.gs-hint { padding: 9px 16px; font-size: 11.5px; color: var(--muted); border-top: 1px solid var(--line-2); display: flex; gap: 14px; }
.gs-empty { padding: 26px; text-align: center; color: var(--muted); font-size: 13.5px; }

/* ---------- مكونات ---------- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 18px; }
.card h2 { display: flex; align-items: center; gap: 8px; }
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(2, 1fr); } .g3 { grid-template-columns: repeat(3, 1fr); } .g4 { grid-template-columns: repeat(4, 1fr); }

.stat { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; position: relative; overflow: hidden; }
.stat::after { content: ""; position: absolute; inset-inline-start: 0; top: 0; bottom: 0; width: 4px; background: var(--brand); }
.stat .num { font-size: 26px; font-weight: 800; color: var(--brand); }
.stat .lbl { color: var(--muted); font-size: 13px; margin-top: 2px; }
.stat.warn::after { background: var(--warn); } .stat.warn .num { color: var(--warn); }
.stat.danger::after { background: var(--danger); } .stat.danger .num { color: var(--danger); }

button, .btn {
  font-family: inherit; font-size: 14px; border: none; cursor: pointer;
  background: var(--brand); color: #fff; padding: 9px 18px; border-radius: 10px; font-weight: 600;
  transition: filter .15s; display: inline-flex; align-items: center; gap: 7px;
}
button:hover { filter: brightness(1.1); }
.btn-ghost { background: transparent; color: var(--brand); border: 1.5px solid var(--line); }
.btn-ghost:hover { border-color: var(--brand); filter: none; }
.btn-gold { background: var(--accent); color: #201803; }
.btn-danger { background: var(--danger); }
.btn-sm { padding: 5px 12px; font-size: 12.5px; border-radius: 8px; }
button:disabled { opacity: .5; cursor: not-allowed; }

input, select, textarea {
  font-family: inherit; font-size: 14px; width: 100%; padding: 9px 12px;
  border: 1.5px solid var(--line); border-radius: 10px; background: var(--card); color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); }
label { display: block; font-size: 12.5px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
.field { margin-bottom: 12px; }
textarea { min-height: 90px; resize: vertical; }

/* ---------- الجداول ---------- */
table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: var(--fs-table); }
th {
  text-align: right; padding: 9px 11px; background: var(--brand-soft); color: var(--brand);
  font-size: 12px; font-weight: 700; white-space: nowrap;
  position: sticky; top: 0; z-index: 5; border-bottom: 1.5px solid var(--line);
}
th:first-child { border-radius: 0 10px 0 0; } th:last-child { border-radius: 10px 0 0 0; }
td { padding: var(--row-pad) 11px; border-bottom: 1px solid var(--line-2); vertical-align: middle; transition: padding .15s; }
tbody tr:nth-child(even) td, tr:nth-child(even) td { background: color-mix(in srgb, var(--bg) 45%, transparent); }
tr:hover td { background: var(--brand-soft); }
tr.clickable { cursor: pointer; }
.table-wrap { overflow-x: auto; position: relative; max-height: 74vh; overflow-y: auto; }
.sub { font-size: 11px; color: var(--muted); margin-top: 1px; }

/* تجميد عمودَي الهوية (الرقم الداخلي + المكتبي) — يبقيان ظاهرين مهما مرّرت أفقيًا */
.stick1, .stick2 { position: sticky; z-index: 6; background: var(--card) !important; }
.stick1 { inset-inline-start: 0; min-width: 118px; }
.stick2 { inset-inline-start: 118px; box-shadow: -8px 0 8px -8px rgba(0, 0, 0, .16); }
/* جدول القضايا: عمودا الأرقام بأضيق عرض يسع الرقم فقط */
.cs-grid .stick1, .cs-grid th.stick1 { width: 82px; min-width: 82px; max-width: 82px; padding-inline: 7px; text-align: center; }
.cs-grid .stick2, .cs-grid th.stick2 { inset-inline-start: 82px; width: 46px; min-width: 46px; max-width: 46px; padding-inline: 5px; text-align: center; }

/* ═══ جدول القضايا: صف واحد لكل قضية ليظهر أكبر عدد بالشاشة (توجيه المالك 2026-08-12) ═══ */
.cs-grid td, .cs-grid th { white-space: nowrap; }
.cs-grid td { padding-top: calc(var(--row-pad) - 2px); padding-bottom: calc(var(--row-pad) - 2px); }
.cs-grid td.cut { max-width: 190px; overflow: hidden; text-overflow: ellipsis; }
/* 🎨 تلوين صف وصف — يفصل القضايا بصريًا فلا تختلط عند التمرير */
.cs-grid tbody tr td { background: var(--card); }
.cs-grid tbody tr:nth-child(even) td { background: color-mix(in srgb, var(--brand) 14%, var(--card)); }
.cs-grid tbody tr:hover td { background: color-mix(in srgb, var(--brand) 28%, var(--card)) !important; }
.cs-grid tbody tr td { border-bottom: 1px solid color-mix(in srgb, var(--line) 60%, transparent); }
/* العمودان المجمَّدان يتبعان لون صفهما */
.cs-grid tbody tr .stick1, .cs-grid tbody tr .stick2 { background: var(--card) !important; }
.cs-grid tbody tr:nth-child(even) .stick1, .cs-grid tbody tr:nth-child(even) .stick2 { background: color-mix(in srgb, var(--brand) 14%, var(--card)) !important; }
.cs-grid tbody tr:hover .stick1, .cs-grid tbody tr:hover .stick2 { background: color-mix(in srgb, var(--brand) 28%, var(--card)) !important; }
/* شريط جانبي يميّز الصف تحت المؤشر */
.cs-grid tbody tr .stick1 { border-inline-start: 3px solid transparent; }
.cs-grid tbody tr:hover .stick1 { border-inline-start-color: var(--brand); }

/* سقوف عرض لكل عمود طويل — الاسم الكامل يظهر بالتلميح */
.cs-grid .c-client { max-width: 132px; width: 132px; }
.cs-grid .c-lawyer { max-width: 78px; width: 78px; }
.cs-grid .c-last   { max-width: 118px; width: 118px; }
.cs-grid .c-phase  { max-width: 104px; width: 104px; overflow: hidden; }
.cs-grid .c-phase .badge { max-width: 100%; overflow: hidden; text-overflow: ellipsis; vertical-align: middle; }
.cs-grid tbody tr { height: 1px; }

/* قوائم منسدلة داخل الخلايا (تفصيل المبالغ والأتعاب) */
details.mini { display: inline-block; position: relative; }
details.mini > summary { list-style: none; cursor: pointer; white-space: nowrap; }
details.mini > summary::-webkit-details-marker { display: none; }
details.mini > summary::after { content: ' ⌄'; font-size: 13px; color: var(--muted); font-weight: 700; }
details.mini[open] > summary::after { content: ' ⌃'; }
details.mini[open] > summary { color: var(--brand); }
details.mini .mini-body {
  position: absolute; z-index: 20; inset-inline-start: 0; top: 100%; margin-top: 4px; min-width: 190px;
  background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 7px 10px;
  box-shadow: 0 8px 22px rgba(0, 0, 0, .14); font-size: 12px; white-space: nowrap;
}
details.mini .mini-body > div { display: flex; justify-content: space-between; gap: 16px; padding: 2px 0; }
details.mini .mini-body > div + div { border-top: 1px dashed var(--line-2); }
details.mini .mini-body span { color: var(--muted); }
th.stick1, th.stick2 { z-index: 8; background: color-mix(in srgb, var(--brand-soft) 100%, var(--card)) !important; }
tr:hover .stick1, tr:hover .stick2 { background: color-mix(in srgb, var(--brand-soft) 55%, var(--card)) !important; }
tr:nth-child(even) .stick1, tr:nth-child(even) .stick2 { background: color-mix(in srgb, var(--bg) 45%, var(--card)) !important; }

.badge { display: inline-block; padding: 2.5px 9px; border-radius: 999px; font-size: 11px; font-weight: 700; white-space: nowrap; }
.b-green { background: color-mix(in srgb, var(--okc) 14%, transparent); color: var(--okc); }
.b-red { background: color-mix(in srgb, var(--danger) 13%, transparent); color: var(--danger); }
.b-amber { background: color-mix(in srgb, var(--warn) 15%, transparent); color: var(--warn); }
.b-gray { background: var(--line-2); color: var(--muted); }
.b-blue { background: color-mix(in srgb, var(--info) 13%, transparent); color: var(--info); }
.b-gold { background: color-mix(in srgb, var(--accent) 22%, transparent); color: color-mix(in srgb, var(--warn) 80%, var(--ink)); }

.toolbar { display: flex; gap: 9px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.toolbar input, .toolbar select { width: auto; min-width: 160px; }
.toolbar .grow { flex: 1; }

/* مبدّل كثافة الصفوف: مريح / مضغوط */
.viewctl { display: flex; gap: 4px; align-items: center; background: var(--card); border: 1.5px solid var(--line); border-radius: 9px; padding: 3px; }
.viewctl button { border: 0; background: none; font-size: 12.5px; padding: 5px 11px; border-radius: 6px; color: var(--muted); font-weight: 600; }
.viewctl button:hover { filter: none; background: var(--brand-soft); }
.viewctl button.on { background: var(--brand); color: #fff; }

/* تبويبا الموضوعية/التنفيذية */
.classtabs { display: flex; background: var(--card); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); margin-bottom: 14px; }
.classtabs button { flex: 1; border: 0; background: none; padding: 0; border-radius: 0; position: relative; display: block; }
.classtabs button:hover { filter: none; }
.classtabs .in {
  padding: 13px 16px; display: flex; align-items: center; justify-content: center; gap: 9px;
  font-size: 15.5px; font-weight: 600; color: var(--muted); transition: all .18s;
}
.classtabs button.on .in { color: var(--brand); background: var(--brand-soft); }
.classtabs button.on.enf .in { color: var(--warn); background: color-mix(in srgb, var(--warn) 7%, transparent); }
.classtabs button.on::after { content: ""; position: absolute; inset-inline: 0; bottom: 0; height: 3px; background: var(--brand); }
.classtabs button.on.enf::after { background: var(--warn); }
.classtabs .n { font-size: 13px; background: var(--line-2); color: var(--muted); padding: 2px 9px; border-radius: 99px; font-weight: 700; }
.classtabs button.on .n { background: var(--brand); color: #fff; }
.classtabs button.on.enf .n { background: var(--warn); color: #fff; }

/* ---------- نوافذ ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(12, 22, 16, .45); z-index: 90; display: flex; align-items: flex-start; justify-content: center; padding: 4vh 14px; overflow-y: auto; }
.modal { background: var(--card); border-radius: 16px; max-width: 720px; width: 100%; padding: 22px; box-shadow: 0 20px 60px rgba(0, 0, 0, .25); animation: pop .18s ease; }
.modal.wide { max-width: 960px; }
@keyframes pop { from { transform: translateY(14px); opacity: 0; } }
.modal h2 { color: var(--brand); }
.modal-actions { display: flex; gap: 10px; justify-content: flex-start; margin-top: 16px; }

/* ---------- تنبيهات ---------- */
#toasts { position: fixed; bottom: 18px; inset-inline-start: 18px; z-index: 220; display: flex; flex-direction: column; gap: 8px; }
.toast { background: #1c2620; color: #fff; padding: 12px 18px; border-radius: 12px; box-shadow: var(--shadow); font-size: 13.5px; animation: pop .2s; max-width: 360px; }
.toast.err { background: var(--danger); } .toast.ok { background: var(--okc); }
[data-theme="dark"] .toast { background: #2a3830; }

.notif-dot { position: absolute; top: 4px; inset-inline-end: 4px; width: 9px; height: 9px; background: var(--danger); border-radius: 50%; border: 2px solid var(--card); }
.icon-btn { position: relative; background: var(--brand-soft); color: var(--brand); border-radius: 10px; padding: 8px 12px; font-size: 16px; }
.icon-btn:hover { filter: none; background: color-mix(in srgb, var(--brand-soft) 60%, var(--brand) 12%); }

.empty { text-align: center; color: var(--muted); padding: 36px 10px; }
.empty .big { font-size: 38px; margin-bottom: 8px; }

.tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--line); margin-bottom: 16px; flex-wrap: wrap; }
.tabs button { background: none; color: var(--muted); border-radius: 10px 10px 0 0; padding: 9px 16px; font-weight: 600; }
.tabs button:hover { filter: none; background: var(--brand-soft); }
.tabs button.active { color: var(--brand); background: var(--brand-soft); box-shadow: inset 0 -2.5px 0 var(--brand); }

.timeline { border-inline-start: 2.5px solid var(--line); margin-inline-start: 8px; padding-inline-start: 18px; }
.tl-item { position: relative; margin-bottom: 14px; }
.tl-item::before { content: ""; position: absolute; inset-inline-start: -25.5px; top: 5px; width: 11px; height: 11px; border-radius: 50%; background: var(--brand); border: 2.5px solid var(--card); box-shadow: 0 0 0 2px var(--line); }
.tl-item .when { font-size: 12px; color: var(--muted); }

.ai-out { background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 18px; white-space: pre-wrap; line-height: 1.95; font-size: 14.5px; max-height: 520px; overflow-y: auto; }
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; background: linear-gradient(140deg, var(--brand) 0%, var(--brand-d) 100%); }
.login-card { background: #fff; border-radius: 20px; padding: 34px; width: 100%; max-width: 420px; box-shadow: 0 24px 70px rgba(0, 0, 0, .35); color: #17211b; }
.login-card img { width: 100%; margin-bottom: 10px; }
.tenant-pick { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 18px; }
.tenant-pick button { justify-content: center; padding: 13px; font-size: 15px; }
.tenant-pick button.off { background: #eceeed; color: #67736c; }

.chart-bars { display: flex; align-items: flex-end; gap: 6px; height: 150px; padding-top: 10px; }
.chart-bars .bar { flex: 1; background: linear-gradient(180deg, var(--brand), color-mix(in srgb, var(--brand) 70%, var(--card))); border-radius: 6px 6px 0 0; min-height: 3px; position: relative; }
.chart-bars .bar span { position: absolute; top: -20px; inset-inline-start: 0; inset-inline-end: 0; text-align: center; font-size: 10.5px; color: var(--muted); }
.chart-bars .bar em { position: absolute; bottom: -20px; inset-inline-start: 0; inset-inline-end: 0; text-align: center; font-size: 10.5px; font-style: normal; color: var(--muted); }

.doc-preview { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 28px; white-space: pre-wrap; line-height: 2.1; font-family: "Traditional Arabic", "IBM Plex Sans Arabic", serif; font-size: 16px; }

@media print {
  .sidebar, .topbar, .toolbar, .no-print, #toasts, .classtabs, .viewctl { display: none !important; }
  .main { margin: 0 !important; } .content { padding: 0; max-width: none; }
  .card { box-shadow: none; border: none; }
  body { background: #fff; color: #000; }
  .table-wrap { max-height: none; overflow: visible; }
  th, td { position: static !important; }
}

@media (max-width: 960px) {
  .g4 { grid-template-columns: repeat(2, 1fr); } .g3 { grid-template-columns: repeat(2, 1fr); }
  .sidebar { transform: translateX(100%); }
  .sidebar.open { transform: none; box-shadow: 0 0 60px rgba(0, 0, 0, .4); }
  .main { margin-inline-start: 0; }
  .topbar .burger { display: inline-flex; }
  .gsearch { min-width: 0; flex: 1; }
  .gsearch .gtxt { display: none; }
}
@media (max-width: 620px) {
  .g4, .g3, .g2 { grid-template-columns: 1fr; }
  .content { padding: 14px; }
  .modal { padding: 16px; }
}

/* 🔢 الأرقام باللاتينية دائمًا في كل الشاشات (قرار المالك 2026-08-12) */
body, table, input, select, textarea, .badge, .stat .num { font-variant-numeric: lining-nums tabular-nums; }
.cs-grid td { font-variant-numeric: tabular-nums; }
