/* ==========================================================================
   Outreach — Chat Panel Styles
   Terracotta warm palette
   ========================================================================== */

/* ===== Chat Toggle Button ===== */
#chat-toggle {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: var(--terracotta);
  color: white;
  border: none;
  cursor: pointer;
  z-index: 850;
  box-shadow: 0 4px 16px rgba(181, 114, 90, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.25s, transform 0.25s, box-shadow 0.25s;
}

#chat-toggle:hover {
  background: var(--terracotta-hover);
  transform: scale(1.06) translateY(-1px);
  box-shadow: 0 6px 20px rgba(181, 114, 90, 0.4);
}

#chat-toggle:active {
  transform: scale(0.97);
}

#chat-toggle svg {
  width: 22px;
  height: 22px;
}

/* ===== Chat Panel ===== */
#chat-panel {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 400px;
  height: 520px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  z-index: 850;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: opacity 0.25s, transform 0.25s;
  border: 1px solid var(--border-light);
}

#chat-panel.chat-closed {
  display: none;
}

#chat-panel.chat-open {
  display: flex;
}

/* ===== Chat Header ===== */
.chat-header {
  background: var(--brown-deep);
  color: white;
  padding: 15px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.chat-header span {
  font-family: var(--font-heading);
  font-size: 0.88rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}

#chat-minimize {
  background: none;
  border: none;
  color: white;
  font-size: 1.4rem;
  cursor: pointer;
  opacity: 0.7;
  transition: opacity 0.2s;
  line-height: 1;
  padding: 0 4px;
}

#chat-minimize:hover {
  opacity: 1;
}

/* ===== Chat Messages Area ===== */
#chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: var(--bg);
}

#chat-messages::-webkit-scrollbar {
  width: 5px;
}

#chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

#chat-messages::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

/* ===== Message Bubbles ===== */
.chat-msg {
  max-width: 85%;
  padding: 11px 15px;
  border-radius: 14px;
  font-size: 0.84rem;
  line-height: 1.55;
  word-wrap: break-word;
  font-family: var(--font-sans);
}

.chat-msg.user {
  align-self: flex-end;
  background: var(--terracotta);
  color: white;
  border-bottom-right-radius: 4px;
  max-width: 80%;
}

.chat-msg.assistant {
  align-self: flex-start;
  background: var(--surface);
  color: var(--text-body);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.chat-msg.assistant p {
  margin: 0 0 8px 0;
}

.chat-msg.assistant p:last-child {
  margin-bottom: 0;
}

.chat-msg.assistant strong {
  color: var(--brown-deep);
  font-weight: 600;
}

.chat-msg.assistant h3,
.chat-msg.assistant h4,
.chat-msg.assistant h5,
.chat-msg.assistant h6 {
  font-family: var(--font-heading);
  color: var(--brown-deep);
  font-weight: 600;
  margin: 10px 0 4px 0;
  line-height: 1.3;
}

.chat-msg.assistant h3 { font-size: 0.92rem; }
.chat-msg.assistant h4 { font-size: 0.86rem; }
.chat-msg.assistant h5,
.chat-msg.assistant h6 { font-size: 0.82rem; }

.chat-msg.assistant h3:first-child,
.chat-msg.assistant h4:first-child {
  margin-top: 0;
}

.chat-msg.assistant ul,
.chat-msg.assistant ol {
  margin: 4px 0 8px 16px;
  padding: 0;
}

.chat-msg.assistant ol {
  list-style: decimal;
}

.chat-msg.assistant li {
  margin-bottom: 4px;
}

.chat-msg.assistant code {
  background: rgba(181, 114, 90, 0.08);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 0.8rem;
  color: var(--brown-deep);
}

/* ===== Entity Links ===== */
.chat-link {
  color: var(--terracotta);
  text-decoration: underline;
  text-decoration-style: dotted;
  text-underline-offset: 2px;
  cursor: pointer;
  font-weight: 500;
  transition: color 0.15s;
}

.chat-link:hover {
  color: var(--brown-deep);
  text-decoration-style: solid;
}

/* ===== Welcome Message ===== */
.chat-welcome {
  text-align: center;
  padding: 10px 0;
}

.chat-welcome h3 {
  font-family: var(--font-heading);
  font-size: 0.95rem;
  color: var(--brown-deep);
  margin-bottom: 6px;
  font-weight: 600;
}

.chat-welcome p {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 14px;
  line-height: 1.5;
}

/* ===== Suggestion Pills ===== */
.chat-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  justify-content: center;
}

.chat-suggestion {
  display: inline-block;
  padding: 7px 13px;
  border: 1px solid var(--terracotta);
  border-radius: 22px;
  font-size: 0.73rem;
  color: var(--terracotta);
  cursor: pointer;
  background: var(--surface);
  font-family: var(--font-sans);
  font-weight: 500;
  transition: all 0.2s ease;
}

.chat-suggestion:hover {
  background: var(--terracotta);
  color: white;
  box-shadow: 0 2px 8px rgba(181, 114, 90, 0.25);
}

/* ===== Typing Indicator ===== */
.typing-dots {
  display: inline-flex;
  gap: 5px;
  padding: 6px 0;
}

.typing-dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--terracotta);
  opacity: 0.35;
  animation: typingPulse 1.2s infinite;
}

.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingPulse {
  0%, 60%, 100% { opacity: 0.35; transform: scale(1); }
  30% { opacity: 1; transform: scale(1.2); }
}

/* ===== Input Bar ===== */
.chat-input-bar {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

#chat-input {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 14px;
  font-size: 0.84rem;
  font-family: var(--font-sans);
  color: var(--text-body);
  resize: none;
  outline: none;
  max-height: 72px;
  line-height: 1.45;
  transition: border-color 0.2s, box-shadow 0.2s;
  background: var(--surface);
}

#chat-input:focus {
  border-color: var(--terracotta);
  box-shadow: 0 0 0 3px var(--terracotta-light);
}

#chat-input::placeholder {
  color: var(--text-muted);
}

#chat-send {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--terracotta);
  color: white;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
  transition: background 0.2s, transform 0.15s, opacity 0.2s;
}

#chat-send:hover {
  background: var(--terracotta-hover);
  transform: scale(1.05);
}

#chat-send:active {
  transform: scale(0.95);
}

#chat-send:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

/* ===== Thinking Indicator ===== */
.thinking-indicator {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 2px 0;
  position: relative;
  overflow: hidden;
}

.thinking-shimmer {
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(181, 114, 90, 0.06) 40%,
    rgba(181, 114, 90, 0.10) 50%,
    rgba(181, 114, 90, 0.06) 60%,
    transparent 100%
  );
  animation: thinkingShimmer 2.4s ease-in-out infinite;
  border-radius: 14px;
  pointer-events: none;
}

@keyframes thinkingShimmer {
  0% { left: -100%; }
  100% { left: 100%; }
}

.thinking-phrase {
  font-size: 0.8rem;
  color: var(--text-muted, #9A8E85);
  font-style: italic;
  font-family: var(--font-sans);
  transition: opacity 0.25s ease;
  white-space: nowrap;
}

.thinking-phrase.thinking-fade {
  opacity: 0;
}

.thinking-dots {
  display: inline-flex;
  gap: 4px;
  flex-shrink: 0;
}

.thinking-dots span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--terracotta, #B5725A);
  opacity: 0.3;
  animation: thinkingDotPulse 1.4s infinite;
}

.thinking-dots span:nth-child(2) { animation-delay: 0.2s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes thinkingDotPulse {
  0%, 70%, 100% { opacity: 0.3; transform: scale(1); }
  35% { opacity: 0.9; transform: scale(1.3); }
}

/* Reveal animation when response arrives */
.chat-msg.assistant.thinking-reveal {
  animation: revealResponse 0.35s ease-out;
}

@keyframes revealResponse {
  from { opacity: 0.6; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ===== Error Message ===== */
.chat-error {
  color: #c0392b;
  font-size: 0.8rem;
  text-align: center;
  padding: 8px;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  #chat-panel {
    width: calc(100% - 16px);
    height: 60vh;
    bottom: 8px;
    right: 8px;
    border-radius: var(--radius);
  }

  #chat-toggle {
    bottom: 16px;
    right: 16px;
    width: 48px;
    height: 48px;
  }

  .chat-msg {
    max-width: 90%;
  }
}
