/**
 * LiveChat WP - Responsive Mobile-First Widget Styles
 * Compatible with all modern mobile devices (iOS Safari, Android Chrome)
 */

:root {
  --wplc-primary: #059669;
  --wplc-primary-hover: #047857;
  --wplc-header-text: #ffffff;
  --wplc-bg: #ffffff;
  --wplc-text: #0f172a;
  --wplc-bubble-visitor: #059669;
  --wplc-bubble-agent: #f1f5f9;
  --wplc-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
  --wplc-radius: 16px;
  --wplc-font: 'Cairo', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

#wplc-chat-root {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 999999;
  font-family: var(--wplc-font);
  direction: rtl;
}

/* Floating Launcher Trigger */
.wplc-launcher {
  display: flex;
  align-items: center;
  gap: 10px;
  background-color: var(--wplc-primary);
  color: #ffffff;
  border: none;
  border-radius: 9999px;
  padding: 14px 20px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.15), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
  transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.2s ease;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.wplc-launcher:hover {
  transform: translateY(-2px);
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.2);
}

.wplc-launcher-icon {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.wplc-unread-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background-color: #ef4444;
  color: #ffffff;
  font-size: 11px;
  font-weight: 700;
  width: 20px;
  height: 20px;
  border-radius: 9999px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #ffffff;
}

/* Chat Window Container */
.wplc-window {
  display: none;
  flex-direction: column;
  width: 380px;
  height: 580px;
  max-height: calc(100vh - 100px);
  background: var(--wplc-bg);
  border-radius: var(--wplc-radius);
  box-shadow: var(--wplc-shadow);
  border: 1px solid rgba(0, 0, 0, 0.08);
  overflow: hidden;
  transition: opacity 0.2s ease, transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  transform-origin: bottom right;
}

.wplc-window.wplc-open {
  display: flex;
  animation: wplcFadeIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

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

/* Header Area */
.wplc-header {
  background: var(--wplc-primary);
  color: var(--wplc-header-text);
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.wplc-header-profile {
  display: flex;
  align-items: center;
  gap: 12px;
}

.wplc-avatar-wrap {
  position: relative;
  width: 44px;
  height: 44px;
}

.wplc-avatar-img {
  width: 44px;
  height: 44px;
  border-radius: 9999px;
  object-fit: cover;
  border: 2px solid rgba(255, 255, 255, 0.8);
}

.wplc-status-dot {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 12px;
  height: 12px;
  background-color: #22c55e;
  border-radius: 9999px;
  border: 2px solid #ffffff;
}

.wplc-header-title {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  color: #ffffff;
}

.wplc-header-subtitle {
  font-size: 12px;
  opacity: 0.9;
  color: #ffffff;
}

.wplc-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.wplc-btn-icon {
  background: transparent;
  border: none;
  color: #ffffff;
  opacity: 0.85;
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.15s ease, background-color 0.15s ease;
}

.wplc-btn-icon:hover {
  opacity: 1;
  background: rgba(255, 255, 255, 0.15);
}

/* Messages Body */
.wplc-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background-color: #f8fafc;
  -webkit-overflow-scrolling: touch;
}

.wplc-welcome-banner {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 14px;
  text-align: center;
  margin-bottom: 8px;
}

.wplc-welcome-banner p {
  margin: 0;
  font-size: 13px;
  color: #475569;
  line-height: 1.5;
}

.wplc-msg {
  display: flex;
  flex-direction: column;
  max-width: 82%;
  word-break: break-word;
}

.wplc-msg-visitor {
  align-self: flex-start;
}

.wplc-msg-agent {
  align-self: flex-end;
}

.wplc-bubble {
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.5;
}

.wplc-msg-visitor .wplc-bubble {
  background-color: var(--wplc-primary);
  color: #ffffff;
  border-bottom-right-radius: 3px;
}

.wplc-msg-agent .wplc-bubble {
  background-color: #ffffff;
  color: #1e293b;
  border: 1px solid #e2e8f0;
  border-bottom-left-radius: 3px;
}

.wplc-msg-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: #94a3b8;
  margin-top: 3px;
  padding: 0 4px;
}

/* Quick Question Starters */
.wplc-quick-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
}

.wplc-chip {
  background: #ffffff;
  border: 1px solid #cbd5e1;
  color: #334155;
  padding: 6px 10px;
  font-size: 12px;
  border-radius: 9999px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.wplc-chip:hover {
  border-color: var(--wplc-primary);
  color: var(--wplc-primary);
  background: #f0fdf4;
}

/* Input Area */
.wplc-footer {
  padding: 12px 14px;
  background: #ffffff;
  border-top: 1px solid #e2e8f0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.wplc-input {
  flex: 1;
  border: 1px solid #cbd5e1;
  border-radius: 20px;
  padding: 10px 14px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  background: #f8fafc;
  transition: border-color 0.2s, background-color 0.2s;
}

.wplc-input:focus {
  border-color: var(--wplc-primary);
  background: #ffffff;
}

.wplc-send-btn {
  background: var(--wplc-primary);
  color: #ffffff;
  border: none;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 0.15s ease, background-color 0.15s ease;
}

.wplc-send-btn:hover {
  background-color: var(--wplc-primary-hover);
  transform: scale(1.05);
}

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

/* Multi-channel fallback (WhatsApp / Phone) */
.wplc-channels-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 8px 12px;
  background: #f1f5f9;
  border-top: 1px solid #e2e8f0;
  font-size: 12px;
}

.wplc-channel-link {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: #475569;
  text-decoration: none;
  font-weight: 500;
  transition: color 0.15s;
}

.wplc-channel-link:hover {
  color: var(--wplc-primary);
}

/* ==========================================================================
   MOBILE RESPONSIVENESS OPTIMIZATIONS (iOS & Android)
   ========================================================================== */
@media (max-width: 640px) {
  #wplc-chat-root {
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100%;
  }

  /* Fixed bottom-safe launcher on mobile */
  .wplc-launcher {
    position: fixed;
    right: 16px;
    bottom: max(16px, env(safe-area-inset-bottom, 16px));
    padding: 12px 18px;
    font-size: 14px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  }

  /* Mobile Fullscreen / Drawer Style */
  .wplc-window {
    width: 100% !important;
    height: 100vh !important;
    height: 100dvh !important; /* Dynamic viewport units for mobile address bar */
    max-height: 100dvh !important;
    border-radius: 0 !important;
    border: none !important;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000000;
  }

  .wplc-header {
    padding-top: max(16px, env(safe-area-inset-top, 16px));
    padding-bottom: 14px;
  }

  .wplc-footer {
    padding-bottom: max(12px, env(safe-area-inset-bottom, 12px));
  }

  .wplc-input {
    font-size: 16px; /* Prevents auto-zoom on iOS Safari when tapping input */
  }
}
