/**
 * EVCcost AI Assistant CSS
 * ──────────────────────────────────────────
 * @package EVCcost
 * @version 2026.08.26.3
 */

:root {
  --ai-primary: #2563eb;
  --ai-gradient: linear-gradient(135deg, #2563eb 0%, #7c3aed 100%);
  --ai-glow: rgba(37, 99, 235, 0.35);
  --ai-surf: #ffffff;
  --ai-surf-sub: #f8fafc;
  --ai-brd: rgba(15, 23, 42, 0.08);
  --ai-txt: #0f172a;
  --ai-txt-sub: #475569;
  --ai-txt-muted: #94a3b8;
  --ai-danger: #ef4444;
}

[data-theme="dark"] {
  --ai-primary: #3b82f6;
  --ai-gradient: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 100%);
  --ai-glow: rgba(59, 130, 246, 0.35);
  --ai-surf: #0f172a;
  --ai-surf-sub: #1e293b;
  --ai-brd: rgba(255, 255, 255, 0.10);
  --ai-txt: #f8fafc;
  --ai-txt-sub: #cbd5e1;
  --ai-txt-muted: #64748b;
  --ai-danger: #f87171;
}

/* ── Scroll-to-top Position & Auto-Hide on Open ── */
.evc-scroll-top {
  bottom: calc(72px + env(safe-area-inset-bottom)) !important;
  right: max(22px, env(safe-area-inset-right)) !important;
  transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s ease, bottom 0.25s ease !important;
}

body.evc-ai-active .evc-scroll-top,
.evc-ai-drawer.is-active ~ .evc-scroll-top {
  opacity: 0 !important;
  pointer-events: none !important;
  transform: translateY(12px) !important;
  visibility: hidden !important;
}

/* ── Floating Action Button (FAB) ── */
.evc-ai-fab {
  position: fixed;
  bottom: calc(18px + env(safe-area-inset-bottom));
  right: max(18px, env(safe-area-inset-right));
  z-index: 9990;
  width: 44px;
  height: 44px;
  border-radius: 999px;
  background: var(--ai-gradient);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.45);
  box-shadow: 0 10px 25px var(--ai-glow), 0 2px 8px rgba(0, 0, 0, 0.14);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  outline: none;
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.25s ease, bottom 0.25s ease;
  user-select: none;
  padding: 0;
}

.evc-ai-fab:hover {
  transform: scale(1.08) translateY(-2px);
  box-shadow: 0 14px 30px var(--ai-glow), 0 4px 12px rgba(0, 0, 0, 0.2);
}

.evc-ai-fab:active {
  transform: scale(0.94);
}

.evc-ai-fab svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.2s ease;
}

.evc-ai-fab .icon-open {
  display: block;
}

.evc-ai-fab .icon-close {
  display: none;
}

.evc-ai-fab.is-open .icon-open {
  display: none;
}

.evc-ai-fab.is-open .icon-close {
  display: block;
  transform: rotate(90deg);
}

/* Pulse animation on idle */
.evc-ai-fab::before {
  content: '';
  position: absolute;
  top: -4px;
  left: -4px;
  right: -4px;
  bottom: -4px;
  border-radius: 999px;
  background: var(--ai-gradient);
  opacity: 0.35;
  z-index: -1;
  animation: evc-ai-pulse 3s infinite;
}

.evc-ai-fab.is-open::before {
  display: none;
}

@keyframes evc-ai-pulse {
  0% { transform: scale(1); opacity: 0.35; }
  50% { transform: scale(1.22); opacity: 0; }
  100% { transform: scale(1); opacity: 0; }
}

/* ── AI Chat Drawer Window ── */
.evc-ai-drawer {
  position: fixed;
  bottom: calc(80px + env(safe-area-inset-bottom));
  right: max(18px, env(safe-area-inset-right));
  width: 380px;
  max-width: calc(100vw - 36px);
  height: 540px;
  max-height: calc(100vh - 120px);
  background: var(--ai-surf);
  border: 1px solid var(--ai-brd);
  border-radius: 20px;
  box-shadow: 0 20px 45px rgba(15, 23, 42, 0.20), 0 4px 12px rgba(0, 0, 0, 0.08);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 9995;
  opacity: 0;
  pointer-events: none;
  transform: translateY(18px) scale(0.96);
  transform-origin: bottom right;
  transition: opacity 0.22s ease, transform 0.22s cubic-bezier(0.4, 0, 0.2, 1);
}

.evc-ai-drawer.is-active {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0) scale(1);
}

/* ── RTL (Arabic) Support ── */
html[dir="rtl"] .evc-ai-fab,
[dir="rtl"] .evc-ai-fab {
  right: auto !important;
  left: max(18px, env(safe-area-inset-left)) !important;
}

html[dir="rtl"] .evc-ai-drawer,
[dir="rtl"] .evc-ai-drawer {
  right: auto !important;
  left: max(18px, env(safe-area-inset-left)) !important;
  transform-origin: bottom left;
}

html[dir="rtl"] .evc-scroll-top,
[dir="rtl"] .evc-scroll-top {
  right: auto !important;
  left: max(22px, env(safe-area-inset-left)) !important;
}

/* ── Header ── */
.evc-ai-header {
  padding: 14px 16px;
  background: var(--ai-gradient);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(255, 255, 255, 0.15);
}

.evc-ai-header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.evc-ai-header-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
}

.evc-ai-header-avatar svg,
.evc-ai-header-avatar img {
  width: 22px;
  height: 22px;
  object-fit: contain;
  display: block;
}

.evc-ai-fab img.icon-open {
  width: 26px;
  height: 26px;
  object-fit: contain;
  display: block;
  pointer-events: none;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.15));
}

.evc-ai-header-info h4 {
  font-size: 0.95rem;
  font-weight: 700;
  margin: 0;
  line-height: 1.2;
  color: #ffffff;
}

.evc-ai-header-info span {
  font-size: 0.72rem;
  color: rgba(255, 255, 255, 0.85);
}

.evc-ai-header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.evc-ai-btn-icon {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.18s ease;
  font-size: 0.85rem;
}

.evc-ai-btn-icon:hover {
  background: rgba(255, 255, 255, 0.2);
  color: #ffffff;
}

/* ── Messages Stream ── */
.evc-ai-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--ai-surf-sub);
  scrollbar-width: thin;
  scrollbar-color: var(--ai-txt-muted) transparent;
}

.evc-ai-messages::-webkit-scrollbar {
  width: 5px;
}

.evc-ai-messages::-webkit-scrollbar-thumb {
  background: var(--ai-txt-muted);
  border-radius: 4px;
}

.evc-ai-msg {
  max-width: 86%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 0.88rem;
  line-height: 1.5;
  word-break: break-word;
  animation: evc-ai-msg-pop 0.2s ease forwards;
}

@keyframes evc-ai-msg-pop {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.evc-ai-msg.user {
  align-self: flex-end;
  background: var(--ai-primary);
  color: #ffffff;
  border-bottom-right-radius: 4px;
  box-shadow: 0 2px 6px rgba(37, 99, 235, 0.2);
}

.evc-ai-msg.assistant {
  align-self: flex-start;
  background: var(--ai-surf);
  color: var(--ai-txt);
  border: 1px solid var(--ai-brd);
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.04);
}

.evc-ai-msg.assistant ul, 
.evc-ai-msg.assistant ol {
  margin: 6px 0;
  padding-left: 18px;
}

.evc-ai-msg.assistant p {
  margin: 0 0 6px 0;
}

.evc-ai-msg.assistant p:last-child {
  margin-bottom: 0;
}

.evc-ai-msg.assistant strong {
  font-weight: 600;
  color: var(--ai-primary);
}

/* Typing Dots */
.evc-ai-msg.typing {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 12px 16px;
}

.evc-ai-msg.typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ai-txt-muted);
  animation: evc-ai-dot 1.2s infinite ease-in-out;
}

.evc-ai-msg.typing span:nth-child(2) { animation-delay: 0.2s; }
.evc-ai-msg.typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes evc-ai-dot {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1.1); opacity: 1; }
}

/* ── Suggestions Bar ── */
.evc-ai-suggestions {
  padding: 8px 12px 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  background: var(--ai-surf-sub);
}

.evc-ai-sug-title {
  width: 100%;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--ai-txt-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.evc-ai-sug-chip {
  background: var(--ai-surf);
  border: 1px solid var(--ai-brd);
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 0.76rem;
  color: var(--ai-txt-sub);
  cursor: pointer;
  transition: all 0.18s ease;
  white-space: nowrap;
}

.evc-ai-sug-chip:hover {
  background: var(--ai-primary);
  color: #ffffff;
  border-color: var(--ai-primary);
  transform: translateY(-1px);
}

/* ── Footer Input Area ── */
.evc-ai-footer {
  padding: 10px 12px;
  background: var(--ai-surf);
  border-top: 1px solid var(--ai-brd);
  display: flex;
  align-items: center;
  gap: 8px;
}

.evc-ai-input {
  flex: 1;
  background: var(--ai-surf-sub);
  border: 1px solid var(--ai-brd);
  border-radius: 12px;
  padding: 8px 12px;
  font-size: 0.88rem;
  color: var(--ai-txt);
  outline: none;
  resize: none;
  max-height: 80px;
  height: 38px;
  line-height: 1.4;
  font-family: inherit;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.evc-ai-input:focus {
  border-color: var(--ai-primary);
  box-shadow: 0 0 0 3px var(--ai-glow);
  background: var(--ai-surf);
}

/* Voice Mic Button */
.evc-ai-mic-btn {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background: var(--ai-surf-sub);
  color: var(--ai-txt-sub);
  border: 1px solid var(--ai-brd);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  outline: none;
  transition: all 0.18s ease;
  font-size: 0.95rem;
}

.evc-ai-mic-btn:hover {
  background: var(--ai-surf);
  color: var(--ai-primary);
  border-color: var(--ai-primary);
}

.evc-ai-mic-btn.is-recording {
  background: var(--ai-danger) !important;
  color: #ffffff !important;
  border-color: var(--ai-danger) !important;
  animation: evc-ai-mic-pulse 1.2s infinite;
}

@keyframes evc-ai-mic-pulse {
  0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4); }
  50% { transform: scale(1.08); box-shadow: 0 0 0 8px rgba(239, 68, 68, 0); }
  100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

.evc-ai-send-btn {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background: var(--ai-primary);
  color: #ffffff;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  outline: none;
  transition: transform 0.18s ease, background 0.18s ease;
  font-size: 0.95rem;
}

.evc-ai-send-btn:hover:not(:disabled) {
  background: #1d4ed8;
  transform: scale(1.05);
}

.evc-ai-send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ── Mobile adjustments ── */
@media (max-width: 640px) {
  .evc-ai-drawer {
    right: 8px;
    left: 8px;
    bottom: calc(76px + env(safe-area-inset-bottom));
    width: auto;
    max-width: none;
    height: 70vh;
    max-height: 520px;
  }
}
