/* ============================================================
   若邻云 · 患者数据中心
   设计理念：轻盈明亮 · 白底蓝绿 · 精致克制（Linear / Stripe 级）
   适合医疗信息化场景，长时间阅片不疲劳
   ============================================================ */

/* ---------- 设计令牌 ---------- */
:root {
    /* 品牌 - 蓝绿（teal）系，专业且温暖 */
    --brand-50:  #F0FDFA;
    --brand-100: #CCFBF1;
    --brand-200: #99F6E4;
    --brand-300: #5EEAD4;
    --brand-400: #2DD4BF;
    --brand-500: #14B8A6;
    --brand-600: #0D9488;
    --brand-700: #0F766E;
    --brand-800: #115E59;
    --brand-900: #134E4A;

    /* 辅助 - 信息蓝 */
    --blue-50:  #EFF6FF;
    --blue-100: #DBEAFE;
    --blue-500: #3B82F6;
    --blue-600: #2563EB;
    --blue-700: #1D4ED8;

    /* 语义色 */
    --success-50: #F0FDF4;
    --success-500: #16A34A;
    --success-600: #15803D;
    --warning-50: #FFFBEB;
    --warning-500: #D97706;
    --warning-600: #B45309;
    --danger-50:  #FEF2F2;
    --danger-500: #DC2626;
    --danger-600: #B91C1C;
    --purple-50: #FAF5FF;
    --purple-500: #9333EA;

    /* 中性 - 冷灰带轻微蓝调 */
    --bg:          #F6F8FA;
    --bg-subtle:   #F1F4F7;
    --surface:     #FFFFFF;
    --surface-2:   #FBFCFD;
    --border:      #E7EBF0;
    --border-strong:#D7DEE6;
    --text-1: #0F172A;
    --text-2: #475569;
    --text-3: #94A3B8;
    --text-4: #CBD5E1;

    /* 阴影 - 极克制 */
    --shadow-xs: 0 1px 2px rgba(15,23,42,.04);
    --shadow-sm: 0 1px 3px rgba(15,23,42,.05), 0 1px 2px rgba(15,23,42,.03);
    --shadow-md: 0 4px 12px -2px rgba(15,23,42,.06), 0 2px 6px -2px rgba(15,23,42,.04);
    --shadow-lg: 0 12px 32px -8px rgba(15,23,42,.10), 0 4px 12px -4px rgba(15,23,42,.05);
    --shadow-xl: 0 24px 48px -12px rgba(15,23,42,.16);
    --ring: 0 0 0 3px rgba(13,148,136,.14);

    /* 圆角 */
    --r-sm: 6px;
    --r-md: 10px;
    --r-lg: 14px;
    --r-xl: 18px;
    --r-pill: 999px;

    /* 字体 */
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
            "Microsoft YaHei", "Noto Sans SC", Roboto, Helvetica, Arial, sans-serif;
    --font-mono: "SF Mono", "JetBrains Mono", "Cascadia Code", Consolas, monospace;

    --header-h: 64px;
    --maxw: 1320px;
}

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

html { -webkit-text-size-adjust: 100%; }

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text-1);
    font-size: 14px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

/* 极淡的背景纹理，避免纯白单调 */
body::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: -1;
    background:
        radial-gradient(900px 500px at 88% -8%, rgba(20,184,166,.07), transparent 60%),
        radial-gradient(700px 480px at 0% 0%, rgba(37,99,235,.05), transparent 55%);
    pointer-events: none;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; border: none; background: none; }
ul { list-style: none; }
svg { display: block; }
/* span内联图标兜底：避免svg按默认尺寸渲染撑大排版 */
span > svg:only-child { width: 1em; height: 1em; }

::selection { background: var(--brand-200); color: var(--brand-900); }

/* 滚动条 */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 99px; border: 3px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--text-3); }

/* ---------- 布局容器 ---------- */
.app {
    max-width: var(--maxw);
    margin: 0 auto;
    padding: 0 28px 64px;
}

/* ============================================================
   顶部导航栏
   ============================================================ */
.topbar {
    position: sticky;
    top: 0;
    z-index: 50;
    height: var(--header-h);
    display: flex;
    align-items: center;
    gap: 24px;
    margin: 0 -28px 24px;
    padding: 0 28px;
    background: rgba(255,255,255,.82);
    backdrop-filter: saturate(180%) blur(14px);
    -webkit-backdrop-filter: saturate(180%) blur(14px);
    border-bottom: 1px solid var(--border);
    transition: box-shadow .25s ease, border-color .25s ease;
}
.topbar.scrolled { box-shadow: var(--shadow-sm); border-color: transparent; }

.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
    width: 36px; height: 36px;
    display: grid; place-items: center;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--brand-500), var(--brand-700));
    color: #fff;
    box-shadow: 0 4px 12px -2px rgba(13,148,136,.45);
}
.brand-mark svg { width: 20px; height: 20px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text .t1 { font-size: 15px; font-weight: 650; color: var(--text-1); letter-spacing: -.01em; }
.brand-text .t2 { font-size: 11px; color: var(--text-3); font-weight: 500; }

.topbar-spacer { flex: 1; }

.topbar-meta { display: flex; align-items: center; gap: 8px; }
.meta-chip {
    display: inline-flex; align-items: center; gap: 7px;
    height: 32px; padding: 0 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-pill);
    font-size: 12.5px; color: var(--text-2); font-weight: 500;
    transition: border-color .2s, background .2s;
}
.meta-chip svg { width: 15px; height: 15px; color: var(--brand-600); }
.meta-chip:hover { border-color: var(--border-strong); }
.meta-chip.live::before {
    content: ""; width: 6px; height: 6px; border-radius: 50%;
    background: var(--success-500); box-shadow: 0 0 0 3px var(--success-50);
}

/* ============================================================
   患者信息卡（Hero）
   ============================================================ */
.hero {
    position: relative;
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 24px;
    align-items: center;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-xl);
    padding: 22px 26px;
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}
.hero::before {
    content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px;
    background: linear-gradient(180deg, var(--brand-400), var(--brand-700));
}
.hero-deco {
    position: absolute; right: -40px; top: -40px; width: 220px; height: 220px;
    background: radial-gradient(circle, rgba(20,184,166,.10), transparent 65%);
    pointer-events: none;
}

.avatar {
    width: 72px; height: 72px; border-radius: 20px;
    display: grid; place-items: center;
    font-size: 26px; font-weight: 650; color: #fff;
    background: linear-gradient(135deg, var(--brand-500), var(--brand-700));
    box-shadow: 0 8px 20px -6px rgba(13,148,136,.5), inset 0 1px 0 rgba(255,255,255,.25);
    letter-spacing: .02em;
}

.hero-main { min-width: 0; }
.hero-name-row { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.hero-name { font-size: 24px; font-weight: 700; letter-spacing: -.02em; color: var(--text-1); }

.tag {
    display: inline-flex; align-items: center; gap: 5px;
    height: 24px; padding: 0 10px;
    border-radius: var(--r-pill);
    font-size: 12px; font-weight: 600;
    border: 1px solid transparent;
}
.tag svg { width: 13px; height: 13px; }
.tag-male { background: var(--blue-50); color: var(--blue-700); border-color: var(--blue-100); }
.tag-female { background: #FDF2F8; color: #BE185D; border-color: #FCE7F3; }
.tag-age { background: var(--brand-50); color: var(--brand-700); border-color: var(--brand-100); }
.tag-allergy-yes { background: var(--danger-50); color: var(--danger-600); border-color: #FECACA; }
.tag-allergy-no { background: var(--success-50); color: var(--success-600); border-color: #BBF7D0; }

.fact-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 14px 28px;
}
.fact { display: flex; align-items: center; gap: 11px; min-width: 0; }
.fact .ic {
    flex: none; width: 34px; height: 34px; border-radius: 9px;
    display: grid; place-items: center;
    background: var(--bg-subtle); color: var(--brand-600);
}
.fact .ic svg { width: 17px; height: 17px; }
.fact .body { min-width: 0; display: flex; flex-direction: column; line-height: 1.3; }
.fact .lbl { font-size: 11px; color: var(--text-3); font-weight: 500; letter-spacing: .02em; }
.fact .val { font-size: 13.5px; color: var(--text-1); font-weight: 550; font-variant-numeric: tabular-nums; word-break: break-all; }

.hero-side { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.hero-side .label { font-size: 11px; color: var(--text-3); font-weight: 500; }
.hero-side .risk {
    display: inline-flex; align-items: center; gap: 7px;
    padding: 8px 14px; border-radius: var(--r-pill);
    background: var(--danger-50); color: var(--danger-600);
    font-size: 12.5px; font-weight: 600; border: 1px solid #FECACA;
}
.hero-side .risk svg { width: 15px; height: 15px; }
.hero-side .risk.ok { background: var(--success-50); color: var(--success-600); border-color: #BBF7D0; }

/* ============================================================
   统计卡片
   ============================================================ */
.stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-top: 16px;
}
.stat {
    position: relative;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: 18px 20px;
    box-shadow: var(--shadow-xs);
    transition: transform .25s ease, box-shadow .25s ease, border-color .25s;
    overflow: hidden;
}
.stat:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); border-color: var(--border-strong); }
.stat .ic {
    width: 40px; height: 40px; border-radius: 11px;
    display: grid; place-items: center; margin-bottom: 14px;
}
.stat .ic svg { width: 20px; height: 20px; }
.stat.c-blue .ic { background: var(--blue-50); color: var(--blue-600); }
.stat.c-teal .ic { background: var(--brand-50); color: var(--brand-600); }
.stat.c-violet .ic { background: var(--purple-50); color: var(--purple-500); }
.stat.c-amber .ic { background: var(--warning-50); color: var(--warning-600); }
.stat .num { font-size: 28px; font-weight: 700; letter-spacing: -.02em; color: var(--text-1); font-variant-numeric: tabular-nums; line-height: 1; }
.stat .lbl { margin-top: 6px; font-size: 12.5px; color: var(--text-3); font-weight: 500; }
.stat .bar { position: absolute; right: 16px; top: 18px; font-size: 11px; color: var(--text-4); font-weight: 600; }

/* ============================================================
   通用区块 / 卡片
   ============================================================ */
.section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-xs);
}
.sec-head {
    display: flex; align-items: center; gap: 12px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}
.sec-head h3 {
    display: inline-flex; align-items: center; gap: 9px;
    font-size: 14.5px; font-weight: 650; color: var(--text-1); letter-spacing: -.01em;
}
.sec-head h3 .ic { width: 18px; height: 18px; color: var(--brand-600); display: grid; place-items: center; }
.sec-head h3 .ic svg { width: 18px; height: 18px; }
.sec-head .spacer { flex: 1; }
.sec-head .count {
    font-size: 12px; color: var(--text-3); font-weight: 550;
    padding: 3px 10px; border-radius: var(--r-pill); background: var(--bg-subtle);
}
.sec-head .count.warn { color: var(--warning-600); background: var(--warning-50); }

.sec-body { padding: 14px; }

/* ---------- 主网格 ---------- */
.main-grid {
    display: grid;
    grid-template-columns: 360px 1fr;
    gap: 16px;
    margin-top: 16px;
    align-items: start;
}

/* ============================================================
   时间线（就诊记录）
   ============================================================ */
.timeline-col { position: sticky; top: calc(var(--header-h) + 16px); }
.timeline { max-height: calc(100vh - var(--header-h) - 110px); overflow-y: auto; padding: 6px; }

.tl-item {
    position: relative;
    display: grid;
    grid-template-columns: 84px 1fr;
    gap: 12px;
    padding: 8px 10px;
    border-radius: var(--r-md);
    cursor: pointer;
    transition: background .18s ease;
}
.tl-item + .tl-item { margin-top: 2px; }
.tl-item:hover { background: var(--bg-subtle); }
.tl-item.active { background: var(--brand-50); box-shadow: inset 0 0 0 1px var(--brand-200); }
.tl-item.active .tl-dot { background: var(--brand-600); border-color: var(--brand-200); }

.tl-date {
    display: flex; flex-direction: column; align-items: flex-start; justify-content: center;
    padding: 6px 0;
}
.tl-date .d { font-size: 15px; font-weight: 700; color: var(--text-1); letter-spacing: -.01em; font-variant-numeric: tabular-nums; line-height: 1.1; }
.tl-date .m { font-size: 10.5px; color: var(--text-3); font-weight: 500; margin-top: 1px; }

.tl-card { position: relative; padding: 10px 12px 10px 18px; min-width: 0; }
.tl-dot {
    position: absolute; left: 2px; top: 16px;
    width: 9px; height: 9px; border-radius: 50%;
    background: var(--surface); border: 2px solid var(--border-strong);
    box-shadow: 0 0 0 3px var(--surface);
    z-index: 2;
}
.tl-item:not(:last-child) .tl-card::before {
    content: ""; position: absolute; left: 6px; top: 24px; bottom: -14px; width: 2px;
    background: var(--border); border-radius: 2px;
}
.tl-top { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.tl-dept { font-size: 13px; font-weight: 600; color: var(--text-1); }
.tl-state {
    font-size: 10.5px; font-weight: 600; padding: 2px 7px; border-radius: var(--r-pill);
    background: var(--success-50); color: var(--success-600);
}
.tl-doc { font-size: 12px; color: var(--text-2); display: flex; align-items: center; gap: 5px; margin-bottom: 5px; }
.tl-doc svg { width: 12px; height: 12px; color: var(--text-3); }
.tl-dx { font-size: 12.5px; color: var(--text-3); line-height: 1.45; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.tl-fee {
    margin-top: 6px; font-size: 12px; font-weight: 600; color: var(--brand-700);
    font-variant-numeric: tabular-nums;
}

/* ============================================================
   详情面板
   ============================================================ */
.detail-col { display: flex; flex-direction: column; gap: 16px; min-width: 0; }

/* 随访计划 */
.fu-list { display: flex; flex-direction: column; gap: 10px; }
.fu-item {
    display: grid; grid-template-columns: auto 1fr auto; gap: 14px; align-items: center;
    padding: 13px 16px; border-radius: var(--r-md);
    background: var(--surface-2); border: 1px solid var(--border);
    cursor: pointer; transition: border-color .2s, box-shadow .2s, transform .2s;
}
.fu-item:hover { border-color: var(--brand-200); box-shadow: var(--shadow-sm); transform: translateY(-1px); }
.fu-bar { width: 4px; height: 38px; border-radius: 2px; }
.fu-item.pending .fu-bar { background: var(--warning-500); }
.fu-item.completed .fu-bar { background: var(--success-500); }
.fu-item.expired .fu-bar { background: var(--text-4); }
.fu-main { min-width: 0; }
.fu-top { display: flex; align-items: center; gap: 8px; margin-bottom: 3px; }
.fu-name { font-size: 13.5px; font-weight: 600; color: var(--text-1); }
.fu-sub { font-size: 12px; color: var(--text-3); display: flex; gap: 12px; flex-wrap: wrap; }
.fu-sub span { display: inline-flex; align-items: center; gap: 4px; }
.fu-sub svg { width: 12px; height: 12px; }
.fu-state { font-size: 11px; font-weight: 600; padding: 3px 9px; border-radius: var(--r-pill); white-space: nowrap; }
.fu-item.pending .fu-state { background: var(--warning-50); color: var(--warning-600); }
.fu-item.completed .fu-state { background: var(--success-50); color: var(--success-600); }
.fu-item.expired .fu-state { background: var(--bg-subtle); color: var(--text-3); }

/* 检验 / 检查 列表 */
.rec-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; }
.rec-item {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 14px; border-radius: var(--r-md);
    background: var(--surface-2); border: 1px solid var(--border);
    cursor: pointer; transition: border-color .2s, box-shadow .2s, transform .2s;
}
.rec-item:hover { border-color: var(--brand-200); box-shadow: var(--shadow-sm); transform: translateY(-1px); }
.rec-item .ic { flex: none; width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; }
.rec-item .ic svg { width: 18px; height: 18px; }
.rec-item.lab .ic { background: var(--brand-50); color: var(--brand-600); }
.rec-item.exam .ic { background: var(--blue-50); color: var(--blue-600); }
.rec-main { min-width: 0; flex: 1; }
.rec-name { font-size: 13.5px; font-weight: 600; color: var(--text-1); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rec-meta { font-size: 11.5px; color: var(--text-3); margin-top: 2px; display: flex; align-items: center; gap: 8px; }
.rec-badge { font-size: 10.5px; font-weight: 600; padding: 2px 7px; border-radius: var(--r-pill); }
.rec-badge.abn { background: var(--danger-50); color: var(--danger-600); }
.rec-badge.ok { background: var(--success-50); color: var(--success-600); }
.rec-badge.struct { background: var(--brand-50); color: var(--brand-700); }
.rec-badge.img { background: var(--bg-subtle); color: var(--text-2); }
.rec-chev { color: var(--text-4); flex: none; }
.rec-chev svg { width: 16px; height: 16px; }

.empty {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 10px; padding: 38px 20px; color: var(--text-3); text-align: center;
}
.empty .ic { width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center; background: var(--bg-subtle); color: var(--text-4); }
.empty .ic svg { width: 22px; height: 22px; }
.empty .t { font-size: 13px; font-weight: 500; }
.empty .s { font-size: 12px; color: var(--text-4); }

/* ============================================================
   AI 总结
   ============================================================ */
.ai-section { margin-top: 16px; overflow: hidden; }
.ai-section .sec-head { padding: 18px 22px; }
.ai-badge {
    display: inline-flex; align-items: center; gap: 5px;
    font-size: 11px; font-weight: 600; padding: 3px 9px; border-radius: var(--r-pill);
    background: linear-gradient(135deg, var(--purple-50), var(--brand-50)); color: var(--purple-500);
    border: 1px solid #E9D5FF;
}
.ai-badge svg { width: 12px; height: 12px; }

.btn {
    display: inline-flex; align-items: center; gap: 8px;
    height: 38px; padding: 0 18px;
    border-radius: var(--r-md);
    font-size: 13px; font-weight: 600; letter-spacing: -.005em;
    transition: transform .15s, box-shadow .2s, background .2s, opacity .2s;
}
.btn svg { width: 16px; height: 16px; }
.btn-primary {
    background: linear-gradient(135deg, var(--brand-500), var(--brand-700));
    color: #fff; box-shadow: 0 4px 12px -2px rgba(13,148,136,.45);
}
.btn-primary:hover { box-shadow: 0 8px 20px -4px rgba(13,148,136,.55); transform: translateY(-1px); }
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled { opacity: .65; cursor: not-allowed; transform: none; box-shadow: none; }

.ai-body { padding: 22px; min-height: 140px; }
.ai-placeholder {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 12px; padding: 28px; text-align: center; color: var(--text-3);
}
.ai-placeholder .orb {
    width: 56px; height: 56px; border-radius: 18px; display: grid; place-items: center;
    background: linear-gradient(135deg, var(--purple-50), var(--brand-50)); color: var(--purple-500);
    box-shadow: 0 6px 18px -6px rgba(147,51,234,.3);
}
.ai-placeholder .orb svg { width: 28px; height: 28px; }
.ai-placeholder .t { font-size: 14px; font-weight: 600; color: var(--text-2); }
.ai-placeholder .s { font-size: 12.5px; color: var(--text-3); max-width: 420px; line-height: 1.6; }

.ai-loading { display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 30px; }
.ai-loading .txt { font-size: 13px; color: var(--text-2); }

.shimmer {
    width: 100%; border-radius: var(--r-md); overflow: hidden; background: var(--bg-subtle);
}
.shimmer-row { height: 12px; border-radius: 6px; margin-bottom: 10px; }
.shimmer .ph { display: block; height: 12px; border-radius: 6px; margin-bottom: 10px;
    background: linear-gradient(90deg, var(--bg-subtle) 0%, #eef2f6 50%, var(--bg-subtle) 100%);
    background-size: 200% 100%; animation: shimmer 1.4s infinite; }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

.ai-summary-text { font-size: 14px; line-height: 1.85; color: var(--text-1); }
.ai-summary-text h1 { font-size: 19px; margin: 4px 0 12px; }
.ai-summary-text h2 { font-size: 16px; margin: 20px 0 10px; color: var(--text-1); display: flex; align-items: center; gap: 8px; }
.ai-summary-text h2::before { content: ""; width: 3px; height: 15px; border-radius: 2px; background: var(--brand-500); }
.ai-summary-text h3 { font-size: 14.5px; margin: 16px 0 8px; color: var(--text-2); font-weight: 650; }
.ai-summary-text p { margin-bottom: 12px; }
.ai-summary-text strong { color: var(--danger-600); font-weight: 650; background: var(--danger-50); padding: 1px 5px; border-radius: 4px; }
.ai-summary-text em { font-style: normal; color: var(--brand-700); font-weight: 600; }
.ai-summary-text ul { margin: 6px 0 14px; padding-left: 4px; display: flex; flex-direction: column; gap: 6px; }
.ai-summary-text li { padding-left: 20px; position: relative; color: var(--text-2); }
.ai-summary-text li::before { content: ""; position: absolute; left: 4px; top: 9px; width: 6px; height: 6px; border-radius: 50%; background: var(--brand-400); }
.ai-summary-text li strong { color: var(--danger-600); }
.ai-foot { margin-top: 16px; padding-top: 14px; border-top: 1px dashed var(--border); display: flex; align-items: center; justify-content: space-between; font-size: 11.5px; color: var(--text-3); }
.ai-foot .left { display: inline-flex; align-items: center; gap: 6px; }
.ai-foot svg { width: 13px; height: 13px; }

.ai-error { display: flex; align-items: center; gap: 10px; padding: 16px 18px; border-radius: var(--r-md); background: var(--danger-50); color: var(--danger-600); font-size: 13px; border: 1px solid #FECACA; }
.ai-error svg { width: 18px; height: 18px; flex: none; }

/* ============================================================
   弹窗 Modal
   ============================================================ */
.modal {
    position: fixed; inset: 0; z-index: 100;
    display: none; align-items: center; justify-content: center;
    padding: 32px;
    background: rgba(15,23,42,.42);
    backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
    opacity: 0; transition: opacity .22s ease;
}
.modal.active { display: flex; opacity: 1; }
.modal-content {
    width: 100%; max-width: 720px; max-height: calc(100vh - 64px);
    background: var(--surface); border-radius: var(--r-xl);
    box-shadow: var(--shadow-xl);
    display: flex; flex-direction: column;
    overflow: hidden;
    transform: translateY(12px) scale(.98); transition: transform .26s cubic-bezier(.2,.9,.3,1);
}
.modal.active .modal-content { transform: translateY(0) scale(1); }
.modal-content.modal-large { max-width: 960px; }
.modal-head {
    display: flex; align-items: center; gap: 12px;
    padding: 18px 22px; border-bottom: 1px solid var(--border);
}
.modal-head .ic { width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; background: var(--brand-50); color: var(--brand-600); flex: none; }
.modal-head .ic svg { width: 19px; height: 19px; }
.modal-head .title { flex: 1; min-width: 0; }
.modal-head .title .t1 { font-size: 16px; font-weight: 650; color: var(--text-1); letter-spacing: -.01em; }
.modal-head .title .t2 { font-size: 12px; color: var(--text-3); margin-top: 1px; }
.modal-close {
    width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center;
    color: var(--text-3); transition: background .2s, color .2s; flex: none;
}
.modal-close:hover { background: var(--bg-subtle); color: var(--text-1); }
.modal-close svg { width: 18px; height: 18px; }
.modal-body { padding: 22px; overflow-y: auto; }

/* 检验详情表 */
.dt-meta { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 18px; }
.dt-meta .m {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 6px 12px; border-radius: var(--r-pill);
    background: var(--bg-subtle); font-size: 12px; color: var(--text-2); font-weight: 500;
}
.dt-meta .m svg { width: 13px; height: 13px; color: var(--text-3); }

.lab-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.lab-table th {
    text-align: left; padding: 10px 12px; font-size: 11.5px; font-weight: 600;
    color: var(--text-3); letter-spacing: .03em; text-transform: uppercase;
    background: var(--bg-subtle); border-bottom: 1px solid var(--border);
    position: sticky; top: 0;
}
.lab-table td { padding: 11px 12px; border-bottom: 1px solid var(--border); color: var(--text-2); }
.lab-table tr:last-child td { border-bottom: none; }
.lab-table tr:hover td { background: var(--surface-2); }
.lab-table .col-idx { color: var(--text-4); font-variant-numeric: tabular-nums; width: 48px; }
.lab-table .col-name { color: var(--text-1); font-weight: 550; }
.lab-table .col-result { font-weight: 650; color: var(--text-1); font-variant-numeric: tabular-nums; white-space: nowrap; }
.lab-table .col-result.abn-high { color: var(--danger-600); }
.lab-table .col-result.abn-low { color: var(--warning-600); }
.lab-table .col-ref { font-variant-numeric: tabular-nums; color: var(--text-3); white-space: nowrap; }
.lab-arrow { display: inline-flex; align-items: center; gap: 3px; margin-left: 4px; }
.lab-arrow svg { width: 13px; height: 13px; }
.lab-arrow.up { color: var(--danger-500); }
.lab-arrow.down { color: var(--warning-500); }

/* 检查详情 */
.exam-sec { margin-bottom: 20px; }
.exam-sec h4 { font-size: 12px; font-weight: 600; color: var(--text-3); letter-spacing: .04em; text-transform: uppercase; margin-bottom: 8px; display: flex; align-items: center; gap: 6px; }
.exam-sec h4 svg { width: 14px; height: 14px; color: var(--brand-500); }
.exam-content { padding: 14px 16px; background: var(--surface-2); border-radius: var(--r-md); border: 1px solid var(--border); font-size: 13.5px; line-height: 1.8; color: var(--text-1); white-space: pre-wrap; }
.exam-imgs { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.exam-img { border-radius: var(--r-md); overflow: hidden; border: 1px solid var(--border); background: var(--bg-subtle); cursor: pointer; transition: transform .2s, box-shadow .2s; }
.exam-img:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); }
.exam-img img { width: 100%; height: 180px; object-fit: cover; display: block; background: #fff; }
.exam-img .cap { padding: 9px 12px; font-size: 12px; color: var(--text-2); text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* 随访详情表单 */
.fu-form { display: flex; flex-direction: column; gap: 10px; }
.fu-form-item { display: grid; grid-template-columns: 1fr auto; gap: 16px; align-items: center; padding: 12px 16px; background: var(--surface-2); border-radius: var(--r-md); border: 1px solid var(--border); }
.fu-form-item .q { font-size: 13px; color: var(--text-2); }
.fu-form-item .a { font-size: 13px; font-weight: 600; color: var(--brand-700); padding: 4px 12px; background: var(--brand-50); border-radius: var(--r-pill); }

/* ---------- 加载 ---------- */
.spinner {
    width: 26px; height: 26px; border-radius: 50%;
    border: 2.5px solid var(--brand-100); border-top-color: var(--brand-600);
    animation: spin .7s linear infinite;
}
.spinner.sm { width: 18px; height: 18px; border-width: 2px; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-center { display: flex; align-items: center; justify-content: center; padding: 40px; }

/* ---------- 动画 ---------- */
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes slideIn { from { opacity: 0; transform: translateX(-10px); } to { opacity: 1; transform: none; } }
@keyframes pulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.015); } }
.anim-in { animation: fadeIn .4s ease both; }
.tl-item { animation: slideIn .35s ease both; }

/* ============================================================
   响应式
   ============================================================ */
@media (max-width: 1080px) {
    .stats { grid-template-columns: repeat(2, 1fr); }
    .main-grid { grid-template-columns: 1fr; }
    .timeline-col { position: static; }
    .timeline { max-height: 460px; }
}
@media (max-width: 720px) {
    .app { padding: 0 16px 48px; }
    .topbar { margin: 0 -16px 16px; padding: 0 16px; gap: 12px; }
    .topbar-meta .meta-chip:not(.live) { display: none; }
    .hero { grid-template-columns: auto 1fr; padding: 18px; }
    .hero-side { grid-column: 1 / -1; flex-direction: row; align-items: center; justify-content: space-between; }
    .stats { grid-template-columns: repeat(2, 1fr); gap: 10px; }
    .modal { padding: 0; align-items: flex-end; }
    .modal-content { max-height: 92vh; border-radius: var(--r-xl) var(--r-xl) 0 0; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ---------- 图片灯箱预览 ---------- */
.img-preview {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: none;
    align-items: center;
    justify-content: center;
}
.img-preview.active { display: flex; }

.img-preview .ip-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.88);
    backdrop-filter: blur(6px);
    animation: ipFade .25s ease;
}
@keyframes ipFade {
    from { opacity: 0; }
    to { opacity: 1; }
}

.img-preview .ip-img {
    position: relative;
    max-width: 92vw;
    max-height: 86vh;
    object-fit: contain;
    border-radius: 10px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    cursor: zoom-in;
    animation: ipZoom .3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
@keyframes ipZoom {
    from { opacity: 0; transform: scale(0.9); }
    to { opacity: 1; transform: scale(1); }
}

.img-preview .ip-btn {
    position: absolute;
    z-index: 2;
    border: none;
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all .2s ease;
    backdrop-filter: blur(8px);
}
.img-preview .ip-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

.img-preview .ip-close {
    top: 24px;
    right: 28px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    font-size: 26px;
    line-height: 1;
}
.img-preview .ip-prev,
.img-preview .ip-next {
    top: 50%;
    transform: translateY(-50%);
    width: 52px;
    height: 52px;
    border-radius: 50%;
    font-size: 32px;
    line-height: 1;
}
.img-preview .ip-prev { left: 28px; }
.img-preview .ip-next { right: 28px; }

.img-preview .ip-caption {
    position: absolute;
    bottom: 28px;
    left: 50%;
    transform: translateX(-50%);
    max-width: 80vw;
    padding: 8px 18px;
    background: rgba(0, 0, 0, 0.5);
    color: #fff;
    font-size: 13px;
    border-radius: 20px;
    text-align: center;
    backdrop-filter: blur(8px);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

@media (max-width: 768px) {
    .img-preview .ip-prev { left: 12px; }
    .img-preview .ip-next { right: 12px; }
    .img-preview .ip-close { top: 14px; right: 14px; }
}

/* ============ 新增：患者搜索 / 同步控制 / 待随访横幅 / 趋势 ============ */

/* 患者搜索框 */
.patient-search {
    display: flex; align-items: center; gap: 8px;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--r-pill);
    padding: 6px 14px;
    min-width: 280px;
    box-shadow: var(--shadow-xs);
}
.patient-search svg { width: 16px; height: 16px; color: var(--text-3); flex: none; }
.patient-search input {
    border: none; outline: none; background: transparent;
    font: inherit; font-size: 13px; color: var(--text-1);
    width: 100%; padding: 2px 0;
}
.patient-search input::placeholder { color: var(--text-4); }
.search-results {
    position: absolute; top: calc(100% + 6px); left: 0; right: 0;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--r-md); box-shadow: var(--shadow-lg);
    max-height: 360px; overflow: auto; z-index: 50; display: none;
}
.search-results.show { display: block; }
.search-item {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 14px; cursor: pointer; border-bottom: 1px solid var(--bg-subtle);
    transition: background .15s;
}
.search-item:last-child { border-bottom: none; }
.search-item:hover { background: var(--brand-50); }
.search-item .si-name { font-weight: 600; color: var(--text-1); font-size: 14px; }
.search-item .si-meta { font-size: 12px; color: var(--text-3); }
.search-item .si-tag { font-size: 11px; color: var(--brand-700); background: var(--brand-50); padding: 2px 8px; border-radius: var(--r-pill); }
.search-wrap { position: relative; }

/* 同步按钮 + 状态 */
.sync-controls { display: flex; align-items: center; gap: 10px; }
.sync-btn {
    display: inline-flex; align-items: center; gap: 6px;
    border: 1px solid var(--border-strong); background: var(--surface);
    color: var(--text-2); padding: 7px 14px; border-radius: var(--r-pill);
    font-size: 13px; cursor: pointer; transition: all .15s; font-weight: 500;
}
.sync-btn:hover { border-color: var(--brand-400); color: var(--brand-700); }
.sync-btn:disabled { opacity: .6; cursor: not-allowed; }
.sync-btn svg { width: 15px; height: 15px; }
.sync-status {
    font-size: 12px; color: var(--text-3); display: flex; align-items: center; gap: 6px;
}
.sync-status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--success-500); }
.sync-status.running .dot { background: var(--warning-500); animation: pulse 1.2s infinite; }

/* 待随访醒目横幅 */
.followup-alert {
    display: none; align-items: center; gap: 12px;
    background: linear-gradient(90deg, var(--warning-50), #FFFBEB);
    border: 1px solid var(--warning-200, #FDE68A); border-left: 4px solid var(--warning-500, #D97706);
    border-radius: var(--r-md); padding: 12px 16px; margin-bottom: 16px;
    animation: fadeIn .4s ease both;
}
.followup-alert.show { display: flex; }
.followup-alert .fa-ic {
    width: 36px; height: 36px; flex: none; border-radius: var(--r-md);
    background: var(--warning-500, #D97706); color: #fff;
    display: flex; align-items: center; justify-content: center;
}
.followup-alert .fa-ic svg { width: 20px; height: 20px; }
.followup-alert .fa-main { flex: 1; }
.followup-alert .fa-title { font-weight: 600; color: var(--warning-700, #B45309); font-size: 14px; }
.followup-alert .fa-sub { font-size: 12px; color: var(--text-3); margin-top: 2px; }
.followup-alert .fa-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.followup-alert .fa-chip {
    font-size: 12px; background: rgba(255,255,255,.7); border: 1px solid var(--warning-200, #FDE68A);
    padding: 3px 10px; border-radius: var(--r-pill); color: var(--text-2);
}

/* 空状态（无患者选中） */
.no-patient {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    padding: 80px 20px; text-align: center; color: var(--text-3);
}
.no-patient svg { width: 56px; height: 56px; color: var(--brand-300); margin-bottom: 16px; }
.no-patient .t { font-size: 18px; font-weight: 600; color: var(--text-2); margin-bottom: 6px; }
.no-patient .s { font-size: 13px; }

/* 趋势图容器 */
.trend-box { width: 100%; height: 320px; }
.trend-picker { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.trend-picker select {
    border: 1px solid var(--border-strong); border-radius: var(--r-md);
    padding: 7px 12px; font: inherit; font-size: 13px; background: var(--surface);
    color: var(--text-1); min-width: 240px; outline: none;
}
