/* AI Analysis Drawer Styles */

.ai-drawer {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1000;
  display: none;
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none; /* Don't block clicks */
}

.ai-drawer.open {
  display: flex;
  opacity: 1;
}

/* Remove overlay completely - no background covering */
.ai-drawer-overlay {
  display: none; /* Hide the overlay completely */
}

/* Allow interaction with main content when drawer is open */
body.drawer-open .ai-drawer {
  pointer-events: auto;
}

.ai-drawer-content {
  position: absolute;
  top: 0;
  right: 0;
  width: 60vw; /* Increased width for two columns */
  height: 100%;
  background: var(--primary-bg);
  border-left: 1px solid var(--border-muted);
  box-shadow: -4px 0 24px rgba(0, 0, 0, 0.15);
  transform: translateX(100%);
  transition: transform 0.3s ease;
  display: flex;
  flex-direction: column;
  pointer-events: auto; /* Only the drawer content can be clicked */
}

.ai-drawer.open .ai-drawer-content {
  transform: translateX(0);
}

.ai-drawer-header {
  padding: 1.5rem;
  border-bottom: 1px solid var(--border-muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--nav-bg);
}

.ai-drawer-header h3 {
  color: var(--text-strong);
  font-size: 1.25rem;
  font-weight: 600;
  margin: 0;
}

.close-ai-drawer {
  background: none;
  border: none;
  padding: 0.5rem;
  border-radius: 6px;
  color: var(--text-medium);
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.close-ai-drawer:hover {
  background: var(--button-hover-bg);
  color: var(--text-strong);
}

.ai-drawer-body {
  flex: 1;
  padding: 1.5rem;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* Two-column layout */
.ai-drawer-columns {
  flex: 1;
  display: flex;
  gap: 1rem;
  overflow: hidden;
}

.ai-analysis-column {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.icd10-tree-column {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.icd10-section {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

.icd10-section h4 {
  color: var(--text-strong);
  font-size: 1rem;
  font-weight: 600;
  margin: 0 0 0.75rem 0;
  flex-shrink: 0;
}

.icd10-search {
  position: relative;
  margin-bottom: 1rem;
  flex-shrink: 0;
}

.icd10-search-input {
  width: 100%;
  padding: 0.5rem 2rem 0.5rem 0.75rem;
  border: 1px solid var(--input-border);
  border-radius: 6px;
  background: var(--input-bg);
  color: var(--text-medium);
  font-size: 0.9rem;
}

.icd10-search i {
  position: absolute;
  right: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  width: 16px;
  height: 16px;
}

.icd10-tree-container {
  flex: 1;
  overflow-y: auto;
  padding-right: 0.5rem;
}

/* ICD-10 Tree Structure */
.icd10-category {
  margin-bottom: 0.5rem;
}

.icd10-category-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem;
  cursor: pointer;
  border-radius: 6px;
  transition: background-color 0.2s ease;
  user-select: none;
}

.icd10-category-header:hover {
  background: var(--button-hover-bg);
}

.icd10-category-header.checked {
  background: rgba(76, 175, 80, 0.1);
}

.icd10-expand-icon {
  width: 16px;
  height: 16px;
  color: var(--text-medium);
  transition: transform 0.2s ease;
  flex-shrink: 0;
}

.icd10-category.expanded .icd10-expand-icon {
  transform: rotate(90deg);
}

.icd10-checkbox {
  width: 16px;
  height: 16px;
  margin: 0;
  cursor: pointer;
  flex-shrink: 0;
}

.icd10-category-title {
  font-weight: 600;
  color: var(--text-strong);
  font-size: 0.9rem;
  flex: 1;
}

.icd10-category-code {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-family: monospace;
  flex-shrink: 0;
}

.icd10-subcategories {
  margin-left: 1.5rem;
  display: none;
  border-left: 1px solid var(--border-muted);
  padding-left: 1rem;
}

.icd10-category.expanded .icd10-subcategories {
  display: block;
}

.icd10-diagnosis {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.25rem 0.5rem;
  margin-bottom: 0.25rem;
  border-radius: 4px;
  transition: background-color 0.2s ease;
  cursor: pointer;
}

.icd10-diagnosis:hover {
  background: var(--button-hover-bg);
}

.icd10-diagnosis.checked {
  background: rgba(76, 175, 80, 0.1);
}

.icd10-diagnosis-title {
  font-size: 0.85rem;
  color: var(--text-medium);
  flex: 1;
}

.icd10-diagnosis-code {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-family: monospace;
  flex-shrink: 0;
}

.ai-response-section,
.ai-controls-section {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 1rem;
}

.ai-response-section.full-height {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.ai-response-section h4 {
  color: var(--text-strong);
  font-size: 1rem;
  font-weight: 600;
  margin: 0 0 0.75rem 0;
  flex-shrink: 0;
}

.ai-response-content {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.ai-response-text {
  flex: 1;
  overflow-y: auto;
  padding-right: 0.5rem;
}

.ai-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: 2rem 1rem;
  color: var(--text-medium);
}

.loading-spinner {
  width: 24px;
  height: 24px;
  border: 2px solid var(--border-muted);
  border-top: 2px solid var(--accent-color);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.ai-loading p {
  margin: 0;
  font-size: 0.9rem;
}

.ai-response-text {
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: 8px;
  padding: 1rem;
  min-height: 100px;

  overflow-y: auto;
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--text-medium);
}

.ai-response-text p {
  margin: 0 0 0.75rem 0;
}

.ai-response-text p:last-child {
  margin-bottom: 0;
}

.ai-response-text strong {
  color: var(--text-strong);
  font-weight: 600;
}

.ai-response-text em {
  color: var(--accent-color);
  font-style: normal;
  font-weight: 500;
}

/* Emoji and structured content styling */
.ai-response-text ul {
  margin: 0.5rem 0;
  padding-left: 1.25rem;
}

.ai-response-text li {
  margin-bottom: 0.25rem;
}

.ai-response-text h1, 
.ai-response-text h2, 
.ai-response-text h3, 
.ai-response-text h4 {
  color: var(--text-strong);
  margin: 1rem 0 0.5rem 0;
}

.ai-response-text h1:first-child,
.ai-response-text h2:first-child,
.ai-response-text h3:first-child,
.ai-response-text h4:first-child {
  margin-top: 0;
}

/* Medical Category Color Coding - Simplified */
.medical-category {
  margin: 0.5rem 0;
  padding: 0;
  border: none;
  background: none;
}

/* Medical Report Styling - Match App Color Theme */
.medical-report {
  font-family: Roboto, -apple-system, BlinkMacSystemFont, "Segoe UI", Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-medium);
  background-color: var(--primary-bg);
  padding: 15px;
  border-radius: 4px;
  white-space: pre-wrap;
}

/* Color classes for medical terms - using fixed colors */
.medical-report .red { color: #ff5252; }
.medical-report .green { color: #4caf50; }
.medical-report .blue { color: #2196f3; }
.medical-report .yellow { color: #ffeb3b; }
.medical-report .orange { color: #ff9800; }
.medical-report .purple { color: #9c27b0; }
.medical-report .cyan { color: #00bcd4; }
.medical-report .teal { color: #009688; }
.medical-report .lime { color: #cddc39; }
.medical-report .brown { color: #795548; }
.medical-report .pink { color: #e91e63; }
.medical-report .white { color: #ffffff; }
.medical-report .gray { color: #9e9e9e; }
.medical-report .highlight-blue { 
  background-color: var(--info-blue); 
  color: var(--primary-bg); 
  padding: 1px 3px;
  border-radius: 2px;
}
.medical-report .highlight-green { 
  background-color: var(--low-risk); 
  color: var(--primary-bg); 
  padding: 1px 3px;
  border-radius: 2px;
}

/* Legacy styling for backwards compatibility */
.medical-report-structured {
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--text-medium);
}

.medical-section {
  margin: 0.5rem 0;
  padding: 0.25rem 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.medical-section:last-child {
  border-bottom: none;
}

.section-header {
  color: var(--text-strong);
  font-weight: bold;
  display: inline-block;
  min-width: 80px;
  margin-right: 0.5rem;
}

.section-content {
  color: var(--text-medium);
}

.exam-details, .assessment-content, .plan-content {
  margin-left: 0;
  padding-left: 0;
}

.exam-item, .assessment-item, .plan-item {
  margin: 0.25rem 0;
  padding: 0;
  font-size: 0.9rem;
}

/* Simplified styling - no complex color categories needed */

/* Exam details */
.exam-details {
  margin-top: 0.5rem;
  padding-left: 1rem;
}

.exam-item {
  margin: 0.25rem 0;
  font-size: 0.85rem;
}

.exam-item strong {
  color: var(--text-strong);
  min-width: 60px;
  display: inline-block;
}

/* Assessment section */
.assessment-section {
  background: rgba(255, 193, 7, 0.05);
  border-radius: 8px;
  padding: 0.75rem;
}

.assessment-content {
  margin-top: 0.5rem;
  padding-left: 1rem;
}

.assessment-item {
  margin: 0.25rem 0;
}

.assessment-item strong {
  color: #ffc107;
}

/* Plan section */
.plan-section {
  background: rgba(76, 175, 80, 0.05);
  border-radius: 8px;
  padding: 0.75rem;
}

.plan-content {
  margin-top: 0.5rem;
  padding-left: 1rem;
}

.plan-item {
  margin: 0.25rem 0;
}

.plan-item strong {
  color: #4caf50;
}

/* Fallback text format */
.medical-report-text {
  font-family: 'Courier New', monospace;
  font-size: 0.85rem;
  line-height: 1.4;
  color: var(--text-medium);
}

.medical-report-text pre {
  margin: 0;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.ai-error {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 1.5rem;
  background: rgba(255, 82, 82, 0.1);
  border: 1px solid rgba(255, 82, 82, 0.3);
  border-radius: 8px;
  color: var(--high-risk);
}

.error-message {
  margin: 0 0 0.75rem 0;
  text-align: center;
  font-size: 0.9rem;
}

.retry-btn {
  background: var(--high-risk);
  color: white;
  border: none;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  font-size: 0.8rem;
  cursor: pointer;
  transition: opacity 0.2s ease;
}

.retry-btn:hover {
  opacity: 0.8;
}

.ai-controls-section {
  flex-shrink: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  margin-top: 1rem;
}

.processing-status {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  color: var(--text-medium);
}

.status-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--low-risk);
  transition: background-color 0.3s ease;
}

.status-indicator.processing {
  background: var(--medium-risk);
  animation: pulse 1.5s ease-in-out infinite;
}

.status-indicator.error {
  background: var(--high-risk);
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.manual-refresh-btn {
  background: var(--accent-color);
  color: white;
  border: none;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  font-size: 0.9rem;
  cursor: pointer;
  transition: opacity 0.2s ease;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.manual-refresh-btn:hover {
  opacity: 0.8;
}

.manual-refresh-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Responsive Design */
@media (max-width: 1200px) {
  .ai-drawer-content {
    width: 90%;
  }
}

@media (max-width: 768px) {
  .ai-drawer-content {
    width: 100%;
    right: 0;
  }
  
  .ai-drawer-columns {
    flex-direction: column;
  }
  
  .ai-analysis-column,
  .icd10-tree-column {
    flex: none;
    height: 300px;
  }
  
  .ai-drawer-header {
    padding: 1rem;
  }
  
  .ai-drawer-body {
    padding: 1rem;
    gap: 1rem;
  }
  
  .ai-response-section,
  .icd10-section {
    padding: 0.875rem;
  }
}

@media (max-width: 480px) {
  .ai-drawer-header {
    padding: 0.75rem;
  }
  
  .ai-drawer-header h3 {
    font-size: 1.1rem;
  }
  
  .ai-drawer-body {
    padding: 0.75rem;
  }
  
  .ai-controls-section {
    flex-direction: column;
    gap: 0.75rem;
    align-items: stretch;
  }
  
  .manual-refresh-btn {
    justify-content: center;
  }
}

/* Theme-specific adjustments */
:root.light-theme .ai-drawer-content {
  background: var(--primary-bg);
  border-left: 1px solid var(--border-muted);
  box-shadow: -4px 0 24px rgba(0, 0, 0, 0.1);
}

:root.light-theme .ai-drawer-overlay {
  background: rgba(0, 0, 0, 0.3);
}
