:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-soft: #eef3f7;
  --text: #20242a;
  --muted: #69717d;
  --line: #d9dee7;
  --primary: #1f6feb;
  --primary-dark: #174ea6;
  --teal: #0f9f8f;
  --danger: #c2410c;
  --shadow: 0 18px 42px rgba(27, 39, 61, 0.12);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
}

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

button {
  border: 0;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 18px 22px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-left {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  min-width: 0;
}

.topbar-warning {
  width: 100%;
  padding: 8px 12px;
  background: #ffd21e;
  color: #000;
  font-weight: 700;
  line-height: 1.25;
}

.topbar-warning p {
  margin: 0;
  font-size: 14px;
}

.brand-block h1,
.brand-block p,
.panel-header h2,
.panel-header p,
.preview-toolbar h2,
.preview-toolbar p {
  margin: 0;
}

.breadcrumb-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.back-link {
  color: var(--primary-dark);
  text-decoration: none;
}

.back-link:hover {
  text-decoration: underline;
}

.breadcrumb-sep {
  color: #9aa3af;
}

.brand-block h1 {
  font-size: 22px;
  line-height: 1.15;
}

.brand-block p,
.panel-header p,
.preview-toolbar p,
.field-label-row,
.rail-header,
.field-hint {
  color: var(--muted);
  font-size: 13px;
}

.global-form {
  display: grid;
  grid-template-columns: minmax(150px, 1fr) 96px minmax(130px, 0.8fr);
  gap: 12px;
}

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

[hidden] {
  display: none !important;
}

label span,
.field-label-row span:first-child {
  color: #3a414b;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
}

.required-star {
  color: var(--danger);
  font-style: normal;
}

.field-hint {
  margin: -2px 0 0;
  line-height: 1.35;
}

.fob-header span:first-child {
  font-size: 15px;
}

.major-field-label {
  font-size: 15px;
}

.fob-header .tiny-button {
  min-height: 34px;
  font-size: 13px;
  padding: 0 12px;
}

.warning-hint {
  color: var(--danger);
  font-size: 13px;
}

.spec-soft-hint {
  color: #7a4b12;
  font-size: 13px;
}

.spec-overflow-message {
  margin: 0;
  padding: 10px 12px;
  border-radius: 4px;
  background: #ef1d2d;
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.25;
}

input,
select,
textarea {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--text);
  padding: 9px 11px;
  outline: none;
}

textarea {
  resize: vertical;
  min-height: 132px;
  line-height: 1.45;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(31, 111, 235, 0.14);
}

.invalid-field {
  border-color: var(--danger) !important;
  box-shadow: 0 0 0 3px rgba(194, 65, 12, 0.12) !important;
}

.topbar-actions {
  display: flex;
  gap: 10px;
  position: fixed;
  left: 10px;
  bottom: 10px;
  z-index: 30;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 10px 28px rgba(27, 39, 61, 0.18);
}

.primary-button,
.secondary-button,
.danger-button,
.tiny-button,
.icon-text-button {
  min-height: 40px;
  border-radius: var(--radius);
  padding: 0 14px;
  font-weight: 700;
  white-space: nowrap;
}

.primary-button {
  background: var(--primary);
  color: #fff;
}

.primary-button:hover {
  background: var(--primary-dark);
}

.secondary-button {
  background: #e7eefb;
  color: var(--primary-dark);
}

.danger-button,
.icon-text-button {
  background: #fff1eb;
  color: var(--danger);
}

.tiny-button {
  min-height: 30px;
  padding: 0 10px;
  background: #e7eefb;
  color: var(--primary-dark);
  font-size: 12px;
}

.workspace {
  display: grid;
  grid-template-columns: 156px minmax(330px, 440px) minmax(560px, 1fr);
  gap: 18px;
  padding: 18px 22px 24px;
  flex: 1;
}

.page-rail,
.editor-panel,
.preview-panel {
  min-width: 0;
}

.page-rail {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  height: fit-content;
}

.rail-header,
.field-label-row,
.panel-header,
.preview-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.rail-header {
  padding: 0 4px 10px;
  border-bottom: 1px solid var(--line);
}

.page-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 10px;
}

.page-tab {
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--text);
  text-align: left;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.page-tab strong {
  font-size: 13px;
}

.page-tab span {
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.page-tab em {
  color: var(--muted);
  font-size: 11px;
  font-style: normal;
  font-weight: 700;
}

.page-tab.active {
  border-color: var(--primary);
  background: #edf4ff;
}

.page-tab.invalid {
  border-color: rgba(194, 65, 12, 0.55);
  background: #fff4f0;
}

.page-tab.invalid em {
  color: var(--danger);
}

.page-tab.invalid.active {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px rgba(194, 65, 12, 0.12);
}

.editor-panel,
.preview-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.editor-panel {
  padding: 18px;
  height: fit-content;
}

.panel-header,
.preview-toolbar {
  margin-bottom: 16px;
}

.panel-header h2,
.preview-toolbar h2 {
  font-size: 18px;
}

.page-form,
#productFields {
  gap: 14px;
}

.two-col,
.three-col,
.fob-row {
  display: grid;
  gap: 12px;
}

.clone-tools-row {
  display: grid;
  grid-template-columns: minmax(220px, 1.5fr) minmax(96px, auto);
  gap: 12px;
  align-items: end;
}

.two-col {
  grid-template-columns: 1fr 1fr;
}

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

.carton-row {
  grid-template-columns: 1.7fr 1fr;
}

.packing-group {
  gap: 16px;
  padding: 16px;
  border: 1px solid #d9dee7;
  border-radius: var(--radius);
  background: #fbfcfe;
}

.packing-group .field-label-row span:first-child {
  font-size: 17px;
  font-weight: 800;
}

.packing-group .three-col,
.packing-group .two-col {
  gap: 14px;
}

.clone-tools {
  gap: 12px;
  padding: 14px 16px;
  border: 1px solid #e0e6ef;
  border-radius: var(--radius);
  background: #fbfcfe;
}

.clone-tools-inline {
  margin: 0;
  padding: 10px 0 4px;
  border: 0;
  border-radius: 0;
  background: transparent;
}

.clone-tools .secondary-button {
  min-width: 96px;
}

.fob-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.fob-row {
  grid-template-columns: minmax(96px, 0.85fr) minmax(150px, 1.15fr) auto;
  align-items: end;
  padding: 10px;
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.single-fob-note {
  font-size: 12px;
  padding-left: 8px;
  padding-right: 8px;
}

.layout-picker {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.layout-option {
  min-width: 0;
  min-height: 68px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--text);
}

.layout-option.active {
  border-color: var(--primary);
  background: #edf4ff;
  box-shadow: 0 0 0 3px rgba(31, 111, 235, 0.11);
}

.layout-option strong {
  font-size: 12px;
}

.layout-mini {
  width: 42px;
  height: 28px;
  display: grid;
  gap: 3px;
}

.layout-mini::before,
.layout-mini::after,
.layout-mini span {
  content: "";
}

.layout-mini,
.layout-mini::before,
.layout-mini::after {
  border-radius: 3px;
}

.layout-mini::before,
.layout-mini::after {
  background: #9db8df;
  min-width: 0;
  min-height: 0;
}

.mini-single {
  background: #9db8df;
}

.mini-single::before,
.mini-single::after {
  display: none;
}

.mini-two-horizontal {
  grid-template-columns: 1fr 1fr;
}

.mini-two-vertical {
  grid-template-rows: 1fr 1fr;
}

.mini-three-hero-left {
  background:
    linear-gradient(#9db8df 0 0) 0 0 / calc(58% - 2px) 100%,
    linear-gradient(#9db8df 0 0) 100% 0 / calc(42% - 2px) calc(50% - 1.5px),
    linear-gradient(#9db8df 0 0) 100% 100% / calc(42% - 2px) calc(50% - 1.5px);
  background-repeat: no-repeat;
}

.mini-three-hero-left::before,
.mini-three-hero-left::after {
  display: none;
}

.mini-three-hero-top {
  background:
    linear-gradient(#9db8df 0 0) 0 0 / 100% calc(58% - 2px),
    linear-gradient(#9db8df 0 0) 0 100% / calc(50% - 1.5px) calc(42% - 2px),
    linear-gradient(#9db8df 0 0) 100% 100% / calc(50% - 1.5px) calc(42% - 2px);
  background-repeat: no-repeat;
}

.mini-three-hero-top::before,
.mini-three-hero-top::after {
  display: none;
}

.mini-four-grid {
  background:
    linear-gradient(#9db8df 0 0) 0 0 / calc(50% - 1.5px) calc(50% - 1.5px),
    linear-gradient(#9db8df 0 0) 100% 0 / calc(50% - 1.5px) calc(50% - 1.5px),
    linear-gradient(#9db8df 0 0) 0 100% / calc(50% - 1.5px) calc(50% - 1.5px),
    linear-gradient(#9db8df 0 0) 100% 100% / calc(50% - 1.5px) calc(50% - 1.5px);
  background-repeat: no-repeat;
}

.mini-four-grid::before,
.mini-four-grid::after {
  display: none;
}

.mini-five-hero-left {
  background:
    linear-gradient(#9db8df 0 0) 0 0 / calc(45% - 2px) 100%,
    linear-gradient(#9db8df 0 0) 58% 0 / calc(27% - 2px) calc(50% - 1.5px),
    linear-gradient(#9db8df 0 0) 100% 0 / calc(27% - 2px) calc(50% - 1.5px),
    linear-gradient(#9db8df 0 0) 58% 100% / calc(27% - 2px) calc(50% - 1.5px),
    linear-gradient(#9db8df 0 0) 100% 100% / calc(27% - 2px) calc(50% - 1.5px);
  background-repeat: no-repeat;
}

.mini-five-hero-left::before,
.mini-five-hero-left::after {
  display: none;
}

.mini-six-grid {
  background:
    linear-gradient(#9db8df 0 0) 0 0 / calc(33.33% - 2px) calc(50% - 1.5px),
    linear-gradient(#9db8df 0 0) 50% 0 / calc(33.33% - 2px) calc(50% - 1.5px),
    linear-gradient(#9db8df 0 0) 100% 0 / calc(33.33% - 2px) calc(50% - 1.5px),
    linear-gradient(#9db8df 0 0) 0 100% / calc(33.33% - 2px) calc(50% - 1.5px),
    linear-gradient(#9db8df 0 0) 50% 100% / calc(33.33% - 2px) calc(50% - 1.5px),
    linear-gradient(#9db8df 0 0) 100% 100% / calc(33.33% - 2px) calc(50% - 1.5px);
  background-repeat: no-repeat;
}

.mini-six-grid::before,
.mini-six-grid::after {
  display: none;
}

.upload-box {
  width: min(260px, 100%);
  min-height: 74px;
  justify-content: center;
  align-items: center;
  border: 1px dashed #aeb7c5;
  border-radius: var(--radius);
  background: var(--surface-soft);
  color: var(--primary-dark);
  font-weight: 700;
  transition: border-color 160ms ease, background 160ms ease;
}

.upload-box input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.image-chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 96px;
  padding: 10px;
  border: 1px dashed #d9dee7;
  border-radius: var(--radius);
  background: #fff;
  align-content: flex-start;
}

.image-chip {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) 26px;
  align-items: center;
  gap: 7px;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 5px;
  background: #fff;
  cursor: grab;
}

.image-chip.dragging {
  opacity: 0.55;
  border-color: var(--primary);
  cursor: grabbing;
}

.image-chip img {
  width: 28px;
  height: 28px;
  object-fit: cover;
  border-radius: 5px;
}

.image-chip span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
}

.image-chip button {
  width: 24px;
  height: 24px;
  border-radius: 5px;
  background: #fff1eb;
  color: var(--danger);
  font-weight: 700;
}

.preview-panel {
  padding: 18px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 144px;
  max-height: calc(100vh - 162px);
  overflow: hidden;
}

.status-pill {
  min-width: 74px;
  border-radius: 999px;
  padding: 6px 10px;
  background: #fff7db;
  color: #815b00;
  text-align: center;
  font-size: 12px;
  font-weight: 700;
}

.status-pill.ready {
  background: #dff8f3;
  color: #087266;
}

.validation-message {
  min-height: 18px;
  margin: -8px 0 12px;
  color: var(--danger);
  font-size: 13px;
  font-weight: 700;
}

.slide-frame {
  flex: 1;
  min-height: 520px;
  display: grid;
  place-items: center;
  overflow: auto;
  padding: 18px;
  background:
    linear-gradient(90deg, rgba(217, 222, 231, 0.65) 1px, transparent 1px),
    linear-gradient(rgba(217, 222, 231, 0.65) 1px, transparent 1px);
  background-size: 24px 24px;
  border-radius: var(--radius);
}

.slide {
  width: 960px;
  height: 540px;
  flex: 0 0 auto;
  background: #fff;
  border: 1px solid #cdd3dc;
  box-shadow: 0 12px 28px rgba(27, 39, 61, 0.16);
  position: relative;
  overflow: hidden;
  font-family: Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
  color: #000;
}

.slide h2,
.slide h3,
.slide p,
.slide pre {
  margin: 0;
}

.category-slide {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 4.2% 3.55%;
  overflow: hidden;
}

.category-slide::before,
.category-slide::after {
  content: "";
  position: absolute;
  left: -2%;
  right: -1%;
  z-index: 0;
}

.category-slide::before {
  top: 36%;
  height: 19%;
  background:
    linear-gradient(135deg, transparent 0 10%, rgba(255, 255, 255, 0.82) 10% 28%, transparent 28%) left bottom / 55% 36% no-repeat,
    linear-gradient(135deg, transparent 0 62%, rgba(210, 151, 35, 0.36) 62% 72%, transparent 72%) right top / 46% 80% no-repeat,
    linear-gradient(90deg, #f8d45c, #e4ae3a);
}

.category-slide::after {
  top: 31%;
  height: 10%;
  background:
    linear-gradient(135deg, transparent 0 68%, #e9b447 68%) right center / 44% 100% no-repeat,
    linear-gradient(90deg, rgba(255, 255, 255, 0.94), rgba(255, 255, 255, 0.94));
}

.category-slide h2 {
  position: relative;
  z-index: 1;
  max-width: 86%;
  font-size: 48px;
  line-height: 1.08;
  font-weight: 700;
  text-align: center;
  word-break: break-word;
  color: #fff;
  text-shadow: 0 1px 0 rgba(120, 85, 18, 0.08);
}

.product-slide {
  position: absolute;
  inset: 0;
}

.preview-heading {
  position: absolute;
  left: calc(1.2 / 33.867 * 100%);
  top: calc(0.5 / 19.05 * 100%);
  width: calc(15.3 / 33.867 * 100%);
  line-height: 1.05;
}

.preview-heading h3 {
  font-size: 24px;
  line-height: 1.05;
  font-weight: 700;
}

.preview-heading p {
  margin-top: 2px;
  font-size: 20px;
  line-height: 1.05;
  font-weight: 700;
}

.product-image-grid {
  position: absolute;
  left: calc(1.2 / 33.867 * 100%);
  top: calc(2.55 / 19.05 * 100%);
  width: calc(15.3 / 33.867 * 100%);
  height: calc(11.5 / 19.05 * 100%);
  display: grid;
  gap: 8px;
  background: #fff;
}

.product-image-grid.empty {
  place-items: center;
  border: 1px dashed #c6ced9;
  color: #9aa3af;
  font-weight: 700;
}

.product-image-grid img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: top center;
  min-width: 0;
  min-height: 0;
  background: #fff;
}

.product-image-grid.layout-single {
  grid-template-columns: 1fr;
}

.product-image-grid.layout-two-vertical {
  grid-template-rows: 1fr 1fr;
}

.product-image-grid.layout-two-horizontal {
  grid-template-columns: 1fr 1fr;
}

.product-image-grid.layout-three-hero-left {
  grid-template-columns: 1.35fr 1fr;
  grid-template-rows: 1fr 1fr;
}

.product-image-grid.layout-three-hero-left img:first-child {
  grid-row: 1 / span 2;
}

.product-image-grid.layout-three-hero-top {
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1.15fr 1fr;
}

.product-image-grid.layout-three-hero-top img:first-child {
  grid-column: 1 / span 2;
}

.product-image-grid.layout-four-grid {
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
}

.product-image-grid.layout-five-hero-left {
  grid-template-columns: 1.25fr 1fr 1fr;
  grid-template-rows: 1fr 1fr;
}

.product-image-grid.layout-five-hero-left img:first-child {
  grid-row: 1 / span 2;
}

.product-image-grid.layout-six-grid {
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: 1fr 1fr;
}

.price-block {
  position: absolute;
  left: calc(1.55 / 33.867 * 100%);
  top: calc(14.42 / 19.05 * 100%);
  width: calc(15.6 / 33.867 * 100%);
  font-size: 18px;
  font-weight: 400;
  line-height: 1;
}

.price-block p {
  min-height: 1em;
}

#previewMoq,
#previewFobs strong {
  font-weight: 700;
}

#previewNote {
  margin-top: 25px;
  font-size: 12px;
  line-height: 1;
  font-weight: 400;
}

.spec-block {
  position: absolute;
  left: calc(17.5 / 33.867 * 100%);
  top: calc(1.55 / 19.05 * 100%);
  width: calc(15 / 33.867 * 100%);
  height: calc(12.55 / 19.05 * 100%);
  overflow: hidden;
}

.spec-block h3 {
  font-size: 18px;
  line-height: 1;
  font-weight: 700;
  margin-bottom: 0;
}

.spec-block ul {
  position: absolute;
  top: calc(1 / 12.55 * 100%);
  right: 0;
  bottom: 0;
  left: 0;
  margin: 0;
  padding: 0 0 0 1.05em;
  overflow: hidden;
  font-family: Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 18px;
  line-height: 1;
}

.spec-block li {
  margin: 0;
  padding: 0;
  overflow-wrap: anywhere;
}

.spec-block li.spec-group-start {
  margin-top: 1em;
}

.packing-block {
  position: absolute;
  left: calc(17.5 / 33.867 * 100%);
  top: calc(14.52 / 19.05 * 100%);
  width: calc(15 / 33.867 * 100%);
  font-size: 18px;
  line-height: 1.18;
}

.packing-block p {
  min-height: 1.18em;
  white-space: nowrap;
}

.underline-value,
.line-value,
.short-line-value {
  display: inline-block;
  min-width: 5ch;
  border-bottom: 1.5px solid #000;
  text-align: center;
  line-height: 0.9;
}

.line-value {
  min-width: 16ch;
}

.short-line-value {
  min-width: 5ch;
}

.weight-gap {
  display: inline-block;
  width: 4.8ch;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: 360px;
  padding: 11px 13px;
  border-radius: var(--radius);
  background: #20242a;
  color: #fff;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 1120px) {
  .topbar {
    align-items: stretch;
  }

  .topbar-left {
    align-items: start;
    justify-content: space-between;
  }

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

  .workspace {
    grid-template-columns: 130px minmax(300px, 400px) minmax(460px, 1fr);
  }
}

@media (max-width: 900px) {
  .topbar,
  .workspace {
    padding-left: 12px;
    padding-right: 12px;
  }

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

  .page-rail {
    order: 2;
  }

  .editor-panel {
    order: 1;
  }

  .preview-panel {
    order: 3;
    position: static;
    max-height: none;
    overflow: visible;
  }

  .page-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  }

  .slide-frame {
    min-height: 360px;
    padding: 10px;
  }
}

@media (max-width: 620px) {
  .global-form,
  .two-col,
  .three-col,
  .layout-picker,
  .fob-row,
  .carton-row {
    grid-template-columns: 1fr;
  }

  .panel-header,
  .preview-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .panel-header .danger-button,
  .danger-button {
    width: 100%;
  }
}
