/**
 * Al-Farouq Fasteners & Supplies - AI Chatbot Styles
 * هوية شركة الفاروق: كحلي داكن #122240 وذهبي #fab019 وخط Cairo
 */

:root {
  --chat-primary: #122240;
  --chat-primary-dark: #0a1526;
  --chat-accent: #fab019;
  --chat-accent-hover: #e59d07;
  --chat-bg: #f8fafc;
  --chat-white: #ffffff;
  --chat-text: #1e293b;
  --chat-text-muted: #64748b;
  --chat-border: #e2e8f0;
  --chat-bot-bubble: #ffffff;
  --chat-user-bubble: #122240;
  --chat-shadow: 0 12px 40px rgba(18, 34, 64, 0.22);
}

/* 1. Floating Toggle Trigger Button */
.alfarouq-chat-trigger {
  position: fixed;
  bottom: 30px;
  right: 30px;
  z-index: 9999;
  display: flex;
  align-items: center;
  gap: 10px;
  background: linear-gradient(135deg, var(--chat-primary) 0%, #1e3a6a 100%);
  color: var(--chat-white);
  border: 2px solid var(--chat-accent);
  border-radius: 50px;
  padding: 10px 18px 10px 14px;
  box-shadow: 0 8px 24px rgba(18, 34, 64, 0.35);
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  user-select: none;
  direction: rtl;
  font-family: 'Cairo', sans-serif;
}

html[dir="ltr"] .alfarouq-chat-trigger {
  right: auto;
  left: 30px;
  direction: ltr;
}

.alfarouq-chat-trigger:hover {
  transform: translateY(-3px) scale(1.02);
  box-shadow: 0 12px 30px rgba(250, 176, 25, 0.45);
  border-color: #ffd066;
}

.alfarouq-chat-icon-wrap {
  position: relative;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: var(--chat-primary);
  border: 2px solid var(--chat-accent);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
  overflow: visible;
}

.alfarouq-trigger-avatar-img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  object-position: center 28%;
  display: block;
}

.alfarouq-chat-icon-wrap svg {
  width: 24px;
  height: 24px;
  fill: currentColor;
}

.alfarouq-chat-badge-pulse {
  position: absolute;
  top: -2px;
  right: -2px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #10b981;
  border: 2px solid var(--chat-white);
  animation: pulse-ring 2s infinite;
}

@keyframes pulse-ring {
  0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7); }
  70% { transform: scale(1); box-shadow: 0 0 0 8px rgba(16, 185, 129, 0); }
  100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

.alfarouq-chat-trigger-text {
  display: flex;
  flex-direction: column;
  text-align: right;
  line-height: 1.25;
}

html[dir="ltr"] .alfarouq-chat-trigger-text {
  text-align: left;
}

.alfarouq-chat-trigger-title {
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--chat-white);
}

.alfarouq-chat-trigger-sub {
  font-size: 0.75rem;
  color: var(--chat-accent);
  font-weight: 700;
}

/* 2. Main Chat Window */
.alfarouq-chat-window {
  position: fixed;
  bottom: 95px;
  right: 30px;
  width: 380px;
  max-width: calc(100vw - 32px);
  height: 580px;
  max-height: calc(100vh - 120px);
  background: var(--chat-white);
  border-radius: 20px;
  box-shadow: var(--chat-shadow);
  border: 1px solid rgba(18, 34, 64, 0.12);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 10000;
  opacity: 0;
  visibility: hidden;
  transform: translateY(20px) scale(0.96);
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  direction: rtl;
  font-family: 'Cairo', sans-serif;
}

html[dir="ltr"] .alfarouq-chat-window {
  right: auto;
  left: 30px;
  direction: ltr;
}

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

/* Window Header */
.alfarouq-chat-header {
  background: linear-gradient(135deg, var(--chat-primary) 0%, #1a3461 100%);
  color: var(--chat-white);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 2px solid var(--chat-accent);
}

.alfarouq-chat-brand-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
}

.alfarouq-chat-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--chat-primary);
  border: 2px solid var(--chat-accent);
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
  overflow: hidden;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.alfarouq-avatar-img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  object-position: center 28%;
  display: block;
}

.alfarouq-chat-header-info {
  line-height: 1.3;
}

.alfarouq-chat-header-name {
  font-size: 1rem;
  font-weight: 800;
  color: var(--chat-white);
  display: flex;
  align-items: center;
  gap: 6px;
}

.alfarouq-chat-header-status {
  font-size: 0.78rem;
  color: #a7f3d0;
  display: flex;
  align-items: center;
  gap: 5px;
}

.alfarouq-chat-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #10b981;
}

.alfarouq-chat-close-btn {
  background: rgba(255,255,255,0.12);
  border: none;
  color: var(--chat-white);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  transition: all 0.2s ease;
}

.alfarouq-chat-close-btn:hover {
  background: rgba(255,255,255,0.25);
  transform: rotate(90deg);
}

/* Chat Messages Area */
.alfarouq-chat-body {
  flex: 1;
  background: #f8fafc;
  padding: 16px;
  overflow-y: auto;
  scroll-behavior: smooth;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Message Rows with Bot Avatar */
.alfarouq-chat-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  width: 100%;
  animation: messageFadeIn 0.25s ease-out;
}

.alfarouq-row-bot {
  justify-content: flex-start;
}

.alfarouq-row-user {
  justify-content: flex-end;
}

.alfarouq-msg-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1.5px solid var(--chat-accent);
  background: var(--chat-primary);
  overflow: hidden;
  flex-shrink: 0;
  margin-bottom: 2px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.15);
}

.alfarouq-msg-avatar img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  object-position: center 28%;
  display: block;
}

.alfarouq-chat-bubble {
  max-width: 86%;
  padding: 12px 16px;
  border-radius: 16px;
  font-size: 0.92rem;
  line-height: 1.6;
  position: relative;
  word-wrap: break-word;
}

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

.alfarouq-bubble-bot {
  background: var(--chat-white);
  color: var(--chat-text);
  align-self: flex-start;
  border-bottom-right-radius: 4px;
  border: 1px solid var(--chat-border);
  box-shadow: 0 2px 6px rgba(0,0,0,0.04);
}

html[dir="ltr"] .alfarouq-bubble-bot {
  border-bottom-right-radius: 16px;
  border-bottom-left-radius: 4px;
}

.alfarouq-bubble-bot strong {
  color: var(--chat-primary);
}

.alfarouq-bubble-bot a {
  color: #1d4ed8;
  text-decoration: underline;
  font-weight: 700;
}

.alfarouq-bubble-user {
  background: linear-gradient(135deg, var(--chat-primary) 0%, #1e3a6a 100%);
  color: var(--chat-white);
  align-self: flex-end;
  border-bottom-left-radius: 4px;
  box-shadow: 0 3px 10px rgba(18, 34, 64, 0.2);
}

html[dir="ltr"] .alfarouq-bubble-user {
  border-bottom-left-radius: 16px;
  border-bottom-right-radius: 4px;
}

.alfarouq-chat-time {
  font-size: 0.7rem;
  opacity: 0.7;
  margin-top: 5px;
  text-align: left;
}

html[dir="ltr"] .alfarouq-chat-time {
  text-align: right;
}

/* Quick Suggestion Chips */
.alfarouq-chat-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
}

.alfarouq-chip-btn {
  background: #ffffff;
  border: 1px solid #cbd5e1;
  color: var(--chat-primary);
  font-size: 0.78rem;
  font-weight: 700;
  padding: 6px 12px;
  border-radius: 50px;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: 'Cairo', sans-serif;
  text-align: right;
}

.alfarouq-chip-btn:hover {
  background: var(--chat-accent);
  border-color: var(--chat-accent);
  color: var(--chat-primary);
  transform: translateY(-1px);
}

/* Typing Indicator Animation */
.alfarouq-typing-dots {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 14px;
  background: var(--chat-white);
  border: 1px solid var(--chat-border);
  border-radius: 16px;
  align-self: flex-start;
  width: fit-content;
}

.alfarouq-typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #94a3b8;
  animation: typingBounce 1.4s infinite ease-in-out both;
}

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

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

/* Footer / Input Area */
.alfarouq-chat-footer {
  background: var(--chat-white);
  border-top: 1px solid var(--chat-border);
  padding: 10px 14px;
  flex-shrink: 0;
}

.alfarouq-chat-window .alfarouq-chat-form,
form.alfarouq-chat-form {
  display: flex !important;
  flex-direction: row !important;
  align-items: center !important;
  gap: 8px !important;
  width: 100% !important;
  margin: 0 !important;
  padding: 0 !important;
  box-sizing: border-box !important;
}

.alfarouq-chat-window .alfarouq-chat-input,
.alfarouq-chat-input {
  flex: 1 1 auto !important;
  width: auto !important;
  min-width: 0 !important;
  height: 44px !important;
  min-height: 44px !important;
  max-height: 44px !important;
  border: 1px solid #cbd5e1 !important;
  border-radius: 25px !important;
  padding: 0 16px !important;
  font-size: 0.92rem !important;
  font-family: 'Cairo', sans-serif !important;
  outline: none !important;
  transition: border-color 0.2s !important;
  background: #f8fafc !important;
  box-sizing: border-box !important;
}

.alfarouq-chat-window .alfarouq-chat-input:focus,
.alfarouq-chat-input:focus {
  border-color: var(--chat-primary) !important;
  background: #ffffff !important;
}

/* Explicitly protect send button from global button { width: 100% } */
.alfarouq-chat-window button.alfarouq-chat-send-btn,
button.alfarouq-chat-send-btn,
form.alfarouq-chat-form button[type="submit"] {
  width: 44px !important;
  min-width: 44px !important;
  max-width: 44px !important;
  height: 44px !important;
  min-height: 44px !important;
  max-height: 44px !important;
  border-radius: 50% !important;
  flex: 0 0 44px !important;
  padding: 0 !important;
  margin: 0 !important;
  background: var(--chat-primary) !important;
  color: var(--chat-white) !important;
  border: none !important;
  cursor: pointer !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  transition: all 0.2s ease !important;
  box-sizing: border-box !important;
}

.alfarouq-chat-send-btn:hover {
  background: var(--chat-accent) !important;
  color: var(--chat-primary) !important;
  transform: scale(1.05);
}

.alfarouq-chat-send-btn svg {
  width: 18px !important;
  height: 18px !important;
  fill: currentColor !important;
  margin: 0 !important;
  display: block !important;
}

.alfarouq-chat-disclaimer {
  font-size: 0.68rem;
  color: var(--chat-text-muted);
  text-align: center;
  margin-top: 5px;
}

/* Body lock when chat is active on mobile to eliminate page panning */
body.alfarouq-chat-open {
  overflow: hidden !important;
  height: 100% !important;
  touch-action: none !important;
}

/* Mobile Responsive */
@media (max-width: 600px) {
  .alfarouq-chat-trigger {
    bottom: 18px;
    right: 16px;
    padding: 7px 12px;
    box-shadow: 0 6px 20px rgba(18, 34, 64, 0.4);
  }
  html[dir="ltr"] .alfarouq-chat-trigger {
    right: auto;
    left: 16px;
  }
  .alfarouq-chat-trigger-text {
    display: none;
  }
  .alfarouq-chat-window {
    position: fixed !important;
    top: 0 !important;
    bottom: 0 !important;
    right: 0 !important;
    left: 0 !important;
    width: 100% !important;
    max-width: 100vw !important;
    height: 100% !important;
    height: 100dvh !important;
    max-height: 100dvh !important;
    border-radius: 0 !important;
    margin: 0 !important;
    box-shadow: none !important;
    z-index: 999999 !important;
  }
  html[dir="ltr"] .alfarouq-chat-window {
    left: 0 !important;
    right: 0 !important;
  }
  .alfarouq-chat-header {
    padding: 10px 14px !important;
    min-height: 54px !important;
    border-radius: 0 !important;
    flex-shrink: 0 !important;
  }
  .alfarouq-chat-header-name {
    font-size: 0.92rem !important;
  }
  .alfarouq-chat-header-status {
    font-size: 0.72rem !important;
  }
  .alfarouq-chat-close-btn {
    width: 38px !important;
    height: 38px !important;
    font-size: 1.35rem !important;
  }
  .alfarouq-chat-body {
    padding: 12px 14px !important;
    gap: 10px !important;
    flex: 1 1 auto !important;
    min-height: 0 !important;
  }
  .alfarouq-chat-bubble {
    max-width: 90% !important;
    font-size: 0.88rem !important;
    line-height: 1.55 !important;
    padding: 10px 14px !important;
  }
  .alfarouq-chat-footer {
    padding: 8px 12px max(8px, env(safe-area-inset-bottom)) 12px !important;
    background: #ffffff !important;
    border-top: 1px solid #e2e8f0 !important;
    flex-shrink: 0 !important;
  }
  .alfarouq-chat-input {
    font-size: 16px !important; /* Prevents mobile browser auto-zoom */
    height: 42px !important;
    min-height: 42px !important;
  }
  .alfarouq-chat-send-btn {
    width: 42px !important;
    height: 42px !important;
    min-width: 42px !important;
    max-width: 42px !important;
    flex: 0 0 42px !important;
  }
  .alfarouq-chat-disclaimer {
    font-size: 0.65rem !important;
    margin-top: 3px !important;
    line-height: 1.2 !important;
  }
}
