/* ✅ MK Created 2026-03-11: Premium Live Chat Widget — Visitor Side */

:root {
  --chat-accent: #0d9488;
  --chat-accent-dark: #0f766e;
  --chat-radius: 20px;
  --chat-font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --chat-shadow: 0 20px 60px rgba(15, 23, 42, 0.18), 0 4px 20px rgba(15, 23, 42, 0.08);
  --chat-shadow-sm: 0 4px 16px rgba(15, 23, 42, 0.10);
}

/* ── Launcher Button ──────────────────────────────────────────────────────── */
#chatLauncher {
  position: fixed;
  bottom: 28px;
  right: 28px;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: var(--chat-accent);
  border: none;
  cursor: pointer;
  display: none; /* hidden until admin opens chat for first time */
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(13, 148, 136, 0.45);
  z-index: 99998;
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.2s;
  animation: chatLauncherPop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}
#chatLauncher:hover {
  transform: scale(1.08);
  box-shadow: 0 8px 28px rgba(13, 148, 136, 0.55);
}
#chatLauncher svg {
  width: 26px;
  height: 26px;
  fill: #fff;
  transition: transform 0.2s;
  flex-shrink: 0;
}
#chatLauncher.open svg.icon-chat  { display: none; }
#chatLauncher.open svg.icon-close { display: block !important; }
#chatLauncher svg.icon-close      { display: none; }

/* Unread notification dot on launcher */
#chatLauncherDot {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 14px;
  height: 14px;
  background: #ef4444;
  border-radius: 50%;
  border: 2px solid #fff;
  display: none;
  animation: chatPulse 1.5s infinite;
  pointer-events: none;
}

/* ── Chat Window ──────────────────────────────────────────────────────────── */
#chatWindow {
  position: fixed;
  bottom: 100px;
  right: 28px;
  width: 370px;
  max-height: 560px;
  background: #fff;
  border-radius: var(--chat-radius);
  box-shadow: var(--chat-shadow);
  z-index: 99999;
  display: none;
  flex-direction: column;
  overflow: hidden;
  font-family: var(--chat-font);
  border: 1px solid rgba(15, 23, 42, 0.06);
  transform: translateY(12px) scale(0.97);
  opacity: 0;
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.25s ease;
}
#chatWindow.visible {
  transform: translateY(0) scale(1);
  opacity: 1;
}

/* ── Chat Header ──────────────────────────────────────────────────────────── */
#chatHeader {
  background: var(--chat-accent);
  padding: 18px 20px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}
#chatAgentAvatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  flex-shrink: 0;
  border: 2px solid rgba(255, 255, 255, 0.4);
  overflow: hidden;
}
#chatAgentAvatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
#chatHeaderInfo  { flex: 1; min-width: 0; }
#chatAgentName {
  color: #fff;
  font-weight: 700;
  font-size: 0.92rem;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#chatAgentStatus {
  color: rgba(255, 255, 255, 0.82);
  font-size: 0.72rem;
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 3px;
}
#chatAgentStatus::before {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #4ade80;
  display: inline-block;
  flex-shrink: 0;
  box-shadow: 0 0 6px rgba(74, 222, 128, 0.7);
}
#chatMinimize {
  background: rgba(255, 255, 255, 0.18);
  border: none;
  color: #fff;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  line-height: 1;
  transition: background 0.15s;
  flex-shrink: 0;
  font-weight: 300;
}
#chatMinimize:hover { background: rgba(255, 255, 255, 0.32); }

/* ── Messages Area ────────────────────────────────────────────────────────── */
#chatMessages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 200px;
  max-height: 340px;
  scroll-behavior: smooth;
  background: #fafbfc;
}
#chatMessages::-webkit-scrollbar { width: 4px; }
#chatMessages::-webkit-scrollbar-track { background: transparent; }
#chatMessages::-webkit-scrollbar-thumb { background: #e2e8f0; border-radius: 4px; }

/* ── Message Bubbles ──────────────────────────────────────────────────────── */
.chat-msg {
  display: flex;
  flex-direction: column;
  max-width: 82%;
  animation: chatMsgIn 0.25s ease-out;
}
.chat-msg.admin   { align-self: flex-start; }
.chat-msg.visitor { align-self: flex-end;   }

.chat-bubble {
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 0.875rem;
  line-height: 1.55;
  word-break: break-word;
  white-space: pre-wrap;
}
.chat-msg.admin .chat-bubble {
  background: #f1f5f9;
  color: #1e293b;
  border-bottom-left-radius: 4px;
}
.chat-msg.visitor .chat-bubble {
  background: var(--chat-accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.chat-msg-time {
  font-size: 0.68rem;
  color: #94a3b8;
  margin-top: 3px;
  padding: 0 4px;
}
.chat-msg.visitor .chat-msg-time { text-align: right; }

/* ── Typing Indicator ─────────────────────────────────────────────────────── */
#chatTyping {
  display: none;
  align-items: center;
  gap: 4px;
  padding: 9px 14px;
  background: #f1f5f9;
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  width: fit-content;
  align-self: flex-start;
}
#chatTyping span {
  width: 7px;
  height: 7px;
  background: #94a3b8;
  border-radius: 50%;
  animation: chatTypingDot 1.2s infinite;
  display: block;
}
#chatTyping span:nth-child(2) { animation-delay: 0.2s; }
#chatTyping span:nth-child(3) { animation-delay: 0.4s; }

/* ── Input Area ───────────────────────────────────────────────────────────── */
#chatInputArea {
  padding: 10px 12px 12px;
  border-top: 1px solid #f1f5f9;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  flex-shrink: 0;
  background: #fff;
}
#chatInput {
  flex: 1;
  border: 1.5px solid #e2e8f0;
  border-radius: 14px;
  padding: 10px 14px;
  font-size: 0.875rem;
  font-family: var(--chat-font);
  color: #1e293b;
  background: #fff;
  resize: none;
  outline: none;
  max-height: 100px;
  min-height: 42px;
  line-height: 1.45;
  transition: border-color 0.15s;
  overflow-y: auto;
}
#chatInput:focus { border-color: var(--chat-accent); }
#chatInput::placeholder { color: #94a3b8; }
#chatSendBtn {
  width: 40px;
  height: 40px;
  background: var(--chat-accent);
  border: none;
  border-radius: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.15s;
}
#chatSendBtn:hover { background: var(--chat-accent-dark); transform: scale(1.06); }
#chatSendBtn svg   { width: 18px; height: 18px; fill: #fff; }
#chatSendBtn:disabled { opacity: 0.5; cursor: default; transform: none; }

/* ── Powered-by footer ────────────────────────────────────────────────────── */
#chatPoweredBy {
  text-align: center;
  font-size: 0.65rem;
  color: #cbd5e1;
  padding: 4px 0 6px;
  letter-spacing: 0.02em;
  background: #fff;
  flex-shrink: 0;
}

/* ── Animations ───────────────────────────────────────────────────────────── */
@keyframes chatLauncherPop {
  from { transform: scale(0); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}
@keyframes chatMsgIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes chatTypingDot {
  0%, 60%, 100% { transform: translateY(0);    opacity: 0.4; }
  30%           { transform: translateY(-5px); opacity: 1;   }
}
@keyframes chatPulse {
  0%, 100% { transform: scale(1);   opacity: 1;   }
  50%      { transform: scale(1.3); opacity: 0.7; }
}

/* ── Intercom-style notification bubble ───────────────────────────────────── */
/* ✅ MK Updated 2026-03-11: Clean, white, subtle — Intercom-style */
@keyframes chatNotifUp {
  0%   { transform: translateY(16px); opacity: 0; }
  100% { transform: translateY(0);    opacity: 1; }
}
#chatNotifBubble {
  position: fixed;
  bottom: 100px;
  right: 24px;
  z-index: 99999;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: #fff;
  border-radius: 14px;
  padding: 13px 14px 13px 13px;
  max-width: 288px;
  min-width: 220px;
  cursor: pointer;
  box-shadow: 0 4px 24px rgba(15,23,42,0.13), 0 1px 4px rgba(15,23,42,0.06);
  border: 1px solid rgba(15,23,42,0.06);
  opacity: 0;
  transform: translateY(16px);
  transition: transform 0.3s cubic-bezier(0.22,1,0.36,1), opacity 0.25s ease, box-shadow 0.2s;
}
#chatNotifBubble.visible {
  opacity: 1;
  transform: translateY(0);
  animation: chatNotifUp 0.3s cubic-bezier(0.22,1,0.36,1) forwards;
}
#chatNotifBubble:hover {
  box-shadow: 0 8px 32px rgba(15,23,42,0.16), 0 1px 4px rgba(15,23,42,0.06);
  transform: translateY(-1px);
}
.chat-notif-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--chat-accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
  color: #fff;
  font-weight: 700;
}
.chat-notif-body {
  flex: 1;
  min-width: 0;
}
.chat-notif-name {
  font-size: 0.78rem;
  font-weight: 700;
  color: #0f172a;
  margin-bottom: 3px;
  font-family: var(--chat-font);
}
.chat-notif-text {
  font-size: 0.82rem;
  color: #475569;
  font-weight: 400;
  font-family: var(--chat-font);
  line-height: 1.5;
  word-break: break-word;
}
.chat-notif-hint {
  font-size: 0.7rem;
  color: var(--chat-accent);
  margin-top: 5px;
  font-family: var(--chat-font);
  font-weight: 600;
}
.chat-notif-close {
  background: none;
  border: none;
  color: #94a3b8;
  font-size: 1rem;
  cursor: pointer;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: -2px;
  transition: color 0.15s, background 0.15s;
  line-height: 1;
  padding: 0;
}
.chat-notif-close:hover { color: #1e293b; background: #f1f5f9; }

/* ── Mobile ───────────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  #chatWindow {
    width: calc(100vw - 24px);
    right: 12px;
    bottom: 90px;
    max-height: 80vh;
  }
  #chatMessages {
    max-height: calc(80vh - 180px);
  }
  #chatLauncher {
    right: 16px;
    bottom: 20px;
    width: 52px;
    height: 52px;
  }
  #chatLauncher svg { width: 22px; height: 22px; }
}
