/* ── Chat Widget ─────────────────────────────────────────── */

/* Trigger button */
#chat-trigger {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: #2B5C8A;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  z-index: 9000;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
#chat-trigger:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.2);
}
#chat-trigger svg {
  width: 24px;
  height: 24px;
  fill: white;
}

/* Chat panel */
#chat-panel {
  position: fixed;
  bottom: 92px;
  right: 24px;
  width: 380px;
  max-height: 520px;
  background: #ffffff;
  border: 1px solid #D5CFCA;
  border-radius: 12px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.12);
  display: flex;
  flex-direction: column;
  z-index: 9000;
  overflow: hidden;
  transform: translateY(16px);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.25s ease, opacity 0.25s ease;
}
#chat-panel.open {
  transform: translateY(0);
  opacity: 1;
  pointer-events: all;
}

/* Header */
#chat-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid #D5CFCA;
  background: #FAF8F5;
  flex-shrink: 0;
}
#chat-header-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  border: 1.5px solid #D5CFCA;
}
#chat-header-label {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
#chat-header-name {
  font-family: 'DM Sans', -apple-system, sans-serif;
  font-size: 14px;
  font-weight: 600;
  color: #2A2520;
  line-height: 1.3;
}
#chat-header-status {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  color: #6B6560;
  letter-spacing: 0.5px;
}
#chat-close {
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  color: #6B6560;
  display: flex;
  align-items: center;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
}
#chat-close:hover {
  color: #2A2520;
  background: #F5F1EB;
}
#chat-close svg {
  width: 16px;
  height: 16px;
}

/* Messages */
#chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  scroll-behavior: smooth;
}
#chat-messages::-webkit-scrollbar {
  width: 4px;
}
#chat-messages::-webkit-scrollbar-track {
  background: transparent;
}
#chat-messages::-webkit-scrollbar-thumb {
  background: #D5CFCA;
  border-radius: 2px;
}

/* Message bubbles */
.chat-msg {
  display: flex;
  flex-direction: column;
  max-width: 86%;
}
.chat-msg.user {
  align-self: flex-end;
  align-items: flex-end;
}
.chat-msg.assistant,
.chat-msg.human {
  align-self: flex-start;
  align-items: flex-start;
}

.chat-bubble {
  padding: 9px 13px;
  font-family: 'DM Sans', -apple-system, sans-serif;
  font-size: 14px;
  line-height: 1.55;
  color: #2A2520;
  word-break: break-word;
}
.chat-msg.user .chat-bubble {
  background: #D6E4F0;
  border-radius: 12px 12px 2px 12px;
}
.chat-msg.assistant .chat-bubble {
  background: #F5F1EB;
  border-radius: 12px 12px 12px 2px;
}
.chat-msg.human .chat-bubble {
  background: #EFF8F0;
  border-radius: 12px 12px 12px 2px;
}

.chat-msg-sender {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  color: #6B6560;
  letter-spacing: 0.5px;
  margin-bottom: 3px;
  text-transform: uppercase;
}

/* Notice messages (centered) */
.chat-notice {
  align-self: center;
  text-align: center;
  max-width: 92%;
}
.chat-notice-escalation {
  background: #F5F1EB;
  border: 1px solid #D5CFCA;
  border-radius: 8px;
  padding: 12px 16px;
  font-family: 'DM Sans', -apple-system, sans-serif;
  font-size: 13px;
  color: #6B6560;
  line-height: 1.5;
}
.chat-notice-escalation strong {
  display: block;
  color: #2A2520;
  font-weight: 600;
  margin-bottom: 4px;
}
.chat-notice-offtopic {
  font-family: 'DM Sans', -apple-system, sans-serif;
  font-size: 12px;
  color: #6B6560;
  font-style: italic;
  padding: 4px 0;
}
.chat-notice-system {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: #6B6560;
  padding: 4px 0;
}

/* Typing indicator */
.chat-typing {
  align-self: flex-start;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 13px;
  background: #F5F1EB;
  border-radius: 12px 12px 12px 2px;
}
.chat-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #6B6560;
  animation: chat-dot-bounce 1.2s infinite;
}
.chat-typing span:nth-child(2) { animation-delay: 0.2s; }
.chat-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes chat-dot-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* Turn counter */
#chat-turn-counter {
  text-align: center;
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  color: #6B6560;
  padding: 4px 16px 0;
  letter-spacing: 0.3px;
  flex-shrink: 0;
}

/* Input area */
#chat-input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 12px 12px 16px;
  border-top: 1px solid #D5CFCA;
  background: #FAF8F5;
  flex-shrink: 0;
}
#chat-input {
  flex: 1;
  border: 1px solid #D5CFCA;
  border-radius: 8px;
  padding: 9px 12px;
  font-family: 'DM Sans', -apple-system, sans-serif;
  font-size: 14px;
  color: #2A2520;
  background: #ffffff;
  resize: none;
  outline: none;
  line-height: 1.4;
  max-height: 100px;
  overflow-y: auto;
  transition: border-color 0.15s;
}
#chat-input:focus {
  border-color: #2B5C8A;
}
#chat-input::placeholder {
  color: #6B6560;
}
#chat-input:disabled {
  background: #F5F1EB;
  color: #6B6560;
  cursor: not-allowed;
}
#chat-send {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: #2B5C8A;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.1s;
}
#chat-send:hover:not(:disabled) {
  background: #234b73;
}
#chat-send:active:not(:disabled) {
  transform: scale(0.95);
}
#chat-send:disabled {
  background: #D5CFCA;
  cursor: not-allowed;
}
#chat-send svg {
  width: 16px;
  height: 16px;
  fill: white;
}

/* Conversation ended footer */
#chat-ended-footer {
  text-align: center;
  padding: 10px 16px 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  border-top: 1px solid #D5CFCA;
  background: #FAF8F5;
  flex-shrink: 0;
}
#chat-ended-label {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: #6B6560;
  letter-spacing: 0.3px;
}
#chat-new-conversation {
  font-family: 'DM Sans', -apple-system, sans-serif;
  font-size: 13px;
  color: #2B5C8A;
  background: none;
  border: 1px solid #2B5C8A;
  border-radius: 6px;
  padding: 5px 14px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
#chat-new-conversation:hover {
  background: #2B5C8A;
  color: #ffffff;
}

/* Check for reply bar */
#chat-check-reply {
  text-align: center;
  padding: 2px 16px 6px;
  flex-shrink: 0;
}
#chat-check-reply-btn {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  color: #6B6560;
  background: none;
  border: none;
  cursor: pointer;
  letter-spacing: 0.3px;
  padding: 3px 10px;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
}
#chat-check-reply-btn:hover {
  color: #2A2520;
  background: #F5F1EB;
}

/* Push permission prompt */
.chat-push-prompt {
  align-self: center;
  width: 92%;
  background: #EFF8F0;
  border: 1px solid #B8DFC0;
  border-radius: 8px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.chat-push-prompt-text {
  font-family: 'DM Sans', -apple-system, sans-serif;
  font-size: 13px;
  color: #2A2520;
  line-height: 1.4;
}
.chat-push-prompt-confirmed {
  font-family: 'DM Sans', -apple-system, sans-serif;
  font-size: 13px;
  color: #3a7a4a;
  line-height: 1.4;
}
.chat-push-prompt-buttons {
  display: flex;
  gap: 8px;
}
.chat-push-prompt-buttons button {
  font-family: 'DM Sans', -apple-system, sans-serif;
  font-size: 12px;
  border-radius: 6px;
  padding: 5px 12px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
#chat-push-yes {
  background: #2B5C8A;
  color: #ffffff;
  border: 1px solid #2B5C8A;
}
#chat-push-yes:hover {
  background: #234b73;
  border-color: #234b73;
}
#chat-push-no {
  background: none;
  color: #6B6560;
  border: 1px solid #D5CFCA;
}
#chat-push-no:hover {
  background: #F5F1EB;
  color: #2A2520;
}

/* Mobile responsive */
@media (max-width: 500px) {
  #chat-panel {
    left: 0;
    right: 0;
    bottom: 0;
    top: 60px;
    width: 100%;
    max-height: none;
    border-radius: 0;
    border-left: none;
    border-right: none;
    border-bottom: none;
  }
  #chat-trigger {
    bottom: 16px;
    right: 16px;
  }
}
