/* ===========================================================
   بورتال التكاليف — ستايل
   =========================================================== */

/* 🔴 أول قاعدة في الملف عن قصد: [hidden] بيتخفي بستايل افتراضي **أضعف من
   أي كلاس**، فأي كلاس فيه display (زي .row{display:flex}) بيلغيه. ده
   اتكلّف باجين منشورين في بوابة العميل: صف تاريخ ظاهر دايمًا، وقائمة فروع
   كانت هتبان لصاحب مطعم عنده فرع واحد. */
[hidden] { display: none !important; }

:root {
  --navy: #0f2742;
  --navy-2: #16324f;
  --teal: #0f8f87;
  --teal-dark: #0b6f69;
  --bg: #f4f6f9;
  --card: #ffffff;
  --line: #e3e8ef;
  --text: #1b2733;
  --muted: #6b7a8d;
  --red: #c0392b;
  --red-bg: #fdecea;
  --amber: #b9770e;
  --amber-bg: #fef5e7;
  --green: #1e8449;
  --green-bg: #eafaf1;
  --radius: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "IBM Plex Sans Arabic", "Segoe UI", Tahoma, sans-serif;
  font-size: 14px;
  direction: rtl;
}

/* ── التخطيط ─────────────────────────────────────────────── */
.shell { display: flex; min-height: 100vh; }

nav.side {
  width: 220px;
  flex: 0 0 220px;
  background: var(--navy);
  color: #dfe7f1;
  display: flex;
  flex-direction: column;
  padding: 18px 0;
}

nav.side .brand {
  padding: 0 18px 18px;
  font-size: 16px;
  font-weight: 700;
  color: #fff;
  border-bottom: 1px solid rgba(255, 255, 255, .12);
  margin-bottom: 10px;
}

nav.side .brand small { display: block; font-weight: 400; font-size: 11px; color: #9fb3cc; margin-top: 4px; }

nav.side button {
  background: none;
  border: 0;
  color: #dfe7f1;
  text-align: right;
  padding: 11px 18px;
  font: inherit;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 9px;
}

nav.side button:hover { background: var(--navy-2); }
nav.side button.on { background: var(--teal); color: #fff; font-weight: 600; }
nav.side button svg { width: 17px; height: 17px; flex: 0 0 17px; }

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

header.top {
  background: #fff;
  border-bottom: 1px solid var(--line);
  padding: 13px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  /* height: auto صريح — style عام ممكن يحدّد height ثابت و min-height
     ما بيلغيهوش، فالعناصر اللي بتلفّ بتنزل فوق المحتوى. */
  height: auto;
  flex-wrap: wrap;
}

header.top h1 { margin: 0; font-size: 17px; }
header.top .meta { color: var(--muted); font-size: 12px; }

.page { padding: 18px 20px 40px; max-width: 1500px; width: 100%; }

/* ── الكروت والشبكة ──────────────────────────────────────── */
.cols { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }

/* 🔴 min-width: 0 على أبناء الشبكة — من غيرها جدول عريض جوه .scroll
   بيوسّع عمود الشبكة و**الصفحة كلها تتزحلق أفقيًا** بدل ما الجدول يتزحلق
   جوه كارته. اتكشفت بالقياس على عرض 375 في بوابة العميل. */
.cols > *, .card, .tiles > * { min-width: 0; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 15px 16px;
  margin-bottom: 14px;
}

.card h2 { margin: 0 0 4px; font-size: 15px; }
.card .hint { color: var(--muted); font-size: 12px; margin: 0 0 12px; line-height: 1.7; }

.tiles { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); margin-bottom: 14px; }

.tile {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 13px 15px;
}

.tile .k { color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.tile .v { font-size: 20px; font-weight: 700; }
.tile .s { color: var(--muted); font-size: 11px; margin-top: 5px; }
.tile.bad { border-color: var(--red); background: var(--red-bg); }
.tile.warn { border-color: var(--amber); background: var(--amber-bg); }

/* ── الجداول ─────────────────────────────────────────────── */
.scroll { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 8px 9px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { background: #f7f9fc; color: var(--muted); font-weight: 600; font-size: 12px; position: sticky; top: 0; }
tr.bad td { background: var(--red-bg); }
tr.dim td { opacity: .55; }
td.num, th.num { font-variant-numeric: tabular-nums; }
tbody tr:hover td { background: #f9fbfd; }

/* ── العناصر ─────────────────────────────────────────────── */
button.btn {
  background: var(--teal);
  color: #fff;
  border: 0;
  border-radius: 8px;
  padding: 8px 15px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

button.btn:hover { background: var(--teal-dark); }
button.btn:disabled { background: #b8c4d2; cursor: not-allowed; }
button.btn.ghost { background: #fff; color: var(--teal-dark); border: 1px solid var(--teal); }
button.btn.ghost:hover { background: #f0fbfa; }
button.btn.danger { background: #fff; color: var(--red); border: 1px solid var(--red); }
button.btn.small { padding: 5px 10px; font-size: 12px; font-weight: 500; }

input, select, textarea {
  font: inherit;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  width: 100%;
  min-width: 0;
}

input:focus, select:focus { outline: 2px solid var(--teal); outline-offset: -1px; }
input:disabled, select:disabled { background: #f2f4f7; color: var(--muted); }

.form { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); align-items: end; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.row { display: flex; gap: 9px; align-items: center; flex-wrap: wrap; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

.badge.ok { background: var(--green-bg); color: var(--green); }
.badge.bad { background: var(--red-bg); color: var(--red); }
.badge.warn { background: var(--amber-bg); color: var(--amber); }
.badge.mute { background: #eef1f5; color: var(--muted); }

.note { padding: 10px 12px; border-radius: 9px; font-size: 13px; line-height: 1.75; margin-bottom: 10px; }
.note.bad { background: var(--red-bg); color: var(--red); border: 1px solid #f5c6c0; }
.note.warn { background: var(--amber-bg); color: var(--amber); border: 1px solid #f7dca0; }
.note.ok { background: var(--green-bg); color: var(--green); border: 1px solid #b7e4c9; }
.note.info { background: #eef4fb; color: #2c4a6b; border: 1px solid #cddff2; }

.muted { color: var(--muted); }
.err { color: var(--red); font-size: 13px; }
.bar { height: 7px; background: #eef1f5; border-radius: 5px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--teal); }

/* ── الموبايل ────────────────────────────────────────────── */
@media (max-width: 760px) {
  .shell { flex-direction: column; }

  nav.side {
    position: fixed;
    inset: auto 0 0 0;
    width: auto;
    flex: none;
    flex-direction: row;
    padding: 0;
    overflow-x: auto;
    z-index: 20;
    border-top: 1px solid rgba(255, 255, 255, .15);
  }

  nav.side .brand { display: none; }

  nav.side button {
    flex-direction: column;
    gap: 3px;
    font-size: 10px;
    padding: 8px 10px;
    flex: 1 0 auto;
    text-align: center;
  }

  /* مساحة للشريط السفلي عشان ما يغطّيش آخر كارت */
  .page { padding: 14px 14px 100px; }
  header.top { padding: 11px 14px; }
  .tiles { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
}

@media print {
  nav.side, header.top .row, button { display: none !important; }
  .scroll { overflow: visible !important; }
  body { background: #fff; }
}

/* ── شاشة فشل الإقلاع ─────────────────────────────────────
   بتستبدل الصفحة كلها، فبتحمل طريق خروج بنفسها (شوف app.js). */
.bootfail { padding: 28px 20px; max-width: 520px; margin: 40px auto; text-align: center; }
.bootfail h2 { color: #c0392b; margin: 0 0 10px; font-size: 19px; }
.bootfail p { margin: 0 0 8px; }
.bootfail .row { justify-content: center; margin-top: 18px; }

/* ── أرضية اللمس ──────────────────────────────────────────
   🔴 بـ`pointer: coarse` مش بعرض الشاشة: التابلت عرضه أوسع من بريك بوينت
   الموبايل ولسه صباع. وكده مفيش رقم بنخمّنه — وتخمين زي ده وقع النهاردة
   في بوابة تانية (الفحص قال 760 والحقيقة 900).
   اتقاس: على 375 كان فيه ١٥ عنصر تفاعلي تحت 36px، منهم أزرار الحفظ
   الأساسية (35) وزرار الخروج (28). */
@media (pointer: coarse) {
  .btn { min-height: 36px; }
}

/* ── عناصر شاشات المشتريات والصلاحيات ───────────────────── */

/* خانة اختيار بعنوانها — لازم `inline-flex` عشان المربّع والنص ما يفترقوش
   على سطرين في الشاشة الضيّقة. */
.chk {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-inline-end: 14px;
  font-size: 13px;
  color: var(--text);
  white-space: nowrap;
}
.chk input { margin: 0; }

/* علامة صغيرة جوه خلية — «حسابك» · «اعتماد ذاتي» */
.pill {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 11px;
  background: var(--line);
  color: var(--muted);
  white-space: nowrap;
}
.pill.bad { background: var(--red-bg); color: var(--red); }

/* فاصل مطاطي في سطر الأزرار */
.grow { flex: 1 1 auto; }

/* 🔴 الصف اللي فيه فرق غير مفسَّر لازم يبان — الفرق بين مجموع السطور
   والمكتوب على الورقة هو كل فايدة المطابقة. */
tr.warn > td { background: var(--amber-bg); }

/* ── الفروقات والجرد ────────────────────────────────────── */

/* 🔴 لون الفرق بيقول «كويس ولا وحش» مش «موجب ولا سالب» — والاتجاه بيختلف
   حسب الجدول: في الاستهلاك، صرف **أكتر** من المفروض وحش؛ وفي الجرد،
   رصيد **أقل** من الدفتري وحش. علشان كده الكلاس بيتحدد في الجافاسكريبت
   لكل جدول على حدة، مش من إشارة الرقم هنا. */
td.num.bad  { color: var(--red); font-weight: 600; }
td.num.good { color: var(--green); font-weight: 600; }

.card h3 {
  margin: 20px 0 6px;
  font-size: 14px;
  color: var(--text);
}

/* 🔴 رقم الكارت لما يكون خسارة — ومعاه الملاحظة تحته.
   (الموجود `.tile.bad` بيلوّن الكارت كله؛ هنا الرقم بس، عشان كارت «قيمة
   الفرق» ما يبقاش أحمر بالكامل وهو ممكن يكون صفر أو سالب.) */
.tile .v.bad { color: var(--red); }
.tile .s .bad { color: var(--red); }
