/* Modern AI Medical Assistant Design System */
:root {
  --font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-heading: 'Outfit', 'Plus Jakarta Sans', sans-serif;
  
  /* Midnight Obsidian Palette */
  --bg-primary: #0b0f19;
  --bg-surface: #111827;
  --bg-surface-hover: #1f2937;
  --bg-glass: rgba(17, 24, 39, 0.82);
  --border-color: rgba(255, 255, 255, 0.09);
  --border-active: rgba(56, 189, 248, 0.45);
  
  --text-primary: #f8fafc;
  --text-secondary: #cbd5e1;
  --text-muted: #64748b;
  
  --accent-primary: #10b981;
  --accent-secondary: #06b6d4;
  --accent-gradient: linear-gradient(135deg, #10b981 0%, #06b6d4 100%);
  --accent-light: rgba(16, 185, 129, 0.12);
  
  --btn-primary-bg: linear-gradient(135deg, #10b981 0%, #06b6d4 100%);
  --btn-primary-text: #ffffff;
  
  --user-msg-bg: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%);
  --user-msg-text: #ffffff;
  --bot-msg-bg: rgba(17, 24, 39, 0.75);
  
  --danger: #ef4444;
  --danger-light: rgba(239, 68, 68, 0.12);
  --success: #10b981;
  --success-light: rgba(16, 185, 129, 0.15);
  
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-full: 9999px;
  
  --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 8px 20px rgba(0, 0, 0, 0.6);
  --shadow-lg: 0 16px 36px rgba(0, 0, 0, 0.8);
  --shadow-glow: 0 0 20px rgba(6, 182, 212, 0.25);
  
  --transition: all 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Light Theme High-Contrast Mode */
[data-theme="light"] {
  --bg-primary: #f8fafc;
  --bg-surface: #ffffff;
  --bg-surface-hover: #f1f5f9;
  --bg-glass: rgba(255, 255, 255, 0.9);
  --border-color: #e2e8f0;
  --border-active: #0284c7;
  
  --text-primary: #0f172a;
  --text-secondary: #334155;
  --text-muted: #64748b;
  
  --accent-primary: #059669;
  --accent-secondary: #0891b2;
  --accent-gradient: linear-gradient(135deg, #059669 0%, #0891b2 100%);
  --accent-light: rgba(5, 150, 105, 0.08);
  
  --btn-primary-bg: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
  --btn-primary-text: #ffffff;
  
  --user-msg-bg: linear-gradient(135deg, #4338ca 0%, #3730a3 100%);
  --user-msg-text: #ffffff;
  --bot-msg-bg: #ffffff;
  
  --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 6px 16px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 12px 28px rgba(0, 0, 0, 0.12);
  --shadow-glow: 0 0 15px rgba(8, 145, 178, 0.15);
}

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

body {
  font-family: var(--font-family);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  height: 100vh;
  display: flex;
  overflow: hidden;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Custom Scrollbars */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(56, 189, 248, 0.4);
}

/* App Container Layout */
.app-container {
  display: flex;
  width: 100vw;
  height: 100vh;
  position: relative;
  overflow: hidden;
}

/* Sidebar Styles */
.sidebar {
  width: 300px;
  background-color: var(--bg-surface);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  transition: var(--transition);
  z-index: 20;
}

.sidebar-header {
  padding: 18px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--border-color);
}

.brand-icon {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-md);
  background: var(--accent-gradient);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.15rem;
  box-shadow: 0 0 12px rgba(16, 185, 129, 0.35);
}

.brand-info h1 {
  font-family: var(--font-heading);
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.3px;
  color: var(--text-primary);
}

.brand-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.73rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background-color: #10b981;
  box-shadow: 0 0 8px #10b981;
  animation: pulseDot 2s infinite;
}

@keyframes pulseDot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.85); }
}

.sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

/* Document Upload Card */
.section-title {
  font-family: var(--font-heading);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.dropzone {
  border: 1px dashed var(--border-color);
  border-radius: var(--radius-md);
  padding: 22px 14px;
  text-align: center;
  background: var(--bg-primary);
  cursor: pointer;
  transition: var(--transition);
}

.dropzone:hover, .dropzone.dragover {
  border-color: var(--accent-secondary);
  background: var(--bg-surface-hover);
  box-shadow: var(--shadow-glow);
}

.dropzone-icon {
  font-size: 1.8rem;
  color: var(--accent-secondary);
  margin-bottom: 6px;
}

.dropzone p {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 2px;
}

.dropzone span {
  font-size: 0.73rem;
  color: var(--text-muted);
}

#file-input {
  display: none;
}

.selected-files-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 8px;
  max-height: 120px;
  overflow-y: auto;
}

.file-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-primary);
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
}

.file-item .file-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 170px;
}

.file-item .remove-file {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px 4px;
  transition: var(--transition);
}

.file-item .remove-file:hover {
  color: var(--danger);
}

.btn-upload {
  width: 100%;
  margin-top: 10px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: var(--btn-primary-bg);
  color: var(--btn-primary-text);
  border: none;
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: var(--transition);
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.25);
}

.btn-upload:hover:not(:disabled) {
  opacity: 0.94;
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(16, 185, 129, 0.35);
}

.btn-upload:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  box-shadow: none;
}

/* Quick Prompts */
.quick-prompts {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.prompt-chip {
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 0.82rem;
  color: var(--text-secondary);
  cursor: pointer;
  text-align: left;
  transition: var(--transition);
  display: flex;
  align-items: center;
  gap: 10px;
}

.prompt-chip i {
  color: var(--accent-secondary);
}

.prompt-chip:hover {
  border-color: var(--border-active);
  color: var(--text-primary);
  background: var(--bg-surface-hover);
  transform: translateX(2px);
}

/* Main Chat Section */
.chat-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  background-color: var(--bg-primary);
  position: relative;
  height: 100vh;
}

.chat-header {
  height: 62px;
  padding: 0 24px;
  background-color: var(--bg-glass);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 10;
}

.chat-title-container {
  display: flex;
  align-items: center;
  gap: 12px;
}

.toggle-sidebar-btn {
  display: none;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 1.15rem;
  cursor: pointer;
}

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

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

.icon-btn:hover {
  background: var(--bg-surface-hover);
  color: var(--text-primary);
  border-color: var(--border-active);
}

/* Messages Area */
.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 28px 24px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  scroll-behavior: smooth;
}

/* Welcome Screen */
.welcome-screen {
  margin: auto;
  max-width: 560px;
  text-align: center;
  padding: 40px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.welcome-icon {
  width: 60px;
  height: 60px;
  border-radius: var(--radius-lg);
  background: var(--accent-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  font-size: 1.75rem;
  margin-bottom: 20px;
  box-shadow: var(--shadow-glow);
}

.welcome-screen h2 {
  font-family: var(--font-heading);
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 10px;
  letter-spacing: -0.3px;
  background: linear-gradient(135deg, #ffffff 0%, #cbd5e1 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.welcome-screen p {
  color: var(--text-muted);
  font-size: 0.92rem;
  margin-bottom: 28px;
  line-height: 1.6;
}

.welcome-cards {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
  width: 100%;
}

.welcome-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 16px;
  text-align: left;
  cursor: pointer;
  transition: var(--transition);
}

.welcome-card:hover {
  border-color: var(--accent-secondary);
  background: var(--bg-surface-hover);
  transform: translateY(-2px);
  box-shadow: var(--shadow-glow);
}

.welcome-card i {
  color: var(--accent-secondary);
  margin-bottom: 10px;
  font-size: 1.1rem;
}

.welcome-card h4 {
  font-family: var(--font-heading);
  font-size: 0.88rem;
  font-weight: 600;
  margin-bottom: 3px;
  color: var(--text-primary);
}

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

/* Message Items */
.message {
  display: flex;
  gap: 14px;
  max-width: 86%;
  animation: messageSlideIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes messageSlideIn {
  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;
}

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

.message.user .avatar {
  background: var(--user-msg-bg);
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.message.assistant .avatar {
  background: var(--accent-gradient);
  color: #ffffff;
  box-shadow: 0 0 14px rgba(16, 185, 129, 0.35);
}

.message-content {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

.bubble {
  padding: 16px 20px;
  border-radius: var(--radius-lg);
  font-size: 0.93rem;
  line-height: 1.65;
  word-break: break-word;
}

.message.user .bubble {
  background: var(--user-msg-bg);
  color: var(--user-msg-text);
  border-top-right-radius: 4px;
  white-space: pre-wrap;
  box-shadow: var(--shadow-sm);
}

.message.assistant .bubble {
  background: var(--bot-msg-bg);
  color: var(--text-primary);
  border-top-left-radius: 4px;
  border: 1px solid var(--border-color);
  border-left: 3px solid var(--accent-secondary);
  backdrop-filter: blur(12px);
  box-shadow: var(--shadow-md);
}

/* Modern AI Markdown Body Styling */
.markdown-body {
  font-size: 0.93rem;
  line-height: 1.68;
  color: var(--text-primary);
}

.markdown-body p {
  margin-bottom: 12px;
}

.markdown-body p:last-child {
  margin-bottom: 0;
}

.markdown-body strong {
  font-weight: 700;
  color: #ffffff;
}

.markdown-body em {
  font-style: italic;
  color: var(--text-secondary);
}

.markdown-body h1, 
.markdown-body h2, 
.markdown-body h3, 
.markdown-body h4 {
  font-family: var(--font-heading);
  font-weight: 700;
  color: var(--text-primary);
  margin-top: 18px;
  margin-bottom: 10px;
  letter-spacing: -0.2px;
}

.markdown-body h1 { font-size: 1.3rem; border-bottom: 1px solid var(--border-color); padding-bottom: 8px; }
.markdown-body h2 { font-size: 1.18rem; }
.markdown-body h3 { font-size: 1.08rem; color: #38bdf8; }
.markdown-body h4 { font-size: 0.98rem; }

.markdown-body ul, 
.markdown-body ol {
  margin-bottom: 14px;
  padding-left: 22px;
}

.markdown-body li {
  margin-bottom: 6px;
  line-height: 1.6;
}

.markdown-body li strong {
  color: #ffffff;
}

/* Modern AI Ultra-Sleek Markdown Tables */
.markdown-body table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  margin: 16px 0;
  border: 1px solid rgba(56, 189, 248, 0.25);
  border-radius: var(--radius-md);
  overflow: hidden;
  font-size: 0.88rem;
  background: rgba(17, 24, 39, 0.7);
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.4);
}

.markdown-body th {
  background: linear-gradient(90deg, rgba(16, 185, 129, 0.16) 0%, rgba(6, 182, 212, 0.16) 100%);
  color: #38bdf8;
  font-family: var(--font-heading);
  font-weight: 700;
  text-align: left;
  padding: 12px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  border-right: 1px solid rgba(255, 255, 255, 0.06);
  letter-spacing: 0.5px;
  text-transform: uppercase;
  font-size: 0.78rem;
}

.markdown-body th:last-child {
  border-right: none;
}

.markdown-body td {
  padding: 12px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  border-right: 1px solid rgba(255, 255, 255, 0.04);
  color: var(--text-secondary);
  vertical-align: top;
  line-height: 1.6;
}

.markdown-body tr:last-child td {
  border-bottom: none;
}

.markdown-body td:last-child {
  border-right: none;
}

.markdown-body tr:nth-child(even) {
  background: rgba(255, 255, 255, 0.015);
}

.markdown-body tr:hover {
  background: rgba(56, 189, 248, 0.08);
  transition: background 0.2s ease;
}

/* Code & Callouts */
.markdown-body code {
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
  font-size: 0.84rem;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  padding: 2px 6px;
  border-radius: 5px;
  color: #38bdf8;
}

.markdown-body pre {
  background: #090d16;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 14px 18px;
  overflow-x: auto;
  margin: 14px 0;
}

.markdown-body pre code {
  background: none;
  border: none;
  padding: 0;
  color: #f8fafc;
  font-size: 0.86rem;
}

.markdown-body blockquote {
  border-left: 3px solid var(--accent-secondary);
  padding: 10px 18px;
  margin: 14px 0;
  background: rgba(6, 182, 212, 0.06);
  color: var(--text-secondary);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.markdown-body hr {
  height: 1px;
  background: var(--border-color);
  border: none;
  margin: 18px 0;
}

/* Assistant Message Actions Toolbar */
.message-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
}

.action-btn {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  font-size: 0.76rem;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  transition: var(--transition);
}

.action-btn:hover {
  background: var(--bg-surface-hover);
  color: var(--text-primary);
  border-color: var(--border-active);
}

/* Sources section */
.sources-container {
  margin-top: 8px;
  padding: 10px 14px;
  background: rgba(17, 24, 39, 0.6);
  border: 1px solid rgba(16, 185, 129, 0.25);
  border-radius: var(--radius-md);
}

.sources-header {
  font-family: var(--font-heading);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  color: #10b981;
  letter-spacing: 0.6px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.sources-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.source-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(16, 185, 129, 0.12);
  border: 1px solid rgba(16, 185, 129, 0.3);
  padding: 4px 10px;
  border-radius: var(--radius-full);
  font-size: 0.76rem;
  color: #34d399;
}

.source-badge i {
  color: #10b981;
  font-size: 0.72rem;
}

.source-badge .page-tag {
  background: rgba(6, 182, 212, 0.2);
  color: #38bdf8;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 6px;
  font-size: 0.7rem;
}

/* Typing / Loading Dots */
.typing-dots {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 4px;
}

.typing-dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background-color: var(--accent-secondary);
  animation: typingBounce 1.2s infinite ease-in-out both;
}

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

@keyframes typingBounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.3; }
  40% { transform: scale(1.1); opacity: 1; }
}

/* Notification Toast */
.toast-container {
  position: absolute;
  top: 72px;
  right: 24px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  min-width: 280px;
  max-width: 400px;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-left: 4px solid var(--accent-primary);
  color: var(--text-primary);
  font-size: 0.85rem;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  animation: slideIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.toast.error {
  border-left-color: var(--danger);
}

.toast.success {
  border-left-color: var(--accent-primary);
}

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* Chat Input Bar */
.input-container {
  padding: 16px 24px 24px;
  background-color: var(--bg-primary);
}

.input-box {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 10px 12px 10px 18px;
  display: flex;
  align-items: flex-end;
  gap: 12px;
  box-shadow: var(--shadow-md);
  transition: var(--transition);
}

.input-box:focus-within {
  border-color: var(--accent-secondary);
  box-shadow: var(--shadow-glow);
}

.input-box textarea {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-family: var(--font-family);
  font-size: 0.93rem;
  resize: none;
  max-height: 140px;
  min-height: 26px;
  line-height: 1.55;
}

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

.send-btn {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  background: var(--btn-primary-bg);
  border: none;
  color: var(--btn-primary-text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
  transition: var(--transition);
  flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}

.send-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(16, 185, 129, 0.45);
}

.send-btn:disabled {
  opacity: 0.25;
  cursor: not-allowed;
  box-shadow: none;
}

.disclaimer {
  font-size: 0.72rem;
  color: var(--text-muted);
  text-align: center;
  margin-top: 10px;
}

/* Responsive adjustments */
@media (max-width: 768px) {
  .sidebar {
    position: absolute;
    top: 0;
    bottom: 0;
    left: -300px;
  }
  
  .sidebar.open {
    left: 0;
    box-shadow: var(--shadow-lg);
  }
  
  .toggle-sidebar-btn {
    display: block;
  }
  
  .welcome-cards {
    grid-template-columns: 1fr;
  }

  .message {
    max-width: 95%;
  }
}
