:root {
  --bg: #eef3f7;
  --bg-strong: #e3ebf2;
  --panel: #ffffff;
  --panel-subtle: #f7fafc;
  --ink: #17202a;
  --ink-strong: #0b1220;
  --muted: #647386;
  --muted-strong: #445366;
  --line: #dce4ec;
  --line-strong: #c5d0dc;
  --accent: #0f766e;
  --accent-dark: #0b5f59;
  --accent-soft: #e4f3f0;
  --indigo: #2f4f8f;
  --gold: #b7791f;
  --danger: #9c2f2f;
  --shadow-soft: 0 14px 34px rgba(18, 32, 46, 0.08);
  --shadow-panel: 0 22px 60px rgba(18, 32, 46, 0.14);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.72), rgba(255, 255, 255, 0) 260px),
    linear-gradient(135deg, var(--bg), var(--bg-strong));
  color: var(--ink);
  font-family: "Microsoft YaHei", "PingFang SC", "Noto Sans SC", Arial, sans-serif;
}

button,
input,
textarea {
  font: inherit;
}

button {
  user-select: none;
}

.app-shell {
  min-height: 100vh;
  padding: 20px;
}

.topbar {
  align-items: center;
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid rgba(197, 208, 220, 0.78);
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
  display: flex;
  gap: 20px;
  justify-content: space-between;
  margin: 0 auto 18px;
  max-width: 1540px;
  padding: 14px 16px;
}

.brand-block {
  min-width: 0;
  padding-left: 48px;
  position: relative;
}

.brand-block::before {
  align-items: center;
  background: linear-gradient(135deg, var(--ink-strong), var(--indigo));
  border-radius: 8px;
  box-shadow: 0 10px 22px rgba(47, 79, 143, 0.22);
  color: #fff;
  content: "¥";
  display: flex;
  font-size: 20px;
  font-weight: 900;
  height: 36px;
  justify-content: center;
  left: 0;
  line-height: 1;
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 36px;
}

.brand-block h1 {
  color: var(--ink-strong);
  font-size: 20px;
  font-weight: 900;
  letter-spacing: 0;
  line-height: 1.2;
  margin: 0 0 5px;
}

.brand-block p {
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.35;
  margin: 0;
}

.topbar-actions {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.primary-button,
.secondary-button {
  align-items: center;
  border-radius: 7px;
  cursor: pointer;
  display: inline-flex;
  font-size: 14px;
  font-weight: 800;
  gap: 8px;
  height: 38px;
  justify-content: center;
  line-height: 1;
  padding: 0 15px;
  transition: background 0.16s ease, border-color 0.16s ease, color 0.16s ease, box-shadow 0.16s ease, transform 0.16s ease;
  white-space: nowrap;
}

.primary-button::before,
.secondary-button::before {
  background: currentColor;
  content: "";
  display: inline-block;
  flex: 0 0 auto;
  height: 16px;
  mask-position: center;
  mask-repeat: no-repeat;
  mask-size: 16px 16px;
  width: 16px;
}

#sampleBtn::before {
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 3v5'/%3E%3Cpath d='M12 16v5'/%3E%3Cpath d='M3 12h5'/%3E%3Cpath d='M16 12h5'/%3E%3Cpath d='m5.6 5.6 3.5 3.5'/%3E%3Cpath d='m14.9 14.9 3.5 3.5'/%3E%3Cpath d='m18.4 5.6-3.5 3.5'/%3E%3Cpath d='m9.1 14.9-3.5 3.5'/%3E%3C/svg%3E");
}

#clearBtn::before {
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 6h18'/%3E%3Cpath d='M8 6V4h8v2'/%3E%3Cpath d='M19 6l-1 14H6L5 6'/%3E%3Cpath d='M10 11v5'/%3E%3Cpath d='M14 11v5'/%3E%3C/svg%3E");
}

#generatePdfBtn::before {
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M14 2H7a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V7z'/%3E%3Cpath d='M14 2v5h5'/%3E%3Cpath d='M12 11v6'/%3E%3Cpath d='m9.5 14.5 2.5 2.5 2.5-2.5'/%3E%3C/svg%3E");
}

#printPdfBtn::before {
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9V3h12v6'/%3E%3Cpath d='M6 18H4a2 2 0 0 1-2-2v-5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v5a2 2 0 0 1-2 2h-2'/%3E%3Cpath d='M6 14h12v7H6z'/%3E%3C/svg%3E");
}

.primary-button {
  background: var(--accent);
  border: 1px solid var(--accent);
  box-shadow: 0 10px 20px rgba(15, 118, 110, 0.2);
  color: #fff;
  min-width: 116px;
}

.secondary-button {
  background: #fff;
  border: 1px solid var(--line-strong);
  color: var(--muted-strong);
}

.primary-button:hover {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
  box-shadow: 0 12px 24px rgba(15, 118, 110, 0.24);
}

.secondary-button:hover {
  background: #f8fbfd;
  border-color: #aebdcc;
  color: var(--ink-strong);
}

.primary-button:active,
.secondary-button:active {
  transform: translateY(1px);
}

.primary-button:disabled,
.secondary-button:disabled {
  cursor: wait;
  opacity: 0.65;
}

.workspace {
  align-items: start;
  display: grid;
  gap: 18px;
  grid-template-columns: minmax(430px, 510px) minmax(560px, 1fr);
  margin: 0 auto;
  max-width: 1540px;
}

.form-panel,
.preview-panel {
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid rgba(197, 208, 220, 0.82);
  border-radius: var(--radius);
  box-shadow: var(--shadow-panel);
}

.form-panel {
  display: flex;
  flex-direction: column;
  gap: 0;
  overflow: hidden;
}

.panel-title,
.preview-head {
  align-items: flex-start;
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 16px;
  justify-content: space-between;
}

.panel-title {
  background: linear-gradient(180deg, #ffffff, #f8fbfd);
  padding: 16px;
}

.preview-head {
  padding: 16px 16px 14px;
}

.panel-title h2,
.preview-head h2 {
  color: var(--ink-strong);
  font-size: 18px;
  font-weight: 900;
  line-height: 1.3;
  margin: 0 0 5px;
}

.panel-title span,
.preview-head p,
.section-heading span,
#pdfStatus {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.panel-title output {
  background: #f0f7f5;
  border: 1px solid #bedbd6;
  border-radius: 8px;
  color: var(--accent-dark);
  font-size: 22px;
  font-variant-numeric: tabular-nums;
  font-weight: 900;
  min-width: 120px;
  padding: 10px 13px;
  text-align: right;
}

.form-section {
  background: transparent;
  border: 0;
  border-top: 1px solid var(--line);
  padding: 14px 16px;
}

.panel-title + .form-section {
  border-top: 0;
}

.section-heading {
  align-items: center;
  display: flex;
  justify-content: space-between;
  margin-bottom: 10px;
}

.section-heading h3 {
  color: var(--ink-strong);
  font-size: 14px;
  font-weight: 900;
  line-height: 1.3;
  margin: 0;
}

.field-grid {
  display: grid;
  gap: 13px 14px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.field-grid.sign-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

label,
.block-field {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.block-field + .block-field {
  margin-top: 12px;
}

label span,
.block-field span,
.amount-readout span {
  color: var(--muted-strong);
  font-size: 12px;
  font-weight: 900;
  line-height: 1.1;
}

input,
textarea {
  background: #fff;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  color: var(--ink);
  outline: none;
  transition: border-color 0.16s ease, box-shadow 0.16s ease, background 0.16s ease;
  width: 100%;
}

input {
  font-size: 15px;
  font-variant-numeric: tabular-nums;
  font-weight: 650;
  height: 38px;
  padding: 0 11px;
}

textarea {
  font-size: 15px;
  font-weight: 600;
  line-height: 1.55;
  min-height: 86px;
  padding: 10px 11px;
  resize: vertical;
}

input:hover,
textarea:hover {
  border-color: #afbdcb;
}

input:focus,
textarea:focus {
  background: #fff;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.13);
}

.detail-table-wrap {
  background: #fff;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  overflow: hidden;
}

.detail-table {
  border-collapse: collapse;
  width: 100%;
}

.detail-table th,
.detail-table td {
  border-bottom: 1px solid var(--line);
  padding: 7px;
  vertical-align: middle;
}

.detail-table th {
  background: #f0f4f8;
  color: var(--muted-strong);
  font-size: 12px;
  font-weight: 900;
  height: 31px;
  text-align: left;
}

.detail-table tr:last-child td {
  border-bottom: 0;
}

.detail-table tr:hover td {
  background: #fbfdff;
}

.detail-table input {
  background: #fff;
  border-color: #d2dce6;
  height: 33px;
  padding: 0 9px;
}

.detail-table td:nth-child(1) {
  width: 28%;
}

.detail-table td:nth-child(2) {
  width: 48%;
}

.detail-table td:nth-child(3) {
  width: 24%;
}

.amount-readout {
  align-items: center;
  background: linear-gradient(90deg, #f1f8f5, #ffffff);
  border-top: 1px solid var(--line);
  display: flex;
  gap: 14px;
  justify-content: space-between;
  padding: 14px 16px;
}

.amount-readout strong {
  color: var(--ink-strong);
  font-size: 14px;
  font-weight: 900;
  line-height: 1.5;
  text-align: right;
}

.preview-panel {
  min-width: 0;
  padding: 0;
  position: sticky;
  top: 20px;
}

#pdfStatus {
  align-items: center;
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 999px;
  display: inline-flex;
  line-height: 1;
  padding: 7px 11px;
  white-space: nowrap;
}

.canvas-frame {
  background:
    linear-gradient(180deg, #f2f6fa, #e8eef5);
  border-radius: 0 0 var(--radius) var(--radius);
  max-height: calc(100vh - 182px);
  overflow: auto;
  padding: 18px;
}

#previewCanvas {
  background: #fff;
  box-shadow:
    0 2px 0 rgba(255, 255, 255, 0.7) inset,
    0 24px 52px rgba(15, 23, 42, 0.24);
  display: block;
  height: auto;
  margin: 0 auto;
  max-width: 100%;
  width: min(100%, 540px);
}

@page {
  size: 595pt 842pt;
  margin: 0;
}

@media print {
  body {
    background: #fff;
  }

  .topbar,
  .form-panel,
  .preview-head {
    display: none;
  }

  .app-shell,
  .preview-panel,
  .canvas-frame {
    background: #fff;
    border: 0;
    box-shadow: none;
    margin: 0;
    padding: 0;
  }

  .workspace {
    display: block;
    margin: 0;
    max-width: none;
  }

  #previewCanvas {
    box-shadow: none;
    height: 842pt;
    margin: 0;
    max-width: none;
    width: 595pt;
  }
}

@media (max-width: 1160px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .preview-panel {
    position: static;
  }

  .canvas-frame {
    max-height: none;
  }
}

@media (max-width: 680px) {
  .app-shell {
    padding: 12px;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .brand-block {
    padding-left: 44px;
  }

  .topbar-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    justify-content: stretch;
  }

  .primary-button,
  .secondary-button {
    min-width: 0;
    padding: 0 11px;
  }

  .field-grid,
  .field-grid.sign-grid {
    grid-template-columns: 1fr;
  }

  .detail-table th,
  .detail-table td {
    padding: 6px;
  }

  .detail-table th {
    font-size: 11px;
  }

  .detail-table td:nth-child(1) {
    width: 24%;
  }

  .detail-table td:nth-child(2) {
    width: 42%;
  }

  .detail-table td:nth-child(3) {
    width: 34%;
  }

  .panel-title,
  .preview-head {
    align-items: stretch;
    flex-direction: column;
  }

  .panel-title output {
    width: 100%;
  }

  .form-section {
    padding: 13px;
  }

  .canvas-frame {
    padding: 10px;
  }
}
