/* ============================================================
   HCC Explorer — 浅色主题
   ============================================================ */

:root {
    --bg:        #f4f6fa;
    --surface:   #ffffff;
    --surface-2: #fafbfd;
    --border:    #e2e8f0;
    --border-2:  #cbd5e1;
    --text:      #16202e;
    --text-2:    #48566b;
    --muted:     #8494a8;
    --primary:   #2563eb;
    --primary-d: #1d4ed8;
    --tint:      #eff6ff;
    --tint-2:    #dbeafe;
    --danger:    #dc2626;
    --danger-bg: #fef2f2;
    --ok:        #059669;
    --ok-bg:     #ecfdf5;
    --warn:      #b45309;
    --warn-bg:   #fffbeb;
    --radius:    10px;
    --shadow:    0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .04);
    --shadow-lg: 0 12px 32px rgba(16, 24, 40, .14);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
                 "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
    font-size: 14px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
}

b { font-weight: 600; }

/* ---------------------------------------------------- 顶栏 */

.topbar {
    position: sticky;
    top: 0;
    z-index: 50;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow);
}

.topbar-inner {
    max-width: 1680px;
    margin: 0 auto;
    padding: 14px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
}

.brand { display: flex; align-items: center; gap: 14px; }

.brand-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 42px; height: 42px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--primary), #0ea5e9);
    color: #fff;
    font-weight: 700;
    font-size: 15px;
    letter-spacing: .5px;
    flex: none;
}

.brand-text h1 { margin: 0; font-size: 17px; font-weight: 650; letter-spacing: -.2px; }
.brand-text p  { margin: 2px 0 0; font-size: 12.5px; color: var(--muted); }
.brand-text p b { color: var(--primary); font-weight: 650; }

.topbar-actions { display: flex; gap: 10px; flex: none; }

/* ---------------------------------------------------- 按钮 */

.btn {
    appearance: none;
    border: 1px solid var(--border-2);
    background: var(--surface);
    color: var(--text-2);
    padding: 7px 14px;
    border-radius: 8px;
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
    transition: background .15s, border-color .15s, color .15s;
    white-space: nowrap;
}
.btn:hover { background: var(--surface-2); border-color: var(--primary); color: var(--primary); }
.btn:active { transform: translateY(1px); }

.btn-primary {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
    font-weight: 550;
}
.btn-primary:hover { background: var(--primary-d); border-color: var(--primary-d); color: #fff; }

.btn-sm { padding: 5px 10px; font-size: 12.5px; }

.link-btn {
    appearance: none;
    border: 0; background: none;
    color: var(--primary);
    font-size: 12.5px;
    font-family: inherit;
    cursor: pointer;
    padding: 2px 4px;
    border-radius: 4px;
}
.link-btn:hover { background: var(--tint); text-decoration: underline; }

/* ---------------------------------------------------- 布局 */

.layout {
    max-width: 1680px;
    margin: 0 auto;
    padding: 20px 24px 60px;
    display: grid;
    grid-template-columns: 288px minmax(0, 1fr);
    gap: 20px;
    align-items: start;
}

/* ---------------------------------------------------- 侧栏 */

.sidebar {
    position: sticky;
    top: 86px;
    max-height: calc(100vh - 106px);
    overflow-y: auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 4px 0 12px;
    scrollbar-width: thin;
}
.sidebar::-webkit-scrollbar { width: 8px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 4px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }

.sidebar-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px 8px;
    position: sticky;
    top: 0;
    background: var(--surface);
    z-index: 2;
    border-bottom: 1px solid var(--border);
}
.sidebar-head h2 { margin: 0; font-size: 14px; font-weight: 650; }

.search-box { padding: 12px 14px 4px; }
.search-box input {
    width: 100%;
    padding: 8px 11px;
    border: 1px solid var(--border-2);
    border-radius: 8px;
    font-size: 13px;
    font-family: inherit;
    background: var(--surface-2);
    color: var(--text);
    outline: none;
}
.search-box input:focus {
    border-color: var(--primary);
    background: #fff;
    box-shadow: 0 0 0 3px var(--tint);
}

/* 数值区间 */
.range-box {
    margin: 10px 14px 4px;
    padding: 11px 12px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 8px;
}
.range-title { font-size: 12.5px; font-weight: 600; color: var(--text-2); margin-bottom: 8px; }
.range-row {
    display: grid;
    grid-template-columns: 62px 1fr 10px 1fr;
    align-items: center;
    gap: 5px;
    margin-bottom: 6px;
}
.range-row label { font-size: 12px; color: var(--muted); }
.range-row span  { color: var(--muted); text-align: center; font-size: 12px; }
.range-row input {
    width: 100%;
    min-width: 0;
    padding: 5px 6px;
    border: 1px solid var(--border-2);
    border-radius: 6px;
    font-size: 12px;
    font-family: inherit;
    background: #fff;
    color: var(--text);
    outline: none;
}
.range-row input:focus { border-color: var(--primary); box-shadow: 0 0 0 2px var(--tint); }
.range-box .btn { width: 100%; margin-top: 4px; }

/* 筛选分组 */
.facet-list { padding: 6px 0 0; }

.facet-group { border-bottom: 1px solid var(--border); }
.facet-group:last-child { border-bottom: 0; }

.facet-group-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 9px 14px;
    cursor: pointer;
    user-select: none;
}
.facet-group-head:hover { background: var(--surface-2); }
.facet-group-head .gt { font-size: 13px; font-weight: 600; color: var(--text); }
.facet-group-head .gc { font-size: 11px; color: var(--muted); }
.facet-group-head .arrow {
    font-size: 10px; color: var(--muted);
    transition: transform .18s;
    margin-left: 6px;
}
.facet-group.collapsed .arrow { transform: rotate(-90deg); }
.facet-group.collapsed .facet-group-body { display: none; }

.facet-group-body { padding: 2px 14px 10px; }

.facet { margin-bottom: 12px; }
.facet:last-child { margin-bottom: 2px; }

.facet-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-2);
    margin-bottom: 5px;
    display: flex;
    align-items: center;
    gap: 5px;
}
.facet-label .facet-reset { margin-left: auto; font-size: 11px; }

.facet-opts { display: flex; flex-direction: column; gap: 1px; max-height: 232px; overflow-y: auto; }
.facet-opts::-webkit-scrollbar { width: 6px; }
.facet-opts::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 3px; }

.opt {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 4px 6px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12.5px;
    color: var(--text-2);
    transition: background .12s;
}
.opt:hover { background: var(--surface-2); }
.opt.on { background: var(--tint); color: var(--primary-d); font-weight: 550; }
.opt.zero { opacity: .38; cursor: not-allowed; }
.opt.zero:hover { background: none; }

.opt input { margin: 0; accent-color: var(--primary); cursor: pointer; flex: none; }
.opt .ov {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.opt .on-count {
    font-size: 11px;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
    flex: none;
}
.opt.on .on-count { color: var(--primary); }

/* ---------------------------------------------------- 已选 chips */

.chips-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
    align-items: center;
    margin-bottom: 12px;
    min-height: 0;
}
.chips-bar:empty { display: none; }

.chips-label { font-size: 12.5px; color: var(--muted); margin-right: 2px; }

.chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 8px 3px 10px;
    background: var(--tint);
    border: 1px solid var(--tint-2);
    border-radius: 999px;
    font-size: 12px;
    color: var(--primary-d);
    max-width: 340px;
}
.chip .ck { color: var(--muted); }
.chip .cv { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip .cx {
    appearance: none; border: 0; background: none;
    color: var(--muted); cursor: pointer;
    font-size: 14px; line-height: 1; padding: 0 1px;
    font-family: inherit;
    border-radius: 999px;
}
.chip .cx:hover { color: var(--danger); background: var(--danger-bg); }

.chip-clear {
    appearance: none;
    border: 1px dashed var(--border-2);
    background: none;
    color: var(--muted);
    font-size: 12px;
    padding: 3px 10px;
    border-radius: 999px;
    cursor: pointer;
    font-family: inherit;
}
.chip-clear:hover { border-color: var(--danger); color: var(--danger); background: var(--danger-bg); }

/* ---------------------------------------------------- 工具条 */

.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 0 2px 10px;
    flex-wrap: wrap;
}
.toolbar-left  { display: flex; align-items: center; gap: 10px; }
.toolbar-right { display: flex; align-items: center; gap: 8px; }
.toolbar-sep   { color: var(--border-2); }

.result-count { font-size: 13px; color: var(--text-2); }
.result-count b { color: var(--primary); font-size: 15px; font-variant-numeric: tabular-nums; }

.inline-field { font-size: 12.5px; color: var(--muted); display: inline-flex; align-items: center; gap: 5px; }
.inline-field select {
    padding: 4px 7px;
    border: 1px solid var(--border-2);
    border-radius: 6px;
    font-size: 12.5px;
    font-family: inherit;
    background: #fff;
    color: var(--text);
    cursor: pointer;
    outline: none;
}
.inline-field select:focus { border-color: var(--primary); }

/* ---------------------------------------------------- 表格 */

.table-wrap {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: auto;
    max-height: calc(100vh - 240px);
}

.grid { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; }

.grid thead th {
    position: sticky;
    top: 0;
    z-index: 3;
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
    padding: 9px 10px;
    text-align: left;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-2);
    white-space: nowrap;
    cursor: pointer;
    user-select: none;
}
.grid thead th:hover { color: var(--primary); background: var(--tint); }
.grid thead th .sort-ind { color: var(--primary); font-size: 10px; margin-left: 3px; }
.grid thead th.plain { cursor: default; }
.grid thead th.plain:hover { color: var(--text-2); background: var(--surface-2); }

.grid tbody td {
    padding: 8px 10px;
    border-bottom: 1px solid #f1f4f8;
    color: var(--text-2);
    white-space: nowrap;
    max-width: 260px;
    overflow: hidden;
    text-overflow: ellipsis;
}
.grid tbody tr:hover { background: var(--surface-2); cursor: pointer; }
.grid tbody tr:last-child td { border-bottom: 0; }

.grid .c-assay  { color: var(--text); font-weight: 600; }
.grid .c-mono   { font-family: ui-monospace, "SFMono-Regular", Consolas, monospace; font-size: 12px; }
.grid .c-num    { font-variant-numeric: tabular-nums; text-align: right; }

/* 标签 */
.tag {
    display: inline-block;
    padding: 1px 7px;
    border-radius: 999px;
    font-size: 11.5px;
    font-weight: 550;
    line-height: 1.6;
    white-space: nowrap;
}
.tag-tumor    { background: var(--danger-bg); color: var(--danger); }
.tag-adj      { background: var(--ok-bg);     color: var(--ok); }
.tag-border   { background: var(--warn-bg);   color: var(--warn); }
.tag-blood    { background: var(--tint);      color: var(--primary-d); }
.tag-other    { background: #f1f5f9;          color: var(--muted); }
.tag-na       { background: #f8fafc;          color: #b8c2ce; }
.tag-yes      { background: var(--ok-bg);     color: var(--ok); }
.tag-no       { background: #f1f5f9;          color: var(--muted); }

.treat-list { display: flex; flex-wrap: wrap; gap: 3px; max-width: 190px; }
.treat-list .t {
    background: var(--tint);
    color: var(--primary-d);
    border-radius: 4px;
    padding: 0 5px;
    font-size: 11px;
    line-height: 1.7;
}

.ds-link { color: var(--primary); text-decoration: none; font-weight: 550; }
.ds-link:hover { text-decoration: underline; }

.empty { padding: 48px 24px; text-align: center; color: var(--muted); font-size: 13.5px; }

/* ---------------------------------------------------- 分页 */

.pager {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 16px 0 0;
    flex-wrap: wrap;
}
.pager button {
    appearance: none;
    min-width: 32px;
    padding: 5px 9px;
    border: 1px solid var(--border-2);
    background: var(--surface);
    color: var(--text-2);
    border-radius: 7px;
    font-size: 12.5px;
    font-family: inherit;
    cursor: pointer;
    font-variant-numeric: tabular-nums;
}
.pager button:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); background: var(--tint); }
.pager button:disabled { opacity: .4; cursor: not-allowed; }
.pager button.cur { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }
.pager .gap { color: var(--muted); padding: 0 2px; }

/* ---------------------------------------------------- 列选择面板 */

.colpanel {
    position: fixed;
    right: 24px;
    top: 84px;
    z-index: 80;
    width: 260px;
    max-height: 70vh;
    overflow-y: auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
}
.colpanel-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    position: sticky; top: 0; background: var(--surface);
    font-size: 13px;
}
.colpanel-body { padding: 8px 14px 14px; display: flex; flex-direction: column; gap: 2px; }
.colpanel-body .opt { font-size: 12.5px; }

/* ---------------------------------------------------- 详情弹窗 */

.modal {
    position: fixed; inset: 0;
    z-index: 100;
    background: rgba(16, 24, 40, .45);
    display: flex; align-items: center; justify-content: center;
    padding: 24px;
}

/* 必须显式声明：作者样式里的 display:flex 会盖掉 UA 的 [hidden]{display:none}，
   导致 hidden 属性形同虚设（弹窗一加载就出现且关不掉） */
.modal[hidden], .colpanel[hidden] { display: none; }
.modal-box {
    background: var(--surface);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    width: min(880px, 100%);
    max-height: 86vh;
    display: flex;
    flex-direction: column;
}
.modal-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
    font-size: 15px;
}
.modal-body { padding: 16px 18px 20px; overflow-y: auto; }

.dl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 10px 20px; }
.dl-sec {
    grid-column: 1 / -1;
    margin: 8px 0 0;
    font-size: 12px;
    font-weight: 700;
    color: var(--primary);
    text-transform: uppercase;
    letter-spacing: .6px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 5px;
}
.dl-sec:first-child { margin-top: 0; }
.dl { display: flex; gap: 8px; font-size: 13px; align-items: baseline; }
.dl dt { color: var(--muted); flex: none; min-width: 88px; font-size: 12px; }
.dl dd { margin: 0; color: var(--text); word-break: break-word; }

/* ---------------------------------------------------- 移动端专用元素（宽屏隐藏） */

.btn-filter { display: none; align-items: center; }

.fcount {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 17px; height: 17px;
    padding: 0 4px;
    margin-left: 5px;
    border-radius: 999px;
    background: var(--primary);
    color: #fff;
    font-size: 11px;
    font-weight: 600;
    line-height: 1;
    font-variant-numeric: tabular-nums;
}
.fcount:empty { display: none; }

.sidebar-close { display: none; }
.drawer-footer { display: none; }

/* 小屏隐藏表头后，排序改由工具条里的下拉框承担 */
.sort-field { display: none; }

.sidebar-head-right { display: flex; align-items: center; gap: 4px; }

.drawer-mask {
    position: fixed;
    inset: 0;
    z-index: 60;
    background: rgba(16, 24, 40, .45);
}
/* 作者样式若设了 display 会盖掉 UA 的 [hidden]，这里显式兜住 */
.drawer-mask[hidden] { display: none; }

body.no-scroll { overflow: hidden; }

/* ---------------------------------------------------- 响应式 */

/* 中屏（<=1000px）：侧栏收进抽屉 */
@media (max-width: 1000px) {
    .layout {
        grid-template-columns: 1fr;
        padding: 14px 14px 40px;
        gap: 14px;
    }

    .btn-filter { display: inline-flex; }
    .sidebar-close { display: inline-block; }

    .sidebar {
        position: fixed;
        top: 0; left: 0; bottom: 0;
        z-index: 70;
        width: min(90vw, 380px);
        height: 100%;
        max-height: none;
        border: 0;
        border-right: 1px solid var(--border);
        border-radius: 0;
        box-shadow: var(--shadow-lg);
        transform: translateX(-102%);
        transition: transform .25s ease;
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }
    .sidebar.open { transform: translateX(0); }
    .sidebar > * { flex: none; }
    .sidebar .facet-list { flex: 1 1 auto; min-height: 0; overflow-y: auto; }

    .drawer-footer {
        display: block;
        padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
        background: var(--surface);
        border-top: 1px solid var(--border);
    }
    .drawer-footer .btn { width: 100%; padding: 10px; font-size: 14px; }

    .table-wrap { max-height: none; }
    .topbar-inner { padding: 12px 14px; }
}

/* 小屏（<=760px）：表格转卡片 + 底部弹窗 */
@media (max-width: 760px) {
    .topbar-inner { padding: 10px 14px; gap: 10px; }
    .brand { gap: 10px; }
    .brand-mark { width: 34px; height: 34px; font-size: 12.5px; border-radius: 8px; }
    .brand-text h1 { font-size: 14.5px; }
    .brand-text p  { font-size: 11px; }
    .topbar-actions { gap: 6px; }
    .topbar-actions .btn { padding: 6px 10px; font-size: 12px; }

    .layout { padding: 12px 12px 40px; gap: 12px; }

    .chips-bar { gap: 6px; }
    .chip { max-width: 100%; }

    .toolbar { padding-bottom: 8px; align-items: stretch; }
    .toolbar-left, .toolbar-right { flex-wrap: wrap; }
    .result-count { font-size: 12.5px; }
    .toolbar-sep { display: none; }
    .sort-field { display: inline-flex; align-items: center; }
    #sortDir { min-width: 34px; padding: 5px 9px; }

    /* ---- 表格 -> 卡片 ---- */
    .table-wrap { background: none; border: 0; box-shadow: none; overflow: visible; }
    .grid { display: block; }
    .grid thead { display: none; }
    .grid tbody { display: block; }

    .grid tbody tr {
        display: block;
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: var(--radius);
        box-shadow: var(--shadow);
        margin-bottom: 10px;
        overflow: hidden;
    }
    .grid tbody tr:active { background: var(--surface-2); }

    .grid tbody td {
        display: flex;
        align-items: baseline;
        justify-content: space-between;
        gap: 14px;
        max-width: none;
        white-space: normal;
        text-align: right;
        padding: 5px 13px;
        border-bottom: 0;
        font-size: 13px;
    }
    .grid tbody td::before {
        content: attr(data-l);
        color: var(--muted);
        font-size: 12px;
        flex: none;
    }
    /* 第一格当卡片标题 */
    .grid tbody td:first-child {
        justify-content: flex-start;
        background: var(--surface-2);
        border-bottom: 1px solid var(--border);
        padding: 9px 13px;
        font-size: 14px;
        font-weight: 650;
        color: var(--text);
    }
    .grid tbody td:first-child::before { content: none; }

    .treat-list { justify-content: flex-end; max-width: none; }
    .grid .c-num { text-align: right; }

    .empty { padding: 40px 20px; }

    /* ---- 详情：底部弹出 ---- */
    .modal { padding: 0; align-items: flex-end; }
    .modal-box {
        width: 100%;
        max-width: none;
        max-height: 90vh;
        border-radius: 16px 16px 0 0;
        animation: sheet-up .22s ease;
    }
    .modal-head { padding: 13px 16px; font-size: 14.5px; }
    .modal-body { padding: 14px 16px calc(18px + env(safe-area-inset-bottom)); }
    .dl-grid { grid-template-columns: 1fr; gap: 8px 0; }
    .dl dt { min-width: 96px; }

    /* ---- 列选择：贴底全宽 ---- */
    .colpanel {
        left: 12px; right: 12px;
        top: auto; bottom: 12px;
        width: auto;
        max-height: 62vh;
        border-radius: 12px;
    }

    .pager { gap: 5px; }
    .pager button { min-width: 36px; padding: 7px 9px; }

    /* 触摸友好：加大点按区 */
    .opt { padding: 7px 8px; }
    .facet-opts { max-height: none; }
    .range-row { grid-template-columns: 54px 1fr 10px 1fr; }
    .facet-group-head { padding: 11px 14px; }
}

@keyframes sheet-up {
    from { transform: translateY(24px); opacity: .6; }
    to   { transform: translateY(0);    opacity: 1; }
}

/* 超小屏 */
@media (max-width: 420px) {
    .brand-text p { display: none; }
    .topbar-actions .btn { padding: 6px 8px; font-size: 11.5px; }
    .result-count { font-size: 12px; }
}

/* 尊重「减少动效」偏好 */
@media (prefers-reduced-motion: reduce) {
    .sidebar, .modal-box { transition: none; animation: none; }
}
