/* ============================================================
   UniversalAI3 — Frontend chat widget  v6.4.0
   Clean, modern, polished chat UI
   ============================================================ */

/* ---- Base box ---- */
.unai3-box {
  --unai3-accent:       #2563eb;
  --unai3-accent-light: #eff6ff;
  --unai3-accent-text:  #ffffff;
  --unai3-radius:       16px;

  display: flex;
  flex-direction: column;
  max-width: 680px;
  width: 100%;
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: var(--unai3-radius);
  overflow: hidden;
  box-shadow: 0 4px 24px rgba(0,0,0,0.08);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* ---- Header bar ---- */
.unai3-chat-header-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  background: var(--unai3-accent);
  border-bottom: none;
}

.unai3-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: rgba(255,255,255,0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  overflow: hidden;
  flex-shrink: 0;
  border: 2px solid rgba(255,255,255,0.4);
}
.unai3-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.unai3-header-name {
  font-size: 15px;
  font-weight: 600;
  color: #ffffff;
  flex: 1;
}
.unai3-header-status {
  font-size: 12px;
  color: rgba(255,255,255,0.75);
  margin-top: 1px;
}
.unai3-header-online {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #4ade80;
  margin-right: 5px;
  vertical-align: middle;
}

/* ---- Messages area ---- */
.unai3-messages {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: 200px;
  max-height: 440px;
  overflow-y: auto;
  padding: 20px 16px;
  background: #f8fafc;
  scroll-behavior: smooth;
}
.unai3-messages::-webkit-scrollbar { width: 4px; }
.unai3-messages::-webkit-scrollbar-track { background: transparent; }
.unai3-messages::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 2px; }

/* ---- Message rows ---- */
.unai3-msg {
  display: flex;
  flex-direction: column;
  max-width: 78%;
  margin-bottom: 6px;
}
.unai3-msg-name {
  font-size: 11px;
  font-weight: 600;
  color: #94a3b8;
  margin-bottom: 4px;
  letter-spacing: 0.03em;
  padding: 0 4px;
}
.unai3-msg-bubble {
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 14px;
  line-height: 1.65;
  word-break: break-word;
}

/* User messages — right side */
.unai3-msg-user {
  align-self: flex-end;
  align-items: flex-end;
}
.unai3-msg-user .unai3-msg-name {
  text-align: right;
}
.unai3-msg-user .unai3-msg-bubble {
  background: var(--unai3-accent);
  color: #fff;
  border-radius: 18px 18px 4px 18px;
}

/* AI messages — left side */
.unai3-msg-ai {
  align-self: flex-start;
  align-items: flex-start;
}
.unai3-msg-ai .unai3-msg-bubble {
  background: #ffffff;
  color: #1e293b;
  border: 1px solid #e2e8f0;
  border-radius: 18px 18px 18px 4px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

/* Error messages */
.unai3-msg-error {
  align-self: flex-start;
  align-items: flex-start;
}
.unai3-msg-error .unai3-msg-bubble {
  background: #fef2f2;
  color: #dc2626;
  border: 1px solid #fecaca;
  border-radius: 18px 18px 18px 4px;
  font-size: 13px;
}

/* Markdown inside AI bubbles */
.unai3-msg-ai .unai3-msg-bubble p        { margin: 0 0 8px; }
.unai3-msg-ai .unai3-msg-bubble p:last-child { margin-bottom: 0; }
.unai3-msg-ai .unai3-msg-bubble ul,
.unai3-msg-ai .unai3-msg-bubble ol       { margin: 4px 0 8px; padding-left: 18px; }
.unai3-msg-ai .unai3-msg-bubble li       { margin-bottom: 3px; }
.unai3-msg-ai .unai3-msg-bubble strong   { font-weight: 600; }
.unai3-msg-ai .unai3-msg-bubble em       { font-style: italic; }
.unai3-msg-ai .unai3-msg-bubble code     { font-family: monospace; font-size: 12px; background: #f1f5f9; padding: 2px 5px; border-radius: 4px; color: #0f172a; }
.unai3-msg-ai .unai3-msg-bubble pre      { background: #1e293b; padding: 12px; border-radius: 8px; overflow-x: auto; margin: 8px 0; }
.unai3-msg-ai .unai3-msg-bubble pre code { background: none; padding: 0; color: #e2e8f0; font-size: 13px; }
.unai3-msg-ai .unai3-msg-bubble a        { color: var(--unai3-accent); text-decoration: underline; }
.unai3-msg-ai .unai3-msg-bubble h1,
.unai3-msg-ai .unai3-msg-bubble h2,
.unai3-msg-ai .unai3-msg-bubble h3       { margin: 10px 0 4px; font-weight: 600; }

/* ---- Typing indicator ---- */
.unai3-typing {
  align-self: flex-start;
  align-items: flex-start;
  display: flex;
  flex-direction: column;
  margin-bottom: 6px;
}
.unai3-typing .unai3-msg-name {
  font-size: 11px;
  font-weight: 600;
  color: #94a3b8;
  margin-bottom: 4px;
  padding: 0 4px;
}
.unai3-typing-dots {
  padding: 12px 16px;
  border-radius: 18px 18px 18px 4px;
  border: 1px solid #e2e8f0;
  background: #fff;
  display: flex;
  align-items: center;
  gap: 5px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.unai3-typing-dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #94a3b8;
  display: inline-block;
  animation: unai3-bounce 1.3s infinite ease-in-out;
}
.unai3-typing-dots span:nth-child(2) { animation-delay: 0.18s; }
.unai3-typing-dots span:nth-child(3) { animation-delay: 0.36s; }
@keyframes unai3-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.35; }
  30%            { transform: translateY(-5px); opacity: 1; }
}

/* ---- Quick-reply buttons ---- */
.unai3-quick-replies {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 16px 4px;
  background: #f8fafc;
}
.unai3-qr-btn {
  font-size: 13px;
  padding: 7px 16px;
  border-radius: 20px;
  border: 1.5px solid var(--unai3-accent);
  color: var(--unai3-accent);
  background: #fff;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  font-family: inherit;
  font-weight: 500;
}
.unai3-qr-btn:hover {
  background: var(--unai3-accent);
  color: #fff;
}

/* ---- Input area ---- */
.unai3-form {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 12px 14px;
  background: #fff;
  border-top: 1px solid #e2e8f0;
}
.unai3-form textarea {
  flex: 1;
  resize: none;
  border: 1.5px solid #e2e8f0;
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 14px;
  line-height: 1.5;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  font-family: inherit;
  min-height: 44px;
  max-height: 120px;
  box-sizing: border-box;
  background: #f8fafc;
  color: #1e293b;
}
.unai3-form textarea::placeholder { color: #94a3b8; }
.unai3-form textarea:focus {
  border-color: var(--unai3-accent);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(37,99,235,0.12);
}
.unai3-send-btn {
  flex-shrink: 0;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: var(--unai3-accent);
  color: #fff;
  border: none;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}
.unai3-send-btn::after { content: '\279C'; }
.unai3-send-btn:hover  { opacity: 0.88; }
.unai3-send-btn:active { transform: scale(0.94); }
.unai3-send-btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

/* ---- Floating bubble mode ---- */
.unai3-float-trigger {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: var(--unai3-accent);
  color: #fff;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(0,0,0,0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9998;
  transition: transform 0.15s, box-shadow 0.15s;
}
.unai3-float-trigger:hover {
  transform: scale(1.06);
  box-shadow: 0 6px 28px rgba(0,0,0,0.25);
}
.unai3-float-trigger svg { width: 26px; height: 26px; fill: #fff; }

.unai3-float-panel {
  position: fixed;
  bottom: 96px;
  right: 24px;
  width: 370px;
  max-height: 580px;
  border-radius: 20px;
  box-shadow: 0 12px 48px rgba(0,0,0,0.18);
  z-index: 9999;
  display: none;
  flex-direction: column;
  overflow: hidden;
  background: #fff;
  border: 1px solid #e2e8f0;
}
.unai3-float-panel.is-open { display: flex; }
.unai3-float-panel .unai3-messages { flex: 1; max-height: none; }

.unai3-float-close {
  position: absolute;
  top: 12px;
  right: 14px;
  background: rgba(255,255,255,0.2);
  border: none;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  font-size: 14px;
  cursor: pointer;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.unai3-float-close:hover { background: rgba(255,255,255,0.35); }

@media (max-width: 480px) {
  .unai3-float-panel {
    right: 0; bottom: 0; left: 0; width: 100%;
    max-height: 85vh;
    border-radius: 20px 20px 0 0;
  }
  .unai3-float-trigger { bottom: 16px; right: 16px; }
}
