/* ============================================
   صفحة مراسلة الدعم - مطابق لـ lib/view/home/chat_page.dart
   ============================================ */

.chat-page {
  background-color: #F5F5F5;
  height: 100vh;
  width: 100%;
  overflow: hidden;
  box-sizing: border-box;
}

.chat-main {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 800px;
  margin: 0 auto;
  overflow: hidden;
}

/* الهيدر - مثل التطبيق */
.chat-header {
  display: flex;
  flex-direction: row-reverse;
  align-items: center;
  padding: 12px 16px;
  background: #F5F5F5;
  flex-shrink: 0;
  gap: 12px;
}

.chat-header-back {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  text-decoration: none;
  color: inherit;
}

.chat-header-back img {
  width: 24px;
  height: 19px;
  object-fit: contain;
}

.chat-header-title {
  flex: 1;
  font-size: 14px;
  font-weight: 800;
  color: #515459;
  margin: 0;
  text-align: right;
}

.chat-header-icon-wrap {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #8FAEA6;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.chat-header-icon {
  width: 20px;
  height: 20px;
  object-fit: contain;
  filter: brightness(0) invert(1);
}

/* منطقة الرسائل - خلفية مغايرة لتمييز المحادثة (يجب أن تكون قابلة للتمرير) */
.chat-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px 16px 16px;
  display: flex;
  flex-direction: column;
  background-color: #E8ECEB;
  -webkit-overflow-scrolling: touch;
}

.chat-loading,
.chat-empty,
.chat-older-loading {
  padding: 24px;
  text-align: center;
  font-size: 14px;
  font-weight: 600;
  color: #515459;
}

.chat-older-loading {
  flex-shrink: 0;
}

.chat-load-older-wrap {
  flex-shrink: 0;
  padding: 12px 16px;
  text-align: center;
}

.chat-load-older-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 20px;
  font-size: 13px;
  font-weight: 700;
  font-family: var(--font-arabic);
  color: #457667;
  background: #fff;
  border: 1px solid #8FAEA6;
  border-radius: 12px;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

.chat-load-older-btn:hover:not(:disabled) {
  background: #f0f7f5;
  border-color: #457667;
}

.chat-load-older-btn:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}

.chat-messages {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* فقاعة رسالة */
.chat-msg {
  display: flex;
  flex-direction: row-reverse;
  align-items: flex-start;
  gap: 6px;
  max-width: 100%;
}

/* رسائل المستخدم: على اليمين */
.chat-msg--user {
  flex-direction: row;
  justify-content: flex-start;
  margin-right: 0;
  margin-left: auto;
}

/* رسائل الدعم: على اليسار */
.chat-msg--admin {
  flex-direction: row-reverse;
  justify-content: flex-end;
  margin-right: auto;
  margin-left: 0;
}

.chat-msg__bubble {
  max-width: 267px;
  padding: 11px 13px;
  border-radius: 12px;
  font-size: 12.8px;
  font-weight: 800;
  line-height: 1.4;
  word-break: break-word;
}

.chat-msg--user .chat-msg__bubble {
  background: #457667;
  color: #FBFAF8;
  border-top-right-radius: 0;
}

.chat-msg--admin .chat-msg__bubble {
  background: #515459;
  color: #FBFAF8;
  border-top-left-radius: 0;
}

.chat-msg__bubble img.chat-msg__img {
  display: block;
  max-width: 200px;
  max-height: 200px;
  border-radius: 8px;
  margin-top: 4px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.chat-msg__bubble img.chat-msg__img:hover {
  transform: scale(1.02);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.chat-msg__status {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  margin-top: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chat-msg__status--sending {
  color: #8FAEA6;
}

.chat-msg__status--sent {
  color: #22c55e;
}

.chat-msg__status--error {
  color: #ef4444;
}

.chat-msg__spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(143, 174, 166, 0.3);
  border-top-color: #8FAEA6;
  border-radius: 50%;
  animation: chat-spin 0.8s linear infinite;
}

@keyframes chat-spin {
  to { transform: rotate(360deg); }
}

.chat-msg__avatar {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #8FAEA6;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chat-msg__avatar img {
  width: 20px;
  height: 20px;
  object-fit: contain;
  filter: brightness(0) invert(1);
}

/* الفوتر - حقل الإدخال وإرسال */
.chat-footer {
  flex-shrink: 0;
  padding: 12px 16px;
  padding-bottom: max(16px, var(--safe-area-inset-bottom));
  background: #F5F5F5;
  display: flex;
  align-items: center;
  gap: 9px;
  box-sizing: border-box;
  z-index: 50;
}

.chat-input-wrap {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
  padding: 0 8px 0 16px;
  min-height: 48px;
}

.chat-input {
  flex: 1;
  min-width: 0;
  border: none;
  padding: 12px 8px;
  font-size: 14px;
  font-family: var(--font-arabic);
  color: var(--text-primary);
  background: transparent;
  outline: none;
}

.chat-input::placeholder {
  color: #9ca3af;
}

.chat-attach {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  padding: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #8FAEA6;
}

.chat-attach img {
  width: 21px;
  height: 21px;
  object-fit: contain;
}

.chat-send {
  flex-shrink: 0;
  width: 48px;
  height: 48px;
  border-radius: 16px;
  background: #457667;
  border: none;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
}

.chat-send:hover {
  background: #3d6a5c;
}

.chat-send:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}

.chat-send svg {
  display: block;
}

/* زر النزول للأسفل العائم */
.chat-scroll-down-btn {
  position: absolute;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%);
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: #457667;
  border: none;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(69, 118, 103, 0.3);
  z-index: 100;
  transition: all 0.3s ease;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

.chat-scroll-down-btn:hover {
  background: #3d6a5c;
  box-shadow: 0 6px 16px rgba(69, 118, 103, 0.4);
  transform: translateX(-50%) scale(1.05);
}

.chat-scroll-down-btn:active {
  transform: translateX(-50%) scale(0.95);
}

.chat-scroll-down-btn svg {
  display: block;
}

/* Modal عرض الصورة بحجم كامل */
.chat-image-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: modalFadeIn 0.3s ease;
}

@keyframes modalFadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.chat-image-modal__overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.9);
  cursor: pointer;
}

.chat-image-modal__content {
  position: relative;
  max-width: 90%;
  max-height: 90vh;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chat-image-modal__img {
  max-width: 100%;
  max-height: 90vh;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  animation: imageZoomIn 0.3s ease;
}

@keyframes imageZoomIn {
  from {
    transform: scale(0.8);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

.chat-image-modal__close {
  position: absolute;
  top: -50px;
  right: 0;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.9);
  border: none;
  color: #333;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  z-index: 2;
}

.chat-image-modal__close:hover {
  background: #fff;
  transform: scale(1.1);
}

.chat-image-modal__close:active {
  transform: scale(0.95);
}

.chat-image-modal__close svg {
  display: block;
}

/* مؤشر تحميل رفع الصورة */
.chat-upload-loader {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chat-upload-loader__overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
}

.chat-upload-loader__content {
  position: relative;
  z-index: 1;
  background: #fff;
  padding: 32px 40px;
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
  animation: loaderFadeIn 0.3s ease;
}

@keyframes loaderFadeIn {
  from {
    opacity: 0;
    transform: scale(0.9);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.chat-upload-loader__spinner {
  width: 48px;
  height: 48px;
  border: 4px solid #E8ECEB;
  border-top-color: #457667;
  border-radius: 50%;
  animation: loaderSpin 0.8s linear infinite;
}

@keyframes loaderSpin {
  to {
    transform: rotate(360deg);
  }
}

.chat-upload-loader__text {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  color: #515459;
  font-family: var(--font-arabic);
}

@media (min-width: 768px) {
  .chat-msg__bubble {
    max-width: 320px;
  }
  
  .chat-image-modal__content {
    max-width: 80%;
  }
}
