/* ============================================================
   chat.css — واجهة المحادثة (مشتركة بين لوحة الأدمن ولوحة التاجر)
   دعم RTL كامل
   ============================================================ */

:root {
  --chat-bg: #f6f7fb;
  --chat-surface: #ffffff;
  --chat-border: #e5e7eb;
  --chat-text: #1f2937;
  --chat-muted: #6b7280;
  --chat-primary: #4f46e5;
  --chat-primary-soft: #eef2ff;
  --chat-bubble-me: #4f46e5;
  --chat-bubble-me-text: #ffffff;
  --chat-bubble-other: #ffffff;
  --chat-radius: 14px;
  --chat-shadow: 0 1px 3px rgba(16, 24, 40, 0.08);
}

.chat-wrap {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 16px;
  height: calc(100vh - 140px);
  min-height: 480px;
  font-family: inherit;
  color: var(--chat-text);
}

.chat-wrap.chat-single {
  grid-template-columns: 1fr;
}

/* ---------- قائمة المحادثات ---------- */

.chat-sidebar {
  background: var(--chat-surface);
  border: 1px solid var(--chat-border);
  border-radius: var(--chat-radius);
  box-shadow: var(--chat-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-sidebar__head {
  padding: 14px 16px;
  border-bottom: 1px solid var(--chat-border);
}

.chat-sidebar__head h3 {
  margin: 0 0 10px;
  font-size: 16px;
  font-weight: 700;
}

.chat-search {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--chat-border);
  border-radius: 10px;
  font: inherit;
  outline: none;
}

.chat-search:focus {
  border-color: var(--chat-primary);
  box-shadow: 0 0 0 3px var(--chat-primary-soft);
}

.chat-list {
  list-style: none;
  margin: 0;
  padding: 6px;
  overflow-y: auto;
  flex: 1;
}

.chat-list__item {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  width: 100%;
  padding: 10px;
  border: 0;
  background: transparent;
  border-radius: 10px;
  cursor: pointer;
  text-align: start;
  font: inherit;
  color: inherit;
}

.chat-list__item:hover {
  background: var(--chat-bg);
}

.chat-list__item[aria-current='true'] {
  background: var(--chat-primary-soft);
}

.chat-list__item:focus-visible {
  outline: 2px solid var(--chat-primary);
  outline-offset: 2px;
}

.chat-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--chat-bg);
  flex: 0 0 auto;
}

.chat-list__body {
  min-width: 0;
  flex: 1;
}

.chat-list__name {
  display: block;
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-list__preview {
  display: block;
  font-size: 12.5px;
  color: var(--chat-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.chat-list__meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  flex: 0 0 auto;
}

.chat-time {
  font-size: 11px;
  color: var(--chat-muted);
  white-space: nowrap;
}

.chat-badge {
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: #ef4444;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

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

/* ---------- لوحة المحادثة ---------- */

.chat-panel {
  background: var(--chat-surface);
  border: 1px solid var(--chat-border);
  border-radius: var(--chat-radius);
  box-shadow: var(--chat-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

.chat-panel__head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--chat-border);
}

.chat-panel__title {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
}

.chat-panel__sub {
  font-size: 12px;
  color: var(--chat-muted);
}

.chat-panel__actions {
  margin-inline-start: auto;
  display: flex;
  gap: 8px;
}

.chat-btn {
  padding: 8px 14px;
  border-radius: 10px;
  border: 1px solid var(--chat-border);
  background: #fff;
  font: inherit;
  cursor: pointer;
}

.chat-btn:hover {
  background: var(--chat-bg);
}

.chat-btn--primary {
  background: var(--chat-primary);
  border-color: var(--chat-primary);
  color: #fff;
}

.chat-btn--primary:hover {
  filter: brightness(0.94);
}

.chat-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.chat-status {
  font-size: 11.5px;
  padding: 3px 9px;
  border-radius: 999px;
  background: #dcfce7;
  color: #166534;
}

.chat-status--closed {
  background: #fee2e2;
  color: #991b1b;
}

/* ---------- الرسائل ---------- */

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px;
  background: var(--chat-bg);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.chat-day {
  align-self: center;
  font-size: 11.5px;
  color: var(--chat-muted);
  background: #fff;
  border: 1px solid var(--chat-border);
  padding: 3px 12px;
  border-radius: 999px;
}

.chat-msg {
  max-width: min(72%, 560px);
  padding: 10px 13px;
  border-radius: 14px;
  background: var(--chat-bubble-other);
  border: 1px solid var(--chat-border);
  align-self: flex-start;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}

.chat-msg--mine {
  align-self: flex-end;
  background: var(--chat-bubble-me);
  border-color: var(--chat-bubble-me);
  color: var(--chat-bubble-me-text);
}

.chat-msg__sender {
  display: block;
  font-size: 11.5px;
  font-weight: 700;
  opacity: 0.8;
  margin-bottom: 3px;
}

.chat-msg__body {
  margin: 0;
  font-size: 14px;
  line-height: 1.6;
  white-space: pre-wrap;
}

.chat-msg__file {
  display: inline-block;
  margin-top: 6px;
  font-size: 13px;
  text-decoration: underline;
  color: inherit;
}

.chat-msg__time {
  display: block;
  font-size: 10.5px;
  opacity: 0.7;
  margin-top: 5px;
  text-align: end;
}

.chat-empty {
  margin: auto;
  text-align: center;
  color: var(--chat-muted);
  font-size: 14px;
  padding: 30px;
}

/* ---------- مربع الكتابة ---------- */

.chat-composer {
  border-top: 1px solid var(--chat-border);
  padding: 12px;
  background: #fff;
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.chat-composer__input {
  flex: 1;
  resize: none;
  min-height: 44px;
  max-height: 150px;
  padding: 11px 13px;
  border: 1px solid var(--chat-border);
  border-radius: 12px;
  font: inherit;
  line-height: 1.5;
  outline: none;
}

.chat-composer__input:focus {
  border-color: var(--chat-primary);
  box-shadow: 0 0 0 3px var(--chat-primary-soft);
}

.chat-attach {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: 1px solid var(--chat-border);
  cursor: pointer;
  background: #fff;
  font-size: 18px;
}

.chat-attach:hover {
  background: var(--chat-bg);
}

.chat-attach input {
  display: none;
}

.chat-attach__label {
  font-size: 12px;
  color: var(--chat-muted);
  padding: 0 8px;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-alert {
  margin: 10px 12px 0;
  padding: 9px 12px;
  border-radius: 10px;
  background: #fef2f2;
  color: #991b1b;
  font-size: 13px;
}

.chat-alert[hidden] {
  display: none;
}

.chat-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- مؤشر الحضور اللحظي (liveDot) ---------- */

.chat-live {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  color: var(--chat-muted);
  margin-inline-start: 8px;
  vertical-align: middle;
  transition: color 0.3s;
}

.chat-live--on {
  color: #16a34a;
}

.chat-live__dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--chat-muted);
  transition: background 0.3s;
}

.chat-live--on .chat-live__dot {
  background: #16a34a;
  animation: chatLivePulse 1.8s ease-in-out infinite;
}

.chat-live__text {
  line-height: 1;
}

@keyframes chatLivePulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.35; }
}

/* ---------- علامة القراءة (tick ✓ / ✓✓) ---------- */

.chat-msg__tick {
  display: inline-flex;
  gap: 1px;
  margin-inline-start: 5px;
  font-size: 11px;
  opacity: 0.7;
  vertical-align: bottom;
}

.chat-msg__tick--read {
  opacity: 1;
  color: #3b82f6;
}

/* ---------- توست إشعار الرسائل الجديدة ---------- */

.chat-toast {
  position: fixed;
  bottom: 24px;
  inset-inline-start: 24px;
  max-width: 380px;
  padding: 12px 18px;
  border-radius: 12px;
  background: #1e293b;
  color: #f8fafc;
  font-size: 13.5px;
  line-height: 1.5;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  z-index: 99999;
  pointer-events: none;
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 0.35s, transform 0.35s;
}

.chat-toast--show {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

/* ---------- الشاشات الصغيرة ---------- */

@media (max-width: 860px) {
  .chat-wrap {
    grid-template-columns: 1fr;
    height: auto;
  }
  .chat-sidebar {
    max-height: 300px;
  }
  .chat-messages {
    height: 55vh;
  }
  .chat-msg {
    max-width: 88%;
  }

  .chat-toast {
    max-width: calc(100vw - 32px);
    inset-inline-start: 16px;
    bottom: 16px;
  }
}
