/**
 * assets/css/app.css — مكوّنات الحالة التي لم تكن في الـmock.
 *
 * ملف منفصل عن style.css عمداً: هذا كله إضافات ربط البيانات (تحميل، فراغ،
 * خطأ، رسائل)، وفصله يجعل التراجع عنه ممكناً بسطر واحد دون المساس بالتصميم.
 * كل الألوان من متغيّرات style.css نفسها فلا يوجد لون مكتوب مرتين.
 */

/* ---------- الصورة الرمزية بالحروف الأولى ---------- */
.avatar-initials {
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: color-mix(in srgb, var(--color-primary) 14%, var(--color-surface));
  color: var(--color-primary);
  font-weight: 700;
  flex-shrink: 0;
  user-select: none;
  letter-spacing: -0.02em;
}

/* ---------- هيكل التحميل ---------- */
.skeleton-wrap { display: flex; flex-direction: column; gap: 12px; }

.skeleton-card {
  height: 84px;
  border-radius: var(--radius-md);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  position: relative;
  overflow: hidden;
}

.skeleton-card::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg,
    transparent, color-mix(in srgb, var(--color-foreground) 5%, transparent), transparent);
  animation: skeleton-sweep 1.4s ease-in-out infinite;
}

@keyframes skeleton-sweep {
  from { transform: translateX(100%); }
  to   { transform: translateX(-100%); }
}

/* حركة لا نهائية تُتعب من لديه حساسية للحركة، والقاعدة تحترم إعداد النظام. */
@media (prefers-reduced-motion: reduce) {
  .skeleton-card::after { animation: none; }
  .toast { transition: none; }
}

/* ---------- الفراغ والخطأ ---------- */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 48px 24px;
  color: var(--color-muted);
}

.empty-icon {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: color-mix(in srgb, var(--color-primary) 8%, transparent);
  color: var(--color-primary);
  margin-bottom: 16px;
}

.empty-icon.is-error {
  background: color-mix(in srgb, #DC2626 10%, transparent);
  color: #DC2626;
}

.empty-title  { font-size: 16px; font-weight: 600; color: var(--color-foreground); }
.empty-desc   { font-size: 13px; margin-top: 6px; max-width: 34ch; line-height: 1.6; }

/* ---------- الرسائل العابرة ---------- */
#toast-host {
  position: fixed;
  bottom: 92px;               /* فوق شريط التنقّل السفلي */
  left: 0; right: 0;
  display: flex;
  justify-content: center;
  padding: 0 20px;
  pointer-events: none;
  z-index: 1000;
}

.toast {
  max-width: 560px;
  width: 100%;
  padding: 14px 18px;
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-foreground);
  border: 1px solid var(--color-border);
  box-shadow: var(--shadow-glass);
  font-size: 14px;
  line-height: 1.6;
  text-align: center;
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 220ms ease, transform 220ms ease;
}

.toast.is-visible { opacity: 1; transform: translateY(0); }
.toast.is-error   { border-color: color-mix(in srgb, #DC2626 45%, var(--color-border)); }
.toast.is-success { border-color: color-mix(in srgb, var(--color-accent) 45%, var(--color-border)); }

/* ---------- شارة عدد الإشعارات ---------- */
.icon-btn { position: relative; }

.unread-badge {
  position: absolute;
  top: 2px;
  inset-inline-end: 2px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--color-primary);
  color: var(--color-on-primary);
  font-size: 10px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--color-background);
}

.unread-badge[hidden] { display: none; }

/* ---------- شارة الحالة الملوّنة ---------- */
/* اللون يأتي من ERP (tm_list_statuses.color) عبر متغيّر مضبوط في السطر،
   فتظل الحالات متطابقة بين الويب والجوال بلا جدول ألوان ثانٍ هنا. */
.status-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 600;
  background: color-mix(in srgb, var(--chip) 16%, transparent);
  color: var(--chip);
  border: 1px solid color-mix(in srgb, var(--chip) 30%, transparent);
  white-space: nowrap;
}

.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--chip);
  flex-shrink: 0;
}

/* ---------- شرائح المعدات ---------- */
.chip-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  background: var(--color-surface-hover);
  border: 1px solid var(--color-border);
  font-size: 13px;
  font-weight: 500;
}

.chip small { color: var(--color-muted); font-size: 11px; }

/* ---------- قائمة الحالات (ورقة سفلية) ---------- */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  z-index: 1100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.sheet {
  width: 100%;
  max-width: 600px;
  background: var(--color-surface);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: 20px 20px calc(20px + env(safe-area-inset-bottom));
  max-height: 80dvh;
  overflow-y: auto;
}

.sheet-title { font-size: 16px; font-weight: 700; margin-bottom: 16px; }

.sheet-option {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 14px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--color-foreground);
  font: inherit;
  font-size: 15px;
  text-align: start;
  cursor: pointer;
  margin-bottom: 8px;
  transition: background 180ms ease, border-color 180ms ease;
}

.sheet-option:hover  { background: var(--color-surface-hover); }
.sheet-option:focus-visible,
.chip:focus-visible,
.date-pill:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; }
.sheet-option[aria-current="true"] { border-color: var(--color-primary); }

/* ---------- التعليقات ---------- */
.comment { display: flex; gap: 12px; padding: 14px 0; border-bottom: 1px solid var(--color-border); }
.comment:last-child { border-bottom: none; }
.comment-body   { flex: 1; min-width: 0; }
.comment-author { font-size: 13px; font-weight: 600; }
.comment-time   { font-size: 11px; color: var(--color-muted); }
.comment-text   { font-size: 14px; margin-top: 4px; line-height: 1.6; white-space: pre-wrap; overflow-wrap: anywhere; }

.comment-form { display: flex; gap: 8px; margin-top: 16px; align-items: flex-end; }

.comment-form textarea {
  flex: 1;
  min-height: 44px;
  max-height: 140px;
  padding: 12px 14px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-background);
  color: var(--color-foreground);
  font: inherit;
  font-size: 15px;       /* أقل من 16px يجعل سفاري يكبّر الصفحة تلقائياً عند الكتابة */
  resize: none;
}

.comment-form textarea:focus {
  outline: none;
  border-color: var(--color-primary);
}

.comment-send {
  width: 44px; height: 44px;
  border-radius: var(--radius-sm);
  border: none;
  background: var(--color-primary);
  color: var(--color-on-primary);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}

.comment-send:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- المهام الفرعية ---------- */
.subtask {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  cursor: pointer;
}

.subtask input { width: 20px; height: 20px; accent-color: var(--color-primary); cursor: pointer; }
.subtask.is-done span { text-decoration: line-through; color: var(--color-muted); }

/* ---------- الأزرار المعطَّلة ---------- */
.btn:disabled, .icon-btn:disabled { opacity: 0.55; cursor: not-allowed; }

/* ---------- شريط المؤقّت ---------- */
.timer-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--color-accent) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--color-accent) 30%, transparent);
  margin-top: 16px;
  font-size: 14px;
  font-weight: 600;
}

.timer-bar.is-idle {
  background: var(--color-surface-hover);
  border-color: var(--color-border);
  font-weight: 500;
}

/* أيام الشريط صارت <button> لتعمل بلوحة المفاتيح وقارئ الشاشة.
   الأزرار لا ترث الخط من الصفحة، فبدون هذا السطر يظهر يوم واحد بخط النظام. */
button.date-pill { font-family: inherit; }

/* ---------- من ينزل معي اليوم ---------- */
.crew-bar {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px 16px;
  margin-bottom: 14px;
  border-radius: var(--radius-md);
  background: color-mix(in srgb, var(--color-primary) 7%, var(--color-surface));
  border: 1px solid color-mix(in srgb, var(--color-primary) 20%, transparent);
}

.crew-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 700;
  color: var(--color-primary);
}

.crew-avatars { display: flex; align-items: center; }

/* تراكب خفيف: الطاقم مجموعة واحدة لا قائمة منفصلة */
.crew-avatars > * { margin-inline-start: -8px; }
.crew-avatars > *:first-child { margin-inline-start: 0; }
.crew-avatars .avatar-initials { border: 2px solid var(--color-surface); }

.crew-more {
  width: 32px; height: 32px;
  border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--color-surface-hover);
  border: 2px solid var(--color-surface);
  color: var(--color-muted);
  font-size: 11px; font-weight: 700;
}

/* الحروف الأولى وحدها لا تُعرِّف أحداً — الأسماء تظهر نصاً كذلك */
.crew-names { font-size: 12px; color: var(--color-muted); line-height: 1.6; }

/* ---------- تجميع القوائم ---------- */
.group-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--color-muted);
  margin: 24px 0 12px;
  letter-spacing: 0.04em;
}

.group-title:first-child { margin-top: 8px; }
