/* ============================================================
   Travelife AI Assistant Widget — Phase 1L.2
   Uses: --main-color CSS variable from agency theme
         Bootstrap 4 compatible
         RTL compatible (auto via [dir=rtl])
   ============================================================ */

:root {
  --ai-primary:    var(--main-color, #2563eb);
  --ai-bg:         #ffffff;
  --ai-panel-w:    380px;
  --ai-panel-h:    540px;
  --ai-radius:     16px;
  --ai-shadow:     0 8px 40px rgba(0,0,0,.18);
  --ai-msg-user:   var(--main-color, #2563eb);
  --ai-msg-bot:    #f1f5f9;
  --ai-z:          9999;
}

/* ── Floating button ───────────────────────────────────────── */
#ai-chat-btn {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--ai-primary);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(0,0,0,.25);
  z-index: var(--ai-z);
  transition: transform .2s, box-shadow .2s;
  outline: none;
}
[dir=rtl] #ai-chat-btn { right: auto; left: 24px; }
#ai-chat-btn:hover { transform: scale(1.08); box-shadow: 0 6px 28px rgba(0,0,0,.32); }
#ai-chat-btn svg { width: 26px; height: 26px; }
#ai-chat-btn .ai-badge {
  position: absolute;
  top: -2px; right: -2px;
  width: 14px; height: 14px;
  background: #ef4444;
  border-radius: 50%;
  border: 2px solid #fff;
  display: none;
}
#ai-chat-btn.has-notif .ai-badge { display: block; }

/* ── Chat panel ────────────────────────────────────────────── */
#ai-chat-panel {
  position: fixed;
  bottom: 90px;
  right: 24px;
  width: var(--ai-panel-w);
  height: var(--ai-panel-h);
  background: var(--ai-bg);
  border-radius: var(--ai-radius);
  box-shadow: var(--ai-shadow);
  display: flex;
  flex-direction: column;
  z-index: var(--ai-z);
  overflow: hidden;
  transform: scale(.92) translateY(12px);
  opacity: 0;
  pointer-events: none;
  transition: transform .22s cubic-bezier(.34,1.56,.64,1), opacity .18s;
  font-family: "Open Sans", sans-serif;
}
[dir=rtl] #ai-chat-panel { right: auto; left: 24px; }
#ai-chat-panel.open {
  transform: scale(1) translateY(0);
  opacity: 1;
  pointer-events: all;
}

/* ── Panel header ──────────────────────────────────────────── */
.ai-panel-header {
  background: var(--ai-primary);
  color: #fff;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.ai-panel-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: rgba(255,255,255,.25);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  font-size: 18px;
}
.ai-panel-title { font-weight: 700; font-size: 15px; line-height: 1.2; }
.ai-panel-subtitle { font-size: 11px; opacity: .8; }
.ai-panel-close {
  margin-left: auto;
  background: none; border: none; color: #fff;
  cursor: pointer; padding: 4px; display: flex;
  opacity: .8; transition: opacity .15s;
}
[dir=rtl] .ai-panel-close { margin-left: 0; margin-right: auto; }
.ai-panel-close:hover { opacity: 1; }

/* ── Messages area ─────────────────────────────────────────── */
.ai-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.ai-messages::-webkit-scrollbar { width: 4px; }
.ai-messages::-webkit-scrollbar-track { background: transparent; }
.ai-messages::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }

/* ── Message bubbles ───────────────────────────────────────── */
.ai-msg { display: flex; flex-direction: column; max-width: 88%; animation: ai-pop .18s; }
.ai-msg--user { align-self: flex-end; align-items: flex-end; }
.ai-msg--bot  { align-self: flex-start; align-items: flex-start; }
[dir=rtl] .ai-msg--user { align-self: flex-start; align-items: flex-start; }
[dir=rtl] .ai-msg--bot  { align-self: flex-end;   align-items: flex-end; }

.ai-msg__bubble {
  padding: 9px 13px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.5;
  word-break: break-word;
}
.ai-msg--user .ai-msg__bubble {
  background: var(--ai-msg-user);
  color: #fff;
  border-bottom-right-radius: 4px;
}
[dir=rtl] .ai-msg--user .ai-msg__bubble { border-bottom-right-radius: 14px; border-bottom-left-radius: 4px; }
.ai-msg--bot .ai-msg__bubble {
  background: var(--ai-msg-bot);
  color: #1e293b;
  border-bottom-left-radius: 4px;
}
[dir=rtl] .ai-msg--bot .ai-msg__bubble { border-bottom-left-radius: 14px; border-bottom-right-radius: 4px; }

/* ── Message time ──────────────────────────────────────────── */
.ai-msg__time { font-size: 11px; color: #94a3b8; margin-top: 3px; padding: 0 4px; }

/* ── End session button ────────────────────────────────────── */
.ai-panel-end {
  margin-left: auto;
  background: none; border: none; color: #fff;
  cursor: pointer; padding: 4px; display: flex;
  opacity: .8; transition: opacity .15s;
}
.ai-panel-end + .ai-panel-close { margin-left: 4px; }
[dir=rtl] .ai-panel-end { margin-left: 0; margin-right: auto; }
[dir=rtl] .ai-panel-end + .ai-panel-close { margin-left: 0; margin-right: 4px; }
.ai-panel-end:hover { opacity: 1; }

/* ── Typing indicator ──────────────────────────────────────── */
.ai-typing { display: flex; gap: 4px; align-items: center; padding: 10px 13px; }
.ai-typing__label { font-size: 12px; color: #64748b; margin-left: 6px; font-style: normal; }
[dir=rtl] .ai-typing__label { margin-left: 0; margin-right: 6px; }
.ai-sys-msg--warning { color: #b45309; background: #fffbeb; }
.ai-typing span {
  width: 7px; height: 7px;
  background: #94a3b8;
  border-radius: 50%;
  animation: ai-bounce 1.2s infinite;
}
.ai-typing span:nth-child(2) { animation-delay: .2s; }
.ai-typing span:nth-child(3) { animation-delay: .4s; }

/* ── Product cards ─────────────────────────────────────────── */
.ai-cards { display: flex; flex-direction: column; gap: 8px; margin-top: 6px; }
.ai-card {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
  transition: border-color .15s;
  overflow: hidden;
}
.ai-card:hover { border-color: var(--ai-primary); }
.ai-card__image {
  display: block; width: calc(100% + 24px); height: 126px;
  margin: -10px -12px 10px; object-fit: cover; background: #f1f5f9;
}
.ai-card__name { font-weight: 600; color: #1e293b; margin-bottom: 3px; }
.ai-card__stars { color: #d5a82b; font-size: 13px; letter-spacing: 1px; margin-bottom: 3px; }
.ai-card__meta { color: #64748b; font-size: 12px; }
.ai-card__itinerary { color: #475569; font-size: 12px; line-height: 1.4; margin-top: 5px; }
.ai-card__price { font-weight: 700; color: var(--ai-primary); font-size: 14px; margin-top: 6px; }
.ai-card__actions { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.ai-card__btn {
  font-size: 12px; padding: 5px 12px; border-radius: 20px;
  border: 1px solid var(--ai-primary);
  color: var(--ai-primary); background: transparent;
  cursor: pointer; text-decoration: none; transition: all .15s;
  display: inline-flex; align-items: center; gap: 4px;
}
.ai-card__btn:hover, .ai-card__btn--primary {
  background: var(--ai-primary); color: #fff;
}
.ai-results-link {
  display: block; padding: 9px 12px; border-radius: 9px;
  background: var(--ai-primary); color: #fff; text-align: center;
  font-size: 12px; font-weight: 600; text-decoration: none;
}

/* ── Action buttons (handoff proposal, etc.) ───────────────── */
.ai-actions { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.ai-action-btn {
  font-size: 13px; padding: 7px 14px; border-radius: 20px;
  border: 1px solid var(--ai-primary);
  color: var(--ai-primary); background: transparent;
  cursor: pointer; transition: all .15s; flex: 1; min-width: 0;
  text-align: center;
}
.ai-action-btn:hover, .ai-action-btn--primary {
  background: var(--ai-primary); color: #fff;
}
.ai-action-btn--secondary { border-color: #e2e8f0; color: #64748b; }
.ai-action-btn--secondary:hover { background: #f1f5f9; }

/* ── Contact form ──────────────────────────────────────────── */
.ai-contact-form { padding: 4px 0; }
.ai-contact-intro { color: #334155; font-size: 13px; line-height: 1.45; margin-bottom: 10px; }
.ai-contact-hint { color: #64748b; font-size: 11px; margin: -2px 0 9px; }
.ai-contact-form input {
  width: 100%; padding: 8px 10px; border: 1px solid #e2e8f0;
  border-radius: 8px; font-size: 13px; margin-bottom: 8px;
  outline: none; transition: border-color .15s;
}
.ai-contact-form input:focus { border-color: var(--ai-primary); }
.ai-contact-form button {
  width: 100%; padding: 9px; border-radius: 8px;
  background: var(--ai-primary); color: #fff;
  border: none; font-size: 14px; font-weight: 600;
  cursor: pointer; transition: opacity .15s;
}
.ai-contact-form button:disabled { opacity: .6; cursor: not-allowed; }

/* ── Error / system messages ───────────────────────────────── */
.ai-sys-msg {
  text-align: center; font-size: 12px; color: #94a3b8;
  padding: 6px 12px; margin: 4px auto;
  background: #f8fafc; border-radius: 8px;
}
.ai-sys-msg--error { color: #ef4444; background: #fef2f2; }
.ai-sys-msg--success { color: #10b981; background: #f0fdf4; }

/* ── Input bar ─────────────────────────────────────────────── */
.ai-input-bar {
  padding: 10px 12px;
  border-top: 1px solid #f1f5f9;
  display: flex;
  gap: 8px;
  align-items: flex-end;
  flex-shrink: 0;
}
.ai-input-bar textarea {
  flex: 1; min-height: 36px; max-height: 110px;
  border: 1px solid #e2e8f0; border-radius: 10px;
  padding: 8px 10px; resize: none; font-size: 14px;
  outline: none; transition: border-color .15s;
  font-family: inherit; overflow-y: auto;
}
.ai-input-bar textarea:focus { border-color: var(--ai-primary); }
.ai-input-bar textarea::placeholder { color: #94a3b8; }
.ai-send-btn {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--ai-primary); color: #fff;
  border: none; cursor: pointer; display: flex;
  align-items: center; justify-content: center;
  flex-shrink: 0; transition: opacity .15s;
}
.ai-send-btn:disabled { opacity: .5; cursor: not-allowed; }
.ai-send-btn svg { width: 16px; height: 16px; }

/* ── Animations ────────────────────────────────────────────── */
@keyframes ai-pop { from { transform: scale(.88); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes ai-bounce { 0%,80%,100% { transform: scale(1); } 40% { transform: scale(1.5); } }

/* ── Mobile ────────────────────────────────────────────────── */
@media (max-width: 480px) {
  #ai-chat-panel {
    bottom: 0; right: 0; left: 0;
    width: 100%; height: 92vh;
    border-radius: var(--ai-radius) var(--ai-radius) 0 0;
  }
  [dir=rtl] #ai-chat-panel { right: 0; left: 0; }
  #ai-chat-btn { bottom: 16px; right: 16px; }
  [dir=rtl] #ai-chat-btn { right: auto; left: 16px; }
}
