/* Primix AI Chat Widget v1 — styling */

:root {
  --pmx-ai-accent: var(--accent, #2563eb);
  --pmx-ai-accent-2: var(--accent-2, #7c3aed);
  --pmx-ai-card: var(--card, #ffffff);
  --pmx-ai-bg: var(--bg, #f8fafc);
  --pmx-ai-text: var(--text, #0f172a);
  --pmx-ai-muted: var(--muted, #64748b);
  --pmx-ai-border: var(--border, rgba(15, 23, 42, 0.08));
  --pmx-ai-surface: var(--surface, #f1f5f9);
  --pmx-ai-user-bg: var(--pmx-ai-accent);
  --pmx-ai-user-fg: #ffffff;
  --pmx-ai-assistant-bg: var(--surface, #f1f5f9);
  --pmx-ai-assistant-fg: var(--text, #0f172a);
  --pmx-ai-shadow: 0 10px 40px -10px rgba(37, 99, 235, 0.35), 0 4px 16px -4px rgba(0, 0, 0, 0.1);
  --pmx-ai-shadow-btn: 0 8px 24px -6px rgba(37, 99, 235, 0.55), 0 4px 10px -2px rgba(0, 0, 0, 0.12);
}

@media (prefers-color-scheme: dark) {
  :root {
    --pmx-ai-card: var(--card, #0f172a);
    --pmx-ai-bg: var(--bg, #020617);
    --pmx-ai-text: var(--text, #f1f5f9);
    --pmx-ai-muted: var(--muted, #94a3b8);
    --pmx-ai-border: var(--border, rgba(255, 255, 255, 0.08));
    --pmx-ai-surface: var(--surface, #1e293b);
    --pmx-ai-assistant-bg: var(--surface, #1e293b);
    --pmx-ai-assistant-fg: #f1f5f9;
  }
}

/* ============================================================
   Floating button
   ============================================================ */
.pmx-ai-chat-btn {
  position: fixed;
  bottom: 20px;
  left: 20px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  z-index: 9999;
  color: #ffffff;
  background: linear-gradient(135deg, var(--pmx-ai-accent) 0%, var(--pmx-ai-accent-2) 100%);
  box-shadow: var(--pmx-ai-shadow-btn);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.18s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.2s ease;
  padding: 0;
  outline: none;
  -webkit-tap-highlight-color: transparent;
}

[dir="ltr"] .pmx-ai-chat-btn,
html[dir="ltr"] .pmx-ai-chat-btn {
  left: auto;
  right: 20px;
}

.pmx-ai-chat-btn::before {
  content: "";
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--pmx-ai-accent), var(--pmx-ai-accent-2));
  opacity: 0.35;
  filter: blur(12px);
  z-index: -1;
  transition: opacity 0.25s ease;
}

.pmx-ai-chat-btn:hover {
  transform: translateY(-2px) scale(1.05);
}

.pmx-ai-chat-btn:hover::before {
  opacity: 0.55;
}

.pmx-ai-chat-btn:active {
  transform: translateY(0) scale(0.98);
}

.pmx-ai-chat-btn:focus-visible {
  box-shadow: var(--pmx-ai-shadow-btn), 0 0 0 3px rgba(37, 99, 235, 0.35);
}

body.pmx-ai-chat-open .pmx-ai-chat-btn {
  transform: scale(0.9);
  opacity: 0.9;
}

/* ============================================================
   Panel
   ============================================================ */
.pmx-ai-chat-panel {
  position: fixed;
  top: 20px;
  bottom: 20px;
  left: 20px;
  width: 400px;
  max-width: calc(100vw - 40px);
  height: auto;
  max-height: calc(100vh - 40px);
  background: var(--pmx-ai-card);
  border-radius: 16px;
  box-shadow: var(--pmx-ai-shadow);
  border: 1px solid var(--pmx-ai-border);
  z-index: 10000;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateX(-120%);
  opacity: 0;
  pointer-events: none;
  transition:
    transform 0.32s cubic-bezier(0.22, 1, 0.36, 1),
    opacity 0.25s ease;
  color: var(--pmx-ai-text);
  font-family: inherit;
}

[dir="ltr"] .pmx-ai-chat-panel,
html[dir="ltr"] .pmx-ai-chat-panel {
  left: auto;
  right: 20px;
  transform: translateX(120%);
}

body.pmx-ai-chat-open .pmx-ai-chat-panel {
  transform: translateX(0);
  opacity: 1;
  pointer-events: auto;
}

/* ============================================================
   Backdrop (mobile only)
   ============================================================ */
.pmx-ai-chat-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  z-index: 9998;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  display: none;
}

body.pmx-ai-chat-open .pmx-ai-chat-backdrop {
  opacity: 1;
  pointer-events: auto;
}

/* ============================================================
   Header
   ============================================================ */
.pmx-ai-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: linear-gradient(135deg, var(--pmx-ai-accent) 0%, var(--pmx-ai-accent-2) 100%);
  color: #ffffff;
  flex-shrink: 0;
  border-bottom: 1px solid var(--pmx-ai-border);
}

.pmx-ai-chat-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 15px;
}

.pmx-ai-chat-title-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #10b981;
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.25);
  animation: pmx-ai-pulse 2s infinite;
}

@keyframes pmx-ai-pulse {
  0%, 100% { box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.25); }
  50%      { box-shadow: 0 0 0 6px rgba(16, 185, 129, 0.05); }
}

.pmx-ai-chat-title-text {
  letter-spacing: 0.2px;
}

.pmx-ai-chat-ctx {
  font-size: 11px;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.18);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.25);
  letter-spacing: 0.3px;
  margin-inline-start: 4px;
}

.pmx-ai-chat-close {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: none;
  background: rgba(255, 255, 255, 0.15);
  color: #ffffff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease;
  padding: 0;
}

.pmx-ai-chat-close:hover {
  background: rgba(255, 255, 255, 0.28);
}

.pmx-ai-chat-close:focus-visible {
  outline: 2px solid #ffffff;
  outline-offset: 2px;
}

/* ============================================================
   Messages list
   ============================================================ */
.pmx-ai-chat-messages {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 16px;
  background: var(--pmx-ai-bg);
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}

.pmx-ai-chat-messages::-webkit-scrollbar { width: 6px; }
.pmx-ai-chat-messages::-webkit-scrollbar-track { background: transparent; }
.pmx-ai-chat-messages::-webkit-scrollbar-thumb {
  background: var(--pmx-ai-border);
  border-radius: 999px;
}

/* ============================================================
   Welcome state
   ============================================================ */
.pmx-ai-chat-welcome {
  margin: auto;
  text-align: center;
  padding: 24px 12px;
  color: var(--pmx-ai-muted);
  animation: pmx-ai-fade-in 0.4s ease;
}

.pmx-ai-chat-welcome-icon {
  font-size: 36px;
  margin-bottom: 8px;
  filter: drop-shadow(0 2px 6px rgba(37, 99, 235, 0.25));
}

.pmx-ai-chat-welcome-logo {
  width: 56px;
  height: 56px;
  object-fit: contain;
  background: #ffffff;
  border-radius: 50%;
  padding: 8px;
  box-shadow: 0 4px 16px rgba(59, 130, 246, 0.25);
}

.pmx-ai-chat-welcome-text {
  font-size: 16px;
  font-weight: 600;
  color: var(--pmx-ai-text);
  margin-bottom: 4px;
}

.pmx-ai-chat-welcome-hint {
  font-size: 13px;
  color: var(--pmx-ai-muted);
  line-height: 1.5;
  max-width: 260px;
  margin: 0 auto;
}

@keyframes pmx-ai-fade-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ============================================================
   Messages
   ============================================================ */
.pmx-ai-chat-msg {
  display: flex;
  max-width: 100%;
  animation: pmx-ai-msg-in 0.22s ease;
}

@keyframes pmx-ai-msg-in {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.pmx-ai-chat-msg-user {
  justify-content: flex-end;
}

.pmx-ai-chat-msg-assistant {
  justify-content: flex-start;
}

.pmx-ai-chat-bubble {
  max-width: 82%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.6;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}

.pmx-ai-chat-msg-user .pmx-ai-chat-bubble {
  background: var(--pmx-ai-user-bg);
  color: var(--pmx-ai-user-fg);
  border-bottom-right-radius: 4px;
}

[dir="rtl"] .pmx-ai-chat-msg-user .pmx-ai-chat-bubble,
.pmx-ai-chat-panel[dir="rtl"] .pmx-ai-chat-msg-user .pmx-ai-chat-bubble {
  border-bottom-right-radius: 14px;
  border-bottom-left-radius: 4px;
}

.pmx-ai-chat-msg-assistant .pmx-ai-chat-bubble {
  background: var(--pmx-ai-assistant-bg);
  color: var(--pmx-ai-assistant-fg);
  border-bottom-left-radius: 4px;
  border: 1px solid var(--pmx-ai-border);
}

[dir="rtl"] .pmx-ai-chat-msg-assistant .pmx-ai-chat-bubble,
.pmx-ai-chat-panel[dir="rtl"] .pmx-ai-chat-msg-assistant .pmx-ai-chat-bubble {
  border-bottom-left-radius: 14px;
  border-bottom-right-radius: 4px;
}

/* Markdown-ish content inside bubbles */
.pmx-ai-chat-bubble p { margin: 0 0 8px 0; }
.pmx-ai-chat-bubble p:last-child { margin-bottom: 0; }
.pmx-ai-chat-bubble h4 { font-size: 14px; font-weight: 700; margin: 10px 0 6px; }
.pmx-ai-chat-bubble h5 { font-size: 13px; font-weight: 600; margin: 8px 0 4px; }
.pmx-ai-chat-bubble ul {
  margin: 6px 0;
  padding-inline-start: 20px;
}
.pmx-ai-chat-bubble li { margin: 3px 0; }
.pmx-ai-chat-bubble strong { font-weight: 700; }
.pmx-ai-chat-bubble code {
  background: rgba(0, 0, 0, 0.08);
  padding: 1px 5px;
  border-radius: 4px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.9em;
}
.pmx-ai-chat-msg-user .pmx-ai-chat-bubble code {
  background: rgba(255, 255, 255, 0.22);
}
.pmx-ai-chat-bubble pre {
  background: rgba(0, 0, 0, 0.08);
  padding: 8px 10px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 8px 0;
  font-size: 12px;
}
.pmx-ai-chat-bubble pre code {
  background: transparent;
  padding: 0;
}

/* ============================================================
   Loading dots
   ============================================================ */
.pmx-ai-chat-dots {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  padding: 2px 0;
}

.pmx-ai-chat-dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--pmx-ai-muted);
  animation: pmx-ai-bounce 1.2s infinite ease-in-out;
}

.pmx-ai-chat-dots span:nth-child(2) { animation-delay: 0.15s; }
.pmx-ai-chat-dots span:nth-child(3) { animation-delay: 0.30s; }

@keyframes pmx-ai-bounce {
  0%, 80%, 100% { transform: scale(0.7); opacity: 0.5; }
  40%           { transform: scale(1);   opacity: 1; }
}

/* ============================================================
   Form (input + send)
   ============================================================ */
.pmx-ai-chat-form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px;
  background: var(--pmx-ai-card);
  border-top: 1px solid var(--pmx-ai-border);
  flex-shrink: 0;
}

.pmx-ai-chat-input {
  flex: 1 1 auto;
  min-height: 40px;
  max-height: 140px;
  resize: none;
  border: 1px solid var(--pmx-ai-border);
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 14px;
  font-family: inherit;
  line-height: 1.5;
  background: var(--pmx-ai-bg);
  color: var(--pmx-ai-text);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  box-sizing: border-box;
}

.pmx-ai-chat-input:focus {
  border-color: var(--pmx-ai-accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.pmx-ai-chat-input::placeholder {
  color: var(--pmx-ai-muted);
}

.pmx-ai-chat-send {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: none;
  background: linear-gradient(135deg, var(--pmx-ai-accent) 0%, var(--pmx-ai-accent-2) 100%);
  color: #ffffff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform 0.15s ease, opacity 0.15s ease;
  padding: 0;
}

.pmx-ai-chat-send:hover:not(:disabled) {
  transform: translateY(-1px);
}

.pmx-ai-chat-send:active:not(:disabled) {
  transform: translateY(0);
}

.pmx-ai-chat-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.pmx-ai-chat-send:focus-visible {
  outline: 2px solid var(--pmx-ai-accent);
  outline-offset: 2px;
}

/* ============================================================
   Mobile (≤ 768px)
   ============================================================ */
@media (max-width: 768px) {
  .pmx-ai-chat-btn {
    bottom: 16px;
    left: 16px;
    width: 52px;
    height: 52px;
  }

  [dir="ltr"] .pmx-ai-chat-btn,
  html[dir="ltr"] .pmx-ai-chat-btn {
    right: 16px;
  }

  .pmx-ai-chat-panel {
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    max-width: 100%;
    height: 85vh;
    max-height: 85vh;
    border-radius: 16px 16px 0 0;
    transform: translateY(100%);
    border-bottom: none;
  }

  [dir="ltr"] .pmx-ai-chat-panel,
  html[dir="ltr"] .pmx-ai-chat-panel {
    right: 0;
    transform: translateY(100%);
  }

  body.pmx-ai-chat-open .pmx-ai-chat-panel {
    transform: translateY(0);
  }

  .pmx-ai-chat-backdrop {
    display: block;
  }

  body.pmx-ai-chat-open .pmx-ai-chat-btn {
    opacity: 0;
    pointer-events: none;
  }
}

/* ============================================================
   Reduced motion
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  .pmx-ai-chat-btn,
  .pmx-ai-chat-panel,
  .pmx-ai-chat-backdrop,
  .pmx-ai-chat-msg,
  .pmx-ai-chat-welcome,
  .pmx-ai-chat-title-dot,
  .pmx-ai-chat-dots span {
    animation: none !important;
    transition: opacity 0.15s ease !important;
  }
}

/* ============================================================
   Brand logo (FAB + header)
   ============================================================ */
.pmx-ai-chat-btn-logo {
  width: 38px;
  height: 38px;
  object-fit: contain;
  background: #ffffff;
  border-radius: 50%;
  padding: 5px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1) inset;
  transition: transform 0.2s ease;
}

.pmx-ai-chat-btn:hover .pmx-ai-chat-btn-logo {
  transform: scale(1.05);
}

.pmx-ai-chat-title-logo {
  width: 28px;
  height: 28px;
  object-fit: contain;
  background: #ffffff;
  border-radius: 50%;
  padding: 3px;
  margin-inline-end: 4px;
  flex-shrink: 0;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}

/* ============================================================
   Print: hide widget
   ============================================================ */
@media print {
  .pmx-ai-chat-btn,
  .pmx-ai-chat-panel,
  .pmx-ai-chat-backdrop {
    display: none !important;
  }
}
