/* StrainBank 设计系统
   分层：1 tokens → 2 base → 3 layout → 4 components → 5 utilities → 6 pages → 7 responsive/print
   移动优先；768px 起切换为桌面布局。颜色全部走 token，深色模式跟随系统。 */

/* ========== 1. tokens ========== */
:root {
  --bg: #f4f6f9; --surface: #ffffff; --surface-2: #eef2f6; --surface-3: #e5eaf0;
  --text: #17212b; --text-2: #55657a; --text-3: #8592a3; --inverse: #ffffff;
  --line: #e1e7ee; --line-2: #c9d3de;
  --primary: #1c5d86; --primary-hover: #174c6e; --primary-soft: #e4eef6; --primary-text: #1c5d86;
  --danger: #b3261e; --danger-soft: #fbe9e7; --warn: #a85f00; --warn-soft: #fff1d6; --ok: #1d7f4f; --ok-soft: #dff3e8; --info-soft: #e3edf9; --info: #2b6cb0;
  --s-in: #1d7f4f; --s-in-soft: #dff3e8; --s-pending: #2b6cb0; --s-pending-soft: #e3edf9;
  --s-out: #a85f00; --s-out-soft: #fff1d6; --s-used: #6b7a8c; --s-used-soft: #eceff3;
  --s-undo: #b3261e; --s-undo-soft: #fbe9e7; --s-move: #6b4fbb; --s-move-soft: #eee9fa; --s-blank: #55657a; --s-blank-soft: #eceff3;
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px;
  --fs-xs: .75rem; --fs-sm: .85rem; --fs-md: .95rem; --fs-lg: 1.1rem; --fs-xl: 1.35rem; --fs-2xl: 1.7rem;
  --r-sm: 6px; --r: 10px; --r-lg: 14px;
  --shadow-1: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.05);
  --shadow-2: 0 8px 24px rgba(16,24,40,.12);
  --topbar-h: 52px; --tabbar-h: 58px; --actionbar-h: 64px;
  --z-bar: 20; --z-toast: 50;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1419; --surface: #171d25; --surface-2: #1f2730; --surface-3: #283240;
    --text: #e6ebf1; --text-2: #a2adbb; --text-3: #6f7c8c; --inverse: #0f1419;
    --line: #273140; --line-2: #34404f;
    --primary: #5aa5d6; --primary-hover: #7ab8e0; --primary-soft: #16303f; --primary-text: #7ab8e0;
    --danger: #ef7a72; --danger-soft: #3a1e1c; --warn: #e6a94a; --warn-soft: #3a2c15; --ok: #5ec48f; --ok-soft: #15301f; --info: #6ea8e6; --info-soft: #172a3d;
    --s-in: #5ec48f; --s-in-soft: #15301f; --s-pending: #6ea8e6; --s-pending-soft: #172a3d;
    --s-out: #e6a94a; --s-out-soft: #3a2c15; --s-used: #8b97a6; --s-used-soft: #232b35;
    --s-undo: #ef7a72; --s-undo-soft: #3a1e1c; --s-move: #b39ddb; --s-move-soft: #2a2340; --s-blank: #a2adbb; --s-blank-soft: #232b35;
    --shadow-1: 0 1px 2px rgba(0,0,0,.4); --shadow-2: 0 8px 24px rgba(0,0,0,.5);
  }
}

/* ========== 2. base ========== */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
}
body.has-actionbar { padding-bottom: calc(var(--tabbar-h) + var(--actionbar-h) + env(safe-area-inset-bottom)); }
a { color: var(--primary-text); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; letter-spacing: -.01em; }
h1 { font-size: var(--fs-xl); font-weight: 650; }
h2 { font-size: var(--fs-lg); font-weight: 600; }
h3 { font-size: var(--fs-md); font-weight: 600; }
p { margin: 0 0 var(--s3); }
hr { border: 0; border-top: 1px solid var(--line); margin: var(--s4) 0; }
code, .mono { font-family: var(--mono); }
code { background: var(--surface-2); padding: .05em .4em; border-radius: var(--r-sm); font-size: .92em; }
i { font-style: italic; }
kbd { font: inherit; font-size: var(--fs-xs); border: 1px solid var(--line-2); border-bottom-width: 2px; border-radius: 4px; padding: 0 .35em; background: var(--surface-2); }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
::selection { background: var(--primary-soft); }
.ic { width: 1.1em; height: 1.1em; vertical-align: -.18em; flex: none; }
.ic-lg { width: 2.4rem; height: 2.4rem; color: var(--text-3); }

/* ========== 3. layout ========== */
.topbar {
  position: sticky; top: 0; z-index: var(--z-bar); height: var(--topbar-h);
  display: flex; align-items: center; gap: var(--s3); padding: 0 var(--s4);
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: var(--s2); font-weight: 650; color: var(--text); white-space: nowrap; }
.brand .ic { color: var(--primary); width: 1.35em; height: 1.35em; }
.brand span { display: none; }
.nav { display: none; gap: 2px; }
.nav a { padding: 6px 10px; border-radius: var(--r-sm); color: var(--text-2); font-weight: 500; font-size: var(--fs-md); }
.nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--primary-soft); color: var(--primary-text); }
.topsearch { flex: 1; position: relative; }
.topsearch .ic { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--text-3); pointer-events: none; }
.topsearch input { width: 100%; min-height: 36px; padding: 6px 10px 6px 32px; border-radius: 999px; background: var(--surface-2); border-color: transparent; }
.topsearch input:focus { background: var(--surface); border-color: var(--primary); }
.userchip { display: flex; align-items: center; gap: var(--s2); color: var(--text); text-decoration: none !important; }
.userchip .uname { display: none; font-size: var(--fs-sm); color: var(--text-2); }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--primary); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: var(--fs-sm); }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: var(--z-bar);
  display: flex; background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 7px 0 5px; font-size: var(--fs-xs); color: var(--text-3); text-decoration: none !important; }
.tabbar a .ic { width: 1.5rem; height: 1.5rem; }
.tabbar a.active { color: var(--primary-text); font-weight: 600; }
.tabbar a.primary-tab .ic { background: var(--primary); color: #fff; border-radius: 50%; width: 2.2rem; height: 2.2rem; padding: .45rem; margin-top: -.55rem; box-shadow: var(--shadow-1); }

.container { padding: var(--s4); max-width: 1120px; margin: 0 auto; }
.container.narrow { max-width: 520px; }
.container.wide { max-width: 1400px; }
.sitefoot { display: flex; flex-wrap: wrap; justify-content: center; gap: var(--s1) var(--s4); padding: var(--s3) var(--s4) var(--s4); font-size: var(--fs-xs); }
.sitefoot a { color: var(--text-3); }

.page-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-start; gap: var(--s3); margin-bottom: var(--s4); }
.page-title { display: flex; align-items: flex-start; gap: var(--s2); min-width: 0; }
.page-title .back { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: var(--r-sm); color: var(--text-2); }
.page-title .back:hover { background: var(--surface-2); text-decoration: none; }
.page-title .kicker { font-size: var(--fs-sm); color: var(--text-2); font-style: italic; }
.page-title .subtitle { margin: 2px 0 0; color: var(--text-2); font-size: var(--fs-md); }
.page-title h1.mono { font-size: var(--fs-lg); word-break: break-all; }
.page-actions { display: flex; flex-wrap: wrap; gap: var(--s2); align-items: center; }

.cols { display: grid; gap: var(--s4); grid-template-columns: 1fr; }
.row { display: flex; gap: var(--s2); align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.row.end { justify-content: flex-end; }
.inline, form.inline { display: inline-flex; margin: 0; gap: var(--s2); align-items: center; }
.stack { display: flex; flex-direction: column; gap: var(--s3); }
.stack.tight { gap: var(--s2); }

/* ========== 4. components ========== */
/* 卡片 */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: var(--s4); margin-bottom: var(--s4); }
.card > h2, .card > .card-head { margin-bottom: var(--s3); }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: var(--s2); flex-wrap: wrap; }
.card-head .count { color: var(--text-3); font-weight: 400; font-size: var(--fs-sm); margin-left: var(--s1); }
fieldset.card { border: 1px solid var(--line); min-width: 0; }
legend { font-weight: 600; padding: 0 var(--s2); }

/* 表单区块 */
.form-section { padding: var(--s4) var(--s5); margin-bottom: var(--s4); }
.form-section .section-head { margin-bottom: var(--s4); padding-bottom: var(--s3); border-bottom: 1px solid var(--line-2); }
.form-section .section-title { display: inline-flex; align-items: center; gap: var(--s2); }
.form-section .section-title h2 { margin: 0; font-size: var(--fs-lg); font-weight: 600; color: var(--text); }
.step-num {
  display: inline-flex; align-items: center; justify-content: center;
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--primary-soft); color: var(--primary-text);
  font-size: var(--fs-xs); font-weight: 700; line-height: 1;
}
.section-subtext { color: var(--text-3); font-size: var(--fs-sm); }
details.card > summary { cursor: pointer; list-style: none; display: flex; align-items: center; gap: var(--s2); flex-wrap: wrap; }
details.card > summary::-webkit-details-marker { display: none; }
details.card > summary::before { content: ""; width: .5em; height: .5em; border-right: 2px solid var(--text-3); border-bottom: 2px solid var(--text-3); transform: rotate(-45deg); margin-right: var(--s1); transition: transform .15s; }
details.card[open] > summary::before { transform: rotate(45deg); }
details.card[open] > summary { margin-bottom: var(--s3); }
details.card > summary h2 { margin: 0; }

/* 按钮 */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4em;
  min-height: 38px; padding: 7px 14px; border-radius: var(--r-sm); border: 1px solid var(--line-2);
  background: var(--surface); color: var(--text); font: inherit; font-size: var(--fs-md); font-weight: 500;
  cursor: pointer; line-height: 1.2; text-decoration: none !important; white-space: nowrap; transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.warn { background: var(--warn); border-color: var(--warn); color: #fff; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--primary-text); }
.btn.ghost:hover { background: var(--primary-soft); }
.btn.ghost.danger-text { color: var(--danger); } .btn.ghost.danger-text:hover { background: var(--danger-soft); }
.btn.subtle { background: var(--surface-2); border-color: transparent; }
.btn.lg { min-height: 46px; padding: 10px 18px; font-size: 1.02rem; }
.btn.sm { min-height: 30px; padding: 3px 10px; font-size: var(--fs-sm); }
.btn.icon { padding: 0; width: 34px; min-height: 34px; }
.btn.icon.sm { width: 28px; min-height: 28px; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

/* 表单 */
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); width: 100%; min-height: 40px;
  padding: 8px 10px; border: 1px solid var(--line-2); border-radius: var(--r-sm);
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); outline: 2px solid var(--primary-soft); outline-offset: 0; }
input::placeholder, textarea::placeholder { color: var(--text-3); }
select { appearance: none; -webkit-appearance: none; padding-right: 32px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238592a3' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 8px center; background-size: 16px; }
input.inline, select.inline { width: auto; min-height: 32px; padding: 4px 8px; }
select.inline { padding-right: 28px; }
textarea { min-height: 92px; font-family: var(--mono); font-size: var(--fs-sm); resize: vertical; }
input[type=checkbox], input[type=radio] { width: auto; min-height: 0; accent-color: var(--primary); }
label.check { display: inline-flex; align-items: center; gap: var(--s2); font-weight: 400; cursor: pointer; }
label.check input { width: 16px; height: 16px; margin: 0; }
.field { display: flex; flex-direction: column; gap: var(--s1); min-width: 0; }
.field .lbl { font-weight: 500; font-size: var(--fs-sm); color: var(--text-2); display: flex; gap: var(--s1); align-items: baseline; flex-wrap: wrap; }
.field .lbl small { font-weight: 400; color: var(--text-3); }
.field .req { color: var(--danger); }
.field .ferr { color: var(--danger); font-style: normal; font-size: var(--fs-sm); }
.field.err input, .field.err select, .field.err textarea { border-color: var(--danger); }
.field .hint { font-size: var(--fs-xs); color: var(--text-3); }
.field a.hint { cursor: pointer; } .field a.hint:hover { color: var(--primary-text); }
.fgrid { display: grid; gap: var(--s3) var(--s4); grid-template-columns: 1fr; }
.fgrid .wide { grid-column: 1 / -1; }
.combo { display: flex; flex-direction: column; gap: var(--s1); }
.combo-new[hidden] { display: none; }
.seg { display: flex; border: 1px solid var(--line-2); border-radius: var(--r-sm); overflow: hidden; background: var(--surface); }
.seg label { flex: 1; margin: 0; position: relative; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; text-align: center; padding: 9px 6px; cursor: pointer; border-right: 1px solid var(--line-2); font-weight: 500; color: var(--text-2); }
.seg label:last-child span { border-right: 0; }
.seg input:checked + span { background: var(--primary); color: #fff; }
.seg input:focus-visible + span { outline: 2px solid var(--primary); outline-offset: -2px; }
.preview { display: block; padding: 8px 10px; background: var(--surface-2); border-radius: var(--r-sm); word-break: break-all; font-size: var(--fs-sm); }
.actions.sticky { position: sticky; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + var(--s2)); display: flex; gap: var(--s2); background: color-mix(in srgb, var(--bg) 88%, transparent); padding: var(--s2) 0; backdrop-filter: blur(8px); }

/* 5 级纯数字位置分段输入器 */
.loc-stepper-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--s2);
  margin: var(--s1) 0;
}
@media (min-width: 600px) {
  .loc-stepper-grid {
    grid-template-columns: repeat(5, 1fr);
  }
}
.loc-segment {
  display: flex;
  align-items: center;
  border: 1px solid var(--line-2);
  border-radius: var(--r-sm);
  background: var(--surface);
  overflow: hidden;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}
.loc-segment:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 15%, transparent);
}
.loc-segment .prefix,
.loc-segment .suffix {
  padding: 0 8px;
  font-size: var(--fs-xs);
  color: var(--text-2);
  font-weight: 500;
  user-select: none;
  background: var(--surface-2);
  display: flex;
  align-items: center;
  align-self: stretch;
  white-space: nowrap;
}
.loc-segment input {
  border: 0;
  box-shadow: none;
  border-radius: 0;
  text-align: center;
  font-size: var(--fs-base);
  font-weight: 600;
  font-family: var(--mono);
  padding: 8px 2px;
  min-height: 42px;
  width: 100%;
  background: transparent;
}
.loc-segment input:focus {
  outline: none;
  border: 0;
  box-shadow: none;
}
.loc-segment input::-webkit-inner-spin-button,
.loc-segment input::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.loc-segment input[type=number] {
  -moz-appearance: textfield;
}
.loc-preview-bar {
  margin-top: var(--s1);
  display: flex;
  align-items: center;
  gap: var(--s2);
}
.loc-preview-bar code {
  background: var(--surface-2);
  padding: 2px 8px;
  border-radius: var(--r-xs);
  color: var(--primary-text);
  font-weight: 600;
}

/* 状态 / 徽章 */
.status { display: inline-flex; align-items: center; gap: .35em; font-size: var(--fs-xs); font-weight: 600; padding: 2px 8px; border-radius: 999px; white-space: nowrap; line-height: 1.5; background: var(--surface-3); color: var(--text-2); }
.status::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .85; }
.status.lg { font-size: var(--fs-sm); padding: 4px 12px; }
.status.mini { font-size: .68rem; padding: 0 6px; } .status.mini::before { display: none; }
.s-in { background: var(--s-in-soft); color: var(--s-in); }
.s-pending { background: var(--s-pending-soft); color: var(--s-pending); }
.s-out { background: var(--s-out-soft); color: var(--s-out); }
.s-used, .s-discarded { background: var(--s-used-soft); color: var(--s-used); }
.s-discarded { text-decoration: line-through; }
.s-undo { background: var(--s-undo-soft); color: var(--s-undo); }
.s-move { background: var(--s-move-soft); color: var(--s-move); }
.s-blank { background: var(--s-blank-soft); color: var(--s-blank); }
.badge { display: inline-block; font-size: var(--fs-xs); padding: 1px 7px; border-radius: 999px; background: var(--surface-3); color: var(--text-2); vertical-align: middle; font-weight: 500; }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.on-primary { background: rgba(255,255,255,.22); color: #fff; }
.pill { display: inline-block; min-width: 1.7em; text-align: center; font-size: var(--fs-xs); font-weight: 600; padding: 0 .45em; border-radius: 999px; background: var(--surface-3); color: var(--text-2); }
.pill.ok { background: var(--s-in-soft); color: var(--s-in); } .pill.warn { background: var(--s-out-soft); color: var(--s-out); } .pill.info { background: var(--s-pending-soft); color: var(--s-pending); }

/* 提示 */
.alert { display: flex; gap: var(--s2); align-items: flex-start; padding: var(--s3) var(--s4); border-radius: var(--r-sm); margin-bottom: var(--s4); border: 1px solid transparent; background: var(--surface-2); color: var(--text); }
.alert .ic { margin-top: .15em; }
.alert.error { background: var(--danger-soft); color: var(--danger); }
.alert.warn { background: var(--warn-soft); color: var(--warn); }
.alert.ok { background: var(--ok-soft); color: var(--ok); }
.alert.info { background: var(--info-soft); color: var(--info); }
.alert > div { flex: 1; min-width: 0; } .alert p:last-child { margin: 0; }
.toast { position: fixed; top: calc(var(--topbar-h) + var(--s2)); left: 50%; transform: translateX(-50%); z-index: var(--z-toast); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: var(--r); box-shadow: var(--shadow-2); max-width: min(92vw, 560px); font-size: var(--fs-md); animation: toastin .25s ease; }
.toast.ok { background: var(--ok); color: #fff; } .toast.error { background: var(--danger); color: #fff; } .toast.warn { background: var(--warn); color: #fff; }
@keyframes toastin { from { opacity: 0; transform: translate(-50%, -8px);} to { opacity: 1; transform: translate(-50%, 0);} }

/* 空状态 */
.empty { text-align: center; padding: var(--s6) var(--s4); color: var(--text-2); display: flex; flex-direction: column; align-items: center; gap: var(--s2); }
.empty p { margin: 0; }
.empty .row { justify-content: center; }

/* 表格 */
.tablewrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); margin-bottom: var(--s4); }
.table { width: 100%; border-collapse: collapse; font-size: var(--fs-md); }
.table th, .table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th { background: var(--surface-2); color: var(--text-2); font-weight: 600; font-size: var(--fs-sm); white-space: nowrap; position: sticky; top: 0; z-index: 1; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--surface-2); }
.table.compact th, .table.compact td { padding: 6px 10px; }
.table .sel { width: 2.2rem; text-align: center; }
.table .sel input { width: 16px; height: 16px; margin: 0; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table tr.muted td { color: var(--text-3); }

/* 键值 / 列表 / 时间线 */
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px var(--s4); margin: 0; font-size: var(--fs-md); }
.kv dt { color: var(--text-3); } .kv dd { margin: 0; min-width: 0; word-break: break-word; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 10px 0; border-bottom: 1px solid var(--line); display: flex; flex-wrap: wrap; gap: var(--s1) var(--s3); align-items: center; }
.list li:last-child { border-bottom: 0; }
.list li.late { border-left: 3px solid var(--warn); padding-left: var(--s2); background: var(--warn-soft); margin: 0 calc(-1 * var(--s2)); padding-right: var(--s2); }
.list .grow { flex: 1; min-width: 0; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: grid; grid-template-columns: auto 1fr; gap: var(--s1) var(--s3); padding: 10px 0; border-bottom: 1px dashed var(--line); align-items: start; }
.timeline li:last-child { border-bottom: 0; }
.timeline li.reversed { opacity: .5; }
.timeline .meta { color: var(--text-2); font-size: var(--fs-sm); display: flex; flex-wrap: wrap; gap: var(--s1) var(--s2); align-items: center; }
.timeline .note { color: var(--text-2); font-size: var(--fs-sm); grid-column: 2; }
.timeline .undo-form { grid-column: 2; }

/* 子导航 / chips */
.subnav { display: flex; gap: 2px; flex-wrap: wrap; margin-bottom: var(--s4); border-bottom: 1px solid var(--line); }
.subnav a { padding: 8px 12px; color: var(--text-2); font-weight: 500; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.subnav a:hover { color: var(--text); text-decoration: none; }
.subnav a.active { color: var(--primary-text); border-bottom-color: var(--primary); }
.chips { list-style: none; padding: 0; margin: 0 0 var(--s2); display: flex; flex-wrap: wrap; gap: var(--s1); }
.chips li { background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; padding: 2px 4px 2px 10px; font-size: var(--fs-sm); display: inline-flex; gap: 2px; align-items: center; }
.chips li.off { opacity: .5; text-decoration: line-through; }
.chips li.pending { border-color: var(--warn); }
.chips li .n { color: var(--text-3); font-size: var(--fs-xs); margin-left: 2px; }
.chips button { border: 0; background: transparent; cursor: pointer; padding: 2px; color: var(--text-3); display: inline-grid; place-items: center; border-radius: 50%; }
.chips button:hover { color: var(--text); background: var(--surface-3); }
.chips button .ic { width: .95em; height: .95em; }

/* 统计卡 */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s2); margin-bottom: var(--s4); }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: var(--s3); color: var(--text); display: flex; flex-direction: column; text-decoration: none !important; }
.stat:hover { border-color: var(--line-2); }
.stat b { font-size: var(--fs-2xl); line-height: 1.1; font-weight: 650; font-variant-numeric: tabular-nums; }
.stat span { font-size: var(--fs-xs); color: var(--text-3); }
.stat.ok b { color: var(--s-in); } .stat.warn b { color: var(--s-out); } .stat.info b { color: var(--s-pending); }
.stats.stats-lean { grid-template-columns: repeat(3, 1fr); }
@media (min-width: 720px) {
  .stats.stats-lean { grid-template-columns: repeat(3, 1fr); }
}

/* 对话框 */
dialog { border: 0; border-radius: var(--r-lg); padding: var(--s5); max-width: min(92vw, 440px); background: var(--surface); color: var(--text); box-shadow: var(--shadow-2); }
dialog::backdrop { background: rgba(0,0,0,.35); }

/* ========== 5. utilities ========== */
.muted { color: var(--text-2); } .faint { color: var(--text-3); }
.small { font-size: var(--fs-sm); } .xs { font-size: var(--fs-xs); }
.nowrap { white-space: nowrap; } .truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.mt { margin-top: var(--s3); } .mb0 { margin-bottom: 0; } .mt0 { margin-top: 0; }
.grow { flex: 1; min-width: 0; }
.hidden, [hidden] { display: none !important; }
.danger-text { color: var(--danger); }
.text-ok { color: var(--s-in); font-weight: 700; }

/* ========== 6. pages ========== */
/* 登录 / 初始化 */
.auth { max-width: 420px; margin: var(--s6) auto; }
.auth .brandmark { display: flex; flex-direction: column; align-items: center; gap: var(--s2); margin-bottom: var(--s4); text-align: center; }
.auth .brandmark .ic { width: 2.6rem; height: 2.6rem; color: var(--primary); }

/* 菌株详情 */
.taxon { font-size: var(--fs-lg); color: var(--text-2); margin: 0; }
.vial-list { list-style: none; margin: 0; padding: 0; }
.vial-list li { display: grid; grid-template-columns: auto auto 1fr auto; gap: var(--s2) var(--s3); align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.vial-list li:last-child { border-bottom: 0; }
.vial-list .sel { width: 16px; height: 16px; margin: 0; }
.vial-list .rep { font-weight: 700; color: var(--primary-text); font-variant-numeric: tabular-nums; }
.vial-list .main { min-width: 0; display: flex; flex-wrap: wrap; gap: var(--s1) var(--s2); align-items: center; }
.vial-list .main a.vial { font-family: var(--mono); letter-spacing: .04em; font-weight: 600; }
.vial-list .loc { color: var(--text-2); font-size: var(--fs-sm); }
.vial-list .sub { grid-column: 3; color: var(--text-3); font-size: var(--fs-xs); }
.vial-list .ops { display: flex; gap: 2px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.vial-list .ops .btn.sm.ghost { padding: 2px 6px; min-height: 26px; font-size: var(--fs-xs); }
.vial-list li.final { opacity: .7; }
@media (max-width: 767px) {
  /* 窄屏：操作按钮换到第二行，不挤压位置文字 */
  .vial-list li { grid-template-columns: auto auto 1fr; row-gap: 4px; }
  .vial-list .ops { grid-column: 3; justify-content: flex-start; }
}

/* 菌株详情页头：种属为主、编号分段 */
.strain-head .taxon { font-size: var(--fs-xl); margin: 0; }
.strain-head .code { margin: 4px 0 0; color: var(--text-2); font-size: var(--fs-md); word-break: break-word; }
.strain-head .code .cseg { border-bottom: 1px dotted var(--line-strong, var(--line)); cursor: help; }
.strain-head .code .cseg:hover { color: var(--primary-text); border-bottom-color: var(--primary); }
.strain-head .code .dash { color: var(--text-3); margin: 0 1px; }
.chips-inline { display: flex; flex-wrap: wrap; gap: var(--s1) var(--s2); margin-top: var(--s2); }
.min0 { min-width: 0; }
.row.tight { gap: var(--s1); }

/* 元数据分块 */
.meta .kv-title { font-size: var(--fs-xs); font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--text-3); margin: 0 0 var(--s2); padding-bottom: 4px; border-bottom: 1px solid var(--line); }
.meta .kv + .kv-title { margin-top: var(--s4); }
.kv .help { display: inline-flex; vertical-align: -2px; color: var(--text-3); cursor: help; }
.kv .help .ic { width: 13px; height: 13px; }
.kv dd.mono { font-family: var(--mono); }
.kv dd.italic { font-style: italic; }
.kv .abbr { display: inline-block; font-family: var(--mono); font-size: var(--fs-xs); padding: 0 5px; border-radius: 4px; background: var(--surface-3); color: var(--text-2); margin-left: 4px; }
.seqtext { white-space: pre-wrap; word-break: break-all; font-size: var(--fs-xs); background: var(--surface-2); padding: var(--s3); border-radius: var(--r-sm); max-height: 260px; overflow: auto; margin: 0 0 var(--s2); }
.danger-zone { margin-top: var(--s4); color: var(--text-2); }
.danger-zone summary { cursor: pointer; font-size: var(--fs-sm); }
.table .danger-zone.user-delete { margin-top: 0; }

/* 管详情 */
.vial-head .vid { font-size: var(--fs-lg); letter-spacing: .08em; font-weight: 600; }
.vial-head .rep { color: var(--primary-text); font-weight: 600; }
.locbox { display: flex; align-items: center; gap: var(--s3); padding: var(--s3) var(--s4); background: var(--surface-2); border-radius: var(--r-sm); margin: var(--s3) 0; flex-wrap: wrap; }
.locbox .lbl { color: var(--text-3); font-size: var(--fs-sm); }
.locbox .loc { font-size: var(--fs-lg); font-weight: 600; }
.operator-bar { display: flex; justify-content: space-between; align-items: center; gap: var(--s2); font-size: var(--fs-sm); color: var(--text-2); margin-bottom: var(--s2); }
.actionbar { position: fixed; left: 0; right: 0; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); z-index: calc(var(--z-bar) - 1); background: var(--surface); border-top: 1px solid var(--line); padding: var(--s2) var(--s4); }
.actionbar .row { flex-wrap: nowrap; justify-content: flex-start; gap: var(--s2); }
.actionbar form.inline { display: inline-flex; flex: 1 1 auto; margin: 0; }
.actionbar form.inline .btn.lg { width: 100%; }
.actionbar .btn.lg { flex: 1 1 auto; min-width: 0; padding-left: var(--s3); padding-right: var(--s3); white-space: nowrap; }
.actionbar .btn.ghost { flex: 0 0 auto; padding-left: var(--s2); padding-right: var(--s2); }

/* 标签勾选页 */
.label-groups .group-head { display: flex; justify-content: space-between; align-items: center; gap: var(--s2); padding: var(--s2) 0; }

/* 管理：版式示意（按 mm 等比缩放） */
.label-preview { position: relative; background: var(--surface-2); border: 1px dashed var(--line-strong, var(--line)); border-radius: 4px; max-width: 100%; overflow: hidden; }
.label-preview .lp-rect { position: absolute; background: #fff; border: 1px solid #999; display: flex; align-items: center; gap: 4px; padding: 3px; box-sizing: border-box; color: #111; }
.label-preview .lp-circle { position: absolute; background: #fff; border: 1px solid #999; border-radius: 50%; display: grid; place-items: center; box-sizing: border-box; }
.label-preview .lp-qr { display: block; flex: 0 0 auto; background: repeating-conic-gradient(#222 0 25%, #fff 0 50%) 0 0 / 6px 6px; border: 2px solid #fff; box-sizing: border-box; }
.label-preview .lp-text { font-size: 9px; line-height: 1.15; white-space: nowrap; overflow: hidden; font-family: var(--mono); }

/* 管理：版式参数 */
.cfggrid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s3); }
.cfggrid .wide { grid-column: 1 / -1; }
.preset-bar { display: flex; flex-wrap: wrap; gap: var(--s2); margin: var(--s1) 0; }
.vocabgrid { display: grid; grid-template-columns: 1fr; gap: var(--s3); }
.diff { white-space: pre-wrap; word-break: break-all; display: block; max-width: 520px; font-size: var(--fs-xs); }

/* ========== 菌株列表：紧凑筛选工具栏与折叠抽屉 ========== */
.filters { display: flex; flex-direction: column; gap: var(--s2); padding: var(--s3) var(--s4); margin-bottom: var(--s4); }
.filter-toolbar { display: flex; align-items: center; gap: var(--s2); flex-wrap: wrap; }
.search-wrap { position: relative; flex: 1 1 200px; min-width: 180px; display: flex; align-items: center; }
.search-wrap .search-ic { position: absolute; left: 10px; width: 15px; height: 15px; color: var(--text-3); pointer-events: none; }
.search-wrap .search { width: 100%; height: 34px; padding-left: 32px; padding-right: 28px; font-size: var(--fs-sm); }
.search-wrap .search-clear { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); border: 0; background: transparent; padding: 3px; cursor: pointer; color: var(--text-3); border-radius: 4px; display: inline-flex; align-items: center; justify-content: center; }
.search-wrap .search-clear:hover { color: var(--danger); background: var(--surface-2); }
.search-wrap .search-clear .ic { width: 13px; height: 13px; }

/* 状态高频胶囊组 */
.chip-group { display: inline-flex; align-items: center; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-sm); padding: 2px; gap: 2px; flex-shrink: 0; overflow-x: auto; max-width: 100%; }
.chip { display: inline-flex; align-items: center; padding: 4px 10px; font-size: var(--fs-xs); font-weight: 500; color: var(--text-2); border-radius: 4px; cursor: pointer; user-select: none; transition: all .15s ease; white-space: nowrap; margin: 0; position: relative; }
.chip input { position: absolute; opacity: 0; width: 0; height: 0; pointer-events: none; }
.chip:hover { color: var(--text); background: var(--surface-3); }
.chip.active { background: var(--surface); color: var(--primary-text); font-weight: 600; box-shadow: 0 1px 2px rgba(16,24,40,.08); }
@media (prefers-color-scheme: dark) {
  .chip.active { background: var(--surface-3); color: var(--primary-text); }
}

/* 排序选择器 */
.sort-wrap { flex-shrink: 0; }
.sort-select { font-size: var(--fs-xs); height: 34px; padding: 0 10px; border-radius: var(--r-sm); border: 1px solid var(--line); background: var(--surface); color: var(--text-2); cursor: pointer; }
.sort-select:hover { color: var(--text); border-color: var(--line-2); }

/* 高级筛选折叠按钮 */
.filter-toggle { display: inline-flex; align-items: center; gap: 5px; font-size: var(--fs-xs); height: 34px; padding: 0 10px; border-radius: var(--r-sm); cursor: pointer; flex-shrink: 0; border: 1px solid var(--line); background: var(--surface); color: var(--text-2); }
.filter-toggle:hover { color: var(--text); background: var(--surface-2); }
.filter-toggle .chevron { width: 12px; height: 12px; transition: transform .2s ease; color: var(--text-3); }
.filter-toggle.open .chevron { transform: rotate(180deg); }
.filter-toggle.has-adv { border-color: var(--primary); color: var(--primary-text); background: var(--primary-soft); font-weight: 600; }
.filter-toggle .badge { font-size: 10px; padding: 0 5px; height: 16px; line-height: 16px; border-radius: 8px; margin-left: 2px; }

.toolbar-clear { font-size: var(--fs-xs); height: 34px; padding: 0 8px; flex-shrink: 0; color: var(--danger); }

/* 折叠抽屉面板 */
.filter-drawer { margin-top: var(--s2); padding-top: var(--s3); border-top: 1px solid var(--line); }
.filter-drawer[hidden] { display: none; }
.filters:not(.js) .filter-drawer { display: block !important; }
.filter-drawer-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--s3) var(--s2); }
.fitem { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.fitem .flbl { font-size: var(--fs-xs); color: var(--text-3); font-weight: 500; }
.fitem select { width: 100%; height: 34px; font-size: var(--fs-sm); border-radius: var(--r-sm); }
.fitem-date { grid-column: 1 / -1; }

/* 日期范围组合 */
.date-range { display: flex; align-items: center; gap: 4px; border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--surface); padding: 0 8px; height: 34px; }
.date-range.active { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-soft); background: var(--primary-soft); }
.date-range .date-input { border: 0; background: transparent; font-size: var(--fs-xs); color: var(--text); padding: 4px 0; outline: none; width: calc(50% - 10px); }
.date-range .date-input:focus { outline: none; }
.date-range .range-sep { color: var(--text-3); font-size: var(--fs-xs); padding: 0 2px; user-select: none; }

.drawer-actions { display: flex; justify-content: flex-end; align-items: center; gap: var(--s2); margin-top: var(--s3); padding-top: var(--s2); border-top: 1px dashed var(--line); }
.filters.js .apply { display: none; }
.filters select.active, .filters input.active { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-soft); background: var(--primary-soft); }
.filters .clear { color: var(--danger); }

@media (max-width: 767px) {
  .filter-toolbar { gap: var(--s2); }
  .search-wrap { width: 100%; flex: 1 1 100%; }
  .chip-group { width: 100%; justify-content: space-between; }
  .chip { flex: 1 0 auto; text-align: center; justify-content: center; padding: 6px 4px; font-size: 11px; }
  .sort-wrap { flex: 1 1 calc(50% - var(--s1)); }
  .sort-select { width: 100%; }
  .filter-toggle { flex: 1 1 calc(50% - var(--s1)); justify-content: center; }
  .toolbar-clear { width: 100%; text-align: center; justify-content: center; }
  .filter-drawer-grid { grid-template-columns: 1fr 1fr; }
}

/* ========== 7. responsive / print ========== */
@media (max-width: 767px) {
  .desktop-only { display: none !important; }
}

@media (min-width: 768px) {
  .mobile-only { display: none !important; }
  body, body.has-actionbar { padding-bottom: var(--s5); }
  .tabbar { display: none; }
  .brand span { display: inline; }
  .nav { display: flex; }
  .topsearch { max-width: 360px; margin-left: auto; }
  .userchip .uname { display: inline; }
  .container { padding: var(--s5) var(--s5) var(--s6); }
  .cols { grid-template-columns: 1fr 1fr; }
  .cols.wide-left { grid-template-columns: 3fr 2fr; }
  .fgrid { grid-template-columns: 1fr 1fr; }
  .fgrid.three { grid-template-columns: repeat(3, 1fr); }
  .stats:not(.stats-lean) { grid-template-columns: repeat(6, 1fr); }
  .filter-drawer-grid { grid-template-columns: repeat(5, 1fr) 1.8fr; align-items: end; }
  .fitem-date { grid-column: auto; }
  .actionbar { position: static; background: transparent; border: 0; padding: 0; margin: 0 0 var(--s4); }
  .actionbar .row { justify-content: flex-start; gap: var(--s3); }
  .actionbar form.inline { flex: 0 0 auto; }
  .actionbar form.inline .btn.lg { width: auto; }
  .actionbar .btn.lg { flex: 0 0 auto; }
  .actions.sticky { bottom: 0; }
  .vocabgrid { grid-template-columns: repeat(3, 1fr); }
  .cfggrid { grid-template-columns: repeat(4, 1fr); }
  h1 { font-size: var(--fs-2xl); } .page-title h1.mono { font-size: var(--fs-xl); }
}
/* 备份页状态提示：超过 36 小时无成功备份、备份失败标红；xlsx 失败、校验文件缺失标橙 */
.bk-stale { color: var(--danger); background: var(--danger-soft); border-left: 3px solid var(--danger); padding: var(--s2); border-radius: 4px; font-weight: 600; }
.bk-warn { color: var(--warn); }
p.bk-warn { background: var(--warn-soft); border-left: 3px solid var(--warn); padding: var(--s2); border-radius: 4px; }

@media print {
  .topbar, .tabbar, .actionbar, .actions, .btn, .toast, .filters, .subnav, .page-actions { display: none !important; }
  body { background: #fff; padding: 0; color: #000; }
  .card { border: 1px solid #ccc; break-inside: avoid; }
}
