/* AI Medical Assistant — Floating Button */
.ai-fab {
  position: fixed;
  bottom: calc(var(--nav-height, 64px) + 16px);
  right: 16px;
  width: 56px;
  height: 56px;
  border-radius: 14px;
  border: none;
  cursor: pointer;
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--specialty-primary, #3090e8), var(--specialty-secondary, #1a6ab8));
  color: #fff;
  box-shadow: 0 0 0 0 rgba(var(--specialty-primary-rgb, 48,144,232), 0.4), 0 4px 20px rgba(0,0,0,0.5);
  animation: aiButtonPulse 3s ease-out infinite;
  transition: transform 200ms ease;
  -webkit-tap-highlight-color: transparent;
}
.ai-fab:active { transform: scale(0.92); }
.ai-fab.ai-fab-open { transform: rotate(45deg); animation: none; }
.ai-fab.ai-fab-hidden { display: none !important; }
.ai-fab svg { width: 24px; height: 24px; transition: transform 200ms ease; }

@keyframes aiButtonPulse {
  0%   { box-shadow: 0 0 0 0 rgba(var(--specialty-primary-rgb, 48,144,232), 0.4), 0 4px 20px rgba(0,0,0,0.5); }
  70%  { box-shadow: 0 0 0 10px rgba(var(--specialty-primary-rgb, 48,144,232), 0), 0 4px 20px rgba(0,0,0,0.5); }
  100% { box-shadow: 0 0 0 0 rgba(var(--specialty-primary-rgb, 48,144,232), 0), 0 4px 20px rgba(0,0,0,0.5); }
}

/* Overlay */
.ai-chat-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-primary);
  z-index: 600;
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform 350ms cubic-bezier(0.34, 1.56, 0.64, 1);
}
.ai-chat-overlay.ai-chat-open { transform: translateY(0); }
.ai-chat-overlay.hidden { display: none; }

.ai-chat-header {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-shrink: 0;
}
.ai-chat-header-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.ai-chat-header-icon {
  width: 32px; height: 32px; border-radius: 9px;
  background: linear-gradient(135deg, var(--specialty-primary, #3090e8), var(--specialty-secondary, #1a6ab8));
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.ai-chat-header-icon svg { width: 18px; height: 18px; color: #fff; }
.ai-chat-header-title {
  font-family: var(--font-mono);
  font-size: 14px; font-weight: 700;
  color: var(--specialty-primary, #3090e8);
  line-height: 1.2;
}
.ai-chat-header-sub { font-size: 11px; color: var(--text-muted); }
.ai-chat-header-right { display: flex; gap: 6px; }
.ai-chat-newchat-btn {
  background: none; border: 1px solid var(--border);
  border-radius: 99px; padding: 4px 10px;
  font-size: 11px; color: var(--text-secondary); cursor: pointer;
  font-family: var(--font-mono);
}
.ai-chat-close-btn {
  background: none; border: none; color: var(--text-secondary);
  width: 32px; height: 32px; border-radius: 50%;
  font-size: 20px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.ai-chat-close-btn:hover { background: rgba(255,255,255,0.05); }

.ai-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Empty State */
.ai-empty {
  text-align: center;
  padding: 32px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.ai-empty-icon {
  width: 64px; height: 64px; border-radius: 18px;
  background: linear-gradient(135deg, var(--specialty-primary, #3090e8), var(--specialty-secondary, #1a6ab8));
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 24px rgba(var(--specialty-primary-rgb, 48,144,232), 0.4);
}
.ai-empty-icon svg { width: 36px; height: 36px; color: #fff; }
.ai-empty-title {
  font-family: var(--font-mono); font-size: 20px; font-weight: 700;
  color: var(--specialty-primary, #3090e8);
}
.ai-empty-sub {
  font-size: 14px; color: var(--text-muted);
  max-width: 320px; line-height: 1.5;
}
.ai-suggest-grid {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 8px; margin-top: 8px; width: 100%; max-width: 480px;
}
.ai-suggest-chip {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-left: 3px solid var(--specialty-primary, #3090e8);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
  color: var(--text-secondary);
  text-align: left;
  cursor: pointer;
  font-family: var(--font-sans);
  line-height: 1.4;
}
.ai-suggest-chip:active { opacity: 0.7; }

/* Message Bubbles */
.ai-msg-row { display: flex; flex-direction: column; gap: 4px; max-width: 100%; }
.ai-msg-row-user { align-items: flex-end; }
.ai-msg-row-ai { align-items: flex-start; }
.ai-msg-avatar {
  display: flex; align-items: center; gap: 6px;
  font-size: 11px; color: var(--text-muted);
  padding: 0 6px;
}
.ai-msg-avatar-icon {
  width: 16px; height: 16px; border-radius: 5px;
  background: linear-gradient(135deg, var(--specialty-primary, #3090e8), var(--specialty-secondary, #1a6ab8));
  display: inline-flex; align-items: center; justify-content: center;
}
.ai-msg-avatar-icon svg { width: 10px; height: 10px; color: #fff; }
.ai-msg-bubble {
  padding: 10px 14px;
  font-size: 15px;
  font-family: var(--font-sans);
  line-height: 1.5;
  color: var(--text-primary);
  word-wrap: break-word;
  position: relative;
}
.ai-msg-bubble-user {
  background: rgba(var(--specialty-primary-rgb, 48,144,232), 0.15);
  border: 1px solid rgba(var(--specialty-primary-rgb, 48,144,232), 0.3);
  border-radius: 18px 18px 4px 18px;
  max-width: 80%;
}
.ai-msg-bubble-ai {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 18px 18px 18px 4px;
  max-width: 85%;
  padding-bottom: 28px;
}
.ai-msg-copy-btn {
  position: absolute; bottom: 4px; right: 6px;
  background: none; border: none; cursor: pointer;
  font-size: 12px; color: var(--text-muted);
  padding: 4px 6px; border-radius: 4px;
}
.ai-msg-copy-btn:hover { color: var(--text-primary); }

/* AI content formatting */
.ai-message-content p { margin: 0 0 10px 0; line-height: 1.6; }
.ai-message-content p:last-child { margin-bottom: 0; }
.ai-message-content strong { color: var(--text-primary); font-weight: 700; }
.ai-message-content ul.ai-list { padding-left: 18px; margin: 8px 0; list-style: disc; }
.ai-message-content ul.ai-list li { margin-bottom: 6px; line-height: 1.5; color: var(--text-secondary); }

/* Typing dots */
.ai-typing { display: flex; gap: 4px; align-items: center; padding: 4px 0; }
.ai-typing span {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--text-muted);
  animation: aiTypingDot 1.2s ease-in-out infinite;
}
.ai-typing span:nth-child(2) { animation-delay: 0.2s; }
.ai-typing span:nth-child(3) { animation-delay: 0.4s; }
.ai-typing-label { font-size: 11px; color: var(--text-muted); margin-top: 4px; }
@keyframes aiTypingDot {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* System / error message */
.ai-msg-system {
  background: rgba(240,160,48,0.08);
  border: 1px solid rgba(240,160,48,0.3);
  border-radius: 12px;
  padding: 14px;
  font-size: 14px;
  color: var(--text-primary);
  line-height: 1.5;
  text-align: center;
}
.ai-msg-system-action {
  display: inline-block; margin-top: 10px;
  background: var(--yellow); color: #1a1a1a;
  border: none; border-radius: 8px;
  padding: 8px 14px; font-weight: 600; font-size: 13px;
  cursor: pointer; text-decoration: none;
}

/* Disclaimer bar */
.ai-chat-disclaimer {
  background: rgba(240,160,48,0.08);
  border-top: 1px solid rgba(240,160,48,0.2);
  padding: 8px 16px;
  font-size: 12px;
  color: var(--yellow);
  text-align: center;
  flex-shrink: 0;
}

/* Input bar */
.ai-chat-input-bar {
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom)) 12px;
  display: flex; gap: 8px; align-items: flex-end;
  flex-shrink: 0;
}
.ai-chat-input {
  flex: 1;
  min-height: 44px; max-height: 120px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 12px 16px;
  font-size: 16px;
  font-family: var(--font-sans);
  color: var(--text-primary);
  resize: none;
  outline: none;
  line-height: 1.4;
}
.ai-chat-input:focus { border-color: var(--specialty-primary, #3090e8); }
.ai-chat-send {
  width: 44px; height: 44px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--specialty-primary, #3090e8), var(--specialty-secondary, #1a6ab8));
  color: #fff;
  border: none;
  cursor: pointer;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
}
.ai-chat-send:disabled { opacity: 0.5; cursor: not-allowed; }
.ai-chat-send-spinner {
  width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: aiSpin 0.8s linear infinite;
}
@keyframes aiSpin { to { transform: rotate(360deg); } }

/* Copy toast */
.ai-copy-toast {
  position: fixed;
  bottom: 80px; left: 50%;
  transform: translateX(-50%);
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--green);
  padding: 8px 14px;
  border-radius: 99px;
  font-size: 13px;
  font-weight: 600;
  z-index: 700;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}

/* Hide FAB while resus mode is active (handled via .ai-fab-hidden class) */

/* AI Response — Linked Content */
.ai-links-wrap {
  margin-top: 10px;
  width: 100%;
}
.ai-links-section {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.ai-links-header {
  font-family: var(--font-mono, 'JetBrains Mono', monospace);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted, #8a8a99);
  margin: 4px 0 4px 2px;
}
.ai-link-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  background: var(--bg-elevated, #1c1c24);
  border: 1px solid var(--border, #2a2a35);
  border-radius: 10px;
  cursor: pointer;
  text-align: left;
  color: var(--text-primary, #e8e8ef);
  font-family: inherit;
  transition: transform 0.08s ease, border-color 0.15s ease, background 0.15s ease;
}
.ai-link-chip:hover {
  border-color: var(--specialty-primary, #4a90e8);
  background: var(--bg-elevated-hover, #232330);
}
.ai-link-chip:active { transform: scale(0.98); }
.ai-link-icon { font-size: 18px; flex-shrink: 0; }
.ai-link-text {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}
.ai-link-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary, #e8e8ef);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ai-link-sub {
  font-size: 12px;
  color: var(--text-muted, #8a8a99);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 1px;
}
.ai-link-badge {
  font-family: var(--font-mono, 'JetBrains Mono', monospace);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.08em;
  padding: 3px 6px;
  border-radius: 4px;
  color: #fff;
  flex-shrink: 0;
}
.ai-link-arrow {
  color: var(--text-muted, #8a8a99);
  font-size: 16px;
  flex-shrink: 0;
}
