/* ═══════════════════════════════════════════════════════════════════════════
   RaaS Operations Guide — AI Chat Widget v2
   Polished, professional design matching Rhapsody Blue palette
   ═══════════════════════════════════════════════════════════════════════════ */

/* ─── CSS variables (scoped to avoid conflicts) ──────────────────────────── */
:root {
  --chat-blue:       #1A81F4;
  --chat-blue-dark:  #1268c7;
  --chat-blue-xdark: #0d4f9e;
  --chat-bg:         #ffffff;
  --chat-surface:    #f7f9fc;
  --chat-border:     #e2e8f0;
  --chat-text:       #0f172a;
  --chat-muted:      #64748b;
  --chat-user-bg:    #1A81F4;
  --chat-user-text:  #ffffff;
  --chat-ai-bg:      #f1f5ff;
  --chat-ai-border:  #dbeafe;
  --chat-error-bg:   #fef2f2;
  --chat-error-text: #991b1b;
  --chat-error-bdr:  #fecaca;
  --chat-radius:     14px;
  --chat-shadow:     0 20px 60px -10px rgba(15, 23, 42, 0.18), 0 4px 16px -4px rgba(15, 23, 42, 0.12);
}

/* ── FAB (floating action button) ────────────────────────────────────────── */
#raas-chat-fab {
  position: fixed;
  bottom: 1.75rem;
  right: 1.75rem;
  z-index: 9999;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: var(--chat-blue);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(26, 129, 244, 0.45), 0 2px 8px rgba(26, 129, 244, 0.2);
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1),
              box-shadow 0.2s ease,
              background 0.2s ease;
}

#raas-chat-fab:hover {
  background: var(--chat-blue-dark);
  transform: translateY(-2px) scale(1.05);
  box-shadow: 0 8px 28px rgba(26, 129, 244, 0.5), 0 4px 12px rgba(26, 129, 244, 0.3);
}

#raas-chat-fab:active {
  transform: scale(0.96);
}

#raas-chat-fab svg {
  width: 24px;
  height: 24px;
  flex-shrink: 0;
}

.fab-icon-close { display: none; }
#raas-chat-fab.open .fab-icon-open  { display: none; }
#raas-chat-fab.open .fab-icon-close { display: block; }

/* Pulse ring on first load (draws attention once) */
#raas-chat-fab::before {
  content: "";
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid rgba(26, 129, 244, 0.35);
  animation: raas-pulse-ring 2.5s ease-out 1.5s 3;
  pointer-events: none;
}

@keyframes raas-pulse-ring {
  0%   { transform: scale(1); opacity: 0.7; }
  100% { transform: scale(1.55); opacity: 0; }
}

/* ── Panel ────────────────────────────────────────────────────────────────── */
#raas-chat-panel {
  position: fixed;
  bottom: 5.5rem;
  right: 1.75rem;
  z-index: 9998;
  width: 360px;
  max-width: calc(100vw - 2rem);
  height: 460px;
  max-height: calc(100vh - 7rem);
  background: var(--chat-bg);
  border-radius: var(--chat-radius);
  box-shadow: var(--chat-shadow);
  border: 1px solid var(--chat-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;

  /* Hidden state */
  transform: translateY(16px) scale(0.97);
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
  transition: transform 0.25s cubic-bezier(0.32, 0.72, 0, 1),
              opacity 0.25s ease,
              visibility 0s linear 0.25s;
}

#raas-chat-panel.open {
  transform: translateY(0) scale(1);
  opacity: 1;
  pointer-events: all;
  visibility: visible;
  transition: transform 0.25s cubic-bezier(0.32, 0.72, 0, 1),
              opacity 0.25s ease,
              visibility 0s linear 0s;
}

/* ── Header ───────────────────────────────────────────────────────────────── */
#raas-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.1rem;
  background: linear-gradient(135deg, var(--chat-blue) 0%, var(--chat-blue-xdark) 100%);
  flex-shrink: 0;
}

.chat-header-left {
  display: flex;
  align-items: center;
  gap: 0.7rem;
}

.chat-header-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: rgba(255,255,255,0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.chat-header-avatar svg {
  width: 20px;
  height: 20px;
  color: #fff;
}

.chat-header-title {
  color: #fff;
  font-family: "Poppins", sans-serif;
  font-weight: 600;
  font-size: 0.9rem;
  line-height: 1.2;
  letter-spacing: 0.01em;
}

.chat-header-status {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.72rem;
  color: rgba(255,255,255,0.75);
  font-family: "Inter", sans-serif;
  margin-top: 1px;
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #4ade80;
  box-shadow: 0 0 0 2px rgba(74, 222, 128, 0.3);
  display: inline-block;
}

#raas-chat-close {
  background: rgba(255,255,255,0.12);
  border: none;
  color: rgba(255,255,255,0.85);
  cursor: pointer;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
  flex-shrink: 0;
}

#raas-chat-close svg {
  width: 16px;
  height: 16px;
}

#raas-chat-close:hover {
  background: rgba(255,255,255,0.25);
  color: #fff;
}

/* ── Message area ─────────────────────────────────────────────────────────── */
#raas-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  scroll-behavior: smooth;
  background: var(--chat-surface);
}

#raas-chat-messages::-webkit-scrollbar {
  width: 4px;
}
#raas-chat-messages::-webkit-scrollbar-track {
  background: transparent;
}
#raas-chat-messages::-webkit-scrollbar-thumb {
  background: var(--chat-border);
  border-radius: 4px;
}

/* ── Messages ─────────────────────────────────────────────────────────────── */
.raas-msg {
  max-width: 85%;
  padding: 0.65rem 0.95rem;
  border-radius: 12px;
  font-family: "Inter", sans-serif;
  font-size: 0.875rem;
  line-height: 1.6;
  word-break: break-word;
}

.raas-msg.user {
  align-self: flex-end;
  background: var(--chat-user-bg);
  color: var(--chat-user-text);
  border-bottom-right-radius: 4px;
  box-shadow: 0 2px 8px rgba(26, 129, 244, 0.25);
}

.raas-msg.assistant {
  align-self: flex-start;
  background: var(--chat-bg);
  color: var(--chat-text);
  border: 1px solid var(--chat-ai-border);
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.06);
}

.raas-msg.assistant p { margin: 0 0 0.5em; }
.raas-msg.assistant p:last-child { margin-bottom: 0; }
.raas-msg.assistant ul, .raas-msg.assistant ol {
  margin: 0.35em 0 0.5em;
  padding-left: 1.4em;
}
.raas-msg.assistant li { margin-bottom: 0.2em; }
.raas-msg.assistant strong { color: var(--chat-blue-dark); }
.raas-msg.assistant code {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.82em;
  background: #eef2ff;
  color: #3730a3;
  padding: 0.15em 0.4em;
  border-radius: 4px;
  border: 1px solid #c7d2fe;
}

/* Code blocks in assistant messages */
.raas-code-block {
  position: relative;
  background: #0f172a;
  border-radius: 8px;
  margin: 0.6em 0;
  overflow: hidden;
}

.raas-code-lang {
  display: block;
  padding: 0.4em 0.8em;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.72em;
  color: #64748b;
  background: #1e293b;
  border-bottom: 1px solid #334155;
  letter-spacing: 0.05em;
}

.raas-code-block pre {
  margin: 0;
  padding: 0.85em 1em;
  overflow-x: auto;
}

.raas-code-block code {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.82em;
  color: #e2e8f0;
  background: transparent;
  border: none;
  padding: 0;
  white-space: pre;
}

.raas-copy-btn {
  position: absolute;
  top: 0.35rem;
  right: 0.5rem;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.12);
  color: rgba(255,255,255,0.6);
  font-size: 0.7rem;
  padding: 0.2rem 0.55rem;
  border-radius: 4px;
  cursor: pointer;
  font-family: "Inter", sans-serif;
  transition: background 0.15s, color 0.15s;
}

.raas-copy-btn:hover {
  background: rgba(255,255,255,0.18);
  color: #fff;
}

.raas-msg.error {
  align-self: flex-start;
  background: var(--chat-error-bg);
  color: var(--chat-error-text);
  border: 1px solid var(--chat-error-bdr);
  border-bottom-left-radius: 4px;
  font-size: 0.84rem;
}

/* ── Typing indicator ─────────────────────────────────────────────────────── */
.raas-typing {
  align-self: flex-start;
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.55rem 0.85rem;
  background: var(--chat-bg);
  border: 1px solid var(--chat-ai-border);
  border-radius: 12px;
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.06);
}

.raas-typing-avatar {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--chat-ai-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.raas-typing-avatar svg {
  width: 13px;
  height: 13px;
  color: var(--chat-blue);
}

.raas-typing-dots {
  display: flex;
  align-items: center;
  gap: 4px;
}

.raas-typing-dots span {
  width: 7px;
  height: 7px;
  background: var(--chat-muted);
  border-radius: 50%;
  display: inline-block;
  animation: raas-bounce 1.3s infinite ease-in-out;
}

.raas-typing-dots span:nth-child(2) { animation-delay: 0.18s; }
.raas-typing-dots span:nth-child(3) { animation-delay: 0.36s; }

@keyframes raas-bounce {
  0%, 80%, 100% { transform: translateY(0);     opacity: 0.4; }
  40%           { transform: translateY(-5px);  opacity: 1;   }
}

/* ── Welcome message ──────────────────────────────────────────────────────── */
.raas-welcome {
  align-self: stretch;
  background: var(--chat-bg);
  border: 1px solid var(--chat-ai-border);
  border-radius: 12px;
  padding: 0.9rem 1.05rem;
  font-size: 0.875rem;
  color: var(--chat-text);
  line-height: 1.6;
}

.raas-welcome p {
  margin: 0 0 0.75rem;
  color: var(--chat-muted);
}

.raas-welcome strong {
  color: var(--chat-blue);
  font-weight: 600;
}

/* ── Suggestion chips ─────────────────────────────────────────────────────── */
.raas-chips {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.raas-chip {
  background: var(--chat-surface);
  border: 1px solid var(--chat-border);
  color: var(--chat-text);
  border-radius: 8px;
  padding: 0.45rem 0.8rem;
  font-size: 0.82rem;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.1s;
  font-family: "Inter", sans-serif;
  line-height: 1.4;
}

.raas-chip:hover {
  background: #eef6ff;
  border-color: var(--chat-blue);
  color: var(--chat-blue-dark);
  transform: translateX(3px);
}

/* ── Footer / input row ───────────────────────────────────────────────────── */
#raas-chat-footer {
  display: flex;
  align-items: flex-end;
  gap: 0;
  padding: 0.75rem;
  border-top: 1px solid var(--chat-border);
  background: var(--chat-bg);
  flex-shrink: 0;
}

#raas-chat-input {
  flex: 1;
  resize: none;
  border: 1.5px solid var(--chat-border);
  border-radius: 10px;
  padding: 0.6rem 0.85rem;
  font-family: "Inter", sans-serif;
  font-size: 0.875rem;
  line-height: 1.5;
  color: var(--chat-text);
  background: var(--chat-surface);
  max-height: 120px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
  margin-right: 0.5rem;
}

#raas-chat-input::placeholder {
  color: var(--chat-muted);
  opacity: 0.7;
}

#raas-chat-input:focus {
  border-color: var(--chat-blue);
  box-shadow: 0 0 0 3px rgba(26, 129, 244, 0.1);
  background: #fff;
}

#raas-chat-input:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.raas-footer-actions {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-shrink: 0;
}

#raas-chat-clear {
  width: 34px;
  height: 34px;
  background: none;
  border: 1.5px solid var(--chat-border);
  border-radius: 8px;
  color: var(--chat-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
  flex-shrink: 0;
}

#raas-chat-clear svg {
  width: 15px;
  height: 15px;
}

#raas-chat-clear:hover {
  border-color: #fca5a5;
  color: #dc2626;
  background: #fef2f2;
}

#raas-chat-send {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: var(--chat-blue);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.1s, box-shadow 0.15s, opacity 0.2s;
  box-shadow: 0 2px 6px rgba(26, 129, 244, 0.3);
}

#raas-chat-send svg {
  width: 17px;
  height: 17px;
  margin-left: 1px;
}

#raas-chat-send:not(:disabled):hover {
  background: var(--chat-blue-dark);
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(26, 129, 244, 0.4);
}

#raas-chat-send:not(:disabled):active {
  transform: scale(0.93);
}

#raas-chat-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  box-shadow: none;
}

/* Spinner while loading */
#raas-chat-send.loading svg {
  animation: raas-spin 0.8s linear infinite;
  opacity: 0.7;
}

@keyframes raas-spin {
  to { transform: rotate(360deg); }
}

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  #raas-chat-panel {
    right: 0;
    left: 0;
    bottom: 0;
    width: 100%;
    max-width: 100%;
    height: 70vh;
    max-height: 70vh;
    border-radius: var(--chat-radius) var(--chat-radius) 0 0;
  }
  #raas-chat-fab {
    right: 1rem;
    bottom: 1rem;
  }
}
