/**
 * Demo Chat Widget Styles
 * AI-Правовед Landing Page
 */

/* Modal Overlay */
.demo-chat-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

.demo-chat-modal.open {
  opacity: 1;
  visibility: visible;
}

.demo-chat-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
}

/* Chat Container */
.demo-chat-container {
  position: relative;
  width: 100%;
  max-width: 500px;
  height: 80vh;
  max-height: 700px;
  background: linear-gradient(180deg, #1a1a2e 0%, #16162a 100%);
  border-radius: 24px;
  border: 1px solid rgba(99, 102, 241, 0.3);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 25px 50px rgba(0, 0, 0, 0.5), 0 0 100px rgba(99, 102, 241, 0.1);
  transform: translateY(20px);
  transition: transform 0.3s ease;
}

.demo-chat-modal.open .demo-chat-container {
  transform: translateY(0);
}

/* Header */
.demo-chat-header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px;
  background: rgba(99, 102, 241, 0.1);
  border-bottom: 1px solid rgba(99, 102, 241, 0.2);
}

.demo-chat-title {
  display: flex;
  align-items: center;
  gap: 12px;
}

.demo-chat-logo {
  font-size: 32px;
}

.demo-chat-title h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: #fff;
}

.demo-chat-status {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.6);
}

.demo-chat-close {
  width: 36px;
  height: 36px;
  border: none;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 50%;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease;
}

.demo-chat-close:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* Messages Area */
.demo-chat-messages {
  flex: 1;
  min-height: 0; /* Critical for flex scroll to work */
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.demo-chat-messages::-webkit-scrollbar {
  width: 6px;
}

.demo-chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

.demo-chat-messages::-webkit-scrollbar-thumb {
  background: rgba(99, 102, 241, 0.3);
  border-radius: 3px;
}

/* Message */
.demo-chat-message {
  display: flex;
  gap: 12px;
  max-width: 85%;
  animation: messageIn 0.3s ease;
}

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

.demo-chat-message.user {
  flex-direction: row-reverse;
  align-self: flex-end;
}

.demo-chat-message.system {
  align-self: center;
  max-width: 100%;
}

.demo-chat-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(99, 102, 241, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}

.demo-chat-message.user .demo-chat-avatar {
  background: rgba(139, 92, 246, 0.2);
}

.demo-chat-bubble {
  padding: 12px 16px;
  border-radius: 16px;
  background: rgba(99, 102, 241, 0.15);
  border: 1px solid rgba(99, 102, 241, 0.2);
}

.demo-chat-message.user .demo-chat-bubble {
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  border: none;
}

.demo-chat-message.system .demo-chat-bubble {
  background: rgba(255, 193, 7, 0.1);
  border-color: rgba(255, 193, 7, 0.3);
  text-align: center;
}

.demo-chat-content {
  font-size: 14px;
  line-height: 1.6;
  color: rgba(255, 255, 255, 0.9);
}

.demo-chat-content strong {
  color: #fff;
  font-weight: 600;
}

.demo-chat-content code {
  background: rgba(0, 0, 0, 0.3);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: monospace;
  font-size: 13px;
}

.demo-chat-content ul {
  margin: 8px 0;
  padding-left: 20px;
}

.demo-chat-content li {
  margin: 4px 0;
}

.demo-chat-content a {
  color: #818cf8;
  text-decoration: underline;
}

.demo-chat-time {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.4);
  margin-top: 6px;
}

/* Typing Indicator */
.demo-chat-typing {
  display: flex;
  gap: 4px;
  padding: 8px 0;
}

.demo-chat-typing span {
  width: 8px;
  height: 8px;
  background: rgba(99, 102, 241, 0.6);
  border-radius: 50%;
  animation: typingBounce 1.4s infinite ease-in-out;
}

.demo-chat-typing span:nth-child(1) { animation-delay: 0s; }
.demo-chat-typing span:nth-child(2) { animation-delay: 0.2s; }
.demo-chat-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
  0%, 80%, 100% { transform: translateY(0); }
  40% { transform: translateY(-6px); }
}

/* CTA Banner */
.demo-chat-cta {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: linear-gradient(135deg, rgba(34, 197, 94, 0.1), rgba(99, 102, 241, 0.1));
  border-top: 1px solid rgba(34, 197, 94, 0.2);
  gap: 12px;
}

.demo-chat-cta p {
  margin: 0;
  font-size: 13px;
  color: rgba(255, 255, 255, 0.8);
}

.demo-chat-cta-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: linear-gradient(135deg, #22c55e, #16a34a);
  color: #fff;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.demo-chat-cta-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(34, 197, 94, 0.4);
}

/* Input Area */
.demo-chat-input-area {
  flex-shrink: 0;
  padding: 16px;
  background: rgba(0, 0, 0, 0.2);
  border-top: 1px solid rgba(99, 102, 241, 0.1);
}

.demo-chat-limit {
  display: none;
  font-size: 12px;
  color: #f59e0b;
  margin-bottom: 8px;
  text-align: center;
}

.demo-chat-input-wrapper {
  display: flex;
  gap: 12px;
  align-items: flex-end;
}

.demo-chat-input-wrapper textarea {
  flex: 1;
  padding: 12px 16px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(99, 102, 241, 0.2);
  border-radius: 16px;
  color: #fff;
  font-size: 14px;
  font-family: inherit;
  resize: none;
  min-height: 44px;
  max-height: 120px;
  transition: border-color 0.2s ease;
}

.demo-chat-input-wrapper textarea:focus {
  outline: none;
  border-color: rgba(99, 102, 241, 0.5);
}

.demo-chat-input-wrapper textarea::placeholder {
  color: rgba(255, 255, 255, 0.4);
}

.demo-chat-send {
  width: 44px;
  height: 44px;
  border: none;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  border-radius: 50%;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease, opacity 0.2s ease;
  flex-shrink: 0;
}

.demo-chat-send:hover:not(:disabled) {
  transform: scale(1.05);
}

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

.demo-chat-send.loading {
  animation: pulse 1s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

/* Mobile Responsive */
@media (max-width: 768px) {
  .demo-chat-modal {
    align-items: flex-end;
  }
  
  .demo-chat-container {
    max-width: 100%;
    width: 100%;
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height for mobile browsers */
    max-height: none;
    border-radius: 0;
    transform: translateY(100%);
  }
  
  .demo-chat-modal.open .demo-chat-container {
    transform: translateY(0);
  }
  
  .demo-chat-header {
    padding: 16px;
    flex-shrink: 0;
  }
  
  .demo-chat-logo {
    font-size: 28px;
  }
  
  .demo-chat-title h3 {
    font-size: 16px;
  }
  
  .demo-chat-messages {
    flex: 1;
    min-height: 0; /* Important for flex scroll */
    overflow-y: auto;
    -webkit-overflow-scrolling: touch; /* Smooth scroll on iOS */
    overscroll-behavior: contain;
    padding: 16px;
  }
  
  .demo-chat-message {
    max-width: 90%;
  }
  
  .demo-chat-cta {
    flex-direction: column;
    text-align: center;
    padding: 12px;
    flex-shrink: 0;
  }
  
  .demo-chat-input-area {
    flex-shrink: 0;
    padding: 12px;
    padding-bottom: max(12px, env(safe-area-inset-bottom)); /* Safe area for iPhone notch */
    background: rgba(0, 0, 0, 0.3);
  }
  
  .demo-chat-input-wrapper {
    gap: 8px;
  }
  
  .demo-chat-input-wrapper textarea {
    padding: 10px 14px;
    font-size: 16px; /* Prevents zoom on iOS */
    border-radius: 12px;
  }
  
  .demo-chat-send {
    width: 44px;
    height: 44px;
    flex-shrink: 0;
  }
  
  .demo-chat-bubble {
    padding: 10px 14px;
    border-radius: 14px;
  }
  
  .demo-chat-content {
    font-size: 14px;
  }
}

/* Action Buttons */
.demo-chat-action-buttons {
  display: flex;
  justify-content: center;
  padding: 12px 0;
  animation: messageIn 0.3s ease;
}

.demo-doc-preview-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 20px;
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.2), rgba(139, 92, 246, 0.2));
  border: 1px solid rgba(99, 102, 241, 0.4);
  border-radius: 12px;
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.demo-doc-preview-btn:hover {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.3), rgba(139, 92, 246, 0.3));
  border-color: rgba(99, 102, 241, 0.6);
  transform: translateY(-2px);
}

.demo-doc-preview-btn i {
  font-size: 18px;
}

/* Wide bubble for document */
.demo-chat-bubble-wide {
  max-width: 100% !important;
}

/* Document Preview Styles */
.demo-document {
  background: linear-gradient(180deg, rgba(255,255,255,0.03) 0%, rgba(255,255,255,0.01) 100%);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 12px;
  padding: 20px;
  margin: 12px 0;
  font-size: 13px;
  line-height: 1.6;
}

.demo-doc-header {
  text-align: center;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}

.demo-doc-badge {
  display: inline-block;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  margin-bottom: 12px;
}

.demo-doc-title {
  font-size: 18px;
  font-weight: 700;
  color: #fff;
  margin-bottom: 4px;
  letter-spacing: 2px;
}

.demo-doc-subtitle {
  font-size: 12px;
  color: rgba(255,255,255,0.6);
}

.demo-doc-section {
  margin-bottom: 16px;
}

.demo-doc-label {
  font-size: 11px;
  font-weight: 600;
  color: rgba(99, 102, 241, 0.8);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 4px;
}

.demo-doc-value {
  color: rgba(255,255,255,0.9);
}

.demo-doc-body {
  margin: 20px 0;
  padding: 16px;
  background: rgba(0,0,0,0.2);
  border-radius: 8px;
}

.demo-doc-body p {
  margin-bottom: 12px;
}

.demo-doc-body p:last-child {
  margin-bottom: 0;
}

.demo-doc-require {
  background: rgba(34, 197, 94, 0.1);
  border: 1px solid rgba(34, 197, 94, 0.2);
  padding: 16px;
  border-radius: 8px;
}

.demo-doc-require ol {
  margin: 8px 0 0 20px;
  padding: 0;
}

.demo-doc-require li {
  margin: 8px 0;
}

.demo-doc-footer {
  display: flex;
  justify-content: space-between;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid rgba(255,255,255,0.1);
  font-size: 12px;
  color: rgba(255,255,255,0.6);
}

.demo-doc-note {
  margin-top: 16px;
  padding: 12px;
  background: rgba(99, 102, 241, 0.1);
  border-left: 3px solid #6366f1;
  border-radius: 0 8px 8px 0;
  font-size: 12px;
  color: rgba(255,255,255,0.8);
}

/* Responsive document */
@media (max-width: 768px) {
  .demo-document {
    padding: 12px;
  }
  
  .demo-doc-footer {
    flex-direction: column;
    gap: 8px;
  }
}
