/* ========================================================
   Modern Live Chat Widget - Pro Minimal Dark Style
   ======================================================== */

#livechat-wrapper {
  font-family: inherit;
  font-size: 0.9rem;
  color: #f1f5f9;
  z-index: 99999;
  position: relative;
}

/* Floating Launcher Container */
.livechat-launcher-container {
  position: fixed;
  bottom: 24px;
  left: 24px;
  z-index: 99999;
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Tooltip Pill */
.livechat-tooltip {
  background: rgba(15, 23, 42, 0.95);
  color: #f8fafc;
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 0.82rem;
  font-weight: 600;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
  border: 1px solid rgba(255, 255, 255, 0.1);
  white-space: nowrap;
  pointer-events: none;
  opacity: 1;
  transition: opacity 0.3s ease, transform 0.3s ease;
  transform: translateX(0);
}

.livechat-tooltip.hide {
  opacity: 0;
  transform: translateX(8px);
  pointer-events: none;
}

/* Launcher Button */
.livechat-launcher {
  position: relative;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, #0284c7, #0ea5e9);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 10px 25px -3px rgba(14, 165, 233, 0.5), 0 4px 6px -4px rgba(14, 165, 233, 0.3);
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  outline: none;
}

.livechat-launcher:hover {
  transform: scale(1.06) translateY(-2px);
  box-shadow: 0 14px 30px -3px rgba(14, 165, 233, 0.65);
}

.livechat-launcher:active {
  transform: scale(0.95);
}

/* Icon Switching */
.livechat-icon {
  font-size: 1.5rem;
  transition: transform 0.3s ease, opacity 0.3s ease;
  position: absolute;
}

.livechat-icon-close {
  opacity: 0;
  transform: rotate(-90deg) scale(0.5);
}

#livechat-wrapper.is-open .livechat-icon-open,
.livechat-wrapper.is-open .livechat-icon-open {
  opacity: 0;
  transform: rotate(90deg) scale(0.5);
}

#livechat-wrapper.is-open .livechat-icon-close,
.livechat-wrapper.is-open .livechat-icon-close {
  opacity: 1;
  transform: rotate(0) scale(1);
}

/* Unread Badge */
.livechat-badge {
  position: absolute;
  top: -3px;
  right: -3px;
  background: #ef4444;
  color: #ffffff;
  font-size: 0.72rem;
  font-weight: 700;
  min-width: 22px;
  height: 22px;
  line-height: 22px;
  border-radius: 50%;
  text-align: center;
  border: 2px solid #0f172a;
  box-shadow: 0 0 10px rgba(239, 68, 68, 0.7);
  animation: livechatPulse 2s infinite;
}

@keyframes livechatPulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.12); }
  100% { transform: scale(1); }
}

/* ========================================================
   Chat Window Box
   ======================================================== */
.livechat-box {
  position: fixed;
  bottom: 96px;
  left: 24px;
  width: 375px;
  max-width: calc(100vw - 32px);
  height: 540px;
  max-height: calc(100vh - 120px);
  background: #0f172a;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 20px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.7), 0 0 0 1px rgba(255, 255, 255, 0.05);
  overflow: hidden;
  z-index: 100000;
  opacity: 0;
  visibility: hidden;
  transform: scale(0.92) translateY(24px);
  transform-origin: bottom left;
  transition: opacity 0.3s cubic-bezier(0.16, 1, 0.3, 1),
              transform 0.3s cubic-bezier(0.16, 1, 0.3, 1),
              visibility 0.3s;
}

.livechat-box.active {
  opacity: 1;
  visibility: visible;
  transform: scale(1) translateY(0);
}

/* Header */
.livechat-header {
  background: linear-gradient(135deg, #1e293b, #0f172a);
  padding: 14px 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.livechat-avatar {
  position: relative;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: linear-gradient(135deg, #0369a1, #0ea5e9);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
}

.livechat-online-dot {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 10px;
  height: 10px;
  background: #10b981;
  border: 2px solid #0f172a;
  border-radius: 50%;
}

.livechat-header-info {
  display: flex;
  flex-direction: column;
}

.livechat-subtext {
  font-size: 0.74rem;
  color: #94a3b8;
  display: flex;
  align-items: center;
  gap: 4px;
}

.livechat-pulse-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #10b981;
  display: inline-block;
  box-shadow: 0 0 6px #10b981;
}

.livechat-header-btn {
  color: #94a3b8 !important;
  background: transparent !important;
  border: none !important;
  padding: 4px 8px;
  border-radius: 8px;
  transition: all 0.2s;
}

.livechat-header-btn:hover {
  color: #ffffff !important;
  background: rgba(255, 255, 255, 0.08) !important;
}

/* Screens */
.livechat-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #0b1120;
}

/* ========================================================
   Screen 1: Form View
   ======================================================== */
.livechat-form-intro {
  padding: 20px 20px 10px;
  text-align: center;
}

.livechat-welcome-icon {
  width: 48px;
  height: 48px;
  margin: 0 auto 10px;
  border-radius: 50%;
  background: rgba(14, 165, 233, 0.12);
  color: #38bdf8;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
}

.livechat-form {
  padding: 10px 20px 20px;
  overflow-y: auto;
  flex: 1;
}

.livechat-input {
  background: #1e293b !important;
  border: 1px solid rgba(255, 255, 255, 0.12) !important;
  color: #f8fafc !important;
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 0.85rem;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.livechat-input:focus {
  border-color: #0ea5e9 !important;
  box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.25) !important;
}

.livechat-input::placeholder {
  color: #64748b;
  font-size: 0.82rem;
}

/* ========================================================
   Screen 2: Chat Messages Area
   ======================================================== */
.livechat-messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Custom Slim Scrollbar */
.livechat-messages-container::-webkit-scrollbar,
.livechat-form::-webkit-scrollbar {
  width: 5px;
}
.livechat-messages-container::-webkit-scrollbar-thumb,
.livechat-form::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.12);
  border-radius: 10px;
}
.livechat-messages-container::-webkit-scrollbar-track,
.livechat-form::-webkit-scrollbar-track {
  background: transparent;
}

.livechat-system-badge {
  text-align: center;
  font-size: 0.72rem;
  color: #94a3b8;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.06);
  padding: 4px 10px;
  border-radius: 20px;
  align-self: center;
  margin-bottom: 6px;
}

.livechat-messages-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Message Bubble Rows */
.livechat-msg-row {
  display: flex;
  flex-direction: column;
  max-width: 82%;
  animation: livechatSlideIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

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

/* User Message (Left aligned in RTL or Me) */
.livechat-msg-row.msg-user {
  align-self: flex-start;
  align-items: flex-start;
}

.livechat-msg-row.msg-user .livechat-msg-bubble {
  background: linear-gradient(135deg, #0284c7, #0369a1);
  color: #ffffff;
  border-radius: 16px 16px 4px 16px;
  box-shadow: 0 4px 12px rgba(2, 132, 199, 0.25);
}

/* Admin Message (Right aligned in RTL) */
.livechat-msg-row.msg-admin {
  align-self: flex-end;
  align-items: flex-end;
}

.livechat-msg-row.msg-admin .livechat-msg-bubble {
  background: #1e293b;
  color: #f1f5f9;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 16px 16px 16px 4px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.livechat-msg-bubble {
  padding: 9px 13px;
  font-size: 0.86rem;
  line-height: 1.5;
  word-break: break-word;
  white-space: pre-wrap;
  position: relative;
}

/* Meta: time + checkmarks */
.livechat-msg-meta {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.68rem;
  color: #94a3b8;
  margin-top: 3px;
  padding: 0 4px;
}

.livechat-msg-row.msg-user .livechat-msg-meta {
  color: #93c5fd;
}

.livechat-status-icon {
  font-size: 0.85rem;
  line-height: 1;
}

.livechat-status-read {
  color: #38bdf8 !important;
}

/* Admin Sender Label */
.livechat-msg-sender {
  font-size: 0.7rem;
  font-weight: 600;
  color: #38bdf8;
  margin-bottom: 2px;
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Typing row */
.livechat-typing-row {
  align-self: flex-end;
  margin-top: 4px;
}

.livechat-typing-bubble {
  background: #1e293b;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  padding: 8px 12px;
  display: flex;
  gap: 4px;
  align-items: center;
}

.livechat-typing-bubble span {
  width: 6px;
  height: 6px;
  background: #94a3b8;
  border-radius: 50%;
  animation: typingBounce 1.4s infinite ease-in-out both;
}
.livechat-typing-bubble span:nth-child(1) { animation-delay: -0.32s; }
.livechat-typing-bubble span:nth-child(2) { animation-delay: -0.16s; }

@keyframes typingBounce {
  0%, 80%, 100% { transform: scale(0); }
  40% { transform: scale(1); }
}

/* ========================================================
   Chat Footer Input Area
   ======================================================== */
.livechat-footer {
  background: #0f172a;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  padding: 10px 12px 8px;
  flex-shrink: 0;
  position: relative;
  z-index: 10;
}

.livechat-chat-textarea {
  background: #1e293b !important;
  border: 1px solid rgba(255, 255, 255, 0.12) !important;
  color: #ffffff !important;
  border-radius: 12px;
  padding: 8px 12px;
  font-size: 0.86rem;
  resize: none;
  max-height: 100px;
  min-height: 38px;
  line-height: 1.4;
  transition: border-color 0.2s;
}

.livechat-chat-textarea:focus {
  border-color: #0ea5e9 !important;
  box-shadow: 0 0 0 2px rgba(14, 165, 233, 0.25) !important;
}

.livechat-btn-send {
  width: 42px;
  height: 42px;
  min-width: 42px;
  min-height: 42px;
  border-radius: 12px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  cursor: pointer;
  position: relative;
  z-index: 15;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.15s ease, background-color 0.15s ease;
}

.livechat-btn-send:hover {
  transform: scale(1.05);
}

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

.livechat-btn-send i {
  transform: scaleX(-1);
  font-size: 1.05rem;
  pointer-events: none;
}

.livechat-footer-note {
  font-size: 0.68rem;
  color: #64748b;
  text-align: center;
  margin-top: 4px;
}

/* ========================================================
   Mobile Responsive Adjustments
   ======================================================== */
@media (max-width: 768px), (max-height: 650px) {
  /* Hide launcher button completely when chat is open so it never overlaps send button */
  #livechat-wrapper.is-open .livechat-launcher-container,
  .livechat-wrapper.is-open .livechat-launcher-container {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    pointer-events: none !important;
  }

  .livechat-launcher-container {
    bottom: 20px;
    left: 16px;
    z-index: 99999;
  }

  /* User panel has a bottom navbar on mobile */
  .mobile-bottom-nav ~ #livechat-wrapper .livechat-launcher-container,
  body.has-bottom-nav .livechat-launcher-container,
  .user-mobile-bottom-nav ~ #livechat-wrapper .livechat-launcher-container {
    bottom: 75px;
  }

  .livechat-tooltip {
    display: none !important;
  }

  .livechat-box {
    position: fixed !important;
    top: 0 !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    height: 100% !important;
    height: 100dvh !important;
    max-height: 100% !important;
    max-height: 100dvh !important;
    border-radius: 0 !important;
    border: none !important;
    z-index: 100000 !important;
  }

  .livechat-footer {
    padding: 10px 12px max(12px, env(safe-area-inset-bottom)) !important;
  }

  .livechat-chat-textarea,
  .livechat-input {
    font-size: 16px !important;
  }

  .livechat-btn-send {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
  }
}
