/**
 * KAIA Chat Widget — Kogga.IT
 * Floating chat UI with message bubbles, typing indicator, and responsive layout.
 * Self-contained — no CSS variable dependencies.
 *
 * @version 2.0.0
 * @author  Kogga.IT
 * @see     docs/CHAT-WIDGET.md
 */

/* ========== TOGGLE BUTTON ========== */
#kogga-chat-btn {
  position: fixed;
  z-index: 99999;
  bottom: 24px;
  right: 24px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: #1a6ff5;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(26, 111, 245, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}
#kogga-chat-btn:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 28px rgba(26, 111, 245, 0.45);
}
#kogga-chat-btn svg { width: 28px; height: 28px; }
#kogga-chat-btn .icon-close { display: none; }
#kogga-chat-btn.open .icon-chat { display: none; }
#kogga-chat-btn.open .icon-close { display: block; }
#kogga-chat-btn.open {
  background: #0a1628;
  box-shadow: 0 4px 20px rgba(10, 22, 40, 0.35);
}

/* ========== CHAT WINDOW ========== */
#kogga-chat-window {
  position: fixed;
  z-index: 99998;
  bottom: 96px;
  right: 24px;
  width: 400px;
  height: 560px;
  border-radius: 20px;
  background: #ffffff;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.15), 0 2px 8px rgba(0, 0, 0, 0.08);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: translateY(16px) scale(0.96);
  pointer-events: none;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
#kogga-chat-window.open {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}

/* ========== HEADER ========== */
.kc-header {
  padding: 16px 20px;
  background: linear-gradient(135deg, #1a6ff5, #0ea5e9);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
.kc-header-info {
  display: flex;
  align-items: center;
  gap: 12px;
}
.kc-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Outfit', system-ui, sans-serif;
  font-weight: 800;
  font-size: 15px;
}
.kc-name {
  font-family: 'Outfit', system-ui, sans-serif;
  font-weight: 700;
  font-size: 15px;
}
.kc-status {
  font-size: 11px;
  opacity: 0.85;
  display: flex;
  align-items: center;
  gap: 5px;
}
.kc-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #4ade80;
  display: inline-block;
  animation: kcPulse 2s infinite;
}
@keyframes kcPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}
.kc-close {
  background: rgba(255, 255, 255, 0.1);
  border: none;
  cursor: pointer;
  color: rgba(255, 255, 255, 0.7);
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  transition: all 0.15s;
}
.kc-close:hover {
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
}

/* ========== MESSAGES ========== */
.kc-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  scroll-behavior: smooth;
  background: #f7f8fb;
}

/* Scrollbar */
.kc-messages::-webkit-scrollbar { width: 5px; }
.kc-messages::-webkit-scrollbar-track { background: transparent; }
.kc-messages::-webkit-scrollbar-thumb { background: #c8ceda; border-radius: 10px; }

/* ========== WELCOME ========== */
.kc-welcome {
  text-align: center;
  padding: 40px 20px 20px;
  color: #7a8599;
  font-size: 13px;
  line-height: 1.6;
}
.kc-welcome-icon { margin-bottom: 12px; }
.kc-welcome strong {
  display: block;
  font-family: 'Outfit', system-ui, sans-serif;
  font-size: 16px;
  color: #0a1628;
  margin-bottom: 8px;
}
.kc-welcome p {
  font-size: 13px;
  color: #7a8599;
  margin: 0;
}

/* ========== MESSAGE BUBBLES ========== */
.kc-msg {
  max-width: 82%;
  padding: 10px 16px;
  font-size: 13.5px;
  line-height: 1.6;
  word-break: break-word;
  animation: kcFadeIn 0.25s ease;
}
.kc-msg.user {
  align-self: flex-end;
  background: #1a6ff5;
  color: #fff;
  border-radius: 16px 16px 6px 16px;
}
.kc-msg.agent {
  align-self: flex-start;
  background: #ffffff;
  color: #1a2332;
  border-radius: 16px 16px 16px 6px;
  border: 1px solid #e2e6ee;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}
.kc-msg.agent strong { color: #0a1628; }
.kc-msg-time {
  font-size: 10px;
  color: #7a8599;
  padding: 0 4px 4px;
  align-self: flex-end;
}
.kc-msg-time.left { align-self: flex-start; }

@keyframes kcFadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

/* ========== TYPING INDICATOR ========== */
.kc-typing {
  align-self: flex-start;
  padding: 14px 20px;
  background: #ffffff;
  border: 1px solid #e2e6ee;
  border-radius: 16px 16px 16px 6px;
  display: flex;
  gap: 5px;
  animation: kcFadeIn 0.2s ease;
}
.kc-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #7a8599;
  animation: kcBounce 0.6s infinite alternate;
}
.kc-typing span:nth-child(2) { animation-delay: 0.15s; }
.kc-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes kcBounce {
  to { transform: translateY(-5px); opacity: 0.4; }
}

/* ========== INPUT ========== */
.kc-input-area {
  padding: 12px 16px;
  border-top: 1px solid #e2e6ee;
  background: #ffffff;
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}
.kc-input {
  flex: 1;
  border: 1.5px solid #e2e6ee;
  border-radius: 24px;
  padding: 10px 18px;
  font-size: 13.5px;
  font-family: 'Source Sans 3', system-ui, sans-serif;
  outline: none;
  background: #f7f8fb;
  color: #1a2332;
  transition: border-color 0.15s;
}
.kc-input:focus {
  border-color: #1a6ff5;
  box-shadow: 0 0 0 3px rgba(26, 111, 245, 0.1);
  background: #ffffff;
}
.kc-input::placeholder { color: #7a8599; }

.kc-send {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #1a6ff5;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  flex-shrink: 0;
}
.kc-send:hover:not(:disabled) {
  transform: scale(1.05);
  box-shadow: 0 2px 8px rgba(26, 111, 245, 0.3);
}
.kc-send:disabled {
  opacity: 0.35;
  cursor: default;
  transform: none;
}

/* ========== POWERED BY ========== */
.kc-powered {
  text-align: center;
  padding: 6px;
  font-size: 9px;
  color: #7a8599;
  background: #ffffff;
  border-top: 1px solid #e2e6ee;
}
.kc-powered a { color: #7a8599; text-decoration: none; }
.kc-powered a:hover { text-decoration: underline; }

/* ========== RESPONSIVE ========== */
@media (max-width: 480px) {
  #kogga-chat-window {
    width: calc(100vw - 16px);
    height: calc(100vh - 100px);
    left: 8px;
    right: 8px;
    bottom: 88px;
    border-radius: 16px;
  }
  #kogga-chat-btn {
    bottom: 16px;
    right: 16px;
    width: 54px;
    height: 54px;
  }
}