.template-library-modal {
  width: min(1180px, calc(100vw - 28px));
  max-height: 92vh;
  padding: 0;
  overflow: hidden;
}

.template-library-modal > form {
  display: grid;
  grid-template-rows: auto minmax(170px, 1fr) auto;
  gap: 0;
  max-height: 92vh;
}

.template-modal-heading {
  margin: 0;
  padding: 26px 30px 20px;
  border-bottom: 1px solid var(--line);
}

.template-modal-heading h2 {
  margin-bottom: 8px;
}

.template-modal-heading > div > p:last-child,
.template-preview-modal .modal-heading > div > p:last-child {
  max-width: 700px;
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.7;
}

.template-picker {
  min-height: 0;
  padding: 22px 30px 30px;
  overflow: auto;
  background: #f7faf8;
}

.template-picker-toolbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 16px;
}

.template-picker-toolbar > div > strong,
.template-picker-toolbar > div > span {
  display: block;
}

.template-picker-toolbar > div > strong {
  font-size: 18px;
}

.template-picker-toolbar > div > span {
  margin-top: 5px;
  color: var(--muted);
  font-size: 11px;
}

.template-search {
  display: flex !important;
  align-items: center;
  grid-template-columns: auto 1fr;
  gap: 8px !important;
  width: min(300px, 100%);
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #fff;
}

.template-search span {
  color: #829089;
  font-size: 11px;
}

.template-search input {
  min-width: 0;
  padding: 0 !important;
  border: 0 !important;
  box-shadow: none !important;
}

.template-filters {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
  overflow: auto;
  scrollbar-width: none;
}

.template-filters::-webkit-scrollbar {
  display: none;
}

.template-filter {
  flex: none;
  padding: 8px 13px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.template-filter.active {
  border-color: var(--green);
  background: var(--green);
  color: #fff;
}

.template-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
}

.template-loading,
.template-no-result {
  grid-column: 1 / -1;
  padding: 70px 20px;
  border: 1px dashed #b9c9c1;
  border-radius: 18px;
  background: #fff;
  color: var(--muted);
  text-align: center;
}

.template-card {
  position: relative;
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 8px 24px rgba(20, 50, 39, .045);
  transition: .2s ease;
}

.template-card:hover {
  border-color: #8eaaa0;
  box-shadow: 0 16px 38px rgba(20, 50, 39, .1);
  transform: translateY(-2px);
}

.template-card.selected {
  border-color: var(--green-2);
  box-shadow: 0 0 0 3px rgba(36, 165, 118, .14), 0 16px 38px rgba(20, 50, 39, .1);
}

.template-card-select {
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
}

.template-thumb {
  position: relative;
  height: 148px;
  overflow: hidden;
  background: var(--tpl-bg);
  color: var(--tpl-text);
}

.template-thumb::before {
  position: absolute;
  top: 13px;
  left: 14px;
  width: 54px;
  height: 7px;
  border-radius: 99px;
  background: var(--tpl-text);
  content: "";
  opacity: .9;
}

.template-thumb::after {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 58px;
  height: 5px;
  border-radius: 99px;
  background: var(--tpl-text);
  box-shadow: -23px 0 0 color-mix(in srgb, var(--tpl-text) 55%, transparent);
  content: "";
  opacity: .45;
}

.template-thumb-copy {
  position: absolute;
  z-index: 2;
  top: 46px;
  left: 14px;
  width: 58%;
}

.template-thumb-copy i,
.template-thumb-copy b,
.template-thumb-copy span {
  display: block;
  border-radius: 99px;
}

.template-thumb-copy i {
  width: 38px;
  height: 4px;
  margin-bottom: 9px;
  background: var(--tpl-accent);
}

.template-thumb-copy b {
  width: 100%;
  height: 10px;
  margin-bottom: 6px;
  background: var(--tpl-text);
  box-shadow: 0 16px 0 color-mix(in srgb, var(--tpl-text) 82%, transparent);
}

.template-thumb-copy span {
  width: 45px;
  height: 15px;
  margin-top: 31px;
  background: var(--tpl-accent);
}

.template-thumb-art {
  position: absolute;
  right: -13px;
  bottom: -20px;
  width: 116px;
  height: 116px;
  border-radius: 38% 62% 55% 45%;
  background: var(--tpl-primary);
  box-shadow: -16px -10px 0 color-mix(in srgb, var(--tpl-accent) 52%, transparent);
}

.template-thumb-art::before {
  position: absolute;
  top: 27px;
  left: 23px;
  width: 61px;
  height: 46px;
  border: 1px solid rgba(255, 255, 255, .55);
  border-radius: 8px;
  background: rgba(255, 255, 255, .17);
  content: "";
}

.template-thumb[data-layout="centered"] .template-thumb-copy {
  left: 25%;
  width: 50%;
  text-align: center;
}

.template-thumb[data-layout="centered"] .template-thumb-copy i,
.template-thumb[data-layout="centered"] .template-thumb-copy span {
  margin-right: auto;
  margin-left: auto;
}

.template-thumb[data-layout="centered"] .template-thumb-art {
  right: 34%;
  bottom: -67px;
}

.template-thumb[data-layout="editorial"] .template-thumb-art {
  right: 0;
  bottom: 0;
  height: 105px;
  border-radius: 0;
}

.template-thumb[data-layout="editorial"] .template-thumb-copy {
  width: 48%;
}

.template-thumb[data-layout="bold"] .template-thumb-copy {
  width: 76%;
}

.template-thumb[data-layout="bold"] .template-thumb-copy b {
  height: 13px;
}

.template-thumb[data-layout="bold"] .template-thumb-art {
  right: -35px;
  opacity: .65;
}

.template-badge {
  position: absolute;
  z-index: 4;
  top: 34px;
  right: 10px;
  padding: 4px 7px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .9);
  color: #26362f;
  font-size: 9px;
  font-weight: 900;
  box-shadow: 0 4px 12px rgba(0, 0, 0, .08);
}

.template-card-body {
  min-height: 121px;
  padding: 15px 15px 13px;
}

.template-card-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.template-card-title strong {
  font-size: 15px;
}

.template-card-title span {
  color: var(--muted);
  font-size: 9px;
}

.template-card-body p {
  min-height: 35px;
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.55;
}

.template-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 0 15px 13px;
}

.template-selected-label {
  color: var(--green);
  font-size: 10px;
  font-weight: 900;
  opacity: 0;
}

.template-card.selected .template-selected-label {
  opacity: 1;
}

.template-preview-button {
  padding: 6px 9px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  font-size: 10px;
  font-weight: 800;
}

.site-create-fields {
  display: grid;
  gap: 14px;
  padding: 22px 30px 26px;
  border-top: 1px solid var(--line);
  background: #fff;
  box-shadow: 0 -14px 40px rgba(16, 46, 35, .06);
}

.site-create-field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.selected-template-summary {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 11px;
}

.selected-template-summary strong {
  color: var(--green);
  font-size: 12px;
}

.template-preview-modal {
  width: min(1180px, calc(100vw - 28px));
  max-height: 94vh;
  padding: 22px;
  overflow: auto;
}

.template-preview-modal .modal-heading {
  margin-bottom: 18px;
}

.template-preview-browser {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #edf2ef;
  box-shadow: 0 24px 70px rgba(16, 46, 35, .13);
}

.template-preview-browser-bar {
  display: flex;
  align-items: center;
  gap: 7px;
  height: 38px;
  padding: 0 14px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.template-preview-browser-bar i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #f2b8ad;
}

.template-preview-browser-bar i:nth-child(2) {
  background: #f5d17d;
}

.template-preview-browser-bar i:nth-child(3) {
  background: #83d7ae;
}

.template-preview-browser-bar span {
  margin-left: auto;
  color: var(--muted);
  font-size: 10px;
  font-style: normal;
}

.template-preview-browser iframe {
  display: block;
  width: 100%;
  height: min(70vh, 760px);
  border: 0;
  background: #fff;
}

.template-preview-actions {
  display: flex;
  justify-content: flex-end;
  gap: 9px;
  margin-top: 18px;
}

@media (max-width: 980px) {
  .template-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .template-library-modal,
  .template-library-modal > form {
    max-height: 96vh;
  }

  .template-modal-heading,
  .template-picker,
  .site-create-fields {
    padding-right: 18px;
    padding-left: 18px;
  }

  .template-modal-heading > div > p:last-child {
    display: none;
  }

  .template-picker-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .template-search {
    width: 100%;
  }

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

  .site-create-field-grid {
    grid-template-columns: 1fr;
  }

  .site-create-fields > label {
    display: none;
  }

  .template-preview-modal {
    padding: 16px;
  }
}

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

  .template-thumb {
    height: 168px;
  }
}
