/* ============================================================================
   لوحة إدارة توتال تولز — نظام التصميم
   ----------------------------------------------------------------------------
   الموضوع: دفترُ حساباتٍ لشركة عُدد، لا لوحةُ SaaS. فالألوان من المشغل
   والدفتر — ورقٌ دافئ وجرافيت ومسطرةٌ رمادية، وتيل العلامة يُستعمل **بنيةً**
   لا توهّجاً. والبطل هو **الجدول**: الأرقام جدوليةٌ واثقة، وما حولها هادئ.

   وما تُجُنِّب عمداً: البطاقاتُ المتطابقة ذات الظلّ الواحد، والأسودُ المائل
   بلمسةٍ نيون، والفواصلُ بالنقطة الوسطى، والإيموجي في قائمةٍ مالية.
   ========================================================================= */

/* ─────────── الورق: الوضع الفاتح ─────────── */
:root {
  --canvas: #FBFAF7;
  --surface: #FFFFFF;
  --surface-2: #F4F2ED;
  --surface-3: #EAE7DF;

  --ink: #15181C;
  --ink-2: #4A5159;
  --ink-3: #7C858D;

  --rule: #E5E1D8;
  --rule-2: #CFC9BC;

  --teal: #0E7C7B;
  --teal-2: #0A6463;
  --teal-ink: #FFFFFF;
  --teal-wash: #E4F0F0;

  --amber: #9A5B0C;
  --amber-wash: #FAF0E0;
  --green: #176B44;
  --green-wash: #E3F0E9;
  --red: #A3221C;
  --red-wash: #FAE9E7;
  --blue: #1B5E8C;
  --blue-wash: #E5EEF5;

  --shade-1: 0 1px 1px rgba(21, 24, 28, .05);
  --shade-2: 0 8px 24px -10px rgba(21, 24, 28, .22);
  --shade-3: 0 24px 56px -16px rgba(21, 24, 28, .32);

  /* إيقاع 4 نقاط */
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px;
  --s5: 24px; --s6: 32px; --s7: 48px;

  --r1: 6px; --r2: 10px; --r3: 16px; --rp: 999px;
  --rail: 232px;
  --ease: cubic-bezier(.2, .6, .3, 1);

  color-scheme: light;
}

/* ─────────── الجرافيت: الوضع المظلم ─────────── */
:root[data-theme="dark"] {
  --canvas: #1A1E22;
  --surface: #22272C;
  --surface-2: #2A3036;
  --surface-3: #333A41;

  --ink: #EDEFF1;
  --ink-2: #AEB6BD;
  --ink-3: #79828A;

  --rule: #333A41;
  --rule-2: #454D56;

  --teal: #3FB8B2;
  --teal-2: #55CDC6;
  --teal-ink: #0A2423;
  --teal-wash: #1E3634;

  --amber: #D79328;
  --amber-wash: #352C19;
  --green: #4FAE7F;
  --green-wash: #1C3328;
  --red: #E0726A;
  --red-wash: #38241F;
  --blue: #5AA6D8;
  --blue-wash: #1C2E3B;

  --shade-1: 0 1px 1px rgba(0, 0, 0, .3);
  --shade-2: 0 10px 28px -12px rgba(0, 0, 0, .6);
  --shade-3: 0 28px 60px -18px rgba(0, 0, 0, .7);

  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--canvas);
  color: var(--ink);
  font-family: 'IBM Plex Sans Arabic', 'Segoe UI', system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  direction: rtl;
  -webkit-font-smoothing: antialiased;
}

/* مقياسٌ طباعي واحد — لا أحجامٌ مرتجلة */
h1 { font-size: 27px; font-weight: 600; letter-spacing: -.02em; margin: 0 0 var(--s2); }
h2 { font-size: 21px; font-weight: 600; letter-spacing: -.015em; margin: 0 0 var(--s1); line-height: 1.35; }
h3 { font-size: 17px; font-weight: 600; margin: 0 0 var(--s2); }
h4 { font-size: 15px; font-weight: 600; margin: 0 0 var(--s2); }
p  { margin: 0 0 var(--s2); max-width: 72ch; }

a { color: var(--teal); text-decoration: none; }
a:hover { text-decoration: underline; }
code {
  font-family: 'IBM Plex Mono', Consolas, monospace; font-size: .9em;
  background: var(--surface-2); padding: 1px 6px; border-radius: var(--r1);
}

/* الأرقام: جدوليةٌ ومن اليسار كي تصطفّ فواصلها */
.num, td.num {
  font-variant-numeric: tabular-nums;
  font-feature-settings: 'tnum' 1;
  direction: ltr;
  text-align: left;
  unicode-bidi: isolate;
}

.muted { color: var(--ink-2); }
.faint { color: var(--ink-3); }
.small { font-size: 13.5px; }
.tiny  { font-size: 12.5px; }
.hidden { display: none !important; }
.row { display: flex; gap: var(--s3); flex-wrap: wrap; align-items: center; }
.row.tight { gap: var(--s2); }
.spread { display: flex; justify-content: space-between; align-items: center; gap: var(--s4); flex-wrap: wrap; }
.grow { flex: 1 1 180px; }
.center { text-align: center; }

svg.i { width: 17px; height: 17px; stroke: currentColor; fill: none;
  stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ═══════════ الدخول ═══════════ */
#login { min-height: 100vh; display: grid; place-items: center; padding: var(--s5); }
#login .box {
  width: min(400px, 100%);
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--r3);
  padding: var(--s6);
  box-shadow: var(--shade-2);
}
#login .mark { height: 38px; object-fit: contain; display: block; margin: 0 auto var(--s5); }
#login h2 { text-align: center; }
#login .sub { text-align: center; color: var(--ink-3); font-size: 13.5px; margin-bottom: var(--s5); }

/* ═══════════ الهيكل ═══════════ */
#shell { display: none; min-height: 100vh; }
#shell.on { display: grid; grid-template-columns: var(--rail) minmax(0, 1fr); }

aside {
  background: var(--surface);
  border-left: 1px solid var(--rule);
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column;
  padding: var(--s4) var(--s3) var(--s3);
  overflow-y: auto;
}
aside .brand {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--s2); padding: 0 var(--s2) var(--s4);
}
aside .brand img { height: 26px; object-fit: contain; }

aside .group {
  font-size: 11.5px; font-weight: 600; color: var(--ink-3);
  padding: var(--s4) var(--s2) var(--s1);
}

aside button.nav {
  display: flex; align-items: center; gap: var(--s2);
  background: none; border: 0; cursor: pointer;
  font: inherit; font-size: 14.5px; font-weight: 500;
  color: var(--ink-2); text-align: right;
  padding: 9px var(--s3); border-radius: var(--r2);
  position: relative; transition: background-color .12s var(--ease), color .12s var(--ease);
}
aside button.nav:hover { background: var(--surface-2); color: var(--ink); }
aside button.nav.active { background: var(--teal-wash); color: var(--teal); font-weight: 600; }
/* علامةٌ بنيوية على الحافة — لا توهّج */
aside button.nav.active::before {
  content: ''; position: absolute; inset-inline-end: -11px;
  inset-block: 6px; width: 3px; border-radius: var(--rp); background: var(--teal);
}
aside button.nav .tag {
  margin-inline-start: auto; background: var(--amber); color: #fff;
  font-size: 11.5px; font-weight: 600; min-width: 19px; height: 19px;
  border-radius: var(--rp); display: grid; place-items: center; padding: 0 5px;
}

aside .who {
  margin-top: auto; padding-top: var(--s3); border-top: 1px solid var(--rule);
}
aside .who .nm { font-weight: 600; font-size: 14px; }
aside .who .rl { color: var(--ink-3); font-size: 12.5px; margin-bottom: var(--s2); }

main { min-width: 0; padding: 0 0 var(--s7); }

/* شريط الأدوات — ثابتٌ أعلى كل شاشة */
.toolbar {
  position: sticky; top: 0; z-index: 10;
  background: var(--canvas);
  border-bottom: 1px solid var(--rule);
  padding: var(--s4) var(--s5) var(--s3);
  display: flex; align-items: flex-end; gap: var(--s3); flex-wrap: wrap;
}
.toolbar .ttl { margin-inline-end: auto; }
.toolbar h2 { margin: 0; }
.toolbar .sub { color: var(--ink-3); font-size: 13px; margin-top: 2px; }
.toolbar .acts { display: flex; gap: var(--s2); align-items: flex-end; flex-wrap: wrap; }

.pane { padding: var(--s5); }
.pane > * + * { margin-top: var(--s4); }

/* فتحةٌ واحدة عند التحميل — لا حركةَ على كل بطاقة */
.tab:not(.hidden) { animation: in .2s var(--ease); }
@keyframes in { from { opacity: 0; transform: translateY(4px) } to { opacity: 1; transform: none } }

/* ═══════════ شريط الأرقام ═══════════ */
/* سطرُ ملخّصٍ كما في الدفتر، لا أربع بطاقاتٍ متطابقة */
.stats {
  display: flex; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--rule);
  border-radius: var(--r2); overflow: hidden;
}
.stats .st {
  flex: 1 1 150px; padding: var(--s4) var(--s5);
  border-inline-start: 1px solid var(--rule);
}
.stats .st:first-child { border-inline-start: 0; }
.stats .st .v {
  font-size: 26px; font-weight: 600; line-height: 1.2; letter-spacing: -.02em;
  font-variant-numeric: tabular-nums; direction: ltr; text-align: start;
}
.stats .st .l { color: var(--ink-3); font-size: 12.5px; margin-top: 2px; }
.stats .st.ok .v { color: var(--green); }
.stats .st.warn .v { color: var(--amber); }
.stats .st.bad .v { color: var(--red); }
.stats .st.info .v { color: var(--blue); }

/* ═══════════ البطاقات ═══════════ */
.card {
  background: var(--surface); border: 1px solid var(--rule);
  border-radius: var(--r2); padding: var(--s5);
}
.card.tight { padding: var(--s3) var(--s4); }
.card > h3:first-child, .card > .spread:first-child { margin-top: 0; }
.grid { display: grid; gap: var(--s4); }
.grid.k2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid.k3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }

/* ═══════════ الجدول — البطل ═══════════ */
.sheet {
  background: var(--surface); border: 1px solid var(--rule);
  border-radius: var(--r2); overflow: hidden;
}
.sheet > .head {
  display: flex; align-items: center; gap: var(--s3);
  padding: var(--s3) var(--s4); border-bottom: 1px solid var(--rule);
  flex-wrap: wrap;
}
.sheet > .head h3 { margin: 0; font-size: 15px; }
.sheet > .head .cnt { color: var(--ink-3); font-size: 12.5px; }
.sheet > .head .sp { margin-inline-start: auto; }
.sheet > .head input { width: 190px; font-size: 13px; padding: 6px 10px; }
.scroll { overflow: auto; max-height: 68vh; }

table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 14px; }
th, td {
  padding: 10px var(--s4); text-align: right; vertical-align: middle;
  border-bottom: 1px solid var(--rule);
}
th {
  position: sticky; top: 0; z-index: 2;
  background: var(--surface-2); color: var(--ink-2);
  font-weight: 600; font-size: 12.5px; white-space: nowrap;
  border-bottom: 1px solid var(--rule-2);
  user-select: none;
}
th.sortable { cursor: pointer; }
th.sortable:hover { color: var(--ink); background: var(--surface-3); }
th .ar { opacity: 0; margin-inline-start: 3px; font-size: 10px; }
th.sortable:hover .ar { opacity: .4; }
th.asc .ar, th.desc .ar { opacity: 1; color: var(--teal); }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--teal-wash); }
td b { font-weight: 600; }

.empty { padding: var(--s7) var(--s5); text-align: center; color: var(--ink-3); }
.empty .ttl { font-size: 15px; color: var(--ink-2); margin-bottom: 2px; }

/* ═══════════ الحالة ═══════════ */
.state { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; font-size: 13px; }
.state::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--ink-3); flex: none; }
.state.ok::before { background: var(--green); }
.state.warn::before { background: var(--amber); }
.state.bad::before { background: var(--red); }
.state.info::before { background: var(--blue); }
.state.ok { color: var(--green); } .state.warn { color: var(--amber); }
.state.bad { color: var(--red); } .state.info { color: var(--blue); }

.pill {
  display: inline-block; padding: 2px 9px; border-radius: var(--rp);
  font-size: 12.5px; font-weight: 600; white-space: nowrap;
}
.pill.ok { background: var(--green-wash); color: var(--green); }
.pill.warn { background: var(--amber-wash); color: var(--amber); }
.pill.bad { background: var(--red-wash); color: var(--red); }
.pill.info { background: var(--blue-wash); color: var(--blue); }
.pill.mute { background: var(--surface-3); color: var(--ink-2); }

.meter { display: flex; align-items: center; gap: var(--s2); direction: ltr; }
.meter .bar { flex: 1; min-width: 46px; height: 5px; border-radius: var(--rp);
  background: var(--surface-3); overflow: hidden; }
.meter .bar > i { display: block; height: 100%; background: var(--teal); }
.meter.ok .bar > i { background: var(--green); }
.meter.warn .bar > i { background: var(--amber); }
.meter.bad .bar > i { background: var(--red); }
.meter .pc { font-variant-numeric: tabular-nums; font-size: 12.5px; color: var(--ink-2); min-width: 38px; }

/* ═══════════ الأزرار والحقول ═══════════ */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--teal); color: var(--teal-ink); border: 1px solid transparent;
  border-radius: var(--r1); padding: 8px 15px;
  font: inherit; font-size: 14px; font-weight: 600; cursor: pointer;
  transition: background-color .12s var(--ease); white-space: nowrap;
}
.btn:hover:not(:disabled) { background: var(--teal-2); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.ghost { background: var(--surface); color: var(--ink-2); border-color: var(--rule-2); }
.btn.ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--ink); }
.btn.danger { background: var(--red); color: #fff; }
.btn.sm { padding: 5px 11px; font-size: 13px; }
.btn.block { width: 100%; justify-content: center; }
.btn.icon { padding: 7px; }

.seg { display: inline-flex; border: 1px solid var(--rule-2); border-radius: var(--r1); overflow: hidden; }
.seg button {
  background: var(--surface); border: 0; border-inline-start: 1px solid var(--rule);
  font: inherit; font-size: 13px; color: var(--ink-2); padding: 6px 13px; cursor: pointer;
}
.seg button:first-child { border-inline-start: 0; }
.seg button:hover { background: var(--surface-2); }
.seg button.on { background: var(--teal); color: var(--teal-ink); font-weight: 600; }

label { display: block; font-size: 12.5px; font-weight: 500; color: var(--ink-2); margin-bottom: 4px; }
label small { color: var(--ink-3); font-weight: 400; }
input, select, textarea {
  width: 100%; background: var(--surface); color: var(--ink);
  border: 1px solid var(--rule-2); border-radius: var(--r1);
  padding: 8px 11px; font: inherit; font-size: 14px;
  transition: border-color .12s var(--ease), box-shadow .12s var(--ease);
}
input::placeholder, textarea::placeholder { color: var(--ink-3); }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--teal);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--teal) 16%, transparent);
}
input[type="file"] { padding: 6px; cursor: pointer; }
.field + .field { margin-top: var(--s3); }
.fields { display: flex; gap: var(--s3); flex-wrap: wrap; align-items: flex-end; }
.fields .field { margin-top: 0; }
.fields .field.w { flex: 1 1 170px; }
.fields .field.n { flex: 0 0 150px; }

/* ═══════════ البحث ═══════════ */
.find { position: relative; margin: 0 var(--s2) var(--s2); }
.find input { padding-inline-start: 32px; font-size: 13.5px; background: var(--surface-2); }
.find > svg.i { position: absolute; inset-inline-start: 9px; top: 9px; color: var(--ink-3); }
.find .res {
  position: absolute; inset-inline: 0; top: calc(100% + 4px); z-index: 40;
  background: var(--surface); border: 1px solid var(--rule-2);
  border-radius: var(--r2); box-shadow: var(--shade-3);
  max-height: 62vh; overflow: auto; padding: var(--s1);
}
.find .res .g { font-size: 11.5px; font-weight: 600; color: var(--ink-3); padding: var(--s2) var(--s2) 2px; }
.find .res .it { padding: 7px var(--s2); border-radius: var(--r1); cursor: pointer; font-size: 13.5px; }
.find .res .it:hover, .find .res .it.on { background: var(--teal-wash); }
.find .res .it .s { display: block; color: var(--ink-3); font-size: 12px; }
.find .res .none { padding: var(--s4); text-align: center; color: var(--ink-3); font-size: 13px; }

/* ═══════════ الحوار ═══════════ */
#modal {
  position: fixed; inset: 0; z-index: 60; display: none; place-items: center;
  padding: var(--s4); background: rgba(21, 24, 28, .45);
}
:root[data-theme="dark"] #modal { background: rgba(0, 0, 0, .6); }
#modal.on { display: grid; }
#modalSheet {
  width: min(720px, 100%); max-height: 88vh; overflow: auto;
  background: var(--surface); border: 1px solid var(--rule-2);
  border-radius: var(--r3); box-shadow: var(--shade-3);
  padding: var(--s5) var(--s6);
}
#modalSheet h3 { font-size: 19px; }
#modalSheet table { font-size: 13.5px; }
#modalSheet th, #modalSheet td { padding: 7px var(--s3); }

/* ═══════════ التنبيهات ═══════════ */
#toast { position: fixed; bottom: var(--s5); inset-inline-start: var(--s5); z-index: 90; display: grid; gap: var(--s2); }
#toast .t {
  background: var(--surface); border: 1px solid var(--rule-2);
  border-inline-start: 3px solid var(--teal);
  border-radius: var(--r1); padding: 10px var(--s4); max-width: 400px;
  box-shadow: var(--shade-2); font-size: 13.5px;
  animation: slide .2s var(--ease);
}
#toast .t.bad { border-inline-start-color: var(--red); }
#toast .t.ok { border-inline-start-color: var(--green); }
@keyframes slide { from { transform: translateY(8px); opacity: 0 } to { transform: none; opacity: 1 } }

/* ═══════════ مسار الحالات ═══════════ */
.track { display: flex; flex-wrap: wrap; gap: 2px; margin: var(--s3) 0; }
.track .s {
  font-size: 12.5px; padding: 5px 11px; color: var(--ink-3);
  background: var(--surface-2); border-radius: var(--r1);
}
.track .s.done { background: var(--green-wash); color: var(--green); }
.track .s.now { background: var(--teal); color: var(--teal-ink); font-weight: 600; }

/* ═══════════ صناديق الرسائل ═══════════ */
.note, .warnbox, .okbox {
  border-radius: var(--r1); padding: var(--s3) var(--s4);
  font-size: 13.5px; border-inline-start: 3px solid;
}
.note { background: var(--blue-wash); border-color: var(--blue); }
.warnbox { background: var(--amber-wash); border-color: var(--amber); }
.okbox { background: var(--green-wash); border-color: var(--green); }
.warnbox ul { margin: var(--s1) 0 0; padding-inline-start: var(--s4); }
.warnbox li { margin: 2px 0; }

.keybox {
  background: var(--surface-2); border: 1px solid var(--rule-2);
  border-radius: var(--r1); padding: var(--s3) var(--s4);
  font-family: 'IBM Plex Mono', Consolas, monospace;
  direction: ltr; text-align: left; word-break: break-all; font-size: 13px;
}

.thumbs { display: flex; gap: var(--s2); flex-wrap: wrap; }
.thumbs img {
  max-width: 100%; border-radius: var(--r1);
  border: 1px solid var(--rule); cursor: pointer; background: var(--surface-2);
}
td img.th { height: 34px; border-radius: var(--r1); border: 1px solid var(--rule); }

/* ═══════════ رسمٌ بالأعمدة ═══════════ */
.bars { display: flex; align-items: flex-end; gap: 2px; height: 96px; overflow-x: auto; padding-top: var(--s4); }
.bars .b { flex: 1 0 6px; min-width: 6px; background: var(--teal); border-radius: 2px 2px 0 0; position: relative; }
.bars .b:hover { background: var(--teal-2); }
.bars .b::after {
  content: attr(data-t); position: absolute; bottom: 100%; inset-inline-start: 50%;
  transform: translateX(50%); white-space: nowrap; font-size: 11.5px;
  background: var(--ink); color: var(--canvas); padding: 2px 7px; border-radius: var(--r1);
  opacity: 0; pointer-events: none; transition: opacity .1s;
}
.bars .b:hover::after { opacity: 1; }

/* شريط تقدّم */
#bar {
  position: fixed; inset-block-start: 0; inset-inline: 0; height: 2px; z-index: 100;
  background: var(--teal); transform: scaleX(0); transform-origin: right;
  transition: transform .25s var(--ease), opacity .3s; opacity: 0;
}
#bar.on { transform: scaleX(.7); opacity: 1; }
#bar.done { transform: scaleX(1); opacity: 0; }

/* ═══════════ شاشة الموظف ═══════════ */
#staff { max-width: 680px; margin: 0 auto; padding: var(--s5) var(--s4) var(--s7); }

/* ═══════════ ضيّق ═══════════ */
@media (max-width: 900px) {
  #shell.on { grid-template-columns: 1fr; }
  aside {
    position: static; height: auto; flex-direction: row; flex-wrap: wrap;
    align-items: center; border-left: 0; border-bottom: 1px solid var(--rule);
    padding: var(--s3);
  }
  aside .brand { width: 100%; padding: 0 0 var(--s2); }
  aside .group { display: none; }
  aside .find { width: 100%; margin: 0 0 var(--s2); }
  aside button.nav { flex: 1 1 auto; justify-content: center; padding: 7px 10px; font-size: 13px; }
  aside button.nav svg.i { display: none; }
  aside button.nav.active::before { display: none; }
  aside .who { width: 100%; }
  .toolbar { padding: var(--s3) var(--s4); position: static; }
  .pane { padding: var(--s4); }
  .stats .st { flex: 1 1 50%; border-inline-start: 0; border-top: 1px solid var(--rule); padding: var(--s3) var(--s4); }
  .stats .st:nth-child(-n+2) { border-top: 0; }
  .stats .st .v { font-size: 22px; }
  th, td { padding: 9px var(--s3); }
  .sheet > .head input { width: 100%; }
  #modalSheet { padding: var(--s4); max-height: 92vh; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
