/* WP RAG Chat – Frontend Widget Styles */

.wprc-chat {
  --bg: #0d1117;
  --surface: #161b22;
  --surface2: #21262d;
  --border: #30363d;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #a78bfa;
  --accent2: #60a5fa;
  --green: #3fb950;
  --red: #f85149;
  --user-bubble: linear-gradient(135deg, #7c3aed, #2563eb);
  --bot-bubble: #1c2128;
  --radius: 18px;

  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  border-radius: 16px;
  border: 1px solid var(--border);
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  position: relative;
  min-height: 400px;
}

/* Light theme override */
.wprc-chat.light {
  --bg: #ffffff;
  --surface: #f6f8fa;
  --surface2: #eaecef;
  --border: #d0d7de;
  --text: #1f2328;
  --muted: #656d76;
  --bot-bubble: #f6f8fa;
  --user-bubble: linear-gradient(135deg, #7c3aed, #2563eb);
}

/* ── Header ── */
.wprc-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

.wprc-logo {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.wprc-logo-icon {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: linear-gradient(135deg, #7c3aed, #2563eb);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
}

.wprc-logo strong { display: block; font-size: 0.95rem; }
.wprc-logo small  { display: block; font-size: 0.72rem; color: var(--muted); }

.wprc-header-right { display: flex; align-items: center; gap: 0.6rem; }

.wprc-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 6px var(--green);
  animation: wprc-pulse 2s infinite;
}

@keyframes wprc-pulse { 0%,100%{opacity:1} 50%{opacity:.4} }

.wprc-btn-reset {
  padding: 0.3rem 0.7rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.2s;
}
.wprc-btn-reset:hover { border-color: var(--accent); color: var(--accent); }

/* ── Terminated banner ── */
.wprc-terminated {
  background: linear-gradient(135deg,#2d0a0a,#1a0000);
  border-bottom: 1px solid #f8514960;
  padding: 0.85rem 1rem;
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  font-size: 0.85rem;
  flex-shrink: 0;
}

.wprc-terminated-icon { font-size: 1.4rem; flex-shrink: 0; }
.wprc-terminated strong { color: var(--red); display: block; }
.wprc-terminated p { color: var(--muted); margin: 0.25rem 0 0; }

.wprc-btn-reset-inline {
  background: none;
  border: 1px solid var(--red);
  color: var(--red);
  padding: 0.2rem 0.6rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.78rem;
  margin-top: 0.4rem;
}
.wprc-btn-reset-inline:hover { background: var(--red); color: #fff; }

/* ── Messages ── */
.wprc-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  scroll-behavior: smooth;
}

.wprc-messages::-webkit-scrollbar { width: 4px; }
.wprc-messages::-webkit-scrollbar-track { background: transparent; }
.wprc-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* Empty state */
.wprc-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--muted);
  gap: 0.5rem;
  padding: 2rem;
}

.wprc-empty-icon { font-size: 2.5rem; opacity: 0.4; }
.wprc-empty p { font-size: 0.88rem; }

/* Message rows */
.wprc-msg {
  display: flex;
  gap: 0.65rem;
  animation: wprc-fadeup 0.25s ease;
}

@keyframes wprc-fadeup { from{opacity:0;transform:translateY(6px)} to{opacity:1;transform:none} }

.wprc-msg.user { flex-direction: row-reverse; }

.wprc-avatar {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
}

.wprc-msg.user .wprc-avatar { background: var(--user-bubble); }
.wprc-msg.bot  .wprc-avatar { background: var(--surface2); border: 1px solid var(--border); }

.wprc-bubble {
  max-width: 78%;
  padding: 0.7rem 1rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
  word-break: break-word;
  line-height: 1.6;
}

.wprc-msg.user .wprc-bubble {
  background: var(--user-bubble);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.wprc-msg.bot .wprc-bubble {
  background: var(--bot-bubble);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
  color: var(--text);
}

.wprc-bubble p { margin: 0.3rem 0; }
.wprc-bubble p:first-child { margin-top: 0; }
.wprc-bubble p:last-child  { margin-bottom: 0; }

/* Badges */
.wprc-badges { display: flex; gap: 0.35rem; flex-wrap: wrap; margin-top: 0.45rem; }

.wprc-badge {
  font-size: 0.67rem;
  padding: 0.12rem 0.5rem;
  border-radius: 6px;
  font-weight: 600;
}

.wprc-badge.cached  { background: #1e2d1e; color: var(--green); border: 1px solid #2d4a2d; }
.wprc-badge.live    { background: #1a1f2e; color: var(--accent2); border: 1px solid #1e3a5f; }

/* Sources */
.wprc-sources-toggle {
  font-size: 0.72rem;
  color: var(--muted);
  cursor: pointer;
  margin-top: 0.5rem;
  background: none;
  border: none;
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0;
}
.wprc-sources-toggle:hover { color: var(--accent); }

.wprc-sources-list { display: none; margin-top: 0.45rem; border-left: 2px solid var(--border); padding-left: 0.75rem; }
.wprc-sources-list.open { display: block; }

.wprc-source-item { font-size: 0.75rem; color: var(--muted); padding: 0.25rem 0; border-bottom: 1px solid var(--border); }
.wprc-source-item:last-child { border-bottom: none; }
.wprc-source-item a { color: var(--accent2); text-decoration: none; }
.wprc-source-item a:hover { text-decoration: underline; }
.wprc-source-score { color: var(--accent); font-weight: 700; margin-right: 0.3rem; }

/* Typing indicator */
.wprc-typing .wprc-bubble { padding: 0.65rem 0.9rem; }

.wprc-dots { display: flex; gap: 0.35rem; align-items: center; height: 18px; }
.wprc-dot  { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: wprc-bounce 0.9s infinite; }
.wprc-dot:nth-child(2) { animation-delay: 0.15s; }
.wprc-dot:nth-child(3) { animation-delay: 0.30s; }

@keyframes wprc-bounce { 0%,60%,100%{transform:translateY(0)} 30%{transform:translateY(-6px)} }

/* ── Input area ── */
.wprc-input-wrap { flex-shrink: 0; padding: 0.75rem; border-top: 1px solid var(--border); background: var(--surface); }

.wprc-input-row {
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0.5rem 0.5rem 0.5rem 0.85rem;
  transition: border-color 0.2s;
}
.wprc-input-row:focus-within { border-color: var(--accent); }

.wprc-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: #ffffff;
  font-size: 0.92rem;
  font-family: inherit;
  resize: none;
  max-height: 200px;
  min-height: 24px;
  line-height: 1.5;
}
.wprc-input::placeholder { color: var(--muted); }

.wprc-send-btn {
  width: 36px;
  height: 36px;
  border-radius: 9px;
  border: none;
  background: linear-gradient(135deg, #7c3aed, #2563eb);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 1rem;
  transition: opacity 0.2s;
}
.wprc-send-btn:hover    { opacity: 0.88; }
.wprc-send-btn:disabled { opacity: 0.35; cursor: not-allowed; }

.wprc-hint { font-size: 0.7rem; color: var(--muted); text-align: center; margin-top: 0.4rem; }
.wprc-hint kbd {
  background: var(--surface2);
  border: 1px solid var(--border);
  padding: 0.05rem 0.35rem;
  border-radius: 4px;
  font-size: 0.67rem;
}

/* Locked state */
.wprc-locked .wprc-input-row { opacity: 0.4; pointer-events: none; filter: saturate(0); }
