/* ===== CSS 变量（设计令牌） ===== */
:root {
    --bg-primary: #f8fafc;
    --bg-card: #ffffff;
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --accent-shadow: rgba(59, 130, 246, 0.25);
    --border: #e2e8f0;
    --border-light: #f1f5f9;
    --cog-color: #f59e0b;
    --mot-color: #f97316;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.04);
    --radius: 8px;

    /* 四象限特征配色 */
    --color-cog-cog: #3b82f6;
    --color-cog-mot: #10b981;
    --color-mot-mot: #f59e0b;
    --color-mot-cog: #ec4899;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* ===== 应用布局 ===== */
.app-layout {
    display: grid;
    grid-template-columns: 260px 1fr;
    flex: 1;
    overflow: hidden;
}

.main-content {
    padding: 0.8rem 1rem 0.8rem 1rem;
    overflow-y: auto;
    max-width: 100%;
}

/* ===== 顶部标题栏 ===== */
.app-header {
    background: var(--bg-card);
    border-bottom: 2px solid var(--accent);
    padding: 0.7rem 1rem;
    margin-bottom: 0.6rem;
    border-radius: 8px 8px 0 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.app-header h2 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 800;
    color: var(--text-primary);
    letter-spacing: -0.02em;
}

.app-header .subtitle {
    margin: 0.15rem 0 0 0;
    font-size: 0.78rem;
    color: var(--text-secondary);
    font-weight: 500;
}

/* ===== 侧边栏 ===== */
.sidebar {
    background: var(--bg-card);
    border-right: 1px solid var(--border);
    padding: 1rem 0.85rem;
    overflow-y: auto;
    min-width: 200px;
}

.sidebar h3 {
    color: var(--text-primary);
    font-size: 1rem;
    font-weight: 700;
    margin-bottom: 0.6rem;
}

.sidebar label {
    font-size: 0.78rem;
    color: var(--text-secondary);
    font-weight: 500;
    display: block;
    margin-bottom: 0.2rem;
}

.sidebar input,
.sidebar select,
.sidebar textarea {
    width: 100%;
    padding: 0.4rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.8rem;
    color: var(--text-primary);
    background: var(--bg-card);
    margin-bottom: 0.55rem;
}

.sidebar input:focus,
.sidebar select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-shadow);
}

.sidebar input[type="range"] {
    padding: 0;
    border: none;
}

.path-control {
    display: flex;
    gap: 0.35rem;
    margin-bottom: 0.55rem;
}

.path-control input {
    margin-bottom: 0;
    min-width: 0;
}

.path-picker-btn {
    flex: 0 0 auto;
    padding: 0.4rem 0.55rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-primary);
    color: var(--text-secondary);
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
}

.path-picker-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--bg-card);
}

.sidebar .form-row {
    display: flex;
    gap: 0.4rem;
}

.sidebar .form-row > * {
    flex: 1;
}

.sidebar .divider {
    border-top: 1px solid var(--border);
    margin: 0.6rem 0;
}

.range-value {
    font-size: 0.72rem;
    color: var(--accent);
    font-weight: 700;
    margin-left: 0.3rem;
}

/* 模式切换按钮 */
.mode-switch {
    display: flex;
    gap: 0.3rem;
}

.mode-btn {
    flex: 1;
    padding: 0.35rem 0.4rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-card);
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s ease;
}

.mode-btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #ffffff;
}

.mode-btn:hover:not(.active) {
    background: var(--bg-primary);
}

/* ===== 主按钮 ===== */
.btn-primary {
    background: var(--accent);
    border: 1px solid var(--accent);
    color: #ffffff;
    border-radius: 6px;
    font-weight: 700;
    font-size: 0.88rem;
    height: 2.5rem;
    width: 100%;
    letter-spacing: 0.03em;
    cursor: pointer;
    transition: all 0.15s ease;
}

.btn-primary:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
    box-shadow: 0 2px 8px var(--accent-shadow);
}

.btn-primary:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

/* ===== 输入行 ===== */
.input-row {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    margin-bottom: 0.55rem;
}

.patient-id-input {
    flex: 1;
    padding: 0.45rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.88rem;
    color: var(--text-primary);
    background: var(--bg-card);
}

.patient-id-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-shadow);
}

/* ===== 卡片基类 ===== */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.75rem 0.85rem;
    margin-bottom: 0.55rem;
    box-shadow: var(--shadow-sm);
}

.card-header {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    margin-bottom: 0.5rem;
}

.card-header .accent-bar {
    width: 3px;
    height: 16px;
    background: var(--accent);
    border-radius: 2px;
    flex-shrink: 0;
}

.card-header .card-title {
    font-weight: 700;
    font-size: 0.85rem;
    color: var(--text-primary);
}

.card-header .card-subtitle {
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-left: 0.3rem;
}

/* ===== 人口学信息指标 ===== */
.demo-grid {
    display: flex;
    gap: 0.4rem;
}

.demo-item {
    flex: 1;
    background: var(--bg-primary);
    border-radius: 6px;
    padding: 0.45rem 0.4rem;
    text-align: center;
    min-width: 0;
}

.demo-item .demo-label {
    font-size: 0.68rem;
    color: var(--text-muted);
}

.demo-item .demo-value {
    font-weight: 700;
    font-size: 0.92rem;
    color: var(--text-primary);
}

/* ===== 诊断卡片 ===== */
.diag-cards {
    display: flex;
    gap: 0.55rem;
    margin-bottom: 0.55rem;
}

.diag-card {
    flex: 1;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.7rem 0.8rem;
    display: flex;
    align-items: center;
    gap: 0.65rem;
}

.diag-card .diag-info .diag-label {
    font-weight: 700;
    font-size: 0.72rem;
    color: #334155;
}

.diag-card .diag-info .diag-grade {
    font-size: 1rem;
    font-weight: 800;
    color: var(--text-primary);
    margin: 0.12rem 0;
}

.diag-badge {
    display: inline-block;
    padding: 0.1rem 0.4rem;
    border-radius: 10px;
    font-size: 0.65rem;
    font-weight: 600;
}

.diag-badge.cognitive { background: #fef3c7; color: #92400e; }
.diag-badge.motor     { background: #fed7aa; color: #9a3412; }

/* ===== CSS 环形饼图（conic-gradient） ===== */
.confidence-ring {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.confidence-ring .ring-center {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--bg-card);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 800;
}

/* ===== 特征分组卡片 ===== */
.feature-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.4rem;
}

.feature-card {
    background: var(--bg-primary);
    border-radius: 6px;
    padding: 0.5rem 0.6rem;
    border-left: 3px solid var(--accent);
}

.feature-card.cog-cog { border-left-color: var(--color-cog-cog); }
.feature-card.cog-mot { border-left-color: var(--color-cog-mot); }
.feature-card.mot-mot { border-left-color: var(--color-mot-mot); }
.feature-card.mot-cog { border-left-color: var(--color-mot-cog); }

.feature-card .feat-group {
    font-size: 0.62rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin-bottom: 0.25rem;
}

.feature-card.cog-cog .feat-group { color: #2563eb; }
.feature-card.cog-mot .feat-group { color: #059669; }
.feature-card.mot-mot .feat-group { color: #d97706; }
.feature-card.mot-cog .feat-group { color: #db2777; }

.feature-card .feat-name {
    font-weight: 700;
    font-size: 0.78rem;
    color: var(--text-primary);
}

.feature-card .feat-value {
    font-size: 0.68rem;
    color: var(--text-secondary);
    margin-bottom: 0.3rem;
}

.feature-card .weight-bar {
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    margin-bottom: 0.15rem;
}

.feature-card .weight-bar-fill {
    height: 4px;
    border-radius: 2px;
}

.feature-card .weight-value {
    font-size: 0.62rem;
    color: var(--text-muted);
    text-align: right;
}

/* ===== RAG 检索证据 ===== */
.knowledge-card .accent-bar {
    background: #0f766e;
}

.knowledge-flow {
    display: flex;
    gap: 0.35rem;
    flex-wrap: wrap;
    margin-bottom: 0.5rem;
}

.knowledge-flow span {
    background: #ecfdf5;
    border: 1px solid #bbf7d0;
    border-radius: 999px;
    color: #047857;
    font-size: 0.66rem;
    font-weight: 700;
    padding: 0.18rem 0.5rem;
}

.knowledge-source-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.4rem;
}

.knowledge-source-card {
    background: var(--bg-primary);
    border: 1px solid var(--border-light);
    border-left: 3px solid #0f766e;
    border-radius: 6px;
    padding: 0.5rem 0.6rem;
    min-width: 0;
}

.knowledge-source-tag {
    color: #0f766e;
    font-size: 0.62rem;
    font-weight: 800;
    letter-spacing: 0.03em;
    margin-bottom: 0.25rem;
    text-transform: uppercase;
}

.knowledge-source-title {
    color: var(--text-primary);
    font-size: 0.78rem;
    font-weight: 750;
    line-height: 1.35;
    margin-bottom: 0.25rem;
}

.knowledge-source-name {
    color: var(--text-secondary);
    font-size: 0.68rem;
    line-height: 1.45;
}

/* ===== 折叠面板（details/summary） ===== */
.accordion {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--bg-card);
}

.accordion details {
    border-bottom: 1px solid var(--border-light);
}

.accordion details:last-of-type {
    border-bottom: none;
}

.accordion summary {
    padding: 0.55rem 0.75rem;
    font-weight: 600;
    font-size: 0.8rem;
    color: var(--text-primary);
    background: var(--bg-card);
    cursor: pointer;
    list-style: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: background 0.12s ease;
}

.accordion summary:hover {
    background: var(--bg-primary);
}

.accordion summary::-webkit-details-marker {
    display: none;
}

.accordion summary::after {
    content: "\25B8";
    font-size: 0.65rem;
    color: var(--text-muted);
    transition: transform 0.2s ease;
}

.accordion details[open] summary::after {
    transform: rotate(90deg);
}

.accordion .detail-content {
    padding: 0.5rem 0.75rem 0.65rem 0.75rem;
    font-size: 0.78rem;
    color: #475569;
    line-height: 1.65;
    background: #fafbfc;
}

.accordion-footer {
    padding: 0.4rem 0.75rem;
    font-size: 0.65rem;
    color: var(--text-muted);
    text-align: center;
    background: #fafbfc;
    border-top: 1px solid var(--border-light);
}

/* ===== 批量处理卡片 ===== */
.batch-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 0.45rem;
}

.batch-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.55rem 0.6rem;
    font-size: 0.72rem;
    transition: border-color 0.2s ease;
}

.batch-card.pending {
    background: var(--bg-primary);
    border-style: dashed;
    color: var(--text-muted);
}

.batch-card.processing {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.12);
}

.batch-card.done {
    border-color: var(--border);
}

.batch-card .batch-id {
    font-weight: 700;
    font-size: 0.8rem;
    color: var(--text-primary);
}

.batch-card .batch-status {
    font-size: 0.65rem;
    margin-top: 0.15rem;
}

.batch-card .batch-grade {
    font-size: 0.62rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
}

.batch-card .mini-progress {
    height: 3px;
    background: var(--border);
    border-radius: 1px;
    margin-top: 0.3rem;
}

.batch-card .mini-progress-fill {
    height: 3px;
    border-radius: 1px;
    background: var(--accent);
}

/* ===== 可折叠区域 ===== */
.collapsible {
    margin-bottom: 0.55rem;
}

.collapsible summary {
    padding: 0.45rem 0.65rem;
    font-weight: 600;
    font-size: 0.78rem;
    color: var(--text-secondary);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
    list-style: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: background 0.12s ease;
}

.collapsible summary:hover {
    background: var(--bg-primary);
}

.collapsible summary::-webkit-details-marker {
    display: none;
}

.collapsible summary::after {
    content: "\25B8";
    font-size: 0.65rem;
    color: var(--text-muted);
    transition: transform 0.2s ease;
}

.collapsible details[open] summary::after {
    transform: rotate(90deg);
}

.collapsible .collapsible-body {
    padding: 0.5rem 0.65rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-top: none;
    border-radius: 0 0 6px 6px;
}

/* ===== 数据表格 ===== */
.dataframe-container {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    margin-top: 0.5rem;
}

.dataframe-container table {
    width: 100%;
    font-size: 0.72rem;
    border-collapse: collapse;
}

.dataframe-container th {
    background: var(--bg-primary);
    color: var(--text-secondary);
    font-weight: 600;
    padding: 0.4rem 0.6rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.dataframe-container td {
    padding: 0.35rem 0.6rem;
    border-bottom: 1px solid var(--border-light);
}

/* ===== 加载状态 ===== */
.spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

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

.loading-overlay {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 1.5rem;
    color: var(--text-secondary);
    font-size: 0.82rem;
}

.error-message {
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #991b1b;
    padding: 0.6rem 0.8rem;
    border-radius: 6px;
    font-size: 0.8rem;
    margin-bottom: 0.5rem;
}

.success-message {
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    color: #166534;
    padding: 0.6rem 0.8rem;
    border-radius: 6px;
    font-size: 0.8rem;
    margin-bottom: 0.5rem;
}

.empty-state {
    color: var(--text-muted);
    font-size: 0.78rem;
    text-align: center;
    padding: 1rem;
}

/* ===== 下载按钮 ===== */
.download-btn {
    display: inline-block;
    background: var(--accent);
    color: #ffffff;
    border: 1px solid var(--accent);
    border-radius: 6px;
    font-weight: 700;
    font-size: 0.88rem;
    padding: 0.55rem 1.2rem;
    letter-spacing: 0.03em;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.15s ease;
    margin-top: 0.5rem;
}

.download-btn:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
    box-shadow: 0 2px 8px var(--accent-shadow);
}

/* ===== JSON 展示 ===== */
.json-block {
    background: #fafbfc;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.6rem 0.75rem;
    font-family: "SF Mono", "Consolas", "Liberation Mono", monospace;
    font-size: 0.7rem;
    line-height: 1.5;
    overflow-x: auto;
    white-space: pre-wrap;
    word-break: break-all;
    max-height: 400px;
    overflow-y: auto;
}

/* ===== 提示/免责声明 ===== */
.disclaimer {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-align: center;
    padding: 0.4rem;
    border-top: 1px solid var(--border-light);
    margin-top: 0.5rem;
}

/* ===== 辅助类 ===== */
.text-muted  { color: var(--text-muted); font-size: 0.72rem; }
.divider     { border-top: 1px solid var(--border); margin: 0.5rem 0; }

.section-title {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 0.4rem;
}

.hidden { display: none !important; }

/* ===== 响应式 ===== */
@media (max-width: 768px) {
    .app-layout {
        grid-template-columns: 1fr;
    }

    .sidebar {
        display: none;
    }

    .diag-cards {
        flex-direction: column;
    }

    .feature-grid {
        grid-template-columns: 1fr;
    }

    .knowledge-source-grid {
        grid-template-columns: 1fr;
    }

    .demo-grid {
        flex-wrap: wrap;
    }

    .demo-item {
        flex: 1 1 45%;
    }

    .form-row {
        flex-direction: column;
    }
}
