:root {
  color-scheme: light;
  --ink: #1d232a;
  --muted: #667085;
  --line: #d8dee8;
  --paper: #f4f6f9;
  --panel: #ffffff;
  --accent: #1976d2;
  --accent-strong: #105ca8;
  --danger: #c62828;
  font-family: Inter, "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
}

@font-face {
  font-family: "PdfDemoSimSun";
  src: url("simsun.ttf") format("truetype");
  font-weight: 400 700;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
}

button:hover {
  border-color: var(--accent);
  color: var(--accent-strong);
}

button.secondary {
  color: var(--muted);
}

.app-shell {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr) 280px;
  min-height: 100vh;
}

.toolbar,
.properties {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 16px;
  background: var(--panel);
  border-right: 1px solid var(--line);
}

.toolbar {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.properties {
  border-right: 0;
  border-left: 1px solid var(--line);
  overflow: auto;
}

.brand {
  display: grid;
  gap: 4px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.brand strong {
  font-size: 17px;
}

.brand span,
.status,
.empty {
  color: var(--muted);
  font-size: 13px;
}

.upload-box {
  display: grid;
  place-items: center;
  min-height: 72px;
  margin: 16px 0;
  border: 1px dashed #9aa8ba;
  border-radius: 8px;
  background: #f9fbfd;
  cursor: pointer;
}

.upload-box input {
  display: none;
}

.tool-group {
  display: grid;
  gap: 8px;
  margin: 16px 0;
}

.toolbar-scroll {
  min-height: 0;
  flex: 1;
  overflow: hidden;
}

.field-library {
  height: 100%;
  min-height: 0;
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.preset-list {
  display: grid;
  gap: 6px;
  min-height: 0;
  overflow: auto;
  padding-right: 4px;
}

.preset-field {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  padding: 6px 8px;
  text-align: left;
}

.preset-field strong {
  overflow: hidden;
  font-size: 13px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.preset-field span {
  color: var(--muted);
  font-size: 12px;
}

.toolbar-fixed {
  flex: 0 0 auto;
  padding-top: 10px;
  border-top: 1px solid var(--line);
  background: var(--panel);
}

.toolbar-fixed .tool-group {
  margin: 10px 0;
}

#openCustomFieldDialog {
  background: #eef6ff;
  border-color: #b8d8fb;
  color: var(--accent-strong);
  font-weight: 700;
}

.intro,
.contact {
  margin-top: 10px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.contact {
  color: var(--accent-strong);
  font-weight: 700;
}

.tool-group label,
.property-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.actions button:first-child,
#printPreview {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.modal {
  width: min(420px, calc(100vw - 32px));
  padding: 0;
  border: 0;
  border-radius: 8px;
  box-shadow: 0 20px 70px rgba(16, 24, 40, 0.28);
}

.modal::backdrop {
  background: rgba(17, 24, 39, 0.42);
}

.modal-panel {
  display: grid;
  gap: 14px;
  padding: 18px;
  background: #fff;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.modal-head button {
  width: 32px;
  min-height: 32px;
  border: 0;
  font-size: 22px;
  line-height: 1;
}

.modal-panel label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.modal-panel input,
.modal-panel select {
  width: 100%;
  min-height: 36px;
  padding: 6px 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.modal-actions button:first-child {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.workspace {
  position: relative;
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 48px;
  padding: 0 18px;
  background: rgba(244, 246, 249, 0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(8px);
}

.viewer {
  display: grid;
  gap: 24px;
  justify-content: center;
  padding: 24px;
  overflow: auto;
}

.empty-viewer {
  display: grid;
  place-items: center;
  min-width: min(720px, calc(100vw - 560px));
  min-height: 520px;
  border: 1px dashed #a8b4c4;
  border-radius: 8px;
  color: var(--muted);
  background: #fff;
}

.loading-mask {
  position: absolute;
  inset: 48px 0 0;
  z-index: 20;
  display: grid;
  place-content: center;
  gap: 12px;
  background: rgba(244, 246, 249, 0.78);
  color: var(--muted);
  backdrop-filter: blur(4px);
}

.spinner {
  width: 34px;
  height: 34px;
  margin: 0 auto;
  border: 3px solid #c8d2df;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.page {
  position: relative;
  background: #fff;
  box-shadow: 0 14px 36px rgba(16, 24, 40, 0.16);
}

.page canvas {
  display: block;
}

.overlay {
  position: absolute;
  inset: 0;
}

.field {
  position: absolute;
  display: flex;
  align-items: center;
  padding: 4px 8px;
  border: 1px solid rgba(25, 118, 210, 0.9);
  background: rgba(227, 242, 253, 0.72);
  color: #111827;
  line-height: 1.2;
  outline: 0;
  overflow: hidden;
  user-select: none;
  white-space: pre-wrap;
}

.field.selected {
  border-color: #e65100;
  background: rgba(255, 243, 224, 0.82);
  box-shadow: 0 0 0 2px rgba(230, 81, 0, 0.16);
}

.field.locked {
  border-style: dashed;
}

.resize-handle {
  position: absolute;
  right: -5px;
  bottom: -5px;
  width: 12px;
  height: 12px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: var(--accent);
  cursor: nwse-resize;
}

.snap-guide {
  position: absolute;
  z-index: 5;
  pointer-events: none;
  background: #00a1ff;
}

.snap-guide.x {
  top: 0;
  bottom: 0;
  width: 1px;
}

.snap-guide.y {
  left: 0;
  right: 0;
  height: 1px;
}

.field img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.panel-title {
  margin-bottom: 14px;
  font-weight: 700;
}

.property-form {
  display: grid;
  gap: 12px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.property-form input,
.property-form select,
.tool-group input,
.tool-group select {
  width: 100%;
  min-height: 34px;
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.check-row {
  display: flex !important;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 8px !important;
}

.check-row input {
  width: auto;
}

.file-row {
  display: none !important;
}

.file-row.visible {
  display: grid !important;
}

.danger {
  border-color: #efb5b5;
  color: var(--danger);
}

.hidden {
  display: none !important;
}

body.is-printing .field {
  border-color: transparent !important;
  background: transparent !important;
  box-shadow: none !important;
  outline: 0 !important;
}

body.is-printing .resize-handle,
body.is-printing .snap-guide {
  display: none !important;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .toolbar,
  .properties {
    position: static;
    height: auto;
    border: 0;
    border-bottom: 1px solid var(--line);
  }
}

@page {
  margin: 0;
}

@media print {
  html,
  body {
    width: 100%;
    margin: 0 !important;
    background: #fff;
  }

  .toolbar,
  .properties,
  .topbar {
    display: none !important;
  }

  .app-shell {
    display: block;
    min-height: 0;
  }

  .viewer {
    display: block;
    padding: 0;
  }

  .page {
    width: var(--page-print-width) !important;
    height: var(--page-print-height) !important;
    margin: 0 auto;
    box-shadow: none;
    break-after: page;
    page-break-after: always;
  }

  .page canvas {
    width: var(--page-print-width) !important;
    height: var(--page-print-height) !important;
  }

  .field {
    left: var(--field-print-left) !important;
    top: var(--field-print-top) !important;
    width: var(--field-print-width) !important;
    height: var(--field-print-height) !important;
    padding: 4pt 8pt !important;
    border-color: transparent !important;
    background: transparent !important;
    box-shadow: none !important;
    font-size: var(--field-print-font-size) !important;
    line-height: 1.2 !important;
    outline: 0 !important;
  }

  .resize-handle,
  .snap-guide {
    display: none !important;
  }
}
