:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --text: #1d2430;
  --muted: #6b7380;
  --line: #dfe3ea;
  --accent: #1f6feb;
  --accent-soft: #e7f0ff;
  --ok: #1a7f37;
  --ok-soft: #e6f4ea;
  --warn: #9a6700;
  --warn-soft: #fff4d6;
  --bad: #c62828;
  --bad-soft: #fdecec;
  --radius: 8px;
  font-family: "Microsoft YaHei", "PingFang SC", "Noto Sans CJK SC", system-ui, sans-serif;
  font-size: 14px;
  color: var(--text);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 20px; margin: 0 0 16px; }
h2 { font-size: 16px; margin: 24px 0 10px; }
h3 { font-size: 15px; margin: 16px 0 8px; }
h4 { margin: 12px 0 6px; }
code, .mono { font-family: Consolas, "Cascadia Mono", monospace; font-size: 12.5px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }

.topbar { display: flex; align-items: center; gap: 24px; padding: 0 20px; height: 52px; background: #17212f; color: #fff; position: sticky; top: 0; z-index: 20; }
.topbar .brand { color: #fff; font-weight: 600; font-size: 15px; }
.topbar nav { display: flex; gap: 4px; flex: 1; }
.topbar nav a { color: #c9d3e0; padding: 6px 12px; border-radius: 6px; }
.topbar nav a.on, .topbar nav a:hover { background: #2a3a50; color: #fff; text-decoration: none; }
.topbar .logout button { color: #c9d3e0; }
.topbar .navmenu { display: flex; align-items: center; gap: 24px; flex: 1; min-width: 0; }
.topbar .navtoggle { display: none; }

.page { max-width: 1280px; margin: 0 auto; padding: 20px; }
.page.wide { max-width: none; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; margin-bottom: 16px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
@media (max-width: 900px) { .grid2, .grid3 { grid-template-columns: 1fr; } }

.stats { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; min-width: 130px; }
.stat b { display: block; font-size: 22px; }
.stat span { color: var(--muted); font-size: 12px; }

.flash { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 12px; border: 1px solid; }
.flash.ok { background: var(--ok-soft); border-color: #b7dfc2; color: var(--ok); }
.flash.info { background: var(--accent-soft); border-color: #c4d8fb; color: #0b4fb3; }
.flash.warn { background: var(--warn-soft); border-color: #f0d68a; color: var(--warn); }
.flash.error { background: var(--bad-soft); border-color: #f2b8b8; color: var(--bad); }

table.data { width: 100%; border-collapse: collapse; background: var(--panel); }
table.data th, table.data td { padding: 7px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
table.data th { background: #f0f2f6; font-weight: 600; font-size: 13px; position: sticky; top: 0; z-index: 1; }
table.data tr:hover td { background: #fafbfd; }

label { display: block; font-weight: 600; margin: 10px 0 4px; font-size: 13px; }
label.inline { display: inline-flex; gap: 6px; align-items: center; font-weight: normal; margin: 0 12px 0 0; }
input[type=text], input[type=password], input[type=date], input[type=number], input:not([type]), select, textarea {
  font: inherit; padding: 6px 9px; border: 1px solid #c8ced8; border-radius: 6px; background: #fff; width: 100%;
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.row { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 140px; }
.row > .shrink { flex: 0 0 auto; min-width: 0; }

button, .btn { font: inherit; display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; border-radius: 6px; border: 1px solid #c8ced8; background: #fff; color: var(--text); cursor: pointer; white-space: nowrap; }
button:hover, .btn:hover { background: #f3f5f8; text-decoration: none; }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover, .btn.primary:hover { background: #1a5fd0; }
button.danger { color: var(--bad); border-color: #f0b4b4; }
button.ok { color: var(--ok); border-color: #9fd3ad; }
button.small, .btn.small { padding: 3px 8px; font-size: 12px; }
button.link { border: none; background: none; padding: 0; color: var(--accent); }
button:disabled { opacity: .5; cursor: default; }
form.inline { display: inline; }

.badge { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; background: #eef0f4; color: #4a5260; white-space: nowrap; }
.badge.review, .badge.pending { background: var(--warn-soft); color: var(--warn); }
.badge.committed, .badge.accepted, .badge.match { background: var(--ok-soft); color: var(--ok); }
.badge.failed, .badge.rejected, .badge.unresolved { background: var(--bad-soft); color: var(--bad); }
.badge.processing, .badge.queued, .badge.create { background: var(--accent-soft); color: #0b4fb3; }
.flag-up { color: var(--bad); font-weight: 600; }
.flag-down { color: #1458c9; font-weight: 600; }

.dropzone { border: 2px dashed #b8c2d1; border-radius: var(--radius); padding: 26px; text-align: center; background: #fafbfd; cursor: pointer; }
.dropzone.drag { border-color: var(--accent); background: var(--accent-soft); }
.dropzone input { display: none; }
.filelist { margin: 8px 0 0; padding: 0; list-style: none; text-align: left; }

/* 审核页 */
.review-layout { display: grid; grid-template-columns: minmax(300px, 34%) 1fr; gap: 14px; height: calc(100vh - 52px - 40px); }
.review-layout .source, .review-layout .work { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: auto; }
.review-layout .source { padding: 10px; }
.review-layout .source img { max-width: 100%; transform-origin: top left; }
.review-layout .source iframe { width: 100%; height: calc(100% - 40px); border: none; }
.review-layout .source pre { white-space: pre-wrap; font-size: 13px; }
.review-layout .work { padding: 12px 14px; }
.review-layout .toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; position: sticky; top: -12px; background: var(--panel); padding: 8px 0; z-index: 5; border-bottom: 1px solid var(--line); margin-bottom: 10px; }
.review-layout .toolbar .spacer { flex: 1; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tabs button { border-radius: 14px; padding: 3px 12px; font-size: 13px; }
.tabs button.on { background: var(--text); color: #fff; border-color: var(--text); }
.pcard { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; margin-bottom: 10px; }
.pcard.unresolved { border-color: #f2b8b8; background: #fffafa; }
.pcard .ids { font-family: Consolas, monospace; }
table.cands td { padding: 5px 6px; font-size: 13px; }
table.cands .c-label { min-width: 130px; }
table.cands .c-raw { min-width: 80px; }
table.cands .c-field { min-width: 140px; }
table.cands .c-hint { min-width: 170px; }
table.cands .c-pt { min-width: 80px; white-space: nowrap; }
table.cands td input, table.cands td select { padding: 3px 6px; font-size: 13px; }
table.cands tr.accepted td { background: #f4fbf6; }
table.cands tr.rejected td { opacity: .45; }
table.cands tr.focus td { outline: 2px solid var(--accent); }
.issue { display: inline-block; font-size: 11.5px; padding: 0 6px; border-radius: 8px; margin: 1px 2px 1px 0; }
.issue.hint { background: var(--warn-soft); color: var(--warn); }
.issue.block { background: var(--bad-soft); color: var(--bad); }
.issue.dup { background: #eef0f4; color: #4a5260; }
.loc { font-size: 11.5px; color: var(--muted); cursor: pointer; }
.loc:hover { color: var(--accent); }
.sheet-wrap { overflow: auto; }
table.sheet { border-collapse: collapse; font-size: 12px; }
table.sheet th, table.sheet td { border: 1px solid #e3e6eb; padding: 2px 6px; max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
table.sheet th { background: #f3f4f6; color: var(--muted); font-weight: normal; }
table.sheet td.hl { background: #fff2b3; outline: 2px solid #e6a700; }
.modal-bg { position: fixed; inset: 0; background: rgba(15, 20, 30, .45); display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal { background: #fff; border-radius: 10px; padding: 18px 20px; width: min(560px, 94vw); max-height: 90vh; overflow: auto; }
.modal h3 { margin-top: 0; }
.modal .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; }
.modal.imgedit { width: auto; max-width: 96vw; }
.imgedit .toolbar { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
.imgedit .stage { display: flex; justify-content: center; background: #2b2f36; padding: 8px; border-radius: 6px; }
.imgedit canvas { cursor: crosshair; touch-action: none; max-width: 100%; }
.prev { margin-left: 4px; font-weight: normal; white-space: nowrap; }

/* 患者时间轴 */
.timeline-wrap { overflow: auto; max-height: 75vh; border: 1px solid var(--line); border-radius: var(--radius); }
table.timeline { border-collapse: separate; border-spacing: 0; font-size: 13px; background: #fff; }
table.timeline th, table.timeline td { border-bottom: 1px solid var(--line); border-right: 1px solid #eef0f4; padding: 5px 9px; white-space: nowrap; }
table.timeline thead th { position: sticky; top: 0; background: #f0f2f6; z-index: 2; }
table.timeline th.fname { position: sticky; left: 0; background: #fff; z-index: 1; text-align: left; font-weight: normal; }
table.timeline thead th.fname { z-index: 3; background: #f0f2f6; }
table.timeline tr.cat th { background: #f7f8fa; text-align: left; position: sticky; left: 0; font-size: 12px; color: var(--muted); }
table.timeline td a { color: var(--text); }
table.timeline td.void a { text-decoration: line-through; color: var(--muted); }

.auth-box { max-width: 380px; margin: 12vh auto; }
.research-only { margin-top: 40px; padding-top: 10px; border-top: 1px solid var(--line, #e5e7eb); text-align: center; }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 6px 12px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
details summary { cursor: pointer; }

/* 评分表 */
.scale-layout { display: grid; grid-template-columns: minmax(0, 3fr) minmax(280px, 2fr); gap: 16px; align-items: start; }
@media (max-width: 1000px) { .scale-layout { grid-template-columns: 1fr; } }
fieldset.domain { border: 1px solid var(--line); border-radius: var(--radius); margin: 0 0 12px; padding: 8px 12px 10px; }
fieldset.domain legend { font-weight: 600; padding: 0 4px; }
label.opt { display: flex; gap: 8px; align-items: baseline; font-weight: normal; margin: 6px 0 0; cursor: pointer; }
label.opt:hover { background: #f6f8fb; }
table.qtable td.center, table.qtable th { text-align: center; }
table.qtable td:first-child { text-align: left; }
.center { text-align: center; }

/* 批次审核：文件标签与分组 */
.ftabs { display: flex; gap: 4px; flex-wrap: wrap; position: sticky; top: -10px; background: var(--panel); padding: 4px 0 8px; z-index: 3; border-bottom: 1px solid var(--line); margin-bottom: 8px; }
.ftab { font-size: 12.5px; padding: 4px 8px; border-radius: 6px; }
.ftab.on { border-color: var(--accent); background: var(--accent-soft); }
.fhead { margin-bottom: 8px; }
.factions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.fcontent iframe { width: 100%; height: 75vh; border: none; }
.chip { font-size: 12px; padding: 1px 8px; border-radius: 10px; background: #eef3fb; border: 1px solid #c9d8f2; color: #0b4fb3; }
.chip:hover { background: var(--accent-soft); }
table.cands tr.grouprow td { background: #f3f5f9; font-size: 13px; border-top: 2px solid var(--line); }
table.cands .c-src { white-space: nowrap; }

/* 访视 */
table.timeline thead th.visit-head { background: #e4ecf8; border-left: 2px solid #c9d8f2; text-align: center; }
table.timeline thead th.date-head { top: 31px; font-weight: normal; font-size: 12px; color: var(--muted); }
.autonote { font-size: 12px; color: #6b5200; background: #fff9e6; border-radius: 6px; padding: 2px 6px; margin: 4px 0; }
.autonote.review { background: #fdecec; color: #8a1f1f; }

/* 用药时间轴 */
.medtl { font-size: 12px; }
.medtl-row, .medtl-axis { display: flex; align-items: center; }
.medtl-row { border-bottom: 1px solid #eef0f4; min-height: 30px; }
.medtl-name { width: 130px; flex: none; padding-right: 8px; text-align: right; color: var(--text); }
.medtl-track { position: relative; flex: 1; height: 26px; margin-right: 12px; }
.medtl-axis .medtl-track { height: 18px; }
.medtl-tick { position: absolute; top: 0; color: var(--muted); white-space: nowrap; transform: translateX(-50%); }
.medtl-tick:first-child { transform: none; }
.medtl-tick.end { transform: translateX(-50%); font-weight: 600; }
.medtl-grid { position: absolute; top: 0; bottom: 0; border-left: 1px dashed var(--line); }
.medtl-grid.now { border-left: 1px solid #b8c0cc; }
.medbar { position: absolute; top: 4px; height: 18px; border-radius: 4px; background: #cfe0fb; border: 1px solid #9dbcf0; overflow: hidden; }
.medbar span { padding: 0 4px; line-height: 16px; white-space: nowrap; color: #17212f; }
.medbar.ongoing { border-right: none; border-radius: 4px 0 0 4px; -webkit-mask-image: linear-gradient(to right, #000 85%, transparent); mask-image: linear-gradient(to right, #000 85%, transparent); }
.medbar.inferred { border-right: 2px dashed #6b7380; }
.gc-小剂量 { background: #e6f4ea; border-color: #a8d5b5; }
.gc-中剂量 { background: #fff4d6; border-color: #e8c66a; }
.gc-大剂量 { background: #ffe1c2; border-color: #f0a660; }
.gc-超大剂量 { background: #fbc9c9; border-color: #e57c7c; }
.gc-冲击 { background: var(--bad); border-color: var(--bad); }
.medbar.gc-冲击 { overflow: visible; }
.medbar.gc-冲击 span { position: absolute; left: 100%; color: var(--bad); font-weight: 600; }
.medkey { display: inline-block; padding: 0 6px; margin: 0 2px; border: 1px solid; border-radius: 4px; }
.medkey.gc-冲击 { color: #fff; }

/* 样本库 */
.boxlist { display: flex; flex-wrap: wrap; gap: 8px; flex: 1; }
.boxcard { display: flex; flex-direction: column; gap: 2px; width: 150px; padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; color: var(--text); }
.boxcard:hover { border-color: var(--accent); text-decoration: none; }
.usage { display: block; height: 4px; background: #eef0f4; border-radius: 2px; overflow: hidden; }
.usage span { display: block; height: 100%; background: var(--accent); }
table.boxgrid { border-collapse: separate; border-spacing: 3px; font-size: 11px; }
table.boxgrid th { color: var(--muted); font-weight: normal; padding: 0 4px; }
table.boxgrid td.well { width: 54px; height: 40px; text-align: center; vertical-align: middle; border-radius: 6px; border: 1px solid #c9d3e0; background: #dfe9f8; line-height: 1.2; }
table.boxgrid td.well a { display: block; color: #17212f; }
table.boxgrid td.well a:hover { text-decoration: none; }
table.boxgrid td.well span { display: block; max-width: 54px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #4a5260; }
table.boxgrid td.empty { background: #fff; border-style: dashed; }
table.boxgrid td.empty a { color: #b8c0cc; }
table.boxgrid td.empty.picked { border: 2px solid var(--accent); }
table.boxgrid td.out { opacity: .55; border-style: dashed; border-width: 2px; }
table.boxgrid td.st-sample-serum { background: #fff4d6; border-color: #e8c66a; }
table.boxgrid td.st-sample-plasma { background: #ffe1c2; border-color: #f0a660; }
table.boxgrid td.st-sample-pbmc { background: #fbc9c9; border-color: #e57c7c; }
table.boxgrid td.st-sample-dna { background: #e6f4ea; border-color: #a8d5b5; }
table.boxgrid td.st-sample-urine { background: #f4f0c8; border-color: #d6cc6a; }
table.boxgrid td.st-sample-saliva { background: #dff3f7; border-color: #8ccbd8; }
table.boxgrid td.st-sample-lip_tissue { background: #eadff7; border-color: #b49ad8; }
.badge.tube-在库 { background: var(--ok-soft); color: var(--ok); }
.badge.tube-已出库 { background: var(--warn-soft); color: var(--warn); }
.badge.tube-已销毁 { background: var(--bad-soft); color: var(--bad); }

/* 当前队列 */
.topbar .cohort-pill { color: #c9d3e0; font-size: 12px; padding: 4px 10px; border: 1px solid #3a4a60; border-radius: 12px; white-space: nowrap; }
.topbar .cohort-pill.on { color: #fff; background: #1f6feb; border-color: #1f6feb; }
.topbar .cohort-pill:hover { text-decoration: none; border-color: #c9d3e0; }
.miss { color: var(--bad); }
.done { color: var(--ok); }

/* 手机与窄屏 */
@media (max-width: 1100px) {
  .topbar { flex-wrap: wrap; height: auto; min-height: 48px; gap: 0 12px; padding: 0 12px; }
  .topbar .brand { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; line-height: 48px; }
  .topbar .navtoggle { display: inline-flex; justify-content: center; width: 44px; height: 40px; padding: 0; font-size: 22px; color: #fff; background: none; border-color: #3a4a60; }
  .topbar .navtoggle:hover { background: #2a3a50; }
  .topbar .navmenu { display: none; flex: 0 0 100%; flex-direction: column; align-items: stretch; gap: 8px; padding: 4px 0 12px; }
  .topbar.open .navmenu { display: flex; }
  .topbar nav { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 4px; }
  .topbar nav a { padding: 10px 12px; }
  .topbar .cohort-pill { align-self: flex-start; padding: 6px 12px; }
  .topbar .navmenu > a.small, .topbar .logout { padding: 6px 12px; }
  .topbar .navmenu > a.small { color: #c9d3e0; }
}
@media (max-width: 760px) {
  input[type=text], input[type=password], input[type=date], input[type=number], input:not([type]), select, textarea { font-size: 16px; }  /* iOS 小于 16px 会自动放大页面 */
  .page { padding: 12px; }
  h1 { font-size: 18px; }
  .panel { padding: 12px; }
  .stat { flex: 1 1 40%; min-width: 0; }
  .kv { grid-template-columns: 96px 1fr; }
  .tablewrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin-bottom: 8px; }
  .tablewrap > table.data th { position: static; }
  .row > * { min-width: 160px; }  /* 面板内两栏放不下时整行排列 */
  .row > [style*="max-width"] { min-width: 0; flex-basis: 90px; }  /* 本身限宽的小输入框（管数、行列）仍并排 */
  .review-layout { grid-template-columns: 1fr; height: auto; }
  .review-layout .source { max-height: 50vh; }
  .review-layout .source iframe { height: 45vh; }
  .medtl-name { width: 76px; }
  .timeline-wrap { max-height: 70vh; }
}
@media (pointer: coarse) {
  button, .btn { min-height: 36px; }
  button.small, .btn.small { min-height: 30px; }
  button.link { min-height: 0; }
}
