/* AI医学顾问 浮动聊天 Widget */

.chat-fab {
  position: fixed;
  bottom: 28px;
  left: 28px;
  z-index: 9999;
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  animation: chat-fab-in 0.4s ease-out;
}

.chat-fab-btn {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: transparent;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
  transition: transform 0.2s, box-shadow 0.2s;
  overflow: hidden;
  padding: 0;
}

.chat-fab-btn:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 28px rgba(79, 70, 229, 0.55);
}

.chat-fab-btn img {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  object-fit: cover;
}

.chat-fab-btn svg {
  width: 28px;
  height: 28px;
  fill: white;
}

.chat-fab-label {
  background: white;
  border-radius: 20px;
  padding: 8px 14px;
  font-size: 13px;
  color: #1f2937;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
  white-space: nowrap;
  font-weight: 500;
}

@keyframes chat-fab-in {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Panel */
.chat-panel {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 420px;
  height: 75vh;
  max-height: 680px;
  min-height: 400px;
  background: #ffffff;
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -4px 40px rgba(0, 0, 0, 0.15);
  z-index: 10000;
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform 0.35s cubic-bezier(0.32, 0.72, 0, 1);
  overflow: hidden;
}

.chat-panel.open {
  transform: translateY(0);
}

/* Panel header */
.chat-panel-header {
  display: flex;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid #f3f4f6;
  background: linear-gradient(135deg, #4f46e5, #7c3aed);
  color: white;
  flex-shrink: 0;
}

.chat-panel-header img {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  margin-right: 12px;
  border: 2px solid rgba(255,255,255,0.3);
  object-fit: cover;
}

.chat-panel-header svg {
  width: 36px;
  height: 36px;
  margin-right: 12px;
}

.chat-panel-title {
  flex: 1;
  font-size: 15px;
  font-weight: 600;
}

.chat-panel-subtitle {
  font-size: 11px;
  opacity: 0.8;
  margin-top: 2px;
}

.chat-panel-close {
  background: none;
  border: none;
  color: white;
  font-size: 22px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 8px;
  transition: background 0.15s;
}

.chat-panel-close:hover {
  background: rgba(255,255,255,0.2);
}

/* Messages area */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.6;
  word-break: break-word;
}

.chat-msg.user {
  align-self: flex-end;
  background: #4f46e5;
  color: white;
  border-bottom-right-radius: 4px;
}

.chat-msg.assistant {
  align-self: flex-start;
  background: #f3f4f6;
  color: #1f2937;
  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: #4f46e5; }
.chat-msg.assistant code { background: #e5e7eb; padding: 1px 5px; border-radius: 4px; font-size: 13px; }
.chat-msg.assistant a.chat-case-link {
  color: #4f46e5;
  font-weight: 700;
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-underline-offset: 2px;
  text-decoration-color: rgba(79, 70, 229, 0.4);
  cursor: pointer;
  transition: color 0.15s, text-decoration-color 0.15s;
}
.chat-msg.assistant a.chat-case-link:hover {
  color: #3730a3;
  text-decoration-color: #3730a3;
}
.chat-msg.assistant ul, .chat-msg.assistant ol { padding-left: 18px; margin: 4px 0; }

.chat-msg-status {
  align-self: center;
  font-size: 12px;
  color: #6b7280;
  padding: 4px 12px;
  background: #f9fafb;
  border-radius: 12px;
}

/* Contact card */
.chat-contact-card {
  align-self: flex-start;
  margin: 8px 0;
  animation: chat-fab-in 0.3s ease-out;
}

.chat-contact-inner {
  display: flex;
  align-items: center;
  gap: 12px;
  background: linear-gradient(135deg, #f0fdf4, #ecfdf5);
  border: 1px solid #bbf7d0;
  border-radius: 12px;
  padding: 12px 16px;
}

.chat-contact-inner img {
  width: 72px;
  height: 72px;
  border-radius: 8px;
  border: 1px solid #d1fae5;
}

.chat-contact-text {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.chat-contact-text strong {
  font-size: 13px;
  color: #166534;
}

.chat-contact-text span {
  font-size: 12px;
  color: #4b5563;
}

/* Typing indicator */
.chat-typing {
  display: flex;
  gap: 4px;
  padding: 10px 14px;
  align-self: flex-start;
}

.chat-typing span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #9ca3af;
  animation: chat-bounce 1.4s infinite ease-in-out;
}

.chat-typing span:nth-child(2) { animation-delay: 0.2s; }
.chat-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes chat-bounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* Input area */
.chat-input-area {
  display: flex;
  align-items: flex-end;
  padding: 12px 16px;
  border-top: 1px solid #f3f4f6;
  background: #fafafa;
  flex-shrink: 0;
}

.chat-input-area textarea {
  flex: 1;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 14px;
  line-height: 1.4;
  resize: none;
  max-height: 100px;
  min-height: 40px;
  outline: none;
  font-family: inherit;
  transition: border-color 0.15s;
}

.chat-input-area textarea:focus {
  border-color: #4f46e5;
}

.chat-input-area button {
  margin-left: 8px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: #4f46e5;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, transform 0.1s;
  flex-shrink: 0;
}

.chat-input-area button:hover { background: #4338ca; }
.chat-input-area button:active { transform: scale(0.92); }
.chat-input-area button:disabled { background: #d1d5db; cursor: not-allowed; }

.chat-input-area button.stop-mode {
  background: #ef4444;
  cursor: pointer;
}
.chat-input-area button.stop-mode:hover { background: #dc2626; }
.chat-input-area button.stop-mode svg { display: none; }
.chat-input-area button.stop-mode::after {
  content: '';
  display: block;
  width: 14px;
  height: 14px;
  background: white;
  border-radius: 2px;
}

.chat-input-area button svg {
  width: 18px;
  height: 18px;
  fill: white;
}

/* Treemap Suggestion Card */
.chat-suggestion-card {
  align-self: flex-start;
  width: 92%;
  background: linear-gradient(135deg, #eff6ff, #f0f9ff);
  border: 1px solid #bfdbfe;
  border-radius: 12px;
  padding: 14px 16px;
  margin: 8px 0;
  animation: chat-fab-in 0.3s ease-out;
  transition: opacity 0.3s, transform 0.3s;
}

.chat-suggestion-card.dismissed {
  opacity: 0.6;
}

.chat-suggestion-card.confirmed {
  border-color: #86efac;
  background: linear-gradient(135deg, #f0fdf4, #ecfdf5);
}

.suggestion-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.suggestion-badge {
  background: #4f46e5;
  color: white;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 500;
}

.suggestion-pain-id {
  font-size: 12px;
  color: #6b7280;
  font-family: monospace;
}

.suggestion-diff {
  margin-bottom: 12px;
  font-size: 13px;
  line-height: 1.5;
}

.diff-old {
  color: #991b1b;
  background: #fef2f2;
  padding: 6px 10px;
  border-radius: 6px;
  margin-bottom: 4px;
  text-decoration: line-through;
  opacity: 0.8;
}

.diff-new {
  color: #166534;
  background: #f0fdf4;
  padding: 6px 10px;
  border-radius: 6px;
}

.diff-label {
  font-weight: 600;
  margin-right: 4px;
}

.suggestion-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.suggestion-btn {
  border: none;
  padding: 6px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

.suggestion-btn:active { transform: scale(0.95); }

.suggestion-btn.confirm {
  background: #4f46e5;
  color: white;
}

.suggestion-btn.confirm:hover { background: #4338ca; }

.suggestion-btn.cancel {
  background: #f3f4f6;
  color: #4b5563;
}

.suggestion-btn.cancel:hover { background: #e5e7eb; }

.suggestion-confirmed {
  color: #166534;
  font-size: 13px;
  font-weight: 500;
}

.suggestion-dismissed {
  color: #6b7280;
  font-size: 13px;
}

.suggestion-applying {
  color: #4f46e5;
  font-size: 13px;
}

.suggestion-error {
  color: #dc2626;
  font-size: 13px;
}

/* Toast notification */
.miya-toast {
  position: fixed;
  top: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(-20px);
  background: #1f2937;
  color: white;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  z-index: 99999;
  opacity: 0;
  transition: opacity 0.3s, transform 0.3s;
  pointer-events: none;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

.miya-toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Mobile */
@media (max-width: 480px) {
  .chat-panel {
    width: 100%;
    height: 100vh;
    height: 100dvh;
    max-height: none;
    min-height: 0;
    border-radius: 0;
    top: 0;
    bottom: auto;
    left: 0;
    right: 0;
  }
  .chat-panel.open {
    transform: translateY(0);
  }
  .chat-panel-header {
    padding: 12px 16px;
    padding-top: max(12px, env(safe-area-inset-top));
  }
  .chat-input-area {
    padding: 10px 12px;
    padding-bottom: max(10px, env(safe-area-inset-bottom));
  }
  .chat-fab { bottom: 90px; }
  .chat-fab-label { display: none; }
  .chat-suggestion-card { width: 100%; }
}
