/* ==========================================
   CHAT VIEW
   ========================================== */

.chat-view {
  display: flex;
  flex-direction: column;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--bg-primary);
  z-index: 10;
  transform: translateX(100%);
  opacity: 0;
  visibility: hidden;
  transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1),
              opacity 0.35s ease,
              visibility 0.35s ease;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.chat-view.open {
  transform: translateX(0);
  opacity: 1;
  visibility: visible;
}

/* Chat Header */
.chat-header {
  padding: 20px 24px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  gap: 16px;
  flex-shrink: 0;
}

.back-btn {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.25s ease;
  flex-shrink: 0;
}

.back-btn:hover {
  background: var(--bg-card-hover);
  border-color: var(--accent-cyan);
  color: var(--accent-cyan);
}

.back-btn svg {
  width: 20px;
  height: 20px;
}

.chat-user-info {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.chat-user-avatar {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--accent-cyan), var(--accent-purple));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 600;
  color: white;
  flex-shrink: 0;
}

.chat-user-avatar.support {
  background: linear-gradient(135deg, var(--accent-purple), var(--accent-cyan));
}

.chat-user-avatar.avito {
  background: linear-gradient(135deg, var(--accent-orange), var(--accent-purple));
}

.chat-user-details {
  flex: 1;
  min-width: 0;
}


/* Message */
.message {
  display: flex;
  gap: 12px;
  max-width: 75%;
  animation: slideIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.message.incoming {
  align-self: flex-start;
  margin-left: 12px;
}

.message.outgoing {
  align-self: flex-end;
  flex-direction: row-reverse;
  margin-right: 12px;
}

.chat-user-name {
  font-size: 17px;
  font-weight: 600;
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-user-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-secondary);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
}

.status-dot.online {
  background: var(--accent-green);
  animation: pulse 2s ease-in-out infinite;
}

.chat-user-phone {
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  color: var(--accent-cyan);
  background: rgba(0, 212, 255, 0.1);
  padding: 6px 12px;
  border-radius: 8px;
  flex-shrink: 0;
}

/* Messages Area */
.messages-area {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* (твой фикс) — если используешь именно .chat-messages как контейнер */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 24px;
}




.message-avatar {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
  color: white;
  flex-shrink: 0;
  align-self: flex-end;
}

.message.incoming .message-avatar {
  background: linear-gradient(135deg, var(--accent-cyan), var(--accent-purple));
}

.message.outgoing .message-avatar {
  background: linear-gradient(135deg, var(--accent-purple), var(--accent-orange));
}

.message-content {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.message-bubble {
  padding: 14px 18px;
  border-radius: 16px;
  font-size: 15px;
  line-height: 1.5;
  position: relative;
  word-wrap: break-word;
}

.message.incoming .message-bubble {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-bottom-left-radius: 4px;
}

.message.outgoing .message-bubble {
  background: linear-gradient(135deg, rgba(0, 212, 255, 0.15), rgba(168, 85, 247, 0.15));
  border: 1px solid rgba(0, 212, 255, 0.3);
  border-bottom-right-radius: 4px;
}

.message-time {
  font-size: 11px;
  color: var(--text-muted);
  font-family: 'JetBrains Mono', monospace;
  padding: 0 4px;
}

.message.outgoing .message-time {
  text-align: right;
}

/* Photo Message */
.message-photo {
  max-width: 300px;
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.2s ease;
}

.message-photo:hover {
  transform: scale(1.02);
}

.message-photo img {
  width: 100%;
  height: auto;
  display: block;
}

/* Date Separator */
.date-separator {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 8px 0;
}

.date-separator::before,
.date-separator::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border-color);
}

.date-separator span {
  font-size: 12px;
  color: var(--text-secondary);
  font-family: 'JetBrains Mono', monospace;
  background: var(--bg-card);
  padding: 6px 14px;
  border-radius: 20px;
  border: 1px solid var(--border-color);
}

/* Typing Indicator */
.typing-indicator {
  display: none;
  align-items: center;
  gap: 12px;
  padding: 8px 0;
  color: var(--text-secondary);
  font-size: 13px;
}

.typing-indicator.visible {
  display: flex;
}

.typing-dots {
  display: flex;
  gap: 4px;
}

.typing-dots span {
  width: 6px;
  height: 6px;
  background: var(--accent-cyan);
  border-radius: 50%;
  animation: typingDot 1.4s ease-in-out infinite;
}

.typing-dots span:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-dots span:nth-child(3) {
  animation-delay: 0.4s;
}

/* Input Area */
.chat-input-area {
  padding: 20px 24px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-color);
  flex-shrink: 0; /* твой фикс */
}

.input-wrapper {
  display: flex;
  gap: 12px;
  align-items: center; /* было flex-end, меняем на center */
}

.input-container {
  flex: 1;
  position: relative;
}

.message-input {
  width: 100%;
  min-height: 52px;
  max-height: 150px;
  padding: 14px 20px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  color: var(--text-primary);
  font-family: 'Outfit', sans-serif;
  font-size: 15px;
  resize: none;
  transition: all 0.25s ease;
  line-height: 1.5;
}

.message-input:focus {
  outline: none;
  border-color: var(--accent-cyan);
  box-shadow: 0 0 0 3px var(--border-glow);
}

.message-input::placeholder {
  color: var(--text-secondary);
}

.input-actions {
  display: flex;
  gap: 8px;
}

.action-btn {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.25s ease;
}

.action-btn:hover {
  background: var(--bg-card-hover);
  border-color: var(--accent-cyan);
  color: var(--accent-cyan);
}

.action-btn svg {
  width: 22px;
  height: 22px;
}

.action-btn.send-btn {
  background: linear-gradient(135deg, var(--accent-cyan), var(--accent-purple));
  border: none;
  color: white;
}

.action-btn.send-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0, 212, 255, 0.3);
}

.action-btn.send-btn:active {
  transform: translateY(0);
}

.action-btn.send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

/* File Upload */
.file-input {
  display: none;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 24px;
  overscroll-behavior: contain; /* добавь эту строку */
}

.upload-preview {
  display: none;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  margin-bottom: 12px;
}

.upload-preview.visible {
  display: flex;
}

.upload-preview-img {
  width: 60px;
  height: 60px;
  border-radius: 8px;
  object-fit: cover;
}

.upload-preview-info {
  flex: 1;
}

.upload-preview-name {
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 4px;
}

.upload-preview-size {
  font-size: 12px;
  color: var(--text-secondary);
}

.upload-preview-remove {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: rgba(239, 68, 68, 0.15);
  border: none;
  color: var(--accent-red);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.25s ease;
}

.upload-preview-remove:hover {
  background: rgba(239, 68, 68, 0.25);
}

.upload-preview-remove svg {
  width: 16px;
  height: 16px;
}

/* Photo Lightbox */
.lightbox {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.9);
  backdrop-filter: blur(8px);
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.3s ease;
}

.lightbox.open {
  display: flex;
}

.lightbox-content {
  max-width: 90vw;
  max-height: 80vh;
  position: relative;
}

.lightbox-content img {
  max-width: 100%;
  max-height: 80vh;
  border-radius: 8px;
}

.lightbox-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.25s ease;
}

.lightbox-close:hover {
  background: var(--bg-card-hover);
  border-color: var(--accent-cyan);
}

.lightbox-close svg {
  width: 24px;
  height: 24px;
}

/* Messages Loading */
.messages-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  color: var(--text-secondary);
}

.messages-loading .loading-spinner {
  margin-bottom: 16px;
}

/* ==========================================
   AI DRAFT PANEL
   ========================================== */

.ai-draft-panel {
    margin: 0 24px;
    padding: 14px 16px;
    background: var(--bg-card);
    border: 1px solid rgba(168, 85, 247, 0.3);
    border-radius: 14px;
    animation: slideUp 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    flex-shrink: 0;
}

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

.ai-draft-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}

.ai-draft-badge {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 600;
    color: var(--accent-purple);
    background: rgba(168, 85, 247, 0.12);
    padding: 4px 10px;
    border-radius: 8px;
}

.ai-draft-badge svg {
    flex-shrink: 0;
    color: var(--accent-purple);
}

.ai-draft-source {
    font-weight: 400;
    color: var(--text-secondary);
    margin-left: 4px;
    font-size: 11px;
}

.ai-draft-close {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    background: rgba(239, 68, 68, 0.1);
    border: none;
    color: var(--accent-red, #ef4444);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.ai-draft-close:hover {
    background: rgba(239, 68, 68, 0.2);
}

.ai-draft-text {
    font-size: 14px;
    line-height: 1.55;
    color: var(--text-primary);
    padding: 10px 12px;
    background: var(--bg-input, rgba(255,255,255,0.04));
    border: 1px solid var(--border-color);
    border-radius: 10px;
    margin-bottom: 12px;
    max-height: 120px;
    overflow-y: auto;
    word-wrap: break-word;
}

.ai-draft-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.ai-draft-btn {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 7px 12px;
    border-radius: 9px;
    border: 1px solid var(--border-color);
    background: var(--bg-card);
    color: var(--text-primary);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: 'Outfit', sans-serif;
}

.ai-draft-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.ai-draft-btn svg {
    flex-shrink: 0;
}

/* Изменить */
.ai-draft-btn-edit {
    border-color: rgba(0, 212, 255, 0.3);
    color: var(--accent-cyan);
}

.ai-draft-btn-edit:hover:not(:disabled) {
    background: rgba(0, 212, 255, 0.1);
    border-color: var(--accent-cyan);
}

/* Одобрить */
.ai-draft-btn-approve {
    border-color: rgba(34, 197, 94, 0.3);
    color: var(--accent-green, #22c55e);
}

.ai-draft-btn-approve:hover:not(:disabled) {
    background: rgba(34, 197, 94, 0.1);
    border-color: var(--accent-green, #22c55e);
}

/* Одобрить + пары */
.ai-draft-btn-approve-pairs {
    border-color: rgba(168, 85, 247, 0.3);
    color: var(--accent-purple);
}

.ai-draft-btn-approve-pairs:hover:not(:disabled) {
    background: rgba(168, 85, 247, 0.1);
    border-color: var(--accent-purple);
}


/* ==========================================
   Mobile Responsive (Chat only)
   ========================================== */

@media (max-width: 768px) {
  .chat-view {
    overscroll-behavior: contain;
  }

  .chat-header {
    padding: 14px 16px;
    gap: 12px;
  }

  .chat-messages {
    padding: 12px 8px;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }

  .message.outgoing {
    align-self: flex-end;
    flex-direction: row-reverse;
    margin-right: 4px;
  }

  .message.incoming {
    align-self: flex-start;
    margin-left: 4px;
  }

  .message {
    max-width: 85%;
  }

  .message-avatar {
    display: none;
  }

  .message-bubble {
    padding: 12px 14px;
    font-size: 14px;
  }

  .message-photo {
    max-width: 220px;
  }

  .back-btn {
    width: 36px;
    height: 36px;
  }

  .chat-user-avatar {
    width: 38px;
    height: 38px;
    border-radius: 12px;
  }

  .chat-user-name {
    font-size: 14px;
  }

  .chat-user-status {
    font-size: 12px;
  }

  .chat-user-phone {
    display: none;
  }

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

  .ai-draft-panel {
    margin: 0 8px;
    padding: 10px 12px;
  }

  .ai-draft-text {
    font-size: 13px;
    max-height: 90px;
    padding: 8px 10px;
  }

  .ai-draft-actions {
    gap: 6px;
  }

  .ai-draft-btn {
    padding: 6px 10px;
    font-size: 11px;
  }

  .ai-draft-btn span {
    /* На маленьких экранах можно скрыть текст кнопок кроме иконки */
  }

  .chat-input-area.typing .attach-btn {
    display: none;
  }

  .input-wrapper {
    gap: 8px;
    align-items: center;
  }

  .action-btn {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    flex-shrink: 0;
  }

  .action-btn svg {
    width: 20px;
    height: 20px;
  }

  .message-input {
    min-height: 44px;
    padding: 10px 14px;
    border-radius: 14px;
  }
}


/* ==========================================
   Touch improvements (Chat-related only)
   ========================================== */

@media (hover: none) and (pointer: coarse) {
  .action-btn:hover {
    background: var(--bg-card);
    border-color: var(--border-color);
    color: var(--text-secondary);
  }

  .action-btn:active {
    background: var(--bg-card-hover);
  }

  .action-btn.send-btn:hover {
    transform: none;
    box-shadow: none;
  }

  .action-btn.send-btn:active {
    transform: scale(0.95);
  }

  .message-photo:hover {
    transform: none;
  }

  .message-photo:active {
    transform: scale(0.98);
  }
}

/* ==========================================
   AI DRAFT BUTTON (inline)
   ========================================== */

.ai-draft-inline-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: linear-gradient(135deg, rgba(168, 85, 247, 0.2), rgba(0, 212, 255, 0.2));
    border: 1px solid rgba(168, 85, 247, 0.4);
    color: var(--accent-purple);
    cursor: pointer;
    margin-left: 8px;
    flex-shrink: 0;
    transition: all 0.25s ease;
    animation: aiPulse 2s ease-in-out infinite;
}

.ai-draft-inline-btn:hover {
    transform: scale(1.1);
    background: linear-gradient(135deg, rgba(168, 85, 247, 0.3), rgba(0, 212, 255, 0.3));
    border-color: var(--accent-purple);
    box-shadow: 0 0 12px rgba(168, 85, 247, 0.4);
}

.ai-draft-inline-btn svg {
    width: 16px;
    height: 16px;
}

@keyframes aiPulse {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(168, 85, 247, 0.4);
    }
    50% {
        box-shadow: 0 0 0 6px rgba(168, 85, 247, 0);
    }
}

/* Контейнер сообщения с кнопкой AI */
.message.incoming .message-content {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.message-row {
    display: flex;
    align-items: flex-end;
    gap: 0;
}

.message-row .message-bubble {
    flex: 0 1 auto;
}

@media (max-width: 768px) {
    .ai-draft-inline-btn {
        width: 24px;
        height: 24px;
    }

    .ai-draft-inline-btn svg {
        width: 14px;
        height: 14px;
    }
}






