/* Template cards, previews, and editor surfaces */

.template-grid {
  --template-card-scale: 0.56;
  --template-card-width: calc((794px * var(--template-card-scale)) + 36px);
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, var(--template-card-width)), var(--template-card-width)));
  gap: 30px;
  min-height: 0;
  justify-content: start;
  align-content: start;
  box-sizing: border-box;
}

.template-card {
  --template-card-thumbnail-scale: var(--template-card-scale);
  display: grid;
  align-content: start;
  gap: 5px;
  width: min(100%, var(--template-card-width));
  padding: 18px;
  border-radius: 24px;
  justify-self: center;
  background: var(--glass-surface);
}

.template-preview {
  position: relative;
  width: calc(794px * var(--template-card-thumbnail-scale));
  min-height: calc(1123px * var(--template-card-thumbnail-scale));
  margin: 0 auto;
  padding: 0;
  border: 1px solid rgba(var(--glass-line-rgb), 0.78);
  border-radius: 18px;
  overflow: hidden;
  background: rgba(var(--glass-surface-rgb), 0.98);
}

.template-card-header {
  align-items: flex-start;
  margin-bottom: 0;
  padding: 0;
}

.template-card-heading {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.template-card-heading h3 {
  margin: 0;
  font-size: 1.02rem;
  line-height: 1.25;
}

.template-card-heading p {
  margin: 0;
  font-size: 0.84rem;
  line-height: 1.45;
}

.template-card-meta-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  min-width: 0;
}

.template-card-meta-row h3,
.template-card-meta-row p {
  min-width: 0;
}

.template-card-meta-edit-button,
.template-card-meta-action-button {
  width: 22px;
  min-width: 22px;
  min-height: 22px;
  padding: 0;
  gap: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--text-dim);
  box-shadow: none;
  transform: none;
}

.template-card-meta-edit-button .button-icon,
.template-card-meta-action-button .button-icon {
  width: 16px;
  height: 16px;
  stroke-width: 2;
}

.template-card-meta-action-button.template-card-save-button {
  color: var(--glass-success);
}

.template-card-meta-action-button.template-card-cancel-button {
  color: var(--glass-error);
}

.template-card-meta-edit-button:hover,
.template-card-meta-action-button:hover {
  background: transparent;
  color: var(--text);
  box-shadow: none;
  transform: none;
}

.template-card-meta-action-button.template-card-save-button:hover {
  color: var(--glass-success);
}

.template-card-meta-action-button.template-card-cancel-button:hover {
  color: var(--glass-error);
}

.template-card-meta-edit-button:focus-visible,
.template-card-meta-action-button:focus-visible {
  border-radius: 6px;
  outline: 2px solid rgba(var(--glass-primary-rgb), 0.24);
  outline-offset: 2px;
  box-shadow: none;
}

.template-card-meta-editor {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  min-width: 0;
}

.template-card-meta-input {
  width: 100%;
  min-height: 30px;
  padding: 0 12px;
  border: 1px solid rgba(var(--glass-line-rgb), 0.92);
  border-radius: 12px;
  background: var(--glass-surface);
  color: var(--text);
  font: inherit;
  box-sizing: border-box;
  outline: none;
}

.template-card-meta-editor-name .template-card-meta-input {
  min-height: 30px;
  font-size: 1.02rem;
  font-weight: 700;
  line-height: 1.25;
}

.template-card-meta-editor-description .template-card-meta-input {
  min-height: 24px;
  font-size: 0.84rem;
  line-height: 1.45;
}

.template-card-meta-input:focus {
  border-color: rgba(var(--glass-primary-rgb), 0.7);
  box-shadow: 0 0 0 3px rgba(var(--glass-primary-rgb), 0.12);
}

.template-card-meta-editor-actions {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.template-card-header-tools {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.template-card-copy-button,
.template-card-delete-button {
  width: 36px;
  min-width: 36px;
  min-height: 36px;
  padding: 0;
  border-radius: 12px;
}

.template-sheet-placeholder {
  width: 100%;
}

.template-card-thumbnail-sheet {
  margin: 0;
  position: absolute;
  top: 0;
  left: 0;
  width: 794px;
  min-height: 1123px;
  transform: scale(var(--template-card-thumbnail-scale));
  transform-origin: top left;
  pointer-events: none;
  user-select: none;
}

.template-card-thumbnail-sheet .examinee-photo-placeholder {
  min-height: 108px;
  font-size: 12px;
}

.template-sheet-placeholder {
  display: grid;
  align-content: start;
  gap: 10px;
  min-height: 100%;
  margin: 0 auto;
  padding: 20px 18px;
  border-radius: 18px;
  background: var(--glass-surface);
}

.template-sheet-placeholder-title,
.template-sheet-placeholder-line,
.template-sheet-placeholder-block {
  display: block;
  border-radius: 999px;
  background: var(--glass-surface);
}

.template-sheet-placeholder-title {
  width: 52%;
  height: 12px;
  margin: 2px auto 8px;
}

.template-sheet-placeholder-line {
  width: 100%;
  height: 8px;
}

.template-sheet-placeholder-line.long {
  width: 86%;
  margin: 0 auto;
}

.template-sheet-placeholder-block {
  height: 86px;
  margin-top: 8px;
  border-radius: 16px;
}

.template-card .inline-actions {
  margin-top: 0 !important;
}

.template-card-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  width: 100%;
}

.template-card-action-button {
  width: 100%;
  min-height: 42px;
  padding: 0 10px;
  border-radius: 14px;
  gap: 6px;
  font-size: 0.84rem;
  font-weight: 700;
  white-space: nowrap;
}


.template-preview-modal-body,
.template-editor-modal-body {
  height: 100%;
  min-height: 0;
}

#templateEditorModal .modal-body.template-editor-modal-body {
  height: 100%;
  min-height: 0;
  max-height: none;
  align-self: stretch;
  overflow: hidden;
}

.template-editor-modal-sheet .modal-header {
  padding: 10px 14px;
}

.template-editor-modal-sheet .modal-header h3 {
  font-size: 1.12rem;
  line-height: 1.1;
}

#templatePreviewModal .modal-body.template-preview-modal-body {
  height: 100%;
  min-height: 0;
  max-height: none;
  overflow: hidden;
  padding: 12px 16px 16px;
  align-self: stretch;
}

.template-preview-modal-sheet .modal-header {
  padding: 12px 16px;
}

.template-preview-modal-sheet .modal-header h3 {
  font-size: 1.16rem;
  line-height: 1.1;
}

.template-preview-modal-sheet .modal-header .toolbar-actions {
  align-items: center;
}

.template-preview-stage,
.template-editor-page {
  --template-editor-canvas-width: 794px;
  height: 100%;
  min-height: 0;
  overflow: auto;
  border-radius: 0;
  background: linear-gradient(180deg, rgba(231, 238, 247, 0.92), rgba(244, 247, 252, 0.92));
}

.template-preview-stage {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 18px 18px 28px;
  scrollbar-gutter: stable both-edges;
  background: radial-gradient(circle at top, rgba(var(--glass-surface-rgb), 0.82), rgba(236, 242, 250, 0.94) 34%, rgba(228, 235, 245, 0.96));
}

.template-render-sheet {
  width: 794px;
  min-height: 1123px;
  margin: 0 auto;
  padding: 44px 46px;
  border-radius: 0;
  background: #ffffff;
  box-shadow: 0 24px 60px rgba(31, 41, 55, 0.12);
}

.template-preview-stage .template-render-sheet {
  flex: 0 0 auto;
  margin: 0 auto 28px;
  box-shadow: 0 26px 68px rgba(31, 41, 55, 0.16);
}

.template-editor-modal-body {
  display: grid;
  grid-template-columns: var(--editor-toolbar-column-width) minmax(180px, 252px) var(--template-editor-canvas-width, 794px);
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 6px;
  align-items: stretch;
  padding: 8px;
  overflow: hidden;
}

.template-editor-meta-grid {
  display: grid;
  grid-column: 1;
  grid-row: 1;
  grid-template-columns: minmax(0, 1fr);
  gap: 12px;
  align-content: start;
  padding: 16px;
  border-radius: 20px;
  background: rgba(var(--glass-surface-rgb), 0.98);
  border: 1px solid rgba(var(--glass-line-rgb), 0.96);
  box-shadow: var(--glass-shadow);
}

.template-editor-field {
  display: grid;
  gap: 6px;
  color: var(--text-dim);
  font-size: 0.78rem;
  font-weight: 700;
}

.template-editor-input {
  width: 100%;
  min-height: 42px;
  padding: 0 14px;
  border: 1px solid rgba(var(--glass-line-rgb), 0.95);
  border-radius: 14px;
  background: rgba(var(--glass-surface-rgb), 0.95);
  color: var(--text);
  font: inherit;
  outline: none;
  transition: border-color 0.18s ease,
    box-shadow 0.18s ease;
}

.template-editor-input:focus {
  border-color: rgba(var(--glass-primary-rgb), 0.7);
  box-shadow: 0 0 0 4px rgba(var(--glass-primary-rgb), 0.12);
}

.editor-toolbar {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  overflow: auto;
  padding: 12px;
  border-radius: 20px;
  background: var(--glass-surface);
  border: 1px solid rgba(var(--glass-line-rgb), 0.96);
  box-shadow: inset 0 1px 0 rgba(88, 121, 143, 0.75);
}

.editor-toolbar-column {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 12px;
  min-height: 0;
  height: 100%;
  align-self: stretch;
  overflow: hidden;
}

.editor-toolbar-column > .editor-toolbar {
  height: 100%;
}

.template-editor-modal-body > .editor-toolbar-column {
  grid-column: 1;
  grid-row: 1 / 3;
}

.template-page-properties-panel {
  grid-column: 2;
  grid-row: 2;
  display: grid;
  gap: 8px;
  align-content: start;
  align-self: start;
  min-width: 0;
  min-height: 0;
  max-height: 100%;
  overflow: auto;
  padding: 10px;
  border: 1px solid rgba(var(--glass-line-rgb), 0.96);
  border-radius: 20px;
  background: rgba(var(--glass-surface-rgb), 0.98);
  box-shadow: var(--glass-shadow);
}

.template-page-properties-title {
  margin: 0;
  color: var(--text-dim);
  font-size: 0.76rem;
  font-weight: 700;
}

.template-page-property-field {
  display: grid;
  gap: 4px;
  min-width: 0;
  margin: 0;
  color: var(--text-dim);
  font-size: 0.72rem;
  font-weight: 700;
}

.template-page-property-fieldset {
  padding: 0;
  border: 0;
}

.template-page-property-fieldset > legend {
  padding: 0;
  margin: 0 0 4px;
}

.template-page-property-control {
  width: 100%;
  min-height: 30px;
  padding: 0 8px;
  border: 1px solid rgba(var(--glass-line-rgb), 0.95);
  border-radius: 8px;
  background: var(--glass-surface);
  color: var(--text);
  font: inherit;
  font-size: 0.76rem;
  font-weight: 700;
  outline: none;
}

.template-page-property-control:focus {
  border-color: rgba(var(--glass-primary-rgb), 0.72);
  box-shadow: 0 0 0 3px rgba(var(--glass-primary-rgb), 0.12);
}

.template-page-orientation-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 5px;
}

.template-page-orientation-options label {
  min-width: 0;
}

.template-page-orientation-options span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 30px;
  border: 1px solid rgba(var(--glass-line-rgb), 0.95);
  border-radius: 8px;
  background: var(--glass-surface);
  color: var(--text);
  font-size: 0.76rem;
  font-weight: 700;
  cursor: pointer;
}

.template-page-orientation-options input:checked + span {
  border-color: rgba(var(--glass-primary-rgb), 0.72);
  background: rgba(var(--glass-primary-rgb), 0.1);
  color: var(--glass-link);
}

.template-page-margin-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 5px;
}

.template-page-margin-grid label {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.template-page-margin-grid span {
  color: var(--text-dim);
  font-size: 0.68rem;
  font-weight: 700;
}

.editor-toolbar-footer {
  padding: 12px;
  border-radius: 20px;
  background: var(--glass-surface);
  border: 1px solid rgba(var(--glass-line-rgb), 0.96);
  box-shadow: inset 0 1px 0 rgba(88, 121, 143, 0.75);
}

.editor-toolbar-footer .toolbar-actions {
  width: 100%;
  justify-content: stretch;
}

.editor-toolbar-footer .toolbar-actions button {
  flex: 1 1 0;
}

.template-toolbar-group {
  display: grid;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid rgba(var(--glass-line-rgb), 0.96);
  border-radius: 14px;
  background: rgba(var(--glass-surface-rgb), 0.98);
  align-content: start;
}

.template-toolbar-group-label {
  color: var(--glass-muted);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.template-toolbar-group-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  min-width: 0;
}

.template-toolbar-section {
  display: grid;
  --template-toolbar-section-label-width: 3em;
  grid-template-columns: var(--template-toolbar-section-label-width) minmax(0, 1fr);
  align-items: start;
  min-width: 0;
}

.template-toolbar-section-row {
  display: grid;
  gap: 8px 14px;
  min-width: 0;
}

.template-toolbar-section-row-format {
  grid-template-columns: minmax(0, 1fr) 90px;
  gap: 8px;
  align-items: start;
}

.template-toolbar-section-row-dual {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  align-items: start;
}

.template-toolbar-section-row-dual > .template-toolbar-section {
  min-width: 0;
}

.template-toolbar-border-section {
  align-items: start;
}

.template-toolbar-border-controls {
  display: grid;
  grid-template-columns: minmax(112px, 1fr) minmax(82px, 0.78fr);
  gap: 8px;
  align-items: stretch;
  min-width: 0;
}

.template-toolbar-select-wrap-border-target {
  grid-column: 1 / -1;
  width: 100%;
  min-width: 0;
  max-width: none;
  flex-basis: auto;
}

.template-toolbar-select-wrap-border-style {
  width: 100%;
  min-width: 0;
  max-width: none;
  flex-basis: auto;
}

.template-toolbar-border-width-field {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  width: 100%;
  min-width: 0;
  min-height: 36px;
  color: var(--text-dim);
  font-size: 0.76rem;
  font-weight: 700;
  justify-content: flex-start;
}

.template-toolbar-border-width {
  width: 58px;
  min-width: 0;
}

.template-toolbar-section-border-color {
  display: block;
  width: 100%;
  min-width: 0;
}

.template-toolbar-section-border-color > .template-toolbar-section-label {
  display: none;
}

.template-toolbar-section-border-color .template-toolbar-color-picker,
.template-toolbar-section-border-color .template-toolbar-color-trigger {
  width: 100%;
  min-width: 0;
  max-width: none;
}

.template-toolbar-section-border-color .template-toolbar-color-picker-align-end {
  justify-self: stretch;
}

.template-toolbar-section-border-color .template-toolbar-color-picker-align-end .template-toolbar-color-panel {
  right: auto;
  left: 0;
}

.template-toolbar-border-apply {
  width: 100%;
  min-width: 0;
}

.template-toolbar-section-label {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  width: var(--template-toolbar-section-label-width);
  min-width: var(--template-toolbar-section-label-width);
  min-height: 36px;
  color: var(--text-dim);
  font-size: 0.74rem;
  font-weight: 700;
  text-align: right;
  white-space: nowrap;
}

.template-toolbar-select-wrap {
  position: relative;
  width: 90px;
  min-width: 90px;
  max-width: 90px;
  flex: 0 0 90px;
}

.template-toolbar-select-wrap.template-toolbar-select-wrap-border-target,
.template-toolbar-select-wrap.template-toolbar-select-wrap-border-style {
  width: 100%;
  min-width: 0;
  max-width: none;
  flex: 1 1 auto;
}

.template-toolbar-icon-select {
  display: block;
  z-index: 10;
}

.template-toolbar-icon-select.open {
  z-index: 40;
}

.template-toolbar-border-native-select {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
  opacity: 0;
  pointer-events: none;
}

.template-toolbar-icon-select-button {
  width: 100%;
  min-height: 36px;
  padding: 0 9px;
  border: 1px solid rgba(var(--glass-line-rgb), 0.95);
  border-radius: 12px;
  background: var(--glass-surface);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font: inherit;
  font-size: 0.8rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  outline: none;
  transition: border-color 0.18s ease,
    background-color 0.18s ease,
    box-shadow 0.18s ease;
}

.template-toolbar-icon-select-button:hover,
.template-toolbar-icon-select-button:focus-visible,
.template-toolbar-icon-select.open .template-toolbar-icon-select-button {
  border-color: rgba(var(--glass-primary-rgb), 0.7);
  box-shadow: 0 0 0 3px rgba(var(--glass-primary-rgb), 0.12);
}

.template-toolbar-icon-select-current-icon,
.template-toolbar-icon-select-option-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  flex: 0 0 auto;
}

.template-toolbar-dropdown-icon {
  width: 22px;
  height: 22px;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: square;
  stroke-linejoin: round;
}

.template-toolbar-border-style-icon {
  stroke-width: 2.4;
}

.template-toolbar-border-icon-muted {
  opacity: 0.28;
}

.template-toolbar-border-icon-active {
  opacity: 1;
}

.template-toolbar-icon-select-label,
.template-toolbar-icon-select-option-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.template-toolbar-icon-select-caret {
  width: 0;
  height: 0;
  margin-left: auto;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 6px solid var(--glass-line);
  transform: translateY(1px);
  flex: 0 0 auto;
}

.template-toolbar-icon-select-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 45;
  display: grid;
  gap: 3px;
  width: 100%;
  min-width: 100%;
  max-height: 260px;
  overflow-y: auto;
  padding: 5px;
  border: 1px solid rgba(var(--glass-line-rgb), 0.95);
  border-radius: 12px;
  background: var(--glass-surface);
  box-shadow: var(--glass-dialog-shadow);
}

.template-toolbar-icon-select.open-up .template-toolbar-icon-select-menu {
  top: auto;
  bottom: calc(100% + 6px);
}

.template-toolbar-icon-select-option {
  width: 100%;
  min-height: 34px;
  padding: 0 8px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 7px;
  font: inherit;
  font-size: 0.78rem;
  font-weight: 700;
  text-align: left;
  cursor: pointer;
}

.template-toolbar-icon-select-option:hover,
.template-toolbar-icon-select-option:focus-visible {
  background: rgba(var(--glass-surface-rgb), 0.95);
  outline: none;
}

.template-toolbar-icon-select-option.active {
  background: rgba(var(--glass-primary-rgb), 0.12);
  color: var(--glass-link);
}

.template-toolbar-select-caret {
  position: absolute;
  top: 50%;
  right: 14px;
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 6px solid var(--glass-line);
  transform: translateY(-30%);
  pointer-events: none;
}

.template-toolbar-select-label {
  color: var(--text-dim);
  font-size: 0.76rem;
  font-weight: 700;
}

.template-toolbar-input-label {
  color: var(--text-dim);
  font-size: 0.74rem;
  font-weight: 700;
  white-space: nowrap;
}

.template-toolbar-number {
  width: 72px;
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid rgba(var(--glass-line-rgb), 0.95);
  border-radius: 11px;
  background: var(--glass-surface);
  color: var(--text);
  font: inherit;
  font-size: 0.8rem;
  font-weight: 700;
  appearance: auto;
  -moz-appearance: auto;
  outline: none;
}

.template-toolbar-number::-webkit-inner-spin-button,
.template-toolbar-number::-webkit-outer-spin-button {
  margin: 0;
  opacity: 1;
}

.template-toolbar-number:focus {
  border-color: rgba(var(--glass-primary-rgb), 0.7);
  box-shadow: 0 0 0 3px rgba(var(--glass-primary-rgb), 0.12);
}

.template-toolbar-font-size-input {
  width: 90px;
  min-width: 90px;
  max-width: 90px;
  padding-right: 42px;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: textfield;
}

.template-toolbar-font-size-input::-webkit-inner-spin-button,
.template-toolbar-font-size-input::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.template-toolbar-select {
  width: 100%;
  min-height: 36px;
  padding: 0 34px 0 12px;
  border: 1px solid rgba(var(--glass-line-rgb), 0.95);
  border-radius: 12px;
  background: var(--glass-surface);
  color: var(--text);
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 700;
  outline: none;
}

.template-toolbar-select-wide {
  width: 90px;
  min-width: 90px;
  max-width: 90px;
  flex: 0 0 90px;
}

.template-toolbar-font-size-controls {
  min-width: 0;
}

.template-toolbar-font-size-combo {
  position: relative;
  flex: 0 0 90px;
  min-width: 90px;
  max-width: 90px;
}

.template-toolbar-combo-toggle {
  position: absolute;
  top: 1px;
  right: 1px;
  bottom: 1px;
  width: 34px;
  border: 0;
  border-left: 1px solid rgba(var(--glass-line-rgb), 0.95);
  border-radius: 0 11px 11px 0;
  background: transparent;
  color: var(--glass-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background-color 0.18s ease;
}

.template-toolbar-combo-toggle:hover,
.template-toolbar-font-size-combo.open .template-toolbar-combo-toggle {
  background: rgba(var(--glass-surface-rgb), 0.95);
}

.template-toolbar-combo-caret {
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 6px solid currentColor;
  transform: translateY(1px);
}

.template-toolbar-combo-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 30;
  width: 100%;
  max-height: 220px;
  overflow-y: auto;
  padding: 4px;
  border: 1px solid rgba(var(--glass-line-rgb), 0.95);
  border-radius: 12px;
  background: var(--glass-surface);
  box-shadow: var(--glass-dialog-shadow);
}

.template-toolbar-combo-option {
  width: 100%;
  min-height: 32px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 0.79rem;
  font-weight: 700;
  text-align: left;
  padding: 0 10px;
  cursor: pointer;
}

.template-toolbar-combo-option:hover,
.template-toolbar-combo-option:focus-visible {
  background: rgba(var(--glass-surface-rgb), 0.95);
  outline: none;
}

.template-toolbar-combo-option.active {
  background: rgba(var(--glass-primary-rgb), 0.12);
  color: var(--glass-link);
}

.template-tool-button {
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid rgba(var(--glass-line-rgb), 0.95);
  border-radius: 12px;
  background: var(--glass-surface);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font: inherit;
  font-size: 0.8rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  transition: border-color 0.18s ease,
    background-color 0.18s ease,
    box-shadow 0.18s ease,
    transform 0.18s ease;
}

.template-tool-button.icon-only {
  width: 36px;
  min-width: 36px;
  padding: 0;
  font-size: 1rem;
}

.template-tool-icon {
  width: 24px;
  height: 24px;
  stroke: currentColor;
  stroke-width: 2.05;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: 0 0 auto;
}

.template-tool-button:hover,
.template-tool-button:focus-visible,
.template-toolbar-select:focus,
.template-toolbar-font-size-combo.open .template-toolbar-font-size-input {
  border-color: rgba(var(--glass-primary-rgb), 0.7);
  box-shadow: 0 0 0 3px rgba(var(--glass-primary-rgb), 0.12);
}

.template-tool-button:active {
  transform: translateY(1px);
}

.template-tool-button.is-active,
.template-tool-button[aria-pressed="true"] {
  border-color: rgba(var(--glass-primary-rgb), 0.78);
  background: rgba(var(--glass-primary-rgb), 0.12);
  color: var(--glass-link);
}

.template-tool-button.type-emphasis {
  min-width: 38px;
  padding: 0;
  font-size: 0.92rem;
}

.template-tool-button.icon-only.type-emphasis {
  width: 36px;
  min-width: 36px;
}

.template-tool-button[data-template-command="bold"] {
  font-weight: 700;
}

.template-tool-button[data-template-command="italic"] {
  font-style: italic;
}

.template-tool-button[data-template-command="underline"] {
  text-decoration: underline;
}

.template-toolbar-table-insert-popover {
  position: relative;
  display: inline-flex;
}

.template-toolbar-table-insert-popover.open {
  z-index: 20;
}

.template-toolbar-table-insert-popover.open .template-toolbar-table-insert-toggle {
  border-color: rgba(var(--glass-primary-rgb), 0.78);
  background: rgba(var(--glass-primary-rgb), 0.12);
  color: var(--glass-link);
}

.template-table-insert-panel {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  width: min(248px, calc(100vw - 56px));
  padding: 10px;
  border: 1px solid rgba(var(--glass-line-rgb), 0.92);
  border-radius: 12px;
  background: var(--glass-surface);
  box-shadow: var(--glass-shadow);
}

.template-toolbar-subfield {
  display: grid;
  gap: 6px;
  color: var(--text-dim);
  font-size: 0.74rem;
  font-weight: 700;
}

.template-toolbar-subfield-wide {
  grid-column: 1 / -1;
}

.template-toolbar-subfield .template-toolbar-number {
  width: 100%;
}

.template-toolbar-cell-split-panel {
  grid-template-columns: minmax(0, 1fr);
  gap: 8px;
  width: min(176px, calc(100vw - 56px));
  align-items: stretch;
}

.template-toolbar-choice-field {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.template-toolbar-choice-field > legend {
  margin: 0 0 6px;
  padding: 0;
  color: var(--text-dim);
  font-size: 0.74rem;
  font-weight: 700;
}

.template-toolbar-choice-group {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.template-toolbar-choice-option {
  min-width: 0;
}

.template-toolbar-choice-option > span {
  min-height: 34px;
  border: 1px solid rgba(var(--glass-line-rgb), 0.95);
  border-radius: 11px;
  background: var(--glass-surface);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  font-size: 0.79rem;
  font-weight: 700;
  cursor: pointer;
  transition: border-color 0.18s ease,
    background-color 0.18s ease,
    box-shadow 0.18s ease;
}

.template-toolbar-choice-option > input:checked + span {
  border-color: rgba(var(--glass-primary-rgb), 0.78);
  background: rgba(var(--glass-primary-rgb), 0.12);
  color: var(--glass-link);
}

.template-toolbar-choice-option > input:focus-visible + span {
  border-color: rgba(var(--glass-primary-rgb), 0.7);
  box-shadow: 0 0 0 3px rgba(var(--glass-primary-rgb), 0.12);
}

.template-toolbar-number-stepper {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 24px;
  gap: 6px;
  align-items: stretch;
  width: 100%;
}

.template-toolbar-number-stepper-input {
  appearance: textfield;
  -webkit-appearance: none;
  -moz-appearance: textfield;
}

.template-toolbar-number-stepper-input::-webkit-inner-spin-button,
.template-toolbar-number-stepper-input::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.template-toolbar-number-stepper-controls {
  display: grid;
  grid-template-rows: repeat(2, minmax(0, 1fr));
  gap: 4px;
}

.template-toolbar-number-stepper-button {
  padding: 0;
  border: 1px solid rgba(var(--glass-line-rgb), 0.95);
  border-radius: 8px;
  background: var(--glass-surface);
  color: var(--glass-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font: inherit;
  font-size: 0.62rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  transition: border-color 0.18s ease,
    background-color 0.18s ease,
    box-shadow 0.18s ease;
}

.template-toolbar-number-stepper-button:hover,
.template-toolbar-number-stepper-button:focus-visible {
  border-color: rgba(var(--glass-primary-rgb), 0.7);
  background: rgba(var(--glass-primary-rgb), 0.08);
  box-shadow: 0 0 0 3px rgba(var(--glass-primary-rgb), 0.12);
  outline: none;
}

.template-toolbar-color-picker {
  position: relative;
  display: grid;
  width: max-content;
  max-width: 100%;
  min-width: 0;
}

.template-toolbar-color-picker.open {
  z-index: 20;
}

.template-toolbar-color-picker-compact {
  width: 100%;
}

.template-toolbar-color-picker-align-end {
  justify-self: end;
}

.template-toolbar-color-trigger {
  width: 90px;
  min-width: 90px;
  max-width: 90px;
  min-height: 36px;
  padding: 0 8px;
  border: 1px solid rgba(var(--glass-line-rgb), 0.95);
  border-radius: 12px;
  background: var(--glass-surface);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  gap: 10px;
  justify-content: flex-start;
  font: inherit;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  transition: border-color 0.18s ease,
    background-color 0.18s ease,
    box-shadow 0.18s ease;
}

.template-toolbar-color-picker-compact .template-toolbar-color-trigger {
  min-width: 0;
  padding: 0 8px;
  gap: 5px;
  font-size: 0.75rem;
}

.template-toolbar-color-trigger:hover,
.template-toolbar-color-trigger:focus-visible,
.template-toolbar-color-picker.open .template-toolbar-color-trigger {
  border-color: rgba(var(--glass-primary-rgb), 0.7);
  box-shadow: 0 0 0 3px rgba(var(--glass-primary-rgb), 0.12);
  outline: none;
}

.template-toolbar-color-trigger-swatch,
.template-toolbar-color-direct-swatch {
  width: 18px;
  height: 18px;
  border: 1px solid rgba(var(--glass-line-rgb), 0.52);
  border-radius: 6px;
  background: var(--editor-toolbar-current-color);
  box-shadow: inset 0 0 0 1px rgba(88, 121, 143, 0.62);
  flex: 0 0 auto;
}

.template-toolbar-color-trigger-label {
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.template-toolbar-color-trigger-caret {
  width: 0;
  height: 0;
  margin-left: auto;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 6px solid var(--glass-line);
  transform: translateY(1px);
}

.template-toolbar-color-panel {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  z-index: 30;
  display: grid;
  gap: 10px;
  width: min(232px, calc(100vw - 56px));
  padding: 10px;
  border: 1px solid rgba(var(--glass-line-rgb), 0.92);
  border-radius: 12px;
  background: var(--glass-surface);
  box-shadow: var(--glass-shadow);
}

.template-toolbar-color-picker.open-up .template-toolbar-color-panel {
  top: auto;
  bottom: calc(100% + 8px);
}

.template-toolbar-color-picker-align-end .template-toolbar-color-panel {
  right: 0;
  left: auto;
}

.template-toolbar-color-presets {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 32px));
  gap: 8px;
}

.template-toolbar-color-swatch {
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid rgba(var(--glass-line-rgb), 0.96);
  border-radius: 10px;
  background: var(--editor-toolbar-swatch-color);
  box-shadow: inset 0 0 0 1px rgba(88, 121, 143, 0.58);
  cursor: pointer;
  transition: border-color 0.18s ease,
    box-shadow 0.18s ease,
    transform 0.18s ease;
}

.template-toolbar-color-swatch:hover,
.template-toolbar-color-swatch:focus-visible {
  border-color: rgba(var(--glass-primary-rgb), 0.7);
  box-shadow: 0 0 0 3px rgba(var(--glass-primary-rgb), 0.12),
    inset 0 0 0 1px rgba(88, 121, 143, 0.58);
  outline: none;
}

.template-toolbar-color-swatch:active {
  transform: translateY(1px);
}

.template-toolbar-color-swatch.active,
.template-toolbar-color-swatch[aria-pressed="true"] {
  border-color: rgba(var(--glass-primary-rgb), 0.82);
  box-shadow: 0 0 0 3px rgba(var(--glass-primary-rgb), 0.16),
    inset 0 0 0 1px rgba(88, 121, 143, 0.58);
}

.template-toolbar-color-panel-actions {
  display: flex;
  align-items: center;
  justify-content: flex-start;
}

.template-toolbar-color-direct-button {
  width: 100%;
  min-height: 34px;
  padding: 0 12px;
  border: 1px dashed rgba(var(--glass-line-rgb), 0.92);
  border-radius: 10px;
  background: var(--glass-surface);
  color: var(--glass-muted);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font: inherit;
  font-size: 0.75rem;
  font-weight: 700;
  cursor: pointer;
  transition: border-color 0.18s ease,
    background-color 0.18s ease,
    box-shadow 0.18s ease;
}

.template-toolbar-color-direct-button:hover,
.template-toolbar-color-direct-button:focus-visible {
  border-color: rgba(var(--glass-primary-rgb), 0.58);
  background: rgba(var(--glass-bg-rgb), 0.98);
  box-shadow: 0 0 0 3px rgba(var(--glass-primary-rgb), 0.1);
  outline: none;
}

.template-toolbar-color-field {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
}

.template-toolbar-color {
  width: 44px;
  height: 36px;
  padding: 3px;
  border: 1px solid rgba(var(--glass-line-rgb), 0.95);
  border-radius: 10px;
  background: var(--glass-surface);
  cursor: pointer;
}

.template-toolbar-color::-webkit-color-swatch-wrapper {
  padding: 0;
}

.template-toolbar-color::-webkit-color-swatch {
  border: 0;
  border-radius: 7px;
}

.template-toolbar-color::-moz-color-swatch {
  border: 0;
  border-radius: 7px;
}

.template-toolbar-color-input-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
  opacity: 0;
  pointer-events: none;
}

@media (max-width: 920px) {
  .template-toolbar-section-row-dual,
  .template-toolbar-section-row-format,
  .template-toolbar-border-controls {
    grid-template-columns: minmax(0, 1fr);
  }

  .template-toolbar-color-picker-align-end {
    justify-self: start;
  }

  .template-toolbar-color-picker-align-end .template-toolbar-color-panel {
    right: auto;
    left: 0;
  }
}

.template-table-insert-panel .template-tool-button {
  grid-column: 1 / -1;
}

.template-editor-page {
  grid-column: 3;
  grid-row: 1 / 3;
  position: relative;
  min-width: var(--template-editor-canvas-width);
  min-height: 0;
  padding: 0;
  overflow-x: hidden;
  overflow-y: auto;
}

.template-editor-surface,
.template-render-sheet {
  color: var(--text);
  line-height: 1.5;
}

.template-editor-surface {
  position: relative;
  width: var(--template-editor-canvas-width);
  height: 1123px;
  margin: 0 auto;
  padding: 44px 46px;
  overflow: auto;
  border-radius: 0;
  background: #ffffff;
  box-shadow: 0 24px 60px rgba(31, 41, 55, 0.12);
  outline: none;
  white-space: normal;
  word-break: break-word;
}

.template-editor-surface .template-doc,
.template-render-sheet .template-doc {
  position: relative;
  min-height: 100%;
}

.template-editor-surface .template-doc {
  border: 1px dashed rgba(45, 99, 245, 0.34);
  border-radius: 0;
  background: linear-gradient(180deg, rgba(247, 250, 255, 0.55), rgba(255, 255, 255, 0.94));
}

.template-editor-surface h1,
.template-editor-surface h2,
.template-editor-surface h3,
.template-render-sheet h1,
.template-render-sheet h2,
.template-render-sheet h3 {
  margin-top: 0;
}

.template-editor-surface p,
.template-render-sheet p {
  margin: 0 0 8px;
}

.template-editor-surface img,
.template-render-sheet img {
  display: block;
  max-width: 100%;
  height: auto;
}

.template-editor-surface .template-generated-object,
.template-render-sheet .template-generated-object,
.template-preview-stage .template-generated-object {
  background: #ffffff;
}

.template-editor-surface .template-generated-object-barcode,
.template-render-sheet .template-generated-object-barcode,
.template-preview-stage .template-generated-object-barcode {
  object-fit: fill;
}

.template-editor-surface .template-generated-object-qrcode,
.template-render-sheet .template-generated-object-qrcode,
.template-preview-stage .template-generated-object-qrcode {
  object-fit: contain;
}

.template-editor-surface img.template-editor-image-object {
  cursor: pointer;
  touch-action: none;
}

.template-editor-surface img.template-editor-image-object.is-selected-object {
  outline: 2px solid rgba(var(--glass-primary-rgb), 0.38);
  outline-offset: 4px;
  cursor: grab;
}

.template-editor-surface img.template-editor-image-object.is-floating-object {
  max-width: 100%;
}

.template-editor-surface img.template-editor-image-object.is-moving-object {
  cursor: grabbing;
  z-index: 3;
}

.template-editor-surface.is-image-moving {
  user-select: none;
  cursor: grabbing;
}

.template-editor-surface.is-image-resizing {
  user-select: none;
  cursor: nwse-resize;
}

.template-editor-image-selection {
  position: absolute;
  z-index: 4;
  border: 2px solid rgba(var(--glass-primary-rgb), 0.82);
  border-radius: 12px;
  box-shadow: 0 0 0 1px rgba(88, 121, 143, 0.96), 0 10px 22px rgba(var(--glass-primary-rgb), 0.16);
  pointer-events: none;
}

.template-editor-image-selection.is-resizing {
  box-shadow: 0 0 0 1px rgba(88, 121, 143, 0.96), 0 14px 28px rgba(var(--glass-primary-rgb), 0.22);
}

.template-editor-image-resize-handle {
  position: absolute;
  right: -9px;
  bottom: -9px;
  width: 18px;
  height: 18px;
  padding: 0;
  border: 2px solid var(--glass-line);
  border-radius: 999px;
  background: var(--glass-button);
  box-shadow: var(--glass-shadow);
  cursor: nwse-resize;
  pointer-events: auto;
}

.template-render-sheet .examinee-photo-token-image,
.template-preview-stage .examinee-photo-token-image {
  width: 100%;
  max-width: 100%;
  height: 100%;
  min-height: 120px;
  object-fit: cover;
}

.template-render-sheet td.examinee-photo-token-cell,
.template-render-sheet th.examinee-photo-token-cell,
.template-preview-stage td.examinee-photo-token-cell,
.template-preview-stage th.examinee-photo-token-cell {
  position: relative;
  overflow: hidden;
  padding: 0 !important;
  line-height: 0;
  text-align: center;
  vertical-align: middle;
}

.template-render-sheet .examinee-photo-token-cell .examinee-photo-token-image,
.template-preview-stage .examinee-photo-token-cell .examinee-photo-token-image {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  min-height: 100%;
  max-width: none;
  max-height: none;
  margin: 0;
  object-fit: contain;
  background: #ffffff;
}

.template-render-sheet .examinee-photo-token-cell .examinee-photo-placeholder,
.template-preview-stage .examinee-photo-token-cell .examinee-photo-placeholder {
  position: absolute;
  inset: 0;
  width: 100%;
  max-width: none;
  margin: 0;
}

.examinee-photo-placeholder {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 120px;
  padding: 12px;
  border: 1px dashed rgba(138, 154, 181, 0.92);
  color: #53627a;
  font-size: 13px;
  font-weight: 700;
  text-align: center;
  background: rgba(246, 248, 252, 0.92);
}

.template-editor-surface table,
.template-render-sheet table {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  margin: 16px 0;
  border-collapse: collapse;
  table-layout: fixed;
}

.template-editor-surface th,
.template-editor-surface td,
.template-render-sheet th,
.template-render-sheet td {
  padding: 5px 6px;
  text-align: left;
  border: 1px solid #000000;
  min-width: 88px;
  vertical-align: top;
}

.template-editor-surface th,
.template-render-sheet th {
  background: #f6f8fc;
}

.template-editor-surface td.is-active-cell,
.template-editor-surface th.is-active-cell {
  background: var(--glass-surface);
  outline: 2px solid rgba(var(--glass-primary-rgb), 0.72);
  outline-offset: -2px;
}

.template-editor-surface td.is-selected-cell,
.template-editor-surface th.is-selected-cell {
  background: rgba(var(--glass-primary-rgb), 0.14);
  outline: 2px solid rgba(var(--glass-primary-rgb), 0.82);
  outline-offset: -2px;
}

.template-editor-surface.is-table-selecting,
.template-editor-surface.is-table-resizing {
  user-select: none;
}

.template-editor-surface.is-table-column-hover,
.template-editor-surface.is-table-column-resizing {
  cursor: col-resize;
}

.template-editor-surface.is-table-row-hover,
.template-editor-surface.is-table-row-resizing {
  cursor: row-resize;
}

.template-editor-surface hr,
.template-render-sheet hr {
  border: 0;
  border-top: 1px solid #d8e0ea;
  margin: 18px 0;
}
