:root {
  --primary: #0284c7;
  --primary-hover: #0369a1;
  --primary-light: #e0f2fe;
  --primary-gradient: linear-gradient(135deg, #0284c7 0%, #0d9488 100%);
  --secondary: #0f766e;
  --accent: #38bdf8;
  
  --bg-main: #f8fafc;
  --bg-card: #ffffff;
  --bg-sidebar: #ffffff;
  --bg-user-msg: #0284c7;
  --text-user-msg: #ffffff;
  --bg-bot-msg: #ffffff;
  --text-bot-msg: #1e293b;
  
  --border-color: #e2e8f0;
  --border-focus: #38bdf8;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  
  --badge-bg: #ecfdf5;
  --badge-text: #059669;
  --warning-bg: #fffbeb;
  --warning-text: #b45309;
  
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.07), 0 2px 4px -2px rgb(0 0 0 / 0.07);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.08), 0 4px 6px -4px rgb(0 0 0 / 0.08);
  
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-full: 9999px;
  
  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-family);
  background-color: var(--bg-main);
  color: var(--text-primary);
  line-height: 1.5;
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* App Layout */
.app-container {
  display: flex;
  height: 100vh;
  width: 100%;
  max-width: 1440px;
  margin: 0 auto;
  background-color: var(--bg-card);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  width: 320px;
  background: #f8fafc;
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: transform 0.3s ease;
}

.sidebar-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  background: var(--primary-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 1.25rem;
  box-shadow: 0 4px 10px rgba(2, 132, 199, 0.3);
}

.brand-text h1 {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.brand-text p {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.sidebar-content {
  padding: 1.25rem;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.sidebar-card {
  background: #ffffff;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1rem;
  box-shadow: var(--shadow-sm);
}

.sidebar-card h3 {
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  margin-bottom: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.info-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.85rem;
  padding: 0.4rem 0;
  border-bottom: 1px dashed #f1f5f9;
}

.info-item:last-child {
  border-bottom: none;
}

.info-label {
  color: var(--text-secondary);
}

.info-val {
  font-weight: 500;
  color: var(--text-primary);
  background: #f1f5f9;
  padding: 0.15rem 0.5rem;
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
  font-family: monospace;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: var(--badge-bg);
  color: var(--badge-text);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.25rem 0.6rem;
  border-radius: var(--radius-full);
}

.status-badge.offline {
  background: #fef2f2;
  color: #dc2626;
}

.pulse-dot {
  width: 8px;
  height: 8px;
  background-color: #10b981;
  border-radius: 50%;
  box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7);
  animation: pulse-ring 2s infinite;
}

.status-badge.offline .pulse-dot {
  background-color: #ef4444;
  box-shadow: none;
  animation: none;
}

@keyframes pulse-ring {
  0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7); }
  70% { transform: scale(1); box-shadow: 0 0 0 6px rgba(16, 185, 129, 0); }
  100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

.sample-queries {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.query-chip {
  text-align: left;
  background: #ffffff;
  border: 1px solid var(--border-color);
  padding: 0.6rem 0.85rem;
  border-radius: var(--radius-md);
  font-size: 0.82rem;
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.query-chip:hover {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary-hover);
  transform: translateX(3px);
}

.query-chip svg {
  flex-shrink: 0;
  color: var(--primary);
}

.sidebar-footer {
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border-color);
  background: #ffffff;
}

.btn-secondary {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.65rem 1rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: #ffffff;
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-secondary:hover {
  background: #f1f5f9;
  color: var(--text-primary);
}

/* Main Chat Section */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: relative;
  background: #ffffff;
}

/* Header */
.chat-header {
  padding: 1rem 1.75rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #ffffff;
  z-index: 10;
}

.chat-header-title {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.menu-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 1.25rem;
  padding: 0.25rem;
}

.header-meta h2 {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text-primary);
}

.header-meta p {
  font-size: 0.78rem;
  color: var(--text-secondary);
}

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

.btn-icon {
  background: #f8fafc;
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-icon:hover {
  background: #f1f5f9;
  color: var(--text-primary);
}

/* Medical Disclaimer Banner */
.disclaimer-banner {
  background: #eff6ff;
  border-bottom: 1px solid #bfdbfe;
  color: #1e40af;
  padding: 0.5rem 1.5rem;
  font-size: 0.78rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  line-height: 1.4;
  flex-shrink: 0;
}

.disclaimer-banner svg {
  flex-shrink: 0;
}

/* Messages Window */
.chat-messages {
  flex: 1;
  min-height: 0;
  padding: 1.75rem 2rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  scroll-behavior: smooth;
  scroll-padding-top: 1.75rem;
  scroll-padding-bottom: 1.5rem;
  background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
}

/* Empty / Welcome State */
.welcome-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  text-align: center;
  max-width: 620px;
  margin: 0 auto;
  padding: 2rem 1rem;
}

.welcome-icon-box {
  width: 72px;
  height: 72px;
  border-radius: 20px;
  background: var(--primary-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  margin-bottom: 1.25rem;
  box-shadow: 0 10px 25px -5px rgba(2, 132, 199, 0.4);
}

.welcome-container h2 {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 0.5rem;
}

.welcome-container p {
  color: var(--text-secondary);
  font-size: 0.95rem;
  margin-bottom: 2rem;
  line-height: 1.6;
}

.welcome-suggestions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  width: 100%;
}

.suggestion-card {
  background: #ffffff;
  border: 1px solid var(--border-color);
  padding: 1rem;
  border-radius: var(--radius-md);
  text-align: left;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: var(--shadow-sm);
}

.suggestion-card:hover {
  border-color: var(--primary);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.suggestion-card h4 {
  font-size: 0.85rem;
  color: var(--primary);
  margin-bottom: 0.25rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.suggestion-card p {
  font-size: 0.78rem;
  color: var(--text-secondary);
  margin: 0;
}

/* Chat Message Bubbles */
.message-row {
  display: flex;
  gap: 1rem;
  width: 100%;
  animation: fadeIn 0.3s ease-out;
}

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

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

.avatar {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-weight: 600;
  font-size: 0.9rem;
}

.avatar.bot {
  background: var(--primary-gradient);
  color: white;
  box-shadow: 0 4px 10px rgba(2, 132, 199, 0.25);
}

.avatar.user {
  background: #334155;
  color: white;
}

.message-wrapper {
  max-width: 80%;
  display: flex;
  flex-direction: column;
}

.message-bubble {
  padding: 1rem 1.25rem;
  border-radius: var(--radius-lg);
  font-size: 0.95rem;
  line-height: 1.6;
  position: relative;
  word-break: break-word;
}

.message-row.user .message-bubble {
  background: var(--primary);
  color: var(--text-user-msg);
  border-bottom-right-radius: 4px;
  box-shadow: 0 4px 12px rgba(2, 132, 199, 0.2);
}

.message-row.bot .message-bubble {
  background: #ffffff;
  color: var(--text-bot-msg);
  border: 1px solid var(--border-color);
  border-bottom-left-radius: 4px;
  box-shadow: var(--shadow-sm);
}

/* Markdown styling inside bot bubble */
.message-bubble p {
  margin-bottom: 0.75rem;
}

.message-bubble p:last-child {
  margin-bottom: 0;
}

.message-bubble ul, .message-bubble ol {
  margin: 0.5rem 0 0.75rem 1.25rem;
}

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

.message-bubble strong {
  font-weight: 600;
  color: inherit;
}

.message-bubble code {
  background: #f1f5f9;
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  font-family: monospace;
  font-size: 0.88em;
}

.message-time {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 0.35rem;
  padding: 0 0.25rem;
}

.message-row.user .message-time {
  text-align: right;
}

/* Sources Accordion (RAG Context) */
.sources-container {
  margin-top: 0.75rem;
  border: 1px solid #e2e8f0;
  border-radius: var(--radius-md);
  background: #f8fafc;
  overflow: hidden;
}

.sources-header {
  padding: 0.5rem 0.85rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 600;
  color: #0369a1;
  background: #f0f9ff;
  border-bottom: 1px solid transparent;
  transition: all 0.2s;
  user-select: none;
}

.sources-header:hover {
  background: #e0f2fe;
}

.sources-header.open {
  border-bottom-color: #bae6fd;
}

.sources-header-left {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.sources-toggle-icon {
  transition: transform 0.2s ease;
}

.sources-header.open .sources-toggle-icon {
  transform: rotate(180deg);
}

.sources-list {
  padding: 0.75rem 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  max-height: 250px;
  overflow-y: auto;
}

.source-item {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.75rem;
  font-size: 0.78rem;
}

.source-item-meta {
  font-weight: 600;
  color: #0284c7;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin-bottom: 0.3rem;
}

.source-item-content {
  color: var(--text-secondary);
  line-height: 1.45;
  white-space: pre-line;
  max-height: 80px;
  overflow-y: auto;
}

/* Actions bar under bot message */
.message-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.4rem;
}

.action-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 0.75rem;
  padding: 0.2rem 0.4rem;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  gap: 0.3rem;
  cursor: pointer;
  transition: all 0.15s;
}

.action-btn:hover {
  background: #f1f5f9;
  color: var(--text-secondary);
}

.action-btn.active {
  color: var(--primary);
}

/* Typing Indicator */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.75rem 1rem;
  background: #ffffff;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  border-bottom-left-radius: 4px;
  width: fit-content;
}

.typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #94a3b8;
  animation: bounce 1.4s infinite ease-in-out both;
}

.typing-dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dot:nth-child(2) { animation-delay: -0.16s; }
.typing-dot:nth-child(3) { animation-delay: 0s; }

@keyframes bounce {
  0%, 80%, 100% { transform: scale(0); opacity: 0.5; }
  40% { transform: scale(1); opacity: 1; background: var(--primary); }
}

.typing-text {
  font-size: 0.78rem;
  color: var(--text-secondary);
  margin-left: 0.4rem;
}

/* Input Area */
.chat-input-area {
  padding: 1.25rem 2rem;
  background: #ffffff;
  border-top: 1px solid var(--border-color);
  position: relative;
}

.input-container {
  display: flex;
  align-items: flex-end;
  gap: 0.75rem;
  background: #f8fafc;
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 0.6rem 0.85rem;
  transition: all 0.2s ease;
  box-shadow: var(--shadow-sm);
}

.input-container:focus-within {
  border-color: var(--primary);
  background: #ffffff;
  box-shadow: 0 0 0 3px rgba(2, 132, 199, 0.15);
}

.chat-input {
  flex: 1;
  border: none;
  background: transparent;
  outline: none;
  font-family: inherit;
  font-size: 0.95rem;
  color: var(--text-primary);
  resize: none;
  max-height: 140px;
  min-height: 24px;
  line-height: 1.5;
  padding: 0.2rem 0;
}

.chat-input::placeholder {
  color: var(--text-muted);
}

.btn-send {
  background: var(--primary);
  color: white;
  border: none;
  width: 38px;
  height: 38px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
  flex-shrink: 0;
}

.btn-send:hover {
  background: var(--primary-hover);
  transform: scale(1.04);
}

.btn-send:disabled {
  background: #cbd5e1;
  cursor: not-allowed;
  transform: none;
}

.input-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 0.5rem;
  font-size: 0.72rem;
  color: var(--text-muted);
  padding: 0 0.5rem;
}

/* Toast Notification */
.toast {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  background: #0f172a;
  color: white;
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  box-shadow: var(--shadow-lg);
  transform: translateY(100px);
  opacity: 0;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  z-index: 999;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
}

.modal-overlay.open {
  display: flex;
}

.modal {
  background: #ffffff;
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 520px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: modalScale 0.2s ease-out;
}

@keyframes modalScale {
  from { transform: scale(0.95); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.modal-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h3 {
  font-size: 1.1rem;
  font-weight: 600;
}

.modal-body {
  padding: 1.5rem;
  font-size: 0.9rem;
  color: var(--text-secondary);
  line-height: 1.6;
}

.modal-body ul {
  margin: 0.75rem 0 1rem 1.25rem;
}

.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
}

/* Responsive */
@media (max-width: 900px) {
  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 50;
    transform: translateX(-100%);
    box-shadow: 2px 0 12px rgba(0,0,0,0.15);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .menu-toggle {
    display: block;
  }

  .welcome-suggestions {
    grid-template-columns: 1fr;
  }

  .chat-messages {
    padding: 1rem;
  }

  .chat-input-area {
    padding: 1rem;
  }

  .message-wrapper {
    max-width: 90%;
  }
}
