/**
 * EMR (Electronic Medical Records) Viewer Styles
 * Personal Health Record Dashboard
 */

/* ============================================
   EMR Container
   ============================================ */

.emr-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 24px;
}

.emr-header {
    margin-bottom: 24px;
}

.emr-header-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 16px;
    margin-bottom: 16px;
}

.emr-header h1 {
    font-size: 28px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.emr-header-actions {
    display: flex;
    gap: 12px;
}

/* ============================================
   Stats Overview
   ============================================ */

.emr-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.emr-stat-card {
    background: var(--surface-primary);
    border: 1px solid var(--border-primary);
    border-radius: 12px;
    padding: 20px;
    text-align: center;
}

.emr-stat-value {
    font-size: 32px;
    font-weight: 700;
    color: var(--accent-primary);
}

.emr-stat-label {
    font-size: 14px;
    color: var(--text-secondary);
    margin-top: 4px;
}

.emr-stat-sublabel {
    font-size: 12px;
    color: var(--text-tertiary);
}

/* ============================================
   Category Navigation
   ============================================ */

.emr-categories {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 24px;
    padding: 16px;
    background: var(--surface-secondary);
    border-radius: 12px;
}

.emr-category-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    background: var(--surface-primary);
    border: 1px solid var(--border-primary);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 14px;
    color: var(--text-secondary);
}

.emr-category-btn:hover {
    border-color: var(--accent-primary);
    color: var(--text-primary);
}

.emr-category-btn.active {
    background: var(--accent-primary);
    color: var(--text-on-accent);
    border-color: var(--accent-primary);
}

.emr-category-btn .count {
    background: rgba(0, 0, 0, 0.1);
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
}

.emr-category-btn.active .count {
    background: rgba(255, 255, 255, 0.2);
}

/* ============================================
   Category Icons
   ============================================ */

.emr-category-icon {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ============================================
   Content Area
   ============================================ */

.emr-content {
    display: grid;
    grid-template-columns: 1fr 300px;
    gap: 24px;
}

@media (max-width: 1024px) {
    .emr-content {
        grid-template-columns: 1fr;
    }
}

/* Timeline Content - Full-width stacked layout */
.emr-timeline-content {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

/* ============================================
   Entry List
   ============================================ */

.emr-entries {
    background: var(--surface-primary);
    border: 1px solid var(--border-primary);
    border-radius: 12px;
    overflow: hidden;
}

.emr-entries-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-primary);
    background: var(--surface-secondary);
}

.emr-entries-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
}

.emr-entries-filters {
    display: flex;
    gap: 12px;
    align-items: center;
}

.emr-entries-list {
    max-height: 600px;
    overflow-y: auto;
}

.emr-entry {
    padding: 16px 20px;
    min-height: 44px;
    border-bottom: 1px solid var(--border-secondary);
    cursor: pointer;
    transition: background 0.2s ease;
}

.emr-entry:hover {
    background: var(--surface-hover);
}

.emr-entry:last-child {
    border-bottom: none;
}

/* Citation highlight (Cycle 7) — applied when clicking a citation pill in chat */
.emr-entry-cited {
    animation: emr-cite-pulse 2.5s ease forwards;
}
@keyframes emr-cite-pulse {
    0% { box-shadow: 0 0 0 0 var(--color-primary, #14b8a6); background: rgba(59,130,246,.08); }
    20% { box-shadow: 0 0 0 3px var(--color-primary, #14b8a6); background: rgba(59,130,246,.12); }
    100% { box-shadow: none; background: transparent; }
}

.emr-entry-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 8px;
}

.emr-entry-title {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 15px;
}

.emr-entry-date {
    font-size: 12px;
    color: var(--text-tertiary);
}

.emr-entry-body {
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.5;
}

.emr-entry-meta {
    display: flex;
    gap: 16px;
    margin-top: 8px;
    font-size: 12px;
    color: var(--text-tertiary);
}

.emr-entry-meta span {
    display: flex;
    align-items: center;
    gap: 4px;
}

/* Entry Type Badges */
.emr-entry-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
}

.emr-entry-badge.medication { background: #ccfbf1; color: #0d9488; }
.emr-entry-badge.lab { background: #F3E5F5; color: #7B1FA2; }
.emr-entry-badge.diagnosis { background: #FFEBEE; color: #C62828; }
.emr-entry-badge.procedure { background: #E8F5E9; color: #2E7D32; }
.emr-entry-badge.immunization { background: #FFF3E0; color: #EF6C00; }
.emr-entry-badge.allergy { background: #FCE4EC; color: #AD1457; }
.emr-entry-badge.vital { background: #E0F7FA; color: #00838F; }
.emr-entry-badge.encounter { background: #F1F8E9; color: #558B2F; }
.emr-entry-badge.imaging { background: #EDE7F6; color: #5E35B1; }
.emr-entry-badge.note { background: #FFF8E1; color: #FF8F00; }

/* ============================================
   Enhancement Badges (Confidence, Grounding, Med Classification, RxNorm)
   ============================================ */

/* Confidence badge */
.emr-confidence-badge {
    font-size: 12px;
    padding: 1px 6px;
    border-radius: 6px;
    font-weight: 600;
    flex-shrink: 0;
    line-height: 1.4;
}
.emr-confidence-high { background: #dcfce7; color: #166534; }
.emr-confidence-med { background: #fef9c3; color: #854d0e; }
.emr-confidence-low { background: #fee2e2; color: #991b1b; }

/* Grounding icon */
.emr-grounding-icon {
    font-size: 12px;
    flex-shrink: 0;
    cursor: help;
}

/* Medication classification badge */
.emr-med-badge {
    font-size: 12px;
    padding: 1px 6px;
    border-radius: 6px;
    font-weight: 600;
    flex-shrink: 0;
    line-height: 1.4;
}
.emr-med-standing { background: #ccfbf1; color: #0d9488; border: 1px solid #93c5fd; }
.emr-med-episodic { background: #ffedd5; color: #9a3412; border: 1px solid #fdba74; }
.emr-med-newly_prescribed { background: #ede9fe; color: #6b21a8; border: 1px solid #c4b5fd; }
.emr-med-uncertain { background: #fef3c7; color: #92400e; border: 1px solid #fcd34d; }

/* Medication date (inline) */
.emr-med-date {
    font-size: 12px;
    color: var(--text-tertiary, #4b5563);
    font-style: italic;
    flex-shrink: 0;
}

/* RxNorm badge */
.emr-rxnorm-badge {
    font-size: 12px;
    padding: 1px 5px;
    border-radius: 6px;
    font-weight: 600;
    flex-shrink: 0;
    background: #ecfeff;
    color: #0891b2;
    border: 1px solid #7dd3fc;
    cursor: help;
}

/* Flagged entry (low confidence) */
.emr-entry.emr-flagged {
    border-left: 3px solid #ef4444;
}

/* Confidence dimension breakdown */
.emr-dimensions {
    display: flex;
    gap: 12px;
    margin-top: 6px;
    flex-wrap: wrap;
}
.emr-dim {
    font-size: 12px;
}
.emr-dim-label { color: var(--text-tertiary, #4b5563); }
.emr-dim-value { color: var(--text-primary, #333); font-weight: 500; }

/* Medication mentions (classification detail) */
.emr-mentions-section {
    margin-top: 8px;
    padding-top: 6px;
    border-top: 1px dashed var(--border-secondary, #e0e0e0);
}
.emr-mention-item {
    margin-bottom: 6px;
    padding: 6px 8px;
    background: var(--surface-secondary, #f8f9fc);
    border-radius: 6px;
    border-left: 3px solid var(--border-secondary, #c0c4d0);
}
.emr-mention-item:last-child { margin-bottom: 0; }
.emr-mention-type { font-size: 12px; margin-bottom: 2px; }
.emr-mention-verbatim {
    font-size: 12px;
    color: var(--text-secondary, #555);
    font-style: italic;
    line-height: 1.4;
}

/* Enhancement summary on document detail */
.emr-enhancement-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 8px;
    margin-top: 8px;
}
.emr-enhancement-stat {
    padding: 8px 10px;
    border-radius: 6px;
    background: var(--surface-secondary, #f8f9fc);
    border: 1px solid var(--border-secondary, #e5e7eb);
}
.emr-enhancement-stat-label {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-tertiary, #4b5563);
}
.emr-enhancement-stat-value {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary, #1a1a2e);
    margin-top: 2px;
}
.emr-enhancement-stat-value.good { color: #16a34a; }
.emr-enhancement-stat-value.warn { color: #d97706; }
.emr-enhancement-stat-value.bad { color: #dc2626; }

/* Confidence bar (stacked) */
.emr-confidence-bar {
    display: flex;
    height: 6px;
    border-radius: 3px;
    overflow: hidden;
    margin-top: 4px;
    background: #e5e7eb;
}
.emr-confidence-bar .seg-high { background: #22c55e; }
.emr-confidence-bar .seg-med { background: #eab308; }
.emr-confidence-bar .seg-low { background: #ef4444; }

/* ============================================
   Sidebar
   ============================================ */

.emr-sidebar {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.emr-sidebar-card {
    background: var(--surface-primary);
    border: 1px solid var(--border-primary);
    border-radius: 12px;
    padding: 16px;
}

.emr-sidebar-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 12px;
}

/* Recent Documents */
.emr-recent-docs {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.emr-recent-doc {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.2s ease;
}

.emr-recent-doc:hover {
    background: var(--surface-hover);
}

.emr-doc-icon {
    width: 32px;
    height: 32px;
    background: #FFEBEE;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #C62828;
    font-size: 14px;
}

.emr-doc-info {
    flex: 1;
    min-width: 0;
}

.emr-doc-name {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.emr-doc-date {
    font-size: 12px;
    color: var(--text-tertiary);
}

.emr-doc-delete-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px 8px;
    font-size: 14px;
    opacity: 0;
    transition: opacity 0.2s ease;
    border-radius: 4px;
}

.emr-recent-doc:hover .emr-doc-delete-btn {
    opacity: 0.6;
}

.emr-doc-delete-btn:hover {
    opacity: 1 !important;
    background: #FFEBEE;
}

/* Document Status Indicator */
.emr-doc-status {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 2px;
}

.emr-recent-doc.processing .emr-doc-icon {
    background: #FFF3E0;
    animation: pulse 2s infinite;
}

.emr-recent-doc.stage2-pending .emr-doc-icon {
    background: #E8F5E9;
}

.emr-recent-doc.stage2-pending .emr-doc-status {
    color: #43A047;
}

.emr-recent-doc.complete .emr-doc-icon {
    background: #E8F5E9;
}

.emr-recent-doc.error .emr-doc-icon {
    background: #FFEBEE;
}

.emr-recent-doc.stage2-error .emr-doc-status {
    color: #F57C00;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

/* Stage Details in Modal */
.emr-stage-details {
    grid-column: 1 / -1;
}

.emr-stages-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 8px;
    padding: 16px;
    background: var(--surface-secondary);
    border-radius: 8px;
}

.emr-stage-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 8px 12px;
    border-radius: 6px;
    background: var(--surface-primary);
    transition: all 0.2s ease;
}

.emr-stage-icon {
    font-size: 18px;
    flex-shrink: 0;
    width: 24px;
    text-align: center;
}

.emr-stage-info {
    flex: 1;
    min-width: 0;
}

.emr-stage-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 2px;
}

.emr-stage-desc {
    font-size: 12px;
    color: var(--text-tertiary);
}

.emr-stage-status {
    font-size: 12px;
    margin-top: 4px;
    font-weight: 500;
}

.emr-stage-item.complete {
    border-left: 3px solid #43A047;
}

.emr-stage-item.complete .emr-stage-name {
    color: #43A047;
}

.emr-stage-item.pending {
    border-left: 3px solid #FB8C00;
    background: rgba(251, 140, 0, 0.08);
}

.emr-stage-item.pending .emr-stage-status {
    color: #FB8C00;
}

@keyframes pulse-pending {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

.emr-stage-item.pending .emr-stage-icon {
    animation: pulse-pending 1.5s ease-in-out infinite;
}

.emr-stage-item.not-started,
.emr-stage-item.future {
    opacity: 0.5;
    border-left: 3px solid transparent;
}

.emr-stage-item.error {
    border-left: 3px solid #E53935;
    background: rgba(229, 57, 53, 0.08);
}

.emr-stage-item.error .emr-stage-status {
    color: #E53935;
}

.emr-stage-item.skipped {
    border-left: 3px solid #9E9E9E;
    background: rgba(158, 158, 158, 0.08);
    opacity: 0.7;
}

.emr-stage-item.skipped .emr-stage-status {
    color: #757575;
    font-style: italic;
}

/* Stage progress bar for document cards */
.emr-doc-progress {
    display: flex;
    gap: 2px;
    margin-top: 6px;
}

.emr-doc-progress-step {
    flex: 1;
    height: 3px;
    background: var(--surface-tertiary);
    border-radius: 2px;
    transition: background 0.3s ease;
}

.emr-doc-progress-step.complete {
    background: #43A047;
}

.emr-doc-progress-step.pending {
    background: #FB8C00;
}

.emr-doc-progress-step.error {
    background: #E53935;
}

/* Storage Info */
.emr-storage-bar {
    height: 8px;
    background: var(--surface-tertiary);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 8px;
}

.emr-storage-fill {
    height: 100%;
    background: var(--accent-primary);
    border-radius: 4px;
    transition: width 0.3s ease;
}

.emr-storage-text {
    font-size: 12px;
    color: var(--text-secondary);
}

/* ============================================
   Entry Detail Modal
   ============================================ */

.emr-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 24px;
}

.emr-modal {
    background: var(--surface-primary);
    border-radius: 16px;
    max-width: 700px;
    width: 100%;
    max-height: 80vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.emr-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-primary);
}

.emr-modal-title {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-primary);
}

.emr-modal-close {
    background: none;
    border: none;
    font-size: 24px;
    color: var(--text-tertiary);
    cursor: pointer;
    padding: 4px;
    line-height: 1;
}

.emr-modal-close:hover {
    color: var(--text-primary);
}

.emr-modal-body {
    padding: 24px;
    overflow-y: auto;
}

.emr-detail-section {
    margin-bottom: 24px;
}

.emr-detail-section:last-child {
    margin-bottom: 0;
}

.emr-detail-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-tertiary);
    text-transform: uppercase;
    margin-bottom: 4px;
}

.emr-detail-value {
    font-size: 15px;
    color: var(--text-primary);
    line-height: 1.5;
}

.emr-detail-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
}

/* ============================================
   Empty State
   ============================================ */

.emr-empty {
    text-align: center;
    padding: 60px 24px;
}

.emr-empty-icon {
    font-size: 64px;
    margin-bottom: 16px;
}

.emr-empty-title {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.emr-empty-text {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 24px;
}

/* ============================================
   Loading State
   ============================================ */

.emr-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 60px;
}

.emr-loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-primary);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ============================================
   Buttons
   ============================================ */

.emr-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 1px solid transparent;
}

.emr-btn-primary {
    background: var(--accent-primary);
    color: var(--text-on-accent);
}

.emr-btn-primary:hover {
    background: var(--accent-hover);
}

.emr-btn-secondary {
    background: var(--surface-primary);
    color: var(--text-primary);
    border-color: var(--border-primary);
}

.emr-btn-secondary:hover {
    background: var(--surface-hover);
}

.emr-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    pointer-events: none;
}

.emr-btn-danger {
    background: #FFEBEE;
    color: #C62828;
}

.emr-btn-danger:hover {
    background: #FFCDD2;
}

.emr-btn-warning {
    background: #FFF3E0;
    color: #E65100;
}

.emr-btn-warning:hover {
    background: #FFE0B2;
}

/* ============================================
   Search & Filters
   ============================================ */

.emr-search {
    display: flex;
    gap: 12px;
    margin-bottom: 24px;
}

.emr-search-input-wrapper {
    flex: 1;
    display: flex;
    position: relative;
}

.emr-search-input {
    flex: 1;
    padding: 12px 44px 12px 16px;
    border: 1px solid var(--border-primary);
    border-radius: 8px;
    font-size: 14px;
    background: var(--surface-primary);
    color: var(--text-primary);
}

.emr-search-input:focus {
    outline: none;
    border-color: var(--accent-primary);
}

/* Clear search button (X) */
.emr-search-clear {
    position: absolute;
    right: 40px;
    top: 50%;
    transform: translateY(-50%);
    width: 20px;
    height: 20px;
    border: none;
    background: var(--color-gray-200, #e5e7eb);
    color: var(--color-gray-500, #6b7280);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-family: inherit;
    transition: all 0.15s;
}
.emr-search-clear:hover {
    background: var(--color-gray-300, #d1d5db);
    color: var(--color-gray-700, #374151);
}

.emr-search-btn {
    position: absolute;
    right: 4px;
    top: 50%;
    transform: translateY(-50%);
    padding: 8px;
    border: none;
    background: var(--accent-primary);
    color: var(--text-on-accent);
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease;
}

.emr-search-btn:hover {
    background: var(--accent-primary-hover, #0d9488);
}

/* Search loading state: progress bar on input + dimmed entries */
.emr-search-input-wrapper.emr-search-loading::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    height: 2px;
    width: 40%;
    border-radius: 0 0 8px 8px;
    background: var(--accent-primary, #0d9488);
    animation: emr-search-progress 1.2s ease-in-out infinite;
}
@keyframes emr-search-progress {
    0%   { left: 0;   width: 30%; }
    50%  { left: 35%;  width: 40%; }
    100% { left: 100%; width: 0%; }
}

/* Skeleton loading cards */
.emr-skeleton-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    background: #fff;
    border: 1px solid var(--border-primary, #e5e7eb);
    border-radius: 8px;
    margin-bottom: 6px;
}
.emr-skeleton-bar {
    height: 12px;
    background: linear-gradient(90deg, var(--color-gray-100, #f3f4f6) 25%, var(--color-gray-200, #e5e7eb) 50%, var(--color-gray-100, #f3f4f6) 75%);
    background-size: 200% 100%;
    animation: emr-skeleton-shimmer 1.5s infinite;
    border-radius: 4px;
}
.emr-skeleton-bar.w60 { width: 60%; }
.emr-skeleton-bar.w40 { width: 40%; }
.emr-skeleton-bar.w20 { width: 20%; }
@keyframes emr-skeleton-shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.emr-search-btn svg {
    display: block;
}

.emr-filter-select {
    padding: 12px 16px;
    border: 1px solid var(--border-primary);
    border-radius: 8px;
    font-size: 14px;
    background: var(--surface-primary);
    color: var(--text-primary);
    min-width: 150px;
}

/* ============================================
   Responsive
   ============================================ */

@media (max-width: 768px) {
    .emr-container {
        padding: 12px;
    }

    .emr-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }
    .emr-header h2 { font-size: 16px; margin: 0; }
    .emr-header-top { flex-wrap: wrap; gap: 8px; }
    .emr-header-actions { flex-wrap: wrap; gap: 4px; }
    .emr-btn { padding: 6px 10px; font-size: 12px; }

    .emr-stats {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
        margin-bottom: 12px;
    }
    .emr-stat-card { padding: 10px; overflow: hidden; }
    .emr-stat-value { font-size: 20px; overflow: hidden; text-overflow: ellipsis; }
    .emr-stat-label { font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

    .emr-categories {
        overflow-x: auto;
        flex-wrap: nowrap;
        padding: 8px 0;
        scrollbar-width: none;
        -webkit-overflow-scrolling: touch;
    }
    .emr-categories::-webkit-scrollbar { display: none; }

    .emr-category-btn {
        flex-shrink: 0;
        padding: 6px 12px;
        font-size: 12px;
    }

    .emr-search {
        flex-direction: column;
    }

    .emr-detail-grid {
        grid-template-columns: 1fr;
    }
}

/* ============================================
   Drag-and-Drop Upload Overlay
   ============================================ */

.emr-drag-overlay {
    display: none;
    position: absolute;
    inset: 0;
    z-index: 100;
    background: rgba(var(--color-teal-rgb, 20, 184, 166), 0.08);
    border: 2px dashed rgba(var(--color-teal-rgb, 20, 184, 166), 0.6);
    border-radius: 12px;
    pointer-events: none;
}

.emr-drag-overlay-active {
    display: flex;
    align-items: center;
    justify-content: center;
}

.emr-drag-overlay-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 32px 48px;
    background: var(--surface-primary, #fff);
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
    text-align: center;
}

.emr-drag-overlay-icon {
    font-size: 40px;
    line-height: 1;
}

.emr-drag-overlay-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary, #111);
}

.emr-drag-overlay-sub {
    font-size: 13px;
    color: var(--text-secondary, #666);
}

/* ============================================
   Upload Processing Queue
   ============================================ */

.emr-upload-queue {
    background: var(--surface-primary);
    border: 1px solid var(--border-primary);
    border-radius: 12px;
    margin-bottom: 24px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.emr-queue-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: var(--surface-secondary);
    border-bottom: 1px solid var(--border-primary);
}

.emr-queue-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}

.emr-queue-clear {
    font-size: 12px;
    padding: 4px 10px;
    background: transparent;
    border: 1px solid var(--border-primary);
    border-radius: 4px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
}

.emr-queue-clear:hover {
    background: var(--surface-hover);
    color: var(--text-primary);
}

.emr-queue-items {
    max-height: 300px;
    overflow-y: auto;
}

.emr-queue-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-secondary);
    transition: background 0.2s ease;
}

.emr-queue-item:last-child {
    border-bottom: none;
}

.emr-queue-item-icon {
    font-size: 18px;
    width: 24px;
    text-align: center;
    flex-shrink: 0;
}

.emr-queue-item-info {
    flex: 1;
    min-width: 0;
}

.emr-queue-item-name {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: flex;
    align-items: center;
    gap: 8px;
}

.emr-queue-model-badge {
    font-size: 12px;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 4px;
    background: var(--accent-secondary, #ccfbf1);
    color: var(--accent-primary, #0d9488);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    flex-shrink: 0;
}

.emr-queue-item-status {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 2px;
}

.emr-queue-item-progress {
    height: 4px;
    background: var(--surface-tertiary);
    border-radius: 2px;
    margin-top: 6px;
    overflow: hidden;
}

.emr-queue-progress-bar {
    height: 100%;
    background: var(--accent-primary);
    border-radius: 2px;
    transition: width 0.3s ease;
}

.emr-queue-item-size {
    font-size: 12px;
    color: var(--text-tertiary);
    flex-shrink: 0;
}

.emr-queue-cancel {
    background: none;
    border: none;
    font-size: 14px;
    color: var(--text-tertiary);
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.emr-queue-cancel:hover {
    background: #FFEBEE;
    color: #C62828;
}

.emr-queue-entries {
    font-size: 12px;
    padding: 2px 8px;
    background: #E8F5E9;
    color: #2E7D32;
    border-radius: 10px;
    font-weight: 500;
}

/* Queue Item Status Styles */
.emr-queue-pending {
    background: var(--surface-primary);
}

.emr-queue-uploading {
    background: linear-gradient(90deg, rgba(33, 150, 243, 0.05) 0%, transparent 100%);
}

.emr-queue-uploading .emr-queue-progress-bar {
    background: #2196F3;
}

.emr-queue-processing {
    background: linear-gradient(90deg, rgba(156, 39, 176, 0.05) 0%, transparent 100%);
}

.emr-queue-processing .emr-queue-item-icon {
    animation: spin 1.5s linear infinite;
}

.emr-queue-processing .emr-queue-progress-bar {
    background: #9C27B0;
}

/* Indeterminate shimmer for queued/extracting states */
.emr-queue-processing .emr-queue-progress-bar,
.emr-queue-uploading .emr-queue-progress-bar {
    position: relative;
    overflow: hidden;
}

.emr-queue-processing .emr-queue-progress-bar::after,
.emr-queue-uploading .emr-queue-progress-bar::after {
    content: '';
    position: absolute;
    top: 0;
    left: -50%;
    width: 50%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.4), transparent);
    animation: emr-shimmer 1.5s ease-in-out infinite;
}

@keyframes emr-shimmer {
    0%   { left: -50%; }
    100% { left: 150%; }
}

.emr-queue-completed {
    background: linear-gradient(90deg, rgba(76, 175, 80, 0.05) 0%, transparent 100%);
}

.emr-queue-completed .emr-queue-item-status {
    color: #2E7D32;
}

.emr-queue-error {
    background: linear-gradient(90deg, rgba(244, 67, 54, 0.05) 0%, transparent 100%);
}

.emr-queue-error .emr-queue-item-status {
    color: #C62828;
}

/* Responsive */
@media (max-width: 768px) {
    .emr-queue-item {
        flex-wrap: wrap;
    }

    .emr-queue-item-info {
        order: 2;
        width: calc(100% - 36px);
    }

    .emr-queue-item-size,
    .emr-queue-cancel,
    .emr-queue-entries {
        order: 3;
        margin-top: 8px;
    }
}

/* ============================================
   Queue — Intel Panel Compact Variant
   (overrides for 310px right panel context)
   ============================================ */

#v4-intel-queue .emr-upload-queue {
    border: none;
    border-radius: 0;
    padding: 0;
    background: transparent;
}
#v4-intel-queue .emr-queue-header {
    padding: 7px 10px 4px;
}
#v4-intel-queue .emr-queue-title {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .05em;
    text-transform: uppercase;
    color: var(--text-secondary, #6b7280);
}
#v4-intel-queue .emr-queue-clear {
    font-size: 11px;
    padding: 2px 8px;
}
#v4-intel-queue .emr-queue-items {
    max-height: 240px;
    padding: 0 8px 8px;
}
#v4-intel-queue .emr-queue-item {
    padding: 5px 4px;
    gap: 6px;
}
#v4-intel-queue .emr-queue-item-name {
    font-size: 12px;
    max-width: 170px;
}
#v4-intel-queue .emr-queue-item-status {
    font-size: 11px;
}
#v4-intel-queue .emr-queue-item-size {
    font-size: 11px;
}
#v4-intel-queue .emr-queue-entries {
    font-size: 11px;
    padding: 1px 6px;
}
#v4-intel-queue .emr-queue-item-icon {
    font-size: 14px;
    width: 20px;
}

/* ============================================
   Model Selector
   ============================================ */

.emr-model-options {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.emr-model-option {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 16px;
    border: 2px solid var(--border-primary);
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s ease;
    background: var(--surface-primary);
}

.emr-model-option:hover {
    border-color: var(--accent-primary);
    background: var(--surface-hover);
}

.emr-model-option.selected {
    border-color: var(--accent-primary);
    background: rgba(var(--accent-primary-rgb, 59, 130, 246), 0.05);
}

.emr-model-option input[type="radio"] {
    margin-top: 3px;
    accent-color: var(--accent-primary);
}

.emr-model-info {
    flex: 1;
}

.emr-model-name {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.emr-model-desc {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.emr-model-badge {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
}

.emr-model-badge.recommended {
    background: #E8F5E9;
    color: #2E7D32;
}

.emr-model-badge.premium {
    background: #ccfbf1;
    color: #0d9488;
}

.emr-model-badge.alternate {
    background: #FFF3E0;
    color: #E65100;
}

/* ============================================
   Delete Document Modal
   ============================================ */

.emr-delete-modal {
    padding: 8px 0;
}

.emr-delete-modal p {
    margin: 0 0 12px 0;
    color: var(--text-primary);
    line-height: 1.5;
}

.emr-delete-modal .emr-delete-info {
    background: var(--surface-secondary, #f5f5f5);
    padding: 12px 16px;
    border-radius: 8px;
    border-left: 4px solid var(--accent-primary, #2196F3);
}

.emr-delete-modal .emr-delete-warning {
    font-weight: 500;
    color: var(--text-secondary);
    margin-top: 16px;
}

/* Button styling for delete modal */
.modal-footer .btn-warning {
    background: #FF9800;
    color: var(--text-on-accent);
    border: none;
}

.modal-footer .btn-warning:hover {
    background: #F57C00;
}

.modal-footer .btn-danger {
    background: #f44336;
    color: var(--text-on-accent);
    border: none;
}

.modal-footer .btn-danger:hover {
    background: #d32f2f;
}

/* ============================================
   View Mode Tabs (Records / Timeline)
   Increment 11.6 - Derivatives UI
   ============================================ */

.emr-view-tabs {
    display: flex;
    gap: 0;
    background: var(--surface-secondary, #f5f5f5);
    border-radius: 8px;
    padding: 4px;
    width: fit-content;
}

.emr-view-tab {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: none;
    background: transparent;
    color: var(--text-secondary, #666);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.2s ease;
}

.emr-view-tab:hover {
    color: var(--text-primary, #333);
    background: var(--surface-hover, rgba(0, 0, 0, 0.05));
}

.emr-view-tab.active {
    background: var(--surface-primary, #fff);
    color: var(--primary, #2196F3);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

/* ============================================
   Derivative Entry Styles
   ============================================ */

.emr-derivative-entry {
    position: relative;
}

.emr-derivative-entry .emr-entry-meta {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 4px;
}

.emr-derivative-status {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    padding: 2px 8px;
    border-radius: 12px;
    font-weight: 500;
}

.emr-derivative-status.valid {
    background: rgba(76, 175, 80, 0.15);
    color: #2E7D32;
}

.emr-derivative-status.orphaned {
    background: rgba(255, 152, 0, 0.15);
    color: #E65100;
}

.emr-derivative-status.unknown {
    background: rgba(158, 158, 158, 0.15);
    color: #616161;
}

/* Derivative detail modal meta section */
.emr-detail-meta {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border-primary, #eee);
}

/* Form styles for edit modal */
.emr-form-group {
    margin-bottom: 16px;
}

.emr-form-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary, #666);
    margin-bottom: 6px;
}

.emr-form-input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-primary, #ddd);
    border-radius: 6px;
    font-size: 14px;
    color: var(--text-primary, #333);
    background: var(--surface-primary, #fff);
    transition: border-color 0.2s ease;
}

.emr-form-input:focus {
    outline: none;
    border-color: var(--primary, #2196F3);
    box-shadow: 0 0 0 3px rgba(33, 150, 243, 0.1);
}

.emr-form-input::placeholder {
    color: var(--text-tertiary, #4b5563);
}

select.emr-form-input {
    cursor: pointer;
}

/* ============================================
   Derivative Modal Positioning Fix
   ============================================ */

.emr-derivative-modal {
    position: relative;
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    margin: auto;
}

#derivative-detail-backdrop,
#derivative-edit-backdrop,
#trace-origins-backdrop,
#build-timelines-backdrop,
#rebuild-timelines-backdrop,
#condition-timeline-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

#derivative-detail-backdrop .modal,
#derivative-edit-backdrop .modal,
#trace-origins-backdrop .modal,
#build-timelines-backdrop .modal,
#rebuild-timelines-backdrop .modal,
#condition-timeline-backdrop .modal {
    background: var(--surface-primary, #fff);
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

#derivative-detail-backdrop .modal-header,
#derivative-edit-backdrop .modal-header,
#trace-origins-backdrop .modal-header,
#build-timelines-backdrop .modal-header,
#rebuild-timelines-backdrop .modal-header,
#condition-timeline-backdrop .modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-primary, #eee);
}

#derivative-detail-backdrop .modal-header h3,
#derivative-edit-backdrop .modal-header h3,
#trace-origins-backdrop .modal-header h3,
#build-timelines-backdrop .modal-header h3,
#rebuild-timelines-backdrop .modal-header h3,
#condition-timeline-backdrop .modal-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
}

#derivative-detail-backdrop .modal-close,
#derivative-edit-backdrop .modal-close,
#trace-origins-backdrop .modal-close,
#build-timelines-backdrop .modal-close,
#rebuild-timelines-backdrop .modal-close,
#condition-timeline-backdrop .modal-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--text-secondary, #666);
    padding: 0;
    line-height: 1;
}

#derivative-detail-backdrop .modal-close:hover,
#derivative-edit-backdrop .modal-close:hover,
#trace-origins-backdrop .modal-close:hover,
#build-timelines-backdrop .modal-close:hover,
#rebuild-timelines-backdrop .modal-close:hover,
#condition-timeline-backdrop .modal-close:hover {
    color: var(--text-primary, #333);
}

#derivative-detail-backdrop .modal-body,
#derivative-edit-backdrop .modal-body,
#trace-origins-backdrop .modal-body,
#build-timelines-backdrop .modal-body,
#rebuild-timelines-backdrop .modal-body,
#condition-timeline-backdrop .modal-body {
    padding: 20px;
}

#derivative-detail-backdrop .modal-footer,
#derivative-edit-backdrop .modal-footer,
#trace-origins-backdrop .modal-footer,
#build-timelines-backdrop .modal-footer,
#rebuild-timelines-backdrop .modal-footer,
#condition-timeline-backdrop .modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding: 16px 20px;
    border-top: 1px solid var(--border-primary, #eee);
}

/* Detail rows */
.emr-detail-row {
    display: flex;
    margin-bottom: 12px;
}

.emr-detail-label {
    font-weight: 500;
    color: var(--text-secondary, #666);
    min-width: 120px;
    flex-shrink: 0;
}

.emr-detail-value {
    color: var(--text-primary, #333);
    word-break: break-word;
}

/* =========================================
   Condition Timeline UI (Increment 12.7)
   ========================================= */

/* Condition Timelines Section */
.emr-condition-timelines-section {
    margin-top: 24px;
    margin-bottom: 24px;
    padding: 20px;
    background: var(--bg-secondary, #f8f9fa);
    border-radius: 12px;
}

.emr-condition-timelines-section .emr-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.emr-condition-timelines-section .emr-section-header h3 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary, #333);
    margin: 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.emr-condition-timelines-section .emr-section-count {
    font-size: 13px;
    color: var(--text-secondary, #666);
}

.emr-condition-timelines-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
}

/* Condition Timeline Card */
.emr-condition-timeline-card {
    background: var(--bg-primary, #fff);
    border-radius: 10px;
    padding: 16px;
    border: 1px solid var(--border-primary, #e0e0e0);
    transition: box-shadow 0.2s, transform 0.2s;
}

.emr-condition-timeline-card:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    transform: translateY(-2px);
}

/* Forward-only card (pending backward analysis) */
.emr-condition-timeline-card.forward-only {
    border-color: #ff9800;
    border-style: dashed;
    background: linear-gradient(135deg, #fff9e6 0%, #fff 100%);
}

.emr-ct-pending-badge {
    font-size: 12px;
    padding: 2px 6px;
    border-radius: 10px;
    background: #fff3e0;
    color: #e65100;
    margin-left: auto;
}

.emr-ct-card-insight-pending {
    color: var(--text-secondary, #666);
    font-style: italic;
}

.emr-ct-card-insight-pending strong {
    color: #e65100;
    font-weight: 600;
}

.emr-ct-card-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
}

.emr-ct-status-badge {
    font-size: 12px;
    font-weight: 500;
    padding: 3px 8px;
    border-radius: 12px;
    text-transform: capitalize;
}

.emr-ct-status-badge.active {
    background: #e8f5e9;
    color: #2e7d32;
}

.emr-ct-status-badge.resolved {
    background: #ccfbf1;
    color: #0d9488;
}

.emr-ct-status-badge.monitoring {
    background: #fff3e0;
    color: #e65100;
}

.emr-ct-lifecycle {
    font-size: 12px;
    color: var(--text-secondary, #666);
    text-transform: capitalize;
}

.emr-ct-card-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary, #333);
    margin-bottom: 8px;
}

.emr-ct-card-diagnosis {
    font-size: 12px;
    color: var(--text-secondary, #666);
    margin-bottom: 10px;
}

.emr-ct-label {
    font-weight: 500;
}

.emr-ct-card-insight {
    font-size: 13px;
    color: var(--text-primary, #333);
    margin-bottom: 12px;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.emr-ct-card-stats {
    display: flex;
    gap: 16px;
    margin-bottom: 14px;
    font-size: 12px;
    color: var(--text-secondary, #666);
}

.emr-ct-stat strong {
    color: var(--text-primary, #333);
    font-weight: 600;
}

.emr-ct-card-actions {
    display: flex;
    justify-content: flex-end;
}

/* Condition Timeline Modal */
.emr-ct-modal-content {
    padding: 20px;
    max-height: 70vh;
    overflow-y: auto;
}

.emr-ct-condition-header {
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-primary, #e0e0e0);
}

.emr-ct-condition-name {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-primary, #333);
    margin-bottom: 8px;
}

.emr-ct-condition-meta {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
}

.emr-ct-lifecycle-badge {
    font-size: 12px;
    padding: 3px 10px;
    border-radius: 14px;
    background: var(--bg-secondary, #f0f0f0);
    color: var(--text-secondary, #666);
    text-transform: capitalize;
}

.emr-ct-diagnosis-info {
    font-size: 13px;
    color: var(--text-secondary, #666);
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.emr-ct-time-range {
    color: var(--text-primary, #333);
}

/* Insights Section */
.emr-ct-insights-section {
    margin-bottom: 24px;
    padding: 16px;
    background: linear-gradient(135deg, #f8f9ff 0%, #f0f4ff 100%);
    border-radius: 10px;
    border-left: 4px solid var(--primary, #4a90d9);
}

.emr-ct-insights-section h4 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary, #333);
    margin: 0 0 10px 0;
}

.emr-ct-assessment {
    font-size: 14px;
    color: var(--text-primary, #333);
    line-height: 1.5;
    margin-bottom: 12px;
}

.emr-ct-insight-group {
    margin-top: 10px;
    font-size: 13px;
}

.emr-ct-insight-label {
    font-weight: 500;
    color: var(--text-secondary, #666);
}

/* Labs Section */
.emr-ct-labs-section h4,
.emr-ct-symptoms-section h4,
.emr-ct-medications-section h4,
.emr-ct-sources-section h4 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary, #333);
    margin: 0 0 12px 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.emr-ct-labs-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 12px;
}

.emr-ct-lab-card {
    background: var(--bg-primary, #fff);
    border: 1px solid var(--border-primary, #e0e0e0);
    border-radius: 8px;
    padding: 12px;
}

.emr-ct-lab-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.emr-ct-lab-name {
    font-weight: 600;
    font-size: 13px;
    color: var(--text-primary, #333);
}

.emr-ct-lab-trend {
    font-size: 12px;
    padding: 2px 8px;
    border-radius: 10px;
}

.emr-ct-lab-trend.improving {
    background: #e8f5e9;
    color: #2e7d32;
}

.emr-ct-lab-trend.worsening {
    background: #ffebee;
    color: #c62828;
}

.emr-ct-lab-trend.stable {
    background: #fff3e0;
    color: #e65100;
}

.emr-ct-lab-values {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.emr-ct-lab-value {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 8px 12px;
    border-radius: 6px;
    background: var(--bg-secondary, #f5f5f5);
}

.emr-ct-lab-value.backward {
    border-left: 3px solid #9c27b0;
}

.emr-ct-lab-value.forward {
    border-left: 3px solid #2196f3;
}

.emr-ct-lab-date {
    font-size: 12px;
    color: var(--text-secondary, #4b5563);
    margin-bottom: 2px;
}

.emr-ct-lab-val {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary, #333);
}

.emr-ct-lab-arrow {
    color: var(--text-secondary, #4b5563);
    font-size: 16px;
}

.emr-ct-lab-count {
    font-size: 12px;
    color: var(--text-secondary, #4b5563);
    margin-top: 8px;
    text-align: center;
}

/* Symptoms Section */
.emr-ct-symptoms-section {
    margin-bottom: 20px;
}

.emr-ct-symptom-timeline {
    position: relative;
    padding-left: 24px;
}

.emr-ct-symptom-timeline::before {
    content: '';
    position: absolute;
    left: 8px;
    top: 0;
    bottom: 0;
    width: 2px;
    background: linear-gradient(to bottom, #9c27b0, #2196f3);
}

.emr-ct-symptom-entry {
    display: flex;
    gap: 12px;
    margin-bottom: 14px;
    position: relative;
}

.emr-ct-symptom-marker {
    position: absolute;
    left: -24px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--bg-primary, #fff);
    border: 2px solid #9c27b0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
}

.emr-ct-symptom-entry.forward .emr-ct-symptom-marker {
    border-color: #2196f3;
}

.emr-ct-symptom-content {
    flex: 1;
    background: var(--bg-secondary, #f8f9fa);
    padding: 10px 14px;
    border-radius: 8px;
}

.emr-ct-symptom-entry.backward .emr-ct-symptom-content {
    border-left: 3px solid #9c27b0;
}

.emr-ct-symptom-entry.forward .emr-ct-symptom-content {
    border-left: 3px solid #2196f3;
}

.emr-ct-symptom-date {
    font-size: 12px;
    color: var(--text-secondary, #4b5563);
    margin-bottom: 4px;
}

.emr-ct-symptom-text {
    font-size: 13px;
    color: var(--text-primary, #333);
    line-height: 1.4;
}

.emr-ct-symptom-note {
    font-size: 12px;
    color: #7b1fa2;
    margin-top: 6px;
    font-style: italic;
}

.emr-ct-symptom-severity {
    display: inline-block;
    font-size: 12px;
    padding: 2px 8px;
    border-radius: 10px;
    background: #fff3e0;
    color: #e65100;
    margin-top: 6px;
}

/* Medications Section */
.emr-ct-medications-section {
    margin-bottom: 20px;
}

.emr-ct-medication-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.emr-ct-medication-entry {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px;
    background: var(--bg-secondary, #f8f9fa);
    border-radius: 8px;
}

.emr-ct-medication-entry.backward {
    border-left: 3px solid #9c27b0;
}

.emr-ct-medication-entry.forward {
    border-left: 3px solid #2196f3;
}

.emr-ct-med-icon {
    font-size: 18px;
    flex-shrink: 0;
}

.emr-ct-med-content {
    flex: 1;
}

.emr-ct-med-name {
    font-weight: 600;
    font-size: 14px;
    color: var(--text-primary, #333);
    margin-bottom: 4px;
}

.emr-ct-med-details {
    font-size: 12px;
    color: var(--text-secondary, #666);
    margin-bottom: 4px;
}

.emr-ct-med-date {
    font-size: 12px;
    color: var(--text-secondary, #4b5563);
}

.emr-ct-med-note {
    font-size: 12px;
    color: var(--text-secondary, #666);
    font-style: italic;
    margin-top: 4px;
}

/* Sources Section */
.emr-ct-sources-section {
    padding-top: 16px;
    border-top: 1px solid var(--border-primary, #e0e0e0);
}

.emr-ct-sources-count {
    font-size: 13px;
    color: var(--text-secondary, #666);
}

/* Empty State */
.emr-ct-empty {
    text-align: center;
    padding: 30px;
    color: var(--text-secondary, #4b5563);
}

.emr-ct-empty p {
    margin: 8px 0;
    font-size: 14px;
}

/* ============================================
   Time-Series Cards (Longitudinal Health Data)
   ============================================ */

.emr-timeseries-section {
    margin-top: 24px;
}

.emr-timeseries-category {
    margin-bottom: 32px;
}

.emr-timeseries-category-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
    padding-bottom: 8px;
    border-bottom: 2px solid var(--border-color, #e0e0e0);
}

.emr-timeseries-category-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary, #333);
}

.emr-timeseries-icon {
    font-size: 24px;
}

.emr-timeseries-count {
    margin-left: auto;
    font-size: 13px;
    color: var(--text-secondary, #666);
    background: var(--bg-tertiary, #f0f0f0);
    padding: 4px 10px;
    border-radius: 12px;
}

.emr-timeseries-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 16px;
}

.emr-timeseries-card {
    background: var(--bg-primary, #fff);
    border: 1px solid var(--border-color, #e0e0e0);
    border-radius: 12px;
    padding: 16px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    transition: box-shadow 0.2s ease;
}

.emr-timeseries-card:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.emr-ts-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 12px;
}

.emr-ts-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary, #333);
}

.emr-ts-trend {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    padding: 4px 8px;
    border-radius: 4px;
    font-weight: 500;
}

.emr-ts-trend.improving {
    background: #e8f5e9;
    color: #2e7d32;
}

.emr-ts-trend.worsening {
    background: #ffebee;
    color: #c62828;
}

.emr-ts-trend.stable {
    background: #ccfbf1;
    color: #0d9488;
}

.emr-ts-trend-icon {
    font-size: 14px;
}

.emr-ts-latest {
    font-size: 14px;
    color: var(--text-secondary, #666);
    margin-bottom: 12px;
    padding: 8px 12px;
    background: var(--bg-secondary, #f5f5f5);
    border-radius: 6px;
}

.emr-ts-latest strong {
    font-size: 18px;
    color: var(--text-primary, #333);
}

.emr-ts-latest-date {
    font-size: 12px;
    color: var(--text-tertiary, #4b5563);
    margin-left: 4px;
}

.emr-ts-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    margin-bottom: 12px;
}

.emr-ts-table thead {
    background: var(--bg-tertiary, #f0f0f0);
}

.emr-ts-table th {
    padding: 8px 10px;
    text-align: left;
    font-weight: 600;
    color: var(--text-secondary, #666);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.emr-ts-table td {
    padding: 8px 10px;
    border-bottom: 1px solid var(--border-light, #eee);
}

.emr-ts-row:last-child td {
    border-bottom: none;
}

.emr-ts-date {
    color: var(--text-secondary, #666);
    white-space: nowrap;
}

.emr-ts-value {
    font-weight: 500;
    color: var(--text-primary, #333);
}

.emr-ts-flag-cell {
    text-align: right;
}

.emr-ts-flag {
    display: inline-block;
    font-size: 12px;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 3px;
    text-transform: uppercase;
}

.emr-ts-flag.high {
    background: #ffcdd2;
    color: #c62828;
}

.emr-ts-flag.low {
    background: #bbdefb;
    color: #0d9488;
}

.emr-ts-flag.normal {
    background: #c8e6c9;
    color: #2e7d32;
}

.emr-ts-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12px;
    color: var(--text-tertiary, #4b5563);
    padding-top: 8px;
    border-top: 1px solid var(--border-light, #eee);
}

.emr-ts-count {
    font-weight: 500;
}

.emr-ts-range {
    color: var(--text-secondary, #666);
}

/* ============================================
   Health Time Machine (Visualization)
   ============================================ */

.emr-time-machine {
    background: var(--surface-primary, #fff);
    border: 1px solid var(--border-primary, #e0e0e0);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 24px;
}

.emr-tm-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 12px;
}

.emr-tm-title {
    display: flex;
    align-items: center;
    gap: 10px;
}

.emr-tm-title h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary, #333);
}

.emr-tm-icon {
    font-size: 24px;
}

.emr-tm-date-display {
    display: flex;
    align-items: center;
    gap: 12px;
}

.emr-tm-current-date {
    font-size: 16px;
    font-weight: 600;
    color: var(--accent-primary, #0d9488);
    background: var(--accent-light, #ccfbf1);
    padding: 6px 14px;
    border-radius: 20px;
}

.emr-tm-today-btn {
    padding: 6px 12px;
    font-size: 13px;
    background: var(--surface-secondary, #f5f5f5);
    border: 1px solid var(--border-primary, #e0e0e0);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    color: var(--text-secondary, #666);
}

.emr-tm-today-btn:hover {
    background: var(--accent-primary, #0d9488);
    color: var(--text-on-accent);
    border-color: var(--accent-primary, #0d9488);
}

/* Time Machine Slider */
.emr-tm-slider-container {
    margin-bottom: 24px;
}

.emr-tm-date-range {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    color: var(--text-tertiary, #4b5563);
    margin-bottom: 8px;
}

.emr-tm-slider-track {
    position: relative;
    height: 40px;
    background: var(--surface-secondary, #f5f5f5);
    border-radius: 8px;
    padding: 8px 0;
}

.emr-tm-slider {
    width: 100%;
    height: 8px;
    margin-top: 12px;
    -webkit-appearance: none;
    appearance: none;
    background: linear-gradient(to right,
        var(--accent-light, #ccfbf1) 0%,
        var(--accent-primary, #0d9488) 100%);
    border-radius: 4px;
    cursor: pointer;
}

.emr-tm-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    background: var(--accent-primary, #0d9488);
    border-radius: 50%;
    cursor: grab;
    box-shadow: 0 2px 8px rgba(25, 118, 210, 0.4);
    transition: transform 0.15s ease;
}

.emr-tm-slider::-webkit-slider-thumb:hover {
    transform: scale(1.15);
}

.emr-tm-slider::-webkit-slider-thumb:active {
    cursor: grabbing;
    transform: scale(1.05);
}

.emr-tm-slider::-moz-range-thumb {
    width: 20px;
    height: 20px;
    background: var(--accent-primary, #0d9488);
    border: none;
    border-radius: 50%;
    cursor: grab;
    box-shadow: 0 2px 8px rgba(25, 118, 210, 0.4);
}

/* Event markers on track */
.emr-tm-marker {
    position: absolute;
    top: 4px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    transform: translateX(-50%);
    cursor: pointer;
    transition: transform 0.15s ease;
    z-index: 1;
}

.emr-tm-marker:hover {
    transform: translateX(-50%) scale(1.4);
    z-index: 2;
}

.emr-tm-marker.diagnosis {
    background: #F44336;
}

.emr-tm-marker.medication {
    background: #4CAF50;
}

.emr-tm-marker.lab {
    background: #2196F3;
}

/* Snapshot Cards Grid */
.emr-tm-snapshot-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 16px;
    margin-bottom: 20px;
}

.emr-tm-card {
    background: var(--surface-secondary, #fafafa);
    border: 1px solid var(--border-secondary, #eee);
    border-radius: 10px;
    overflow: hidden;
}

.emr-tm-card-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 14px;
    background: var(--surface-tertiary, #f0f0f0);
    border-bottom: 1px solid var(--border-secondary, #eee);
}

.emr-tm-card-icon {
    font-size: 18px;
}

.emr-tm-card-title {
    flex: 1;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary, #333);
}

.emr-tm-card-count {
    font-size: 12px;
    font-weight: 600;
    background: var(--accent-primary, #0d9488);
    color: var(--text-on-accent);
    padding: 2px 8px;
    border-radius: 12px;
    min-width: 20px;
    text-align: center;
}

.emr-tm-card-body {
    padding: 12px 14px;
    max-height: 180px;
    overflow-y: auto;
}

.emr-tm-card-empty {
    color: var(--text-tertiary, #4b5563);
    font-size: 13px;
    font-style: italic;
    text-align: center;
    padding: 20px 0;
}

/* Condition/Medication items */
.emr-tm-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 8px 0;
    border-bottom: 1px solid var(--border-light, #f0f0f0);
}

.emr-tm-item:last-child {
    border-bottom: none;
}

.emr-tm-item-name {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary, #333);
}

.emr-tm-item-detail {
    font-size: 12px;
    color: var(--text-secondary, #666);
}

/* Lab value items */
.emr-tm-lab-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 0;
    border-bottom: 1px solid var(--border-light, #f0f0f0);
}

.emr-tm-lab-item:last-child {
    border-bottom: none;
}

.emr-tm-lab-item.abnormal {
    background: #FFF8E1;
    margin: 0 -14px;
    padding: 6px 14px;
    border-left: 3px solid #F44336;
}

.emr-tm-lab-name {
    font-size: 13px;
    color: var(--text-primary, #333);
}

.emr-tm-lab-value {
    font-size: 13px;
    font-weight: 600;
    color: var(--accent-primary, #0d9488);
}

/* Vital sign items */
.emr-tm-vital-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 0;
    border-bottom: 1px solid var(--border-light, #f0f0f0);
}

.emr-tm-vital-item:last-child {
    border-bottom: none;
}

.emr-tm-vital-name {
    font-size: 13px;
    color: var(--text-primary, #333);
}

.emr-tm-vital-value {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary, #333);
}

/* Events List */
.emr-tm-events {
    background: var(--surface-secondary, #fafafa);
    border-radius: 10px;
    overflow: hidden;
}

.emr-tm-events-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary, #333);
    background: var(--surface-tertiary, #f0f0f0);
    border-bottom: 1px solid var(--border-secondary, #eee);
}

.emr-tm-events-list {
    padding: 8px 0;
    max-height: 200px;
    overflow-y: auto;
}

.emr-tm-event {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 10px 16px;
    transition: background 0.15s ease;
}

.emr-tm-event:hover {
    background: var(--surface-hover, #f5f5f5);
}

.emr-tm-event-icon {
    font-size: 16px;
    flex-shrink: 0;
    margin-top: 2px;
}

.emr-tm-event-content {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
}

.emr-tm-event-date {
    font-size: 12px;
    color: var(--text-tertiary, #4b5563);
    font-weight: 500;
}

.emr-tm-event-label {
    font-size: 13px;
    color: var(--text-primary, #333);
}

/* Event type colors */
.emr-tm-event.diagnosis {
    border-left: 3px solid #F44336;
    padding-left: 13px;
}

.emr-tm-event.medication-start {
    border-left: 3px solid #4CAF50;
    padding-left: 13px;
}

.emr-tm-event.medication-stop {
    border-left: 3px solid #FF9800;
    padding-left: 13px;
}

.emr-tm-event.abnormal-lab {
    border-left: 3px solid #2196F3;
    padding-left: 13px;
}

/* Responsive */
@media (max-width: 768px) {
    .emr-tm-snapshot-grid {
        grid-template-columns: 1fr;
    }

    .emr-tm-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .emr-tm-date-display {
        width: 100%;
        justify-content: space-between;
    }
}

/* ============================================
   Condition Network Graph (Visualization)
   ============================================ */

.emr-condition-network {
    background: var(--card-bg, white);
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    overflow: hidden;
}

.emr-network-empty {
    padding-bottom: 24px;
}

.emr-network-empty-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 48px 24px;
    text-align: center;
}

.emr-network-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color, #eee);
    flex-wrap: wrap;
    gap: 12px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.emr-network-header h2 {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: var(--text-on-accent);
}

.emr-network-icon {
    font-size: 22px;
}

.emr-network-stats {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
}

.emr-network-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.emr-network-stat .emr-stat-value {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-on-accent);
}

.emr-network-stat .emr-stat-label {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.8);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Enrichment in-progress banner */
.emr-enrichment-banner {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    margin: 0 20px;
    background: var(--bg-tertiary, #2a2a3e);
    border: 1px solid var(--border-secondary, #3a3a5c);
    border-radius: 6px;
    font-size: 12px;
    color: var(--text-secondary, #a0a0b8);
}

.emr-enrichment-spinner {
    width: 12px;
    height: 12px;
    border: 2px solid var(--border-secondary, #3a3a5c);
    border-top-color: var(--accent-primary, #6c63ff);
    border-radius: 50%;
    animation: emr-spin 0.8s linear infinite;
}

@keyframes emr-spin {
    to { transform: rotate(360deg); }
}

/* Network body - main content area */
.emr-network-body {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 20px;
}

/* Main layout: list + detail panel */
.emr-network-main {
    display: grid;
    grid-template-columns: 300px 1fr;
    gap: 20px;
    min-height: 350px;
}

/* Condition list */
.emr-network-list {
    background: var(--surface-secondary, #f8f9fa);
    border-radius: 10px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.emr-network-list-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: var(--surface-tertiary, #eee);
    font-weight: 600;
    font-size: 13px;
    color: var(--text-primary, #333);
}

.emr-network-list-hint {
    font-size: 12px;
    font-weight: 400;
    color: var(--text-tertiary, #4b5563);
}

.emr-network-list-items {
    flex: 1;
    overflow-y: auto;
    max-height: 320px;
}

.emr-network-list-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    cursor: pointer;
    transition: all 0.15s ease;
    border-bottom: 1px solid var(--border-color, #eee);
}

.emr-network-list-item:hover {
    background: rgba(102, 126, 234, 0.08);
}

.emr-network-list-item.selected {
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.15) 0%, rgba(118, 75, 162, 0.1) 100%);
    border-left: 3px solid #667eea;
}

.emr-network-item-status {
    flex-shrink: 0;
}

.emr-status-dot {
    display: block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #9E9E9E;
}

.emr-status-dot.active {
    background: #4CAF50;
    box-shadow: 0 0 6px rgba(76, 175, 80, 0.4);
}

.emr-status-dot.resolved {
    background: #9E9E9E;
}

.emr-network-item-content {
    flex: 1;
    min-width: 0;
}

.emr-network-item-name {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary, #333);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.emr-network-item-meta {
    display: flex;
    gap: 8px;
    margin-top: 3px;
}

.emr-network-item-code {
    font-size: 12px;
    color: var(--text-tertiary, #4b5563);
    font-family: monospace;
    background: rgba(0, 0, 0, 0.05);
    padding: 1px 5px;
    border-radius: 3px;
}

.emr-network-item-connections {
    font-size: 12px;
    color: #667eea;
    font-weight: 500;
}

.emr-network-item-arrow {
    font-size: 18px;
    color: var(--text-tertiary, #4b5563);
    flex-shrink: 0;
}

/* Detail panel */
.emr-network-detail {
    background: var(--surface-primary);
    border: 1px solid var(--border-color, #eee);
    border-radius: 10px;
    overflow: hidden;
}

.emr-network-detail-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    padding: 40px;
    text-align: center;
    color: var(--text-tertiary, #4b5563);
}

.emr-detail-placeholder-icon {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.emr-detail-placeholder-text strong {
    display: block;
    font-size: 16px;
    color: var(--text-secondary, #666);
    margin-bottom: 8px;
}

.emr-detail-placeholder-text p {
    margin: 0;
    font-size: 13px;
    line-height: 1.5;
}

.emr-network-detail-content {
    padding: 20px;
}

.emr-detail-header {
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-color, #eee);
}

.emr-detail-status {
    display: inline-block;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 4px 10px;
    border-radius: 12px;
    margin-bottom: 8px;
}

.emr-detail-status.active {
    background: #E8F5E9;
    color: #2E7D32;
}

.emr-detail-status.resolved {
    background: #F5F5F5;
    color: #757575;
}

.emr-detail-title {
    margin: 0 0 6px;
    font-size: 20px;
    font-weight: 600;
    color: var(--text-primary, #333);
}

.emr-detail-date {
    font-size: 13px;
    color: var(--text-tertiary, #4b5563);
}

.emr-detail-section {
    margin-bottom: 18px;
}

.emr-detail-section-title {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-tertiary, #4b5563);
    margin-bottom: 10px;
}

.emr-detail-codes {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.emr-detail-code {
    display: flex;
    flex-direction: column;
    padding: 10px 14px;
    background: var(--surface-secondary, #f8f9fa);
    border-radius: 8px;
}

.emr-code-label {
    font-size: 12px;
    color: var(--text-tertiary, #4b5563);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.emr-code-value {
    font-size: 14px;
    font-weight: 600;
    font-family: monospace;
    color: var(--text-primary, #333);
}

.emr-detail-code-empty {
    font-size: 13px;
    color: var(--text-tertiary, #4b5563);
    font-style: italic;
}

.emr-detail-relations {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.emr-detail-relation {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    background: var(--surface-secondary, #f8f9fa);
    border-radius: 8px;
    border-left: 3px solid #90CAF9;
}

.emr-detail-relation.progression {
    border-left-color: #FF9800;
}

.emr-relation-icon {
    font-size: 16px;
    flex-shrink: 0;
}

.emr-relation-content {
    flex: 1;
}

.emr-relation-name {
    display: block;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary, #333);
}

.emr-relation-type {
    font-size: 12px;
    color: var(--text-tertiary, #4b5563);
}

.emr-relation-types {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 2px;
}

.emr-relation-type-tag {
    font-size: 12px;
    padding: 1px 6px;
    border-radius: 3px;
    background: #eef0f5;
    color: #4a5568;
    border: 1px solid #d1d5e0;
}

.emr-relation-rationale {
    font-size: 12px;
    color: var(--text-tertiary, #4b5563);
    margin-top: 2px;
    line-height: 1.3;
}

.emr-relation-confidence {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    padding: 2px 6px;
    border-radius: 3px;
    white-space: nowrap;
    align-self: flex-start;
}
.emr-relation-confidence.high { color: #4caf50; background: rgba(76, 175, 80, 0.1); }
.emr-relation-confidence.moderate { color: #ff9800; background: rgba(255, 152, 0, 0.1); }
.emr-relation-confidence.low { color: #9e9e9e; background: rgba(158, 158, 158, 0.1); }

.emr-relation-status {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    padding: 3px 8px;
    border-radius: 10px;
    background: #E8F5E9;
    color: #2E7D32;
}

.emr-relation-status.resolved {
    background: #F5F5F5;
    color: #757575;
}

.emr-detail-empty {
    font-size: 13px;
    color: var(--text-tertiary, #4b5563);
    font-style: italic;
    line-height: 1.5;
}

.emr-detail-empty small {
    display: block;
    margin-top: 4px;
    font-size: 12px;
}

.emr-detail-labs {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.emr-detail-lab {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: #ccfbf1;
    border-radius: 16px;
    font-size: 12px;
    color: #0d9488;
}

.emr-lab-icon {
    font-size: 12px;
}

.emr-detail-knowledge {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.emr-knowledge-item {
    font-size: 13px;
    color: var(--text-secondary, #555);
    line-height: 1.5;
    padding: 8px 12px;
    background: var(--surface-secondary, #f8f9fa);
    border-radius: 6px;
}

.emr-knowledge-item.warning {
    background: #FFF3E0;
    border-left: 3px solid #FF9800;
}

.emr-knowledge-label {
    font-weight: 500;
    color: var(--text-tertiary, #4b5563);
}

/* Insights section */
.emr-network-insights {
    background: linear-gradient(135deg, #f5f7fa 0%, #e8ecf1 100%);
    border-radius: 10px;
    overflow: hidden;
}

.emr-insights-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    background: rgba(102, 126, 234, 0.1);
    font-weight: 600;
    font-size: 14px;
    color: #667eea;
}

.emr-insights-icon {
    font-size: 18px;
}

.emr-insights-content {
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.emr-insight-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 14px 16px;
    background: var(--surface-primary);
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

.emr-insight-icon {
    font-size: 20px;
    flex-shrink: 0;
    margin-top: 2px;
}

.emr-insight-text strong {
    display: block;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary, #333);
    margin-bottom: 4px;
}

.emr-insight-text p {
    margin: 0;
    font-size: 13px;
    color: var(--text-secondary, #555);
    line-height: 1.5;
}

.emr-insight-item.warning {
    border-left: 3px solid #FF9800;
    background: #FFFDE7;
}

.emr-insight-item.comorbid {
    border-left: 3px solid #90CAF9;
}

.emr-insight-item.highlight {
    border-left: 3px solid #667eea;
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.05) 0%, rgba(118, 75, 162, 0.05) 100%);
}

.emr-insight-empty {
    text-align: center;
    padding: 20px;
    color: var(--text-tertiary, #4b5563);
    font-size: 13px;
}

/* Notice box */
.emr-network-notice {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 14px 18px;
    background: linear-gradient(135deg, #FFF3E0 0%, #FFE0B2 100%);
    border-radius: 8px;
    border-left: 4px solid #FF9800;
    margin: 0;
}

.emr-notice-icon {
    font-size: 18px;
    flex-shrink: 0;
}

.emr-notice-content strong {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary, #333);
    margin-bottom: 4px;
}

.emr-notice-content p {
    margin: 0;
    font-size: 12px;
    color: var(--text-secondary, #555);
    line-height: 1.5;
}

/* Responsive */
@media (max-width: 900px) {
    .emr-network-main {
        grid-template-columns: 1fr;
    }

    .emr-network-list-items {
        max-height: 200px;
    }
}

@media (max-width: 768px) {
    .emr-network-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .emr-network-stats {
        width: 100%;
        justify-content: space-around;
    }
}

/* ============================================
   Med-Lab-Condition Triangle (Visualization)
   ============================================ */

.emr-triangle {
    background: var(--card-bg, white);
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    overflow: hidden;
}

.emr-triangle-empty {
    padding-bottom: 24px;
}

.emr-triangle-empty-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 48px 24px;
    text-align: center;
}

.emr-triangle-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color, #eee);
    flex-wrap: wrap;
    gap: 12px;
    background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
}

.emr-triangle-header h2 {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: var(--text-on-accent);
}

.emr-triangle-icon {
    font-size: 22px;
}

.emr-triangle-stats {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
}

.emr-triangle-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.emr-triangle-stat .emr-stat-value {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-on-accent);
}

.emr-triangle-stat .emr-stat-label {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.8);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Triangle body */
.emr-triangle-body {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 20px;
}

/* Three-column layout */
.emr-triangle-columns {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 16px;
}

.emr-triangle-column {
    background: var(--surface-secondary, #f8f9fa);
    border-radius: 10px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.emr-triangle-column-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    font-weight: 600;
    font-size: 13px;
    color: var(--text-on-accent);
}

.emr-triangle-column.medications .emr-triangle-column-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.emr-triangle-column.labs .emr-triangle-column-header {
    background: linear-gradient(135deg, #1e88e5 0%, #0d9488 100%);
}

.emr-triangle-column.conditions .emr-triangle-column-header {
    background: linear-gradient(135deg, #e53935 0%, #c62828 100%);
}

.emr-column-icon {
    font-size: 16px;
}

.emr-triangle-column-items {
    flex: 1;
    overflow-y: auto;
    max-height: 250px;
}

.emr-triangle-empty-col {
    padding: 24px;
    text-align: center;
    color: var(--text-tertiary, #4b5563);
    font-size: 13px;
}

/* Triangle items */
.emr-triangle-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 10px 14px;
    cursor: pointer;
    transition: all 0.15s ease;
    border-bottom: 1px solid var(--border-color, #eee);
}

.emr-triangle-item:hover {
    background: rgba(0, 0, 0, 0.04);
}

.emr-triangle-item.selected {
    background: linear-gradient(135deg, rgba(17, 153, 142, 0.15) 0%, rgba(56, 239, 125, 0.1) 100%);
    border-left: 3px solid #11998e;
}

.emr-triangle-item-main {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
    min-width: 0;
}

.emr-triangle-item-name {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary, #333);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.emr-triangle-item-sub {
    font-size: 12px;
    color: var(--text-tertiary, #4b5563);
}

.emr-triangle-badge {
    background: #667eea;
    color: var(--text-on-accent);
    font-size: 12px;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 10px;
    flex-shrink: 0;
}

.emr-triangle-interp {
    font-size: 12px;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 10px;
    flex-shrink: 0;
    text-transform: uppercase;
}

.emr-triangle-interp.normal {
    background: #E8F5E9;
    color: #2E7D32;
}

.emr-triangle-interp.abnormal {
    background: #FFF3E0;
    color: #E65100;
}

.emr-triangle-interp.critical {
    background: #FFEBEE;
    color: #C62828;
}

/* Detail panel */
.emr-triangle-detail {
    background: var(--surface-primary);
    border: 1px solid var(--border-color, #eee);
    border-radius: 10px;
    min-height: 200px;
}

.emr-triangle-detail-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 200px;
    padding: 40px;
    text-align: center;
    color: var(--text-tertiary, #4b5563);
}

.emr-triangle-detail-content {
    padding: 20px;
}

.emr-triangle-detail-content .emr-detail-header {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    margin-bottom: 16px;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--border-color, #eee);
}

.emr-triangle-detail-content .emr-detail-type-icon {
    font-size: 32px;
    flex-shrink: 0;
}

.emr-triangle-detail-content .emr-detail-header-text h3 {
    margin: 0 0 4px;
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary, #333);
}

.emr-triangle-detail-content .emr-detail-dose,
.emr-triangle-detail-content .emr-detail-value {
    font-size: 14px;
    color: var(--text-secondary, #555);
}

.emr-detail-value.abnormal {
    color: #E65100;
}

.emr-detail-value.critical {
    color: #C62828;
    font-weight: 600;
}

.emr-interp-badge {
    display: inline-block;
    font-size: 12px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 10px;
    margin-left: 8px;
    text-transform: uppercase;
}

.emr-interp-badge.normal {
    background: #E8F5E9;
    color: #2E7D32;
}

.emr-interp-badge.abnormal {
    background: #FFF3E0;
    color: #E65100;
}

.emr-interp-badge.critical {
    background: #FFEBEE;
    color: #C62828;
}

.emr-detail-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    margin-bottom: 8px;
}

.emr-detail-meta-row {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    margin-bottom: 16px;
}

.emr-meta-label {
    color: var(--text-tertiary, #4b5563);
}

.emr-meta-value {
    color: var(--text-primary, #333);
    font-weight: 500;
}

.emr-meta-value.trend-improving {
    color: #4CAF50;
}

.emr-meta-value.trend-worsening {
    color: #F44336;
}

.emr-meta-value.trend-stable {
    color: #FF9800;
}

.emr-detail-relation-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: var(--surface-secondary, #f8f9fa);
    border-radius: 8px;
    margin-bottom: 8px;
}

.emr-detail-relation-item.medication {
    border-left: 3px solid #667eea;
}

.emr-detail-relation-item.lab {
    border-left: 3px solid #1e88e5;
}

.emr-detail-relation-item.condition {
    border-left: 3px solid #e53935;
}

.emr-detail-relation-item.no-data {
    background: #FFF8E1;
}

.emr-detail-relation-item.abnormal {
    background: #FFF3E0;
}

.emr-relation-icon {
    font-size: 16px;
    flex-shrink: 0;
}

.emr-relation-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.emr-relation-name {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary, #333);
}

.emr-relation-value {
    font-size: 12px;
    color: var(--text-secondary, #666);
}

.emr-relation-missing {
    font-size: 12px;
    color: #E65100;
    font-style: italic;
}

.emr-relation-status {
    font-size: 12px;
    font-weight: 600;
    padding: 3px 8px;
    border-radius: 10px;
    text-transform: uppercase;
    flex-shrink: 0;
}

.emr-relation-status.normal {
    background: #E8F5E9;
    color: #2E7D32;
}

.emr-relation-status.high,
.emr-relation-status.low {
    background: #FFF3E0;
    color: #E65100;
}

.emr-relation-status.critical_high,
.emr-relation-status.critical_low {
    background: #FFEBEE;
    color: #C62828;
}

.emr-relation-status.missing {
    background: #FFF8E1;
    color: #F57C00;
}

.emr-detail-interactions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.emr-interaction-tag {
    font-size: 12px;
    padding: 4px 10px;
    background: #FFECB3;
    color: #F57C00;
    border-radius: 12px;
}

.emr-interaction-more {
    font-size: 12px;
    color: var(--text-tertiary, #4b5563);
    font-style: italic;
    padding: 4px;
}

.emr-detail-code-section {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    background: var(--surface-secondary, #f8f9fa);
    border-radius: 8px;
    font-size: 12px;
}

.emr-detail-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.emr-detail-tag {
    font-size: 12px;
    padding: 4px 10px;
    background: var(--surface-secondary, #f0f0f0);
    color: var(--text-secondary, #555);
    border-radius: 12px;
}

/* Triangle insights */
.emr-triangle-insights {
    background: linear-gradient(135deg, #f5f7fa 0%, #e8ecf1 100%);
    border-radius: 10px;
    overflow: hidden;
}

.emr-triangle-insights-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    background: rgba(17, 153, 142, 0.1);
    font-weight: 600;
    font-size: 14px;
    color: #11998e;
}

.emr-insights-counts {
    margin-left: auto;
    display: flex;
    gap: 8px;
}

.emr-insights-counts .alert-count {
    font-size: 12px;
    padding: 2px 8px;
    background: #FFEBEE;
    color: #C62828;
    border-radius: 10px;
}

.emr-insights-counts .warning-count {
    font-size: 12px;
    padding: 2px 8px;
    background: #FFF3E0;
    color: #E65100;
    border-radius: 10px;
}

.emr-triangle-insights-content {
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.emr-triangle-insight {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px 14px;
    background: var(--surface-primary);
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

.emr-triangle-insight.alert {
    border-left: 3px solid #C62828;
    background: #FFEBEE;
}

.emr-triangle-insight.warning {
    border-left: 3px solid #F57C00;
    background: #FFF8E1;
}

.emr-triangle-insight.info {
    border-left: 3px solid #11998e;
}

.emr-triangle-insight .emr-insight-icon {
    font-size: 18px;
    flex-shrink: 0;
}

.emr-triangle-insight .emr-insight-text strong {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary, #333);
    margin-bottom: 3px;
}

.emr-triangle-insight .emr-insight-text p {
    margin: 0;
    font-size: 12px;
    color: var(--text-secondary, #555);
    line-height: 1.5;
}
.emr-triangle-insight .emr-insight-rationale {
    margin-top: 4px;
    font-size: 11px;
    color: var(--text-tertiary, #888);
    font-style: italic;
    line-height: 1.4;
}

/* Responsive */
@media (max-width: 900px) {
    .emr-triangle-columns {
        grid-template-columns: 1fr;
    }

    .emr-triangle-column-items {
        max-height: 150px;
    }
}

@media (max-width: 768px) {
    .emr-triangle-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .emr-triangle-stats {
        width: 100%;
        justify-content: space-around;
    }
}

/* ============================================
   Header To-Do Dropdown
   ============================================ */

.emr-todo-dropdown {
    position: relative;
    margin-right: 8px;
}

.emr-todo-trigger {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    background: linear-gradient(135deg, #7C4DFF 0%, #536DFE 100%);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    color: var(--text-on-accent);
    font-size: 13px;
    font-weight: 500;
}

.emr-todo-trigger:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(124, 77, 255, 0.3);
}

.emr-todo-icon {
    font-size: 14px;
}

.emr-todo-label {
    font-weight: 600;
}

.emr-todo-badge {
    background: rgba(255, 255, 255, 0.25);
    padding: 2px 6px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 700;
}

.emr-todo-arrow {
    font-size: 8px;
    opacity: 0.8;
}

.emr-todo-menu {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    width: 340px;
    max-height: 420px;
    background: var(--surface-primary, #fff);
    border: 1px solid var(--border-primary, #e0e0e0);
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    display: flex;
    flex-direction: column;
}

.emr-todo-list {
    overflow-y: auto;
    max-height: 350px;
}

.emr-todo-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: var(--surface-secondary, #f5f5f5);
    border-bottom: 1px solid var(--border-secondary, #eee);
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary, #333);
}

.emr-todo-dismiss {
    background: none;
    border: none;
    font-size: 18px;
    color: var(--text-tertiary, #4b5563);
    cursor: pointer;
    padding: 2px 6px;
    line-height: 1;
    border-radius: 4px;
    transition: all 0.15s ease;
}

.emr-todo-dismiss:hover {
    background: rgba(0, 0, 0, 0.08);
    color: var(--text-primary, #333);
}

.emr-todo-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.emr-todo-item {
    display: flex;
    gap: 12px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-secondary, #eee);
    transition: background 0.15s ease;
}

.emr-todo-item:last-child {
    border-bottom: none;
}

.emr-todo-item:hover {
    background: var(--surface-hover, #fafafa);
}

.emr-todo-check-label {
    display: flex;
    align-items: center;
    flex-shrink: 0;
    cursor: pointer;
}
.emr-todo-checkbox {
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: #4caf50;
}
.emr-todo-item--done {
    opacity: 0.5;
}
.emr-todo-item--done .emr-todo-item-title {
    text-decoration: line-through;
    color: #4b5563;
}

.emr-todo-item-icon {
    font-size: 18px;
    flex-shrink: 0;
}

.emr-todo-item-content {
    flex: 1;
    min-width: 0;
}

.emr-todo-item-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary, #333);
    margin-bottom: 3px;
}

.emr-todo-item-desc {
    font-size: 12px;
    color: var(--text-secondary, #666);
    line-height: 1.4;
    margin-bottom: 6px;
}

.emr-todo-item-code {
    display: inline-block;
    background: rgba(124, 77, 255, 0.1);
    color: #7C4DFF;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'SF Mono', Monaco, monospace;
    font-size: 12px;
}

/* Add task button in header */
.emr-todo-add-btn {
    background: none;
    border: 1px dashed var(--color-gray-300, #d1d5db);
    font-size: 11px;
    color: var(--color-gray-500, #6b7280);
    cursor: pointer;
    padding: 3px 8px;
    border-radius: 4px;
    font-family: inherit;
    transition: all 0.15s ease;
    margin-left: auto;
    margin-right: 8px;
}
.emr-todo-add-btn:hover {
    border-color: var(--med-teal, #0d7377);
    color: var(--med-teal, #0d7377);
}

/* Delete custom task button */
.emr-todo-delete-custom {
    background: none;
    border: none;
    font-size: 14px;
    color: var(--color-gray-300, #d1d5db);
    cursor: pointer;
    padding: 0 4px;
    flex-shrink: 0;
    font-family: inherit;
    transition: color 0.12s;
    align-self: flex-start;
    margin-top: 2px;
}
.emr-todo-delete-custom:hover {
    color: var(--color-error, #ef4444);
}

.emr-todo-item-ready {
    display: inline-block;
    font-size: 12px;
    color: #4CAF50;
    font-weight: 500;
}

/* ============================================
   Smart Questions (Visualization)
   ============================================ */

.emr-smart-questions {
    background: var(--surface-primary, #fff);
    border: 1px solid var(--border-primary, #e0e0e0);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 24px;
}

.emr-sq-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    flex-wrap: wrap;
    gap: 12px;
}

.emr-sq-title {
    display: flex;
    align-items: center;
    gap: 10px;
}

.emr-sq-title h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary, #333);
}

.emr-sq-icon {
    font-size: 24px;
}

.emr-sq-summary {
    display: flex;
    gap: 16px;
}

.emr-sq-stat {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: var(--surface-secondary, #f5f5f5);
    border-radius: 20px;
}

.emr-sq-stat.high {
    background: #FFEBEE;
}

.emr-sq-stat.high .emr-sq-stat-value {
    color: #F44336;
}

.emr-sq-stat-value {
    font-size: 16px;
    font-weight: 600;
    color: var(--accent-primary, #0d9488);
}

.emr-sq-stat-label {
    font-size: 12px;
    color: var(--text-secondary, #666);
}

.emr-sq-intro {
    padding: 12px 16px;
    background: linear-gradient(135deg, #E8F5E9 0%, #F3E5F5 100%);
    border-radius: 8px;
    margin-bottom: 20px;
}

.emr-sq-intro p {
    margin: 0;
    font-size: 14px;
    color: var(--text-secondary, #555);
    line-height: 1.5;
}

/* Temporal data note */
.emr-sq-temporal-note {
    display: flex;
    gap: 12px;
    padding: 12px 16px;
    background: #FFF8E1;
    border: 1px solid #FFE082;
    border-radius: 8px;
    margin-bottom: 20px;
}

.emr-sq-temporal-icon {
    font-size: 20px;
    flex-shrink: 0;
}

.emr-sq-temporal-content {
    flex: 1;
}

.emr-sq-temporal-content strong {
    display: block;
    font-size: 13px;
    color: #F57C00;
    margin-bottom: 4px;
}

.emr-sq-temporal-content p {
    margin: 0;
    font-size: 12px;
    color: #795548;
    line-height: 1.5;
}

.emr-sq-categories {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.emr-sq-category {
    border: 1px solid var(--border-primary, #e0e0e0);
    border-radius: 10px;
    overflow: hidden;
}

.emr-sq-category-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    background: var(--surface-secondary, #f8f9fa);
    border-left: 4px solid #666;
    cursor: pointer;
    user-select: none;
    transition: background 0.2s ease;
}

.emr-sq-category-header:hover {
    background: var(--surface-tertiary, #f0f0f0);
}

.emr-sq-category-icon {
    font-size: 20px;
    flex-shrink: 0;
}

.emr-sq-category-info {
    flex: 1;
}

.emr-sq-category-info h4 {
    margin: 0 0 2px 0;
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary, #333);
}

.emr-sq-category-desc {
    font-size: 12px;
    color: var(--text-tertiary, #4b5563);
}

.emr-sq-category-count {
    background: var(--accent-primary, #0d9488);
    color: var(--text-on-accent);
    font-size: 12px;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 12px;
    flex-shrink: 0;
}

.emr-sq-category-toggle {
    font-size: 12px;
    color: var(--text-tertiary, #4b5563);
    flex-shrink: 0;
    margin-left: 4px;
    transition: transform 0.2s ease;
}

.emr-sq-category.collapsed .emr-sq-category-count {
    background: var(--text-tertiary, #4b5563);
}

.emr-sq-questions {
    padding: 8px;
}

/* Individual Question Card */
.emr-sq-question {
    background: var(--surface-primary, #fff);
    border: 1px solid var(--border-light, #eee);
    border-radius: 8px;
    margin-bottom: 8px;
    transition: all 0.2s ease;
}

.emr-sq-question:last-child {
    margin-bottom: 0;
}

.emr-sq-question:hover {
    border-color: var(--accent-light, #BBDEFB);
    box-shadow: 0 2px 8px rgba(0,0,0,0.04);
}

.emr-sq-question.expanded {
    border-color: var(--accent-primary, #0d9488);
    box-shadow: 0 4px 12px rgba(25, 118, 210, 0.1);
}

.emr-sq-question-header {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 14px;
    cursor: pointer;
    user-select: none;
}

.emr-sq-priority {
    font-size: 12px;
    flex-shrink: 0;
    margin-top: 3px;
}

.emr-sq-question-icon {
    font-size: 18px;
    flex-shrink: 0;
}

.emr-sq-question-text {
    flex: 1;
    font-size: 14px;
    color: var(--text-primary, #333);
    line-height: 1.5;
}

.emr-sq-expand-icon {
    font-size: 12px;
    color: var(--text-tertiary, #4b5563);
    flex-shrink: 0;
    margin-top: 4px;
    transition: transform 0.2s ease;
}

.emr-sq-question.expanded .emr-sq-expand-icon {
    color: var(--accent-primary, #0d9488);
}

/* Question Details (expanded) */
.emr-sq-question-details {
    padding: 0 14px 14px 14px;
    border-top: 1px solid var(--border-light, #eee);
    margin-top: 0;
    padding-top: 12px;
    animation: slideDown 0.2s ease;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.emr-sq-detail-row {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 12px;
}

.emr-sq-detail-row:last-child {
    margin-bottom: 0;
}

.emr-sq-detail-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-tertiary, #4b5563);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.emr-sq-detail-value {
    font-size: 13px;
    color: var(--text-secondary, #555);
    line-height: 1.5;
}

.emr-sq-detail-value.action {
    background: #E8F5E9;
    color: #2E7D32;
    padding: 8px 12px;
    border-radius: 6px;
    font-weight: 500;
}

.emr-sq-detail-badge {
    display: inline-block;
    background: var(--surface-secondary, #f0f0f0);
    color: var(--text-secondary, #666);
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 500;
}

/* Category-specific header colors */
.emr-sq-category[data-category="actionRecommended"] .emr-sq-category-header {
    border-left-color: #F44336;
    background: linear-gradient(90deg, #FFEBEE 0%, #f8f9fa 100%);
}

.emr-sq-category[data-category="patternsToDiscuss"] .emr-sq-category-header {
    border-left-color: #FF9800;
    background: linear-gradient(90deg, #FFF3E0 0%, #f8f9fa 100%);
}

.emr-sq-category[data-category="screeningSuggestions"] .emr-sq-category-header {
    border-left-color: #2196F3;
    background: linear-gradient(90deg, #ccfbf1 0%, #f8f9fa 100%);
}

.emr-sq-category[data-category="symptomQuestions"] .emr-sq-category-header {
    border-left-color: #9C27B0;
    background: linear-gradient(90deg, #F3E5F5 0%, #f8f9fa 100%);
}

/* Smart Questions: Actions bar */
.emr-sq-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
}

.emr-sq-stale-badge {
    display: inline-block;
    background: #FFF3E0;
    color: #E65100;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
}

/* Smart Questions: Addressed state */
.emr-sq-addressed {
    opacity: 0.5;
}

.emr-sq-addressed .emr-sq-question-text {
    text-decoration: line-through;
}

.emr-sq-addressed-toggle {
    display: flex;
    align-items: center;
    cursor: pointer;
    margin-right: 4px;
}

.emr-sq-addressed-toggle input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: #4CAF50;
}

/* Smart Questions: Question action buttons */
.emr-sq-question-actions {
    display: flex;
    gap: 8px;
    padding-top: 10px;
    margin-top: 10px;
    border-top: 1px solid var(--border-color, #e0e0e0);
}

/* Responsive */
@media (max-width: 768px) {
    .emr-sq-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .emr-sq-summary {
        width: 100%;
        justify-content: flex-start;
    }

    .emr-sq-category-header {
        flex-wrap: wrap;
    }

    .emr-sq-category-desc {
        width: 100%;
        margin-top: 4px;
    }
}

/* ============================================
   3-Phase Pipeline (Entry Processing)
   ============================================ */

/* Wrapper for entire pipeline */
.emr-pipeline-wrapper {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 16px;
    background: var(--surface-secondary, #f8f9fa);
    border-radius: 12px;
    margin-bottom: 16px;
    overflow-x: auto;
}

/* Each phase block */
.emr-pipeline-phase-block {
    flex: 1;
    min-width: 200px;
    background: var(--surface-primary, #fff);
    border: 1px solid var(--border-primary, #e0e0e0);
    border-radius: 8px;
    padding: 12px;
    transition: all 0.2s ease;
}

.emr-pipeline-phase-block.complete {
    border-color: #4CAF50;
    background: linear-gradient(180deg, rgba(76, 175, 80, 0.03) 0%, transparent 100%);
}

.emr-pipeline-phase-block.in-progress {
    border-color: #FF9800;
    box-shadow: 0 0 0 2px rgba(255, 152, 0, 0.15);
}

.emr-pipeline-phase-block.pending {
    border-color: #2196F3;
}

.emr-pipeline-phase-block.future,
.emr-pipeline-phase-block.not-started {
    opacity: 0.5;
    background: var(--surface-secondary, #f5f5f5);
}

/* Phase header */
.emr-pipeline-phase-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border-primary, #e0e0e0);
}

.emr-pipeline-phase-icon {
    font-size: 18px;
}

.emr-pipeline-phase-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary, #333);
}

.emr-pipeline-phase-summary {
    margin-left: auto;
    font-size: 12px;
    color: var(--text-secondary, #666);
    background: var(--surface-secondary, #f5f5f5);
    padding: 2px 8px;
    border-radius: 10px;
}

.emr-pipeline-phase-block.complete .emr-pipeline-phase-summary {
    background: #E8F5E9;
    color: #2e7d32;
}

/* Substages container */
.emr-pipeline-substages {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

/* Individual substage */
.emr-pipeline-substage {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    background: var(--surface-secondary, #f8f9fa);
    border-radius: 6px;
    font-size: 12px;
    transition: all 0.2s ease;
}

.emr-pipeline-substage.complete {
    background: #E8F5E9;
}

.emr-pipeline-substage.skipped {
    background: #ECEFF1;
    opacity: 0.7;
}

.emr-pipeline-substage.pending {
    background: #FFF3E0;
}

.emr-pipeline-substage.future,
.emr-pipeline-substage.not-started {
    opacity: 0.5;
}

.emr-substage-icon {
    font-size: 14px;
    flex-shrink: 0;
}

.emr-substage-name {
    font-weight: 500;
    color: var(--text-primary, #333);
    white-space: nowrap;
}

.emr-substage-desc {
    color: var(--text-tertiary, #4b5563);
    font-size: 12px;
    margin-left: auto;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.emr-substage-label {
    margin-left: 4px;
    font-size: 12px;
    color: #757575;
    font-style: italic;
}

/* Arrow between phases */
.emr-pipeline-arrow-block {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-tertiary, #4b5563);
    font-size: 24px;
    flex-shrink: 0;
    padding-top: 20px;
}

/* Action button */
.emr-pipeline-action {
    margin-top: 10px;
    padding: 6px 12px;
    font-size: 12px;
    border-radius: 4px;
    cursor: pointer;
    border: none;
    background: var(--accent-primary, #6C63FF);
    color: var(--text-on-accent);
    transition: all 0.2s ease;
    width: 100%;
}

.emr-pipeline-action:hover {
    background: var(--accent-dark, #5A52D5);
    transform: translateY(-1px);
}

.emr-pipeline-action:disabled {
    background: var(--border-primary, #e0e0e0);
    color: var(--text-tertiary, #4b5563);
    cursor: not-allowed;
    transform: none;
}

/* Pipeline in document detail modal */
.emr-pipeline-details {
    margin-top: 16px;
}

.emr-pipeline-details .emr-pipeline-wrapper {
    margin-top: 8px;
}

/* Legacy pipeline container (keep for backwards compat) */
.emr-pipeline-container {
    display: flex;
    align-items: stretch;
    gap: 8px;
    padding: 16px;
    background: var(--surface-secondary, #f8f9fa);
    border-radius: 12px;
    margin-bottom: 16px;
}

.emr-pipeline-phase {
    flex: 1;
    background: var(--surface-primary, #fff);
    border: 1px solid var(--border-primary, #e0e0e0);
    border-radius: 8px;
    padding: 16px;
    text-align: center;
    transition: all 0.2s ease;
}

.emr-pipeline-arrow {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-tertiary, #4b5563);
    font-size: 20px;
    flex-shrink: 0;
}

/* Responsive - stack phases vertically on mobile */
@media (max-width: 768px) {
    .emr-pipeline-wrapper {
        flex-direction: column;
    }

    .emr-pipeline-phase-block {
        min-width: unset;
    }

    .emr-pipeline-arrow-block {
        transform: rotate(90deg);
        padding: 8px 0;
    }

    .emr-substage-desc {
        display: none;
    }
}

/* ═══════════════════════════════════════════════════════════════════════════
   CONDITION TIMELINE VISUALIZATION
   ═══════════════════════════════════════════════════════════════════════════ */

.emr-ct-viz-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.emr-ct-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    cursor: pointer;
}

.emr-ct-container {
    position: relative;
    background: var(--surface-primary);
    border-radius: 12px;
    width: 90%;
    max-width: 900px;
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.emr-ct-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    background: linear-gradient(135deg, #0d9488, #0d9488);
    color: var(--text-on-accent);
}

.emr-ct-title {
    display: flex;
    align-items: center;
    gap: 12px;
}

.emr-ct-icon {
    font-size: 24px;
}

.emr-ct-title h2 {
    margin: 0;
    font-size: 20px;
    font-weight: 600;
}

.emr-ct-icd {
    background: rgba(255, 255, 255, 0.2);
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
}

.emr-ct-close {
    background: none;
    border: none;
    color: var(--text-on-accent);
    font-size: 20px;
    cursor: pointer;
    padding: 8px;
    opacity: 0.8;
    transition: opacity 0.2s;
}

.emr-ct-close:hover {
    opacity: 1;
}

.emr-ct-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

/* Loading state */
.emr-ct-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    color: #666;
}

.emr-ct-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid #E0E0E0;
    border-top-color: #0d9488;
    border-radius: 50%;
    animation: emr-ct-spin 1s linear infinite;
    margin-bottom: 16px;
}

@keyframes emr-ct-spin {
    to { transform: rotate(360deg); }
}

/* Error state */
.emr-ct-error {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 40px 20px;
    color: #666;
}

.emr-ct-error-icon {
    font-size: 40px;
    margin-bottom: 12px;
}

/* Diagnosis info bar */
.emr-ct-diagnosis-info {
    display: flex;
    gap: 24px;
    padding: 12px 16px;
    background: #F5F5F5;
    border-radius: 8px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.emr-ct-info-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.emr-ct-info-label {
    font-size: 12px;
    color: #666;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.emr-ct-info-value {
    font-size: 14px;
    font-weight: 500;
    color: #333;
}

.emr-ct-status-active {
    color: #4CAF50;
}

.emr-ct-status-resolved {
    color: #9E9E9E;
}

/* Stats row */
.emr-ct-stats {
    display: flex;
    gap: 16px;
    margin-bottom: 24px;
    flex-wrap: wrap;
}

.emr-ct-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 12px 20px;
    background: #FAFAFA;
    border-radius: 8px;
    min-width: 80px;
}

.emr-ct-stat-value {
    font-size: 24px;
    font-weight: 700;
    color: #0d9488;
}

.emr-ct-stat-label {
    font-size: 12px;
    color: #666;
    text-transform: uppercase;
}

/* Sections */
.emr-ct-section {
    margin-bottom: 24px;
}

.emr-ct-section h3 {
    margin: 0 0 16px 0;
    font-size: 16px;
    font-weight: 600;
    color: #333;
    display: flex;
    align-items: center;
    gap: 8px;
}

.emr-ct-empty-msg {
    color: #4b5563;
    font-style: italic;
    padding: 20px;
    text-align: center;
    background: #FAFAFA;
    border-radius: 8px;
}

/* Lab Charts Grid */
.emr-ct-charts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
    gap: 16px;
}

.emr-ct-chart-card {
    background: #FAFAFA;
    border-radius: 8px;
    padding: 12px;
    border: 1px solid #E0E0E0;
}

.emr-ct-chart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.emr-ct-chart-title {
    font-weight: 600;
    color: #333;
}

.emr-ct-chart-current {
    font-weight: 500;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 13px;
}

.emr-ct-chart-current.rising {
    background: #FFEBEE;
    color: #C62828;
}

.emr-ct-chart-current.falling {
    background: #E8F5E9;
    color: #2E7D32;
}

.emr-ct-chart-current.stable {
    background: #ccfbf1;
    color: #0d9488;
}

.emr-ct-chart-svg {
    width: 100%;
    height: auto;
}

.emr-ct-chart-empty {
    text-align: center;
    padding: 30px;
    color: #4b5563;
}

.emr-ct-point {
    cursor: pointer;
    transition: r 0.2s;
}

.emr-ct-point:hover {
    r: 7;
}

.emr-ct-chart-legend {
    display: flex;
    gap: 16px;
    justify-content: center;
    margin-top: 8px;
    font-size: 12px;
    color: #666;
}

.emr-ct-legend-item {
    display: flex;
    align-items: center;
    gap: 4px;
}

.emr-ct-legend-item.backward {
    color: #757575;
}

.emr-ct-legend-item.diagnosis {
    color: #F44336;
}

.emr-ct-legend-item.forward {
    color: #2196F3;
}

/* Symptom Timeline */
.emr-ct-symptom-timeline {
    border-left: 3px solid #E0E0E0;
    margin-left: 12px;
    padding-left: 0;
}

.emr-ct-symptom-phase {
    position: relative;
    margin-bottom: 16px;
}

.emr-ct-phase-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 0 8px 20px;
    position: relative;
}

.emr-ct-phase-marker {
    position: absolute;
    left: -12px;
    font-size: 18px;
}

.emr-ct-symptom-phase.backward .emr-ct-phase-marker {
    color: #757575;
}

.emr-ct-symptom-phase.diagnosis .emr-ct-phase-marker {
    color: #F44336;
}

.emr-ct-symptom-phase.forward .emr-ct-phase-marker {
    color: #2196F3;
}

.emr-ct-phase-label {
    font-weight: 600;
    font-size: 13px;
    color: #555;
}

.emr-ct-symptom-phase.diagnosis .emr-ct-phase-label {
    color: #F44336;
}

.emr-ct-phase-items {
    padding-left: 20px;
}

.emr-ct-symptom-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 12px;
    background: #FAFAFA;
    border-radius: 6px;
    margin-bottom: 6px;
    border-left: 3px solid transparent;
}

.emr-ct-symptom-item.backward {
    border-left-color: #9E9E9E;
}

.emr-ct-symptom-item.diagnosis {
    border-left-color: #F44336;
    background: #FFEBEE;
}

.emr-ct-symptom-item.forward {
    border-left-color: #2196F3;
}

.emr-ct-symptom-date {
    font-size: 12px;
    color: #4b5563;
    min-width: 80px;
}

.emr-ct-symptom-name {
    flex: 1;
    font-weight: 500;
    color: #333;
}

.emr-ct-symptom-hpo,
.emr-ct-symptom-quote {
    font-size: 14px;
    cursor: help;
    opacity: 0.7;
}

/* Phenotypes */
.emr-ct-phenotype-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.emr-ct-phenotype-tag {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: #ccfbf1;
    border-radius: 16px;
    font-size: 12px;
    color: #0d9488;
}

.emr-ct-phenotype-freq {
    font-size: 12px;
    background: rgba(25, 118, 210, 0.2);
    padding: 2px 6px;
    border-radius: 8px;
}

/* Source Documents */
.emr-ct-docs-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.emr-ct-doc-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    background: #FAFAFA;
    border-radius: 6px;
    border-left: 3px solid #E0E0E0;
}

.emr-ct-doc-item.backward {
    border-left-color: #9E9E9E;
}

.emr-ct-doc-item.diagnosis {
    border-left-color: #F44336;
}

.emr-ct-doc-item.forward {
    border-left-color: #2196F3;
}

.emr-ct-doc-item.is-diagnosis-doc {
    background: #FFF3E0;
}

.emr-ct-doc-phase {
    font-size: 16px;
}

.emr-ct-doc-item.backward .emr-ct-doc-phase { color: #757575; }
.emr-ct-doc-item.diagnosis .emr-ct-doc-phase { color: #F44336; }
.emr-ct-doc-item.forward .emr-ct-doc-phase { color: #2196F3; }

.emr-ct-doc-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.emr-ct-doc-name {
    font-weight: 500;
    color: #333;
}

.emr-ct-doc-meta {
    font-size: 12px;
    color: #666;
}

/* Timeline button on entries */
.emr-timeline-btn:hover {
    opacity: 1 !important;
    transform: scale(1.1);
}

/* Responsive */
@media (max-width: 600px) {
    .emr-ct-container {
        width: 100%;
        max-width: 100%;
        height: 100%;
        max-height: 100%;
        border-radius: 0;
    }

    .emr-ct-diagnosis-info {
        flex-direction: column;
        gap: 12px;
    }

    .emr-ct-stats {
        flex-wrap: wrap;
    }

    .emr-ct-stat {
        flex: 1;
        min-width: 70px;
    }

    .emr-ct-charts-grid {
        grid-template-columns: 1fr;
    }

    .emr-ct-chart-legend {
        flex-wrap: wrap;
    }
}

/* ============================================
   Medication Timeline (Records view)
   ============================================ */

.emr-medtl-section {
    margin-bottom: 20px;
}

.emr-medtl-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    background: var(--surface-secondary, #f8fafc);
    border: 1px solid var(--border-secondary, #e2e8f0);
    border-radius: 8px 8px 0 0;
    cursor: pointer;
    user-select: none;
}

.emr-medtl-header h2 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary, #334155);
    margin: 0;
}

.emr-medtl-toggle-icon {
    font-size: 12px;
    color: var(--text-tertiary, #4b5563);
}

.emr-medtl-container {
    position: relative;
    background: var(--surface-primary, #fff);
    border: 1px solid var(--border-secondary, #e2e8f0);
    border-top: none;
    border-radius: 0 0 8px 8px;
    padding: 20px 16px 16px;
    min-height: 80px;
}

/* ── Axis ── */
.emr-medtl-axis-row {
    display: flex;
    align-items: flex-end;
    margin-bottom: 4px;
}

.emr-medtl-axis-spacer {
    width: 160px;
    flex-shrink: 0;
    position: sticky;
    left: 0;
    background: var(--surface-primary, #fff);
    z-index: 5;
}

.emr-medtl-axis {
    position: relative;
    height: 42px;
    flex: 1;
    min-width: 0;
    border-bottom: 2px solid var(--border-secondary, #cbd5e1);
}

.emr-medtl-tick {
    position: absolute;
    top: 0;
    transform: translateX(-50%);
    text-align: center;
}

.emr-medtl-tick-line {
    width: 2px;
    height: 14px;
    background: var(--text-tertiary, #4b5563);
    margin: 0 auto;
}

.emr-medtl-tick-label {
    font-size: 12px;
    color: var(--text-secondary, #475569);
    font-weight: 500;
    white-space: nowrap;
    margin-top: 2px;
}

/* Minor month/quarter ticks */
.emr-medtl-tick-minor .emr-medtl-tick-line {
    width: 1px;
    height: 8px;
    background: var(--border-secondary, #cbd5e1);
}

/* Encounter date markers (document uploads) */
.emr-medtl-tick-encounter .emr-medtl-tick-line {
    width: 2px;
    height: 18px;
    background: #6366f1;
    opacity: 0.5;
}

/* Reconciliation badge (dose overlap indicator) */
.emr-medtl-reconcile-badge {
    font-size: 12px;
    padding: 1px 6px;
    border-radius: 4px;
    background: #fef3c7;
    color: #92400e;
    font-weight: 500;
    cursor: pointer;
    flex-shrink: 0;
}

.emr-medtl-reconcile-badge:hover {
    background: #fde68a;
}

/* Scrollable inner container */
.emr-medtl-scroll {
    overflow-x: auto;
    overflow-y: visible;
    -webkit-overflow-scrolling: touch;
}

.emr-medtl-scroll::-webkit-scrollbar {
    height: 6px;
}

.emr-medtl-scroll::-webkit-scrollbar-thumb {
    background: var(--border-secondary, #cbd5e1);
    border-radius: 3px;
}

/* ── Ingredient Groups ── */
.emr-medtl-group {
    border-bottom: 1px solid var(--border-secondary, #e2e8f0);
    padding-bottom: 2px;
}

.emr-medtl-group:last-child {
    border-bottom: none;
}

.emr-medtl-group-multi {
    background: var(--surface-secondary, #fafbfd);
    border-radius: 6px;
    margin: 4px 0;
    border: 1px solid var(--border-light, #eef0f4);
}

.emr-medtl-group-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px 2px;
    position: sticky;
    left: 0;
    background: inherit;
    z-index: 5;
    width: fit-content;
}

.emr-medtl-group-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary, #334155);
}

.emr-medtl-group-count {
    font-size: 12px;
    color: var(--text-tertiary, #4b5563);
    font-weight: 400;
}

/* ── Drug Rows ── */
.emr-medtl-rows {
    display: flex;
    flex-direction: column;
}

.emr-medtl-row {
    display: flex;
    align-items: center;
    min-height: 36px;
    border-bottom: 1px solid var(--border-light, #f1f5f9);
    cursor: pointer;
    transition: background 0.15s;
}

.emr-medtl-row:hover {
    background: var(--surface-hover, #f8fafc);
}

.emr-medtl-row:last-child {
    border-bottom: none;
}

/* Row label (left side) — matches axis spacer width, sticky for freeze-pane */
.emr-medtl-row-label {
    width: 160px;
    flex-shrink: 0;
    position: sticky;
    left: 0;
    background: var(--surface-primary, #fff);
    z-index: 5;
    padding: 6px 8px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px;
    overflow: hidden;
}

.emr-medtl-row-dose {
    font-size: 12px;
    color: var(--text-secondary, #64748b);
    white-space: nowrap;
}

.emr-medtl-row-info {
    width: 100%;
    display: flex;
    gap: 4px;
    align-items: center;
}

.emr-medtl-row-indication {
    font-size: 12px;
    color: var(--text-tertiary, #4b5563);
    font-style: italic;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Context tags */
.emr-medtl-ctx-tag {
    font-size: 12px;
    padding: 1px 5px;
    border-radius: 4px;
    font-weight: 600;
    flex-shrink: 0;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.emr-medtl-ctx-standing { background: #ccfbf1; color: #0d9488; }
.emr-medtl-ctx-episodic { background: #ffedd5; color: #9a3412; }
.emr-medtl-ctx-newly_prescribed { background: #ede9fe; color: #6b21a8; }
.emr-medtl-ctx-uncertain { background: #f3f4f6; color: #6b7280; }

/* Doc count badge */
.emr-medtl-doc-count {
    font-size: 12px;
    color: var(--text-tertiary, #4b5563);
    padding: 0 4px;
    background: var(--surface-secondary, #f1f5f9);
    border-radius: 3px;
    flex-shrink: 0;
}

/* Row bar area (right side) */
.emr-medtl-row-bar {
    flex: 1;
    position: relative;
    height: 28px;
    min-width: 0;
}

/* Horizontal bars */
.emr-medtl-bar {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    height: 6px;
    border-radius: 3px;
}

.emr-medtl-bar-solid { border-style: solid; }
.emr-medtl-bar-dashed { border-style: dashed; }

/* Standing bars — blue */
.emr-medtl-bar-standing {
    background: #93c5fd;
}

.emr-medtl-bar-dashed.emr-medtl-bar-standing {
    background: transparent;
    border: 2px dashed #93c5fd;
    height: 2px;
}

/* Newly prescribed bars — purple */
.emr-medtl-bar-new-rx {
    background: #c4b5fd;
}

/* Dots */
.emr-medtl-dot {
    position: absolute;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 10px;
    height: 10px;
    border-radius: 50%;
    z-index: 2;
}

.emr-medtl-dot-standing { background: #3b82f6; }
.emr-medtl-dot-episodic { background: #f97316; width: 12px; height: 12px; }
.emr-medtl-dot-new-rx { background: #8b5cf6; }
.emr-medtl-dot-uncertain { background: #d1d5db; width: 8px; height: 8px; }

/* Arrow indicators (ongoing medication) */
.emr-medtl-bar-arrow {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0;
    width: 0;
    height: 0;
    border-top: 5px solid transparent;
    border-bottom: 5px solid transparent;
    z-index: 2;
}

.emr-medtl-bar-standing-arrow { border-left: 7px solid #3b82f6; }
.emr-medtl-bar-new-rx-arrow { border-left: 7px solid #8b5cf6; }

/* Inferred end cap (dose titration) */
.emr-medtl-bar-end-cap {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    font-size: 12px;
    color: var(--text-tertiary, #4b5563);
    font-weight: 500;
    white-space: nowrap;
    padding-left: 4px;
}

.emr-medtl-bar-inferred-end {
    color: #f59e0b;
    font-style: italic;
}

/* Bar labels (e.g., "since 2014", "noted", duration) */
.emr-medtl-bar-label {
    position: absolute;
    top: -12px;
    transform: translateX(-50%);
    font-size: 12px;
    color: var(--text-tertiary, #4b5563);
    font-weight: 500;
    white-space: nowrap;
}

/* Vertical gridlines at encounter dates */
.emr-medtl-gridline {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 1px;
    background: var(--border-secondary, #e2e8f0);
    pointer-events: none;
    z-index: 0;
}

/* Show all toggle */
.emr-medtl-show-all {
    text-align: center;
    padding: 8px;
    font-size: 12px;
    color: #4f46e5;
    cursor: pointer;
    font-weight: 500;
}

.emr-medtl-show-all:hover {
    text-decoration: underline;
}

/* ── Highlight flash animation (timeline row → entry link) ── */
@keyframes emr-highlight-flash-anim {
    0% { background-color: #fef08a; }
    100% { background-color: transparent; }
}

.emr-highlight-flash {
    animation: emr-highlight-flash-anim 2s ease-out;
}

/* ============================================
   Document Library View
   ============================================ */

.emr-doclib {
    max-width: 100%;
}

.emr-doclib-card {
    border: 1px solid var(--border-secondary, #e2e8f0);
    border-radius: 8px;
    margin-bottom: 8px;
    background: var(--surface-primary, #fff);
    overflow: hidden;
}

.emr-doclib-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    cursor: pointer;
}

.emr-doclib-header:hover {
    background: var(--surface-hover, #f8fafc);
}

.emr-doclib-icon {
    font-size: 24px;
    flex-shrink: 0;
}

.emr-doclib-title-area {
    flex: 1;
    min-width: 0;
}

.emr-doclib-filename {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary, #1e293b);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.emr-doclib-meta {
    display: flex;
    gap: 12px;
    font-size: 12px;
    color: var(--text-secondary, #64748b);
    margin-top: 2px;
}

.emr-doclib-meta span::before {
    content: '';
}

.emr-doclib-stats {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

.emr-doclib-stat {
    font-size: 12px;
    color: var(--text-secondary, #64748b);
    background: var(--surface-secondary, #f1f5f9);
    padding: 2px 6px;
    border-radius: 4px;
    white-space: nowrap;
}

.emr-doclib-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

.emr-doclib-expand-btn,
.emr-doclib-actions .emr-doc-delete-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    font-size: 14px;
    opacity: 0.5;
    border-radius: 4px;
}

.emr-doclib-expand-btn:hover,
.emr-doclib-actions .emr-doc-delete-btn:hover {
    opacity: 1;
    background: var(--surface-secondary, #f1f5f9);
}

.emr-doclib-progress {
    padding: 0 16px 8px;
}

.emr-doclib-sections {
    padding: 0 16px 12px;
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.emr-doclib-section-tag {
    font-size: 12px;
    padding: 1px 6px;
    border-radius: 3px;
    background: var(--surface-secondary, #f1f5f9);
    color: var(--text-secondary, #64748b);
}

/* Document detail (expanded inline) */
.emr-doclib-detail-content {
    padding: 16px;
    border-top: 1px solid var(--border-secondary, #e2e8f0);
    background: var(--surface-secondary, #fafbfc);
}

.emr-doclib-detail-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-primary, #334155);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Structured content sections */
.emr-doclib-text-sections {
    margin-bottom: 16px;
}

.emr-doclib-text-section {
    margin-bottom: 4px;
    border: 1px solid var(--border-light, #eef0f4);
    border-radius: 6px;
    overflow: hidden;
}

.emr-doclib-text-header {
    padding: 8px 12px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-primary, #334155);
    background: var(--surface-primary, #fff);
    cursor: pointer;
    user-select: none;
}

.emr-doclib-text-header:hover {
    background: var(--surface-hover, #f8fafc);
}

.emr-doclib-text-body {
    padding: 8px 12px 12px;
    font-size: 12px;
    color: var(--text-secondary, #475569);
    line-height: 1.6;
    white-space: pre-wrap;
    font-family: inherit;
    max-height: 300px;
    overflow-y: auto;
    background: var(--surface-primary, #fff);
}

/* Linked categories */
.emr-doclib-linked {
    margin-bottom: 16px;
}

.emr-doclib-linked-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.emr-doclib-linked-tag {
    font-size: 12px;
    padding: 4px 10px;
    border-radius: 6px;
    background: var(--surface-primary, #fff);
    border: 1px solid var(--border-secondary, #e2e8f0);
    color: var(--text-primary, #334155);
    cursor: pointer;
}

.emr-doclib-linked-tag:hover {
    background: #eef2ff;
    border-color: #6366f1;
    color: #4f46e5;
}

/* Pipeline in detail view */
.emr-doclib-pipeline {
    margin-bottom: 16px;
}

/* ── Extraction Council ── */
.emr-doclib-council {
    margin-bottom: 16px;
}
.emr-doclib-council-grid {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    margin: 8px 0;
}
.emr-doclib-council-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 60px;
}
.emr-doclib-council-value {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
}
.emr-doclib-council-label {
    font-size: 12px;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.emr-doclib-council-bar {
    height: 6px;
    background: var(--bg-tertiary, #2a2a2a);
    border-radius: 3px;
    overflow: hidden;
    margin-top: 8px;
}
.emr-doclib-council-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, #4CAF50, #66BB6A);
    border-radius: 3px;
    transition: width 0.3s ease;
}
.emr-doclib-council-bar-label {
    font-size: 12px;
    color: var(--text-tertiary);
    margin-top: 4px;
}

/* ── Smooth Completion Update Animations ── */

/* Stat card updating — scale up with accent color */
.emr-stat-updating .emr-stat-value {
    transform: scale(1.1);
    color: #6366f1;
    transition: transform 0.3s ease-out, color 0.3s ease-out;
}

/* Stat card updated — green pulse flash */
.emr-stat-updated {
    animation: emr-stat-pulse 1s ease-out;
}

@keyframes emr-stat-pulse {
    0% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.4); }
    40% { box-shadow: 0 0 0 8px rgba(34, 197, 94, 0.15); }
    100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); }
}

/* Category badge updated — green ring flash */
.emr-badge-updated {
    animation: emr-badge-flash 1.5s ease-out;
}

@keyframes emr-badge-flash {
    0% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.5); }
    30% { box-shadow: 0 0 0 6px rgba(34, 197, 94, 0.2); }
    100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); }
}

/* New category badge appearing — scale in */
.emr-badge-new {
    animation: emr-badge-appear 0.5s ease-out;
}

@keyframes emr-badge-appear {
    0% { transform: scale(0.8); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

/* New entry — initial hidden state */
.emr-entry.emr-entry-new {
    opacity: 0;
    transform: translateY(8px);
}

/* New entry — visible with transition */
.emr-entry.emr-entry-new.emr-entry-new-visible {
    opacity: 1;
    transform: translateY(0);
    transition: opacity 0.5s ease-out, transform 0.5s ease-out;
}

/* ── Responsive ── */
@media (max-width: 768px) {
    /* Timeline: keep horizontal scroll, narrower labels (STOA: Apple Health style) */
    .emr-medtl-axis { font-size: 12px; }
    .emr-medtl-axis-spacer { width: 100px; }
    .emr-medtl-row { flex-direction: row; align-items: center; }
    .emr-medtl-row-label { width: 100px; font-size: 12px; padding: 4px 6px; }
    .emr-medtl-row-bar { height: 20px; }
    .emr-medtl-scroll { -webkit-overflow-scrolling: touch; }

    /* Entries: compact padding, 44px min touch target */
    .emr-entry { padding: 12px; min-height: 44px; }

    /* Categories: hide scrollbar, add momentum scroll */
    .emr-categories { scrollbar-width: none; -webkit-overflow-scrolling: touch; }
    .emr-categories::-webkit-scrollbar { display: none; }
    .emr-category-btn { padding: 6px 12px; font-size: 12px; }

    /* Stat cards: compact */
    .emr-stat-card { padding: 12px; }
    .emr-stat-value { font-size: 24px; }
    .emr-stat-label { font-size: 12px; }

    .emr-doclib-header { flex-wrap: wrap; }
    .emr-doclib-stats { width: 100%; }
    .emr-doclib-meta { flex-wrap: wrap; }
}

/* ═══════════════════════════════════════════════════════════════════════════
   SCREENING DASHBOARD (Preventive Screening)
   ═══════════════════════════════════════════════════════════════════════════ */

.emr-screening-dashboard {
    padding: 16px;
    max-width: 900px;
    margin: 0 auto;
}

/* Loading state */
.emr-screening-loading {
    text-align: center;
    padding: 60px 20px;
    color: #666;
}
.emr-screening-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid #e0e0e0;
    border-top-color: #4a90d9;
    border-radius: 50%;
    margin: 0 auto 16px;
    animation: emr-shimmer 0.8s linear infinite;
}
.emr-screening-loading-sub {
    font-size: 13px;
    color: #4b5563;
    margin-top: 8px;
}

/* Empty state */
.emr-screening-empty {
    text-align: center;
    padding: 60px 20px;
    color: #4b5563;
}
.emr-screening-empty h3 {
    margin-bottom: 8px;
}

/* Stale banner */
.emr-screening-stale-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    background: #fff8e1;
    border: 1px solid #ffe082;
    border-radius: 8px;
    padding: 10px 16px;
    margin-bottom: 16px;
    font-size: 13px;
    color: #6d4c00;
}

/* Demographics banner */
.emr-screening-banner {
    background: linear-gradient(135deg, #ccfbf1, #f3e5f5);
    border-radius: 10px;
    padding: 14px 20px;
    margin-bottom: 16px;
    border: 1px solid #e0e0e0;
}
.emr-screening-banner--empty {
    background: #f5f5f5;
    border: 1px dashed #ccc;
}
.emr-screening-banner-content {
    display: flex;
    align-items: center;
    gap: 12px;
}
.emr-screening-banner-icon {
    font-size: 24px;
}
.emr-screening-banner-details {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.emr-screening-banner-text {
    font-size: 16px;
    font-weight: 600;
    color: #333;
}
.emr-screening-banner-dob {
    font-size: 12px;
    color: #666;
}
.emr-screening-banner-edit {
    font-size: 13px;
}

/* Completeness score */
.emr-screening-completeness {
    background: var(--surface-primary);
    border: 1px solid #e0e0e0;
    border-radius: 10px;
    padding: 16px 20px;
    margin-bottom: 16px;
}
.emr-screening-completeness-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}
.emr-screening-completeness-header h3 {
    margin: 0;
    font-size: 15px;
    color: #333;
}

/* Donut chart */
.emr-screening-donut {
    width: 64px;
    height: 64px;
}
.emr-screening-donut-bg {
    fill: none;
    stroke: #eee;
    stroke-width: 3;
}
.emr-screening-donut-fill {
    fill: none;
    stroke: #4a90d9;
    stroke-width: 3;
    stroke-linecap: round;
    transform: rotate(-90deg);
    transform-origin: 50% 50%;
    transition: stroke-dasharray 0.6s ease;
}
.emr-screening-completeness-score { flex-shrink: 0; }
.emr-screening-donut-text {
    fill: #333;
    font-size: 12px;
    font-weight: 600;
    text-anchor: middle;
    dominant-baseline: middle;
}

/* Completeness breakdown bars */
.emr-screening-completeness-breakdown {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.emr-screening-completeness-row {
    display: flex;
    align-items: center;
    gap: 8px;
}
.emr-screening-completeness-label {
    width: 120px;
    font-size: 12px;
    color: #555;
    text-align: right;
    flex-shrink: 0;
}
.emr-screening-completeness-bar {
    flex: 1;
    height: 8px;
    background: #f0f0f0;
    border-radius: 4px;
    overflow: hidden;
}
.emr-screening-completeness-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.5s ease;
}
.emr-screening-bar--good { background: #4caf50; }
.emr-screening-bar--fair { background: #ff9800; }
.emr-screening-bar--poor { background: #f44336; }
.emr-screening-completeness-pct {
    width: 36px;
    font-size: 12px;
    color: #4b5563;
    text-align: right;
}

/* Screening alerts */
.emr-screening-alerts {
    background: var(--surface-primary);
    border: 1px solid #e0e0e0;
    border-radius: 10px;
    padding: 16px 20px;
    margin-bottom: 16px;
}
.emr-screening-alerts h3 {
    margin: 0 0 12px;
    font-size: 15px;
    color: #333;
}
.emr-screening-alerts--empty {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #2e7d32;
    font-size: 14px;
}
.emr-screening-alerts-icon { font-size: 20px; }
.emr-screening-alert-count {
    background: #f44336;
    color: var(--text-on-accent);
    font-size: 12px;
    padding: 2px 7px;
    border-radius: 10px;
    margin-left: 6px;
    font-weight: 600;
}
.emr-screening-alert {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 8px;
    margin-bottom: 8px;
}
.emr-screening-alert:last-child { margin-bottom: 0; }
.emr-screening-alert--overdue {
    background: #ffebee;
    border-left: 3px solid #f44336;
}
.emr-screening-alert--due-soon {
    background: #fff8e1;
    border-left: 3px solid #ff9800;
}
.emr-screening-alert--never-done {
    background: #ccfbf1;
    border-left: 3px solid #2196f3;
}
.emr-screening-alert-icon { font-size: 16px; margin-top: 2px; }
.emr-screening-alert-content strong {
    display: block;
    font-size: 13px;
    color: #333;
    margin-bottom: 2px;
}
.emr-screening-alert-content p {
    margin: 0;
    font-size: 12px;
    color: #555;
}

/* Section cards */
.emr-screening-sections {
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.emr-screening-section-card {
    background: var(--surface-primary);
    border: 1px solid #e0e0e0;
    border-radius: 10px;
    overflow: hidden;
}
.emr-screening-section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    cursor: pointer;
    user-select: none;
    background: #fafafa;
    border-bottom: 1px solid #e0e0e0;
}
.emr-screening-section-header:hover { background: #f0f0f0; }
.emr-screening-section-header h4 {
    margin: 0;
    font-size: 14px;
    color: #333;
}
.emr-screening-section-chevron {
    font-size: 12px;
    color: #4b5563;
    transition: transform 0.2s;
}
.emr-screening-section-card.collapsed .emr-screening-section-body { display: none; }
.emr-screening-section-card.collapsed .emr-screening-section-chevron { transform: rotate(-90deg); }
.emr-screening-section-body {
    padding: 12px 16px;
}

/* Items within section cards */
.emr-screening-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 0;
    border-bottom: 1px solid #f5f5f5;
    font-size: 13px;
}
.emr-screening-item:last-child { border-bottom: none; }
.emr-screening-item-name { flex: 1; color: #333; }
.emr-screening-item-code {
    font-family: monospace;
    font-size: 12px;
    background: #f0f0f0;
    padding: 2px 6px;
    border-radius: 3px;
    color: #666;
}
.emr-screening-item-detail { font-size: 12px; color: #4b5563; }
.emr-screening-item-tag {
    font-size: 12px;
    background: #ccfbf1;
    color: #0d9488;
    padding: 2px 8px;
    border-radius: 10px;
}
.emr-screening-item-label {
    font-weight: 600;
    color: #555;
    margin-right: 4px;
}
.emr-screening-no-data {
    color: #4b5563;
    font-size: 13px;
    font-style: italic;
    padding: 8px 0;
}

/* Status badges */
.emr-screening-status-badge {
    font-size: 12px;
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: 500;
    text-transform: capitalize;
}
.emr-screening-status--active { background: #e8f5e9; color: #2e7d32; }
.emr-screening-status--resolved { background: #f5f5f5; color: #4b5563; }
.emr-screening-status--current { background: #e8f5e9; color: #2e7d32; }
.emr-screening-status--due_soon { background: #fff8e1; color: #f57f17; }
.emr-screening-status--overdue { background: #ffebee; color: #c62828; }
.emr-screening-status--never_done { background: #ccfbf1; color: #0d9488; }
.emr-screening-status--unknown { background: #f5f5f5; color: #4b5563; }
.emr-screening-status--never { background: #e8f5e9; color: #2e7d32; }
.emr-screening-status--former { background: #fff8e1; color: #f57f17; }

/* Lab table */
.emr-screening-lab-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
.emr-screening-lab-table th {
    text-align: left;
    padding: 6px 8px;
    font-size: 12px;
    text-transform: uppercase;
    color: #4b5563;
    border-bottom: 2px solid #e0e0e0;
}
.emr-screening-lab-table td {
    padding: 6px 8px;
    border-bottom: 1px solid #f5f5f5;
}
.emr-screening-lab-row {}
.emr-screening-lab-name { font-weight: 500; color: #333; }
.emr-screening-lab-date { font-size: 12px; }
.emr-screening-lab-value { font-family: monospace; }
.emr-screening-lab-missing { color: #ccc; }
.emr-screening-lab-fresh { color: #2e7d32; }
.emr-screening-lab-aging { color: #f57f17; }
.emr-screening-lab-stale { color: #c62828; }

/* Recommendations */
.emr-screening-recommendations {
    background: var(--surface-primary);
    border: 1px solid #e0e0e0;
    border-radius: 10px;
    padding: 16px 20px;
    margin-bottom: 16px;
}
.emr-screening-recommendations h3 {
    margin: 0 0 12px;
    font-size: 15px;
    color: #333;
}
.emr-screening-domain-group {
    margin-bottom: 16px;
}
.emr-screening-domain-label {
    margin: 0 0 8px;
    font-size: 13px;
    color: #555;
    border-bottom: 1px solid #e0e0e0;
    padding-bottom: 4px;
}
.emr-screening-rec-card {
    padding: 10px 12px;
    border-radius: 8px;
    background: #fafafa;
    margin-bottom: 8px;
    border: 1px solid #eee;
}
.emr-screening-rec-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 8px;
}
.emr-screening-rec-text {
    font-size: 13px;
    color: #333;
    flex: 1;
}
.emr-screening-grade-badge {
    font-size: 12px;
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: 600;
    white-space: nowrap;
}
.emr-screening-grade--green { background: #e8f5e9; color: #2e7d32; }
.emr-screening-grade--blue { background: #ccfbf1; color: #0d9488; }
.emr-screening-grade--amber { background: #fff8e1; color: #f57f17; }
.emr-screening-rec-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 6px;
    font-size: 12px;
    color: #4b5563;
}
.emr-screening-rec-why { font-style: italic; }
.emr-screening-rec-interval {
    font-size: 12px;
    color: #666;
}
.emr-screening-rec-conflict {
    color: #c62828;
    font-weight: 500;
}
.emr-screening-rec-badges {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
    align-items: flex-start;
}

/* Unified recommendation card status colors */
.emr-screening-card--overdue { border-left: 4px solid #f44336; background: #fff8f7; }
.emr-screening-card--due-soon { border-left: 4px solid #ff9800; background: #fffcf5; }
.emr-screening-card--never-done { border-left: 4px solid #2196f3; background: #f8fbff; }
.emr-screening-card--completed { border-left: 4px solid #4caf50; background: #f8fdf8; }
.emr-screening-card--unknown { border-left: 4px solid #9e9e9e; }

/* Screening history line within a recommendation card */
.emr-screening-rec-history {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 6px;
    padding: 6px 8px;
    background: rgba(0,0,0,0.03);
    border-radius: 6px;
    font-size: 12px;
    color: #555;
    flex-wrap: wrap;
}
.emr-screening-rec-history-icon { font-size: 14px; }
.emr-screening-rec-next-due {
    margin-left: auto;
    font-size: 12px;
    color: #4b5563;
}
.emr-screening-rec-count {
    background: #4a90d9;
    color: var(--text-on-accent);
    font-size: 12px;
    padding: 2px 7px;
    border-radius: 10px;
    margin-left: 6px;
    font-weight: 600;
}

/* Status summary pills */
.emr-screening-status-summary {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 12px;
}
.emr-screening-summary-pill {
    font-size: 12px;
    padding: 4px 10px;
    border-radius: 12px;
    font-weight: 500;
}
.emr-screening-summary--overdue { background: #ffebee; color: #c62828; }
.emr-screening-summary--due-soon { background: #fff8e1; color: #f57f17; }
.emr-screening-summary--never-done { background: #ccfbf1; color: #0d9488; }
.emr-screening-summary--completed { background: #e8f5e9; color: #2e7d32; }

/* Source link styling */
.emr-screening-rec-source {
    background: #f0f0f0;
    padding: 1px 6px;
    border-radius: 3px;
    text-decoration: none;
    color: #555;
}
a.emr-screening-rec-source:hover {
    background: #e0e0e0;
    color: #0d9488;
}

/* Expandable recommendation detail */
.emr-screening-rec-card { cursor: pointer; transition: box-shadow 0.2s; }
.emr-screening-rec-card:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.08); }
.emr-screening-rec-card.expanded { box-shadow: 0 2px 12px rgba(0,0,0,0.1); }
.emr-screening-rec-expand-hint {
    font-size: 12px;
    color: #4b5563;
    margin-left: auto;
}
.emr-screening-rec-detail {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid #eee;
}
.emr-screening-detail-section {
    margin-bottom: 14px;
}
.emr-screening-detail-section:last-child { margin-bottom: 0; }
.emr-screening-detail-section h5 {
    margin: 0 0 4px;
    font-size: 12px;
    font-weight: 600;
    color: #555;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}
.emr-screening-detail-section p {
    margin: 0;
    font-size: 13px;
    color: #444;
    line-height: 1.5;
}
.emr-screening-detail-section ul {
    margin: 4px 0;
    padding-left: 20px;
    font-size: 13px;
    color: #444;
}
.emr-screening-detail-section ul li { margin-bottom: 2px; }
.emr-screening-detail-interval {
    margin-top: 4px;
    font-size: 12px;
    color: #666;
}
.emr-screening-detail-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}
.emr-screening-detail-tag {
    font-size: 12px;
    background: #f5f5f5;
    border: 1px solid #e0e0e0;
    padding: 2px 8px;
    border-radius: 10px;
    color: #555;
}
.emr-screening-citation {
    padding: 8px 10px;
    background: #fafafa;
    border-radius: 6px;
    border: 1px solid #eee;
    margin-bottom: 8px;
}
.emr-screening-citation:last-child { margin-bottom: 0; }
.emr-screening-citation-text {
    font-size: 12px;
    color: #444;
    line-height: 1.4;
    font-style: italic;
}
.emr-screening-citation-finding {
    font-size: 12px;
    color: #333;
    margin-top: 4px;
    font-style: normal;
    font-weight: 500;
}
.emr-screening-citation-year {
    font-size: 12px;
    color: #4b5563;
}
.emr-screening-detail-source {
    padding-top: 8px;
    border-top: 1px solid #eee;
}
.emr-screening-detail-source a {
    font-size: 13px;
    color: #0d9488;
    text-decoration: none;
    font-weight: 500;
}
.emr-screening-detail-source a:hover { text-decoration: underline; }

.emr-screening-detail-discuss {
    padding-top: 12px;
    border-top: 1px solid #eee;
    margin-top: 4px;
}

/* Form elements (for demographics modal) */
.emr-form-group {
    margin-bottom: 14px;
}
.emr-form-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 4px;
    color: #333;
}
.emr-input {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 14px;
    box-sizing: border-box;
}
.emr-input:focus {
    border-color: #4a90d9;
    outline: none;
    box-shadow: 0 0 0 2px rgba(74, 144, 217, 0.15);
}
.emr-btn-link {
    background: none;
    border: none;
    color: #4a90d9;
    cursor: pointer;
    text-decoration: underline;
    font-size: inherit;
    padding: 0;
}
.emr-btn-sm { padding: 4px 12px; font-size: 12px; }

/* Fetch recommendations button */
.emr-screening-rec-fetch {
    text-align: center;
    padding: 20px;
    background: var(--surface-primary);
    border: 1px dashed #ccc;
    border-radius: 10px;
    margin-bottom: 16px;
}
.emr-screening-rec-fetch-hint {
    font-size: 12px;
    color: #4b5563;
    margin-top: 8px;
}

/* Responsive */
@media (max-width: 768px) {
    .emr-screening-banner-content { flex-wrap: wrap; }
    .emr-screening-completeness-label { width: 80px; font-size: 12px; }
    .emr-screening-lab-table { font-size: 12px; }
    .emr-screening-alert { flex-direction: column; gap: 6px; }
}

/* ═══════════════════════════════════════════════════════════
   SYMPTOM NETWORK
   ═══════════════════════════════════════════════════════════ */

.emr-symptom-network {
    background: var(--card-bg, white);
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    overflow: hidden;
    margin-bottom: 24px;
}

.emr-sn-empty {
    padding-bottom: 24px;
}

.emr-sn-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color, #eee);
    flex-wrap: wrap;
    gap: 12px;
    background: linear-gradient(135deg, #0f9b8e 0%, #0a7a6e 100%);
}

.emr-sn-header h2 {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: #ffffff;
}

.emr-sn-stat-unexplained .emr-stat-value {
    color: #ffd480;
}

.emr-sn-header .emr-network-stats {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
    align-items: center;
}

.emr-sn-header .emr-stat-value {
    font-size: 18px;
    font-weight: 700;
    color: #ffffff;
    line-height: 1;
}

.emr-sn-header .emr-stat-label {
    font-size: 11px;
    color: rgba(255,255,255,0.75);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Red flag banners */
.emr-sn-flags {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px 20px;
    font-size: 13px;
}

.emr-sn-flags-urgent {
    background: #fff0f0;
    border-bottom: 1px solid #ffd0d0;
    color: #c0392b;
}

.emr-sn-flags-soon {
    background: #fffbf0;
    border-bottom: 1px solid #ffe0a0;
    color: #c07800;
}

.emr-sn-flag-icon { font-size: 18px; flex-shrink: 0; margin-top: 1px; }
.emr-sn-flag-item { margin-bottom: 4px; }
.emr-sn-flag-item:last-child { margin-bottom: 0; }

/* Body */
.emr-sn-body {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* Coverage bar */
.emr-sn-coverage {}
.emr-sn-coverage-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary, #666);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}
.emr-sn-coverage-bar {
    display: flex;
    height: 10px;
    border-radius: 5px;
    overflow: hidden;
    background: var(--bg-secondary, #f0f0f0);
    margin-bottom: 6px;
}
.emr-sn-bar-explained   { background: #27ae60; transition: width 0.4s; }
.emr-sn-bar-partial     { background: #f39c12; transition: width 0.4s; }
.emr-sn-bar-unexplained { background: #e74c3c; transition: width 0.4s; }

.emr-sn-coverage-counts {
    display: flex;
    gap: 16px;
    font-size: 12px;
    flex-wrap: wrap;
}
.emr-sn-count-explained   { color: #27ae60; font-weight: 600; }
.emr-sn-count-partial     { color: #f39c12; font-weight: 600; }
.emr-sn-count-unexplained { color: #e74c3c; font-weight: 600; }

/* Section titles */
.emr-sn-section-title {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-primary, #222);
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.emr-sn-section-icon { font-size: 16px; }

/* Candidate cause cards */
.emr-sn-causes-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.emr-sn-cause-card {
    border-radius: 8px;
    border: 1px solid var(--border-color, #eee);
    cursor: pointer;
    transition: box-shadow 0.15s;
    overflow: hidden;
}
.emr-sn-cause-card:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.1); }

.emr-sn-cause-new  { border-left: 3px solid #e74c3c; }
.emr-sn-cause-known { border-left: 3px solid #27ae60; }

.emr-sn-cause-header {
    padding: 12px 14px;
    position: relative;
}
.emr-sn-cause-title-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 4px;
    padding-right: 24px;
}
.emr-sn-cause-name {
    font-weight: 600;
    font-size: 14px;
    color: var(--text-primary, #222);
}
.emr-sn-cause-mechanism {
    font-size: 12px;
    color: var(--text-secondary, #666);
    margin-bottom: 8px;
    font-style: italic;
}
.emr-sn-cause-symptoms {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}
.emr-sn-cause-symptom-tag {
    background: rgba(15,155,142,0.1);
    color: #0a7a6e;
    border-radius: 12px;
    padding: 2px 8px;
    font-size: 11px;
    font-weight: 500;
}
.emr-sn-cause-chevron {
    position: absolute;
    top: 12px;
    right: 12px;
    font-size: 11px;
    color: var(--text-secondary, #888);
}

.emr-sn-cause-badge-new {
    background: #fde8e8;
    color: #c0392b;
    border-radius: 10px;
    padding: 2px 8px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    white-space: nowrap;
}
.emr-sn-cause-badge-known {
    background: #e8f8ee;
    color: #1e8449;
    border-radius: 10px;
    padding: 2px 8px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    white-space: nowrap;
}

/* Confidence badges */
.emr-sn-conf {
    border-radius: 10px;
    padding: 2px 8px;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
}
.emr-sn-conf-high { background: #e8f8ee; color: #1e8449; }
.emr-sn-conf-mod  { background: #fff8e8; color: #c07800; }
.emr-sn-conf-low  { background: #f8f8f8; color: #888; }

/* Cause detail (expanded) */
.emr-sn-cause-detail {
    border-top: 1px solid var(--border-color, #eee);
    padding: 12px 14px;
    background: var(--bg-secondary, #fafafa);
}
.emr-sn-confirm-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary, #666);
    margin-bottom: 6px;
}
.emr-sn-confirm-list {
    margin: 0;
    padding-left: 18px;
    font-size: 13px;
    color: var(--text-primary, #333);
    line-height: 1.6;
}

/* Symptom list */
.emr-sn-symptom-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.emr-sn-symptom-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 10px;
    border-radius: 6px;
    background: var(--bg-secondary, #f8f8f8);
}
.emr-sn-symptom-info {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    min-width: 0;
    flex-wrap: wrap;
}
.emr-sn-symptom-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary, #222);
    flex-shrink: 0;
}

/* Severity badges */
.emr-sn-sev {
    border-radius: 10px;
    padding: 2px 8px;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}
.emr-sn-sev-severe  { background: #fde8e8; color: #c0392b; }
.emr-sn-sev-mod     { background: #fff3e0; color: #e65100; }
.emr-sn-sev-mild    { background: #e8f5e9; color: #2e7d32; }
.emr-sn-sev-unknown { background: #f5f5f5; color: #9e9e9e; }

/* Explanation badges */
.emr-sn-expl {
    border-radius: 10px;
    padding: 2px 8px;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}
.emr-sn-expl-explained   { background: #e8f8ee; color: #1e8449; }
.emr-sn-expl-partial     { background: #fff8e8; color: #c07800; }
.emr-sn-expl-unexplained { background: #fde8e8; color: #c0392b; }

/* Persistence bar */
.emr-sn-persist-bar {
    width: 80px;
    height: 5px;
    border-radius: 3px;
    background: var(--border-color, #e0e0e0);
    flex-shrink: 0;
    overflow: hidden;
}
.emr-sn-persist-fill {
    height: 100%;
    background: #0f9b8e;
    border-radius: 3px;
    transition: width 0.3s;
}

@media (max-width: 640px) {
    .emr-sn-body { padding: 14px; }
    .emr-sn-symptom-row { flex-wrap: wrap; }
    .emr-sn-persist-bar { width: 100%; margin-top: 4px; }
}

