:root {
  color-scheme: light;
  --surface: #ffffff;
  --panel: #f6f7f8;
  --panel-line: #d8dde3;
  --text: #17191c;
  --muted: #66707b;
  --accent: #006d77;
  --accent-dark: #04535b;
  --danger: #9c2f2f;
  --preview-bg: #dfe5ea;
  --control-bg: #ffffff;
  --focus: #b65172;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

body {
  font-family: "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  color: var(--text);
  background: var(--preview-bg);
}

button,
input,
select,
textarea {
  font: inherit;
}

button,
select,
input,
textarea {
  border: 1px solid #c8d0d8;
  border-radius: 6px;
}

button,
select,
input[type="checkbox"],
input[type="radio"],
input[type="color"],
.file-button {
  cursor: pointer;
}

button {
  min-height: 36px;
  padding: 0 12px;
  background: #fff;
  color: var(--text);
}

button:hover,
.file-button:hover {
  border-color: #8794a3;
}

button:focus-visible,
select:focus-visible,
input:focus-visible,
textarea:focus-visible,
.file-button:focus-within {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.app-shell {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.settings-panel {
  height: 100vh;
  height: 100dvh;
  overflow: auto;
  background: var(--panel);
  border-right: 1px solid var(--panel-line);
}

.app-header {
  padding: 20px 20px 16px;
  background: #ffffff;
  border-bottom: 1px solid var(--panel-line);
}

.app-header h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.2;
}

.app-header p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.panel-section {
  padding: 16px 20px 18px;
  border-bottom: 1px solid var(--panel-line);
}

.section-title {
  margin-bottom: 12px;
  font-size: 14px;
  font-weight: 700;
  color: #2a3036;
}

.field {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
  font-size: 13px;
  color: var(--muted);
}

.field input:not([type="color"]),
.field select {
  width: 100%;
  min-height: 36px;
  padding: 0 9px;
  background: var(--control-bg);
  color: var(--text);
}

.field input[type="number"] {
  appearance: textfield;
}

.field input[type="color"] {
  width: 100%;
  height: 36px;
  padding: 4px;
  background: var(--control-bg);
}

.field.compact {
  margin-bottom: 0;
}

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

.grid-three {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  margin-bottom: 12px;
  padding: 3px;
  border: 1px solid #c8d0d8;
  border-radius: 7px;
  background: #e9edf1;
}

.segmented label {
  display: block;
}

.segmented input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented span {
  display: grid;
  min-height: 30px;
  place-items: center;
  border-radius: 5px;
  font-size: 13px;
  color: #46505b;
}

.segmented input:checked + span {
  background: #ffffff;
  color: var(--text);
  box-shadow: 0 1px 3px rgb(23 25 28 / 0.12);
}

.toggle-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  color: #39424d;
  font-size: 13px;
}

.toggle-row label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.frame-style-field {
  margin-top: 12px;
  margin-bottom: 0;
}

.names-section textarea {
  width: 100%;
  min-height: 160px;
  padding: 10px;
  resize: vertical;
  line-height: 1.5;
  background: #fff;
  color: var(--text);
}

.names-tools {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  margin-top: 10px;
}

.file-button {
  display: grid;
  min-height: 36px;
  place-items: center;
  border: 1px solid #c8d0d8;
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  font-size: 13px;
}

.file-button input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
  pointer-events: none;
}

.actions-section {
  display: grid;
  grid-template-columns: 1fr;
  gap: 9px;
  position: sticky;
  bottom: 0;
  background: var(--panel);
}

.primary-action {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 700;
}

.primary-action:hover {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
}

.workspace {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-width: 0;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.workspace-bar {
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 52px;
  padding: 10px 24px;
  border-bottom: 1px solid #c7d0d8;
  background: rgb(248 250 251 / 0.94);
  backdrop-filter: blur(8px);
}

.workspace-bar strong {
  font-size: 14px;
}

#warningText {
  display: block;
  margin-top: 3px;
  color: var(--danger);
  font-size: 12px;
}

.view-mode-field {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
  color: #53606c;
  font-size: 13px;
}

.view-mode-field select {
  min-height: 32px;
  padding: 0 8px;
  background: #fff;
  color: var(--text);
}

.preview {
  display: flex;
  min-width: 0;
  min-height: 0;
  overflow: auto;
  align-items: center;
  flex-direction: column;
  gap: 22px;
  padding: 24px;
  background: var(--preview-bg);
  overscroll-behavior: contain;
}

.preview.view-spread,
.preview.view-overview {
  display: grid;
  align-content: start;
  align-items: start;
}

.preview.view-spread {
  grid-template-columns: repeat(2, max-content);
  justify-content: center;
}

.preview.view-overview {
  grid-template-columns: repeat(auto-fill, minmax(170px, max-content));
  justify-content: center;
  gap: 28px 36px;
}

.preview.view-overview .sheet-wrap {
  width: var(--overview-w);
  grid-template-rows: auto var(--overview-h);
  gap: 4px;
  overflow: visible;
}

.preview.view-overview .sheet-label {
  font-size: 11px;
}

.preview.view-overview .sheet-stage {
  position: relative;
  width: var(--overview-w);
  height: var(--overview-h);
}

.preview.view-overview .sheet {
  position: absolute;
  left: 0;
  top: 0;
  transform: scale(var(--overview-scale));
  transform-origin: top left;
}

.sheet-wrap {
  display: grid;
  gap: 8px;
  justify-items: start;
}

.sheet-label {
  padding-left: 2px;
  color: #53606c;
  font-size: 12px;
}

.sheet-stage {
  width: calc(var(--paper-w) * 1mm);
  height: calc(var(--paper-h) * 1mm);
}

.sheet {
  position: relative;
  width: calc(var(--paper-w) * 1mm);
  height: calc(var(--paper-h) * 1mm);
  overflow: hidden;
  background: #fff;
  box-shadow: 0 12px 36px rgb(23 25 28 / 0.22);
}

.card {
  position: absolute;
  overflow: visible;
  background: var(--card-bg);
}

.product-frame {
  position: absolute;
  inset: 0;
  border: 0.25mm var(--frame-style) var(--frame-color);
  pointer-events: none;
}

.dimension-label {
  position: absolute;
  z-index: 6;
  padding: 0.4mm 1mm;
  border-radius: 2px;
  background: #fff;
  color: var(--frame-color);
  font-family: Arial, sans-serif;
  font-size: 3mm;
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
  pointer-events: none;
}

.dimension-label.width {
  left: 50%;
  top: -4.5mm;
  transform: translateX(-50%);
}

.dimension-label.height {
  top: 50%;
  right: -4.5mm;
  transform: translate(50%, -50%) rotate(90deg);
  transform-origin: center;
}

.fold-line {
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  border-top: 0.25mm dashed var(--frame-color);
  opacity: 0.65;
}

.name-panel {
  position: absolute;
  left: 0;
  width: 100%;
  height: var(--face-h);
  display: grid;
  place-items: center;
  padding: 4mm;
  color: var(--text-color);
  text-align: center;
  line-height: 1.05;
  word-break: keep-all;
}

.name-panel.single {
  top: 0;
  height: 100%;
}

.name-panel.top {
  top: 0;
  transform: rotate(180deg);
}

.name-panel.bottom {
  bottom: 0;
}

.name-text {
  max-width: 100%;
  font-size: var(--font-size);
  font-family: var(--font-family);
  font-weight: var(--font-weight);
  white-space: nowrap;
}

.name-text.vertical {
  writing-mode: vertical-rl;
  text-orientation: upright;
  line-height: 1.1;
  white-space: normal;
}

.crop-guide {
  position: absolute;
  display: block;
  background: transparent;
  pointer-events: none;
  z-index: 5;
}

.crop-guide.h {
  height: 0.12mm;
  background: repeating-linear-gradient(
    to right,
    var(--frame-color) 0,
    var(--frame-color) 6mm,
    transparent 6mm,
    transparent 9mm
  );
  transform: translateY(-50%);
}

.crop-guide.v {
  width: 0.12mm;
  background: repeating-linear-gradient(
    to bottom,
    var(--frame-color) 0,
    var(--frame-color) 6mm,
    transparent 6mm,
    transparent 9mm
  );
  transform: translateX(-50%);
}

@media (max-width: 980px) {
  html,
  body {
    height: auto;
    overflow: auto;
  }

  .app-shell {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }

  .settings-panel,
  .workspace {
    height: auto;
    overflow: visible;
  }

  .workspace {
    display: block;
    min-height: 70vh;
  }

  .workspace-bar {
    align-items: flex-start;
    flex-direction: column;
  }

  .preview {
    overflow: auto;
  }

  .preview.view-spread,
  .preview.view-overview {
    display: flex;
    align-items: center;
  }

  .preview.view-overview .sheet-wrap {
    width: var(--overview-w);
  }

  .preview.view-overview .sheet-stage {
    width: var(--overview-w);
    height: var(--overview-h);
  }
}

@media (max-width: 600px) {
  .app-header,
  .panel-section {
    padding-left: 14px;
    padding-right: 14px;
  }

  .app-header h1 {
    font-size: 19px;
  }

  .grid-three {
    grid-template-columns: 1fr;
  }

  .workspace-bar {
    gap: 10px;
    padding: 12px;
  }

  .workspace-bar button,
  .actions-section button,
  .file-button {
    min-height: 44px;
  }

  .field input:not([type="color"]),
  .field select,
  textarea {
    font-size: 16px;
  }

  .preview {
    padding: 12px;
  }
}

@media print {
  html,
  body {
    width: auto;
    height: auto;
    overflow: visible;
    background: #fff;
  }

  .settings-panel,
  .workspace-bar,
  .sheet-label {
    display: none !important;
  }

  .app-shell,
  .workspace,
  .preview {
    display: block;
    width: auto;
    height: auto;
    overflow: visible;
    padding: 0;
    background: #fff;
  }

  .preview.view-spread,
  .preview.view-overview {
    display: block;
  }

  .preview.view-overview .sheet-wrap {
    width: auto;
    grid-template-rows: none;
  }

  .preview.view-overview .sheet-stage {
    width: auto;
    height: auto;
  }

  .preview.view-overview .sheet {
    position: relative;
    transform: none;
  }

  .sheet-wrap {
    display: block;
    page-break-after: always;
    break-after: page;
  }

  .sheet-wrap:last-child {
    page-break-after: auto;
    break-after: auto;
  }

  .sheet {
    margin: 0;
    box-shadow: none;
    page-break-after: auto;
    break-after: auto;
  }
}
