.templates-page,
.template-form-page {
  width: min(920px, 100%);
}

.templates-page__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--wf-space-4);
}

.templates-page__head h2,
.templates-page__head p,
.template-form-page h2,
.template-form-page p {
  margin: 0;
}

.templates-page__head p,
.template-form-page__intro {
  margin-top: var(--wf-space-2);
  color: var(--wf-text-subtle);
}

.template-directory-tools {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--wf-space-4);
  margin-block: var(--wf-space-5);
  padding: var(--wf-space-4);
  border: 1px solid var(--wf-border);
  border-radius: var(--wf-radius-3);
  background: var(--wf-gray-25);
}

.template-directory {
  overflow: hidden;
  border: 1px solid var(--wf-border);
  border-radius: var(--wf-radius-3);
  background: var(--wf-surface);
}

.template-directory__row {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(220px, 1fr);
  align-items: center;
  gap: var(--wf-space-3);
  min-height: 64px;
  padding: var(--wf-space-3) var(--wf-space-4);
}

.template-directory__row + .template-directory__row {
  border-top: 1px solid var(--wf-border);
}

.template-directory__row--head {
  min-height: 42px;
  background: var(--wf-gray-50);
  color: var(--wf-text-subtle);
  font-size: var(--wf-text-xs);
  font-weight: 700;
}

.template-directory__name {
  color: var(--wf-text);
  font-size: var(--wf-text-sm);
  font-weight: 700;
  text-decoration: none;
}

.template-directory__name:hover {
  text-decoration: underline;
}

.template-directory__subject {
  min-width: 0;
  overflow: hidden;
  color: var(--wf-text-subtle);
  font-size: var(--wf-text-sm);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.template-directory__empty {
  padding: var(--wf-space-8);
  color: var(--wf-text-subtle);
  text-align: center;
}

.template-form-page {
  display: flex;
  flex-direction: column;
  gap: var(--wf-space-5);
}

.template-form__surface {
  display: flex;
  flex-direction: column;
  gap: var(--wf-space-4);
  padding: var(--wf-space-5);
  border: 1px solid var(--wf-border);
  border-radius: var(--wf-radius-3);
  background: var(--wf-surface);
}

.template-form__message {
  min-height: 220px;
  resize: vertical;
}

.template-variables {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--wf-space-2);
}

.template-variables__label {
  color: var(--wf-text-subtle);
  font-size: var(--wf-text-xs);
  font-weight: 700;
}

.template-variable {
  min-height: 30px;
  padding-inline: var(--wf-space-3);
}

.template-form__actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--wf-space-3);
}

.template-form__actions-end {
  display: flex;
  gap: var(--wf-space-3);
  margin-left: auto;
}

.template-form__status {
  min-height: 20px;
  margin: 0;
  color: var(--wf-text-subtle);
  font-size: var(--wf-text-sm);
}

@media (max-width: 759.98px) {
  .templates-page__head {
    align-items: stretch;
    flex-direction: column;
  }

  .template-directory-tools {
    grid-template-columns: 1fr;
  }

  .template-directory__row--head {
    display: none;
  }

  .template-directory__row {
    grid-template-columns: minmax(0, 1fr);
    gap: var(--wf-space-2) var(--wf-space-3);
    padding: var(--wf-space-4);
  }

  .template-directory__name,
  .template-directory__subject {
    grid-column: 1;
  }

  .template-form__actions {
    align-items: stretch;
    flex-direction: column-reverse;
  }

  .template-form__actions-end {
    display: grid;
    grid-template-columns: 1fr 1fr;
    margin-left: 0;
  }
}
