/* Floating Chat System Styles */

/* Chat Toggle Button */
.chat-toggle-btn {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border: none;
  border-radius: 8px;
  color: white;
  cursor: pointer;
  font-size: 16px;
  padding: 8px 12px;
  margin-right: 10px;
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
}

.chat-toggle-btn::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
  transition: left 0.5s;
}

.chat-toggle-btn:hover::before {
  left: 100%;
}

.chat-toggle-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.chat-toggle-btn.active {
  background: linear-gradient(135deg, #ff6b6b 0%, #ee5a52 100%);
  box-shadow: 0 2px 8px rgba(255, 107, 107, 0.3);
}

/* Floating Chat Window */
.floating-chat-window {
  position: fixed;
  width: 350px;
  height: 450px;
  background: #ffffff;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  resize: none; /* Prevent browser default resize */
}

.floating-chat-window.dragging {
  cursor: grabbing;
  user-select: none;
}

.floating-chat-window.resizing {
  user-select: none;
}

.floating-chat-window.opening {
  animation: chatFadeIn 0.3s ease-out;
}

.floating-chat-window.closing {
  animation: chatFadeOut 0.3s ease-in;
}

.floating-chat-window.minimized {
  height: 50px !important;
  transition: height 0.3s ease;
  overflow: hidden;
}

.floating-chat-window.minimized .chat-window-content,
.floating-chat-window.minimized .chat-resize-handles {
  display: none;
}

/* Chat Window Header */
.chat-window-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px 8px 16px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  cursor: grab;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  min-height: 40px;
  position: relative;
  touch-action: none; /* Enable touch dragging */
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

.chat-window-header:active {
  cursor: grabbing;
}

.chat-window-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 14px;
  flex: 1;
  min-width: 0; /* Allow text to shrink */
  max-width: calc(100% - 110px); /* Reserve more space for controls */
  padding-right: 20px; /* Extra padding to ensure separation */
}

.chat-icon {
  font-size: 16px;
  flex-shrink: 0;
}

.chat-title-text {
  user-select: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-window-controls {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-shrink: 0; /* prevent shrink */
  flex-wrap: nowrap; /* prevent wrapping */
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 10;
  background: rgba(0, 0, 0, 0.1);
  padding: 4px 6px;
  border-radius: 6px;
  backdrop-filter: blur(5px);
}

.chat-control-btn {
  background: rgba(255, 255, 255, 0.2);
  border: none;
  border-radius: 4px;
  color: white;
  cursor: pointer;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  font-size: 12px;
  font-weight: bold;
  flex-shrink: 0;
  box-sizing: border-box;
  line-height: 1;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.chat-control-btn:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: scale(1.05);
}

.close-btn:hover {
  background: rgba(255, 99, 99, 0.8);
}

.close-btn {
  position: absolute !important;
  top: 0px !important;
  right: 35px !important;
  transform: none !important;
}

.minimize-btn:hover {
  background: rgba(255, 193, 7, 0.8);
}

/* Chat Window Content */
.chat-window-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #f8f9fa;
  position: relative;
  overflow: hidden;
}

.chat-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: #666;
}

.loading-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid #f3f3f3;
  border-top: 3px solid #667eea;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-bottom: 16px;
}

.chat-embed-container {
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.chat-embed-container iframe {
  width: 100%;
  height: 100%;
  border: none;
}

/* Resize Handles */
.chat-resize-handles {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
}

.resize-handle {
  position: absolute;
  pointer-events: all;
  z-index: 10;
}

.resize-se {
  bottom: 0;
  right: 0;
  width: 20px;
  height: 20px;
  cursor: se-resize;
  background: linear-gradient(-45deg, transparent 0%, transparent 30%, rgba(255,255,255,0.1) 30%, rgba(255,255,255,0.1) 35%, transparent 35%);
}

.resize-s {
  bottom: 0;
  left: 20px;
  right: 20px;
  height: 8px;
  cursor: s-resize;
}

.resize-e {
  top: 20px;
  right: 0;
  bottom: 20px;
  width: 8px;
  cursor: e-resize;
}

.resize-handle:hover {
  background-color: rgba(102, 126, 234, 0.2);
}

.resize-se:hover {
  background: linear-gradient(-45deg, transparent 0%, transparent 25%, rgba(102, 126, 234, 0.3) 25%, rgba(102, 126, 234, 0.3) 40%, transparent 40%);
}

/* Animations */
@keyframes chatFadeIn {
  from {
    opacity: 0;
    transform: scale(0.9) translateY(20px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

@keyframes chatFadeOut {
  from {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
  to {
    opacity: 0;
    transform: scale(0.9) translateY(20px);
  }
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
  .chat-toggle-btn {
    font-size: 14px;
    padding: 6px 10px;
    margin-right: 8px;
  }
  
  .floating-chat-window {
    width: 90vw;
    height: 70vh;
    max-width: 320px;
    max-height: 500px;
  }
  
  .chat-window-header {
    padding: 8px 10px 8px 12px;
    min-height: 44px;
  }
  
  .chat-window-title {
    font-size: 13px;
    max-width: calc(100% - 120px);
    padding-right: 15px;
  }
  
  .chat-window-controls {
    right: 10px;
    gap: 6px;
    padding: 3px 5px;
  }
  
  .chat-control-btn {
    width: 26px;
    height: 26px;
    font-size: 12px;
    border-radius: 4px;
  }
  
  .chat-window-header .close-btn {
    position: absolute !important;
    top: 0px !important;
    right: 30px !important;
    transform: none !important;
  }
  
  /* Larger resize handles for mobile */
  .resize-se {
    width: 24px;
    height: 24px;
  }
  
  .resize-s {
    height: 12px;
    left: 24px;
    right: 24px;
  }
  
  .resize-e {
    width: 12px;
    top: 24px;
    bottom: 24px;
  }
}

@media (max-width: 480px) {
  .floating-chat-window {
    width: 95vw;
    height: 60vh;
    border-radius: 8px;
  }
  
  .chat-window-header {
    padding: 6px 8px 6px 10px;
    min-height: 40px;
  }
  
  .chat-window-title {
    font-size: 12px;
    max-width: calc(100% - 80px);
  }
  
  .chat-icon {
    font-size: 14px;
  }
  
  .chat-window-controls {
    right: 4px;
    gap: 4px;
  }
  
  .chat-control-btn {
    width: 24px;
    height: 24px;
    font-size: 11px;
  }
  
  .chat-window-header .close-btn {
    position: absolute !important;
    top: 0px !important;
    right: 25px !important;
    transform: none !important;
  }
}

/* Touch devices optimization */
@media (hover: none) and (pointer: coarse) {
  .chat-window-header {
    padding: 10px 12px 10px 14px;
    min-height: 48px;
  }
  
  .chat-window-controls {
    right: 8px;
    gap: 8px;
  }
  
  .chat-control-btn {
    width: 30px;
    height: 30px;
    font-size: 14px;
    border-radius: 4px;
  }
  
  .chat-window-header .close-btn {
    position: absolute !important;
    top: 0px !important;
    right: 32px !important;
    transform: none !important;
  }
  
  .chat-window-title {
    max-width: calc(100% - 100px);
  }
  
  /* Even larger resize handles for touch */
  .resize-se {
    width: 28px;
    height: 28px;
  }
  
  .resize-s {
    height: 16px;
    left: 28px;
    right: 28px;
  }
  
  .resize-e {
    width: 16px;
    top: 28px;
    bottom: 28px;
  }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
  .floating-chat-window {
    background: #2d3748;
    border-color: rgba(255, 255, 255, 0.1);
  }
  
  .chat-window-content {
    background: #1a202c;
  }
  
  .chat-loading {
    color: #a0aec0;
  }
}

/* High contrast mode */
@media (prefers-contrast: high) {
  .floating-chat-window {
    border: 2px solid #000;
  }
  
  .chat-control-btn {
    border: 1px solid rgba(255, 255, 255, 0.3);
  }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  .floating-chat-window.opening,
  .floating-chat-window.closing {
    animation: none;
  }
  
  .chat-toggle-btn,
  .chat-control-btn,
  .floating-chat-window.minimized {
    transition: none;
  }
  
  .loading-spinner {
    animation: none;
  }
}