/**
 * Chat Widget Styles
 * Modern, responsive chat interface
 */

/* Prevent text size adjustment on mobile */
* {
  -webkit-text-size-adjust: 100%;
  -moz-text-size-adjust: 100%;
  -ms-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

/* Chat Widget Container */
.chat-widget {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 9999;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  -webkit-tap-highlight-color: transparent; /* Remove tap highlight on mobile */
  touch-action: manipulation; /* Prevent double-tap zoom */
}

/* Toggle Button - REMOVED: Chat opens from popup */
.chat-toggle-btn {
  display: none !important;
}

.chat-unread-badge {
  display: none !important;
}

/* Chat Window */
.chat-window {
  position: absolute;
  bottom: 80px;
  right: 0;
  width: 400px;
  height: 600px;
  background: white;
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: slideUp 0.3s ease;
}

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

/* Chat Header */
.chat-header {
  background: linear-gradient(135deg, #2563EB 0%, #1d4ed8 100%);
  color: white;
  padding: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.chat-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.chat-title {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}

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

.chat-new-room-btn:hover {
  background: rgba(255, 255, 255, 0.3);
}

.chat-header-right {
  display: flex;
  gap: 8px;
}

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

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

/* Chat Body */
.chat-body {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* Room List */
.chat-room-list {
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* Search */
.chat-search {
  padding: 16px;
  border-bottom: 1px solid #e5e7eb;
}

.chat-search-input {
  width: 100%;
  padding: 10px 16px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
}

.chat-search-input:focus {
  border-color: #2563EB;
}

/* Tabs */
.chat-tabs {
  display: flex;
  border-bottom: 1px solid #e5e7eb;
}

.chat-tab {
  flex: 1;
  padding: 12px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: #6b7280;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.chat-tab.active {
  color: #2563EB;
  border-bottom-color: #2563EB;
}

.chat-tab:hover {
  background: #f9fafb;
}

/* Rooms Container */
.chat-rooms-container {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
}

.chat-room-item {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  cursor: pointer;
  transition: background 0.2s;
  position: relative;
  min-height: 60px; /* Minimum touch target size */
  touch-action: manipulation;
}

.chat-room-item:hover {
  background: #f9fafb;
}

.chat-room-item.active {
  background: #dbeafe;
  border-left: 3px solid #2563EB;
}

.chat-room-item.active .chat-room-item-name {
  color: #1d4ed8;
}

.chat-room-item-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  object-fit: cover;
  margin-right: 12px;
}

.chat-room-item-content {
  flex: 1;
  min-width: 0;
}

.chat-room-item-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}

.chat-room-item-name {
  font-weight: 600;
  font-size: 14px;
  color: #111827;
}

.chat-room-item-time {
  font-size: 12px;
  color: #9ca3af;
}

.chat-room-item-message {
  font-size: 13px;
  color: #6b7280;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-room-item-message.unread {
  font-weight: 600;
  color: #374151;
}

.chat-room-item-badge {
  position: absolute;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
  background: #2563EB;
  color: white;
  border-radius: 12px;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: bold;
  min-width: 20px;
  text-align: center;
}

/* Room View */
.chat-room-view {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.chat-room-header {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid #e5e7eb;
}

.chat-back-btn {
  background: none;
  border: none;
  color: #6b7280;
  cursor: pointer;
  padding: 4px;
  margin-right: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chat-back-btn:hover {
  color: #111827;
}

.chat-room-info {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 12px;
}

.chat-room-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
}

.chat-room-name {
  font-weight: 600;
  font-size: 14px;
  color: #111827;
}

.chat-room-status {
  font-size: 12px;
  color: #10b981;
}

/* Messages Container */
.chat-messages-container {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
  scroll-behavior: smooth;
}

.chat-message {
  display: flex;
  gap: 8px;
}

.chat-message-own {
  flex-direction: row-reverse;
}

.chat-message-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.chat-message-bubble {
  max-width: 70%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.5;
}

.chat-message-other .chat-message-bubble {
  background: #f3f4f6;
  color: #111827;
  border-bottom-left-radius: 4px;
}

.chat-message-own .chat-message-bubble {
  background: linear-gradient(135deg, #2563EB 0%, #1d4ed8 100%);
  color: white;
  border-bottom-right-radius: 4px;
}

.chat-message-name {
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 4px;
  color: #6b7280;
}

.chat-message-text {
  word-wrap: break-word;
}

.chat-message-image img {
  max-width: 100%;
  border-radius: 8px;
  display: block;
}

.chat-message-time {
  font-size: 11px;
  margin-top: 4px;
  opacity: 0.7;
}

.chat-message-notification {
  text-align: center;
  color: #6b7280;
  font-size: 12px;
  padding: 8px 0;
}

/* Message Input */
.chat-input-container {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  border-top: 1px solid #e5e7eb;
  gap: 8px;
}

.chat-message-input {
  flex: 1;
  padding: 10px 16px;
  border: 1px solid #e5e7eb;
  border-radius: 20px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
  max-height: 120px;
  resize: none;
  font-family: inherit;
}

.chat-message-input:focus {
  border-color: #2563EB;
}

.chat-send-btn {
  background: linear-gradient(135deg, #2563EB 0%, #1d4ed8 100%);
  border: none;
  color: white;
  min-width: 40px;
  min-height: 40px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s;
  touch-action: manipulation;
}

.chat-send-btn:hover {
  transform: scale(1.05);
}

/* Modal */
.chat-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  animation: fadeIn 0.2s ease;
}

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

.chat-modal-content {
  background: white;
  border-radius: 16px;
  width: 90%;
  max-width: 500px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: slideUp 0.3s ease;
}

.chat-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid #e5e7eb;
}

.chat-modal-header h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}

.chat-modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}

.chat-modal-footer {
  padding: 16px 20px;
  border-top: 1px solid #e5e7eb;
  display: flex;
  justify-content: flex-end;
}

.chat-btn-primary {
  background: linear-gradient(135deg, #2563EB 0%, #1d4ed8 100%);
  color: white;
  border: none;
  padding: 10px 24px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.2s;
}

.chat-btn-primary:hover:not(:disabled) {
  opacity: 0.9;
}

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

/* Users List */
.chat-users-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 16px;
}

.chat-user-item {
  display: flex;
  align-items: center;
  padding: 12px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
}

.chat-user-item:hover {
  background: #f9fafb;
  border-color: #2563EB;
}

.chat-user-item.selected {
  background: #dbeafe;
  border-color: #2563EB;
}

.chat-user-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  margin-right: 12px;
}

.chat-user-info {
  flex: 1;
}

.chat-user-name {
  font-weight: 600;
  font-size: 14px;
  color: #111827;
}

.chat-user-email {
  font-size: 12px;
  color: #6b7280;
}

.chat-user-checkbox {
  display: flex;
  align-items: center;
}

.chat-user-checkbox input[type="checkbox"] {
  width: 18px;
  height: 18px;
  cursor: pointer;
}

/* Loading & Empty States */
.chat-loading,
.chat-empty,
.chat-error {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  color: #6b7280;
  font-size: 14px;
  text-align: center;
  gap: 12px;
}

.chat-loading p {
  margin: 0;
  color: #6b7280;
}

.chat-error {
  color: #ef4444;
}

/* Scrollbar */
.chat-rooms-container::-webkit-scrollbar,
.chat-messages-container::-webkit-scrollbar,
.chat-modal-body::-webkit-scrollbar {
  width: 6px;
}

.chat-rooms-container::-webkit-scrollbar-track,
.chat-messages-container::-webkit-scrollbar-track,
.chat-modal-body::-webkit-scrollbar-track {
  background: #f3f4f6;
}

.chat-rooms-container::-webkit-scrollbar-thumb,
.chat-messages-container::-webkit-scrollbar-thumb,
.chat-modal-body::-webkit-scrollbar-thumb {
  background: #d1d5db;
  border-radius: 3px;
}

.chat-rooms-container::-webkit-scrollbar-thumb:hover,
.chat-messages-container::-webkit-scrollbar-thumb:hover,
.chat-modal-body::-webkit-scrollbar-thumb:hover {
  background: #9ca3af;
}

/* Responsive */
@media (max-width: 768px) {
    .chat-header {
      padding-top: calc(16px + env(safe-area-inset-top));
    }
  .chat-widget {
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
  }

  .chat-window {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    border-radius: 0;
    max-height: 100vh;
  }
  
  .chat-toggle-btn {
    width: 56px;
    height: 56px;
    bottom: 16px;
    right: 16px;
  }
  
  .chat-modal-content {
    width: 95%;
    max-height: 90vh;
  }

  .chat-room-item-avatar,
  .chat-room-avatar,
  .chat-message-avatar {
    width: 36px;
    height: 36px;
  }

  .chat-room-item {
    padding: 10px 12px;
  }

  .chat-room-item-name {
    font-size: 13px;
  }

  .chat-room-item-message {
    font-size: 12px;
  }

  .chat-message-bubble {
    max-width: 85%;
    font-size: 13px;
    padding: 8px 12px;
  }

  .chat-search {
    padding: 12px;
  }

  .chat-input-container {
    padding: 10px 12px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
  }

  .chat-message-input {
    font-size: 16px; /* Prevent zoom on iOS */
  }
}

@media (max-width: 480px) {
  .chat-header {
    padding: 12px;
  }

  .chat-title {
    font-size: 16px;
  }

  .chat-new-room-btn,
  .chat-icon-btn {
    width: 28px;
    height: 28px;
  }

  .chat-new-room-btn svg,
  .chat-icon-btn svg {
    width: 16px;
    height: 16px;
  }

  .chat-room-item-avatar,
  .chat-room-avatar,
  .chat-message-avatar {
    width: 32px;
    height: 32px;
  }

  .chat-room-item {
    padding: 8px 10px;
  }

  .chat-room-item-name {
    font-size: 12px;
  }

  .chat-room-item-message,
  .chat-room-item-time {
    font-size: 11px;
  }

  .chat-message-bubble {
    max-width: 90%;
    font-size: 12px;
    padding: 7px 10px;
  }

  .chat-messages-container {
    padding: 12px;
    gap: 8px;
  }
}
