/* تنسيق السيستم. مستوحى من صور التصور: شريط جانبي كحلي على اليمين، وخلفية فاتحة، وكروت بيضا. */
:root {
  --navy: #1b2b45;
  --navy-2: #24385a;
  --bg: #f2f5f9;
  --card: #ffffff;
  --line: #e3e8ef;
  --text: #1c2536;
  --muted: #64708a;
  --accent: #1f4e8c;
  --accent-soft: #e8f0fb;
  --good: #16723a;
  --good-soft: #e3f5ea;
  --bad: #a3241f;
  --bad-soft: #fdeaea;
  --warn: #8a5a00;
  --warn-soft: #fff4dc;
  --radius: 12px;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; max-width: 100%; overflow-x: hidden; }
body {
  font-family: "Segoe UI", Tahoma, "Noto Sans Arabic", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  font-size: 15px;
}
a { color: var(--accent); }
h1 { font-size: 1.6rem; margin: 0 0 4px; }
h2 { font-size: 1.1rem; margin: 0; }
h3 { font-size: 1rem; margin: 0 0 6px; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
[hidden] { display: none !important; }
.mt { margin-top: 14px; }
.mb { margin-bottom: 10px; }
.m0 { margin: 0; }
.line-row { display: grid; grid-template-columns: 2fr 1fr 1fr auto; gap: 6px; margin-bottom: 6px; align-items: center; }
.line-row select, .line-row input { min-width: 0; }
input.num { width: 80px; padding: 6px; }
.date-field { display: grid; grid-template-columns: 1fr 1.4fr 1.2fr; gap: 6px; }
.date-field select { padding: 10px 6px; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }

/* ===== شاشة الدخول وصفحات الخطأ ===== */
.center-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.card.narrow { width: 100%; max-width: 420px; }
.brand { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.brand .logo { width: 42px; height: 42px; border-radius: 10px; background: var(--navy); color: #fff; display: grid; place-items: center; font-weight: 800; font-size: 1.2rem; }
.brand b { display: block; font-size: 1.15rem; }

.brand-logo { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; margin-bottom: 16px; }
.brand-logo img { height: 34px; width: auto; max-width: 100%; }
.brand-logo.on-dark { background: #fff; border-radius: 10px; padding: 10px 12px; margin: 0 2px 14px; }
.brand-logo.on-dark span { color: var(--muted); }

/* ===== الفورم ===== */
label.field { display: block; margin-bottom: 12px; }
label.field span { display: block; font-size: 0.9rem; color: var(--muted); margin-bottom: 4px; }
input, select, textarea {
  width: 100%; font: inherit; color: inherit; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 8px; background: #fff;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
input.ltr { direction: ltr; text-align: right; }
textarea { min-height: 80px; resize: vertical; }
.btn {
  font: inherit; border: 1px solid var(--line); background: #fff; color: var(--text);
  padding: 8px 14px; border-radius: 8px; cursor: pointer; white-space: nowrap; text-decoration: none; display: inline-block;
}
.btn:hover { background: #f7f9fc; }
.btn.primary { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn.primary:hover { background: var(--navy-2); }
.btn.danger { color: var(--bad); border-color: #f0c9c7; }
.btn.block { width: 100%; padding: 11px; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }

.alert { padding: 10px 14px; border-radius: 8px; margin: 10px 0; }
.alert.bad { background: var(--bad-soft); color: var(--bad); }
.alert.good { background: var(--good-soft); color: var(--good); }
.alert.warn { background: var(--warn-soft); color: var(--warn); }
.alert.info { background: var(--accent-soft); color: var(--accent); }

/* ===== الهيكل ===== */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 240px; flex-shrink: 0; background: var(--navy); color: #dfe6f2; padding: 16px 12px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.sidebar .brand { color: #fff; padding: 4px 6px 14px; border-bottom: 1px solid rgba(255,255,255,0.08); }
.sidebar .brand .logo { background: #fff; color: var(--navy); }
.sidebar .brand .sub { font-size: 0.8rem; color: #aab6cb; }
.nav a {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  color: #dfe6f2; text-decoration: none; padding: 9px 12px; border-radius: 8px; margin: 2px 0;
}
.nav a:hover { background: rgba(255,255,255,0.06); }
.nav a.active { background: rgba(255,255,255,0.12); color: #fff; font-weight: 600; }
.badge { background: #d64545; color: #fff; border-radius: 999px; padding: 0 8px; font-size: 0.75rem; min-width: 22px; text-align: center; }

.main { flex: 1; min-width: 0; }
.topbar {
  background: #fff; border-bottom: 1px solid var(--line); padding: 10px 24px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
}
.topbar .who { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.chip { background: var(--accent-soft); color: var(--accent); padding: 4px 12px; border-radius: 999px; font-size: 0.9rem; }
.menu-btn { display: none; }
.switch-banner {
  background: var(--warn-soft); color: var(--warn); padding: 10px 24px; border-bottom: 1px solid #f1dfb5;
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
}
.content { padding: 24px; max-width: 1200px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs button {
  font: inherit; background: none; border: none; padding: 10px 14px; cursor: pointer; color: var(--muted);
  border-bottom: 2px solid transparent; white-space: nowrap;
}
.tabs button.active { color: var(--navy); border-bottom-color: var(--navy); font-weight: 700; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.stat .v { font-size: 1.8rem; font-weight: 800; }
.stat .l { color: var(--muted); font-size: 0.9rem; }

.section { margin-bottom: 16px; }
.section > .head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin-bottom: 12px; }
.filters label.field { margin: 0; min-width: 150px; flex: 1; }

/* ===== الجداول: على الموبايل بتتحوّل لكروت علشان ما تتقصّش ===== */
table.list { width: 100%; border-collapse: collapse; }
table.list th, table.list td { text-align: right; padding: 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.list th { color: var(--muted); font-weight: 600; font-size: 0.88rem; background: #fafbfd; }
table.list tr.denied td { background: #fff8f8; }
.tag { display: inline-block; padding: 1px 10px; border-radius: 999px; font-size: 0.82rem; background: #eef1f6; }
.tag.good { background: var(--good-soft); color: var(--good); }
.tag.bad { background: var(--bad-soft); color: var(--bad); }
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.empty { color: var(--muted); padding: 16px; text-align: center; }

.title-block { border-bottom: 1px solid var(--line); padding: 14px 0; }
.title-block:last-child { border-bottom: none; }
.perm-row { display: flex; align-items: center; gap: 8px; margin: 4px 0; }
.perm-row input { width: auto; }

/* ===== النوافذ ===== */
.modal-back { position: fixed; inset: 0; background: rgba(15, 23, 42, 0.45); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 50; }
.modal { background: #fff; border-radius: var(--radius); width: 100%; max-width: 520px; max-height: 92vh; overflow-y: auto; padding: 20px; }
.modal h2 { margin-bottom: 12px; }
.toast { position: fixed; bottom: 16px; left: 16px; right: 16px; max-width: 480px; margin: 0 auto; z-index: 60; }
ul.plain { margin: 6px 0; padding-inline-start: 20px; }

@media (max-width: 860px) {
  .layout { display: block; }
  .sidebar { position: fixed; inset: 0 0 0 auto; height: 100vh; z-index: 40; transform: translateX(100%); transition: transform 0.2s; width: 260px; }
  .sidebar.open { transform: none; box-shadow: -8px 0 24px rgba(0,0,0,0.2); }
  .menu-btn { display: inline-block; }
  .topbar, .switch-banner { padding: 10px 16px; }
  .content { padding: 16px; }
  h1 { font-size: 1.3rem; }
  table.list thead { display: none; }
  table.list, table.list tbody, table.list tr, table.list td { display: block; width: 100%; }
  table.list tr { border: 1px solid var(--line); border-radius: 10px; margin-bottom: 10px; padding: 6px 4px; background: #fff; }
  table.list td { border: none; padding: 4px 10px; overflow-wrap: anywhere; }
  .line-row { grid-template-columns: 1fr 1fr; }
  input.num { width: 100%; }
  table.list td[data-label]::before { content: attr(data-label); display: block; color: var(--muted); font-size: 0.8rem; }
}

/* المرحلة 6أ: GST (لون مختلف)، وكروت المهمات بزراير كبيرة سهلة على الموبايل */
/* شارة الشركة (هوية GST البصرية): «شوبزي» بالكحلي، و«GST» بأزرق GST #59B6E6 والنص كحلي GST #000D28 */
.tag.shopzy { background: var(--navy); color: #fff; }
.tag.gst { background: #59B6E6; color: #000D28; font-weight: 700; }
.mission.gst { border-inline-start: 6px solid #59B6E6; }
.mission.shopzy { border-inline-start: 6px solid var(--navy); }
.btn.big { padding: 12px 20px; font-size: 1.05rem; min-width: 140px; }
.mission-cards { display: grid; gap: 12px; }
.field.check { display: flex; align-items: center; gap: 8px; }
.btn.small { padding: 2px 8px; font-size: 0.8rem; margin-inline-start: 6px; }

/* المرحلة 6ب: الشريط الأحمر الثابت لأوامر الخامات المستنية موافقة (5.11) */
.approval-bar { display: block; position: sticky; top: 0; z-index: 20; background: var(--bad); color: #fff; padding: 10px 24px; font-weight: 700; text-decoration: none; }
.approval-bar[hidden] { display: none; }
.approval-bar:hover { filter: brightness(1.08); }
.sheet-net { font-weight: 700; font-variant-numeric: tabular-nums; }
.row-bad td { background: var(--bad-soft); }
.row-warn td { background: var(--warn-soft); }

/* مراجعة كودكس R12: فلاتر شيت العهدة على الموبايل (390): كل خانة بعرض الشاشة، والتاريخ (اليوم والشهر والسنة) ظاهر كامل */
.custody-filters label.field { min-width: 0; }
@media (max-width: 600px) {
  .custody-filters { display: grid; grid-template-columns: 1fr; }
  .custody-filters label.field, .custody-filters > .btn { width: 100%; }
  .custody-filters .date-field { grid-template-columns: 0.9fr 1.5fr 1.2fr; }
  .custody-filters .date-field select { min-width: 0; padding: 10px 4px; }
}
/* «مؤقت» جنب القيمة المبدئية جوه خانة الإعدادات (R08) */
label.field span.tag { display: inline-block; margin-top: 4px; }

/* نسخة التجربة: شريط ثابت بلون واضح فوق كل الشاشات */
.training-bar { position: sticky; top: 0; z-index: 70; background: #c2410c; color: #fff; text-align: center; font-weight: 800; padding: 8px 12px; letter-spacing: 0.2px; }
.training-bar[hidden] { display: none; }
.training-bar.fixed { position: fixed; inset: 0 0 auto 0; }

/* المرحلة 7: رسم التأخير الأسبوعي في مؤشرات الأداء */
.mini-chart rect { fill: var(--accent); }
.mini-chart text { font-size: 10px; fill: var(--muted); }

/* المرحلة 8: داش بورد علي وأحمد */
.dash-section > summary { cursor: pointer; list-style: none; }
.dash-section > summary::-webkit-details-marker { display: none; }
.dash-section > summary h2::before { content: '◂ '; color: var(--muted); }
.dash-section[open] > summary h2::before { content: '▾ '; }
.dash-section { margin-top: 14px; }
.cards.big .stat .v { font-size: 1.6rem; }
.chart-wrap { margin-top: 12px; }
.chart { width: 100%; height: auto; max-height: 260px; display: block; direction: ltr; }
.chart .grid { stroke: var(--line); }
.chart .axis { font-size: 13px; fill: var(--muted); }
.scope { color: #8a5a00; }
.legend { display: flex; flex-wrap: wrap; gap: 10px; font-size: 0.85rem; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-inline-end: 4px; vertical-align: middle; }
.note-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 8px; }
.rule-row { border-top: 1px solid var(--line); padding-top: 10px; margin-top: 10px; }
.dash-filters label.field { min-width: 0; }
@media (max-width: 600px) {
  .dash-filters { display: grid; grid-template-columns: 1fr; }
  .dash-filters .date-field { grid-template-columns: 0.9fr 1.5fr 1.2fr; }
  .dash-filters .date-field select { min-width: 0; padding: 10px 4px; }
  .note-row { flex-direction: column; align-items: stretch; }
}

/* ===== قرار علي (بعد المرحلة 9): الكلام ما يتداخلش ولا يتقص في أي شاشة =====
   كل التابات والزراير وعناوين الأعمدة والخانات بتكبر على قد الكلام، ولو المكان ضيق الكلام بينزل سطر جديد */
.btn, .tabs button, .chip, .tag, .badge, table.list th, label.field > span, .nav a, .stat .l, summary h2 {
  white-space: normal; overflow-wrap: break-word; min-width: 0;
}
.btn { text-align: center; max-width: 100%; height: auto; line-height: 1.5; }
.btn.small { line-height: 1.4; }
/* التابات بتنزل سطر تاني بدل ما تستخبى برّه الشاشة */
.tabs { flex-wrap: wrap; overflow-x: visible; row-gap: 2px; }
.tabs button { text-align: center; flex: 0 1 auto; }
/* خانات التاريخ (اليوم والشهر والسنة): كل خانة على قد الكلام اللي فيها، ولو مفيش مكان بتنزل سطر */
.date-field { display: flex; flex-wrap: wrap; gap: 6px; }
.date-field select,
.custody-filters .date-field select,
.dash-filters .date-field select { flex: 1 1 auto; width: auto; min-width: max-content; padding-inline: 8px 28px; }
/* أي قايمة اختيار تانية: ما تعدّيش عرض مكانها */
select { max-width: 100%; }
/* فلاتر الصفحات: الخانة بتاخد عرض الكلام على الأقل */
.filters label.field { min-width: min(150px, 100%); }
/* عناوين الأعمدة على الكمبيوتر: بتنزل سطر جوه العمود */
table.list th { overflow-wrap: break-word; }
