/* =====================================================
   CHAT - Conversaciones y mensajes
   ===================================================== */

/* Conversations List */
.conversations-list {
  display: flex;
  flex-direction: column;
  padding: 0;
  width: 100%;
}

.conversation-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid #f0f0f0;
  cursor: pointer;
  transition: background 0.2s;
}

.conversation-item:hover {
  background: #f5f5f5;
}

.conversation-item:active {
  background: #e0e0e0;
}

.conversation-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.conversation-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.conversation-username {
  font-weight: 500;
  font-size: 15px;
  color: #000;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conversation-last-message {
  font-size: 13px;
  color: #666;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.conversation-time {
  font-size: 12px;
  color: #999;
  flex-shrink: 0;
}

.conversation-unread {
  width: 8px;
  height: 8px;
  background: #2196f3;
  border-radius: 50%;
  flex-shrink: 0;
}

/* Messages View */
#view-messages {
  width: 100%;
}

#view-messages .app-container {
  max-width: 600px;
  margin: 0 auto;
  width: 100%;
  padding-top: 62px;
}

/* Chat View */
.chat-view {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  flex-direction: column;
  background: #fff;
  z-index: 50;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

@media (min-width: 768px) {
  .chat-view {
    max-width: 600px;
    margin: 0 auto;
    left: 50%;
    right: auto;
    width: 600px;
    transform: translateX(-50%);
  }
}

/* Chat Header */
.chat-header {
  flex-shrink: 0;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 101;
  background: #fff;
  border-bottom: 1px solid #e0e0e0;
  width: 100%;
  max-width: none;
}

@media (min-width: 768px) {
  .chat-header {
    width: 600px;
    left: 50%;
    transform: translateX(-50%);
    right: auto;
  }
}

@media (max-width: 600px) {
  .chat-header {
    left: 0;
    right: 0;
    transform: none;
  }
}

.chat-header-info {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
}

.chat-header-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
}

/* Chat Messages Area */
.chat-messages {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 16px;
  padding-bottom: 8px;
  padding-top: 62px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: #f5f5f5;
  min-height: 0;
  width: 100%;
  margin: 0 auto;
}

/* Chat Input Container */
.chat-input-container {
  flex-shrink: 0;
  display: flex;
  gap: 10px;
  padding: 8px 16px;
  padding-bottom: calc(8px + env(safe-area-inset-bottom));
  background: #fff;
  border-top: 1px solid #e0e0e0;
  z-index: 100;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  width: 100%;
}

@media (min-width: 768px) {
  .chat-input-container {
    width: 600px;
    left: 50%;
    transform: translateX(-50%);
    right: auto;
  }
}

@media (max-width: 600px) {
  .chat-input-container {
    left: 0;
    right: 0;
    transform: none;
  }
  
  body.keyboard-open .chat-input-container {
    padding-bottom: 8px;
  }
  
  body.keyboard-open .chat-view {
    height: 100vh;
    height: 100dvh;
  }
}

/* Chat Input */
.chat-input {
  flex: 1;
  padding: 10px 16px;
  border: 1px solid #e0e0e0;
  border-radius: 24px;
  font-size: 16px;
  line-height: 1.4;
  background: #f5f5f5;
  color: #000;
  outline: none;
  resize: none;
  max-height: 100px;
  min-height: 40px;
}

.chat-input:focus {
  background: #fff;
  border-color: #2196f3;
}

/* Chat Buttons */
.btn-gallery,
.btn-send {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: #f5f5f5;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-gallery:active,
.btn-send:active {
  background: #e0e0e0;
  transform: scale(0.95);
}

.btn-send {
  background: #2196f3;
}

.btn-send:active {
  background: #1976d2;
}

.gallery-icon,
.send-icon {
  width: 20px;
  height: 20px;
  filter: brightness(0) saturate(100%) invert(40%);
}

.send-icon {
  filter: brightness(0) saturate(100%) invert(100%);
}

/* Message Items */
.message-item {
  display: flex;
  margin-bottom: 4px;
  max-width: 85%;
  word-wrap: break-word;
}

.message-item.own {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.message-item.other {
  align-self: flex-start;
}

.message-bubble {
  padding: 8px 12px;
  border-radius: 16px;
  position: relative;
  word-wrap: break-word;
  overflow-wrap: break-word;
  max-width: 100%;
}

.message-item.own .message-bubble {
  background: #2196f3;
  color: #fff;
  border-bottom-right-radius: 4px;
}

.message-item.other .message-bubble {
  background: #fff;
  color: #000;
  border-bottom-left-radius: 4px;
  border: 1px solid #e0e0e0;
}

.message-text {
  margin: 0;
  font-size: 15px;
  line-height: 1.4;
  white-space: pre-wrap;
  word-break: break-word;
}

.message-image {
  max-width: 100%;
  border-radius: 12px;
  display: block;
  margin-top: 4px;
  cursor: pointer;
}

.message-time {
  font-size: 11px;
  margin-top: 4px;
  display: block;
  text-align: right;
}

.message-item.own .message-time {
  color: rgba(255, 255, 255, 0.7);
}

.message-item.other .message-time {
  color: #999;
}

/* Typing Indicator */
.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 8px 12px;
  background: #fff;
  border-radius: 16px;
  align-self: flex-start;
  max-width: 60px;
  border: 1px solid #e0e0e0;
}

.typing-dot {
  width: 8px;
  height: 8px;
  background: #999;
  border-radius: 50%;
  animation: typing 1.4s infinite;
}

.typing-dot:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
  animation-delay: 0.4s;
}

/* Safari iOS Fixes */
@supports (-webkit-touch-callout: none) {
  .chat-view {
    position: fixed;
    min-height: 100vh;
    min-height: -webkit-fill-available;
  }
  
  .chat-input-container {
    position: sticky;
    bottom: 0;
    padding-bottom: max(8px, env(safe-area-inset-bottom));
  }
  
  .chat-input {
    font-size: 16px !important;
  }
  
  .chat-messages {
    padding-bottom: 16px;
  }
}

/* Chrome Mobile / Android Fixes */
@media (max-width: 600px) {
  @supports not (-webkit-touch-callout: none) {
    .chat-view {
      height: 100dvh;
      min-height: 100dvh;
    }
    
    body.keyboard-open .chat-view {
      height: 100vh;
      min-height: 100vh;
    }
  }
  
  .chat-input-container {
    position: sticky;
    bottom: 0;
    background: #fff;
    z-index: 101;
  }
  
  .chat-input {
    font-size: 16px;
  }
}
