.dynamic-template-builder-page {
  min-width: 0;
  padding-bottom: 24px;
}

.dynamic-template-builder-page .dynamic-product-builder {
  display: grid;
  gap: 16px;
  min-width: 0;
  max-height: none;
  padding: 20px;
  overflow: visible;
  border: 1px solid #d7e2df;
  border-radius: 20px;
  background: #fff;
  box-shadow: 0 18px 44px rgba(20, 61, 67, .08);
}

.dynamic-template-builder-page .modal-head {
  position: static;
  z-index: 8;
  margin: -20px -20px 0;
  padding: 17px 20px;
  border-bottom: 1px solid #dce6e3;
  border-radius: 20px 20px 0 0;
  background: #fff;
}

.dynamic-template-builder-page .dynamic-builder-grid {
  min-width: 0;
  grid-template-columns: minmax(0, 1fr) 340px;
  align-items: start;
}

.dynamic-template-builder-page .dynamic-builder-fields,
.dynamic-template-builder-page .dynamic-builder-step {
  min-width: 0;
}

.dynamic-product-builder.is-custom-mode .dynamic-builder-grid {
  grid-template-columns: minmax(0, 1fr);
}

.dynamic-product-builder.is-custom-mode .dynamic-builder-preview {
  display: none;
}

.dynamic-auto-manual-bridge {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 13px 14px;
  border: 1px solid #b9d8d2;
  border-radius: 12px;
  background: linear-gradient(135deg, #f3faf8, #e8f4f1);
}

.dynamic-auto-manual-bridge > div {
  display: grid;
  gap: 3px;
}

.dynamic-auto-manual-bridge strong {
  color: #173f46;
  font-size: 13px;
}

.dynamic-auto-manual-bridge small {
  color: #557276;
  line-height: 1.4;
}

.dynamic-auto-manual-bridge .primary-btn {
  flex: 0 0 auto;
  white-space: nowrap;
}

.dynamic-template-background-art,
.dynamic-template-fixed-art {
  position: absolute;
  display: block;
  pointer-events: none;
}

.dynamic-template-background-art {
  inset: 0;
  z-index: 0;
  background-image: var(--art-image);
  background-position: var(--art-position-x, 50%) var(--art-position-y, 50%);
  background-repeat: no-repeat;
  background-size: var(--art-fit, cover);
  opacity: var(--art-opacity, 1);
  filter: var(--art-filter, none);
}

.dynamic-template-fixed-art {
  left: var(--art-x, 0);
  top: var(--art-y, 0);
  z-index: 1;
  width: var(--art-w, 20%);
  height: var(--art-h, 20%);
  transform: rotate(var(--art-rotation, 0deg));
  background-image: var(--art-image);
  background-position: center;
  background-repeat: no-repeat;
  background-size: var(--art-fit, contain);
  opacity: var(--art-opacity, 1);
  filter: var(--art-filter, none);
}

.dynamic-template-canvas > .dynamic-template-slot,
.dynamic-template-canvas > .dynamic-template-label-zone {
  z-index: 2;
}

.custom-template-builder {
  margin-top: 14px;
  border: 1px solid #cfdedb;
  border-radius: 16px;
  overflow: hidden;
  background: #eef4f2;
}

.custom-template-builder[hidden] {
  display: none !important;
}

.template-editor-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 10px;
  border-bottom: 1px solid #cad9d6;
  background: #f9fbfa;
}

.template-editor-toolbar-group,
.template-layer-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.template-editor-toolbar button,
.template-layer-actions button,
.template-placeholder-library button {
  min-height: 34px;
  padding: 6px 10px;
  border: 1px solid #c9d8d5;
  border-radius: 9px;
  background: #fff;
  color: #123f46;
  font: inherit;
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
}

.template-editor-toolbar button:hover,
.template-layer-actions button:hover,
.template-placeholder-library button:hover {
  border-color: #2f8f83;
  background: #e7f4f1;
}

.template-editor-toolbar button.is-danger {
  color: #a23b3b;
}

.template-editor-toolbar label {
  display: flex;
  align-items: center;
  gap: 7px;
  color: #365b60;
  font-size: 12px;
  font-weight: 800;
}

.template-editor-toolbar select {
  min-height: 34px;
  border: 1px solid #c9d8d5;
  border-radius: 9px;
  background: #fff;
}

.template-editor-shell {
  display: grid;
  grid-template-columns: 250px minmax(420px, 1fr) 270px;
  min-height: 650px;
}

.template-editor-panel {
  min-width: 0;
  padding: 14px;
  background: #f8fbfa;
}

.template-editor-setup {
  border-right: 1px solid #cad9d6;
}

.template-editor-properties {
  border-left: 1px solid #cad9d6;
}

.template-editor-panel-head {
  display: grid;
  gap: 2px;
  margin-bottom: 12px;
}

.template-editor-panel-head strong {
  color: #123f46;
  font-size: 14px;
}

.template-editor-panel-head small {
  color: #60777a;
  font-size: 11px;
}

.template-layer-head {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid #d7e2df;
}

.template-editor-properties label,
.template-editor-setup label,
.template-editor-duplex label,
.template-editor-field-grid label {
  display: grid;
  gap: 5px;
  margin-bottom: 9px;
  color: #31575c;
  font-size: 11px;
  font-weight: 800;
}

.template-editor-properties input,
.template-editor-properties select,
.template-editor-properties textarea,
.template-editor-setup input,
.template-editor-setup select,
.template-editor-field-grid input {
  width: 100%;
  min-height: 36px;
  padding: 7px 8px;
  border: 1px solid #c9d8d5;
  border-radius: 8px;
  background: #fff;
  color: #123f46;
  font: inherit;
}

.template-editor-properties input[type="color"] {
  padding: 3px;
}

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

.template-editor-check {
  display: flex !important;
  align-items: center;
  gap: 7px;
  min-height: 34px;
  margin: 3px 0 !important;
}

.template-editor-check input {
  width: 17px !important;
  min-height: 17px !important;
}

.template-background-upload,
.template-object-asset > div {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.template-background-upload button,
.template-object-asset button {
  min-height: 32px;
  padding: 6px 9px;
  border: 1px solid #c9d8d5;
  border-radius: 8px;
  background: #fff;
  color: #123f46;
  font: inherit;
  font-size: 10px;
  font-weight: 800;
  cursor: pointer;
}

.template-background-upload button:hover,
.template-object-asset button:hover {
  border-color: #2f8f83;
  background: #e7f4f1;
}

.template-background-upload button.is-danger,
.template-object-asset button.is-danger {
  color: #a23b3b;
}

.template-background-upload small,
.template-object-asset small {
  flex-basis: 100%;
  overflow: hidden;
  color: #637a7d;
  font-size: 10px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.template-editor-duplex {
  margin-top: 12px;
  padding: 9px;
  border: 1px solid #d5e1df;
  border-radius: 10px;
  background: #fff;
}

.template-editor-duplex summary {
  color: #214e53;
  font-size: 11px;
  font-weight: 900;
  cursor: pointer;
}

.template-editor-duplex[open] summary {
  margin-bottom: 9px;
}

.template-object-asset {
  display: grid;
  gap: 7px;
  margin: 10px 0;
  padding: 10px;
  border: 1px solid #cfe0dc;
  border-radius: 10px;
  background: #f1f8f6;
}

.template-object-asset > strong {
  color: #214e53;
  font-size: 11px;
}

.template-object-asset p {
  margin: 0;
  color: #637a7d;
  font-size: 9px;
  line-height: 1.35;
}

.template-layer-list {
  display: grid;
  gap: 5px;
  max-height: 300px;
  margin-bottom: 9px;
  overflow: auto;
}

.template-layer-row {
  display: grid;
  grid-template-columns: 26px minmax(0, 1fr) 24px;
  align-items: center;
  gap: 6px;
  min-height: 39px;
  padding: 4px 6px;
  border: 1px solid #d3dfdc;
  border-radius: 9px;
  background: #fff;
  cursor: pointer;
}

.template-layer-row.is-selected {
  border-color: #2f8f83;
  box-shadow: 0 0 0 2px rgba(47, 143, 131, .13);
}

.template-layer-row.is-hidden {
  opacity: .48;
}

.template-layer-icon {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 7px;
  background: #e6f1ef;
  color: #1c6964;
  font-size: 10px;
  font-weight: 900;
}

.template-layer-copy {
  min-width: 0;
}

.template-layer-copy strong,
.template-layer-copy small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.template-layer-copy strong {
  color: #173f45;
  font-size: 11px;
}

.template-layer-copy small {
  color: #738689;
  font-size: 9px;
}

.template-editor-stage {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-width: 0;
  padding: 12px;
  overflow: hidden;
  background: linear-gradient(135deg, #dfe8e6 0%, #edf2f1 100%);
}

.template-editor-rulers {
  display: flex;
  justify-content: space-between;
  padding: 0 8px 7px;
  color: #6c8184;
  font-size: 9px;
  font-weight: 800;
}

.template-editor-canvas-wrap {
  display: grid;
  place-items: center;
  min-height: 550px;
  overflow: auto;
  padding: 20px;
}

.template-editor-canvas {
  position: relative;
  width: min(100%, 620px);
  aspect-ratio: 13 / 18;
  overflow: hidden;
  border: 1px solid #aebfbc;
  background-color: #fff;
  box-shadow: 0 18px 40px rgba(31, 61, 66, .18);
  transform: scale(var(--template-editor-zoom, 1));
  transform-origin: center;
  touch-action: none;
}

.template-canvas-background {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}

.template-canvas-background img {
  width: 100%;
  height: 100%;
  object-fit: var(--template-background-fit, cover);
  object-position: var(--template-background-position, 50% 50%);
  opacity: var(--template-background-opacity, 1);
  filter: var(--template-background-filter, none);
}

.template-production-safe-guide,
.template-production-fold-guide,
.template-production-bleed-guide {
  position: absolute;
  z-index: 90;
  pointer-events: none;
}

.template-production-safe-guide {
  border: 1px dashed rgba(35, 151, 117, .9);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, .55);
}

.template-production-fold-guide {
  border-color: rgba(222, 112, 31, .9);
  border-style: dashed;
}

.template-production-fold-guide.is-vertical {
  top: 0;
  bottom: 0;
  border-left-width: 1px;
}

.template-production-fold-guide.is-horizontal {
  right: 0;
  left: 0;
  border-top-width: 1px;
}

.template-production-bleed-guide {
  inset: 3px;
  border: 2px solid rgba(200, 57, 57, .68);
}

.template-editor-canvas.is-grid-visible {
  background-image:
    linear-gradient(to right, rgba(47, 143, 131, .13) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(47, 143, 131, .13) 1px, transparent 1px);
  background-size: var(--template-grid-x, 10%) var(--template-grid-y, 10%);
}

.template-canvas-object {
  position: absolute;
  display: grid;
  place-items: center;
  box-sizing: border-box;
  min-width: 6px;
  min-height: 6px;
  transform-origin: center;
  user-select: none;
  cursor: move;
  z-index: 1;
}

.template-canvas-object.is-selected {
  outline: 2px solid #ed8a2e;
  outline-offset: 2px;
}

.template-canvas-object.is-locked {
  cursor: not-allowed;
}

.template-canvas-object.is-photo {
  overflow: hidden;
  border: var(--object-border-width, 1px) solid var(--object-border, #2f8f83);
  background: repeating-linear-gradient(135deg, #d9ebe7 0 10px, #c9dfdb 10px 20px);
  color: #176a64;
}

.template-canvas-object.is-photo::before {
  content: "PHOTO";
  font-size: clamp(8px, 1.2vw, 14px);
  font-weight: 900;
  letter-spacing: .08em;
}

.template-object-pose {
  position: absolute;
  top: 5px;
  left: 5px;
  display: grid;
  place-items: center;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .9);
  color: #123f46;
  font-size: 10px;
  font-weight: 900;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .16);
}

.template-canvas-object.is-text {
  padding: 3px;
  color: var(--object-color, #123f46);
  font-family: var(--object-font-family, Arial), sans-serif;
  font-size: var(--object-font-size, 12px);
  font-weight: var(--object-font-weight, 400);
  text-align: var(--object-align, center);
  white-space: pre-wrap;
}

.template-canvas-object.is-shape {
  border: var(--object-border-width, 1px) solid var(--object-border, #2f8f83);
  background: var(--object-fill, #fff);
}

.template-canvas-object.is-area {
  border: 2px dashed #d27724;
  background: rgba(242, 153, 74, .14);
  color: #9d5614;
  font-size: 10px;
  font-weight: 900;
  text-transform: uppercase;
}

.template-canvas-object.is-fixed_image,
.template-canvas-object.is-logo {
  overflow: hidden;
  border: var(--object-border-width, 1px) solid var(--object-border, #2f8f83);
  background: repeating-linear-gradient(135deg, #edf2f1 0 10px, #dfe8e6 10px 20px);
  color: #315f63;
  font-size: 10px;
  font-weight: 900;
}

.template-canvas-object.is-logo {
  border-style: dashed;
}

.template-object-image {
  width: 100%;
  height: 100%;
  object-fit: var(--object-fit, cover);
  filter: var(--object-filter, none);
  pointer-events: none;
}

.template-canvas-object.is-pose_marker {
  border: var(--object-border-width, 1px) solid var(--object-border, #123f46);
  border-radius: 50% !important;
  background: var(--object-fill, #fff);
  color: var(--object-color, #123f46);
  font-size: clamp(8px, 1.1vw, 15px);
  font-weight: 900;
}

.template-canvas-object.is-calendar {
  display: grid;
  align-content: start;
  gap: 8px;
  padding: 10px;
  overflow: hidden;
  border: var(--object-border-width) solid var(--object-border);
  background: var(--object-fill);
  color: var(--object-color);
  font-family: var(--object-font-family);
  text-align: center;
}

.template-canvas-object.is-calendar strong {
  font-size: clamp(9px, 1.25vw, 16px);
}

.template-canvas-object.is-calendar > span {
  padding: 8px 4px;
  border-top: 1px solid var(--object-border);
  font-size: clamp(7px, .85vw, 11px);
  line-height: 1.8;
  word-spacing: .45em;
}

[data-template-calendar-field] {
  display: grid;
  gap: 8px;
  margin: 10px 0;
  padding: 10px;
  border: 1px solid #cfe0dc;
  border-radius: 10px;
  background: #f1f8f6;
}

[data-template-calendar-field] > small {
  color: #637a7d;
  font-size: 9px;
}

.template-object-resize {
  position: absolute;
  right: -6px;
  bottom: -6px;
  width: 12px;
  height: 12px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: #ed8a2e;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .2);
  cursor: nwse-resize;
}

.template-object-lock {
  position: absolute;
  top: 3px;
  right: 3px;
  padding: 2px 4px;
  border-radius: 5px;
  background: rgba(18, 63, 70, .84);
  color: #fff;
  font-size: 8px;
}

.template-editor-status {
  min-height: 31px;
  padding-top: 8px;
  color: #4f6d71;
  font-size: 11px;
  text-align: center;
}

.template-editor-empty {
  padding: 18px 10px;
  border: 1px dashed #c8d6d3;
  border-radius: 10px;
  color: #6c8083;
  font-size: 11px;
  text-align: center;
}

.template-placeholder-library {
  margin-top: 12px;
  padding-top: 11px;
  border-top: 1px solid #d8e3e0;
}

.template-placeholder-library > strong {
  display: block;
  margin-bottom: 7px;
  color: #31575c;
  font-size: 11px;
}

.template-placeholder-library > div {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}

.template-placeholder-library > small {
  display: block;
  margin-top: 8px;
  color: #657c80;
  font-size: 9px;
  line-height: 1.4;
}

.template-placeholder-library button {
  min-height: 27px;
  padding: 4px 6px;
  font-size: 9px;
}

.pouch-template-builder-page .dynamic-product-builder {
  gap: 20px;
}

.pouch-composition-step {
  padding: 16px;
  border: 1px solid #cdded9;
  border-radius: 16px;
  background: #f7faf9;
}

.pouch-side-tabs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 14px 0 10px;
}

.pouch-side-tabs button {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 1px 10px;
  align-items: center;
  min-height: 68px;
  padding: 10px 14px;
  border: 1px solid #c9d9d5;
  border-radius: 13px;
  background: #fff;
  color: #264e54;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.pouch-side-tabs button > span {
  grid-row: 1 / 3;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: #e8f1ef;
  font-size: 11px;
  font-weight: 900;
}

.pouch-side-tabs button strong {
  font-size: 14px;
}

.pouch-side-tabs button small {
  color: #697f82;
  font-size: 10px;
}

.pouch-side-tabs button.is-active {
  border-color: #207d73;
  background: #edf8f5;
  box-shadow: 0 0 0 2px rgba(32, 125, 115, .12);
}

.pouch-side-tabs button.is-active > span {
  background: #207d73;
  color: #fff;
}

.pouch-side-sync {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  padding: 9px 12px;
  border-radius: 10px;
  background: #e9f3f1;
  color: #365e62;
  font-size: 11px;
}

.pouch-side-sync strong {
  color: #174e4b;
}

[data-pouch-side-panel][hidden] {
    display: none !important;
}

[data-template-always-visible][hidden] {
    display: block !important;
}

.pouch-side-editor {
  margin-top: 0;
}

.pouch-pair-preview {
  display: flex;
  align-items: center;
  gap: 5px;
  width: 150px;
}

.pouch-pair-preview .dynamic-template-canvas {
  flex: 1 1 0;
  min-width: 0;
  overflow: hidden;
}

.pouch-pair-preview .dynamic-template-canvas > small {
  position: absolute;
  right: 3px;
  bottom: 3px;
  z-index: 4;
  padding: 2px 4px;
  border-radius: 4px;
  background: rgba(18, 63, 70, .82);
  color: #fff;
  font-size: 6px;
  font-weight: 900;
}

.pouch-product-table td {
  vertical-align: middle;
}

.dynamic-digital-formats {
  display: grid;
  gap: 8px;
  margin: 12px 0;
  padding: 12px 14px;
  border: 1px solid #cfe0dc;
  border-radius: 12px;
  background: #f2f8f6;
}

.dynamic-digital-formats[hidden] {
  display: none !important;
}

.dynamic-digital-formats > span {
  color: #214e53;
  font-size: 12px;
  font-weight: 900;
}

.dynamic-digital-formats ul {
  display: flex;
  gap: 8px 14px;
  flex-wrap: wrap;
  margin: 0;
  padding: 0;
  list-style: none;
}

.dynamic-digital-formats label {
  display: flex;
  align-items: center;
  gap: 6px;
  color: #365e62;
  font-size: 11px;
  font-weight: 800;
}

@media (max-width: 1320px) {
  .template-editor-shell {
    grid-template-columns: 220px minmax(350px, 1fr) 240px;
  }
}

@media (max-width: 1050px) {
  .dynamic-template-builder-page .dynamic-builder-grid {
    grid-template-columns: minmax(0, 1fr);
  }
  .dynamic-template-builder-page .dynamic-builder-preview {
    display: none;
  }
  .template-editor-shell {
    grid-template-columns: 190px minmax(360px, 1fr);
  }
  .template-editor-properties {
    grid-column: 1 / -1;
    border-top: 1px solid #cad9d6;
    border-left: 0;
  }
}

@media (max-width: 760px) {
  .dynamic-auto-manual-bridge {
    align-items: stretch;
    flex-direction: column;
  }
  .dynamic-template-builder-page .dynamic-product-builder {
    padding: 12px;
    border-radius: 14px;
  }
  .dynamic-template-builder-page .modal-head {
    margin: -12px -12px 0;
    border-radius: 14px 14px 0 0;
  }
  .template-editor-toolbar,
  .template-editor-shell {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
  }
  .template-editor-setup,
  .template-editor-properties {
    border: 0;
    border-bottom: 1px solid #cad9d6;
  }
  .template-editor-canvas-wrap {
    min-height: 430px;
    padding: 10px;
  }
}
