/* ============================================================
   DK.COFFEE - AI Chat Widget Styles
   ============================================================ */

/* --- Chat Toggle Button --- */
.chat-toggle {
  position: fixed;
  bottom: 30px;
  right: 30px;
  z-index: 9998;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--gradient-primary);
  border: none;
  cursor: pointer;
  box-shadow: 0 8px 32px rgba(0, 212, 255, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.3s ease, box-shadow 0.3s ease, opacity 0.3s ease;
  overflow: hidden;
}

.chat-toggle:hover {
  transform: scale(1.08);
  box-shadow: 0 12px 40px rgba(0, 212, 255, 0.5);
}

.chat-toggle:active {
  transform: scale(0.95);
}

.chat-toggle svg {
  width: 28px;
  height: 28px;
  fill: none;
  stroke: #fff;
  stroke-width: 2;
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.chat-toggle .icon-chat { opacity: 1; transform: scale(1); }
.chat-toggle .icon-close { opacity: 0; transform: scale(0); position: absolute; }

.chat-toggle.active .icon-chat { opacity: 0; transform: scale(0); position: absolute; }
.chat-toggle.active .icon-close { opacity: 1; transform: scale(1); position: static; }

/* Pulse ring */
.chat-toggle::after {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid rgba(0, 212, 255, 0.3);
  animation: chatPulse 2s ease-in-out infinite;
}

@keyframes chatPulse {
  0%, 100% { transform: scale(1); opacity: 0.5; }
  50% { transform: scale(1.08); opacity: 1; }
}

.chat-toggle.active::after {
  animation: none;
  opacity: 0;
}

/* Notification dot */
.chat-toggle .chat-dot {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #ef4444;
  border: 2px solid #fff;
  display: none;
}

.chat-toggle .chat-dot.show {
  display: block;
}

/* --- Backdrop --- */
.chat-backdrop {
  position: fixed;
  inset: 0;
  z-index: 9997;
  background: rgba(0, 0, 0, 0.45);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.35s ease;
}

.chat-backdrop.active {
  opacity: 1;
  pointer-events: all;
}

/* --- Chat Panel --- */
.chat-panel {
  position: fixed;
  bottom: 110px;
  right: 30px;
  z-index: 9999;
  width: 420px;
  max-width: calc(100vw - 60px);
  height: 600px;
  max-height: calc(100vh - 160px);
  background: #0d1117;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5), 0 0 40px rgba(0, 212, 255, 0.08);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateY(20px) scale(0.95);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1),
              opacity 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

.chat-panel.open {
  transform: translateY(0) scale(1);
  opacity: 1;
  pointer-events: all;
}

/* --- Chat Header --- */
.chat-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(255, 255, 255, 0.02);
  flex-shrink: 0;
}

.chat-header-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.chat-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--gradient-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: #fff;
  flex-shrink: 0;
}

.chat-header-text h3 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
}

.chat-header-text span {
  font-size: 12px;
  color: var(--accent-cyan);
  display: flex;
  align-items: center;
  gap: 4px;
}

.chat-header-text span::before {
  content: '';
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #22c55e;
}

.chat-header-actions {
  display: flex;
  gap: 8px;
}

.chat-header-btn {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: all var(--transition);
}

.chat-header-btn:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
  border-color: var(--border-hover);
}

.chat-header-btn svg {
  width: 16px;
  height: 16px;
}

/* --- Chat Messages --- */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scroll-behavior: smooth;
}

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

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

.chat-messages::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
}

/* Welcome message */
.chat-welcome {
  text-align: center;
  padding: 30px 20px;
}

.chat-welcome-icon {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: linear-gradient(135deg, rgba(0, 212, 255, 0.15), rgba(124, 58, 237, 0.15));
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 16px;
  font-size: 30px;
}

.chat-welcome h4 {
  font-size: 16px;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.chat-welcome p {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.6;
}

.chat-quick-asks {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-top: 16px;
}

.chat-quick-ask {
  padding: 8px 14px;
  border-radius: 20px;
  border: 1px solid var(--border-color);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}

.chat-quick-ask:hover {
  background: rgba(0, 212, 255, 0.1);
  border-color: var(--accent-cyan);
  color: var(--accent-cyan);
}

/* Message bubbles */
.chat-msg {
  display: flex;
  gap: 10px;
  animation: msgIn 0.3s ease;
}

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

.chat-msg.user {
  flex-direction: row-reverse;
}

.chat-msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}

.chat-msg.assistant .chat-msg-avatar {
  background: linear-gradient(135deg, #00d4ff, #7c3aed);
  color: #fff;
}

.chat-msg.user .chat-msg-avatar {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-primary);
}

.chat-msg-bubble {
  max-width: 75%;
  padding: 12px 16px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.65;
  word-break: break-word;
}

.chat-msg.assistant .chat-msg-bubble {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.06);
  color: var(--text-primary);
  border-bottom-left-radius: 6px;
}

.chat-msg.user .chat-msg-bubble {
  background: linear-gradient(135deg, rgba(0, 212, 255, 0.25), rgba(124, 58, 237, 0.25));
  color: #fff;
  border-bottom-right-radius: 6px;
}

/* Typing indicator */
.chat-typing {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 0;
}

.chat-typing span {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent-cyan);
  animation: typingDot 1.4s ease-in-out infinite;
}

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

@keyframes typingDot {
  0%, 60%, 100% { opacity: 0.3; transform: scale(0.8); }
  30% { opacity: 1; transform: scale(1.2); }
}

/* KB source tag */
.chat-kb-tag {
  display: inline-block;
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 10px;
  background: rgba(0, 212, 255, 0.15);
  color: var(--accent-cyan);
  margin-bottom: 8px;
}

/* --- Chat Input --- */
.chat-input-area {
  padding: 16px 20px;
  border-top: 1px solid var(--border-color);
  background: rgba(255, 255, 255, 0.02);
  flex-shrink: 0;
}

.chat-input-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

.chat-input {
  flex: 1;
  padding: 12px 16px;
  border-radius: 24px;
  border: 1px solid var(--border-color);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
  font-size: 14px;
  font-family: inherit;
  resize: none;
  outline: none;
  min-height: 44px;
  max-height: 120px;
  transition: border-color var(--transition), background var(--transition);
  line-height: 1.5;
}

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

.chat-input:focus {
  border-color: var(--accent-cyan);
  background: rgba(255, 255, 255, 0.08);
}

.chat-send-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: var(--gradient-primary);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all var(--transition);
  box-shadow: 0 4px 16px rgba(0, 212, 255, 0.3);
}

.chat-send-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 24px rgba(0, 212, 255, 0.45);
}

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

.chat-send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.chat-send-btn svg {
  width: 20px;
  height: 20px;
  transition: transform 0.2s ease;
}

.chat-send-btn:not(:disabled):hover svg {
  transform: translateX(2px);
}


/* --- Responsive --- */
@media (max-width: 640px) {
  .chat-panel {
    width: calc(100vw - 30px);
    right: 15px;
    bottom: 75px;
    height: calc(100vh - 95px);
    max-height: calc(100vh - 95px);
    border-radius: 16px;
  }

  .chat-panel.open {
    transform: translateY(0) scale(1);
  }

  .chat-header {
    height: 35px;
    padding: 4px 10px;
    box-sizing: border-box;
  }

  .chat-avatar {
    width: 24px;
    height: 24px;
    font-size: 11px;
  }

  .chat-header-text h3 {
    font-size: 12px;
  }

  .chat-header-text span {
    font-size: 10px;
  }

  .chat-header-btn {
    width: 20px;
    height: 20px;
    border-radius: 5px;
  }

  .chat-header-btn svg {
    width: 11px;
    height: 11px;
  }

  .chat-messages {
    padding: 10px;
    gap: 8px;
  }

  .chat-input-area {
    padding: 5px 10px;
  }

  .chat-input {
    padding: 7px 10px;
    font-size: 13px;
    min-height: 32px;
  }

  .chat-send-btn {
    width: 32px;
    height: 32px;
  }

  .chat-send-btn svg {
    width: 16px;
    height: 16px;
  }

  .chat-toggle {
    right: 15px;
    bottom: 15px;
    width: 48px;
    height: 48px;
  }

  .chat-toggle svg {
    width: 22px;
    height: 22px;
  }
}
