/* =========================================================
   Modern Professional Chat CSS - "Nexus Theme"
   ========================================================= */

:root {
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --bg-dark: #0f172a;
  --bg-card: #1e293b;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --msg-sent: linear-gradient(135deg, #6366f1, #8b5cf6);
  --msg-received: #334155;
  --glass-bg: rgba(30, 41, 59, 0.7);
  --glass-border: rgba(255, 255, 255, 0.1);
}

body {
  font-family: 'Inter', sans-serif;
  background-color: var(--bg-dark);
  /* Abstract dark background */
  background-image: 
      radial-gradient(circle at top right, rgba(99, 102, 241, 0.15), transparent 40%),
      radial-gradient(circle at bottom left, rgba(139, 92, 246, 0.15), transparent 40%);
  background-attachment: fixed;
  height: 100vh;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-main);
}

/* =========================================================
   Container & Layout 
   ========================================================= */
.chat-wrapper {
  width: 100%;
  max-width: 1000px;
  height: 90vh; /* Responsive scaling */
  padding: 24px;
}

@media (max-width: 768px) {
  .chat-wrapper {
      height: 100vh;
      padding: 0;
  }
}

.chat-container {
  background: var(--bg-card);
  border: 1px solid var(--glass-border);
  border-radius: 24px;
  overflow: hidden;
  height: 100%;
  display: flex;
  flex-direction: column;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(10px);
}

@media (max-width: 768px) {
  .chat-container {
      border-radius: 0;
      border: none;
  }
}

/* =========================================================
   Header 
   ========================================================= */
.chat-header {
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--glass-border);
  z-index: 10;
}

.header-avatar img {
  width: 48px;
  height: 48px;
  border-radius: 16px;
  object-fit: cover;
  border: 2px solid var(--glass-border);
}

.online-badge {
  position: absolute;
  bottom: -2px;
  right: -2px;
  width: 14px;
  height: 14px;
  background-color: #10b981;
  border: 2px solid var(--bg-card);
  border-radius: 50%;
  animation: pulse-green 2s infinite;
}

.btn-icon {
  color: var(--text-muted);
  font-size: 1.25rem;
  transition: all 0.3s ease;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  border: none;
  background: transparent;
}

.btn-icon:hover {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.1);
}

.badge-glass {
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--glass-border);
  color: var(--text-muted);
  font-weight: 500;
  padding: 6px 16px;
}

/* =========================================================
   Chat Body & Messages
   ========================================================= */
.card-body.chat-body {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  background: transparent;
  scroll-behavior: smooth;
  display: flex;
  flex-direction: column;
}

/* Custom Webkit Scrollbar */
.chat-body::-webkit-scrollbar { width: 6px; }
.chat-body::-webkit-scrollbar-track { background: transparent; }
.chat-body::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 10px;
}
.chat-body::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.2); }

/* Message Container */
.message-container {
  width: 100%;
  max-width: 100%;
  animation: slideUpFade 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
  transform-origin: bottom;
  align-items: flex-end; /* Align avatars with bubble base */
  margin-bottom: 20px !important;
}

/* Avatar added by client.js to messages */
.message-container .avatar {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  object-fit: cover;
  box-shadow: 0 4px 6px rgba(0,0,0,0.1);
  margin-left: 14px;
  margin-right: 14px;
}

/* Hide avatars for sent optionally to keep it clean, but client.js uses avatar on both sent & received */
.message-container.justify-content-end .avatar {
  background: transparent;
}

/* Container for bubble and time */
.message-container > div:not(.avatar) {
  max-width: 70%;
  display: flex;
  flex-direction: column;
}

/* Core Message Bubble */
.message {
  padding: 12px 18px;
  font-size: 0.95rem;
  line-height: 1.5;
  border-radius: 20px;
  word-wrap: break-word;
  word-break: break-word;
  margin-bottom: 6px;
  box-shadow: 0 4px 15px rgba(0,0,0,0.1);
  color: var(--text-main);
  position: relative;
  width: fit-content;
}

/* Specific Sent Message */
.message.sent {
  background: var(--msg-sent);
  border-bottom-right-radius: 4px;
  align-self: flex-end;
}

/* Specific Received Message */
.message.received {
  background: var(--msg-received);
  border: 1px solid var(--glass-border);
  border-bottom-left-radius: 4px;
  align-self: flex-start;
}

/* Timestamps */
.message-time {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin: 0;
  opacity: 0.8;
  font-weight: 500;
}

/* Typing Indicator Overlay */
#typing-indicator {
  display: none !important; /* Managed by JS, override flex behavior specifically */
  position: absolute;
  bottom: 0px; 
  left: 36px;
  z-index: 50;
  margin-bottom: 10px;
}

/* Client.js uses style.display = 'flex' natively, so we ensure standard block/flex logic */
#typing-indicator[style*="display: flex"] {
  display: flex !important;
}

.typing-glass {
  background: rgba(51, 65, 85, 0.9);
  backdrop-filter: blur(8px);
  border: 1px solid var(--glass-border);
  padding: 12px 16px;
  border-radius: 20px;
  border-bottom-left-radius: 4px;
  display: flex;
  align-items: center;
  gap: 6px;
  box-shadow: 0 10px 15px -3px rgba(0,0,0,0.2);
  animation: fade-in-up 0.3s ease;
}

.typing-glass .dot {
  width: 6px;
  height: 6px;
  background-color: var(--text-muted);
  border-radius: 50%;
  animation: typing-bounce 1.4s infinite both;
}
.typing-glass .dot:nth-child(1) { animation-delay: -0.32s; }
.typing-glass .dot:nth-child(2) { animation-delay: -0.16s; }

/* =========================================================
   Footer & Input 
   ========================================================= */
.chat-footer {
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--glass-border);
}

.input-group-modern {
  background: rgba(30, 41, 59, 0.8);
  border: 1px solid var(--glass-border);
  border-radius: 20px;
  padding: 6px 12px;
  transition: all 0.3s ease;
}

.input-group-modern:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.15);
  background: rgba(30, 41, 59, 1);
}

.chat-input {
  background: transparent !important;
  border: none !important;
  color: var(--text-main) !important;
  box-shadow: none !important;
  padding: 10px 12px;
}

.chat-input::placeholder {
  color: var(--text-muted);
}

.btn-action-icon {
  font-size: 1.4rem;
  padding: 6px;
  border: none;
  background: transparent;
  transition: color 0.2s ease, transform 0.2s ease;
}

.btn-action-icon:hover {
  color: var(--primary) !important;
  transform: scale(1.1);
}

.btn-send {
  background: var(--primary);
  color: white;
  border-radius: 14px;
  width: 44px;
  height: 44px;
  outline: none;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.btn-send i {
  margin-left: -2px; /* slight visual offset adjustment */
}

.btn-send:hover {
  background: var(--primary-hover);
  transform: scale(1.05) rotate(5deg);
  box-shadow: 0 4px 15px rgba(99, 102, 241, 0.4);
  color: white;
}

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

/* =========================================================
   Animations 
   ========================================================= */
@keyframes slideUpFade {
  0% {
      opacity: 0;
      transform: translateY(30px) scale(0.95);
  }
  100% {
      opacity: 1;
      transform: translateY(0) scale(1);
  }
}

@keyframes typing-bounce {
  0%, 80%, 100% { transform: scale(0); opacity: 0.5; }
  40% { transform: scale(1.2); opacity: 1; background: var(--primary); }
}

@keyframes pulse-green {
  0% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.4); }
  70% { box-shadow: 0 0 0 6px rgba(16, 185, 129, 0); }
  100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

@keyframes fade-in-up {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}