/* Chat Widget — Advantageous Assessment Agent */

.chat-fab {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 9000;
  width: 56px;
  height: 56px;
  border: none;
  border-radius: 50%;
  background: var(--color-primary, #298b67);
  color: #fff;
  font-size: 1.5rem;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}
.chat-fab:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
}
.chat-fab:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}
.chat-fab[aria-expanded="true"] {
  display: none;
}

.chat-fab-icon {
  width: 24px;
  height: 24px;
  fill: currentColor;
}

/* Panel */
.chat-panel {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 9001;
  width: 400px;
  max-width: calc(100vw - 2rem);
  height: 560px;
  max-height: calc(100vh - 3rem);
  background: #1e1e1e;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  display: none;
  flex-direction: column;
  overflow: hidden;
  font-family: var(--font-sans, 'Roboto', sans-serif);
}
.chat-panel.open {
  display: flex;
}

/* Header */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  background: var(--color-primary, #298b67);
  color: #fff;
  flex-shrink: 0;
}
.chat-header-title {
  font-size: 0.9rem;
  font-weight: 700;
  margin: 0;
}
.chat-header-subtitle {
  font-size: 0.75rem;
  opacity: 0.85;
  margin: 0;
}
.chat-close {
  background: none;
  border: none;
  color: #fff;
  font-size: 1.25rem;
  cursor: pointer;
  padding: 0.25rem;
  line-height: 1;
  border-radius: 4px;
}
.chat-close:hover {
  background: rgba(255, 255, 255, 0.15);
}
.chat-close:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

/* Messages area */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.chat-messages::-webkit-scrollbar {
  width: 6px;
}
.chat-messages::-webkit-scrollbar-track {
  background: transparent;
}
.chat-messages::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 3px;
}

/* Message bubbles */
.chat-msg {
  max-width: 85%;
  padding: 0.625rem 0.875rem;
  border-radius: 12px;
  font-size: 0.875rem;
  line-height: 1.5;
  word-wrap: break-word;
  white-space: pre-wrap;
}
.chat-msg a {
  color: inherit;
  text-decoration: underline;
}
.chat-msg-assistant {
  align-self: flex-start;
  background: #2a2a2a;
  color: #e0e0e0;
  border-bottom-left-radius: 4px;
}
.chat-msg-user {
  align-self: flex-end;
  background: var(--color-primary, #298b67);
  color: #fff;
  border-bottom-right-radius: 4px;
}

/* Typing indicator */
.chat-typing {
  align-self: flex-start;
  display: none;
  gap: 4px;
  padding: 0.75rem 1rem;
  background: #2a2a2a;
  border-radius: 12px;
  border-bottom-left-radius: 4px;
}
.chat-typing.visible {
  display: flex;
}
.chat-typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.4);
  animation: chatTypingBounce 1.2s ease-in-out infinite;
}
.chat-typing-dot:nth-child(2) { animation-delay: 0.15s; }
.chat-typing-dot:nth-child(3) { animation-delay: 0.3s; }
@keyframes chatTypingBounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-4px); }
}

/* Input area */
.chat-input-area {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem;
  border-top: 1px solid #333;
  flex-shrink: 0;
}
.chat-input {
  flex: 1;
  padding: 0.5rem 0.75rem;
  border: 1px solid #444;
  border-radius: 8px;
  background: #2a2a2a;
  color: #e0e0e0;
  font-size: 0.875rem;
  font-family: inherit;
  outline: none;
  resize: none;
  min-height: 38px;
  max-height: 80px;
}
.chat-input::placeholder {
  color: rgba(255, 255, 255, 0.35);
}
.chat-input:focus {
  border-color: var(--color-primary, #298b67);
}
.chat-send {
  width: 38px;
  height: 38px;
  border: none;
  border-radius: 8px;
  background: var(--color-primary, #298b67);
  color: #fff;
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.15s;
}
.chat-send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.chat-send:not(:disabled):hover {
  filter: brightness(1.1);
}
.chat-send:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}
.chat-send-icon {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

/* Completion state */
.chat-complete {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  padding: 1rem;
  border-top: 1px solid #333;
  text-align: center;
  flex-shrink: 0;
}
.chat-complete.visible {
  display: flex;
}
.chat-complete p {
  margin: 0;
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.6);
}
.chat-complete a {
  color: var(--color-primary, #298b67);
  font-weight: 600;
  text-decoration: none;
}
.chat-complete a:hover {
  text-decoration: underline;
}

/* Mobile: full-screen panel */
@media (max-width: 640px) {
  .chat-panel {
    inset: 0;
    width: 100%;
    max-width: 100%;
    height: 100%;
    max-height: 100vh;
    max-height: 100dvh;
    border-radius: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .chat-typing-dot { animation: none; opacity: 0.6; }
  .chat-fab { transition: none; }
}
