/* ===================== Tidio-style Live Chat ===================== */

.chat-widget {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 9999;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* ---- Launcher ---- */
.chat-launcher {
  position: relative;
  width: 60px;
  height: 60px;
  border: 0;
  border-radius: 50%;
  background: #1a1a2e;
  color: #fff;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(26, 26, 46, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.25s cubic-bezier(0.34,1.56,0.64,1), box-shadow 0.25s ease, background 0.25s ease;
}
.chat-launcher::after {
  content: '';
  position: absolute;
  top: 2px;
  right: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #2ecc71;
  border: 2.5px solid #1a1a2e;
  animation: chatBlink 1.6s ease-in-out infinite;
  z-index: 1;
}
.chat-launcher:hover { transform: scale(1.08); box-shadow: 0 6px 28px rgba(26, 26, 46, 0.45); }
.chat-launcher:active { transform: scale(0.95); }
.chat-launcher .launcher-ic { font-size: 26px; transition: transform 0.3s ease; }
.chat-launcher .launcher-close { display: none; font-size: 24px; }
.chat-launcher.active .launcher-ic { display: none; }
.chat-launcher.active .launcher-close { display: block; }

.launcher-pulse {
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 3px solid rgba(26, 26, 46, 0.25);
  animation: tidioPulse 2.5s ease-out infinite;
  pointer-events: none;
}
.chat-launcher.active .launcher-pulse { display: none; }
@keyframes tidioPulse {
  0% { transform: scale(0.8); opacity: 0.8; }
  100% { transform: scale(1.35); opacity: 0; }
}

.chat-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 12px;
  background: #ff6b6b;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  line-height: 22px;
  text-align: center;
  box-shadow: 0 2px 8px rgba(255, 107, 107, 0.5);
}

/* ---- Panel ---- */
.chat-panel {
  position: absolute;
  right: 0;
  bottom: 74px;
  width: 380px;
  max-width: calc(100vw - 32px);
  height: min(620px, calc(100vh - 130px));
  background: #fff;
  border-radius: 16px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.18), 0 0 0 1px rgba(0,0,0,0.04);
  opacity: 0;
  transform: translateY(20px) scale(0.96);
  pointer-events: none;
  transition: opacity 0.25s cubic-bezier(0.34,1.56,0.64,1), transform 0.25s cubic-bezier(0.34,1.56,0.64,1);
}
.chat-panel.show {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}

/* ---- Header ---- */
.chat-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 20px;
  background: #1a1a2e;
  color: #fff;
  flex-shrink: 0;
}
.chat-av {
  width: 44px;
  height: 44px;
  flex: none;
  border-radius: 50%;
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  position: relative;
}
.chat-av::after {
  content: '';
  position: absolute;
  bottom: 1px;
  right: 1px;
  width: 12px;
  height: 12px;
  background: #2ecc71;
  border-radius: 50%;
  border: 2px solid #1a1a2e;
}
.chat-head-txt { flex: 1; min-width: 0; }
.chat-head-txt b { display: block; font-size: 15px; font-weight: 600; letter-spacing: 0.2px; }
.chat-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.6);
  margin-top: 2px;
}
.chat-online-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #2ecc71;
  display: inline-block;
  flex-shrink: 0;
  animation: chatBlink 1.6s ease-in-out infinite;
}
@keyframes chatBlink { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }
.chat-min {
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  cursor: pointer;
  font-size: 14px;
  transition: background 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}
.chat-min:hover { background: rgba(255, 255, 255, 0.2); }

/* ---- Body / messages ---- */
.chat-body {
  flex: 1;
  overflow-y: auto;
  background: #f8f9fb;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scrollbar-width: thin;
  scrollbar-color: #d1d5db transparent;
}
.chat-body::-webkit-scrollbar { width: 6px; }
.chat-body::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 4px; }
.chat-body::-webkit-scrollbar-track { background: transparent; }

.chat-msg {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 100%;
  animation: msgSlideIn 0.25s ease-out;
}
@keyframes msgSlideIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

.chat-msg .msg-av {
  width: 30px;
  height: 30px;
  flex: none;
  border-radius: 50%;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.chat-msg.bot .msg-av, .chat-msg.admin .msg-av {
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: #fff;
}
.chat-msg.me .msg-av {
  background: #e8f5e9;
  color: #1a1a2e;
}
.chat-msg.me { flex-direction: row-reverse; }
.chat-msg.me .msg-wrap { align-items: flex-end; }

.msg-wrap {
  display: flex;
  flex-direction: column;
  max-width: 80%;
}

.msg-meta {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 0 4px;
  margin-bottom: 4px;
}
.msg-meta span { font-size: 12px; font-weight: 600; color: #374151; }
.msg-meta time { font-size: 11px; color: #9ca3af; }
.msg-seen { display: inline-flex; align-items: center; gap: 3px; font-size: 11px; font-weight: 600; color: #667eea; }
.msg-seen i { font-size: 10px; }
.chat-msg.me .msg-meta { flex-direction: row-reverse; }

.msg-bubble {
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.5;
  word-break: break-word;
  white-space: normal;
}
.chat-msg.bot .msg-bubble {
  background: #fff;
  color: #1f2937;
  border: 1px solid #e5e7eb;
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.chat-msg.admin .msg-bubble {
  background: #1a1a2e;
  color: #fff;
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.chat-msg.me .msg-bubble {
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: #fff;
  border-bottom-right-radius: 4px;
  box-shadow: 0 2px 8px rgba(102, 126, 234, 0.25);
}

.msg-li { display: block; padding: 1px 0; }
.msg-li-dot { color: #667eea; font-weight: 900; margin-right: 6px; }
.chat-msg.me .msg-li-dot { color: #c7d2fe; }

.chat-sys {
  align-self: center;
  max-width: 90%;
  text-align: center;
  font-size: 12px;
  color: #6b7280;
  background: #e5e7eb;
  border-radius: 20px;
  padding: 6px 14px;
}

/* ---- Typing indicator ---- */
.typing-b {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 12px 16px;
}
.tdot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #9ca3af;
  animation: tidioTyping 1.2s infinite ease-in-out;
}
.tdot:nth-child(2) { animation-delay: 0.15s; }
.tdot:nth-child(3) { animation-delay: 0.3s; }
@keyframes tidioTyping {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-5px); opacity: 1; }
}

/* ---- Pre-chat identity form ---- */
.chat-identity {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px;
  background: #fff;
  border-top: 1px solid #f3f4f6;
}
.chat-identity input {
  width: 100%;
  border: 1.5px solid #e5e7eb;
  border-radius: 10px;
  padding: 11px 14px;
  font-size: 14px;
  font-family: inherit;
  background: #f9fafb;
  color: #1f2937;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.chat-identity input:focus {
  outline: none;
  border-color: #667eea;
  background: #fff;
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.12);
}
.chat-identity input::placeholder { color: #9ca3af; }
.chat-identity .chat-id-btn {
  width: 100%;
  padding: 11px;
  border: 0;
  border-radius: 10px;
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: opacity 0.15s ease, transform 0.15s ease;
}
.chat-identity .chat-id-btn:hover { opacity: 0.9; transform: translateY(-1px); }
.chat-identity .chat-id-btn:active { transform: scale(0.98); }

/* ---- Composer ---- */
.chat-compose {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  background: #fff;
  border-top: 1px solid #f3f4f6;
}
.chat-compose input {
  flex: 1;
  min-width: 0;
  border: 1.5px solid #e5e7eb;
  border-radius: 24px;
  padding: 10px 16px;
  font-size: 14px;
  font-family: inherit;
  background: #f9fafb;
  color: #1f2937;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.chat-compose input:focus {
  outline: none;
  border-color: #667eea;
  background: #fff;
}
.chat-compose input::placeholder { color: #9ca3af; }
.chat-compose button {
  width: 38px;
  height: 38px;
  flex: none;
  border: 0;
  border-radius: 50%;
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: #fff;
  cursor: pointer;
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
}
.chat-compose button:hover { transform: scale(1.05); box-shadow: 0 3px 12px rgba(102, 126, 234, 0.35); }
.chat-compose button:disabled { opacity: 0.4; cursor: default; transform: none; box-shadow: none; }

/* ---- Mobile ---- */
@media (max-width: 640px) {
  .chat-widget { right: 12px; bottom: 12px; }
  .chat-launcher { width: 52px; height: 52px; }
  .chat-launcher::after { width: 12px; height: 12px; top: 0; right: 0; border-width: 2px; }
  .chat-launcher .launcher-ic { font-size: 22px; }
  .chat-panel {
    position: fixed;
    right: 0;
    bottom: 0;
    left: auto;
    width: 50vw;
    height: 90vh;
    max-width: none;
    border-radius: 16px 16px 0 0;
  }
}
