/**
 * ILF WhatsApp Chatbot — UI/UX MAX PRO & 21st.dev Design System
 * Chambers Legal Qualification Widget
 */

:root {
  --ilf-navy: #0F172A;
  --ilf-navy-dark: #090D16;
  --ilf-gold: #C5A880;
  --ilf-gold-light: #F4EFEA;
  --ilf-emerald: #059669;
  --ilf-wa-green: #25D366;
  --ilf-wa-dark: #128C7E;
  --ilf-wa-bubble: #DCF8C6;
  --ilf-wa-user-text: #054740;
  --ilf-bg-chat: #F8FAFC;
  --ilf-border: #E2E8F0;
  --ilf-text-main: #0F172A;
  --ilf-text-muted: #64748B;
  --ilf-shadow-float: 0 12px 30px -4px rgba(5, 150, 105, 0.35);
  --ilf-shadow-window: 0 25px 60px -15px rgba(15, 23, 42, 0.25), 0 0 1px rgba(15, 23, 42, 0.15);
}

/* Base Widget Container */
#ilf-chat-widget {
  font-family: inherit;
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 999999;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  pointer-events: none;
  font-feature-settings: "cv02", "cv03", "cv04", "cv11";
}

[dir="rtl"] #ilf-chat-widget,
.rtl #ilf-chat-widget {
  right: auto;
  left: 24px;
  direction: ltr; /* Keeps launcher button and teaser card left-aligned with each other */
  align-items: flex-start;
}

/* Floating Launcher Button */
.ilf-chat-launcher {
  pointer-events: auto;
  position: relative;
  width: 62px;
  height: 62px;
  border-radius: 50%;
  background: linear-gradient(135deg, #25D366 0%, #128C7E 100%);
  color: #FFFFFF;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--ilf-shadow-float);
  border: 2.5px solid rgba(255, 255, 255, 0.9);
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  outline: none;
  -webkit-tap-highlight-color: transparent;
}

.ilf-chat-launcher:hover {
  transform: scale(1.08) translateY(-2px);
  box-shadow: 0 16px 36px -4px rgba(5, 150, 105, 0.45);
}

.ilf-chat-launcher:active {
  transform: scale(0.96);
}

.ilf-chat-launcher svg {
  width: 32px;
  height: 32px;
  fill: currentColor;
  transition: transform 0.3s ease;
}

.ilf-chat-launcher.is-open svg.icon-chat {
  display: none;
}
.ilf-chat-launcher:not(.is-open) svg.icon-close {
  display: none;
}
.ilf-chat-launcher.is-open svg.icon-close {
  display: block;
}

/* Pulsing Online Radar Badge */
.ilf-radar-badge {
  position: absolute;
  top: 1px;
  right: 1px;
  width: 14px;
  height: 14px;
  background-color: #10B981;
  border: 2.5px solid #FFFFFF;
  border-radius: 50%;
}

[dir="rtl"] .ilf-radar-badge,
.rtl .ilf-radar-badge {
  right: auto;
  left: 1px;
}

.ilf-radar-badge::after {
  content: '';
  position: absolute;
  top: -2.5px;
  left: -2.5px;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  border: 2px solid #10B981;
  animation: ilf-radar-pulse 2s cubic-bezier(0.24, 0, 0.38, 1) infinite;
  box-sizing: content-box;
}

@keyframes ilf-radar-pulse {
  0% { transform: scale(1); opacity: 0.9; }
  100% { transform: scale(2.6); opacity: 0; }
}

/* Proactive Hint Teaser */
.ilf-proactive-teaser {
  pointer-events: auto;
  margin-bottom: 12px;
  background: #FFFFFF;
  border: 1px solid var(--ilf-border);
  border-radius: 14px;
  padding: 12px 14px;
  max-width: 280px;
  box-shadow: 0 10px 25px -5px rgba(15, 23, 42, 0.12);
  display: flex;
  align-items: flex-start;
  gap: 10px;
  animation: ilf-slide-up 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  position: relative;
  cursor: pointer;
  transition: transform 0.2s ease;
}

.ilf-proactive-teaser:hover {
  transform: translateY(-2px);
}

.ilf-proactive-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #0F172A;
  color: var(--ilf-gold);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border: 1.5px solid var(--ilf-gold);
}

.ilf-proactive-text {
  flex: 1;
  font-size: 12px;
  line-height: 1.45;
  color: var(--ilf-text-main);
  text-align: left;
}

[dir="rtl"] .ilf-proactive-teaser,
.rtl .ilf-proactive-teaser {
  direction: rtl;
  text-align: right;
  padding: 12px 14px 12px 34px;
  max-width: 310px;
}

[dir="rtl"] .ilf-proactive-text,
.rtl .ilf-proactive-text {
  text-align: right;
  direction: rtl;
  font-family: 'Noto Sans Arabic', 'Noto Nastaliq Urdu', Tahoma, sans-serif !important;
  line-height: 1.6;
}

.ilf-proactive-title {
  font-weight: 700;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ilf-emerald);
  margin-bottom: 2px;
}

.ilf-proactive-close {
  background: none;
  border: none;
  color: var(--ilf-text-muted);
  cursor: pointer;
  padding: 2px;
  font-size: 14px;
  line-height: 1;
  position: absolute;
  top: 8px;
  right: 8px;
}

[dir="rtl"] .ilf-proactive-close,
.rtl .ilf-proactive-close {
  right: auto;
  left: 8px;
}

/* Chat Main Window */
.ilf-chat-window {
  pointer-events: auto;
  position: fixed;
  bottom: 100px;
  right: 24px;
  width: 380px;
  max-width: calc(100vw - 32px);
  height: 570px;
  max-height: calc(100vh - 130px);
  background: #FFFFFF;
  border-radius: 20px;
  border: 1px solid rgba(226, 232, 240, 0.9);
  box-shadow: var(--ilf-shadow-window);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transform: translateY(20px) scale(0.95);
  transform-origin: bottom right;
  transition: opacity 0.28s ease, transform 0.28s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.28s;
  z-index: 1000000;
}

[dir="rtl"] .ilf-chat-window,
.rtl .ilf-chat-window {
  right: auto;
  left: 24px;
  transform-origin: bottom left;
}

.ilf-chat-window.is-visible {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

/* Window Header */
.ilf-chat-header {
  background: linear-gradient(135deg, #0F172A 0%, #1E293B 100%);
  color: #FFFFFF;
  padding: 16px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 2px solid rgba(197, 168, 128, 0.4);
  flex-shrink: 0;
}

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

.ilf-header-avatar {
  position: relative;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  border: 1.5px solid var(--ilf-gold);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ilf-gold);
  flex-shrink: 0;
}

.ilf-header-avatar svg {
  width: 22px;
  height: 22px;
}

.ilf-header-avatar .status-dot {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 12px;
  height: 12px;
  background-color: #25D366;
  border: 2px solid #0F172A;
  border-radius: 50%;
}

.ilf-header-info {
  display: flex;
  flex-direction: column;
  text-align: left;
}

[dir="rtl"] .ilf-header-info,
.rtl .ilf-header-info {
  text-align: right;
}

.ilf-header-title {
  font-size: 14.5px;
  font-weight: 700;
  color: #FFFFFF;
  letter-spacing: -0.01em;
  margin: 0;
  line-height: 1.25;
}

.ilf-header-subtitle {
  font-size: 11.5px;
  color: #94A3B8;
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 2px;
}

.ilf-header-subtitle .online-text {
  color: #34D399;
  font-weight: 500;
}

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

.ilf-btn-icon {
  background: rgba(255, 255, 255, 0.08);
  border: none;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  color: #94A3B8;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
}

.ilf-btn-icon:hover {
  background: rgba(255, 255, 255, 0.2);
  color: #FFFFFF;
}

/* Chat Messages Stream Area */
.ilf-chat-body {
  flex: 1;
  background-color: var(--ilf-bg-chat);
  background-image: radial-gradient(#E2E8F0 1px, transparent 1px);
  background-size: 16px 16px;
  padding: 16px 14px;
  overflow-y: auto;
  scroll-behavior: smooth;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Scrollbar polish */
.ilf-chat-body::-webkit-scrollbar {
  width: 5px;
}
.ilf-chat-body::-webkit-scrollbar-track {
  background: transparent;
}
.ilf-chat-body::-webkit-scrollbar-thumb {
  background: #CBD5E1;
  border-radius: 4px;
}

/* Messages */
.ilf-msg-row {
  display: flex;
  flex-direction: column;
  max-width: 86%;
  animation: ilf-slide-up 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.ilf-msg-row.bot {
  align-self: flex-start;
}

[dir="rtl"] .ilf-msg-row.bot,
.rtl .ilf-msg-row.bot {
  align-self: flex-start;
}

.ilf-msg-row.user {
  align-self: flex-end;
}

[dir="rtl"] .ilf-msg-row.user,
.rtl .ilf-msg-row.user {
  align-self: flex-end;
}

.ilf-msg-bubble {
  padding: 11px 14px;
  font-size: 13.5px;
  line-height: 1.5;
  border-radius: 16px;
  position: relative;
  word-break: break-word;
}

.ilf-msg-bubble strong,
.ilf-msg-bubble b {
  font-weight: 700;
}

.ilf-msg-row.bot .ilf-msg-bubble strong,
.ilf-msg-row.bot .ilf-msg-bubble b {
  color: #0F172A;
  font-weight: 700;
}

.ilf-msg-row.user .ilf-msg-bubble strong,
.ilf-msg-row.user .ilf-msg-bubble b {
  color: #032d29;
  font-weight: 700;
}

.ilf-msg-row.bot .ilf-msg-bubble {
  background: #FFFFFF;
  color: var(--ilf-text-main);
  border: 1px solid #E2E8F0;
  border-bottom-left-radius: 4px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04);
}

[dir="rtl"] .ilf-msg-row.bot .ilf-msg-bubble,
.rtl .ilf-msg-row.bot .ilf-msg-bubble {
  border-bottom-left-radius: 16px;
  border-bottom-right-radius: 4px;
}

.ilf-msg-row.user .ilf-msg-bubble {
  background: var(--ilf-wa-bubble);
  color: var(--ilf-wa-user-text);
  border-bottom-right-radius: 4px;
  box-shadow: 0 2px 6px rgba(37, 211, 102, 0.15);
}

[dir="rtl"] .ilf-msg-row.user .ilf-msg-bubble,
.rtl .ilf-msg-row.user .ilf-msg-bubble {
  border-bottom-right-radius: 16px;
  border-bottom-left-radius: 4px;
}

.ilf-msg-meta {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  color: #94A3B8;
  margin-top: 3px;
  padding: 0 4px;
}

.ilf-msg-row.user .ilf-msg-meta {
  justify-content: flex-end;
}

.ilf-checkmarks {
  color: #38BDF8;
  font-weight: 700;
  letter-spacing: -2px;
  font-size: 11px;
}

/* Typing Indicator (Realistic 3 Dots Pulse) */
.ilf-typing-indicator {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: #FFFFFF;
  border: 1px solid #E2E8F0;
  padding: 10px 14px;
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  width: fit-content;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04);
  animation: ilf-slide-up 0.2s ease;
}

[dir="rtl"] .ilf-typing-indicator,
.rtl .ilf-typing-indicator {
  border-bottom-left-radius: 16px;
  border-bottom-right-radius: 4px;
}

.ilf-typing-dot {
  width: 7px;
  height: 7px;
  background-color: #64748B;
  border-radius: 50%;
  animation: ilf-typing-bounce 1.4s infinite ease-in-out both;
}

.ilf-typing-dot:nth-child(1) { animation-delay: -0.32s; }
.ilf-typing-dot:nth-child(2) { animation-delay: -0.16s; }
.ilf-typing-dot:nth-child(3) { animation-delay: 0s; }

@keyframes ilf-typing-bounce {
  0%, 80%, 100% {
    transform: scale(0.6);
    opacity: 0.4;
  }
  40% {
    transform: scale(1.1);
    opacity: 1;
    background-color: #059669;
  }
}

/* 21st.dev Interactive Option Chips */
.ilf-chips-container {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 6px;
  animation: ilf-slide-up 0.3s ease;
}

.ilf-chip-btn {
  background: #FFFFFF;
  border: 1px solid var(--ilf-border);
  color: #1E293B;
  padding: 8px 14px;
  border-radius: 9999px;
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
  text-align: left;
}

[dir="rtl"] .ilf-chip-btn,
.rtl .ilf-chip-btn {
  text-align: right;
}

.ilf-chip-btn:hover {
  background: #F0FDF4;
  border-color: #059669;
  color: #047857;
  transform: translateY(-1.5px);
  box-shadow: 0 4px 12px rgba(5, 150, 105, 0.14);
}

.ilf-chip-btn:active {
  transform: scale(0.97);
}

/* Final Summary Card & Big WhatsApp CTA */
.ilf-final-card {
  background: #FFFFFF;
  border: 1px solid #E2E8F0;
  border-radius: 16px;
  padding: 16px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.06);
  display: flex;
  flex-direction: column;
  gap: 12px;
  animation: ilf-slide-up 0.3s ease;
}

.ilf-summary-box {
  background: #F8FAFC;
  border: 1px dashed #CBD5E1;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 12px;
  color: #334155;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.ilf-summary-item {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.ilf-summary-label {
  color: #64748B;
  font-weight: 500;
}

.ilf-summary-val {
  font-weight: 600;
  color: #0F172A;
  text-align: right;
  word-break: break-all;
}

[dir="rtl"] .ilf-summary-val,
.rtl .ilf-summary-val {
  text-align: left;
}

.ilf-wa-submit-btn {
  background: linear-gradient(135deg, #25D366 0%, #128C7E 100%);
  color: #FFFFFF !important;
  border: none;
  border-radius: 12px;
  padding: 13px 18px;
  font-size: 13.5px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  text-decoration: none !important;
  cursor: pointer;
  box-shadow: 0 8px 20px rgba(37, 211, 102, 0.32);
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  letter-spacing: 0.01em;
}

.ilf-wa-submit-btn:hover {
  background: linear-gradient(135deg, #22C55E 0%, #0F766E 100%);
  transform: translateY(-2px);
  box-shadow: 0 12px 28px rgba(37, 211, 102, 0.42);
  color: #FFFFFF !important;
}

.ilf-wa-submit-btn svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

/* Chat Input Footer */
.ilf-chat-footer {
  background: #FFFFFF;
  border-top: 1px solid var(--ilf-border);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
}

.ilf-input-form {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #F8FAFC;
  border: 1px solid var(--ilf-border);
  border-radius: 9999px;
  padding: 4px 6px 4px 14px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

[dir="rtl"] .ilf-input-form,
.rtl .ilf-input-form {
  padding: 4px 14px 4px 6px;
}

.ilf-input-form:focus-within {
  border-color: var(--ilf-emerald);
  background: #FFFFFF;
  box-shadow: 0 0 0 3px rgba(5, 150, 105, 0.12);
}

.ilf-input-field {
  flex: 1;
  background: transparent !important;
  border: none !important;
  outline: none !important;
  box-shadow: none !important;
  font-size: 13.5px;
  color: var(--ilf-text-main);
  padding: 8px 0;
  font-family: inherit;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
}

.ilf-input-field:focus,
.ilf-input-field:focus-visible,
.ilf-input-field:active {
  outline: none !important;
  outline-offset: 0 !important;
  box-shadow: none !important;
  border: none !important;
}

.ilf-input-field::placeholder {
  color: #94A3B8;
}

.ilf-send-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #0F172A;
  color: #FFFFFF;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
  flex-shrink: 0;
}

.ilf-send-btn:hover {
  background: var(--ilf-emerald);
  transform: scale(1.05);
}

.ilf-send-btn svg {
  width: 16px;
  height: 16px;
}

[dir="rtl"] .ilf-send-btn svg,
.rtl .ilf-send-btn svg {
  transform: scaleX(-1);
}

.ilf-security-footnote {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  font-size: 10.5px;
  color: #94A3B8;
  text-align: center;
}

.ilf-security-footnote svg {
  width: 12px;
  height: 12px;
  color: #10B981;
}

/* Animations */
@keyframes ilf-slide-up {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Mobile Responsiveness — Bottom-Sheet UX (Ref: arubadistributorsuae.com) */
@media (max-width: 640px) {
  #ilf-chat-widget {
    bottom: 16px;
    right: 16px;
  }
  [dir="rtl"] #ilf-chat-widget,
  .rtl #ilf-chat-widget {
    left: 16px;
    right: auto;
  }
  .ilf-chat-window {
    right: 0 !important;
    left: 0 !important;
    bottom: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    height: 65vh !important;
    max-height: 85vh !important;
    border-radius: 20px 20px 0 0 !important;
    border-left: none !important;
    border-right: none !important;
    border-bottom: none !important;
    box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.25) !important;
    transform: translateY(100%) !important;
    transform-origin: bottom center !important;
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.25s ease, visibility 0.25s !important;
  }
  .ilf-chat-window.is-visible {
    transform: translateY(0) !important;
  }
  [dir="rtl"] .ilf-chat-window,
  .rtl .ilf-chat-window {
    right: 0 !important;
    left: 0 !important;
    bottom: 0 !important;
    border-radius: 20px 20px 0 0 !important;
    transform-origin: bottom center !important;
  }
  .ilf-chat-header {
    padding: 12px 14px !important;
  }
  .ilf-header-avatar {
    width: 38px !important;
    height: 38px !important;
  }
  .ilf-header-title {
    font-size: 13.5px !important;
  }
  .ilf-header-subtitle {
    font-size: 10.5px !important;
  }
  .ilf-chat-body {
    padding: 12px 12px !important;
    gap: 10px !important;
  }
  .ilf-chat-footer {
    padding: 8px 12px calc(8px + env(safe-area-inset-bottom, 0px)) 12px !important;
    gap: 4px !important;
  }
  .ilf-input-field {
    font-size: 16px !important; /* Prevents iOS Safari auto-zoom on input focus */
    padding: 6px 0 !important;
  }
  .ilf-security-footnote {
    font-size: 9.5px !important;
  }
}
