/* 全局样式 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #2c5f2d;
    --primary-light: #4a8c4e;
    --primary-dark: #1a3f1b;
    /* 派生色 — 由 brand.js 动态计算并覆盖（品牌切换时自动更新） */
    --primary-focus-shadow: rgba(44, 95, 45, 0.10);
    --primary-bg-light: #f0f7f0;
    --secondary-color: #8b4513;
    --accent-color: #d4a574;
    --bg-color: #f8f5f0;
    --card-bg: #ffffff;
    --text-primary: #2d2d2d;
    --text-secondary: #666666;
    --border-color: #e0ddd8;
    --success-color: #52c41a;
    --warning-color: #faad14;
    --error-color: #f5222d;
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.08);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.12);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.15);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
}

body {
    font-family: 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', 'Noto Sans SC', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg-color);
    color: var(--text-primary);
    line-height: 1.6;
    /* [v1.8.5] dvh 优先：动态视口适配 iOS Safari/Android Chrome URL 栏伸缩 */
    min-height: 100vh;
    min-height: 100dvh;
    /* [v1.10.27] mobile-polish.js 提供 --app-h（visualViewport 真实可视高度） */
    min-height: var(--app-h, 100dvh);
    display: flex;
    flex-direction: column;
    /* 防 iOS Safari 整页橡皮筋外露白色背景 */
    overscroll-behavior-y: contain;
}

/* [v1.10.27] 软键盘弹起时（Android），底部 padding 等于键盘高度，防按钮被遮 */
.kb-open .form-section,
.kb-open .input-section,
.kb-open .main-content {
    padding-bottom: calc(var(--kb-h, 0px) + 1rem);
}
/* 键盘弹起时隐藏底部 sticky 元素（按钮通常会自动 scrollIntoView 到可见区） */
.kb-open .nav-bottom,
.kb-open .footer { display: none; }

/* [v1.10.27] 尊重用户的减弱动画偏好 + .reduced-motion class（由 JS 注入） */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}
html.reduced-motion *, html.reduced-motion *::before, html.reduced-motion *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
}

/* 导航栏 */
.navbar {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-light));
    color: white;
    padding: 1.5rem 0;
    /* [v1.8.5] 顶部安全区：iPhone 全面屏刘海/灵动岛不再压住 logo */
    padding-top: max(1.5rem, calc(0.8rem + env(safe-area-inset-top, 0px)));
    box-shadow: var(--shadow-md);
    position: sticky;
    top: 0;
    z-index: 100;
}

.navbar .container {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.logo {
    font-size: 2.5rem;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.2));
}

.navbar h1 {
    font-family: 'Songti SC', 'STSong', 'SimSun', 'Noto Serif SC', 'Hiragino Mincho ProN', serif;
    font-size: 1.8rem;
    font-weight: 700;
    letter-spacing: 0.5px;
}

.nav-info {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.nav-link {
    color: rgba(255, 255, 255, 0.9);
    text-decoration: none;
    padding: 0.4rem 0.8rem;
    border-radius: var(--radius-sm);
    border: 1px solid rgba(255, 255, 255, 0.3);
    font-size: 0.85rem;
    transition: all 0.2s;
}

.nav-link:hover {
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
}

.github-link {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: white;
    text-decoration: none;
    padding: 0.5rem 1rem;
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.15);
    /* [v1.10.38] -webkit- 前缀 */
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    transition: all 0.3s ease;
    font-size: 0.9rem;
}

.github-link:hover {
    background: rgba(255, 255, 255, 0.25);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.github-link svg {
    width: 20px;
    height: 20px;
}

.status-badge {
    background: rgba(255, 255, 255, 0.2);
    padding: 0.5rem 1rem;
    border-radius: 20px;
    font-size: 0.9rem;
    /* [v1.10.38] -webkit- 前缀：iOS Safari 15 以下 / 微信内置浏览器需要 */
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
}

.status-badge.healthy {
    background: rgba(82, 196, 26, 0.3);
}

.status-badge.warn {
    background: rgba(250, 173, 20, 0.35);   /* 橙黄：LLM正常但部分组件异常 */
}

.status-badge.error {
    background: rgba(245, 34, 45, 0.3);
}

/* 表单校验错误提示 */
.field-error {
    color: var(--error-color);
    font-size: 0.82rem;
    margin-top: 0.25rem;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-4px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* 容器 */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 2rem;
}

/* 主内容区 */
.main-content {
    flex: 1;
    padding: 3rem 0;
}

/* AI 体质评估入口横幅 */
.ai-diagnosis-banner {
    display: block;
    /* [v1.10.52] 使用 CSS 变量 — 品牌主色自动适配（真爱金/书院棕/默认绿） */
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-light) 50%, var(--primary-color) 100%);
    border-radius: var(--radius-lg);
    padding: 1.5rem 2rem;
    margin-bottom: 2.5rem;
    text-decoration: none;
    color: #fff;
    box-shadow: 0 4px 20px var(--primary-focus-shadow);
    /* [v1.10.52] transition: all 性能反模式 → 精确声明 */
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    position: relative;
    overflow: hidden;
}

.ai-diagnosis-banner::before {
    content: '';
    position: absolute;
    top: -50%;
    right: -20%;
    width: 300px;
    height: 300px;
    background: rgba(255, 255, 255, 0.06);
    border-radius: 50%;
}

.ai-diagnosis-banner:hover {
    transform: translateY(-3px);
    /* [v1.10.52] 使用品牌色变量 */
    box-shadow: 0 8px 30px var(--primary-focus-shadow);
}

.banner-content {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    position: relative;
    z-index: 1;
}

.banner-icon {
    font-size: 3rem;
    flex-shrink: 0;
    width: 64px;
    height: 64px;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(10px);
}

.banner-text {
    flex: 1;
}

.banner-text h2 {
    font-family: 'Songti SC', 'STSong', 'SimSun', 'Noto Serif SC', 'Hiragino Mincho ProN', serif;
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 0.3rem;
    color: #fff;
}

.banner-text p {
    font-size: 0.95rem;
    color: rgba(255, 255, 255, 0.85);
    line-height: 1.5;
}

.banner-arrow {
    font-size: 2rem;
    font-weight: 700;
    flex-shrink: 0;
    opacity: 0.7;
    transition: all 0.3s ease;
}

.ai-diagnosis-banner:hover .banner-arrow {
    opacity: 1;
    transform: translateX(5px);
}

@media (max-width: 768px) {
    .ai-diagnosis-banner {
        padding: 1.25rem;
    }
    .banner-icon {
        font-size: 2rem;
        width: 48px;
        height: 48px;
        border-radius: 12px;
    }
    .banner-text h2 {
        font-size: 1.2rem;
    }
    .banner-text p {
        font-size: 0.85rem;
    }
    .banner-arrow {
        font-size: 1.5rem;
    }
}

/* 章节样式 */
section {
    margin-bottom: 3rem;
}

.section-header {
    text-align: center;
    margin-bottom: 2.5rem;
}

.section-header h2 {
    font-family: 'Songti SC', 'STSong', 'SimSun', 'Noto Serif SC', 'Hiragino Mincho ProN', serif;
    font-size: 2rem;
    color: var(--primary-color);
    margin-bottom: 0.5rem;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 1rem;
}

/* 表单样式 */
.patient-form {
    background: var(--card-bg);
    padding: 2.5rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
}

.form-group {
    margin-bottom: 2rem;
}

.form-group label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 0.75rem;
    font-size: 1rem;
}

.label-icon {
    font-size: 1.3rem;
}

.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 0.9rem 1.2rem;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-sm);
    /* [v1.8.5] 显式 16px：低于 16px iOS Safari 会自动放大整页让人眩晕 */
    font-size: 16px;
    line-height: 1.5;
    font-family: inherit;
    transition: all 0.3s ease;
    background: #fafafa;
    /* iOS select / textarea 默认外观去除，统一风格 */
    -webkit-appearance: none;
    appearance: none;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary-color);
    background: white;
    box-shadow: 0 0 0 3px var(--primary-focus-shadow);
}

.form-group textarea {
    resize: vertical;
    min-height: 100px;
}

/* [v1.10.9] iOS Safari 防自动放大: 输入框字号 < 16px 时聚焦会触发页面放大,
   导致后续布局割裂。强制移动设备上 input/textarea/select 至少 16px */
@media (hover: none) and (pointer: coarse) {
    input, textarea, select {
        font-size: 16px !important;
    }
    /* 触摸反馈: 按钮点下时立刻有视觉变化 (移动端原生 click 有 300ms 延迟感) */
    button, .btn, [role="button"] {
        -webkit-tap-highlight-color: var(--primary-focus-shadow);
        touch-action: manipulation;
    }
    button:active, .btn:active {
        transform: scale(0.98);
        transition: transform 0.05s;
    }
}

.form-hint {
    display: block;
    margin-top: 0.5rem;
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.char-count {
    font-size: 0.82rem;
    color: var(--text-secondary);
    margin-top: 0.35rem;
    transition: color 0.2s;
}

.char-count.warn {
    color: #e6a817;
    font-weight: 500;
}

.char-count.over {
    color: var(--error-color);
    font-weight: 600;
}

/* 按钮样式 */
.form-actions {
    display: flex;
    gap: 1rem;
    margin-top: 2.5rem;
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.9rem 2rem;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    font-family: inherit;
}

.btn-icon {
    font-size: 1.2rem;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-light));
    color: white;
    box-shadow: var(--shadow-sm);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-secondary {
    background: white;
    color: var(--text-primary);
    border: 2px solid var(--border-color);
}

.btn-secondary:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* 进度显示 */
.progress-section {
    background: var(--card-bg);
    padding: 2.5rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
}

.progress-container {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.progress-item {
    display: flex;
    gap: 1.5rem;
    padding: 1.5rem;
    background: #fafafa;
    border-radius: var(--radius-md);
    border-left: 4px solid var(--border-color);
    transition: all 0.3s ease;
}

.progress-item.active {
    border-left-color: var(--primary-color);
    background: var(--primary-bg-light);
}

.progress-item.completed {
    border-left-color: var(--success-color);
    background: #f6ffed;
}

/* Agent 出错：红色边框 + 淡红背景 */
.progress-item.error {
    border-left-color: var(--error-color);
    background: #fff2f0;
}
.progress-item.error .progress-fill {
    background: var(--error-color);
    width: 100% !important;
    opacity: 0.4;
}

.progress-icon {
    font-size: 2.5rem;
    min-width: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.progress-content {
    flex: 1;
}

.progress-content h3 {
    font-size: 1.1rem;
    margin-bottom: 0.3rem;
    color: var(--text-primary);
}

.progress-content p {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 0.8rem;
}

.progress-bar {
    height: 6px;
    background: #e0e0e0;
    border-radius: 3px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary-color), var(--primary-light));
    width: 0%;
    transition: width 0.5s ease;
    border-radius: 3px;
}

/* 结果展示 */
.result-section {
    background: var(--card-bg);
    padding: 2.5rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
}

.header-actions {
    display: flex;
    gap: 0.8rem;
    margin-top: 1rem;
}

.result-tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 2rem;
    border-bottom: 2px solid var(--border-color);
    overflow-x: auto;
}

.tab-btn {
    padding: 0.8rem 1.5rem;
    background: none;
    border: none;
    border-bottom: 3px solid transparent;
    color: var(--text-secondary);
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    white-space: nowrap;
}

.tab-btn:hover {
    color: var(--primary-color);
}

.tab-btn.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
}

.tab-content {
    min-height: 400px;
}

.tab-pane {
    display: none;
    animation: fadeIn 0.3s ease;
}

.tab-pane.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* 报告容器 */
.report-container {
    background: white;
    padding: 2rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    font-family: 'Songti SC', 'STSong', 'SimSun', 'Noto Serif SC', 'Hiragino Mincho ProN', serif;
    line-height: 1.8;
}

.report-container h1,
.report-container h2,
.report-container h3 {
    color: var(--primary-color);
    margin: 1.5rem 0 1rem;
}

.report-container h1 {
    font-size: 1.8rem;
    text-align: center;
    border-bottom: 2px solid var(--primary-color);
    padding-bottom: 1rem;
}

.report-container h2 {
    font-size: 1.4rem;
}

.report-container h3 {
    font-size: 1.1rem;
}

.report-container p {
    margin: 0.8rem 0;
}

.report-container ul,
.report-container ol {
    margin-left: 2rem;
    margin-bottom: 1rem;
}

.report-container table {
    width: 100%;
    border-collapse: collapse;
    margin: 1rem 0;
}

.report-container th,
.report-container td {
    border: 1px solid var(--border-color);
    padding: 0.8rem;
    text-align: left;
}

.report-container th {
    background: var(--primary-bg-light);
    font-weight: 600;
    color: var(--primary-color);
}

.report-container tr:nth-child(even) td {
    background: #fafff8;
}

.report-container code {
    background: #f0f4f0;
    padding: 0.15em 0.4em;
    border-radius: 3px;
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 0.9em;
}

.report-container hr {
    border: none;
    border-top: 1px solid var(--border-color);
    margin: 1.5rem 0;
}

/* 历史弹窗内的 Markdown 表格样式（复用 report-container 方案） */
.modal-box table {
    width: 100%;
    border-collapse: collapse;
    margin: 1rem 0;
    font-size: 0.9rem;
}
.modal-box th, .modal-box td {
    border: 1px solid var(--border-color);
    padding: 0.5rem 0.75rem;
    text-align: left;
}
.modal-box th {
    background: var(--primary-bg-light);
    font-weight: 600;
    color: var(--primary-color);
}
.modal-box tr:nth-child(even) td { background: #fafff8; }
.modal-box code {
    background: #f0f4f0;
    padding: 0.15em 0.4em;
    border-radius: 3px;
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 0.9em;
}
.modal-box hr {
    border: none;
    border-top: 1px solid var(--border-color);
    margin: 1rem 0;
}
.modal-box ul, .modal-box ol {
    margin-left: 1.5rem;
    margin-bottom: 0.75rem;
}
.modal-box h2 { font-size: 1.2rem; color: var(--primary-color); margin: 1.25rem 0 0.5rem; }
.modal-box h3 { font-size: 1rem;   color: var(--primary-color); margin: 1rem 0 0.4rem; }

/* 数据卡片 */
.data-card {
    background: #fafafa;
    padding: 1.5rem;
    border-radius: var(--radius-md);
    margin-bottom: 1.5rem;
    border-left: 4px solid var(--primary-color);
}

.data-card h4 {
    color: var(--primary-color);
    margin-bottom: 1rem;
    font-size: 1.1rem;
}

.data-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1rem;
}

.data-item {
    background: white;
    padding: 1rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
}

.data-item strong {
    display: block;
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin-bottom: 0.3rem;
}

.data-item span {
    color: var(--text-primary);
    font-size: 1rem;
}

/* 页脚 */
.footer {
    background: var(--primary-dark);
    color: rgba(255, 255, 255, 0.8);
    text-align: center;
    padding: 2rem 0;
    margin-top: auto;
}

/* 加载动画 */
@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.loading {
    display: inline-block;
    animation: spin 1s linear infinite;
}

/* 响应式设计 - 平板 / 中等屏 */
@media (max-width: 768px) {
    .container {
        padding: 0 1rem;
    }

    .navbar {
        padding: 0.8rem 0;          /* 高度收紧 */
    }
    .navbar .container {
        flex-wrap: wrap;            /* 必要时换行,避免压挤 */
        gap: 0.5rem;
    }
    .navbar h1 {
        font-size: 1.15rem;
        line-height: 1.2;
        white-space: nowrap;        /* 不让标题被压成竖排 */
    }
    .logo {
        font-size: 1.8rem;
    }

    .nav-info {
        gap: 0.4rem;
        flex-wrap: nowrap;
    }
    .nav-link {
        font-size: 0.78rem;
        padding: 0.35rem 0.6rem;
        white-space: nowrap;
        /* [v1.10.38] 44px：Apple HIG / Google MD 最小可触摸高度 */
        min-height: 44px;
        display: inline-flex;
        align-items: center;
    }

    .github-link span {
        display: none;
    }
    .github-link {
        padding: 0.5rem;
        min-width: 36px;
        min-height: 36px;
        justify-content: center;
    }

    .status-badge {
        font-size: 0.75rem;
        padding: 0.35rem 0.6rem;
        white-space: nowrap;
        max-width: 130px;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .section-header h2 { font-size: 1.5rem; }
    .patient-form     { padding: 1.5rem; }
    .form-actions     { flex-direction: column; }
    .btn              { width: 100%; justify-content: center; min-height: 44px; }
    .header-actions   { flex-wrap: wrap; }
    .result-tabs      { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .data-grid        { grid-template-columns: 1fr; }
}

/* 超小屏(iPhone SE / 单手握持) */
@media (max-width: 420px) {
    .navbar h1 {
        font-size: 1rem;
    }
    .logo {
        font-size: 1.5rem;
    }
    .nav-brand {
        gap: 0.5rem;
    }
    /* 极窄时主动隐藏 "X 连接失败" 长文字 */
    .status-badge {
        max-width: 100px;
    }
}

/* 打印样式 */
@media print {
    .navbar,
    .footer,
    .header-actions,
    .result-tabs,
    .input-section,
    .modal-actions,
    .modal-close {
        display: none !important;
    }

    .report-container {
        border: none;
        box-shadow: none;
    }

    /* 主页报告区域打印优化 */
    .result-section {
        box-shadow: none;
        border: 1px solid #ccc;
    }

    /* 若页面只有报告 tab 处于激活状态，只印激活内容 */
    .tab-pane:not(.active) {
        display: none !important;
    }

    body {
        font-size: 13px;
        color: #111;
    }

    h2, h3 {
        page-break-after: avoid;
    }

    pre, blockquote, table {
        page-break-inside: avoid;
    }
}

/* ============================================================
 * P26 全端响应式增强
 * 断点矩阵：
 *   ≥ 1400px  大桌面 (2xl)
 *   1200-1399 桌面   (xl)
 *   769-1199  平板/笔记本 (lg)
 *   481-768   手机横屏/平板竖屏 (md) ← 原有
 *   361-480   普通手机 (sm)
 *   321-360   小屏手机 iPhone SE/小米  (xs)
 *   ≤ 320     超窄 WebView / 折叠屏外屏 (xxs)
 *   landscape 手机横屏单独处理
 * ============================================================ */

/* ── 全局基础 ───────────────────────────────────────────────── */
html {
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%; /* 防 iOS 旋转时自动放大字体 */
    text-size-adjust: 100%;
}

/* 触摸设备去掉点击高亮蓝框 */
a, button, input, textarea, select,
.tab-btn, .nav-link, .status-badge, .action-btn {
    -webkit-tap-highlight-color: transparent;
}

/* 防双击缩放 */
button, .btn, .tab-btn, .action-btn {
    touch-action: manipulation;
}

/* 媒体元素不溢出 */
img, video, canvas, iframe {
    max-width: 100%;
    height: auto;
}

/* 容器全宽 */
.container {
    width: 100%;
}

/* 长文本换行（防止报告/档案/链接撑破布局） */
.report-container,
.modal-box,
.data-item,
.progress-content {
    overflow-wrap: break-word;
    word-break: break-word;
}

/* 表格横向滚动（防止长表格溢出屏幕） */
.report-container table,
.modal-box table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
}
/* 恢复 table 内部元素正常宽度 */
.report-container thead,
.report-container tbody,
.report-container tr,
.modal-box thead,
.modal-box tbody,
.modal-box tr {
    width: 100%;
}

/* 底部安全区（iPhone X/14/15 home indicator）*/
.footer {
    padding-bottom: max(2rem, calc(1.25rem + env(safe-area-inset-bottom, 0px)));
}

/* ── 大桌面（≥ 1400px）─────────────────────────────────────── */
@media (min-width: 1400px) {
    .container { max-width: 1320px; }
    .navbar h1 { font-size: 2rem; }
    .patient-form,
    .progress-section,
    .result-section { padding: 3rem; }
}

/* ── 平板 / 笔记本（769px ~ 1199px）────────────────────────── */
@media (min-width: 769px) and (max-width: 1199px) {
    .container { padding: 0 1.5rem; }
    .navbar h1  { font-size: 1.4rem; }
    .patient-form,
    .progress-section,
    .result-section { padding: 2rem; }
    .data-grid { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
}

/* ── 桌面宽屏：进度条双列显示 ──────────────────────────────── */
@media (min-width: 960px) {
    .progress-container {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 1.25rem;
    }
    /* 最后一个奇数项跨两列（report agent） */
    .progress-item:last-child:nth-child(odd) {
        grid-column: 1 / -1;
    }
}

/* ── 手机端增补（补丁叠加在原有 768px 之上）─────────────────── */
@media (max-width: 768px) {
    .main-content {
        padding: 1.25rem 0;
        /* [v1.8.5] 移动端贴底安全区，避免 iOS home indicator 压住 footer 按钮 */
        padding-bottom: calc(1.25rem + env(safe-area-inset-bottom, 0px));
    }
    section { margin-bottom: 1.5rem; }

    .progress-section,
    .result-section { padding: 1.25rem 1rem; }

    /* 结果操作按钮：自动换行，不强制 100% */
    .header-actions .btn {
        width: auto;
        font-size: 0.85rem;
        padding: 0.55rem 0.9rem;
        min-height: 44px;
    }

    /* [v1.8.5] 所有交互按钮在触屏上保证 44×44 苹果可触可达标准 */
    .btn, button.btn, .action-btn, .nav-link, .tab-btn {
        min-height: 44px;
        min-width: 44px;
    }

    /* 进度项：手机横排轻度压缩 */
    .progress-item { padding: 0.9rem 1rem; gap: 0.9rem; }
    .progress-icon { font-size: 2rem; min-width: 48px; }

    .report-container { padding: 1.25rem 1rem; }
    .report-container h1 { font-size: 1.4rem; }
    .report-container h2 { font-size: 1.15rem; }

    /* 页脚文字 */
    .footer { font-size: 0.82rem; line-height: 1.8; }
}

/* ── 普通手机（≤ 480px）────────────────────────────────────── */
@media (max-width: 480px) {
    .container { padding: 0 0.85rem; }

    /* 导航 */
    .navbar { padding: 0.7rem 0; }
    .navbar h1 {
        font-size: 1.05rem;
        max-width: 160px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    .logo { font-size: 1.9rem; }

    /* 进度项：图标竖排 */
    .progress-item {
        flex-direction: column;
        gap: 0.6rem;
        align-items: flex-start;
    }
    .progress-icon {
        font-size: 1.75rem;
        min-width: unset;
        width: 100%;
        height: auto;
        justify-content: flex-start;
    }

    /* 表单 */
    .patient-form { padding: 1.25rem 1rem; }
    .form-group   { margin-bottom: 1.5rem; }

    /* Tab 按钮缩小 */
    .tab-btn {
        padding: 0.6rem 0.9rem;
        font-size: 0.83rem;
    }

    /* 横幅：隐藏箭头，内容允许换行 */
    .banner-content { flex-wrap: wrap; gap: 0.75rem; }
    .banner-arrow   { display: none; }
    .banner-text h2 { font-size: 1.1rem; }
    .banner-text p  { font-size: 0.82rem; }

    /* 表单操作按钮 */
    .form-actions { gap: 0.65rem; }
    .btn { min-height: 48px; }  /* 触摸目标更大 */

    /* [v1.10.38] 结果区操作按钮：横向滚动，避免 6 个按钮换行成多行 */
    .header-actions {
        flex-wrap: nowrap;          /* 不换行 */
        overflow-x: auto;           /* 横向滚动 */
        -webkit-overflow-scrolling: touch;
        padding-bottom: 4px;        /* 防滚动条遮住文字 */
        gap: 0.5rem;
        /* 隐藏滚动条（视觉更干净） */
        scrollbar-width: none;
        -ms-overflow-style: none;
    }
    .header-actions::-webkit-scrollbar { display: none; }
    .header-actions .btn {
        flex-shrink: 0;             /* 按钮不被压缩 */
        font-size: 0.82rem;
        padding: 0.5rem 0.8rem;
        white-space: nowrap;
    }
}

/* ── 小屏手机（≤ 360px）— iPhone SE / 红米 Note mini ──────── */
@media (max-width: 360px) {
    .container { padding: 0 0.65rem; }

    .navbar { padding: 0.55rem 0; }
    .navbar h1 { font-size: 0.95rem; max-width: 120px; }
    .logo { font-size: 1.55rem; }
    .nav-brand { gap: 0.4rem; }

    .status-badge {
        font-size: 0.68rem;
        padding: 0.25rem 0.45rem;
        max-width: 90px;
    }
    .nav-info { gap: 0.3rem; }
    .nav-link {
        font-size: 0.72rem;
        padding: 0.3rem 0.45rem;
    }

    .patient-form   { padding: 1rem 0.75rem; }
    .form-group     { margin-bottom: 1.25rem; }
    /* 字号必须 ≥ 16px，防 iOS 自动缩放输入框 */
    .form-group input,
    .form-group textarea { padding: 0.75rem 0.9rem; font-size: 1rem; }

    .section-header h2   { font-size: 1.15rem; }
    .progress-section    { padding: 0.9rem 0.65rem; }
    .progress-content h3 { font-size: 0.9rem; }
    .progress-content p  { font-size: 0.8rem; }
}

/* ── 超窄设备（≤ 320px）折叠屏外屏 / 老款 Android ─────────── */
@media (max-width: 320px) {
    .container { padding: 0 0.5rem; }
    .patient-form,
    .progress-section,
    .result-section { border-radius: var(--radius-sm); padding: 0.85rem 0.6rem; }
    .btn { font-size: 0.88rem; padding: 0.65rem 0.8rem; }
    /* 最后一个 nav-link 隐藏（仅保留首页/档案之一） */
    .nav-info .nav-link:last-of-type { display: none; }
}

/* ── 手机横屏（高度 ≤ 500px + landscape）────────────────────── */
@media (max-height: 500px) and (orientation: landscape) {
    .navbar { padding: 0.4rem 0; }
    .logo { font-size: 1.5rem; }
    .navbar h1 { font-size: 1rem; }

    .main-content { padding: 0.85rem 0; }
    section { margin-bottom: 0.85rem; }
    .patient-form,
    .progress-section,
    .result-section { padding: 1rem; }

    .section-header { margin-bottom: 0.85rem; }
    .section-header h2 { font-size: 1.25rem; }

    .progress-item { padding: 0.65rem 0.9rem; }
    .progress-icon { font-size: 1.5rem; min-width: 42px; }
    .progress-content h3 { font-size: 0.9rem; margin-bottom: 0.1rem; }
    .progress-content p  { font-size: 0.78rem; margin-bottom: 0.4rem; }

    /* 表单字段上下间距压缩 */
    .form-group { margin-bottom: 1rem; }
}

/* ── 触摸屏设备：抑制 hover 残留 ───────────────────────────── */
@media (hover: none) and (pointer: coarse) {
    /* hover 特效在触摸设备上禁用，改用 :active 表达反馈 */
    .btn:hover,
    .nav-link:hover,
    .github-link:hover,
    .tab-btn:hover,
    .action-btn:hover {
        transform: none !important;
        box-shadow: inherit !important;
        background-color: inherit;
        color: inherit;
    }
    /* :active 代替 hover 给触摸反馈 */
    .btn:active      { opacity: 0.78; transform: scale(0.97) !important; transition: none; }
    .tab-btn:active  { opacity: 0.7; }
    .nav-link:active { opacity: 0.7; }
    .action-btn:hover { background: var(--primary-color); color: white; } /* 保留点击态 */
    .action-btn-danger:hover { background: #f5222d; color: white; }
}

/* ── 打印增强（补充之前遗漏项）──────────────────────────────── */
@media print {
    .report-container thead,
    .modal-box thead {
        display: table-header-group; /* 打印时表格标题每页重复 */
    }
    .report-container tr,
    .modal-box tr {
        page-break-inside: avoid;
    }
    .report-container {
        max-width: 100%;
        font-size: 11pt;
        line-height: 1.7;
    }
    /* 打印时展示所有 tab 内容（而不只是激活的那个） */
    .tab-pane { display: block !important; page-break-before: always; }
    .tab-pane:first-child { page-break-before: auto; }
}

/* 美化 JSON 显示 */
.json-display {
    background: #2d2d2d;
    color: #f8f8f2;
    padding: 1.5rem;
    border-radius: var(--radius-sm);
    overflow-x: auto;
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 0.9rem;
    line-height: 1.6;
}

.json-key {
    color: #66d9ef;
}

.json-string {
    color: #e6db74;
}

.json-number {
    color: #ae81ff;
}

.json-boolean {
    color: #fd971f;
}

/* 警告和提示框 */
.alert {
    padding: 1rem 1.5rem;
    border-radius: var(--radius-sm);
    margin: 1rem 0;
    border-left: 4px solid;
}

.alert-success {
    background: #f6ffed;
    border-color: var(--success-color);
    color: #135200;
}

.alert-warning {
    background: #fffbe6;
    border-color: var(--warning-color);
    color: #614700;
}

.alert-error {
    background: #fff2f0;
    border-color: var(--error-color);
    color: #5c0011;
}

.alert-info {
    background: #e6f7ff;
    border-color: #1890ff;
    color: #003a8c;
}

/* ============================================================
 * P27 电脑端两栏 + 安卓端动态视口优化
 * 版本：v1.5.0
 * ============================================================ */

/* ── 安卓字体渲染 + 全局平滑 ────────────────────────────────── */
body {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

/* ── 动态视口高度（解决安卓 Chrome 地址栏跳动）───────────────── */
/* dvh = dynamic viewport height，浏览器地址栏出现/消失时自动适配 */
@supports (min-height: 100dvh) {
    .main-content {
        min-height: calc(100dvh - 64px); /* 64px ≈ navbar 高度 */
    }
}

/* ── 禁止弹性过度滚动（安卓/iOS app 质感）────────────────────── */
html {
    overscroll-behavior: none;
}

/* ── 安卓安全区适配（带刘海/打孔屏）────────────────────────── */
.navbar {
    padding-top: max(0.85rem, env(safe-area-inset-top, 0px));
    padding-left:  max(0px, env(safe-area-inset-left, 0px));
    padding-right: max(0px, env(safe-area-inset-right, 0px));
}
.footer {
    padding-left:  max(1rem, env(safe-area-inset-left, 0px));
    padding-right: max(1rem, env(safe-area-inset-right, 0px));
}

/* ── 安卓触摸目标最小 48×48px（Material Design 规范）────────── */
@media (hover: none) and (pointer: coarse) {
    .btn,
    .tab-btn,
    .action-btn,
    .nav-link {
        min-height: 48px;
        min-width: 48px;
    }
    /* 输入框/文本域：字号≥16px 防安卓 Chrome 自动缩放 */
    .form-group input,
    .form-group textarea,
    .form-group select {
        font-size: 16px !important;
    }
    /* 滚动容器启用原生动量滚动 */
    .result-content,
    .report-container,
    .modal-box {
        -webkit-overflow-scrolling: touch;
    }
}

/* ── 安卓平板竖屏（600px ~ 900px）── */
@media (min-width: 600px) and (max-width: 900px) {
    .container { padding: 0 1.75rem; }

    /* 进度区两列，比手机舒展 */
    .progress-container {
        grid-template-columns: 1fr 1fr;
        gap: 1rem;
    }

    /* 表单适度放大 */
    .patient-form { padding: 2rem 1.75rem; }

    /* 结果区标签排成一行 */
    .result-tabs {
        display: flex;
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        gap: 0.4rem;
        padding-bottom: 0.25rem;
    }
    .tab-btn {
        flex-shrink: 0;
        white-space: nowrap;
    }

    /* 操作按钮行 */
    .header-actions {
        display: flex;
        flex-wrap: wrap;
        gap: 0.5rem;
    }
    .header-actions .btn { flex: 0 0 auto; }
}

/* ── 安卓平板横屏（901px ~ 1199px）── */
@media (min-width: 901px) and (max-width: 1199px) {
    .container { padding: 0 2rem; }
    .patient-form { padding: 2.25rem 2rem; }

    /* 进度区保持两列 */
    .progress-container {
        grid-template-columns: 1fr 1fr;
        gap: 1.25rem;
    }

    /* 数据网格三列 */
    .data-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* ── 电脑端（≥ 1200px）客户表单两栏布局 ────────────────────── */
@media (min-width: 1200px) {
    /* 输入区整体加宽 */
    .input-section {
        max-width: 1100px;
        margin-left: auto;
        margin-right: auto;
    }

    /* 表单使用 CSS Grid 两栏 */
    #patientForm {
        display: grid;
        grid-template-columns: 1fr 1fr;
        column-gap: 2.5rem;
        align-items: start;
    }

    /* 第一栏：基本信息行 */
    #patientForm > .form-row:first-child {
        grid-column: 1;
        grid-row: 1;
    }

    /* 第一栏：现代病名 */
    #patientForm > div.form-group:nth-of-type(1) {
        grid-column: 1;
        grid-row: 2;
    }

    /* 第一栏：主述 */
    #patientForm > div.form-group:nth-of-type(2) {
        grid-column: 1;
        grid-row: 3;
    }

    /* 第二栏：四诊信息（跨 1~4 行，与左侧等高）*/
    #patientForm > div.form-group:nth-of-type(3) {
        grid-column: 2;
        grid-row: 1 / span 4;
    }
    #patientForm > div.form-group:nth-of-type(3) textarea {
        min-height: 320px;
        resize: vertical;
    }

    /* 第一栏底部：特殊情况 */
    #patientForm > div.form-group:nth-of-type(4) {
        grid-column: 1;
        grid-row: 4;
    }

    /* 操作按钮行：跨两列，左对齐 */
    #patientForm > .form-actions {
        grid-column: 1 / -1;
        grid-row: 5;
        justify-content: flex-start;
        gap: 1rem;
    }
    #patientForm > .form-actions .btn-primary {
        min-width: 200px;
    }

    /* 结果区数据网格 */
    .data-grid {
        grid-template-columns: repeat(4, 1fr);
    }

    /* 报告区最大宽度 */
    .report-container {
        max-width: 960px;
        margin-left: auto;
        margin-right: auto;
    }
}

/* ── 大屏桌面（≥ 1400px）进一步优化 ──────────────────────────── */
@media (min-width: 1400px) {
    .input-section {
        max-width: 1240px;
    }
    #patientForm {
        column-gap: 3rem;
    }
    #patientForm > div.form-group:nth-of-type(3) textarea {
        min-height: 380px;
    }
}

/* ============================================================
 * [v1.10.38] 全设备移动端补丁
 * 修复范围：
 *   - iPhone 横屏两侧内容被 Home 条/刘海遮挡
 *   - WeChat X5 / 旧版 Android Chrome 无 aspect-ratio 支持（见 ai-diagnosis.css）
 *   - OPPO Pad / 华为 MatePad 竖屏（800px）进一步优化
 *   - iOS Safari 平滑滚动动量（-webkit-overflow-scrolling）
 * ============================================================ */

/* ── iPhone 横屏：主内容区两侧安全区（刘海/圆角 notch）────────── */
@media (orientation: landscape) and (max-height: 500px) {
    /* 横屏手机：container 加左右安全区，防刘海/圆角遮内容 */
    .main-content .container,
    .navbar .container,
    .footer .container {
        padding-left:  max(1rem, env(safe-area-inset-left, 0px));
        padding-right: max(1rem, env(safe-area-inset-right, 0px));
    }
}

/* ── iPad / OPPO Pad 横屏（≥ 1024px 平板横屏）──────────────────── */
@media (min-width: 1024px) and (max-width: 1199px) {
    .patient-form { padding: 2rem; }
    .section-header h2 { font-size: 1.7rem; }
    /* 进度区保持 2 列 */
    .progress-container {
        display: grid;
        grid-template-columns: 1fr 1fr;
    }
}

/* ── OPPO Pad 竖屏（750px ~ 900px）─────────────────────────────── */
@media (min-width: 750px) and (max-width: 900px) {
    /* 导航：标题不超出 */
    .navbar h1 { font-size: 1.25rem; }
    /* 表单区域：内边距舒适 */
    .patient-form { padding: 2rem 1.75rem; }
    /* 进度图标保持水平布局 */
    .progress-item { flex-direction: row; }
    .progress-icon { font-size: 2rem; min-width: 52px; }
}

/* ── 所有可滚动容器：iOS 动量滚动 ───────────────────────────────── */
/* 注：iOS 13+ 默认已开启，这里对老 Safari / 微信 WebView 兜底 */
.result-tabs,
.report-container,
.modal-box,
.result-content,
.tab-content {
    -webkit-overflow-scrolling: touch;
}

/* ── 微信 X5：backdrop-filter 不支持时给 status-badge 加不透明背景 */
@supports not (backdrop-filter: blur(1px)) {
    .status-badge {
        background: rgba(0, 0, 0, 0.35); /* 深色兜底，确保文字可读 */
    }
    .github-link {
        background: rgba(0, 0, 0, 0.25);
    }
}

/* ── 通用：select 元素在 iOS Safari 去掉内置圆角（防样式不统一）── */
select {
    -webkit-appearance: none;
    appearance: none;
    border-radius: var(--radius-sm, 8px);
}

/* ── 通用：a[href] 和 button 禁止 callout（iOS 长按菜单不显示） */
a[href], button {
    -webkit-touch-callout: none;
}

/* ── 平板/桌面端 hover 残留修复（触屏鼠标混合设备）── */
@media (hover: none) {
    .ai-diagnosis-banner:hover {
        transform: none;
        /* [v1.10.52] 使用品牌色变量 */
        box-shadow: 0 4px 20px var(--primary-focus-shadow);
    }
}

/* ============================================================
 * [v1.10.41] 全设备 iOS / Android 深度优化
 * ============================================================ */

/* ── 1. iOS/Android 自动填充背景覆盖（消灭黄色 autofill 背景）── */
/* 浅色页面（患者端）*/
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
textarea:-webkit-autofill,
select:-webkit-autofill {
    -webkit-box-shadow: 0 0 0 1000px #fafafa inset !important;
    -webkit-text-fill-color: #2d2d2d !important;
    caret-color: #2d2d2d;
    /* 延迟过渡：让浏览器不立刻覆盖我们的颜色 */
    transition: background-color 5000s ease-in-out 0s;
}

/* ── 2. 结果 Tab 行全尺寸动量滚动 + 隐藏滚动条 ───────────────── */
.result-tabs {
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    -ms-overflow-style: none;
}
.result-tabs::-webkit-scrollbar { display: none; }

/* ── 3. JSON 代码块可横向滚动（iOS 动量）─────────────────────── */
.json-display {
    -webkit-overflow-scrolling: touch;
}

/* ── 4. 主 CTA 横幅触摸态：立刻有视觉缩放反馈 ───────────────── */
@media (hover: none) and (pointer: coarse) {
    .ai-diagnosis-banner:active {
        transform: scale(0.988);
        /* [v1.10.52] 使用品牌色变量 */
        box-shadow: 0 2px 10px var(--primary-focus-shadow);
        transition: transform 0.08s, box-shadow 0.08s;
    }
    /* 卡片区域也需要触摸反馈 */
    .patient-form:active,
    .progress-section:active { /* 不给 :active，防止内容点击触发 */ }
}

/* ── 5. 通用可交互元素：cursor: pointer（PC 端鼠标悬停明确可点）*/
.ai-diagnosis-banner,
.tab-btn,
.action-btn,
.nav-link {
    cursor: pointer;
}

/* ── 6. 更流畅的滚动容器（补充 modal-box + data-item）────────── */
.modal-box,
.data-item {
    -webkit-overflow-scrolling: touch;
}

/* ════════════════════════════════════════════════════════
 * [v1.11.0] UI/UX PRO MAX — 通用基础增强
 * 骨架屏 · 焦点环 · 进度条加粗 · 通用动画工具类
 * ════════════════════════════════════════════════════════ */

/* ── 进度条：8px 更有存在感（从 6px 升级）── */
.progress-bar {
    height: 8px;
    border-radius: 4px;
}

/* ── 骨架屏通用组件 ── */
@keyframes skeleton-shimmer {
    0%   { background-position: -400px 0; }
    100% { background-position:  400px 0; }
}

.skeleton {
    background: linear-gradient(
        90deg,
        rgba(0, 0, 0, 0.06) 25%,
        rgba(0, 0, 0, 0.11) 50%,
        rgba(0, 0, 0, 0.06) 75%
    );
    background-size: 400px 100%;
    animation: skeleton-shimmer 1.5s ease infinite;
    border-radius: var(--radius-sm);
    color: transparent !important;
    pointer-events: none;
    user-select: none;
}

.skeleton-line {
    display: block;
    height: 1em;
    margin-bottom: 0.5em;
    border-radius: 4px;
    width: 100%;
}

.skeleton-line:last-child { width: 65%; }

/* ── 通用 fadeInUp 工具类（可配合 IntersectionObserver 使用）── */
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(18px); }
    to   { opacity: 1; transform: translateY(0); }
}

.animate-in {
    animation: fadeInUp 0.42s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.animate-in-delay-1 { animation-delay: 0.08s; }
.animate-in-delay-2 { animation-delay: 0.16s; }
.animate-in-delay-3 { animation-delay: 0.24s; }

/* ── 通用脉冲动画（加载指示器 / 待机状态）── */
@keyframes pulse-soft {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0.50; }
}

.pulse {
    animation: pulse-soft 1.8s ease-in-out infinite;
}

/* ── WCAG 2.4.11 焦点环基础样式（品牌 CSS 覆盖颜色）── */
:focus-visible {
    outline:        3px solid var(--primary-color);
    outline-offset: 2px;
    border-radius:  var(--radius-sm, 4px);
}

/* 鼠标点击不显示焦点环（仅键盘导航时显示）*/
:focus:not(:focus-visible) {
    outline: none;
}

/* ── 平滑过渡：progress-item 状态切换 ── */
.progress-item {
    transition: background 0.28s ease, border-color 0.28s ease, box-shadow 0.28s ease;
}

/* ── 报告区 h1 下划线加粗 ── */
.report-container h1 {
    border-bottom-width: 2px;
    padding-bottom: 1rem;
}

/* ── 数据卡片 hover 反馈（PC 端）── */
@media (hover: hover) {
    .data-item:hover {
        border-color: var(--primary-color);
        box-shadow:   0 2px 12px var(--primary-focus-shadow);
        transition:   border-color 0.2s, box-shadow 0.2s;
    }
}

