/* 笼卡：按 99.1 × 67.7 mm 标签纸排版（A4 上 2 列 × 4 行，一张 8 枚）。
 *
 * 几何是量好的，不要凭感觉改：
 *   A4  210 × 297 mm
 *   卡   99.1 × 67.7 mm
 *   左右边距 4.65 mm  →  4.65 + 99.1 + 2.5 + 99.1 + 4.65 = 210 ✓
 *   上下边距 13.1 mm  →  13.1 + 67.7 × 4 + 13.1        = 297 ✓
 *   列间距 2.5 mm，行间距 0
 *
 * 打印时必须把缩放设成「实际大小 / 100%」，并关掉页眉页脚，
 * 否则浏览器会按「适应页面」缩一点，位置就全错了。屏幕上的提示写了这句。
 *
 * 全部走 class，不用行内 style —— CSP 是 style-src 'self'，
 * 行内样式会被静默丢掉，看不出任何报错。
 */

/* ---------- 屏幕上的预览 ---------- */

.cardhint {
  margin: 0 0 12px;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--soft);
  color: var(--dim);
  font-size: 13.5px;
  line-height: 1.7;
}
.cardhint b { color: var(--ink); }

.cardbar { display: flex; gap: 9px; flex-wrap: wrap; margin-bottom: 14px; }

/* ---------- 格位图：哪格印、哪格已用 ---------- */

.slotmap {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  max-width: 520px;
  margin: 0 0 16px;
}
.slotpage {
  grid-column: 1 / -1;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--dim);
  padding-top: 6px;
  border-top: 1px dashed var(--line);
}
.slot {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  padding: 9px 11px;
  border: 1.5px dashed var(--line);
  border-radius: 10px;
  background: var(--soft);
  color: var(--dim);
  font: inherit;
  font-size: 13.5px;
  cursor: pointer;
  text-align: left;
}
.slot i {
  font-style: normal;
  font-weight: 800;
  font-size: 12px;
  width: 20px;
  height: 20px;
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  background: #fff;
  border: 1px solid var(--line);
  color: var(--dim);
}
.slot b { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
          font-weight: 600; }
.slot.has {
  border-style: solid;
  border-color: var(--ink);
  background: #fff;
  color: var(--ink);
}
.slot.has i { background: var(--ink); border-color: var(--ink); color: #fff; }
.slot.used {
  border-style: solid;
  border-color: var(--line);
  background:
    repeating-linear-gradient(-45deg, transparent 0 5px, rgb(0 0 0 / 5%) 5px 7px);
  color: var(--dim);
}
.slot.used b { text-decoration: line-through; }
.slot:active { transform: scale(0.98); }

.cardwrapper {
  /* 一张 A4 在手机上放不下，整体缩小预览；打印时这条不生效 */
  overflow-x: auto;
  padding-bottom: 8px;
}

.cardsheet {
  width: 210mm;
  height: 297mm;
  box-sizing: border-box;
  padding: 13.1mm 4.65mm;
  display: grid;
  grid-template-columns: 99.1mm 99.1mm;
  grid-template-rows: repeat(4, 67.7mm);
  column-gap: 2.5mm;
  row-gap: 0;
  background: #fff;
  color: #111;
  margin: 0 auto 18px;
  box-shadow: 0 2px 18px rgb(0 0 0 / 14%);
}

.cardone {
  box-sizing: border-box;
  width: 99.1mm;
  height: 67.7mm;
  padding: 3mm 4.6mm;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 0.9mm;
  font-family: "Noto Sans SC", "Source Han Sans SC", "Microsoft YaHei", sans-serif;
  color: #111;
  /* 顶缘一条墨色带 —— 卡片抽出来一眼认出是 SnapLab 的笼卡 */
  border-top: 0.65mm solid #1c1c1e;
}

/* 名单区：能压就压，压不下就裁掉，**绝不把卡撑变形**。
   裁掉多少由「另有 N 只」如实说出来。 */
.cardlist { flex: 1 1 auto; min-height: 0; overflow: hidden; }

/* 空位也要占格：8 枚一张，第 5 张卡必须落在第二页的第一枚上。
   屏幕上画出格号和「已用」斜纹，打印时全部收掉 —— 那格就是白纸。 */
.cardgap {
  box-sizing: border-box;
  width: 99.1mm;
  height: 67.7mm;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.5mm;
  cursor: pointer;
  color: #b9c2c5;
  font-size: 3mm;
}
.cardgap > i {
  font-style: normal;
  font-weight: 800;
  font-size: 5mm;
  width: 9mm;
  height: 9mm;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 0.3mm dashed #c9d2d4;
  border-radius: 2mm;
}
.cardgap > span { font-weight: 700; letter-spacing: 0.5mm; }
.cardgap.used {
  color: #9aa4a7;
  background:
    repeating-linear-gradient(-45deg, transparent 0 3mm, rgb(0 0 0 / 4%) 3mm 4.5mm);
}
.cardgap.used > i { border-style: solid; border-color: #9aa4a7; color: #9aa4a7; }
.cardone[data-slot] { cursor: pointer; }
@media (hover: hover) {
  .cardone[data-slot]:hover { outline: 0.3mm solid #7fb3b0; outline-offset: -0.3mm; }
}

/* 屏幕上画出裁切参考线；打印时去掉，免得印在标签上 */
.cardsheet.guides .cardone { outline: 0.2mm dashed #c9d2d4; outline-offset: -0.1mm; }
.cardsheet.guides .cardgap:not(.used) { outline: 0.2mm dashed #e4e9ea; outline-offset: -0.1mm; }

.cardhead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 3mm;
}
.cardcount {
  font-size: 3mm;
  font-weight: 800;
  white-space: nowrap;
  background: #edf4f2;
  color: #245c55;
  border-radius: 1mm;
  padding: 0.6mm 2.2mm;
  line-height: 1.2;
}

/* 笼号带：大黑字 + 一条粗重下划线，是整张卡的视觉锚点 */
.cardband {
  border-bottom: 0.25mm solid #b8b8bf;
  padding-bottom: 1mm;
}
.cardlabel {
  font-size: 6.2mm;
  font-weight: 800;
  letter-spacing: 0.3mm;
  line-height: 1.05;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cardmeta {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.6mm 2.4mm;
  font-size: 2.25mm;
  line-height: 1.35;
  margin-top: 1mm;
}
/* 字段不带框 —— 灰标签 + 黑值，比一排小药丸干净 */
.cardmeta span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.cardmeta span + span { position: relative; }
.cardmeta i { font-style: normal; color: #8a9194; margin-right: 0.7mm; font-size: 2.3mm; }

.cardtable { width: 100%; table-layout: fixed; border-collapse: collapse; font-size: 2.2mm; line-height: 1.15; }
/* 9.9.1 起不印周龄（卡几个月不换，周龄会过期），多出来的宽度给基因型。 */
.cardtable th:nth-child(1) { width: 16%; }
.cardtable th:nth-child(2) { width: 9%; }
.cardtable th:nth-child(3) { width: 33%; }
.cardtable th:nth-child(4) { width: 19%; }
.cardtable th:nth-child(5) { width: 23%; }
.cardtable tr { height: 3.15mm; }
.cardtable th, .cardtable td {
  text-align: left;
  padding: 0.15mm 1.2mm 0.15mm 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-variant-numeric: tabular-nums;
}
/* 基因型独占一栏：一笼混两种基因型时各自跟行。等宽字体让
   flox+/- lyz+/- 这类串排得齐；允许折两行，挤不下的由「另有 N 只」兜底。 */
.cardtable .geno { white-space: nowrap; line-height: 1.15; min-width: 0;
  font-family: ui-monospace, "SF Mono", Consolas, monospace; font-size: 2.15mm; }
.cardtable td:last-child { padding-right: 0; }
.cardtable th { font-weight: 700; color: #6a7174; border-bottom: 0.25mm solid #111;
  font-size: 2.1mm; letter-spacing: 0.05mm; }
.cardtable tbody tr:nth-child(even) { background: #f6f8f7; }
.cardtable tbody tr + tr td { border-top: 0.15mm solid #e4e8e9; }
/* td.tag 撞了 styles.css 里列表标签的 .tag 胶囊样式（灰底、圆角、12px、灰字），
   在 2.6mm 的笼卡表格里会变成一排灰色药丸。这里它只是「编号列加粗」，
   把被误带的属性压回继承值。 */
.cardtable td.tag { font-weight: 700; font-size: inherit; background: none;
  border-radius: 0; color: inherit; }

.cardmore { font-size: 2.2mm; line-height: 1.2; color: #555; flex: none; }

.cardfoot {
  margin-top: auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 2.5mm;
  font-size: 2.5mm;
  color: #666;
  border-top: 0.2mm solid #ddd;
  padding-top: 1mm;
  min-height: 13mm;
  flex-shrink: 0;
}
.cfnote {
  min-width: 0;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.cfhint { color: #9aa4a7; font-size: 2.3mm; }
.cdash { color: #b8bfc2; }

/* 卡脚二维码：真码 —— 扫一下把这一笼（含动物名单）导进 SnapLab。
   白底小芯片保证印刷件上的对比度，别让它躺在字上。 */
.cardqr {
  flex: none;
  width: 13mm;
  height: 13mm;
  background: #fff;
  padding: 0.6mm;
  border: 0.15mm solid #ddd;
  border-radius: 1mm;
}

/* 卡头左上角的水印：Snappy 标 + SnapLab · 日期，要看得见但不抢笼号。
   .icon 全局带 stroke，实心 logo 必须关掉，不然会描出一圈毛边。 */
.cardmark { display: inline-flex; align-items: center; gap: 1.2mm;
            white-space: nowrap; font-size: 3.4mm; font-weight: 800;
            color: #111; line-height: 1; }
.cardmark .icon { width: 3.6mm; height: 3.6mm; stroke: none; }
.card-snappy { width: 5.5mm; height: 5.5mm; flex: none; }
.cardmark small { display: block; margin-top: 0.8mm; font-size: 1.9mm; font-weight: 400; color: #687772; }

/* 手机逐枚查看，纸张与打印格位仍保持原始毫米尺寸。 */
@media screen and (max-width: 640px) {
  .cardwrapper { overflow: visible; }
  .cardsheet { width: 100%; height: auto; padding: 0; display: flex; flex-direction: column;
    gap: 14px; background: none; box-shadow: none; }
  .cardone { width: 100%; max-width: 99.1mm; background: #fff; margin: 0 auto;
    padding-left: 3mm; padding-right: 3mm; box-shadow: 0 4px 18px rgb(25 50 42 / 7%); }
  .cardgap { display: none; }
}

/* ---------- 打印 ---------- */

@media print {
  @page { size: A4; margin: 0; }

  html, body { margin: 0; padding: 0; background: #fff; }
  /* 除了内容区，什么都不印：顶栏、底栏、公告、浮动按钮 */
  body > *:not(#main) { display: none !important; }
  #main {
    margin: 0 !important;
    padding: 0 !important;
    width: auto !important;
    max-width: none !important;
  }
  /* 笼卡打印页（body.print-cards 由 tracker.js 在该视图挂上）：剥到只剩纸。
     其它页面没有卡片纸，正常打印可见的视图 —— 不能再一棒打死成空白页 */
  .print-cards #main > .view:not(#v-tracker) { display: none !important; }
  .print-cards #trackerBody > *:not(.cardwrapper) { display: none !important; }
  .print-cards .cardwrapper { overflow: visible !important; padding: 0 !important; }

  .cardsheet {
    margin: 0;
    box-shadow: none;
    break-after: page;
    page-break-after: always;
  }
  .cardsheet:last-child { break-after: auto; page-break-after: auto; }
  .cardsheet.guides .cardone,
  .cardsheet.guides .cardgap,
  .cardone[data-slot]:hover { outline: 0 !important; }

  /* 「已用」和空格在纸上就是空白 —— 格号、斜纹、屏幕提示一律不印 */
  .cardgap { background: none !important; cursor: default; }
  .cardgap > * { display: none !important; }

  /* 一枚卡不许被拆到两页 */
  .cardone, .cardgap { break-inside: avoid; page-break-inside: avoid; }
  .cardone { print-color-adjust: exact; -webkit-print-color-adjust: exact; }
}
