/* ═══════════════════════════════════════════════════════════════════
   AI CHAT ASSISTANT — Styles
   Floating chat widget with modern design
═══════════════════════════════════════════════════════════════════ */

/* ── Toggle Button ── */
.ai-chat-toggle {
  position: fixed;
  bottom: 92px;
  left: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, #1E7A44, #22A05A);
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(30, 122, 68, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9001;
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  animation: chatPulse 3s ease-in-out infinite;
}
.ai-chat-toggle:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 28px rgba(30, 122, 68, 0.5);
}
.ai-chat-toggle.active {
  animation: none;
  background: linear-gradient(135deg, var(--n700), var(--n600));
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
}
.ai-chat-icon {
  font-size: 24px;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.2));
}
.ai-chat-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  width: 18px;
  height: 18px;
  background: var(--red500);
  color: white;
  border-radius: 50%;
  font-size: 10px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid white;
}
@keyframes chatPulse {
  0%, 100% { box-shadow: 0 4px 20px rgba(30, 122, 68, 0.4); }
  50% { box-shadow: 0 4px 20px rgba(30, 122, 68, 0.4), 0 0 0 8px rgba(34, 160, 90, 0.1); }
}

/* ── Chat Panel ── */
.ai-chat-panel {
  position: fixed;
  bottom: 158px;
  left: 24px;
  width: 380px;
  height: 520px;
  background: var(--white);
  border-radius: 20px;
  box-shadow: 0 16px 64px rgba(15, 25, 35, 0.2), 0 0 0 1px var(--n150);
  z-index: 9002;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: translateY(20px) scale(0.95);
  pointer-events: none;
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.ai-chat-panel.open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: all;
}

/* ── Header ── */
.ai-chat-header {
  padding: 14px 16px;
  background: linear-gradient(135deg, #0E4D2F, #1E7A44);
  color: white;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
.ai-chat-header-info {
  display: flex;
  align-items: center;
  gap: 10px;
}
.ai-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255,255,255,0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}
.ai-name {
  font-family: 'Tajawal', sans-serif;
  font-size: 14px;
  font-weight: 700;
}
.ai-status {
  font-size: 10px;
  color: #86EFAC;
  font-weight: 600;
}
.ai-chat-header-actions {
  display: flex;
  gap: 6px;
}
.ai-header-btn {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: none;
  background: rgba(255,255,255,0.12);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  transition: background 0.2s;
}
.ai-header-btn:hover {
  background: rgba(255,255,255,0.25);
}

/* ── Messages Area ── */
.ai-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--n50);
  scroll-behavior: smooth;
}

/* ── Message Bubbles ── */
.ai-msg {
  display: flex;
  flex-direction: column;
  max-width: 85%;
  animation: msgIn 0.25s ease;
}
@keyframes msgIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.ai-msg-user {
  align-self: flex-start;
}
.ai-msg-bot {
  align-self: flex-end;
}
.ai-msg-bubble {
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 13px;
  line-height: 1.7;
  word-wrap: break-word;
}
.ai-msg-user .ai-msg-bubble {
  background: linear-gradient(135deg, #1E7A44, #22A05A);
  color: white;
  border-bottom-right-radius: 4px;
}
.ai-msg-bot .ai-msg-bubble {
  background: var(--white);
  color: var(--n800);
  border: 1px solid var(--n200);
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.04);
}
.ai-msg-time {
  font-size: 10px;
  color: var(--n400);
  margin-top: 3px;
  padding: 0 4px;
}
.ai-msg-user .ai-msg-time { text-align: left; }
.ai-msg-bot .ai-msg-time { text-align: right; }

/* ── Typing Indicator ── */
.ai-typing {
  display: flex;
  gap: 4px;
  padding: 12px 18px;
}
.ai-typing span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--n300);
  animation: typingDot 1.4s ease-in-out infinite;
}
.ai-typing span:nth-child(2) { animation-delay: 0.2s; }
.ai-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typingDot {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-6px); opacity: 1; }
}

/* ── Input Area ── */
.ai-chat-input-wrap {
  padding: 12px;
  border-top: 1px solid var(--n150);
  display: flex;
  gap: 8px;
  background: var(--white);
  flex-shrink: 0;
}
.ai-chat-input {
  flex: 1;
  border: 1.5px solid var(--n200);
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
  background: var(--n50);
}
.ai-chat-input:focus {
  border-color: var(--g400);
  box-shadow: 0 0 0 3px rgba(34,160,90,0.1);
  background: var(--white);
}
.ai-chat-input::placeholder {
  color: var(--n400);
}
.ai-send-btn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: none;
  background: linear-gradient(135deg, #1E7A44, #22A05A);
  color: white;
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
}
.ai-send-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 12px rgba(30,122,68,0.3);
}

/* ── Dark Mode ── */
[data-theme="dark"] .ai-chat-panel {
  background: var(--n900);
  box-shadow: 0 16px 64px rgba(0,0,0,0.5), 0 0 0 1px var(--n700);
}
[data-theme="dark"] .ai-chat-messages {
  background: var(--n950);
}
[data-theme="dark"] .ai-msg-bot .ai-msg-bubble {
  background: var(--n800);
  color: var(--n100);
  border-color: var(--n700);
}
[data-theme="dark"] .ai-chat-input-wrap {
  background: var(--n900);
  border-color: var(--n700);
}
[data-theme="dark"] .ai-chat-input {
  background: var(--n800);
  border-color: var(--n600);
  color: var(--white);
}

/* ── RTL adjustments ── */
[dir="rtl"] .ai-msg-user .ai-msg-bubble {
  border-bottom-right-radius: 16px;
  border-bottom-left-radius: 4px;
}
[dir="rtl"] .ai-msg-bot .ai-msg-bubble {
  border-bottom-left-radius: 16px;
  border-bottom-right-radius: 4px;
}
[dir="rtl"] .ai-msg-user { align-self: flex-end; }
[dir="rtl"] .ai-msg-bot { align-self: flex-start; }
[dir="rtl"] .ai-msg-user .ai-msg-time { text-align: right; }
[dir="rtl"] .ai-msg-bot .ai-msg-time { text-align: left; }
[dir="rtl"] .ai-chat-toggle { left: auto; right: 24px; }
[dir="rtl"] .ai-chat-panel { left: auto; right: 24px; }

/* ── Mobile ── */
@media (max-width: 768px) {
  .ai-chat-panel {
    width: calc(100vw - 32px);
    height: calc(100vh - 200px);
    bottom: 148px;
    left: 16px;
    right: 16px;
    border-radius: 16px;
  }
  [dir="rtl"] .ai-chat-panel {
    left: 16px;
    right: 16px;
  }
  .ai-chat-toggle {
    bottom: 140px; /* Above FAB + bottom nav */
  }
  [dir="rtl"] .ai-chat-toggle {
    right: 16px;
  }
}
