/* Global Chat Widget Styles - Premium Dark Glassmorphism Theme */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
  --chat-primary: #6c5ce7;
  --chat-primary-hover: #5b4cc4;
  --chat-accent: #a29bfe;
  --chat-bg: rgba(18, 20, 32, 0.94);
  --chat-card-bg: rgba(255, 255, 255, 0.05);
  --chat-border: rgba(108, 92, 231, 0.35);
  --chat-text: #f8fafc;
  --chat-text-muted: #94a3b8;
  --chat-user-msg: linear-gradient(135deg, #6c5ce7, #8b5cf6);
  --chat-other-msg: rgba(255, 255, 255, 0.08);
  --chat-shadow: 0 15px 35px rgba(0, 0, 0, 0.6), 0 0 20px rgba(108, 92, 231, 0.25);
}

/* Base Widget Container */
#global-chat-widget {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 99999;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  pointer-events: none;
}

/* Chat Button (Bubble) */
#chat-toggle-btn {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--chat-primary), #8b5cf6);
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.3);
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(108, 92, 231, 0.5), 0 0 15px rgba(139, 92, 246, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), box-shadow 0.3s ease;
  pointer-events: auto;
}

#chat-toggle-btn:hover {
  transform: scale(1.08) rotate(5deg);
  box-shadow: 0 8px 25px rgba(108, 92, 231, 0.7), 0 0 25px rgba(139, 92, 246, 0.5);
}

#chat-toggle-btn svg {
  width: 26px;
  height: 26px;
  fill: currentColor;
}

/* Chat Window */
#chat-window {
  width: 370px;
  height: 520px;
  max-height: calc(100vh - 120px);
  background: var(--chat-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--chat-border);
  border-radius: 20px;
  box-shadow: var(--chat-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  margin-bottom: 16px;
  opacity: 0;
  transform: translateY(20px) scale(0.95);
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  transform-origin: bottom right;
}

#chat-window.open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

#chat-header {
  padding: 14px 18px;
  background: linear-gradient(135deg, rgba(108, 92, 231, 0.9), rgba(139, 92, 246, 0.9));
  color: white;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 700;
  font-size: 15px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

#chat-user-profile {
  display: flex;
  align-items: center;
  gap: 8px;
}

#chat-emoji-btn {
  background: rgba(255, 255, 255, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.4);
  border-radius: 50%;
  width: 32px;
  height: 32px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  transition: all 0.2s ease;
}

#chat-emoji-btn:hover {
  background: rgba(255, 255, 255, 0.35);
  transform: scale(1.1);
}

#chat-emoji-picker {
  position: absolute;
  top: 60px;
  left: 15px;
  background: rgba(18, 20, 32, 0.98);
  border-radius: 12px;
  box-shadow: 0 10px 25px rgba(0,0,0,0.6);
  padding: 12px;
  z-index: 100;
  border: 1px solid rgba(108, 92, 231, 0.4);
  backdrop-filter: blur(12px);
}

.emoji-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}

.emoji-grid span {
  font-size: 20px;
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
  text-align: center;
  transition: background 0.2s, transform 0.2s;
}

.emoji-grid span:hover {
  background: rgba(255, 255, 255, 0.15);
  transform: scale(1.2);
}

#chat-close-btn {
  background: rgba(255, 255, 255, 0.15);
  border: none;
  border-radius: 50%;
  width: 28px;
  height: 28px;
  color: white;
  cursor: pointer;
  opacity: 0.9;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
}

#chat-close-btn:hover {
  opacity: 1;
  background: rgba(231, 76, 60, 0.6);
  transform: scale(1.1);
}

/* Views (Auth & Chat) */
.chat-view {
  display: none;
  flex: 1;
  flex-direction: column;
}

.chat-view.active {
  display: flex;
}

/* Auth View */
#chat-auth-view {
  padding: 30px 22px;
  align-items: center;
  justify-content: center;
  text-align: center;
  background: rgba(10, 11, 16, 0.4);
}

#chat-auth-view h3 {
  margin: 0 0 8px 0;
  color: #ffffff;
  font-size: 20px;
  font-weight: 700;
}

#chat-auth-view p {
  color: var(--chat-text-muted);
  font-size: 13px;
  line-height: 1.5;
  margin-bottom: 24px;
}

.chat-input-group {
  width: 100%;
  margin-bottom: 16px;
  text-align: left;
}

.chat-input-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: #e2e8f0;
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.chat-input-group input {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 10px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  box-sizing: border-box;
  color: #ffffff;
  background: rgba(255, 255, 255, 0.06);
}

.chat-input-group input:focus {
  border-color: var(--chat-primary);
  box-shadow: 0 0 0 3px rgba(108, 92, 231, 0.25);
  background: rgba(255, 255, 255, 0.1);
}

#chat-auth-btn {
  width: 100%;
  padding: 12px;
  background: linear-gradient(135deg, var(--chat-primary), #8b5cf6);
  color: white;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 15px rgba(108, 92, 231, 0.4);
  transition: all 0.2s ease;
}

#chat-auth-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(108, 92, 231, 0.6);
}

#chat-auth-error {
  color: #ff6b6b;
  font-size: 13px;
  margin-top: 12px;
  display: none;
  font-weight: 500;
}

/* Chat Messages View */
#chat-messages {
  flex: 1;
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: rgba(10, 11, 16, 0.6);
}

.chat-message {
  max-width: 82%;
  animation: fadeIn 0.3s ease;
}

.chat-message .sender {
  font-size: 11px;
  color: var(--chat-text-muted);
  margin-bottom: 4px;
  margin-left: 4px;
  display: flex;
  justify-content: flex-start;
  align-items: center;
  gap: 6px;
  font-weight: 500;
}

.chat-message .timestamp {
  color: #64748b;
  font-size: 9px;
}

.chat-message .bubble {
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.45;
  color: #f1f5f9;
  background: var(--chat-other-msg);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-bottom-left-radius: 4px;
  word-break: break-word;
}

.chat-message.self {
  align-self: flex-end;
}

.chat-message.self .sender {
  justify-content: flex-end;
  margin-right: 4px;
  margin-left: 0;
}

.chat-message.self .bubble {
  background: var(--chat-user-msg);
  color: #ffffff;
  border: none;
  border-bottom-left-radius: 16px;
  border-bottom-right-radius: 4px;
  box-shadow: 0 4px 12px rgba(108, 92, 231, 0.3);
}

/* Chat Input Area */
#chat-input-area {
  padding: 12px 16px;
  background: rgba(18, 20, 32, 0.95);
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  gap: 10px;
  align-items: center;
}

#chat-input-area input {
  flex: 1;
  padding: 10px 16px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 20px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s, background 0.2s;
  color: #ffffff;
  background: rgba(255, 255, 255, 0.06);
}

#chat-input-area input:focus {
  border-color: var(--chat-primary);
  background: rgba(255, 255, 255, 0.1);
}

#chat-send-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--chat-primary), #8b5cf6);
  color: white;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(108, 92, 231, 0.4);
  transition: transform 0.2s, box-shadow 0.2s;
}

#chat-send-btn:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 16px rgba(108, 92, 231, 0.6);
}

#chat-send-btn svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
  margin-left: 2px;
}

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

@media (max-width: 480px) {
  #chat-window {
    width: calc(100vw - 32px);
    height: calc(100vh - 120px);
    bottom: 80px;
    right: 16px;
  }
  #global-chat-widget {
    bottom: 16px;
    right: 16px;
  }
}
