/**
 * Conversations Page Styles
 * Modern WhatsApp-style layout with RTL support
 * Features: Claim system, sender info, transfer functionality
 * 
 * @module public/admin/css/conversations.css
 */

/* ============================================
   WHATSAPP-STYLE CONTAINER
   ============================================ */
.whatsapp-container {
  display: flex;
  height: calc(100vh - 100px);
  min-height: 500px;
  background: #f0f2f5;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

/* ============================================
   CONVERSATIONS SIDEBAR
   ============================================ */
.conversations-sidebar {
  width: 380px;
  min-width: 320px;
  max-width: 420px;
  background: #ffffff;
  border-right: 1px solid #e9edef;
  display: flex;
  flex-direction: column;
}

[dir="rtl"] .conversations-sidebar {
  border-right: none;
  border-left: 1px solid #e9edef;
}

/* Sidebar Header */
.sidebar-header {
  padding: 1rem;
  background: linear-gradient(135deg, #00a884 0%, #25D366 100%);
  color: white;
}

.sidebar-header-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
}

.sidebar-header h3 {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: white;
}

.sidebar-header h3 .count {
  background: rgba(255, 255, 255, 0.25);
  padding: 0.125rem 0.5rem;
  border-radius: 10px;
  font-size: 0.75rem;
  font-weight: 500;
}

.sidebar-header .icon-btn {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.sidebar-header .icon-btn:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* Search Container */
.search-container {
  position: relative;
  margin-bottom: 0.75rem;
}

.search-container input {
  width: 100%;
  padding: 0.625rem 1rem 0.625rem 2.5rem;
  border: none;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.95);
  font-size: 0.875rem;
  color: #111b21;
}

.search-container input::placeholder {
  color: #8696a0;
}

.search-container i {
  position: absolute;
  left: 0.875rem;
  top: 50%;
  transform: translateY(-50%);
  color: #8696a0;
}

[dir="rtl"] .search-container input {
  padding: 0.625rem 2.5rem 0.625rem 1rem;
}

[dir="rtl"] .search-container i {
  left: auto;
  right: 0.875rem;
}

/* Filter Tabs */
.filter-tabs {
  display: flex;
  gap: 0.375rem;
  flex-wrap: wrap;
}

.filter-tab {
  padding: 0.375rem 0.75rem;
  border: none;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.2);
  color: rgba(255, 255, 255, 0.9);
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.filter-tab:hover {
  background: rgba(255, 255, 255, 0.3);
}

.filter-tab.active {
  background: white;
  color: #25D366;
}

/* Sidebar Stats */
.sidebar-stats {
  display: flex;
  padding: 0.75rem 1rem;
  background: #f0f2f5;
  border-bottom: 1px solid #e9edef;
  gap: 0.5rem;
}

.mini-stat {
  flex: 1;
  text-align: center;
  padding: 0.5rem;
  background: white;
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.mini-stat-value {
  display: block;
  font-size: 1.125rem;
  font-weight: 700;
  color: #111b21;
}

.mini-stat-label {
  display: block;
  font-size: 0.625rem;
  color: #8696a0;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.mini-stat.waiting .mini-stat-value { color: #f0b429; }
.mini-stat.active .mini-stat-value { color: #25D366; }
.mini-stat.closed .mini-stat-value { color: #8696a0; }

/* ============================================
   CONVERSATIONS LIST
   ============================================ */
.conversations-list {
  flex: 1;
  overflow-y: auto;
  background: white;
}

.conversation-item {
  display: flex;
  align-items: center;
  padding: 0.875rem 1rem;
  cursor: pointer;
  transition: background 0.15s;
  border-bottom: 1px solid #f0f2f5;
  position: relative;
}

.conversation-item:hover {
  background: #f5f6f6;
}

.conversation-item.active {
  background: #f0f2f5;
}

.conversation-item.claimed {
  border-left: 4px solid #25D366;
}

[dir="rtl"] .conversation-item.claimed {
  border-left: none;
  border-right: 4px solid #25D366;
}

.conversation-item.transferred {
  border-left: 4px solid #f0b429;
}

[dir="rtl"] .conversation-item.transferred {
  border-left: none;
  border-right: 4px solid #f0b429;
}

.conversation-avatar {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: linear-gradient(135deg, #00a884 0%, #25D366 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 600;
  font-size: 1.25rem;
  margin-right: 0.875rem;
  flex-shrink: 0;
  position: relative;
}

[dir="rtl"] .conversation-avatar {
  margin-right: 0;
  margin-left: 0.875rem;
}

.conversation-avatar.bot {
  background: linear-gradient(135deg, #9b59b6 0%, #8e44ad 100%);
}

.conversation-content {
  flex: 1;
  min-width: 0;
}

.conversation-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.25rem;
}

.conversation-name {
  font-weight: 600;
  color: #111b21;
  font-size: 0.9375rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 180px;
}

.conversation-time {
  font-size: 0.6875rem;
  color: #8696a0;
  flex-shrink: 0;
  margin-left: 0.5rem;
}

[dir="rtl"] .conversation-time {
  margin-left: 0;
  margin-right: 0.5rem;
}

.conversation-preview {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.conversation-preview-text {
  font-size: 0.8125rem;
  color: #667781;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  max-width: 200px;
}

.conversation-meta {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  flex-shrink: 0;
}

/* Badges */
.unread-badge {
  background: #25D366;
  color: white;
  min-width: 20px;
  height: 20px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.6875rem;
  font-weight: 600;
  padding: 0 0.375rem;
}

.claimed-badge {
  background: #128C7E;
  color: white;
  padding: 0.125rem 0.5rem;
  border-radius: 8px;
  font-size: 0.625rem;
  font-weight: 500;
  white-space: nowrap;
}

.transferred-badge {
  background: #f0b429;
  color: #111b21;
  padding: 0.125rem 0.5rem;
  border-radius: 8px;
  font-size: 0.625rem;
  font-weight: 500;
  white-space: nowrap;
}

.status-indicator {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  position: absolute;
  bottom: 2px;
  right: 2px;
  border: 2px solid white;
}

.status-indicator.waiting { background: #f0b429; }
.status-indicator.attended { background: #00a884; }
.status-indicator.active { background: #25D366; }
.status-indicator.closed { background: #8696a0; }

/* ============================================
   MESSAGES PANEL
   ============================================ */
.messages-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #efeae2;
  position: relative;
  min-width: 0;
}

.messages-panel::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23d4d4d4' fill-opacity='0.12'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
  opacity: 0.6;
  pointer-events: none;
  z-index: 0;
}

/* Messages Header */
.messages-header {
  padding: 0.75rem 1rem;
  background: #f0f2f5;
  border-bottom: 1px solid #e9edef;
  display: flex;
  align-items: center;
  gap: 0.875rem;
  z-index: 1;
  min-height: 64px;
}

.messages-header-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: linear-gradient(135deg, #00a884 0%, #25D366 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 600;
  font-size: 1rem;
  flex-shrink: 0;
}

.messages-header-info {
  flex: 1;
  min-width: 0;
}

.messages-header-name {
  font-weight: 600;
  color: #111b21;
  font-size: 0.9375rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.messages-header-status {
  font-size: 0.75rem;
  color: #8696a0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.messages-header-actions {
  display: flex;
  gap: 0.5rem;
  flex-shrink: 0;
}

.header-action-btn {
  padding: 0.5rem 0.875rem;
  border: none;
  border-radius: 8px;
  background: white;
  color: #54656f;
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.375rem;
  transition: all 0.2s;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.header-action-btn:hover {
  background: #e9edef;
  transform: translateY(-1px);
}

.header-action-btn.primary {
  background: linear-gradient(135deg, #00a884 0%, #25D366 100%);
  color: white;
}

.header-action-btn.primary:hover {
  background: linear-gradient(135deg, #008f6f 0%, #1fb855 100%);
}

.header-action-btn.danger {
  background: #ea4335;
  color: white;
}

.header-action-btn.danger:hover {
  background: #c5221f;
}

.back-btn {
  display: none;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: #54656f;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  font-size: 1.125rem;
  transition: background 0.2s;
}

.back-btn:hover {
  background: rgba(0, 0, 0, 0.05);
}

/* Messages Content */
.messages-content {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  z-index: 1;
  display: flex;
  flex-direction: column;
}

.message-date-divider {
  text-align: center;
  margin: 1rem 0;
}

.message-date-divider span {
  background: #e1f3fb;
  color: #54656f;
  padding: 0.375rem 0.875rem;
  border-radius: 8px;
  font-size: 0.75rem;
  font-weight: 500;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

/* Message Bubble */
.message-bubble {
  display: flex;
  flex-direction: column;
  margin-bottom: 4px;
  max-width: 65%;
  animation: fadeIn 0.2s ease-out;
  border: none !important;
  outline: none !important;
}

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

.message-bubble.incoming {
  align-self: flex-start;
}

.message-bubble.outgoing {
  align-self: flex-end;
}

[dir="rtl"] .message-bubble.incoming {
  align-self: flex-end;
}

[dir="rtl"] .message-bubble.outgoing {
  align-self: flex-start;
}

.message-sender-label {
  font-size: 0.6875rem;
  font-weight: 600;
  margin-bottom: 0.125rem;
  padding: 0 0.375rem;
}

.message-bubble.incoming .message-sender-label {
  color: #667781;
}

.message-bubble.outgoing .message-sender-label {
  color: #25D366;
  text-align: right;
}

[dir="rtl"] .message-bubble.outgoing .message-sender-label {
  text-align: left;
}

.message-bubble.bot .message-sender-label {
  color: #9b59b6;
}

.message-content {
  padding: 6px 8px;
  border-radius: 8px;
  position: relative;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.1);
}

/* Override admin.css styles */
.messages-content .message-bubble .message-content {
  padding: 6px 8px;
  border-radius: 8px;
  position: relative;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.1);
  margin-bottom: 0;
  border-left: none;
  line-height: inherit;
}

.message-bubble.incoming .message-content {
  background: white;
  color: #111b21;
  border-top-left-radius: 0;
  border: none !important;
  outline: none !important;
}

[dir="rtl"] .message-bubble.incoming .message-content {
  border-top-left-radius: 8px;
  border-top-right-radius: 0;
}

.message-bubble.outgoing .message-content {
  background: #d9fdd3;
  color: #111b21;
  border-top-right-radius: 0;
  border: none !important;
  outline: none !important;
}

[dir="rtl"] .message-bubble.outgoing .message-content {
  border-top-right-radius: 8px;
  border-top-left-radius: 0;
}

.message-bubble.bot .message-content {
  background: #e8daef;
  color: #111b21;
}

.message-text {
  font-size: 14px;
  line-height: 1.3;
  word-wrap: break-word;
  white-space: pre-wrap;
}

.message-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  margin-top: 2px;
}

.message-time {
  font-size: 11px;
  color: #667781;
}

.message-status {
  font-size: 0.8125rem;
  color: #53bdeb;
}

/* Messages Footer */
.messages-footer {
  padding: 0.75rem 1rem;
  background: #f0f2f5;
  border-top: 1px solid #e9edef;
  z-index: 1;
}

.message-input-container {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.message-input {
  flex: 1;
  padding: 0.75rem 1rem;
  border: none;
  border-radius: 8px;
  background: white;
  font-size: 0.9375rem;
  color: #111b21;
  resize: none;
  max-height: 100px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.message-input::placeholder {
  color: #8696a0;
}

.message-input:focus {
  outline: none;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 0 0 2px rgba(37, 211, 102, 0.2);
}

.send-btn {
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: linear-gradient(135deg, #00a884 0%, #25D366 100%);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  box-shadow: 0 2px 6px rgba(37, 211, 102, 0.3);
}

.send-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 12px rgba(37, 211, 102, 0.4);
}

.send-btn:disabled {
  background: #8696a0;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

/* View Only Notice */
.view-only-notice {
  padding: 0.875rem 1rem;
  background: linear-gradient(135deg, #fff3cd 0%, #ffeeba 100%);
  display: flex;
  align-items: center;
  gap: 0.625rem;
  color: #856404;
  font-size: 0.8125rem;
  font-weight: 500;
  border-radius: 8px;
}

.view-only-notice i {
  color: #ffc107;
  font-size: 1rem;
}

/* Empty State */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: #8696a0;
  text-align: center;
  padding: 2rem;
  z-index: 1;
}

.empty-state i {
  font-size: 4rem;
  margin-bottom: 1rem;
  opacity: 0.4;
  color: #25D366;
}

.empty-state h3 {
  margin: 0 0 0.5rem 0;
  color: #111b21;
  font-weight: 600;
  font-size: 1.125rem;
}

.empty-state p {
  margin: 0;
  font-size: 0.875rem;
  max-width: 280px;
}

/* ============================================
   TRANSFER MODAL
   ============================================ */
.transfer-modal-content {
  padding: 1.5rem;
}

.transfer-options {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.transfer-option {
  padding: 1.25rem;
  border: 2px solid #e9edef;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s;
}

.transfer-option:hover {
  border-color: #25D366;
  background: #f0fff4;
}

.transfer-option.selected {
  border-color: #25D366;
  background: #d9fdd3;
}

.transfer-option h4 {
  margin: 0 0 0.75rem 0;
  color: #111b21;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.transfer-option h4 i {
  color: #25D366;
}

.transfer-option select {
  width: 100%;
  padding: 0.625rem;
  border: 1px solid #e9edef;
  border-radius: 8px;
  font-size: 0.875rem;
  background: white;
}

.transfer-option select:focus {
  outline: none;
  border-color: #25D366;
}

/* ============================================
   STATUS BADGES
   ============================================ */
.status-badge {
  padding: 0.25rem 0.625rem;
  border-radius: 12px;
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.status-badge.waiting {
  background: #fff3cd;
  color: #856404;
}

.status-badge.attended {
  background: #d1ecf1;
  color: #0c5460;
}

.status-badge.active {
  background: #d4edda;
  color: #155724;
}

.status-badge.closed {
  background: #e2e3e5;
  color: #383d41;
}

.status-badge.archived {
  background: #f8d7da;
  color: #721c24;
}

/* ============================================
   LOADING STATE
   ============================================ */
.loading-spinner {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3rem;
  color: #25D366;
}

.loading-spinner i {
  font-size: 2.5rem;
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 1024px) {
  .whatsapp-container {
    height: calc(100vh - 80px);
  }

  .conversations-sidebar {
    width: 100%;
    min-width: 100%;
    max-width: 100%;
  }

  .messages-panel {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
    border-radius: 0;
  }

  .messages-panel.active {
    display: flex;
  }

  .back-btn {
    display: flex;
  }

  .messages-header {
    padding-left: 0.5rem;
  }
}

@media (max-width: 768px) {
  .sidebar-stats {
    padding: 0.5rem;
    gap: 0.375rem;
  }

  .mini-stat {
    padding: 0.375rem;
  }

  .mini-stat-value {
    font-size: 1rem;
  }

  .mini-stat-label {
    font-size: 0.5625rem;
  }

  .filter-tabs {
    gap: 0.25rem;
  }

  .filter-tab {
    padding: 0.25rem 0.5rem;
    font-size: 0.6875rem;
  }

  .conversation-item {
    padding: 0.75rem;
  }

  .conversation-avatar {
    width: 44px;
    height: 44px;
    font-size: 1rem;
  }

  .conversation-name {
    font-size: 0.875rem;
    max-width: 140px;
  }

  .conversation-preview-text {
    max-width: 150px;
  }

  .message-bubble {
    max-width: 85%;
  }

  .header-action-btn span {
    display: none;
  }

  .header-action-btn {
    padding: 0.5rem;
    width: 36px;
    height: 36px;
    justify-content: center;
  }

  .messages-header-name {
    font-size: 0.875rem;
  }

  .messages-header-status {
    font-size: 0.6875rem;
  }
}

@media (max-width: 480px) {
  .sidebar-header {
    padding: 0.75rem;
  }

  .sidebar-header h3 {
    font-size: 1rem;
  }

  .search-container input {
    font-size: 0.8125rem;
    padding: 0.5rem 0.875rem 0.5rem 2.25rem;
  }

  .messages-content {
    padding: 0.75rem;
  }

  .message-text {
    font-size: 0.8125rem;
  }
}

/* ============================================
   DARK MODE SUPPORT (optional)
   ============================================ */
@media (prefers-color-scheme: dark) {
  /* Add dark mode styles if needed */
}

/* ============================================
   PRINT STYLES
   ============================================ */
@media print {
  .whatsapp-container {
    height: auto;
    box-shadow: none;
  }

  .conversations-sidebar {
    display: none;
  }

  .messages-panel {
    flex: 1;
  }

  .messages-footer {
    display: none;
  }
}
