/* ==================== CHAT BOX ==================== */
#chatBox {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 320px;
  max-height: 450px;
  background: rgba(255, 255, 255, 0.98);
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  display: flex;
  flex-direction: column;
  z-index: 9990;
  transition: all 0.3s ease;
  overflow: hidden;
}

#chatBox.minimized {
  max-height: 50px;
}

#chatBox.minimized #chatMessages,
#chatBox.minimized #chatInputArea {
  display: none;
}

/* New message notification animation */
#chatBox.minimized.has-new-message #chatHeader {
  animation: chat-notification 1s infinite;
}

@keyframes chat-notification {
  0%, 100% {
    background: linear-gradient(135deg, #1976d2, #1565c0);
    box-shadow: 0 0 0 rgba(25, 118, 210, 0);
  }
  50% {
    background: linear-gradient(135deg, #2196f3, #1976d2);
    box-shadow: 0 0 20px rgba(25, 118, 210, 0.8);
  }
}

/* Notification badge */
#chatBox.minimized.has-new-message #chatHeader::after {
  content: '●';
  position: absolute;
  right: 50px;
  top: 50%;
  transform: translateY(-50%);
  color: #ff4444;
  font-size: 24px;
  animation: pulse-notification 1s infinite;
}

@keyframes pulse-notification {
  0%, 100% {
    transform: translateY(-50%) scale(1);
    opacity: 1;
  }
  50% {
    transform: translateY(-50%) scale(1.2);
    opacity: 0.8;
  }
}

#chatHeader {
  background: linear-gradient(135deg, #1976d2, #1565c0);
  color: white;
  padding: 12px 15px;
  font-weight: bold;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-radius: 16px 16px 0 0;
  cursor: pointer;
  user-select: none;
  position: relative;
  transition: all 0.3s ease;
}

#chatHeader:hover {
  background: linear-gradient(135deg, #2196f3, #1976d2);
}

#chatToggle {
  background: rgba(255, 255, 255, 0.2);
  border: none;
  color: white;
  font-size: 1.5em;
  font-weight: bold;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.3s;
  z-index: 10;
}

#chatToggle:hover {
  background: rgba(255, 255, 255, 0.3);
}

#chatMessages {
  flex: 1;
  overflow-y: auto;
  padding: 15px;
  background: white;
  max-height: 350px;
  min-height: 200px;
}

.chat-message {
  margin-bottom: 12px;
  padding: 10px;
  border-radius: 10px;
  background: rgba(33, 150, 243, 0.1);
  word-wrap: break-word;
  animation: slideInChat 0.3s ease;
}

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

.chat-message.my-message {
  background: rgba(76, 175, 80, 0.15);
  border-left: 3px solid #4caf50;
}

.chat-message.other-message {
  background: rgba(33, 150, 243, 0.15);
  border-left: 3px solid #2196f3;
}

.chat-sender {
  font-weight: bold;
  color: #1976d2;
  margin-bottom: 4px;
  font-size: 0.9em;
}

.chat-message.my-message .chat-sender {
  color: #2e7d32;
}

.chat-text {
  color: #333;
  font-size: 0.95em;
  line-height: 1.4;
}

.chat-timestamp {
  font-size: 0.75em;
  color: #999;
  margin-top: 4px;
}

#chatInputArea {
  display: flex;
  padding: 12px;
  background: #f5f5f5;
  border-radius: 0 0 16px 16px;
  gap: 8px;
}

#chatInput {
  flex: 1;
  padding: 10px 12px;
  border: 2px solid #ddd;
  border-radius: 20px;
  font-size: 0.95em;
  outline: none;
  transition: border-color 0.3s;
}

#chatInput:focus {
  border-color: #1976d2;
}

#sendChatBtn {
  background: linear-gradient(135deg, #1976d2, #1565c0);
  color: white;
  border: none;
  border-radius: 50%;
  width: 42px;
  height: 42px;
  font-size: 1.2em;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s;
  flex-shrink: 0;
}

#sendChatBtn:hover {
  background: linear-gradient(135deg, #2196f3, #1976d2);
  transform: scale(1.05);
}

#sendChatBtn:active {
  transform: scale(0.95);
}

/* Scrollbar styling for chat */
#chatMessages::-webkit-scrollbar {
  width: 6px;
}

#chatMessages::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 10px;
}

#chatMessages::-webkit-scrollbar-thumb {
  background: #1976d2;
  border-radius: 10px;
}

#chatMessages::-webkit-scrollbar-thumb:hover {
  background: #1565c0;
}

/* ==================== RESPONSIVE CHAT ==================== */
@media (max-width: 768px) and (orientation: portrait) {
  #chatBox {
    width: 90vw;
    max-width: 350px;
    bottom: 15px;
    right: 15px;
  }
  
  #chatMessages {
    max-height: 280px;
    min-height: 180px;
  }
}

@media (max-width: 480px) {
  #chatBox {
    width: calc(100vw - 20px);
    max-width: none;
    bottom: 10px;
    right: 10px;
    left: 10px;
  }
  
  #chatHeader {
    padding: 10px 12px;
    font-size: 0.95em;
  }
  
  #chatMessages {
    max-height: 250px;
    min-height: 150px;
    padding: 10px;
  }
  
  .chat-message {
    padding: 8px;
    margin-bottom: 10px;
  }
  
  #chatInputArea {
    padding: 10px;
  }
  
  #chatInput {
    padding: 8px 10px;
    font-size: 0.9em;
  }
  
  #sendChatBtn {
    width: 38px;
    height: 38px;
    font-size: 1.1em;
  }
}

@media (max-width: 896px) and (orientation: landscape) {
  #chatBox {
    width: 280px;
    max-height: 350px;
    bottom: 15px;
    right: 15px;
  }
  
  #chatMessages {
    max-height: 250px;
    min-height: 150px;
  }
  
  #chatHeader {
    padding: 8px 12px;
    font-size: 0.9em;
  }
}

@media (max-height: 500px) and (orientation: landscape) {
  #chatBox {
    max-height: 300px;
  }
  
  #chatMessages {
    max-height: 200px;
    min-height: 120px;
  }
}

/* System message styling */
.chat-message.system-message {
  background: rgba(255, 193, 7, 0.15);
  border-left: 3px solid #ffc107;
  text-align: center;
  font-style: italic;
}

.chat-message.system-message .chat-text {
  color: #f57c00;
  font-weight: 500;
}
