.template-workspace {
  gap: 20px;
}

.template-layout {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr) 320px;
  gap: 20px;
}

.template-sidebar,
.template-center,
.template-fields-panel {
  min-height: 720px;
}

.stacked-form {
  display: grid;
  gap: 12px;
  margin-bottom: 18px;
}

.stacked-form label {
  display: grid;
  gap: 6px;
}

.document-type-picker {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 12px;
  border: 1px solid rgba(37, 99, 235, 0.22);
  border-radius: 8px;
  background: rgba(37, 99, 235, 0.06);
}

.document-type-picker legend {
  padding: 0 6px;
  color: #1f2a44;
  font-size: 13px;
  font-weight: 800;
}

.document-type-options {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.document-type-option {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  min-height: 56px;
  padding: 8px 10px;
  border: 1px solid #d8e1ef;
  background: #ffffff;
  color: #172033;
  text-align: left;
}

.document-type-option span {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: #e8eef8;
  color: #1f2a44;
  font-size: 12px;
  font-weight: 900;
}

.document-type-option strong {
  min-width: 0;
  font-size: 14px;
  line-height: 1.2;
}

.document-type-option.active {
  border-color: #2563eb;
  background: #eff6ff;
  box-shadow: 0 0 0 1px rgba(37, 99, 235, 0.24) inset;
}

.document-type-option.active span {
  background: #2563eb;
  color: #ffffff;
}

.stacked-form .document-type-select-fallback,
.document-type-select-fallback {
  display: none;
}

.field-actions {
  display: grid;
  gap: 10px;
}

.danger {
  border: 1px solid rgba(248, 113, 113, 0.35);
  background: rgba(127, 29, 29, 0.25);
  color: #fee2e2;
}

.danger:hover {
  border-color: rgba(248, 113, 113, 0.55);
  background: rgba(127, 29, 29, 0.4);
}

.template-list {
  display: grid;
  gap: 8px;
}

.template-item-wrapper {
  display: flex;
  gap: 8px;
  align-items: stretch;
  border-radius: 8px;
  padding: 0;
  border: 1px solid rgba(148, 163, 184, 0.18);
  background: rgba(15, 23, 42, 0.55);
}

.template-item-wrapper.active {
  border-color: rgba(56, 189, 248, 0.8);
  box-shadow: 0 0 0 1px rgba(56, 189, 248, 0.35) inset;
}

.template-item {
  flex: 1;
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  color: #e5edf7;
  padding: 12px;
  border-radius: 0;
  display: grid;
  gap: 4px;
  cursor: pointer;
}

.template-item:hover {
  background: rgba(56, 189, 248, 0.1);
}

.template-item-actions {
  display: flex;
  gap: 4px;
  padding: 8px 8px;
  border-left: 1px solid rgba(148, 163, 184, 0.18);
}

.template-action {
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid rgba(148, 163, 184, 0.25);
  background: rgba(15, 23, 42, 0.35);
  color: #cbd5e1;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 200ms ease;
}

.template-action:hover {
  border-color: rgba(148, 163, 184, 0.5);
  background: rgba(148, 163, 184, 0.15);
}

.template-action.delete-template:hover {
  border-color: rgba(248, 113, 113, 0.5);
  background: rgba(248, 113, 113, 0.15);
  color: #fecaca;
}

.field-row {
  width: 100%;
  text-align: left;
  border: 1px solid rgba(148, 163, 184, 0.18);
  background: rgba(15, 23, 42, 0.55);
  color: #e5edf7;
  padding: 12px;
  border-radius: 8px;
  display: grid;
  gap: 4px;
}

.field-row.active {
  border-color: rgba(56, 189, 248, 0.8);
  box-shadow: 0 0 0 1px rgba(56, 189, 248, 0.35) inset;
}

.viewer-shell {
  container-type: inline-size;
  min-height: 620px;
  border: 1px dashed rgba(148, 163, 184, 0.25);
  border-radius: 8px;
  padding: 12px;
  background: rgba(15, 23, 42, 0.45);
  overflow: hidden;
}

.template-meta {
  margin: 6px 0 0;
  color: #94a3b8;
  font-size: 14px;
}

.drawing-help {
  width: calc(100% + 24px);
  margin: 0 -12px 12px -12px;
  padding: 10px 12px;
  border: 1px solid rgba(56, 189, 248, 0.35);
  border-radius: 0;
  background: rgba(56, 189, 248, 0.1);
  color: #dbeafe;
  font-size: 14px;
}

.page-toolbar {
  margin-bottom: 12px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid rgba(148, 163, 184, 0.18);
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.35);
}

.page-toolbar-group {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex-wrap: wrap;
}

.page-toolbar > .page-toolbar-group:first-child {
  grid-column: 1;
  grid-row: 2;
  justify-self: start;
}

.page-toolbar > .page-toolbar-group:last-child {
  grid-column: 2;
  grid-row: 2;
  justify-self: end;
}

.page-toolbar-meta {
  display: contents;
}

.page-toolbar-meta strong {
  grid-column: 1 / -1;
  grid-row: 1;
  justify-self: center;
  color: #f8fafc;
  text-align: center;
  white-space: nowrap;
}

.page-toolbar-meta span {
  display: block;
  grid-column: 1 / -1;
  grid-row: 3;
  justify-self: center;
  width: min(100%, 780px);
  color: #cbd5e1;
  font-size: 13px;
  line-height: 1.45;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.zoom-indicator {
  min-width: 54px;
  text-align: center;
  color: #f8fafc;
  font-size: 14px;
}

.page-toolbar button {
  min-height: 42px;
  padding: 0 14px;
}

.page-toolbar #zoomOutButton,
.page-toolbar #zoomInButton {
  width: 54px;
  padding: 0;
}

.page-markers {
  margin-bottom: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.page-marker {
  border: 1px solid rgba(148, 163, 184, 0.18);
  background: rgba(15, 23, 42, 0.5);
  color: #cbd5e1;
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 13px;
  line-height: 1;
}

.page-marker.has-fields {
  border-color: rgba(56, 189, 248, 0.45);
  color: #dbeafe;
}

.page-marker.active {
  border-color: rgba(37, 99, 235, 0.95);
  background: rgba(37, 99, 235, 0.2);
  color: #ffffff;
}

.viewer-loading {
  margin-bottom: 12px;
  display: grid;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid rgba(96, 165, 250, 0.25);
  border-radius: 8px;
  background: rgba(30, 41, 59, 0.55);
}

.viewer-loading strong {
  color: #dbeafe;
  font-size: 14px;
}

.viewer-loading-bar {
  width: 100%;
  height: 8px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.18);
  overflow: hidden;
}

.viewer-loading-bar span {
  display: block;
  width: 32%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #2563eb, #38bdf8);
  animation: template-loading-slide 1.15s ease-in-out infinite;
}

.viewer-placeholder {
  min-height: 580px;
  display: grid;
  place-items: center;
  color: #94a3b8;
}

.template-viewer {
  position: relative;
  width: 100%;
  max-height: 72vh;
  overflow: auto;
  border-radius: 8px;
}

.template-stage {
  position: relative;
  width: 100%;
  min-width: 100%;
  transform-origin: top left;
}

.template-viewer.hidden,
.hidden {
  display: none;
}

.template-viewer img {
  width: 100%;
  display: block;
  border-radius: 6px;
}

.selection-layer {
  position: absolute;
  inset: 0;
  cursor: crosshair;
  z-index: 2;
}

.selection-box {
  position: absolute;
  box-sizing: border-box;
  appearance: none;
  min-height: 0;
  margin: 0;
  padding: 0;
  border: 2px solid rgba(59, 130, 246, 0.9);
  background: rgba(59, 130, 246, 0.18);
  border-radius: 4px;
  overflow: hidden;
}

.selection-box.active {
  border-color: rgba(34, 197, 94, 0.95);
  background: rgba(34, 197, 94, 0.16);
}

.selection-box.ghost {
  pointer-events: none;
}

.selection-box span {
  position: absolute;
  top: 0;
  left: 0;
  font-size: 12px;
  padding: 3px 6px;
  background: rgba(15, 23, 42, 0.8);
  color: #f8fafc;
  pointer-events: none;
}

.resize-handle {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 12px;
  height: 12px;
  border-top-left-radius: 4px;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 0 0 1px rgba(15, 23, 42, 0.18);
  cursor: nwse-resize;
}

.inline-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.empty-note {
  color: #94a3b8;
  font-size: 14px;
}

.preview-results {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid rgba(148, 163, 184, 0.15);
}

.preview-grid {
  display: grid;
  gap: 8px;
}

.preview-grid div {
  display: grid;
  gap: 4px;
}

.preview-grid dt {
  color: #94a3b8;
  font-size: 12px;
  text-transform: uppercase;
}

.preview-grid dd {
  margin: 0;
  color: #f8fafc;
}

.preview-results .raw-preview {
  max-height: 220px;
  overflow: auto;
  margin: 12px 0 0;
  padding: 10px;
  border: 1px solid rgba(148, 163, 184, 0.18);
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.55);
  color: #dbeafe;
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
}

.upload-button input {
  display: none;
}

@keyframes template-loading-slide {
  0% {
    transform: translateX(-100%);
  }

  100% {
    transform: translateX(320%);
  }
}

@media (max-width: 1280px) {
  .template-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .page-toolbar {
    display: flex;
    flex-direction: column;
    align-items: stretch;
  }

  .page-toolbar-meta {
    display: grid;
    justify-items: center;
    gap: 4px;
    text-align: center;
  }

  .page-toolbar-meta strong,
  .page-toolbar-meta span {
    grid-column: auto;
    grid-row: auto;
  }

  .page-toolbar-meta span {
    white-space: normal;
  }

  .page-toolbar-group {
    justify-content: center;
    flex-wrap: wrap;
  }
}

@container (max-width: 760px) {
  .page-toolbar {
    display: flex;
    flex-direction: column;
    align-items: stretch;
  }

  .page-toolbar-meta {
    display: grid;
    justify-items: center;
    gap: 4px;
    text-align: center;
    order: -1;
  }

  .page-toolbar-meta strong,
  .page-toolbar-meta span {
    grid-column: auto;
    grid-row: auto;
  }

  .page-toolbar-meta span {
    white-space: normal;
  }

  .page-toolbar-group {
    justify-content: center;
  }
}
