/**
 * Canadian Association of Family Health Support (CAFHS)
 * AI Health Companion ("Nova") Widget & Chat Stylesheet
 */

/* 1. Floating AI Chat Launcher Button */
.chat-launcher-btn {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  z-index: 990;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-deep) 100%);
  color: #FFFFFF;
  border: 2px solid rgba(255, 255, 255, 0.4);
  padding: 0.85rem 1.4rem;
  border-radius: var(--radius-pill);
  box-shadow: 0 8px 28px rgba(0, 128, 128, 0.35);
  cursor: pointer;
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 0.95rem;
  transition: all var(--transition-bounce);
}

.chat-launcher-btn:hover {
  transform: translateY(-4px) scale(1.03);
  box-shadow: 0 12px 34px rgba(0, 128, 128, 0.45);
}

.launcher-icon-wrap {
  position: relative;
  font-size: 1.3rem;
  display: flex;
  align-items: center;
}

.launcher-pulse {
  position: absolute;
  top: -4px;
  right: -4px;
  width: 10px;
  height: 10px;
  background: #2E7D32;
  border: 2px solid #FFFFFF;
  border-radius: 50%;
}

/* 2. Slide-in Chat Drawer */
.ai-chat-drawer {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  width: 440px;
  height: 640px;
  max-width: calc(100vw - 2rem);
  max-height: calc(100vh - 3rem);
  background: #FFFFFF;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-float);
  border: 1px solid var(--border-color);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transform: translateY(30px) scale(0.95);
  transition: all var(--transition-bounce);
}

.ai-chat-drawer.open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

/* Chat Header */
.chat-header {
  background: linear-gradient(135deg, var(--primary-deep) 0%, var(--primary) 100%);
  color: #FFFFFF;
  padding: 1.25rem 1.4rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow-sm);
}

.chat-header-info {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.chat-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  border: 2px solid rgba(255, 255, 255, 0.4);
}

.chat-titles h4 {
  color: #FFFFFF;
  font-size: 1rem;
  line-height: 1.2;
}

.chat-status {
  font-size: 0.75rem;
  color: #B5E0DE;
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.status-dot {
  width: 7px;
  height: 7px;
  background: #4CAF50;
  border-radius: 50%;
}

.chat-header-actions {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.chat-tool-btn {
  background: rgba(255, 255, 255, 0.15);
  border: none;
  color: #FFFFFF;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  transition: background var(--transition-fast);
}

.chat-tool-btn:hover {
  background: rgba(255, 255, 255, 0.3);
}

.chat-tool-btn.active {
  background: #FFFFFF;
  color: var(--primary-deep);
}

/* Chat Disclaimer Notice */
.chat-disclaimer-bar {
  background: #F0F7F6;
  padding: 0.5rem 1rem;
  font-size: 0.73rem;
  color: var(--text-muted);
  border-bottom: 1px solid #E2ECEB;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

/* Messages Scrollable Area */
.chat-messages-container {
  flex: 1;
  padding: 1.25rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  background: #FAFBFB;
}

/* Welcome Box */
.chat-welcome-box {
  text-align: center;
  background: #FFFFFF;
  border-radius: var(--radius-md);
  padding: 1.5rem;
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  margin-top: 0.5rem;
}

.welcome-avatar {
  font-size: 2.2rem;
  margin-bottom: 0.5rem;
}

.chat-welcome-box h4 {
  font-size: 1.05rem;
  margin-bottom: 0.5rem;
}

.chat-welcome-box p {
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.5;
  margin-bottom: 1.25rem;
}

.welcome-chips {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

/* Message Bubble Rows */
.chat-message {
  display: flex;
  gap: 0.75rem;
  max-width: 90%;
  animation: slideMessage 0.3s ease;
}

@keyframes slideMessage {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.message-user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.message-assistant {
  align-self: flex-start;
}

.message-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--primary-light);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
}

.message-user .message-avatar {
  background: #E2E8F0;
}

.message-bubble-wrapper {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.message-bubble {
  padding: 0.85rem 1.15rem;
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  line-height: 1.55;
  box-shadow: var(--shadow-sm);
}

.message-user .message-bubble {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-hover) 100%);
  color: #FFFFFF;
  border-bottom-right-radius: 2px;
}

.message-assistant .message-bubble {
  background: #FFFFFF;
  color: var(--text-main);
  border: 1px solid var(--border-color);
  border-bottom-left-radius: 2px;
}

.message-bubble h3, .message-bubble h4 {
  font-size: 0.98rem;
  margin-bottom: 0.5rem;
}

.message-bubble ul {
  padding-left: 1.2rem;
  margin: 0.5rem 0;
}

.message-bubble li {
  margin-bottom: 0.35rem;
}

.message-time {
  font-size: 0.7rem;
  color: var(--text-subtle);
  align-self: flex-start;
}

.message-user .message-time {
  align-self: flex-end;
}

/* Crisis Alert Message */
.crisis-alert-msg .message-bubble {
  border: 2px solid var(--crisis-red);
  background: var(--crisis-red-light);
}

.crisis-action-cards {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  margin-top: 0.85rem;
}

.crisis-card {
  background: #FFFFFF;
  border: 1px solid #FFCDD2;
  border-radius: var(--radius-sm);
  padding: 0.75rem;
}

.crisis-card h5 {
  font-size: 0.88rem;
  color: var(--crisis-red);
  margin-bottom: 0.25rem;
}

.crisis-card p {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.btn-crisis-call {
  display: inline-block;
  background: var(--crisis-red);
  color: #FFFFFF !important;
  font-weight: 700;
  font-size: 0.8rem;
  padding: 0.4rem 0.85rem;
  border-radius: var(--radius-pill);
  text-align: center;
}

/* Follow-up Action Chips */
.follow-up-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.4rem;
}

.chip-btn {
  background: #FFFFFF;
  border: 1px solid var(--border-color);
  color: var(--primary-deep);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius-pill);
  cursor: pointer;
  transition: all var(--transition-fast);
  text-align: left;
}

.chip-btn:hover {
  background: var(--primary-light);
  border-color: var(--primary);
}

/* Resources Badges */
.message-resources {
  margin-top: 0.75rem;
  padding-top: 0.6rem;
  border-top: 1px dashed var(--border-color);
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.resources-label {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--primary-deep);
}

.resource-badge {
  display: inline-block;
  background: var(--bg-main);
  border: 1px solid var(--border-color);
  color: var(--primary);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.25rem 0.6rem;
  border-radius: var(--radius-pill);
}

.resource-badge.action {
  background: var(--secondary-light);
  border-color: #F8CBC2;
  color: var(--secondary);
  cursor: pointer;
  border: 1px solid #F8CBC2;
}

/* Typing Indicator Animation */
.typing-bubble {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0.75rem 1rem !important;
}

.typing-bubble .dot {
  width: 6px;
  height: 6px;
  background: var(--text-subtle);
  border-radius: 50%;
  animation: typingDot 1.4s infinite ease-in-out;
}

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

@keyframes typingDot {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-5px); }
}

/* Chat Input Footer */
.chat-footer {
  background: #FFFFFF;
  padding: 0.85rem 1.15rem;
  border-top: 1px solid var(--border-color);
}

.chat-input-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.chat-input {
  flex: 1;
  padding: 0.65rem 0.95rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-pill);
  font-family: var(--font-body);
  font-size: 0.88rem;
  outline: none;
  transition: border-color var(--transition-fast);
}

.chat-input:focus {
  border-color: var(--primary);
}

.chat-btn-icon {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: var(--bg-main);
  color: var(--text-muted);
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
  flex-shrink: 0;
}

.chat-btn-icon:hover {
  background: var(--primary-light);
  color: var(--primary-deep);
}

.chat-btn-icon.recording {
  background: var(--crisis-red);
  color: #FFFFFF;
  animation: pulse-red 1.2s infinite;
}

@keyframes pulse-red {
  0% { box-shadow: 0 0 0 0 rgba(217, 56, 58, 0.6); }
  70% { box-shadow: 0 0 0 8px rgba(217, 56, 58, 0); }
  100% { box-shadow: 0 0 0 0 rgba(217, 56, 58, 0); }
}

.chat-send-btn {
  background: var(--primary);
  color: #FFFFFF;
}

.chat-send-btn:hover {
  background: var(--primary-hover);
  color: #FFFFFF;
}

/* 7. ChatGPT API Quick Config Banner & Inline Card */
.chat-api-banner {
  background: #EFF6FF;
  border-bottom: 1px solid #BFDBFE;
  padding: 0.5rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  font-size: 0.8rem;
  transition: all 0.2s ease;
}

.chat-api-banner.connected {
  background: #F0FDF4;
  border-bottom-color: #BBF7D0;
}

.chat-api-banner-left {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  overflow: hidden;
}

.chat-api-banner-left strong {
  display: block;
  font-size: 0.82rem;
  color: #1E3A8A;
  line-height: 1.15;
}

.chat-api-banner.connected .chat-api-banner-left strong {
  color: #166534;
}

.chat-api-banner-left small {
  display: block;
  font-size: 0.72rem;
  color: #64748B;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.btn-api-quick-config {
  background: #FFFFFF;
  border: 1px solid #93C5FD;
  color: #1D4ED8;
  font-weight: 600;
  font-size: 0.76rem;
  padding: 0.25rem 0.65rem;
  border-radius: var(--radius-pill);
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s ease;
}

.btn-api-quick-config:hover {
  background: #DBEAFE;
}

.chat-api-banner.connected .btn-api-quick-config {
  border-color: #86EFAC;
  color: #15803D;
}

.chat-api-banner.connected .btn-api-quick-config:hover {
  background: #DCFCE7;
}

/* Inline API Key Connect Card in Welcome Box */
.inline-api-card {
  background: #F8FAFC;
  border: 1px dashed #CBD5E1;
  border-radius: var(--radius-md);
  padding: 0.9rem;
  margin: 1rem 0;
  text-align: left;
}

.inline-api-card h6 {
  font-size: 0.86rem;
  font-weight: 700;
  color: #0F172A;
  margin-bottom: 0.35rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.inline-api-card p {
  font-size: 0.78rem !important;
  color: #64748B !important;
  margin-bottom: 0.6rem !important;
  line-height: 1.35 !important;
}

.inline-api-input-row {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 0.4rem;
}

.inline-api-input-row input {
  font-size: 0.8rem;
  padding: 0.4rem 0.6rem;
}

.inline-api-input-row button {
  padding: 0.4rem 0.85rem;
  font-size: 0.8rem;
  white-space: nowrap;
}

.inline-api-card small {
  display: block;
  font-size: 0.7rem;
  color: #94A3B8;
}

/* Test Connection Results Badge */
.api-test-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius-pill);
  font-size: 0.8rem;
  font-weight: 600;
  margin-top: 0.5rem;
}

.api-test-badge.success {
  background: #DCFCE7;
  color: #166534;
  border: 1px solid #86EFAC;
}

.api-test-badge.error {
  background: #FEE2E2;
  color: #991B1B;
  border: 1px solid #FCA5A5;
}

.api-test-badge.loading {
  background: #F1F5F9;
  color: #475569;
  border: 1px solid #CBD5E1;
}
