/* ===== Chat System Styles ===== */

/* Floating Chat Trigger */
.chat-trigger {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 60px;
  height: 60px;
  background: linear-gradient(135deg, #d4a853, #b88a44);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  box-shadow: 0 8px 24px rgba(212,168,83,0.3);
  cursor: pointer;
  z-index: 9999;
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.3s;
}
.chat-trigger:hover {
  transform: scale(1.08) translateY(-4px);
  box-shadow: 0 12px 28px rgba(212,168,83,0.4);
}
.chat-trigger .chat-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  background: #ef4444;
  color: white;
  font-size: 0.75rem;
  font-weight: bold;
  padding: 2px 6px;
  border-radius: 10px;
  border: 2px solid #0d1220;
  display: none;
}

/* Chat Widget Container */
.chat-widget {
  position: fixed;
  bottom: 96px;
  right: 24px;
  width: min(380px, calc(100vw - 48px));
  height: 600px;
  max-height: calc(100vh - 120px);
  background: rgba(13, 18, 32, 0.95);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 24px;
  box-shadow: 0 16px 40px rgba(0,0,0,0.4);
  display: flex;
  flex-direction: column;
  z-index: 9998;
  opacity: 0;
  pointer-events: none;
  transform: translateY(20px) scale(0.95);
  transition: 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  overflow: hidden;
}
.chat-widget.active {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0) scale(1);
}

/* Header */
.chat-header {
  padding: 16px 20px;
  background: rgba(255,255,255,0.03);
  border-bottom: 1px solid rgba(255,255,255,0.05);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.chat-header-title {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #fff;
  font-weight: 700;
  font-size: 1.1rem;
}
.chat-back-btn {
  background: none;
  border: none;
  color: #d4a853;
  cursor: pointer;
  display: none;
  padding: 0;
}
.chat-close-btn {
  background: none;
  border: none;
  color: rgba(255,255,255,0.5);
  cursor: pointer;
  transition: 0.2s;
  padding: 4px;
}
.chat-close-btn:hover {
  color: #fff;
}

/* Views (Inbox vs Active Chat) */
.chat-body {
  flex: 1;
  position: relative;
  overflow: hidden;
}
.chat-view {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  transition: transform 0.3s ease;
}
.chat-inbox-view {
  transform: translateX(0);
}
.chat-active-view {
  transform: translateX(100%);
}
body[dir="rtl"] .chat-active-view {
  transform: translateX(-100%);
}

.chat-widget[data-view="active"] .chat-inbox-view {
  transform: translateX(100%);
}
body[dir="rtl"] .chat-widget[data-view="active"] .chat-inbox-view {
  transform: translateX(100%);
}
.chat-widget[data-view="active"] .chat-active-view {
  transform: translateX(0) !important;
}

/* Inbox View */
.chat-inbox-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}
.chat-inbox-empty {
  text-align: center;
  padding: 40px 20px;
  color: rgba(255,255,255,0.4);
}
.chat-inbox-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: 12px;
  background: rgba(255,255,255,0.02);
  cursor: pointer;
  transition: 0.2s;
  margin-bottom: 8px;
  border: 1px solid transparent;
}
.chat-inbox-item:hover {
  background: rgba(255,255,255,0.05);
  border-color: rgba(212,168,83,0.2);
}
.chat-inbox-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: #1e293b;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border: 2px solid rgba(212,168,83,0.3);
}
.chat-inbox-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.chat-inbox-info {
  flex: 1;
  overflow: hidden;
}
.chat-inbox-name {
  font-weight: 700;
  color: #fff;
  font-size: 0.95rem;
  margin-bottom: 4px;
}
.chat-inbox-preview {
  font-size: 0.8rem;
  color: rgba(255,255,255,0.5);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-inbox-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}
.chat-inbox-time {
  font-size: 0.7rem;
  color: rgba(255,255,255,0.4);
}
.chat-inbox-unread {
  background: #d4a853;
  color: #000;
  font-size: 0.7rem;
  font-weight: bold;
  padding: 2px 6px;
  border-radius: 10px;
}

/* Active Chat View */
.chat-item-context {
  padding: 10px 16px;
  background: rgba(0,0,0,0.3);
  border-bottom: 1px solid rgba(255,255,255,0.05);
  display: flex;
  align-items: center;
  gap: 12px;
}
.chat-item-context img {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  object-fit: cover;
}
.chat-item-context-details {
  flex: 1;
  overflow: hidden;
}
.chat-item-context-title {
  font-size: 0.85rem;
  color: #fff;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-item-context-price {
  font-size: 0.8rem;
  color: #d4a853;
}

.chat-messages {
  flex: 1;
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.chat-msg {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 0.9rem;
  line-height: 1.4;
  position: relative;
}
.chat-msg.received {
  align-self: flex-start;
  background: rgba(255,255,255,0.05);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.chat-msg.sent {
  align-self: flex-end;
  background: linear-gradient(135deg, #d4a853, #b88a44);
  color: #000;
  border-bottom-left-radius: 4px;
}
.chat-msg-time {
  font-size: 0.65rem;
  opacity: 0.6;
  margin-top: 4px;
  text-align: right;
  display: block;
}

/* حالة إرسال رسائلي: ⏳ معلّقة ← ✓ أُرسلت / ⚠️ لم تُرسل */
.chat-msg.sent.pending {
  opacity: 0.75;
}
.chat-msg.sent.failed {
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.5);
  color: #fff;
}
.chat-msg.sent.failed .chat-msg-time {
  opacity: 1;
}
.chat-msg-status {
  margin-inline-start: 4px;
  font-weight: 700;
}
.chat-msg-status.warn {
  color: #7c2d12;
}
.chat-msg-status.err {
  color: #fca5a5;
}
.chat-msg-action {
  margin-inline-start: 6px;
  padding: 2px 8px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  font-family: inherit;
  font-size: 0.7rem;
  cursor: pointer;
}

/* Input Area */
.chat-input-area {
  padding: 16px;
  background: rgba(255,255,255,0.02);
  border-top: 1px solid rgba(255,255,255,0.05);
  display: flex;
  gap: 10px;
}
.chat-input {
  flex: 1;
  background: rgba(0,0,0,0.3);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 20px;
  padding: 10px 16px;
  color: #fff;
  font-family: inherit;
  font-size: 0.9rem;
  transition: 0.2s;
  resize: none;
  height: 40px;
  max-height: 100px;
}
.chat-input:focus {
  outline: none;
  border-color: #d4a853;
}
.chat-send-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #d4a853;
  border: none;
  color: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: 0.2s;
}
.chat-send-btn:hover {
  transform: scale(1.05);
  background: #e5b964;
}
.chat-send-btn:disabled {
  background: rgba(255,255,255,0.1);
  color: rgba(255,255,255,0.3);
  cursor: not-allowed;
  transform: none;
}

/* Mobile responsiveness */
@media (max-width: 768px) {
  .chat-widget {
    bottom: 0;
    right: 0;
    width: 100vw;
    height: 100vh;
    max-height: 100vh;
    border-radius: 0;
  }
}

/* أهداف اللمس (موبايل) */
@media (max-width: 768px) {
  .chat-close-btn { min-width: 44px; min-height: 44px; }
}
