body.csp-template-modal-open {
  overflow: hidden;
}

body.single-product .csp-field.csp-type-template {
  clear: both;
}

body.single-product .csp-field.csp-type-template > label {
  display: none;
}

body.single-product .csp-template-open {
  min-height: 42px;
  padding: 10px 16px;
  border-radius: 6px;
  font-weight: 700;
}

.csp-template-modal[hidden] {
  display: none !important;
}

.csp-template-modal {
  position: fixed;
  inset: 0;
  z-index: 999999;
  display: flex;
  align-items: stretch;
  justify-content: center;
  width: 100vw;
  height: 100vh;
  padding: 0;
}

.csp-template-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(10, 15, 25, 0.72);
}

.csp-template-dialog {
  position: relative;
  z-index: 1;
  width: 100vw;
  height: 100vh;
  max-width: none;
  max-height: none;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
  background: #fff;
  border-radius: 0;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.35);
}

.csp-template-topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto 42px;
  align-items: center;
  gap: 16px;
  padding: 16px 18px;
  border-bottom: 1px solid #e2e5ea;
  background: #fff;
}

.csp-template-brand {
  margin-bottom: 3px;
  color: #64748b;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.csp-template-topbar h3 {
  margin: 0;
  color: #111827;
  font-size: 20px;
  line-height: 1.2;
}

.csp-template-current-size {
  max-width: 320px;
  color: #334155;
  font-size: 14px;
  font-weight: 700;
  text-align: right;
}

.csp-template-close {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #d7dce3;
  border-radius: 6px;
  background: #fff;
  color: #0f172a;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}

.csp-template-body {
  min-height: 0;
  height: 100%;
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  background: #f6f8fb;
}

.csp-template-sidebar {
  min-height: 0;
  overflow: auto;
  padding: 16px;
  border-right: 1px solid #e2e5ea;
  background: #fff;
}

.csp-template-card {
  margin-bottom: 14px;
  padding: 14px;
  border: 1px solid #e2e5ea;
  border-radius: 8px;
  background: #fff;
}

.csp-template-card h4 {
  margin: 0 0 10px;
  color: #111827;
  font-size: 15px;
}

.csp-template-specs {
  margin: 0;
}

.csp-template-specs > div {
  display: grid;
  grid-template-columns: 96px minmax(0, 1fr);
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid #eef1f5;
}

.csp-template-specs > div:last-child {
  border-bottom: 0;
}

.csp-template-specs dt {
  color: #64748b;
  font-size: 12px;
  font-weight: 700;
}

.csp-template-specs dd {
  min-width: 0;
  margin: 0;
  color: #111827;
  font-size: 13px;
  overflow-wrap: anywhere;
}

.csp-template-notes {
  margin: 12px 0 0 18px;
  color: #334155;
  font-size: 13px;
}

.csp-template-help {
  margin: 0 0 10px;
  color: #64748b;
  font-size: 13px;
}

.csp-template-file-name {
  min-height: 36px;
  padding: 8px 10px;
  margin-bottom: 10px;
  border: 1px dashed #cbd5e1;
  border-radius: 6px;
  color: #334155;
  background: #f8fafc;
  font-size: 13px;
  overflow-wrap: anywhere;
}

.csp-template-layer-list {
  display: grid;
  gap: 7px;
  margin: 0 0 10px;
}

.csp-template-layer-list[hidden] {
  display: none !important;
}

.csp-template-layer-title {
  color: #475569;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
}

.csp-template-layer-item {
  width: 100%;
  min-height: 42px;
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr);
  align-items: center;
  gap: 9px;
  padding: 6px 8px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  background: #fff;
  color: #1f2937;
  text-align: left;
  cursor: pointer;
}

.csp-template-layer-item:hover,
.csp-template-layer-item.is-active {
  border-color: #0f766e;
  background: #ecfdf5;
}

.csp-template-layer-thumb {
  width: 32px;
  height: 32px;
  display: block;
  border-radius: 5px;
  object-fit: cover;
  background: #f1f5f9;
}

.csp-template-layer-thumb-text {
  display: flex;
  align-items: center;
  justify-content: center;
  color: #0f766e;
  font-size: 18px;
  font-weight: 800;
}

.csp-template-layer-name {
  min-width: 0;
  overflow: hidden;
  color: inherit;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.csp-template-upload-warning {
  margin-bottom: 10px;
  padding: 8px 10px;
  border: 1px solid #f1c40f;
  border-radius: 6px;
  background: #fff8db;
  color: #6b4e00;
  font-size: 13px;
  line-height: 1.35;
}

.csp-template-tool-row,
.csp-template-zoom {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-top: 8px;
}

.csp-template-tool-row .button {
  width: 100%;
  min-height: 38px;
}

.csp-template-transform-row {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.csp-template-save-row {
  grid-template-columns: 1fr;
}

.csp-template-save-row .button {
  width: 100%;
}

.csp-template-continue {
  border-color: #111827 !important;
  background: #111827 !important;
  color: #fff !important;
  font-weight: 800;
}

.csp-template-continue:hover,
.csp-template-continue:focus {
  background: #020617 !important;
  color: #fff !important;
}

.csp-template-save-status {
  grid-column: 1 / -1;
  min-height: 18px;
  color: #0f766e;
  font-size: 12px;
  font-weight: 800;
  text-align: center;
  opacity: 0;
  transition: opacity 0.16s ease;
}

.csp-template-save-status.is-visible {
  opacity: 1;
}

.csp-template-zoom {
  grid-template-columns: 42px minmax(0, 1fr) 42px;
  align-items: center;
}

.csp-template-zoom .button {
  min-width: 42px;
  min-height: 36px;
}

.csp-template-zoom-slider {
  width: 100%;
}

.csp-template-preview-panel {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto auto auto auto auto minmax(0, 1fr);
  padding: 16px;
  gap: 12px;
}

.csp-template-canvas-note {
  color: #475569;
  font-size: 13px;
}

.csp-template-text-toolbar,
.csp-template-image-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 8px;
  padding: 10px;
  border: 1px solid #dbe2ea;
  border-radius: 8px;
  background: #fff;
}

.csp-template-text-toolbar[hidden],
.csp-template-image-toolbar[hidden] {
  display: none !important;
}

.woocommerce-js div.product form.cart .csp-template-modal .button,
.woocommerce-js div.product form.cart .csp-template-modal button,
.woocommerce-js div.product form.cart .csp-template-text-toolbar .button,
.woocommerce-js div.product form.cart .csp-template-text-toolbar button,
.woocommerce-js div.product form.cart .csp-template-image-toolbar .button,
.woocommerce-js div.product form.cart .csp-template-image-toolbar button {
  margin-bottom: 0 !important;
}

.csp-template-image-toolbar .button {
  min-width: 120px;
  min-height: 36px;
  font-weight: 800;
}

.csp-template-text-toolbar label {
  min-width: 110px;
  display: grid;
  gap: 4px;
  color: #475569;
  font-size: 11px;
  font-weight: 800;
}

.csp-template-text-toolbar input,
.csp-template-text-toolbar select {
  min-height: 34px;
  width: 100%;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  background: #fff;
  color: #111827;
  font-size: 13px;
}

.csp-template-text-toolbar [data-csp-text-content] {
  min-width: 220px;
}

.csp-template-text-bold.is-active {
  border-color: #0f766e;
  background: #ecfdf5;
  color: #0f766e;
}

.csp-template-text-bold {
  height: 38px;
  min-height: 38px;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  margin-bottom: 0 !important;
  padding: 0 16px;
  line-height: 1 !important;
  font-weight: 800;
  text-align: center;
}

.csp-template-remove-text {
  min-height: 38px;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  margin-bottom: 0 !important;
  padding: 0 16px;
  line-height: 1 !important;
  font-weight: 800;
}

.csp-template-guide-legend {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  min-height: 24px;
  line-height: 1;
}

.csp-template-side-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.csp-template-side-tab {
  min-height: 36px;
  padding: 7px 14px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  background: #fff;
  color: #334155;
  font-weight: 700;
  cursor: pointer;
}

.csp-template-side-tab.is-active {
  border-color: #0f766e;
  color: #0f766e;
  background: #ecfdf5;
}

.csp-template-canvas {
  min-height: 0;
  display: grid;
  place-items: center;
  overflow: auto;
  border: 1px solid #dbe2ea;
  border-radius: 8px;
  background: #e8edf3;
}

.csp-template-clip-defs {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.csp-template-empty-shape {
  width: min(520px, calc(100% - 32px));
  margin: auto;
  padding: 18px 20px;
  border: 1px solid #d7dce3;
  border-radius: 8px;
  background: #fff;
  color: #4b5563;
  text-align: center;
  font-weight: 600;
}

.csp-template-side-panel {
  display: none;
  width: 100%;
  height: 100%;
  min-height: 360px;
  place-items: center;
  padding: 18px;
}

.csp-template-side-panel.is-active {
  display: grid;
}

.csp-template-stage {
  position: relative;
  width: fit-content;
  max-width: 100%;
  line-height: 0;
  touch-action: none;
  user-select: none;
}

.csp-template-stage.is-dragging {
  cursor: grabbing;
}

.csp-template-bg {
  display: block;
  max-width: min(100%, 760px);
  max-height: calc(100vh - 220px);
  width: auto;
  height: auto;
  object-fit: contain;
  background: #fff;
  box-shadow: 0 0 0 1px rgba(15, 23, 42, 0.12);
}

.csp-template-empty-bg {
  width: min(760px, 72vw);
  height: 420px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  border: 1px dashed #94a3b8;
  border-radius: 8px;
  background: #fff;
  color: #64748b;
  line-height: 1.4;
  text-align: center;
}

.csp-template-artwork-clip,
.csp-template-polygon {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.csp-template-artwork-clip {
  overflow: hidden;
  pointer-events: auto;
  z-index: 2;
}

.csp-template-artwork {
  position: absolute;
  inset: 0 auto auto 0;
  display: none;
  max-width: none !important;
  height: auto;
  will-change: transform;
  user-select: none;
  -webkit-user-drag: none;
  cursor: move;
  pointer-events: auto;
}

.csp-template-artwork-layer.is-active {
  outline: 2px solid #0f766e;
  outline-offset: 2px;
  filter: drop-shadow(0 0 4px rgba(15, 118, 110, 0.36));
}

.csp-template-text-layer {
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  min-width: 24px;
  min-height: 18px;
  padding: 0;
  line-height: 1.15;
  white-space: pre-wrap;
  overflow: hidden;
}

.csp-template-transform-frame {
  position: absolute;
  z-index: 5;
  display: none;
  box-sizing: border-box;
  border: 1.5px solid #2563eb;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.85);
  pointer-events: none;
}

.csp-template-transform-handle {
  position: absolute;
  width: 12px;
  height: 12px;
  box-sizing: border-box;
  border: 2px solid #2563eb;
  background: #fff;
  border-radius: 2px;
  pointer-events: auto;
}

.csp-template-transform-handle-nw {
  left: -7px;
  top: -7px;
  cursor: nwse-resize;
}

.csp-template-transform-handle-ne {
  right: -7px;
  top: -7px;
  cursor: nesw-resize;
}

.csp-template-transform-handle-se {
  right: -7px;
  bottom: -7px;
  cursor: nwse-resize;
}

.csp-template-transform-handle-sw {
  left: -7px;
  bottom: -7px;
  cursor: nesw-resize;
}

.csp-template-polygon {
  pointer-events: none;
  z-index: 3;
}

.csp-template-guide {
  vector-effect: non-scaling-stroke;
}

.csp-template-guide-bleed {
  fill: rgba(37, 99, 235, 0.08);
  stroke: #2563eb;
  stroke-width: 0.8;
  stroke-dasharray: 2 1.5;
}

.csp-template-guide-safety {
  fill: rgba(22, 163, 74, 0.06);
  stroke: #16a34a;
  stroke-width: 0.8;
  stroke-dasharray: 4 2;
}

.csp-template-guide-labels {
  display: none;
}

.csp-template-guide-label {
  padding: 5px 7px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.92);
  font-size: 11px;
  font-weight: 800;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.15);
}

.csp-template-guide-label-bleed {
  color: #1d4ed8;
}

.csp-template-guide-label-safety {
  color: #15803d;
}

.csp-template-readonly-modal .csp-template-body {
  display: block;
}

.csp-template-readonly-panel {
  min-height: min(72vh, 720px);
}

.csp-template-readonly-modal .csp-template-artwork {
  cursor: default;
  pointer-events: none;
}

.csp-template-readonly-modal .csp-template-transform-frame {
  display: none !important;
}

.csp-template-readonly-trigger {
  margin-top: 4px;
  min-height: 32px;
  padding: 5px 12px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  background: #fff;
  color: #0f172a;
  font-weight: 700;
  cursor: pointer;
}

.csp-template-readonly-trigger:hover {
  border-color: #0f766e;
  color: #0f766e;
}

@media (max-width: 860px) {
  .csp-template-modal {
    align-items: stretch;
    padding: 0;
  }

  .csp-template-dialog {
    width: 100%;
    height: 100dvh;
    max-height: 100dvh;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    grid-template-rows: auto auto;
  }

  .csp-template-topbar {
    position: sticky;
    top: 0;
    z-index: 5;
    grid-template-columns: minmax(0, 1fr);
    gap: 6px;
    padding: 12px 66px 12px 14px;
  }

  .csp-template-current-size {
    grid-column: 1 / -1;
    max-width: none;
    text-align: left;
    font-size: 13px;
  }

  .csp-template-close {
    position: absolute;
    top: 12px;
    right: 14px;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 !important;
    padding: 0;
    border-color: #111827;
    background: #111827;
    color: #fff;
    font-size: 24px;
    line-height: 1;
  }

  .csp-template-body {
    display: flex;
    flex-direction: column;
    min-height: auto;
    overflow: visible;
    padding-bottom: max(18px, env(safe-area-inset-bottom));
  }

  .csp-template-sidebar {
    order: 2;
    display: flex;
    flex-direction: column;
    overflow: visible;
    max-height: none;
    border-right: 0;
    border-bottom: 1px solid #e2e5ea;
  }

  .csp-template-preview-panel {
    order: 1;
  }

  .csp-template-upload-card {
    order: 1;
  }

  .csp-template-sidebar > .csp-template-card:not(.csp-template-upload-card) {
    order: 2;
  }

  .csp-template-card {
    margin-bottom: 10px;
  }

  .csp-template-transform-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .csp-template-side-tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 2px;
    scroll-snap-type: x proximity;
    -webkit-overflow-scrolling: touch;
  }

  .csp-template-side-tab {
    flex: 0 0 auto;
    scroll-snap-align: start;
  }

  .csp-template-preview-panel {
    min-height: 0;
    display: block;
    padding: 14px;
  }

  .csp-template-canvas-note,
  .csp-template-side-tabs {
    margin-bottom: 10px;
  }

  .csp-template-canvas {
    min-height: 280px;
    overflow: auto;
  }

  .csp-template-side-panel {
    height: auto;
    min-height: 280px;
  }

  .csp-template-bg {
    max-width: calc(100vw - 48px);
    max-height: 52vh;
  }

  .csp-template-empty-bg {
    width: calc(100vw - 48px);
    max-width: 100%;
    height: 300px;
  }
}

@media (max-width: 520px) {
  .csp-template-modal {
    padding: 0;
  }

  .csp-template-dialog {
    width: 100%;
    max-height: 100dvh;
    border-radius: 0;
  }

  .csp-template-topbar h3 {
    font-size: 18px;
  }

  .csp-template-tool-row {
    grid-template-columns: 1fr;
  }

  .csp-template-transform-row {
    grid-template-columns: 1fr;
  }

  .csp-template-zoom {
    grid-template-columns: 44px minmax(0, 1fr) 44px;
  }

  .csp-template-tool-row .button,
  .csp-template-zoom .button {
    min-height: 44px;
  }

  .csp-template-preview-panel {
    padding: 12px;
  }

  .csp-template-side-panel {
    padding: 10px;
    min-height: 240px;
  }

  .csp-template-canvas {
    min-height: 250px;
  }

  .csp-template-bg {
    max-width: calc(100vw - 28px);
    max-height: 46vh;
  }

  .csp-template-empty-bg {
    width: calc(100vw - 28px);
    height: 250px;
  }

  .csp-template-guide-labels {
    top: 6px;
    right: 6px;
  }
}
