/*
 * 打印模版设置（第五刀）：列表页 + 编辑页。
 * 列表近 L1（standard-page / erp-card / standard-table）；
 * 编辑紧凑：去长说明、字段三列网格、减少无用 padding；打印测试走隐藏容器。
 *
 * 列表顶栏留白：须压掉 ui_forms .standard-container/.erp-card 双层 24px
 * 与 .standard-header { margin-bottom: 20px }，筛选项↔表头约 8px 阶梯。
 */

/* —— 列表：压掉双层 24px / 标题下 20px 空白带 —— */
.standard-page.ptpl-list-page > .standard-container {
  width: 100%;
  max-width: none;
  padding: 8px 12px 12px;
  box-sizing: border-box;
}

.standard-page.ptpl-list-page .erp-card.ptpl-list-card,
.standard-page.ptpl-list-page .ptpl-list-card.erp-card {
  padding: 12px 16px 16px;
}

.standard-page.ptpl-list-page .ptpl-list-header.standard-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 0;
  min-height: 0;
}

.standard-page.ptpl-list-page .ptpl-list-header .standard-title {
  margin: 0;
  line-height: 1.25;
}

.standard-page.ptpl-list-page .ptpl-list-filters.standard-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding-top: 8px;
  margin-top: 0;
  margin-bottom: 8px;
}

.ptpl-filter-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: #374151;
}

.ptpl-list-app-path {
  font-size: 12px;
  color: #6b7280;
  line-height: 1.35;
  word-break: break-all;
  overflow-wrap: anywhere;
  max-width: 28em;
}

.ptpl-list-page .standard-table-col-ops .standard-table-link + .standard-table-link {
  margin-left: 8px;
}

.ptpl-list-page .ptpl-msg[hidden],
.ptpl-edit-page .ptpl-msg[hidden] {
  display: none;
}

@media (max-width: 768px) {
  .standard-page.ptpl-list-page > .standard-container {
    padding: 8px 0 12px;
  }

  .standard-page.ptpl-list-page .erp-card.ptpl-list-card {
    padding: 12px 14px 14px;
  }
}

/* —— 编辑顶栏 / 工具栏（同类收紧，不大改交互） —— */
.standard-page.ptpl-edit-page > .standard-container {
  padding: 8px 12px 12px;
  box-sizing: border-box;
}

.ptpl-edit-page .ptpl-edit-card.erp-card {
  padding: 12px 16px 16px;
}

.standard-page.ptpl-edit-page .ptpl-edit-header.standard-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
  min-height: 0;
}

.ptpl-edit-header-main {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  min-width: 0;
}

.ptpl-edit-title {
  margin: 0;
  font-size: 16px;
}

.ptpl-header-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.ptpl-scope-chip {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 8px;
  font-size: 12px;
  color: #374151;
  background: #f3f4f6;
}

.ptpl-default-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 8px;
  font-size: 12px;
  color: #2563eb;
  background: #eff6ff;
}

.ptpl-edit-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  margin-bottom: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid #f3f4f6;
}

.ptpl-scope-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: #374151;
}

.ptpl-mm-input {
  width: 72px;
  height: 30px;
}

.ptpl-app-path {
  font-size: 12px;
  color: #6b7280;
}

/* —— 画布 + 字段网格 —— */
.ptpl-editor {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 12px;
}

.ptpl-canvas-wrap {
  position: relative;
  z-index: 1;
  padding: 8px;
  border-radius: 8px;
  background: #f3f4f6;
}

.ptpl-canvas {
  position: relative;
  z-index: 1;
  width: 76mm;
  height: 130mm;
  box-sizing: border-box;
  background: #ffffff;
  border: none;
  border-radius: 8px;
  box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
  overflow: hidden;
  /* 防御：若父级被误设 pointer-events:none，画布仍可点选拖放 */
  pointer-events: auto;
}

/* 模版级整张标签外框（编辑预览；与打印测试 / 业务灌数同源设置） */
.ptpl-canvas.has-outer-border {
  border-style: solid;
  border-width: var(--ptpl-border-w, 0.5mm);
  border-color: var(--ptpl-border-c, #111827);
  border-radius: 0;
}

.ptpl-border-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.ptpl-border-toggle input[type="checkbox"] {
  margin: 0;
}

.ptpl-blank-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.ptpl-blank-toggle input[type="checkbox"] {
  margin: 0;
}

/* 方案 C：表格样卡预览（无拖放节点） */
.ptpl-editor.is-table-layout .ptpl-canvas {
  cursor: default;
  overflow: auto;
}

.ptpl-canvas.ptpl-canvas--table {
  padding: 0;
  display: flex;
  flex-direction: column;
}

.ptpl-canvas.ptpl-canvas--table .pkg-label-card {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 100%;
  box-sizing: border-box;
}

.ptpl-canvas.ptpl-canvas--table .pkg-label-card-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 10px;
}

.ptpl-canvas.ptpl-canvas--table .pkg-label-card-table th,
.ptpl-canvas.ptpl-canvas--table .pkg-label-card-table td {
  border: 1px solid #111827;
  padding: 3px 4px;
  vertical-align: middle;
  word-break: break-word;
}

.ptpl-canvas.ptpl-canvas--table .pkg-label-card-title {
  text-align: center;
  font-weight: 700;
  font-size: 12px;
  padding: 5px 4px;
}

.ptpl-canvas.ptpl-canvas--table .pkg-label-card-th {
  width: 18%;
  text-align: center;
  font-weight: 600;
  background: #f9fafb;
}

.ptpl-canvas.ptpl-canvas--table .pkg-label-card-td {
  width: 32%;
  text-align: center;
}

.ptpl-canvas.ptpl-canvas--table .pkg-label-card-blank {
  flex: 1 1 auto;
  min-height: 24mm;
  border: 1px solid #111827;
  border-top: none;
  box-sizing: border-box;
  background: #fff;
}

.ptpl-print-sheet--table .pkg-label-card-table th,
.ptpl-print-sheet--table .pkg-label-card-table td {
  border: 1px solid #111;
  padding: 4px 6px;
}

.ptpl-print-sheet--table .pkg-label-card-blank {
  flex: 1 1 auto;
  min-height: 28mm;
  border: 1px solid #111;
  border-top: none;
  box-sizing: border-box;
}

.ptpl-node {
  position: absolute;
  box-sizing: border-box;
  max-width: 70mm;
  padding: 0;
  color: #374151;
  line-height: 1.25;
  cursor: grab;
  user-select: none;
  touch-action: none;
  pointer-events: auto;
}

.ptpl-node.is-selected {
  outline: 1px solid #2563eb;
}

.ptpl-node.is-dragging {
  cursor: grabbing;
  outline: 1px dashed #2563eb;
}

.ptpl-field.is-selected {
  outline: 1px solid #2563eb;
  background: #eff6ff;
}

.ptpl-node.is-hidden {
  display: none;
}

.ptpl-node__k {
  margin-right: 1mm;
  color: #6b7280;
}

.ptpl-node--sample_roll_code .ptpl-node__v,
.ptpl-node--material_name .ptpl-node__v {
  font-weight: 700;
  color: #111827;
}

.ptpl-node--barcode {
  background: #ffffff;
}

.ptpl-node--barcode svg {
  display: block;
  width: 100%;
  height: 100%;
}

/* 字段区：三列网格，窄屏降为 2/1，去掉右侧大片空白 */
.ptpl-fields {
  flex: 1 1 420px;
  min-width: 280px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  align-content: start;
}

.ptpl-field {
  padding: 8px 10px;
  border-radius: 8px;
  background: #f8f9fa;
}

.ptpl-field__title {
  margin: 0 0 6px;
  font-size: 13px;
  font-weight: 600;
  color: #111827;
}

.ptpl-field__row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
  font-size: 12px;
  color: #374151;
}

.ptpl-field__row input[type="number"] {
  width: 64px;
  height: 28px;
  padding: 0 6px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  font-size: 13px;
  color: #374151;
  background: #ffffff;
}

.ptpl-msg {
  min-height: 1.2em;
  margin: 8px 0 0;
  font-size: 12px;
  color: #6b7280;
}

.ptpl-msg.is-error {
  color: #ef4444;
}

.ptpl-save-busy {
  opacity: 0.7;
}

@media (max-width: 1100px) {
  .ptpl-fields {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 700px) {
  .ptpl-fields {
    grid-template-columns: 1fr;
  }
}

/*
 * 打印测试：屏外 + 不可交互；切勿用 inset:0 / 全屏 fixed 盖住画布。
 * 仅打印媒体查询 + body.ptpl-print-test-active 时露出打印内容。
 */
.ptpl-print-root {
  position: absolute !important;
  left: -9999px !important;
  top: 0 !important;
  width: 1px !important;
  height: 1px !important;
  margin: 0 !important;
  padding: 0 !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  clip-path: inset(50%) !important;
  visibility: hidden !important;
  pointer-events: none !important;
  z-index: 0;
}

.ptpl-print-sheet {
  box-sizing: border-box;
  position: relative;
  background: #ffffff;
  color: #111827;
  overflow: hidden;
  font-family: Inter, "PingFang SC", sans-serif;
  font-size: 9pt;
  line-height: 1.25;
  border: none;
}

.ptpl-print-sheet.has-outer-border {
  border-style: solid;
  border-width: var(--ptpl-border-w, 0.5mm);
  border-color: var(--ptpl-border-c, #111827);
}

.ptpl-print-sheet .ptpl-print-node {
  box-sizing: border-box;
  max-width: 100%;
}

.ptpl-print-sheet .ptpl-print-node--flow {
  padding: 1mm 1.5mm;
}

.ptpl-print-sheet .ptpl-print-node__k {
  margin-right: 1mm;
  color: #6b7280;
}

.ptpl-print-sheet .ptpl-print-node--barcode svg {
  display: block;
  width: 100%;
  height: 100%;
}

@media print {
  @page {
    margin: 0;
    size: var(--ptpl-print-w, 76mm) var(--ptpl-print-h, 130mm);
  }

  html,
  body {
    margin: 0 !important;
    padding: 0 !important;
    background: #ffffff !important;
  }

  body.ptpl-print-test-active * {
    visibility: hidden !important;
  }

  body.ptpl-print-test-active .ptpl-print-root,
  body.ptpl-print-test-active .ptpl-print-root * {
    visibility: visible !important;
  }

  body.ptpl-print-test-active .ptpl-print-root {
    position: absolute !important;
    left: 0 !important;
    top: 0 !important;
    width: auto !important;
    height: auto !important;
    overflow: visible !important;
    clip: auto !important;
    clip-path: none !important;
    visibility: visible !important;
    z-index: 1 !important;
    pointer-events: none !important;
  }

  body.ptpl-print-test-active .ptpl-print-sheet {
    box-shadow: none;
    page-break-after: avoid;
  }
}
