[data-module-panel="templates"] {
  --template-border: #e7ded6;
  --template-ink: #2b2826;
  --template-muted: #776e68;
}

.printly-templates {
  display: grid;
  gap: 14px;
}

.printly-templates__header,
.printly-templates__footer,
.printly-template-card__body,
.printly-template-card__actions,
.printly-template-preview__actions {
  align-items: center;
  display: flex;
  gap: 8px;
  justify-content: space-between;
}

.printly-templates__header h3,
.printly-template-card h4,
.printly-template-preview h3 {
  color: var(--template-ink);
  margin: 2px 0 0;
}

.printly-templates__header small,
.printly-template-card small,
.printly-template-card__meta,
.printly-templates__footer span {
  color: var(--template-muted);
}

.printly-templates__quick-filters {
  background: #f6f1ed;
  border-radius: 12px;
  display: grid;
  gap: 4px;
  grid-template-columns: repeat(4, 1fr);
  padding: 4px;
}

.printly-templates__quick-filters button {
  background: transparent;
  border: 0;
  border-radius: 9px;
  min-height: 36px;
}

.printly-templates__quick-filters button.is-active {
  background: #fff;
  box-shadow: 0 2px 8px rgba(43, 40, 38, .08);
  color: #d94f3c;
  font-weight: 700;
}

.printly-templates__filters {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.printly-templates__filters label,
.printly-template-preview label {
  display: grid;
  gap: 4px;
}

.printly-templates__filters span,
.printly-template-preview label span {
  color: var(--template-muted);
  font-size: 12px;
}

.printly-templates__filters select,
.printly-template-preview select {
  border: 1px solid var(--template-border);
  border-radius: 9px;
  min-height: 38px;
  width: 100%;
}

.printly-templates__scope {
  align-items: center;
  border-block: 1px solid var(--template-border);
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding-block: 10px;
}

.printly-templates__scope > span {
  font-weight: 700;
}

.printly-templates__grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  min-height: 180px;
}

.printly-template-card {
  background: #fff;
  border: 1px solid var(--template-border);
  border-radius: 14px;
  min-width: 0;
  overflow: hidden;
}

.printly-template-card.is-personal {
  border-color: #ef9c8e;
}

.printly-template-card__preview {
  aspect-ratio: 4 / 3;
  background: #f1ece7;
  border: 0;
  display: block;
  overflow: hidden;
  padding: 0;
  position: relative;
  width: 100%;
}

.printly-template-card__preview img {
  height: 100%;
  object-fit: cover;
  transition: transform .2s ease;
  width: 100%;
}

.printly-template-card:hover .printly-template-card__preview img {
  transform: scale(1.025);
}

.printly-template-card__placeholder {
  align-items: center;
  color: #d5c8bd;
  display: flex;
  font-size: 52px;
  font-weight: 800;
  height: 100%;
  justify-content: center;
}

.printly-template-card__badges {
  display: flex;
  gap: 5px;
  inset-block-start: 8px;
  inset-inline-start: 8px;
  position: absolute;
}

.printly-template-card__badges b,
.printly-template-preview__tags span {
  background: rgba(255, 255, 255, .94);
  border-radius: 99px;
  color: #5c534d;
  font-size: 10px;
  padding: 4px 7px;
}

.printly-template-card__badges .is-premium {
  background: #2b2826;
  color: #fff;
}

.printly-template-card__body,
.printly-template-card__meta,
.printly-template-card__actions {
  padding-inline: 10px;
}

.printly-template-card__body {
  padding-block-start: 10px;
}

.printly-template-card__favorite {
  background: transparent;
  border: 0;
  color: #b8aca3;
  font-size: 20px;
  padding: 4px;
}

.printly-template-card__favorite.is-active {
  color: #ee5c49;
}

.printly-template-card__meta {
  display: flex;
  font-size: 10px;
  gap: 6px;
  justify-content: space-between;
  min-height: 26px;
  padding-block: 5px;
}

.printly-template-card__actions {
  border-top: 1px solid #f0e8e2;
  padding-block: 8px;
}

.printly-template-card__actions button:first-child,
.printly-template-preview__actions button:first-child {
  background: #ee5c49;
  border-color: #ee5c49;
  color: #fff;
}

.printly-templates__empty {
  background: #f8f4f0;
  border-radius: 14px;
  grid-column: 1 / -1;
  padding: 28px 18px;
  text-align: center;
}

.printly-templates__dialog {
  border: 0;
  border-radius: 18px;
  box-shadow: 0 24px 80px rgba(35, 27, 22, .28);
  max-width: min(760px, calc(100vw - 24px));
  padding: 0;
  width: 760px;
}

.printly-templates__dialog::backdrop {
  background: rgba(35, 27, 22, .58);
}

.printly-templates__dialog-card {
  padding: 20px;
  position: relative;
}

.printly-templates__dialog-close {
  background: #fff;
  border: 1px solid var(--template-border);
  border-radius: 50%;
  height: 36px;
  inset-block-start: 10px;
  inset-inline-end: 10px;
  position: absolute;
  width: 36px;
  z-index: 2;
}

.printly-template-preview {
  display: grid;
  gap: 20px;
  grid-template-columns: minmax(240px, 1.15fr) minmax(220px, .85fr);
}

.printly-template-preview__image {
  align-items: center;
  background: #f3ede8;
  border-radius: 14px;
  display: flex;
  justify-content: center;
  min-height: 320px;
  overflow: hidden;
}

.printly-template-preview__image img {
  height: 100%;
  object-fit: contain;
  width: 100%;
}

.printly-template-preview__details {
  display: grid;
  gap: 10px;
}

.printly-template-preview__tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

@media (max-width: 860px) {
  .printly-templates__grid {
    grid-template-columns: repeat(2, minmax(135px, 1fr));
  }

  .printly-template-preview {
    grid-template-columns: 1fr;
  }

  .printly-template-preview__image {
    min-height: 220px;
  }

  .printly-templates__dialog {
    border-radius: 18px 18px 0 0;
    margin-block-end: 0;
    max-height: 90dvh;
    overflow: auto;
    width: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  .printly-template-card__preview img {
    transition: none;
  }
}
