:root {
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --secondary-color: #64748b;
    --success-color: #10b981;
    --warning-color: #f59e0b;
    --danger-color: #ef4444;
    --bg-color: #f8fafc;
    --card-bg: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.1);
    --radius: 8px;
    --radius-lg: 12px;
}

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

body {
    font-family: 'Noto Sans SC', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    line-height: 1.6;
    color: var(--text-primary);
    background-color: var(--bg-color);
    min-height: 100vh;
}

#app {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

header {
    background: linear-gradient(135deg, #1e3a5f 0%, #2563eb 100%);
    color: white;
    padding: 0;
    box-shadow: var(--shadow-lg);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-content {
    max-width: 1400px;
    margin: 0 auto;
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

header h1 {
    font-size: 1.5rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

nav ul {
    list-style: none;
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

nav a {
    color: rgba(255, 255, 255, 0.8);
    text-decoration: none;
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
    font-weight: 500;
    transition: all 0.3s;
}

nav a:hover, nav a.active {
    color: white;
    background-color: rgba(255, 255, 255, 0.15);
}

.user-menu {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding-left: 1rem;
    border-left: 1px solid rgba(255, 255, 255, 0.2);
}

main {
    flex: 1;
    max-width: 1400px;
    width: 100%;
    margin: 0 auto;
    padding: 2rem;
}

section.page {
    display: none;
    animation: fadeIn 0.3s ease;
}

section.page.active {
    display: block;
}

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

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.page-header h2 {
    font-size: 1.75rem;
    color: var(--text-primary);
}

.subtitle {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.auth-container {
    max-width: 420px;
    margin: 3rem auto;
    background: var(--card-bg);
    padding: 2.5rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
}

.auth-logo {
    text-align: center;
    margin-bottom: 2rem;
}

.auth-logo h2 {
    font-size: 1.75rem;
    color: var(--primary-color);
    margin-bottom: 0.5rem;
}

.auth-logo p {
    color: var(--text-secondary);
}

.auth-tabs {
    display: flex;
    margin-bottom: 1.5rem;
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--bg-color);
}

.tab-btn {
    flex: 1;
    padding: 0.75rem;
    border: none;
    background: transparent;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.3s;
}

.tab-btn.active {
    background: var(--primary-color);
    color: white;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
    animation: fadeIn 0.3s ease;
}

.form-group {
    margin-bottom: 1.25rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--text-primary);
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    font-size: 1rem;
    transition: border-color 0.3s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.btn-primary {
    width: 100%;
    padding: 0.875rem 1.5rem;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: var(--radius);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.3s;
}

.btn-primary:hover {
    background: var(--primary-hover);
}

.btn-secondary {
    padding: 0.5rem 1rem;
    background: var(--secondary-color);
    color: white;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background 0.3s;
    text-decoration: none;
    font-size: 0.9rem;
}

.btn-secondary:hover {
    background: #475569;
}

.btn-small {
    padding: 0.375rem 0.75rem;
    font-size: 0.875rem;
}

.auth-notice {
    margin-top: 1.5rem;
    padding: 1rem;
    background: #f0f9ff;
    border-radius: var(--radius);
    border-left: 3px solid var(--primary-color);
}

.auth-notice p {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--card-bg);
    padding: 1.5rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    gap: 1rem;
    transition: transform 0.3s, box-shadow 0.3s;
}

.stat-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-lg);
}

.stat-icon {
    font-size: 2.5rem;
    width: 60px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #e0f2fe 0%, #bae6fd 100%);
    border-radius: var(--radius);
}

.stat-content h3 {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 0.25rem;
    font-weight: 500;
}

.stat-number {
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary-color);
}

.stat-text {
    font-size: 1rem;
    color: var(--text-secondary);
}

.chart-section {
    background: var(--card-bg);
    padding: 1.5rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    margin-bottom: 2rem;
}

.chart-section h3 {
    margin-bottom: 1rem;
    color: var(--text-primary);
}

.chart-container {
    height: 300px;
    position: relative;
}

.quick-actions {
    text-align: center;
}

.reports-grid,
.family-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.5rem;
}

.report-card,
.family-card {
    background: var(--card-bg);
    padding: 1.5rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    transition: transform 0.3s, box-shadow 0.3s;
    cursor: pointer;
    position: relative;
}

.report-card:hover,
.family-card:hover {
    transform: translateY(-5px);
    box-shadow: var(--shadow-lg);
}

.report-card h3,
.family-card h3 {
    font-size: 1.1rem;
    margin-bottom: 0.75rem;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.report-card p,
.family-card p {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 0.375rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.report-card .category-badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    background: #e0f2fe;
    color: var(--primary-color);
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 500;
}

.family-card .relation-badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    background: #f0fdf4;
    color: var(--success-color);
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 500;
}

/* Report Sub-type Label Styling */
.report-subtype-text {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background-color: #f5f3ff;
    color: #7c3aed;
    padding: 4px 10px;
    border-radius: 6px;
    font-weight: 600 !important;
    font-size: 0.85em !important;
    margin: 4px 0 12px 0 !important;
    border: 1px solid #ddd6fe;
    width: fit-content;
}

.search-filter {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    background: var(--card-bg);
    padding: 1rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
}

.search-box {
    display: flex;
    flex: 1;
    min-width: 250px;
    gap: 0.5rem;
}

.search-box input {
    flex: 1;
    padding: 0.625rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
}

.search-box button {
    padding: 0.625rem 1rem;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
}

.search-filter select {
    padding: 0.625rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    min-width: 150px;
    cursor: pointer;
}

.empty-state {
    grid-column: 1 / -1;
    text-align: center;
    padding: 3rem;
    color: var(--text-secondary);
}

.settings-container {
    display: block;
    column-count: 2;
    column-gap: 1.5rem;
}

.settings-card {
    background: var(--card-bg);
    padding: 1.5rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    break-inside: avoid;
    margin-bottom: 1.5rem;
}

/* Visibility Rules Fixes for UI Javascript Toggles */
.form-group.db-config,
.form-group.storage-config,
.form-group.vlm-config { 
    display: none; 
    margin-top: 15px; 
    background-color: var(--bg-color);
    padding: 10px;
    border-radius: var(--radius);
    border-left: 3px solid var(--primary-color);
}

.settings-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.settings-header h3 {
    font-size: 1.1rem;
    color: var(--text-primary);
}

.badge {
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 500;
}

.badge-info {
    background: #e0f2fe;
    color: var(--primary-color);
}

.badge-warning {
    background: #fef3c7;
    color: var(--warning-color);
}

.settings-desc {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 1rem;
}

.api-guide {
    margin: 1rem 0;
    padding: 0.75rem;
    background: var(--bg-color);
    border-radius: var(--radius);
}

.api-guide summary {
    cursor: pointer;
    font-weight: 500;
    color: var(--primary-color);
}

.guide-content {
    margin-top: 0.75rem;
    padding: 0.75rem;
    font-size: 0.875rem;
}

.guide-content h4 {
    margin: 0.5rem 0;
    color: var(--text-primary);
}

.guide-content ol {
    padding-left: 1.25rem;
    color: var(--text-secondary);
}

.guide-content a {
    color: var(--primary-color);
}

.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    align-items: center;
    justify-content: center;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--card-bg);
    padding: 2rem;
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 500px;
    position: relative;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-large {
    max-width: 800px;
}

.close {
    position: absolute;
    right: 1.25rem;
    top: 1rem;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-secondary);
    line-height: 1;
}

.close:hover {
    color: var(--text-primary);
}

.modal h3 {
    margin-bottom: 1.5rem;
    color: var(--text-primary);
}

.file-upload {
    border: 2px dashed var(--border-color);
    border-radius: var(--radius);
    padding: 1.5rem;
    text-align: center;
    transition: border-color 0.3s;
}

.file-upload:hover {
    border-color: var(--primary-color);
}

.file-upload input[type="file"] {
    width: 100%;
}

.file-preview {
    margin-top: 1rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.file-preview-item {
    position: relative;
    width: 80px;
    height: 80px;
    border-radius: var(--radius);
    overflow: hidden;
}

.file-preview-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.ocr-option {
    display: flex;
    align-items: center;
}

.ocr-option label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
}

.upload-progress {
    margin: 1rem 0;
    text-align: center;
}

.progress-bar {
    height: 8px;
    background: var(--bg-color);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 0.5rem;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary-color), var(--success-color));
    width: 0%;
    transition: width 0.3s;
}

#progress-text {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.detail-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.detail-info p {
    margin-bottom: 0.5rem;
    color: var(--text-secondary);
}

.detail-info strong {
    color: var(--text-primary);
    margin-right: 0.5rem;
}

.detail-image {
    margin-bottom: 1.5rem;
    text-align: center;
    background: var(--bg-color);
    border-radius: var(--radius);
    padding: 1rem;
}

.detail-image img {
    max-width: 100%;
    max-height: 400px;
    border-radius: var(--radius);
}

.detail-ocr h4 {
    margin-bottom: 0.75rem;
    color: var(--text-primary);
}

.detail-ocr pre {
    background: var(--bg-color);
    padding: 1rem;
    border-radius: var(--radius);
    overflow-x: auto;
    font-size: 0.875rem;
    max-height: 300px;
    overflow-y: auto;
}

footer {
    background: #1e293b;
    color: rgba(255, 255, 255, 0.7);
    text-align: center;
    padding: 1.5rem;
    margin-top: auto;
}

footer p {
    font-size: 0.875rem;
}

@media (max-width: 768px) {
    .header-content {
        flex-direction: column;
        text-align: center;
    }
    
    nav ul {
        flex-wrap: wrap;
        justify-content: center;
    }
    
    main {
        padding: 1rem;
    }
    
    .stats-grid {
        grid-template-columns: 1fr;
    }
    
    .settings-container {
        column-count: 1;
    }
    
    .form-row {
        grid-template-columns: 1fr;
    }
    
    .search-filter {
        flex-direction: column;
    }
    
    .search-box {
        width: 100%;
    }
}

/* Toast Notifications */
.toast {
    background-color: #fff;
    color: #333;
    padding: 12px 20px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    font-size: 0.95em;
    display: flex;
    align-items: center;
    gap: 10px;
    transform: translateX(120%);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    max-width: 300px;
    border-left: 4px solid #333;
    margin-bottom: 10px;
}
.toast.toast-show {
    transform: translateX(0);
}
.toast.toast-success {
    border-left-color: #4CAF50;
}
.toast.toast-error {
    border-left-color: #f44336;
}
.toast.toast-info {
    border-left-color: #2196F3;
}

/* 打印与 PDF 导出优化 (Print & PDF Export Optimizations) */
@media print {
    body {
        margin: 0;
        padding: 0;
        background: white !important;
    }
    /* Hide everything in the body by default */
    body > *:not(.modal) {
        display: none !important;
    }
    /* Hide all modals except the active detail modal */
    .modal {
        display: none !important;
    }
    #report-detail-modal {
        display: block !important;
        position: relative !important;
        left: auto !important;
        top: auto !important;
        width: 100% !important;
        min-height: auto !important;
        background: none !important;
        padding: 0 !important;
        margin: 0 !important;
        overflow: visible !important;
    }
    .modal-content {
        box-shadow: none !important;
        border: none !important;
        max-width: 100% !important;
        padding: 0 !important;
        margin: 0 !important;
        overflow: visible !important;
        max-height: none !important;
    }
    .close, .detail-actions, footer, header {
        display: none !important;
    }
    .detail-ocr pre {
        white-space: pre-wrap;
        max-height: none !important;
        overflow: visible !important;
    }
    html, body {
        height: auto;
        overflow: visible !important;
        background-color: white !important;
        margin: 0;
    }
    
    /* 强制在化验表格与原片之间进行精准分页，避免图片被截断 */
    .detail-image {
        page-break-before: always;
        break-before: page;
        text-align: center;
        width: 100%;
        margin-top: 2cm;
    }
    .detail-image img {
        max-width: 100% !important;
        max-height: 90vh !important;
        object-fit: contain;
        page-break-inside: avoid;
        break-inside: avoid;
    }
    table {
        page-break-inside: auto;
    }
    tr {
        page-break-inside: avoid;
        page-break-after: auto;
    }
}
/* Health Timeline Styles */
.timeline-layout {
    display: flex;
    gap: 2rem;
    align-items: flex-start;
}

.timeline-sidebar {
    width: 280px;
    flex-shrink: 0;
    position: sticky;
    top: 100px;
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(10px);
    padding: 1.5rem;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow);
}

.timeline-main {
    flex: 1;
}

.filter-group {
    margin-bottom: 2rem;
}

.filter-group label {
    display: block;
    margin-bottom: 0.75rem;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.status-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.filter-btn {
    padding: 0.5rem 1rem;
    border: 1px solid var(--border-color);
    background: white;
    border-radius: 20px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.3s;
}

.filter-btn:hover {
    border-color: var(--primary-color);
}

.filter-btn.active {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.timeline-stats-card {
    background: rgba(255, 255, 255, 0.5);
    border-radius: var(--radius);
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.stat-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.stat-item .label {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.stat-item .value {
    font-weight: 700;
}

.stat-item .value.alert { color: var(--danger-color); }
.stat-item .value.improved { color: var(--warning-color); }
.stat-item .value.normal { color: var(--success-color); }

.timeline-v-container {
    padding-left: 20px;
    border-left: 2px solid var(--border-color);
    margin-left: 10px;
    display: flex;
    flex-direction: column;
    gap: 2rem;
    position: relative;
}

.timeline-item {
    position: relative;
}

.timeline-dot {
    position: absolute;
    left: -29px;
    top: 20px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--bg-color);
    border: 3px solid var(--secondary-color);
    z-index: 1;
    box-shadow: 0 0 10px rgba(0,0,0,0.1);
}

.timeline-item.status-alert .timeline-dot {
    border-color: var(--danger-color);
    box-shadow: 0 0 15px var(--danger-color);
    animation: pulse-red 2s infinite;
}

.timeline-item.status-improved .timeline-dot {
    border-color: var(--warning-color);
}

.timeline-item.status-normal .timeline-dot {
    border-color: var(--success-color);
}

.timeline-card {
    background: var(--card-bg);
    padding: 1.5rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    cursor: pointer;
    border: 1px solid transparent;
}

.timeline-card:hover {
    transform: translateX(10px);
    box-shadow: var(--shadow-lg);
    border-color: var(--primary-color);
}

.timeline-date {
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--primary-color);
    margin-bottom: 0.5rem;
    display: flex;
    justify-content: space-between;
}

.timeline-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.timeline-desc {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.status-tag {
    font-size: 0.7rem;
    padding: 2px 8px;
    border-radius: 4px;
    font-weight: 600;
    text-transform: uppercase;
}

.status-tag.alert { background: #fee2e2; color: #991b1b; }
.status-tag.improved { background: #fef3c7; color: #92400e; }
.status-tag.normal { background: #d1fae5; color: #065f46; }

@keyframes pulse-red {
    0% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.3); opacity: 0.7; }
    100% { transform: scale(1); opacity: 1; }
}

@media (max-width: 900px) {
    .timeline-layout {
        flex-direction: column;
    }
    .timeline-sidebar {
        width: 100%;
        position: static;
        margin-bottom: 2rem;
    }
}
