/* ============================================
   HealthUp Chat Interface
   Conversational SQL Assistant Styles
   ============================================ */

/* Chat Container - Full Height Design */
.chat-container {
  background: var(--color-surface-elevated);
  border-radius: var(--radius-xl);
  border: 1px solid var(--color-border-light);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  /* Use calc to fill viewport minus page header and padding */
  height: calc(100vh - var(--header-height) - var(--space-8) * 2 - var(--space-8));
  min-height: 500px;
  overflow: hidden;
  position: relative;
  max-width: 100%;
  box-sizing: border-box;
}

/* Empty State */
.chat-empty-state {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100%;
  padding: var(--space-8);
}

.chat-empty-content {
  text-align: center;
  max-width: 600px;
  margin: 0 auto;
}

.chat-empty-icon {
  font-size: 4rem;
  margin-bottom: var(--space-4);
  opacity: 0.9;
}

.chat-empty-title {
  font-size: var(--text-3xl);
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--color-slate-900);
  margin: 0 0 var(--space-2) 0;
  letter-spacing: -0.02em;
}

.chat-empty-subtitle {
  font-size: var(--text-base);
  color: var(--color-text-secondary);
  margin: 0 0 var(--space-8) 0;
  line-height: 1.5;
}

/* Example Prompts */
.chat-example-prompts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: var(--space-3);
  margin-top: var(--space-6);
}

.chat-example-prompt {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  background: var(--color-surface-elevated);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: all var(--transition-fast);
  text-align: left;
  font-family: var(--font-body);
  font-size: var(--text-sm);
  color: var(--color-text);
  box-shadow: var(--shadow-sm);
}

.chat-example-prompt:hover {
  border-color: var(--color-accent);
  background: var(--color-accent-light);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.chat-example-prompt .prompt-icon {
  font-size: var(--text-xl);
  flex-shrink: 0;
}

.chat-example-prompt .prompt-text {
  flex: 1;
  font-weight: 500;
}

/* Hide empty state when messages exist */
.chat-messages:has(.chat-message) .chat-empty-state {
  display: none;
}

/* Medical Disclaimer - Bottom Design */
.chat-medical-disclaimer {
  padding: var(--space-3) var(--space-5);
  text-align: center;
  font-size: 11px;
  color: var(--color-text-muted);
  line-height: 1.4;
  background: transparent;
  border-top: 1px solid var(--color-border-light);
}

.chat-medical-disclaimer strong {
  font-weight: 600;
  color: var(--color-text-secondary);
}

/* Messages Container */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  padding: var(--space-5) var(--space-6);
  background: var(--color-surface-elevated);
}

/* Message Bubbles */
.chat-message {
  margin-bottom: var(--space-5);
  display: flex;
  align-items: flex-start;
  animation: messageSlideIn 0.25s ease-out;
  max-width: 900px;
  margin-left: auto;
  margin-right: auto;
}

@keyframes messageSlideIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.chat-message-user {
  justify-content: flex-end;
}

.chat-message-assistant {
  justify-content: flex-start;
}

.chat-message-system {
  justify-content: center;
}

.chat-bubble {
  max-width: 75%;
  padding: var(--space-4) var(--space-5);
  border-radius: var(--radius-lg);
  word-wrap: break-word;
  white-space: pre-wrap;
  font-size: var(--text-sm);
  line-height: 1.6;
  box-shadow: var(--shadow-sm);
}

/* User Bubble */
.chat-bubble-user {
  background: linear-gradient(135deg, var(--color-sage-600), var(--color-sage-700));
  color: white;
  border-bottom-right-radius: var(--radius-sm);
}

/* Assistant Bubble - Minimal Design */
.chat-bubble-assistant {
  background: transparent;
  color: var(--color-text);
  border: none;
  box-shadow: none;
  padding: var(--space-3) 0;
}

/* Success Bubble */
.chat-bubble-success {
  background: var(--color-success-light);
  color: var(--color-success);
  border: 1px solid rgba(5, 150, 105, 0.2);
}

/* Error Bubble */
.chat-bubble-error {
  background: var(--color-error-light);
  color: var(--color-error);
  border: 1px solid rgba(220, 38, 38, 0.2);
  max-width: 85%;
}

/* Streaming Cursor */
.streaming-cursor {
  display: inline-block;
  margin-left: 2px;
  animation: blink 1s step-end infinite;
  color: var(--color-accent);
  font-weight: bold;
}

@keyframes blink {

  0%,
  50% {
    opacity: 1;
  }

  51%,
  100% {
    opacity: 0;
  }
}

/* Tool Indicators */
.tool-indicators {
  margin: var(--space-2) 0;
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.tool-indicator {
  display: inline-flex;
  align-items: center;
  padding: var(--space-2) var(--space-3);
  background: var(--color-info-light);
  color: var(--color-info);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 600;
  border: 1px solid rgba(2, 132, 199, 0.2);
}

.tool-spinner {
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-right: var(--space-2);
  border: 2px solid var(--color-info-light);
  border-top-color: var(--color-info);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* Input Area - Compact Design */
.chat-input-container {
  padding: var(--space-4) var(--space-5);
  border-top: 1px solid var(--color-border-light);
  background: transparent;
  flex-shrink: 0;
}

.chat-input-wrapper {
  display: flex;
  gap: var(--space-3);
  align-items: center;
  max-width: 900px;
  margin: 0 auto;
}

.chat-input-textarea {
  flex: 1;
  min-height: 44px;
  max-height: 120px;
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  font-family: var(--font-body);
  font-size: var(--text-sm);
  resize: none;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  background: var(--color-surface-elevated);
  color: var(--color-text);
  line-height: 1.5;
  box-shadow: var(--shadow-sm);
}

.chat-input-textarea:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px rgba(22, 163, 74, 0.1);
}

.chat-input-textarea:disabled {
  background: var(--color-slate-50);
  cursor: not-allowed;
  color: var(--color-text-muted);
}

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

.chat-send-button {
  padding: var(--space-3) var(--space-5);
  background: var(--color-accent);
  color: white;
  border: none;
  border-radius: var(--radius-lg);
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
  min-height: 44px;
}

.chat-send-button:hover:not(:disabled) {
  background: var(--color-accent-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(22, 163, 74, 0.25);
}

.chat-send-button:active:not(:disabled) {
  transform: translateY(0);
}

.chat-send-button:disabled {
  background: var(--color-slate-300);
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

/* Results Section */
.result-section {
  margin-bottom: var(--space-8);
}

.result-section h3 {
  margin-bottom: var(--space-4);
  font-family: var(--font-display);
  color: var(--color-text);
  font-size: var(--text-lg);
}

.sql-display {
  background: var(--color-slate-900);
  border: 1px solid var(--color-slate-700);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  line-height: 1.6;
  color: var(--color-sage-300);
}

/* Scrollbar Styling */
.chat-messages::-webkit-scrollbar {
  width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
  background: var(--color-surface-elevated);
}

.chat-messages::-webkit-scrollbar-thumb {
  background: var(--color-slate-300);
  border-radius: var(--radius-full);
}

.chat-messages::-webkit-scrollbar-thumb:hover {
  background: var(--color-slate-400);
}

/* Firefox scrollbar */
.chat-messages {
  scrollbar-width: thin;
  scrollbar-color: var(--color-slate-300) var(--color-surface-elevated);
}

/* Accessibility */
.chat-input-textarea:focus-visible,
.chat-send-button:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

/* Screen reader only */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Markdown Content Styling */
.markdown-content {
  white-space: normal;
}

.markdown-content p {
  margin: 0 0 var(--space-3) 0;
}

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

.markdown-content strong {
  font-weight: 600;
  color: var(--color-slate-900);
}

.markdown-content em {
  font-style: italic;
}

.markdown-content code {
  background: var(--color-slate-100);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 0.9em;
}

.markdown-content pre {
  background: var(--color-slate-900);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  overflow-x: auto;
  margin: var(--space-3) 0;
}

.markdown-content pre code {
  background: none;
  padding: 0;
  color: var(--color-sage-300);
  font-size: var(--text-sm);
}

.markdown-content ul,
.markdown-content ol {
  margin: var(--space-3) 0;
  padding-left: var(--space-6);
}

.markdown-content li {
  margin: var(--space-2) 0;
}

.markdown-content h1,
.markdown-content h2,
.markdown-content h3,
.markdown-content h4 {
  font-family: var(--font-display);
  margin: var(--space-4) 0 var(--space-2) 0;
  font-weight: 600;
  line-height: 1.3;
  color: var(--color-slate-900);
}

.markdown-content h1 {
  font-size: var(--text-2xl);
}

.markdown-content h2 {
  font-size: var(--text-xl);
}

.markdown-content h3 {
  font-size: var(--text-lg);
}

.markdown-content h4 {
  font-size: var(--text-base);
}

.markdown-content h1:first-child,
.markdown-content h2:first-child,
.markdown-content h3:first-child,
.markdown-content h4:first-child {
  margin-top: 0;
}

.markdown-content a {
  color: var(--color-accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.markdown-content a:hover {
  color: var(--color-accent-hover);
}

.markdown-content blockquote {
  margin: var(--space-4) 0;
  padding-left: var(--space-4);
  border-left: 3px solid var(--color-accent);
  color: var(--color-text-secondary);
  font-style: italic;
}

.markdown-content hr {
  border: none;
  border-top: 1px solid var(--color-border);
  margin: var(--space-4) 0;
}

.markdown-content table {
  border-collapse: collapse;
  width: 100%;
  margin: var(--space-4) 0;
  font-size: var(--text-sm);
}

.markdown-content table th,
.markdown-content table td {
  border: 1px solid var(--color-border);
  padding: var(--space-2) var(--space-3);
  text-align: left;
}

.markdown-content table th {
  background: var(--color-slate-50);
  font-weight: 600;
}

/* Plot Visualization */
.chat-plot-visualization {
  margin: var(--space-6) 0;
  background: var(--color-surface-elevated);
  border-radius: var(--radius-xl);
  border: 1px solid var(--color-border-light);
  overflow: hidden;
}

.chat-plot-visualization h3 {
  margin: 0;
  padding: var(--space-4) var(--space-5);
  font-family: var(--font-display);
  font-size: var(--text-lg);
  color: var(--color-text);
  background: var(--color-slate-50);
  border-bottom: 1px solid var(--color-border-light);
}

.chat-plot-container {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 0;
}

.chat-parameter-selector-panel {
  padding: var(--space-4);
  background: var(--color-slate-50);
  border-right: 1px solid var(--color-border-light);
}

.chat-parameter-selector-title {
  font-size: var(--text-sm);
  font-weight: 600;
  margin: 0 0 var(--space-3) 0;
  color: var(--color-text-secondary);
}

.chat-parameter-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.chat-parameter-list .parameter-selector-item {
  display: flex;
  align-items: center;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: var(--text-sm);
  transition: background-color var(--transition-fast);
}

.chat-parameter-list .parameter-selector-item:hover {
  background: var(--color-slate-100);
}

.chat-parameter-list .parameter-selector-item input[type="radio"] {
  margin-right: var(--space-2);
  cursor: pointer;
  accent-color: var(--color-accent);
}

.chat-parameter-list .parameter-selector-item:has(input[type="radio"]:checked) {
  background: var(--color-accent-light);
  font-weight: 600;
}

.chat-plot-canvas-wrapper {
  padding: var(--space-5);
  min-height: 400px;
  max-height: 500px;
  display: flex;
  flex-direction: column;
}

.chat-plot-toolbar {
  margin-bottom: var(--space-3);
  text-align: center;
}

.chat-plot-toolbar-hint {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

.chat-plot-canvas-wrapper canvas {
  flex: 1;
  max-height: 420px !important;
}

.chat-parameter-table-container {
  padding: var(--space-5);
  border-top: 1px solid var(--color-border-light);
}

/* Results Table in Chat */
.chat-results-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}

.chat-results-table th {
  background: var(--color-slate-50);
  padding: var(--space-3) var(--space-4);
  text-align: left;
  border-bottom: 2px solid var(--color-border);
  font-weight: 600;
  color: var(--color-text-secondary);
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.chat-results-table td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-border-light);
}

.chat-results-table tbody tr:hover {
  background: var(--color-slate-50);
}

/* Responsive Design */
@media (max-width: 768px) {
  .chat-container {
    /* On mobile, fill available space minus minimal padding */
    height: calc(100vh - var(--header-height) - var(--space-4) * 2);
    min-height: 400px;
    border-radius: var(--radius-lg);
  }

  .chat-empty-state {
    padding: var(--space-4);
  }

  .chat-empty-icon {
    font-size: 3rem;
  }

  .chat-empty-title {
    font-size: var(--text-2xl);
  }

  .chat-empty-subtitle {
    font-size: var(--text-sm);
  }

  .chat-example-prompts {
    grid-template-columns: 1fr;
    gap: var(--space-2);
  }

  .chat-example-prompt {
    padding: var(--space-3) var(--space-4);
  }

  .chat-message {
    margin-bottom: var(--space-4);
    max-width: 100%;
  }

  .chat-bubble {
    max-width: 85%;
    font-size: var(--text-sm);
  }

  .chat-input-wrapper {
    flex-direction: row;
    gap: var(--space-2);
  }

  .chat-send-button {
    min-width: 80px;
    padding: var(--space-3) var(--space-4);
  }

  .chat-plot-container {
    grid-template-columns: 1fr;
  }

  .chat-parameter-selector-panel {
    border-right: none;
    border-bottom: 1px solid var(--color-border-light);
  }

  .chat-messages {
    padding: var(--space-4);
  }

  .chat-input-container {
    padding: var(--space-3) var(--space-4);
  }

  .chat-medical-disclaimer {
    font-size: 10px;
    padding: var(--space-2) var(--space-4);
  }
}

/* High Contrast Mode Support */
@media (prefers-contrast: high) {
  .chat-bubble-user {
    border: 2px solid white;
  }

  .chat-bubble-assistant {
    border: 2px solid var(--color-text);
  }

  .tool-indicator {
    border: 2px solid var(--color-info);
  }
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {

  .streaming-cursor,
  .tool-spinner {
    animation: none;
  }

  .chat-message {
    animation: none;
  }
}

/* ============================================
   PRD v4.2.4: Thumbnail Card Styling
   ============================================ */

/* Thumbnail Visual Tokens */
.thumbnail-card {
  --thumbnail-card-bg: #ffffff;
  --thumbnail-card-border: #e6e8ec;
  --thumbnail-card-radius: 12px;
  --thumbnail-card-padding: 12px 14px;
  --thumbnail-title: #1f2937;
  --thumbnail-subtitle: #6b7280;
  --thumbnail-value: #111827;
  --thumbnail-muted: #9ca3af;
  --thumbnail-sparkline: #1f2937;
  --status-normal: #059669;
  --status-high: #b45309;
  --status-low: #2563eb;
  --status-unknown: #6b7280;
}

/* Thumbnail Stack Container */
.thumbnail-stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 0;
  margin-top: 12px;
}

.thumbnail-stack:empty {
  display: none;
}

/* No text above - remove top margin */
.thumbnail-stack--no-text-above {
  margin-top: 0;
}

/* Thumbnail Card */
.thumbnail-card {
  background: var(--thumbnail-card-bg);
  border: 1px solid var(--thumbnail-card-border);
  border-radius: var(--thumbnail-card-radius);
  padding: var(--thumbnail-card-padding);
  width: 100%;
  max-width: 420px;
  min-width: 320px;
  box-sizing: border-box;
}

/* Header Section */
.thumbnail-header {
  margin-bottom: 8px;
}

.thumbnail-title {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.3;
  color: var(--thumbnail-title);
}

.thumbnail-subtitle {
  font-size: 12px;
  font-weight: 400;
  line-height: 1.3;
  color: var(--thumbnail-subtitle);
  margin-top: 2px;
}

/* Primary Value Row */
.thumbnail-primary {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
}

.thumbnail-value {
  font-size: 20px;
  font-weight: 600;
  line-height: 1.2;
  color: var(--thumbnail-value);
}

/* Status Pill */
.thumbnail-status {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
  line-height: 1.3;
}

.thumbnail-status.status-normal {
  background: rgba(5, 150, 105, 0.1);
  color: var(--status-normal);
}

.thumbnail-status.status-high {
  background: rgba(180, 83, 9, 0.1);
  color: var(--status-high);
}

.thumbnail-status.status-low {
  background: rgba(37, 99, 235, 0.1);
  color: var(--status-low);
}

.thumbnail-status.status-unknown {
  background: rgba(107, 114, 128, 0.1);
  color: var(--status-unknown);
}

/* Delta Row */
.thumbnail-delta {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 400;
  line-height: 1.3;
  color: var(--thumbnail-muted);
  margin-bottom: 8px;
}

.delta-icon {
  font-size: 10px;
}

.delta-icon.delta-up {
  color: var(--status-high);
}

.delta-icon.delta-down {
  color: var(--status-low);
}

.delta-icon.delta-stable {
  color: var(--thumbnail-muted);
}

.delta-value {
  font-weight: 500;
  color: var(--thumbnail-title);
}

.delta-period {
  color: var(--thumbnail-muted);
}

/* Sparkline */
.thumbnail-sparkline {
  height: 24px;
  width: 100%;
  margin-bottom: 8px;
}

.thumbnail-sparkline svg {
  width: 100%;
  height: 100%;
  display: block;
}

/* Footer */
.thumbnail-footer {
  display: flex;
  gap: 12px;
  font-size: 12px;
  font-weight: 400;
  line-height: 1.3;
  color: var(--thumbnail-muted);
}

.thumbnail-meta {
  /* Individual meta items */
}

/* Responsive: Override bubble width for assistant messages with thumbnails */
.chat-message-assistant:has(.thumbnail-stack:not(:empty)) .chat-bubble {
  max-width: 85%;
}

/* Narrow viewport adjustments */
@media (max-width: 380px) {
  .thumbnail-card {
    min-width: 100%;
  }

  .chat-message-assistant:has(.thumbnail-stack:not(:empty)) .chat-bubble {
    max-width: 90%;
  }
}

@media (max-width: 320px) {
  .thumbnail-card {
    min-width: 100%;
  }

  .thumbnail-stack {
    padding: 0 8px;
  }
}

/* ============================================
   PRD v4.3: Patient Selector Row
   ============================================ */

.chat-patient-selector {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  background: linear-gradient(135deg, var(--color-accent-light) 0%, rgba(255, 255, 255, 0.9) 100%);
  border-bottom: 1px solid var(--color-border-light);
  flex-shrink: 0;
  width: 100%;
  box-sizing: border-box;
}

/* Visual separator between scroll controls and New Chat */
.patient-selector-divider {
  width: 1px;
  height: 24px;
  background: var(--color-border);
}

.patient-selector-label {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-text-secondary);
  white-space: nowrap;
}

/* Scroll buttons - inline in the selector row */
.patient-chips-scroll-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  font-size: 16px;
  font-weight: 700;
  color: var(--color-accent);
  background: white;
  border: 2px solid var(--color-accent);
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: all var(--transition-fast);
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
}

.patient-chips-scroll-btn:hover {
  background: var(--color-accent);
  color: white;
}

.patient-chips-scroll-btn[hidden] {
  display: none;
}

.patient-selector-actions {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-shrink: 0;
}

.patient-chips-container {
  display: flex;
  flex-wrap: nowrap;
  gap: var(--space-2);
  flex: 1;
  min-width: 0;
  /* Critical for grid/flex to constrain */
  max-width: 100%;
  /* Ensure container doesn't overflow grid cell */
  overflow-x: auto;
  overflow-y: visible;
  /* Allow hover elevation to show border */
  scrollbar-width: none;
  /* Hide scrollbar, use arrows instead */
  -ms-overflow-style: none;
  scroll-behavior: smooth;
  padding: 2px 0;
  /* Space for hover transform + border */
  margin: -2px 0;
  /* Compensate padding to keep alignment */
}

.patient-chips-container::-webkit-scrollbar {
  display: none;
  /* Hide scrollbar for Chrome/Safari */
}

.patient-chips-loading {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  font-style: italic;
}

/* Patient Chip Styles */
.patient-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-3);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--color-text);
  background: var(--color-surface-elevated);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
  flex-shrink: 0;
}

.patient-chip:hover:not(.patient-chip--selected):not(.patient-chip--locked) {
  background: var(--color-slate-100);
  border-color: var(--color-accent);
  transform: translateY(-1px);
}

.patient-chip--selected {
  background: var(--color-accent);
  border-color: var(--color-accent);
  color: white;
  box-shadow: var(--shadow-sm);
}

.patient-chip--locked {
  cursor: default;
  opacity: 0.6;
}

.patient-chip--locked:not(.patient-chip--selected) {
  display: none;
  /* Hide non-selected chips when locked */
}

/* PRD v4.3: Single patient chip - non-interactive */
.patient-chip--single {
  cursor: default;
}

.patient-chip--single:hover {
  transform: none;
  background: var(--color-accent);
  border-color: var(--color-accent);
}

/* New Chat Button */
.new-chat-button {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-3);
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-accent);
  background: white;
  border: 1px solid var(--color-accent);
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: all var(--transition-fast);
  flex-shrink: 0;
  white-space: nowrap;
}

.new-chat-button:hover {
  background: var(--color-accent);
  color: white;
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.new-chat-icon {
  font-size: var(--text-base);
  font-weight: 700;
}

.new-chat-text {
  white-space: nowrap;
}

/* Responsive */
@media (max-width: 480px) {
  .chat-patient-selector {
    flex-wrap: wrap;
  }

  .patient-selector-label {
    width: 100%;
    margin-bottom: var(--space-1);
  }

  .new-chat-text {
    display: none;
  }
}

/* Dark mode preparation (future) */
@media (prefers-color-scheme: dark) {
  /* Dark mode variables would go here */
}

/* ============================================
   PRD v4.7: Segment Control for Plot/Table View Toggle
   ============================================ */

/* Header with title and segment control */
.chat-plot-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-5);
  background: var(--color-slate-50);
  border-bottom: 1px solid var(--color-border-light);
}

.chat-plot-header h3 {
  margin: 0;
  padding: 0;
  background: transparent;
  border-bottom: none;
  font-family: var(--font-display);
  font-size: var(--text-lg);
  color: var(--color-text);
}

/* Segment Control Container */
.view-segment-control {
  display: flex;
  align-items: center;
  position: relative;
  background: var(--color-slate-200);
  border-radius: var(--radius-full);
  padding: 3px;
  gap: 0;
}

/* Sliding indicator behind active button */
.segment-indicator {
  position: absolute;
  left: 3px;
  top: 3px;
  width: calc(50% - 4px);
  height: calc(100% - 6px);
  background: white;
  border-radius: var(--radius-full);
  box-shadow: var(--shadow-sm);
  transition: transform 250ms ease;
  z-index: 0;
}

.view-segment-control[data-active="table"] .segment-indicator {
  transform: translateX(calc(100% + 2px));
}

/* Segment Button */
.segment-button {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background: transparent;
  border: none;
  border-radius: var(--radius-full);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: color 200ms ease;
  position: relative;
  z-index: 1;
}

.segment-button:hover {
  color: var(--color-text);
}

.segment-button--active {
  color: var(--color-text);
  font-weight: 600;
}

.segment-button:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

/* Segment Icon (inline SVG) */
.segment-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

/* Main content area: sidebar + view container (grid layout) */
.chat-plot-content {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 0;
}

/* Parameter selector panel with internal scroll - PRD v4.7 override */
.chat-plot-content .chat-parameter-selector-panel {
  max-height: 500px;
  overflow-y: auto;
}

.chat-plot-content .chat-parameter-selector-title {
  position: sticky;
  top: 0;
  background: var(--color-slate-50);
  z-index: 1;
  padding-bottom: var(--space-2);
  margin-bottom: var(--space-2);
}

/* View container with fixed height */
.chat-view-container {
  position: relative;
  height: 500px;
  overflow: hidden;
}

/* Individual views with fade transition (uses visibility, NOT hidden attribute) */
.chat-view {
  position: absolute;
  inset: 0;
  opacity: 0;
  visibility: hidden;
  transition: opacity 250ms ease, visibility 250ms ease;
}

.chat-view--active {
  opacity: 1;
  visibility: visible;
}

/* Plot view specific */
.chat-view--plot {
  display: flex;
  flex-direction: column;
}

.chat-view--plot .chat-plot-canvas-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: var(--space-5);
  min-height: 0; /* Allow flex shrinking */
  max-height: none; /* Override existing constraints */
}

.chat-view--plot .chat-plot-canvas-wrapper canvas {
  flex: 1;
  max-height: none !important; /* Override existing 420px constraint */
}

/* Table view specific */
.chat-view--table {
  background: var(--color-surface-elevated);
}

/* Scrollable table with sticky header */
.chat-scrollable-table-container {
  height: 100%;
  overflow-y: auto;
  padding: var(--space-4);
}

/* Sticky header: apply to th for cross-browser support */
.chat-scrollable-table-container th {
  position: sticky;
  top: 0;
  background: var(--color-slate-50);
  z-index: 1;
}

/* Ensure table fills width */
.chat-scrollable-table-container .parameters-table {
  width: 100%;
}

/* No data placeholder row */
.chat-scrollable-table-container .no-data-row td {
  text-align: center;
  color: var(--color-text-muted);
  font-style: italic;
  padding: var(--space-6);
}

/* Reduced motion: disable all segment control and view transitions */
@media (prefers-reduced-motion: reduce) {
  .segment-indicator,
  .chat-view {
    transition: none;
  }
}

/* Responsive: stack layout on mobile */
@media (max-width: 768px) {
  .chat-plot-header {
    flex-direction: column;
    gap: var(--space-3);
    align-items: flex-start;
  }

  .chat-plot-content {
    grid-template-columns: 1fr;
  }

  .chat-plot-content .chat-parameter-selector-panel {
    max-height: none;
    border-right: none;
    border-bottom: 1px solid var(--color-border-light);
  }

  .chat-view-container {
    height: 400px;
  }
}

/* ============================================
   PRD v6.0: Chat Inline Upload
   ============================================ */

/* Attachment Button */
.chat-attach-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  background: transparent;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  font-size: 1.25rem;
  cursor: pointer;
  transition: all var(--transition-fast);
  flex-shrink: 0;
}

.chat-attach-btn:hover:not(:disabled) {
  background: var(--color-slate-50);
  border-color: var(--color-accent);
}

.chat-attach-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.chat-attach-btn svg {
  width: 20px;
  height: 20px;
  stroke: var(--color-slate-500);
  transition: stroke var(--transition-fast);
}

.chat-attach-btn:hover:not(:disabled) svg {
  stroke: var(--color-accent);
}

/* PRD v10.1: Attachment Menu */
.attach-menu {
  position: absolute;
  bottom: 100%;
  left: 0;
  margin-bottom: 8px;
  min-width: 200px;
  background: white;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.15);
  padding: 4px 0;
  z-index: 1000;
}

.attach-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 16px;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 14px;
  color: #1a1a1a;
  text-align: left;
  transition: background-color 0.15s;
}

.attach-menu-item:hover:not(:disabled) {
  background-color: #f3f4f6;
}

.attach-menu-item:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.attach-menu-icon {
  font-size: 16px;
  flex-shrink: 0;
}

.attach-menu-label {
  flex: 1;
}

/* Hidden file input */
.chat-file-input {
  display: none;
}

/* Drag-Drop Overlay */
.chat-drop-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  pointer-events: none;
}

.chat-drop-overlay span {
  color: white;
  font-size: var(--text-2xl);
  font-weight: 600;
  padding: var(--space-6) var(--space-8);
  border: 3px dashed white;
  border-radius: var(--radius-xl);
}

/* Upload Card Base */
.chat-bubble-upload {
  background: var(--color-surface-elevated);
  border: 1px solid var(--color-border);
  padding: 0;
  min-width: 280px;
  max-width: 400px;
  white-space: normal;
  line-height: 1.4;
}

.upload-card {
  padding: var(--space-3);
}

.upload-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
}

.upload-title {
  font-weight: 500;
  font-size: var(--text-sm);
  color: var(--color-text);
}

.upload-file-icon {
  font-size: 1.25rem;
  flex-shrink: 0;
}

.upload-filename {
  flex: 1;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.upload-batch-title {
  flex: 1;
  font-weight: 600;
  font-size: var(--text-base);
}

.upload-cancel-btn {
  width: 24px;
  height: 24px;
  padding: 0;
  background: transparent;
  border: none;
  font-size: 1.25rem;
  color: var(--color-text-muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
}

.upload-cancel-btn:hover {
  background: var(--color-slate-100);
  color: var(--color-text);
}

/* Progress Bar */
.upload-card-progress {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.upload-progress-bar {
  flex: 1;
  height: 6px;
  background: var(--color-slate-200);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.upload-progress-fill {
  height: 100%;
  background: var(--color-accent);
  border-radius: var(--radius-full);
  transition: width 0.3s ease;
}

.upload-status-text {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  white-space: nowrap;
}

/* Multi-file list */
.upload-file-list {
  margin-bottom: var(--space-2);
}

.upload-file-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1) 0;
  font-size: var(--text-xs);
}

.upload-file-row:not(:last-child) {
  border-bottom: 1px solid var(--color-border-light);
  padding-bottom: var(--space-1);
  margin-bottom: var(--space-1);
}

.upload-filename {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--color-text-secondary);
}

.upload-file-status {
  flex-shrink: 0;
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

.upload-file-status--pending {
  color: var(--color-text-muted);
}

.upload-file-status--processing {
  color: var(--color-info);
}

.upload-file-status--completed {
  color: var(--color-success);
  font-weight: 500;
}

.upload-file-status--failed {
  color: var(--color-error);
}

/* Progress bar container */
.upload-card-progress {
  margin-top: var(--space-2);
}

/* Completed state */
.chat-bubble-upload-complete {
  border-color: var(--color-success);
  background: var(--color-success-light);
}

.upload-done-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-2);
  background: var(--color-success);
  color: white;
  font-size: var(--text-xs);
  font-weight: 600;
  border-radius: var(--radius-sm);
}

.upload-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: var(--space-2);
  padding-top: var(--space-2);
  border-top: 1px solid var(--color-border-light);
}

.upload-meta {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
}

.upload-view-btn {
  padding: var(--space-1) var(--space-3);
  background: var(--color-accent);
  color: white;
  font-size: var(--text-sm);
  font-weight: 500;
  text-decoration: none;
  border-radius: var(--radius-md);
  transition: all var(--transition-fast);
}

.upload-view-btn:hover {
  background: var(--color-accent-hover);
}

/* Inline View button in file row - smaller/more compact */
.upload-file-row .upload-view-btn {
  padding: 2px var(--space-2);
  font-size: var(--text-xs);
  flex-shrink: 0;
  margin-left: var(--space-2);
}

/* Error state */
.upload-file-row--error {
  color: var(--color-error);
}

.upload-file-row--error .status-icon {
  color: var(--color-error);
}

/* PRD v10.0: Upload card error state (interrupted jobs) */
.upload-card-error {
  border: 2px solid var(--color-error, #dc2626);
  background: var(--color-error-light, #fee2e2);
}

.upload-card-error .upload-card-status.error {
  color: var(--color-error, #dc2626);
  font-weight: 500;
}

.upload-card-error .upload-card-hint {
  display: block;
  margin-top: var(--space-2, 8px);
  font-size: var(--text-xs, 12px);
  color: var(--color-text-secondary, #666);
}

/* PRD v10.0: Upload card warning state (upload succeeded, LLM failed) */
.upload-card-warning {
  border: 2px solid var(--color-warning, #d97706);
  background: var(--color-warning-light, #fef3c7);
}

.upload-card-warning .upload-card-status.success {
  color: var(--color-success, #059669);
}

.upload-card-warning .upload-card-status.warning {
  color: var(--color-warning, #d97706);
  font-weight: 500;
}

/* PRD v10.0: Retry button for failed LLM analysis */
.upload-retry-btn {
  display: inline-block;
  margin-top: var(--space-2, 8px);
  padding: var(--space-1, 4px) var(--space-3, 12px);
  font-size: var(--text-xs, 12px);
  font-weight: 500;
  background-color: var(--color-accent, #16a34a);
  color: white;
  border: none;
  border-radius: var(--radius-sm, 4px);
  cursor: pointer;
  transition: background-color 0.15s;
}

.upload-retry-btn:hover {
  background-color: var(--color-accent-hover, #15803d);
}

.upload-retry-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* Toast Notification */
.chat-toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  padding: var(--space-3) var(--space-5);
  background: var(--color-slate-800);
  color: white;
  border-radius: var(--radius-lg);
  font-size: var(--text-sm);
  font-weight: 500;
  z-index: 1000;
  animation: toastSlideIn 0.3s ease, toastFadeOut 0.3s ease 2.7s forwards;
  box-shadow: var(--shadow-lg);
}

.chat-toast--success {
  background: var(--color-success);
}

.chat-toast--error {
  background: var(--color-error);
}

@keyframes toastSlideIn {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

@keyframes toastFadeOut {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
  }
}

/* Responsive adjustments for upload UI */
@media (max-width: 768px) {
  .chat-bubble-upload {
    max-width: 90%;
  }

  .chat-attach-btn {
    width: 40px;
    height: 40px;
  }
}

/* ============================================
   PRD v8.0: Slide-Over Detail Panel
   ============================================ */

/* Panel Layout Container - owns viewport height */
.chat-panel-layout {
  display: flex;
  flex-direction: row;
  height: calc(100vh - var(--header-height) - var(--space-8) * 2 - var(--space-8));
  min-height: 500px;
  gap: 0;
  position: relative;
}

/* Chat container within panel layout - parent owns height */
.chat-panel-layout .chat-container {
  flex: 1 1 100%;
  height: 100%;
  min-width: 0;
  transition: flex-basis 300ms ease-out;
}

/* When panel is open, chat shrinks to 40% (panel gets 60% for better chart viewing) */
.chat-panel-layout.panel-open .chat-container {
  flex-basis: 40%;
}

/* Detail Panel - slide-over from right */
.detail-panel {
  flex: 0 0 0;
  overflow: hidden;
  background: var(--color-surface-elevated);
  border-radius: var(--radius-xl);
  border: 1px solid var(--color-border-light);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  height: 100%;
  opacity: 0;
  transition: flex-basis 300ms ease-out, opacity 200ms ease-out, margin-left 300ms ease-out;
  margin-left: 0;
}

/* Panel visible state */
.chat-panel-layout.panel-open .detail-panel {
  flex-basis: 60%;
  opacity: 1;
  margin-left: var(--space-4);
}

/* Panel Header */
.detail-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--color-border-light);
  flex-shrink: 0;
}

.detail-panel-title {
  margin: 0;
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--color-text);
  font-family: var(--font-display);
}

.detail-panel-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  background: transparent;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  color: var(--color-text-secondary);
  font-size: var(--text-xl);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.detail-panel-close:hover {
  background: var(--color-slate-100);
  border-color: var(--color-border-dark);
  color: var(--color-text);
}

.detail-panel-close:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

/* Panel Content Area */
.detail-panel-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: var(--space-4);
}

/* Thumbnail Selected State */
.chat-plot-thumbnail.thumbnail-selected {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 2px var(--color-accent-light);
}

/* Reduced Motion Support */
@media (prefers-reduced-motion: reduce) {
  .chat-panel-layout .chat-container,
  .detail-panel {
    transition: none;
  }
}

/* When panel is open, use full viewport width (remove 1400px cap) */
.content-body:has(.panel-open) {
  max-width: none;
}

/* Responsive: Stack panels on mobile */
@media (max-width: 1024px) {
  .chat-panel-layout {
    flex-direction: column;
  }

  .chat-panel-layout .chat-container {
    flex-basis: 100% !important;
    height: 100%;
    transition: height 300ms ease-out;
  }

  .chat-panel-layout.panel-open .chat-container {
    height: 50%;
  }

  .detail-panel {
    flex-basis: 0;
    margin-left: 0;
    margin-top: 0;
  }

  .chat-panel-layout.panel-open .detail-panel {
    flex-basis: 50%;
    margin-left: 0;
    margin-top: var(--space-4);
  }
}

/* ============================================
   PRD v9.0: Conversation History Sidebar
   ============================================ */

.sidebar-conversations {
  display: flex;
  flex-direction: column;
  padding: var(--space-3) var(--space-2);
  border-top: 1px solid var(--color-border-light);
  overflow: hidden;
  max-height: 300px;
}

.sidebar-conversations-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-2) var(--space-2);
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.sidebar-new-chat-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  padding: 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--color-accent);
  background: transparent;
  border: 1px solid var(--color-accent);
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.sidebar-new-chat-btn:hover {
  background: var(--color-accent);
  color: white;
}

.sidebar-conversations-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.conversation-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-2) var(--space-3);
  background: transparent;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background var(--transition-fast);
  text-align: left;
  width: 100%;
}

.conversation-item:hover {
  background: var(--color-slate-100);
}

.conversation-item-active,
.conversation-item-active:hover {
  background: var(--color-accent-light);
}

.conversation-item-content {
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

.conversation-item-title {
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--color-text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conversation-item-active .conversation-item-title {
  color: var(--color-accent);
}

.conversation-item-time {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  margin-top: 2px;
}

.conversation-item-delete {
  display: none;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  padding: 0;
  font-size: 12px;
  color: var(--color-text-muted);
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
  flex-shrink: 0;
  margin-left: var(--space-2);
}

.conversation-item:hover .conversation-item-delete {
  display: flex;
}

.conversation-item-delete:hover {
  color: var(--color-error);
  background: var(--color-error-light);
}

.no-conversations {
  padding: var(--space-4);
  text-align: center;
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

.sidebar-show-more {
  display: block;
  width: 100%;
  padding: var(--space-2);
  margin-top: var(--space-2);
  font-size: var(--text-sm);
  color: var(--color-accent);
  background: transparent;
  border: none;
  cursor: pointer;
  transition: background var(--transition-fast);
  border-radius: var(--radius-md);
}

.sidebar-show-more:hover {
  background: var(--color-slate-100);
}
