:root {
  --bg: #f5f7fa;
  --card: #ffffff;
  --ink: #1f2933;
  --muted: #6b7785;
  --line: #e3e8ef;
  --brand: #2f6feb;
  --brand-dark: #1d4fa8;
  --danger: #d64545;
  --flag-h: #c0392b;
  --flag-l: #1f6fb2;
  --flag-a: #b8860b;
  --radius: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.6 -apple-system, "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

/* 顶部区块（品牌栏 + 成员子导航）整体吸附，滚动时导航不跟着跑 */
.siteheader {
  position: sticky; top: 0; z-index: 20;
  background: var(--card);
  box-shadow: 0 1px 0 var(--line);
}

.topbar {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 10px 20px; background: var(--card); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 17px; color: var(--ink); flex: 0 0 auto; white-space: nowrap; }
.member-nav { display: flex; gap: 8px; flex-wrap: wrap; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }

.chip {
  padding: 4px 12px; border-radius: 999px; background: #eef2f7; color: var(--ink);
  font-size: 13px; border: 1px solid transparent;
  white-space: nowrap; flex: 0 0 auto;
}
.chip-on { background: var(--brand); color: #fff; }
.chip-on:hover { text-decoration: none; }

.navlink { padding: 4px 8px; border-radius: 8px; color: var(--muted); font-size: 14px; }
.navlink-on { color: var(--brand); background: #eaf1fd; }

.subnav {
  display: flex; gap: 6px; flex-wrap: wrap; padding: 8px 20px;
  background: #fbfcfe; border-bottom: 1px solid var(--line);
}
.subnav .navlink { border: 1px solid transparent; }
.subnav .navlink-on { border-color: #cfe0ff; font-weight: 600; }

/* 窄屏适配统一放在文件末尾（见下），避免被后出现的同名规则覆盖 */

.wrap { max-width: 1120px; margin: 0 auto; padding: 20px; }

.page-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap; margin-bottom: 14px;
}
.h1 { font-size: 22px; margin: 0; }
.h2 { font-size: 16px; margin: 0 0 10px; }
.muted { color: var(--muted); font-size: 13px; }
.empty { color: var(--muted); padding: 10px 0; }
.error { color: var(--danger); font-size: 13px; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin-bottom: 16px;
}
.card-narrow { max-width: 420px; margin: 40px auto; }
.card-link { display: block; color: inherit; }
.card-link:hover { text-decoration: none; border-color: var(--brand); }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 760px) { .two-col { grid-template-columns: 1fr; } }

.counts { display: flex; gap: 10px; flex-wrap: wrap; }
.count {
  display: flex; flex-direction: column; align-items: center; min-width: 62px;
  padding: 6px 10px; background: var(--card); border: 1px solid var(--line);
  border-radius: 10px; color: inherit;
}
.count:hover { text-decoration: none; border-color: var(--brand); }
.count-num { font-weight: 700; font-size: 17px; }
.count-label { font-size: 12px; color: var(--muted); }

.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.check { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 4px; }

.form { display: flex; flex-direction: column; gap: 10px; }
.form-inline { flex-direction: row; flex-wrap: wrap; align-items: center; gap: 8px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.label { font-size: 13px; color: var(--muted); }
.input {
  padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px;
  font: inherit; background: #fff; color: var(--ink); min-width: 120px;
}
.input:focus { outline: 2px solid #cfe0ff; border-color: var(--brand); }
textarea.input { resize: vertical; }
.form-inline .input { min-width: 96px; }

.btn {
  padding: 7px 14px; border-radius: 8px; border: 1px solid var(--line);
  background: #fff; color: var(--ink); font: inherit; cursor: pointer;
}
.btn:hover { border-color: var(--brand); color: var(--brand); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); color: #fff; }
.btn-primary:disabled { opacity: .6; cursor: default; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { border-color: var(--danger); color: var(--danger); }
.btn-mini { padding: 3px 9px; font-size: 13px; }
.row-actions { display: inline-flex; gap: 6px; }
.col-actions-wrap .row-actions { flex-wrap: wrap; }

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td {
  text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line);
  white-space: nowrap; vertical-align: top;
}
.table th { color: var(--muted); font-weight: 600; font-size: 13px; }
.table tbody tr:hover { background: #fafbfd; }
/* 长文本列允许换行（其余列保持 nowrap，避免日期被拆成竖排） */
.table .col-wrap { white-space: normal; word-break: break-word; }

.flag-h { color: var(--flag-h); font-weight: 600; }
.flag-l { color: var(--flag-l); font-weight: 600; }
.flag-a { color: var(--flag-a); font-weight: 600; }
.flag-n { color: var(--ink); }

.dialog {
  border: none; border-radius: var(--radius); padding: 20px; max-width: 520px; width: 92%;
}
.dialog-wide { max-width: 900px; }
.dialog::backdrop { background: rgba(15, 23, 42, .35); }
.dialog-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 6px; }
.dialog-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 10px;
}
.dialog-head .h2 { margin: 0 0 10px; }

/* 详情视图：标签/值对照表 */
.dl { margin: 0; padding: 0; }
.dl dt {
  font-size: 13px; color: var(--muted); margin-top: 12px;
  border-top: 1px solid var(--line); padding-top: 10px;
}
.dl dt:first-child { border-top: none; padding-top: 0; margin-top: 0; }
.dl dd { margin: 4px 0 0; font-size: 14px; }
.dl dd.pre { white-space: pre-wrap; word-break: break-word; }
.detail-links { display: flex; flex-direction: column; gap: 6px; }
.detail-links a { font-size: 14px; }

/* 详情弹窗：标题与「关闭」固定，中间内容区独立滚动，避免长病历把按钮顶出视口 */
#detail-dialog[open] {
  display: flex; flex-direction: column;
  width: 92%; max-width: 900px; max-height: 85vh;
}
#detail-dialog .dialog-head,
#detail-dialog .dialog-actions { flex: 0 0 auto; }
#detail-dialog .dl { flex: 1 1 auto; overflow-y: auto; padding-right: 6px; margin-bottom: 4px; }
#detail-dialog .dialog-actions {
  border-top: 1px solid var(--line); padding-top: 12px; margin-top: 8px;
}

.lab-row {
  display: grid; grid-template-columns: 1.4fr 1.2fr .8fr .9fr .7fr .7fr .7fr auto;
  gap: 6px; align-items: center; margin-bottom: 6px;
}
@media (max-width: 760px) {
  .lab-row { grid-template-columns: 1fr 1fr; }
}

.trend-box { min-height: 40px; }
.chart { width: 100%; height: auto; max-height: 260px; }
.chart-bg { fill: #fbfcfe; }
.chart-band { fill: #e7f0ff; }
.chart-axis { stroke: #cfd8e3; stroke-width: 1; }
.chart-line { fill: none; stroke: var(--brand); stroke-width: 2; }
.chart-dot { stroke: #fff; stroke-width: 1.5; fill: var(--brand); }
.chart-dot.flag-h { fill: var(--flag-h); }
.chart-dot.flag-l { fill: var(--flag-l); }
.chart-dot.flag-a { fill: var(--flag-a); }
.chart-label { font-size: 11px; fill: var(--muted); }
.trend-summary { margin-bottom: 8px; font-size: 14px; }

.markdown { white-space: pre-wrap; word-break: break-word; font-size: 14px; line-height: 1.75; }

.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%);
  padding: 10px 18px; border-radius: 10px; color: #fff; background: #2c3e50;
  font-size: 14px; z-index: 50; max-width: 80vw;
}
.toast-ok { background: #25704a; }
.toast-error { background: #a83232; }

/* ---------- 窄屏适配（放文件末尾：同优先级下才能覆盖前面的 white-space/padding 等规则） ---------- */
@media (max-width: 640px) {
  .wrap { padding: 14px 12px; }
  .h1 { font-size: 19px; }

  /* 顶部吸附区压成两行 */
  .topbar { gap: 6px; padding: 8px 10px; flex-wrap: nowrap; }
  /* 手机端收起低频入口，把空间让给成员切换 */
  a.navlink[href="/admin/ranges"] { display: none; }
  .member-nav { padding-right: 4px; }
  .member-nav { flex-wrap: nowrap; overflow-x: auto; flex: 1 1 auto; min-width: 0; }
  .topbar-right { flex: 0 0 auto; }
  .subnav { padding: 6px 12px; flex-wrap: nowrap; overflow-x: auto; }
  .subnav .navlink { white-space: nowrap; }

  /* 次要列让位（保证「操作」列不用横向拖动就能点到）；
     只让长文本列换行，其余列保持不换行，否则日期会被拆成竖排 */
  .table .col-optional { display: none; }
  .table th, .table td { padding: 8px 4px; font-size: 13px; }
  .row-actions { gap: 4px; }
  .btn-mini { padding: 3px 7px; font-size: 12px; }
  .dialog-wide { max-width: 96%; }
}
