/* ============================================================
   مِرصَد — نظام التصميم
   الفكرة: لوحة قياس مستوحاة من آلات الرصد الفلكي العربية.
   ليل نيلي عميق + نحاس محفور للهوية، وورق بارد لسطح العمل.
   كل الاتجاهات منطقية (inline-start/end) فيعمل الملف نفسه
   في العربية والإنجليزية دون نسخة ثانية.
   ============================================================ */

:root {
  /* اللون */
  --night:      #0F1A2E;
  --night-2:    #16233D;
  --night-3:    #1E2F4F;
  --brass:      #C8A24A;
  --brass-soft: #E0C179;
  --paper:      #F3F5F9;
  --surface:    #FFFFFF;
  --ink:        #0B1220;
  --ink-2:      #3D4A61;
  --ink-3:      #6B7893;
  --line:       #DDE3EC;
  --line-soft:  #EDF1F6;

  --rise:  #1E8E5E;
  --rise-bg: #E4F4EC;
  --fall:  #C8453C;
  --fall-bg: #FAE9E7;
  --watch: #B8791A;
  --watch-bg: #FBF0DC;
  --calm:  #2E5FA3;
  --calm-bg: #E7EFFA;

  /* الخط */
  --display: "Reem Kufi", "Noto Kufi Arabic", "Segoe UI", system-ui, sans-serif;
  --body: "IBM Plex Sans Arabic", "Segoe UI", "Helvetica Neue", system-ui, sans-serif;
  --figures: "IBM Plex Mono", "SFMono-Regular", Consolas, monospace;

  /* المقياس */
  --s1: 4px;  --s2: 8px;  --s3: 12px; --s4: 16px;
  --s5: 24px; --s6: 32px; --s7: 48px; --s8: 72px;

  --r1: 6px; --r2: 10px; --r3: 16px; --r4: 24px;

  --shadow-1: 0 1px 2px rgba(11,18,32,.06), 0 1px 3px rgba(11,18,32,.04);
  --shadow-2: 0 4px 12px rgba(11,18,32,.08), 0 1px 3px rgba(11,18,32,.04);
  --shadow-3: 0 12px 32px rgba(11,18,32,.14);

  --sidebar-w: 248px;
  --topbar-h: 62px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  font-family: var(--body);
  background: var(--paper);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

body[dir="ltr"] { font-size: 14.5px; }

h1,h2,h3,h4 { font-family: var(--display); font-weight: 600; line-height: 1.3; margin: 0 0 var(--s3); letter-spacing: 0; }
h1 { font-size: 1.9rem; } h2 { font-size: 1.45rem; } h3 { font-size: 1.15rem; } h4 { font-size: 1rem; }
p { margin: 0 0 var(--s3); }
a { color: var(--calm); text-decoration: none; }
a:hover { text-decoration: underline; }

/* الأرقام دائمًا لاتينية ومحاذاة جدولية — أسهل للمقارنة البصرية */
.fig, td.num, .kpi-value, .stat-value {
  font-family: var(--figures);
  font-variant-numeric: tabular-nums;
  direction: ltr;
  unicode-bidi: isolate;
}

:focus-visible { outline: 2px solid var(--brass); outline-offset: 2px; border-radius: 3px; }

/* ============================================================
   التخطيط العام للتطبيق
   ============================================================ */
.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w); flex: 0 0 var(--sidebar-w);
  background: var(--night); color: #C3CEE2;
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}

.brand {
  display: flex; align-items: center; gap: var(--s3);
  padding: var(--s5) var(--s4) var(--s4);
  border-bottom: 1px solid rgba(200,162,74,.18);
}
.brand-mark { width: 34px; height: 34px; flex: 0 0 34px; }
.brand-name { font-family: var(--display); font-size: 1.2rem; color: #fff; line-height: 1.1; }
.brand-tag { font-size: .68rem; color: var(--brass); letter-spacing: .04em; }

.nav { padding: var(--s3) var(--s2); flex: 1; }
.nav-group { margin-bottom: var(--s4); }
.nav-label {
  font-size: .66rem; letter-spacing: .1em; text-transform: uppercase;
  color: #6C7C99; padding: 0 var(--s3) var(--s2); display: block;
}
.nav a {
  display: flex; align-items: center; gap: var(--s3);
  padding: 9px var(--s3); margin-bottom: 2px;
  border-radius: var(--r1); color: #C3CEE2; font-size: .9rem;
  border-inline-start: 2px solid transparent;
  transition: background .15s, color .15s;
}
.nav a:hover { background: rgba(255,255,255,.05); color: #fff; text-decoration: none; }
.nav a.active {
  background: rgba(200,162,74,.12); color: #fff;
  border-inline-start-color: var(--brass);
}
.nav a .ico { width: 17px; height: 17px; flex: 0 0 17px; opacity: .85; }
.nav-badge {
  margin-inline-start: auto; background: var(--brass); color: var(--night);
  font-size: .68rem; font-weight: 700; padding: 1px 6px; border-radius: 20px;
  font-family: var(--figures);
}

.sidebar-foot { padding: var(--s3) var(--s4) var(--s5); border-top: 1px solid rgba(255,255,255,.07); font-size: .78rem; color: #7A88A5; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  height: var(--topbar-h); background: var(--surface);
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: var(--s4);
  padding: 0 var(--s5); position: sticky; top: 0; z-index: 20;
}
.topbar h1 { margin: 0; font-size: 1.1rem; }
.topbar-spacer { flex: 1; }

.menu-toggle { display: none; background: none; border: 0; padding: var(--s2); cursor: pointer; }

.content { padding: var(--s5); flex: 1; max-width: 1500px; width: 100%; }

/* ============================================================
   البطاقات والشبكات
   ============================================================ */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r3); padding: var(--s5); margin-bottom: var(--s4);
  box-shadow: var(--shadow-1);
}
.card-head {
  display: flex; align-items: center; gap: var(--s3);
  margin: 0 0 var(--s4); padding-bottom: var(--s3);
  border-bottom: 1px solid var(--line-soft);
}
.card-head h2, .card-head h3 { margin: 0; }
.card-head .spacer { flex: 1; }
.card-note { color: var(--ink-3); font-size: .82rem; }

.grid { display: grid; gap: var(--s4); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-auto { grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }
.split { display: grid; grid-template-columns: 1.6fr 1fr; gap: var(--s4); align-items: start; }

/* ============================================================
   مؤشرات الأداء
   ============================================================ */
.kpi {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r2); padding: var(--s4);
  position: relative; overflow: hidden;
}
.kpi::before {
  content: ""; position: absolute; inset-block-start: 0; inset-inline-start: 0;
  width: 3px; height: 100%; background: var(--brass); opacity: .5;
}
.kpi-label { font-size: .78rem; color: var(--ink-3); margin-bottom: var(--s1); }
.kpi-value { font-size: 1.6rem; font-weight: 600; color: var(--ink); line-height: 1.2; }
.kpi-sub { font-size: .76rem; color: var(--ink-3); margin-top: var(--s1); }
.kpi-delta { font-size: .78rem; font-weight: 600; display: inline-flex; align-items: center; gap: 3px; }
.kpi-delta.up { color: var(--rise); } .kpi-delta.down { color: var(--fall); } .kpi-delta.flat { color: var(--ink-3); }

/* العنصر المميّز: قرص الرصد — قوس متدرّج بعلامات كالإسطرلاب */
.dial { display: block; margin: 0 auto; }
.dial-track { fill: none; stroke: var(--line); stroke-width: 10; stroke-linecap: round; }
.dial-fill  { fill: none; stroke: var(--brass); stroke-width: 10; stroke-linecap: round; transition: stroke-dashoffset .8s cubic-bezier(.2,.8,.3,1); }
.dial-fill.good { stroke: var(--rise); } .dial-fill.warn { stroke: var(--watch); } .dial-fill.bad { stroke: var(--fall); }
.dial-tick { stroke: var(--ink-3); stroke-width: 1; opacity: .35; }
.dial-value { font-family: var(--figures); font-size: 26px; font-weight: 600; fill: var(--ink); text-anchor: middle; }
.dial-label { font-size: 11px; fill: var(--ink-3); text-anchor: middle; }
.dial-target { stroke: var(--ink-2); stroke-width: 2; }

@media (prefers-reduced-motion: reduce) {
  .dial-fill { transition: none; }
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ============================================================
   الجداول
   ============================================================ */
.table-wrap { overflow-x: auto; border-radius: var(--r2); border: 1px solid var(--line); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: .875rem; }
thead th {
  background: var(--paper); text-align: start; font-weight: 600;
  padding: 10px var(--s3); color: var(--ink-2); font-size: .78rem;
  border-bottom: 1px solid var(--line); white-space: nowrap;
}
tbody td { padding: 11px var(--s3); border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #FAFBFD; }
td.num, th.num { text-align: end; }
.t-main { font-weight: 600; color: var(--ink); }
.t-sub { font-size: .76rem; color: var(--ink-3); }

/* ============================================================
   الشارات والحالات
   ============================================================ */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 9px; border-radius: 20px; font-size: .74rem; font-weight: 600;
  background: var(--line-soft); color: var(--ink-2); white-space: nowrap;
}
.badge.rise { background: var(--rise-bg); color: var(--rise); }
.badge.fall { background: var(--fall-bg); color: var(--fall); }
.badge.watch{ background: var(--watch-bg); color: var(--watch); }
.badge.calm { background: var(--calm-bg); color: var(--calm); }
.badge.dot::before { content:""; width:6px; height:6px; border-radius:50%; background: currentColor; }

/* ============================================================
   الأزرار والنماذج
   ============================================================ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  padding: 9px 18px; border-radius: var(--r1); border: 1px solid transparent;
  font-family: var(--body); font-size: .88rem; font-weight: 600;
  cursor: pointer; background: var(--night); color: #fff;
  transition: background .15s, transform .08s;
}
.btn:hover { background: var(--night-2); text-decoration: none; color: #fff; }
.btn:active { transform: translateY(1px); }
.btn.ghost { background: transparent; color: var(--ink-2); border-color: var(--line); }
.btn.ghost:hover { background: var(--paper); color: var(--ink); }
.btn.brass { background: var(--brass); color: var(--night); }
.btn.brass:hover { background: var(--brass-soft); color: var(--night); }
.btn.danger { background: var(--fall); }
.btn.sm { padding: 5px 11px; font-size: .8rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.field { margin-bottom: var(--s4); }
.field label { display: block; font-size: .82rem; font-weight: 600; color: var(--ink-2); margin-bottom: 5px; }
.field .hint { font-size: .76rem; color: var(--ink-3); margin-top: 4px; }
input[type=text], input[type=email], input[type=password], input[type=number],
input[type=date], input[type=url], input[type=file], select, textarea {
  width: 100%; padding: 9px var(--s3); font-family: var(--body); font-size: .9rem;
  border: 1px solid var(--line); border-radius: var(--r1);
  background: var(--surface); color: var(--ink);
}
input[type=number] { font-family: var(--figures); direction: ltr; text-align: start; }
input:focus, select:focus, textarea:focus { border-color: var(--calm); outline: none; box-shadow: 0 0 0 3px var(--calm-bg); }
textarea { min-height: 96px; resize: vertical; line-height: 1.6; }
.field.bad input, .field.bad select, .field.bad textarea { border-color: var(--fall); }
.field-error { color: var(--fall); font-size: .78rem; margin-top: 4px; }

.check { display: flex; align-items: flex-start; gap: var(--s2); font-size: .88rem; cursor: pointer; }
.check input { margin-top: 4px; }

.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: var(--s4); }
.form-actions { display: flex; gap: var(--s3); align-items: center; margin-top: var(--s4); padding-top: var(--s4); border-top: 1px solid var(--line-soft); }

/* الأسرار: عرض مقنّع مع زر إظهار الحقل للتعديل */
.secret {
  display: flex; align-items: center; gap: var(--s3);
  padding: var(--s3); background: var(--paper);
  border: 1px dashed var(--line); border-radius: var(--r1);
}
.secret code { font-family: var(--figures); font-size: .82rem; color: var(--ink-2); direction: ltr; }

/* زر الربط بالمزوّد: يقلّد أزرار تسجيل الدخول المعتادة
   ليتعرّف عليه المستخدم فورًا ويطمئن إلى أنه ينتقل لصفحة رسمية. */
.btn-signin {
  display: flex; align-items: center; justify-content: center; gap: var(--s3);
  width: 100%; padding: 11px 18px;
  background: var(--surface); color: #3C4043;
  border: 1px solid #DADCE0; border-radius: var(--r1);
  font-family: var(--body); font-size: .92rem; font-weight: 600;
  cursor: pointer; transition: background .15s, box-shadow .15s, border-color .15s;
}
.btn-signin:hover { background: #F8F9FA; border-color: #C6C9CE; box-shadow: var(--shadow-1); }
.btn-signin:active { background: #F1F3F4; }
.btn-signin svg { flex: 0 0 18px; }

/* ============================================================
   التنبيهات والتغذية الراجعة
   ============================================================ */
.flash {
  display: flex; align-items: flex-start; gap: var(--s3);
  padding: var(--s3) var(--s4); border-radius: var(--r2);
  margin-bottom: var(--s4); font-size: .88rem;
  border-inline-start: 3px solid;
}
.flash.success { background: var(--rise-bg); border-color: var(--rise); color: #145E3F; }
.flash.error   { background: var(--fall-bg); border-color: var(--fall); color: #8C2F28; }
.flash.info    { background: var(--calm-bg); border-color: var(--calm); color: #1D4276; }
.flash.warn    { background: var(--watch-bg); border-color: var(--watch); color: #7A5010; }

.empty { text-align: center; padding: var(--s7) var(--s4); color: var(--ink-3); }
.empty h3 { color: var(--ink-2); }
.empty .btn { margin-top: var(--s3); }

.banner {
  display: flex; align-items: center; gap: var(--s3); flex-wrap: wrap;
  padding: var(--s3) var(--s4); border-radius: var(--r2); margin-bottom: var(--s4);
  background: var(--night); color: #D8E0EE; font-size: .86rem;
}
.banner .btn { margin-inline-start: auto; }

/* شريط الدخول لحساب عميل — يجب أن يكون مرئيًا دائمًا */
.impersonating {
  background: repeating-linear-gradient(135deg, var(--watch) 0 12px, #A66C14 12px 24px);
  color: #fff; padding: 7px var(--s5); font-size: .82rem;
  display: flex; align-items: center; gap: var(--s3); font-weight: 600;
}
.impersonating form { margin-inline-start: auto; }

/* ============================================================
   التوصيات
   ============================================================ */
.rec {
  border: 1px solid var(--line); border-radius: var(--r2);
  padding: var(--s4); margin-bottom: var(--s3); background: var(--surface);
}
.rec-top { display: flex; align-items: center; gap: var(--s2); flex-wrap: wrap; margin-bottom: var(--s2); }
.rec-title { font-weight: 600; flex: 1; min-width: 200px; }
.rec-body { font-size: .86rem; color: var(--ink-2); }
.rec-change {
  display: inline-flex; align-items: center; gap: var(--s2);
  font-family: var(--figures); font-size: .84rem; direction: ltr;
  background: var(--paper); padding: 3px 10px; border-radius: var(--r1); margin: var(--s2) 0;
}
.rec-actions { display: flex; gap: var(--s2); margin-top: var(--s3); }

/* شريط الثقة — القواعد الثابتة تختلف بصريًا عن مخرجات النموذج */
.conf { display: flex; align-items: center; gap: var(--s2); font-size: .76rem; color: var(--ink-3); }
.conf-bar { width: 54px; height: 4px; background: var(--line); border-radius: 3px; overflow: hidden; }
.conf-bar i { display: block; height: 100%; background: var(--brass); }
.conf-bar.model i { background: var(--calm); }

/* ============================================================
   المرشحات والترقيم
   ============================================================ */
.filters {
  display: flex; gap: var(--s3); flex-wrap: wrap; align-items: flex-end;
  padding: var(--s4); background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r2); margin-bottom: var(--s4);
}
.filters .field { margin: 0; min-width: 150px; }

.tabs { display: flex; gap: var(--s1); border-bottom: 1px solid var(--line); margin-bottom: var(--s5); overflow-x: auto; }
.tabs a {
  padding: 10px var(--s4); font-size: .88rem; font-weight: 600; color: var(--ink-3);
  border-bottom: 2px solid transparent; white-space: nowrap;
}
.tabs a:hover { color: var(--ink); text-decoration: none; }
.tabs a.active { color: var(--ink); border-bottom-color: var(--brass); }

.pager { display: flex; gap: var(--s2); justify-content: center; align-items: center; margin-top: var(--s5); }
.pager a, .pager span {
  padding: 5px 11px; border-radius: var(--r1); font-size: .84rem;
  border: 1px solid var(--line); color: var(--ink-2); font-family: var(--figures);
}
.pager .now { background: var(--night); color: #fff; border-color: var(--night); }

/* ============================================================
   الرسوم البيانية الخفيفة (SVG بلا مكتبات)
   ============================================================ */
.spark { width: 100%; height: 190px; display: block; }
.spark-grid { stroke: var(--line-soft); stroke-width: 1; }
.spark-axis { fill: var(--ink-3); font-size: 10px; font-family: var(--figures); }
.spark-line { fill: none; stroke-width: 2; }
.spark-line.spend { stroke: var(--fall); }
.spark-line.sales { stroke: var(--rise); }
.spark-area { opacity: .08; }

.bar-row { display: flex; align-items: center; gap: var(--s3); margin-bottom: var(--s2); font-size: .84rem; }
.bar-row .name { width: 120px; flex: 0 0 120px; color: var(--ink-2); }
.bar-track { flex: 1; height: 8px; background: var(--line-soft); border-radius: 4px; overflow: hidden; }
.bar-track i { display: block; height: 100%; background: var(--night-3); border-radius: 4px; }
.bar-row .val { width: 92px; flex: 0 0 92px; text-align: end; font-family: var(--figures); font-size: .8rem; }

/* ============================================================
   الاستجابة لكل الشاشات
   ============================================================ */
@media (max-width: 1180px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .split { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
  .sidebar {
    position: fixed; inset-block: 0; inset-inline-start: 0; z-index: 60;
    transform: translateX(calc(var(--sidebar-w) * -1));
    transition: transform .22s ease;
  }
  body[dir="rtl"] .sidebar { transform: translateX(var(--sidebar-w)); }
  .sidebar.open, body[dir="rtl"] .sidebar.open { transform: translateX(0); }
  .menu-toggle { display: block; }
  .content { padding: var(--s4); }
  .scrim { position: fixed; inset: 0; background: rgba(11,18,32,.5); z-index: 50; }
}
@media (max-width: 680px) {
  .grid-3, .grid-4, .grid-2 { grid-template-columns: 1fr; }
  h1 { font-size: 1.5rem; } h2 { font-size: 1.25rem; }
  .content { padding: var(--s3); }
  .card { padding: var(--s4); border-radius: var(--r2); }
  .topbar { padding: 0 var(--s3); }
  .filters { padding: var(--s3); }
  .filters .field { min-width: 100%; }
  .bar-row .name { width: 88px; flex: 0 0 88px; }
}

@media print {
  .sidebar, .topbar, .btn, .filters, .pager { display: none !important; }
  .card { break-inside: avoid; box-shadow: none; }
}
