/* Structured A4 template canvas. This file is intentionally isolated from responsive app styles. */

.template-canvas-document {
  position: relative;
  width: var(--template-page-width, 210mm);
  min-width: var(--template-page-width, 210mm);
  max-width: var(--template-page-width, 210mm);
  height: var(--template-page-height, 297mm);
  min-height: var(--template-page-height, 297mm);
  max-height: var(--template-page-height, 297mm);
  margin: 0 auto;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--border-default);
  border-radius: 0;
  background: var(--surface-card);
  box-shadow: 0 8px 28px rgb(31 41 55 / 12%);
}

.template-canvas-page {
  display: block;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--surface-card);
}

.template-canvas-page-background {
  fill: var(--surface-card);
}

.template-canvas-element-content {
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  overflow: hidden;
  color: #111;
  overflow-wrap: anywhere;
  white-space: normal;
}

.template-canvas-element-content.writing-vertical-rl {
  display: block;
}

.template-canvas-hit-area {
  fill: transparent;
  stroke: transparent;
  stroke-width: 7;
  vector-effect: non-scaling-stroke;
  cursor: move;
  pointer-events: all;
  touch-action: none;
}

.template-canvas-element:hover .template-canvas-hit-area {
  fill: color-mix(in srgb, var(--selection-background) 40%, transparent);
  stroke: var(--selection-border);
  stroke-dasharray: 8 6;
}

.template-canvas-element.selected .template-canvas-hit-area {
  fill: var(--selection-background);
  stroke: var(--selection-border);
  stroke-width: 3;
  stroke-dasharray: none;
}

.template-canvas-element.selected .template-canvas-hit-area:focus-visible,
.template-canvas-hit-area:focus-visible {
  fill: var(--selection-background);
  stroke: var(--focus-ring);
  stroke-width: 4;
  stroke-dasharray: none;
}

.template-canvas-schedule {
  width: 100%;
  height: 100%;
  box-sizing: border-box;
}

.template-canvas-schedule.memorial {
  display: grid;
  align-content: start;
  grid-auto-rows: minmax(min-content, auto);
  border-top: 1px solid currentColor;
}

.template-canvas-schedule.memorial .template-canvas-schedule-header,
.template-canvas-schedule.memorial .template-canvas-schedule-row {
  display: grid;
  grid-template-columns: 1.2fr 1.2fr 1fr 0.8fr;
}

.template-canvas-schedule.memorial span,
.template-canvas-schedule.memorial strong {
  min-width: 0;
  padding: 0.45em 0.55em;
  border-right: 1px solid currentColor;
  border-bottom: 1px solid currentColor;
  font: inherit;
}

.template-canvas-schedule.memorial .template-canvas-schedule-header > :first-child,
.template-canvas-schedule.memorial .template-canvas-schedule-row > :first-child {
  border-left: 1px solid currentColor;
}

.template-canvas-schedule.memorial .template-canvas-schedule-header {
  font-weight: 700;
}

.template-canvas-schedule.chuin,
.template-canvas-schedule.anniversary {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  gap: 0.55em;
}

.template-canvas-schedule.chuin .template-canvas-schedule-row,
.template-canvas-schedule.anniversary .template-canvas-schedule-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 2em;
}

.template-canvas-schedule.chuin strong,
.template-canvas-schedule.anniversary strong {
  font: inherit;
  font-weight: 700;
}

.template-canvas-schedule-row.needs-review {
  color: var(--status-danger);
}

.writing-vertical-rl .template-canvas-schedule.chuin,
.writing-vertical-rl .template-canvas-schedule.anniversary {
  flex-direction: row-reverse;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 1em;
}

.writing-vertical-rl .template-canvas-schedule.chuin .template-canvas-schedule-row,
.writing-vertical-rl .template-canvas-schedule.anniversary .template-canvas-schedule-row {
  flex-direction: column;
  justify-content: flex-start;
  gap: 0.8em;
}

.template-canvas-editor {
  display: grid;
  gap: 14px;
}

.template-canvas-editor-heading {
  display: grid;
  align-items: end;
  gap: 12px;
  grid-template-columns: minmax(240px, 1fr) minmax(150px, 0.55fr) minmax(140px, 0.45fr) minmax(120px, 0.35fr);
}

.template-canvas-toolbar {
  position: sticky;
  z-index: 8;
  top: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 4px 14px rgba(27, 47, 40, 0.08);
}

.template-canvas-toolbar .toolbar-spacer {
  flex: 1;
}

.template-canvas-toolbar .form-field {
  width: 120px;
  gap: 3px;
}

.template-canvas-editor-layout {
  display: grid;
  align-items: start;
  gap: 14px;
  grid-template-columns: minmax(190px, 0.36fr) minmax(0, 1.35fr) minmax(245px, 0.46fr);
}

.template-canvas-palette,
.template-canvas-properties {
  position: sticky;
  top: 76px;
  display: grid;
  max-height: calc(100vh - 130px);
  gap: 12px;
  padding: 12px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.template-canvas-palette h3,
.template-canvas-properties h3 {
  margin: 0;
  font-size: 16px;
}

.template-canvas-palette-group {
  display: grid;
  gap: 7px;
}

.template-canvas-palette-group button {
  justify-content: flex-start;
  text-align: left;
}

.template-canvas-element-list {
  display: grid;
  gap: 5px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.template-canvas-element-list button {
  width: 100%;
  justify-content: flex-start;
  text-align: left;
}

.template-canvas-element-list button.active {
  border-color: var(--selection-border);
  box-shadow: inset 4px 0 0 var(--selection-border);
  background: var(--selection-background);
  color: var(--selection-foreground);
  font-weight: 700;
}

.template-canvas-preview-stage {
  min-width: 0;
  padding: 18px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(45deg, var(--border-default) 25%, transparent 25%),
    linear-gradient(-45deg, var(--border-default) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, var(--border-default) 75%),
    linear-gradient(-45deg, transparent 75%, var(--border-default) 75%);
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  background-size: 16px 16px;
}

.template-canvas-editor-preview {
  --template-editor-zoom: 0.75;
  width: calc(var(--template-page-width, 210mm) * var(--template-editor-zoom));
  height: calc(var(--template-page-height, 297mm) * var(--template-editor-zoom));
  margin: 0 auto;
}

.template-canvas-editor-preview > .template-canvas-document {
  margin: 0;
  transform: scale(var(--template-editor-zoom));
  transform-origin: left top;
}

.template-canvas-properties .form-grid {
  gap: 8px;
}

.template-canvas-properties .form-field {
  gap: 4px;
}

.template-canvas-protected-notice {
  padding: 8px 10px;
  border: 1px solid var(--status-info);
  border-radius: 6px;
  background: var(--status-info-soft);
  color: var(--status-info);
  font-size: 13px;
}

.template-canvas-status-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.template-canvas-status-column {
  display: grid;
  align-content: start;
  gap: 9px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.template-canvas-status-column > h4 {
  margin: 0;
}

.template-canvas-template-card {
  display: grid;
  gap: 7px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface-card);
}

.template-canvas-template-card .item-actions {
  flex-wrap: wrap;
  justify-content: flex-start;
}

.template-canvas-migration-notice {
  grid-column: 1 / -1;
}

.template-canvas-document.pdf-capture-page {
  width: var(--template-page-width, 210mm);
  min-width: var(--template-page-width, 210mm);
  max-width: var(--template-page-width, 210mm);
  height: var(--template-page-height, 297mm);
  min-height: var(--template-page-height, 297mm);
  max-height: var(--template-page-height, 297mm);
  padding: 0;
  border: 0;
  box-shadow: none;
}

.template-canvas-document.pdf-capture-page .template-canvas-hit-area {
  display: none;
}

@media (max-width: 1180px) {
  .template-canvas-editor-layout {
    grid-template-columns: minmax(180px, 0.42fr) minmax(0, 1fr);
  }

  .template-canvas-properties {
    position: static;
    max-height: none;
    grid-column: 1 / -1;
  }
}

@media (max-width: 700px) {
  .template-canvas-editor-heading,
  .template-canvas-editor-layout,
  .template-canvas-status-grid {
    grid-template-columns: 1fr;
  }

  .template-canvas-palette,
  .template-canvas-properties {
    position: static;
    max-height: none;
  }

  .template-canvas-preview-stage {
    min-height: 420px;
  }
}
