.templates-page,
.template-detail-page {
  max-width: 1440px;
  margin: 0 auto;
  padding: 0 clamp(16px, 5vw, 80px) calc(clamp(80px, 11vh, 120px) + clamp(25px, 3.5vh, 40px));
}

/* Деталь шаблона: без «листа страницы вправо в пустоту» из‑за ширины ленты похожих */
.template-detail-page {
  width: 100%;
  max-width: min(1440px, 100%);
  box-sizing: border-box;
  overflow-x: clip;
}

.templates-page[data-user-id]:not([data-user-id=""]) {
  padding-bottom: calc(clamp(92px, 13vh, 136px) + clamp(28px, 4vh, 46px));
}

.templates-page-header h1 {
  font-size: 28px;
  line-height: 1.2;
}

.templates-page-header p {
  margin-top: 8px;
  color: rgba(255, 255, 255, 0.8);
}

.templates-hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: clamp(12px, 2vh, 22px);
  margin-bottom: 10px;
  padding: clamp(12px, 1.8vw, 18px);
  border-radius: clamp(12px, 2vh, 20px);
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.templates-hero__left {
  min-width: 0;
}

.templates-hero__title {
  margin: 0;
  font-size: clamp(20px, 2.2vw, 30px);
  line-height: 1.2;
}

.templates-hero__subtitle {
  margin: 6px 0 0;
  color: rgba(255, 255, 255, 0.82);
  font-size: clamp(12px, 1.2vw, 15px);
}

.templates-hero__right {
  min-width: min(420px, 100%);
  flex: 0 0 min(420px, 100%);
}

.templates-search-input {
  width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  border-radius: 14px;
  padding: 11px 14px;
  font-size: 14px;
  outline: none;
}

.templates-search-input::placeholder {
  color: rgba(255, 255, 255, 0.95);
}

.templates-search-input::-webkit-search-cancel-button {
  -webkit-appearance: none;
  height: 14px;
  width: 14px;
  cursor: pointer;
  opacity: 0.95;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M4 4L12 12M12 4L4 12' stroke='white' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E") center / 14px 14px no-repeat;
}

.templates-search-input:focus {
  border-color: rgba(178, 48, 204, 0.85);
  box-shadow: 0 0 0 2px rgba(178, 48, 204, 0.2);
}

.templates-search-section {
  margin-top: 14px;
}

.templates-search-status {
  margin: 0 0 10px;
  font-size: 13px;
  color: rgba(255, 255, 255, 0.82);
}

.templates-filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: clamp(8px, 1.5vw, 20px);
  margin-top: clamp(15px, 3.5vh, 50px);
  margin-bottom: 4px;
}

.templates-filter-bar .templates-filter-chip {
  flex-shrink: 0;
}

.templates-filter-bar[hidden] {
  display: none !important;
}

.templates-collections-section {
  margin: 10px 0 8px;
}

.templates-collections-title {
  font-size: clamp(12px, 1.2vw, 15px);
  color: rgba(255, 255, 255, 0.72);
  margin-bottom: 8px;
}

.templates-collections-list {
  display: flex;
  flex-wrap: nowrap;
  gap: clamp(8px, 2vw, 12px);
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 2px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}

.templates-collection-card {
  /* Узкий экран — чуть компактнее, широкий — до ~прежнего максимума */
  width: clamp(90px, 21vw, 140px);
  flex: 0 0 clamp(90px, 21vw, 140px);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: clamp(10px, 2vw, 12px);
  background: rgba(255, 255, 255, 0.08);
  padding: 0;
  color: #fff;
  cursor: pointer;
  text-align: left;
  box-sizing: border-box;
}

.templates-collection-card.active {
  border-color: rgba(178, 48, 204, 0.9);
  box-shadow: 0 0 0 2px rgba(178, 48, 204, 0.24);
}

.templates-collection-card__preview {
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: clamp(9px, 1.8vw, 11px) clamp(9px, 1.8vw, 11px) 0 0;
  overflow: hidden;
  background: rgba(0, 0, 0, 0.25);
}

.templates-collection-card__preview img,
.templates-collection-card__preview video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.templates-collection-card__placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(8px, 2.2vw, 10px);
  color: rgba(255, 255, 255, 0.62);
}
.templates-collection-card__title {
  margin-top: clamp(5px, 1.2vw, 7px);
  padding: 0 clamp(5px, 1.6vw, 8px);
  font-size: clamp(10px, 2.6vw, 12px);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.templates-collection-card__count {
  margin-top: 2px;
  padding: 0 clamp(5px, 1.6vw, 8px) clamp(5px, 1.4vw, 7px);
  font-size: clamp(9px, 2.4vw, 11px);
  color: rgba(255, 255, 255, 0.75);
}

.templates-category-dropdown {
  position: relative;
  flex: 0 1 auto;
  min-width: 0;
  max-width: min(280px, 100%);
}

.templates-category-dropdown__trigger {
  width: 100%;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  text-align: left;
}

.templates-category-dropdown__label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.templates-category-dropdown__chevron {
  flex-shrink: 0;
  width: 12px;
  height: 8px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8' fill='none'%3E%3Cpath d='M1 1L6 6L11 1' stroke='white' stroke-width='2' stroke-opacity='0.75' stroke-linecap='round'/%3E%3C/svg%3E")
    center / contain no-repeat;
  opacity: 0.85;
  transition: transform 0.2s ease;
}

.templates-category-dropdown--open .templates-category-dropdown__chevron {
  transform: rotate(180deg);
}

.templates-category-dropdown--has-value .templates-category-dropdown__trigger {
  box-shadow: inset 0 0 0 1px rgba(178, 48, 204, 0.28);
}

.templates-category-dropdown__menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  z-index: 80;
  max-height: min(55vh, 320px);
  overflow-x: hidden;
  overflow-y: auto;
  padding: 6px;
  border-radius: clamp(12px, 2vh, 16px);
  background: rgba(18, 20, 42, 0.96);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.45);
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}

.templates-category-dropdown__menu[hidden] {
  display: none !important;
}

.templates-category-dropdown__option {
  display: block;
  width: 100%;
  margin: 0;
  padding: 10px 12px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: #fff;
  font-family: "Inter", sans-serif;
  font-size: clamp(12px, 1.4vw, 15px);
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s ease;
}

.templates-category-dropdown__option:hover {
  background: rgba(255, 255, 255, 0.1);
}

.templates-category-dropdown__option:focus-visible {
  outline: none;
  background: rgba(172, 75, 255, 0.2);
}

.templates-category-dropdown__option--selected {
  background: rgba(178, 48, 204, 0.22);
}

.templates-category-dropdown__option--selected:hover {
  background: rgba(178, 48, 204, 0.3);
}

.templates-grid,
.templates-history-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: 1fr;
}

.templates-grid {
  margin-top: 20px;
}

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

  .templates-hero__right {
    min-width: 0;
    flex: 1 1 auto;
  }
}

@media (min-width: 300px) {
  .templates-grid,
  .templates-history-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: 600px) {
  .templates-grid,
  .templates-history-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (min-width: 1000px) {
  .templates-grid,
  .templates-history-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

.template-card-link {
  color: inherit;
  text-decoration: none;
  display: block;
  -webkit-tap-highlight-color: transparent;
}

.template-card-link:hover {
  color: inherit;
  text-decoration: none;
}

.template-card-link[hidden] {
  display: none !important;
}

.template-card {
  background: rgba(10, 11, 29, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 16px;
  overflow: hidden;
  transition: transform 0.15s ease, border-color 0.15s ease;
  height: 100%;
  aspect-ratio: 1 / 1;
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}

.template-card::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  background: linear-gradient(
    to top,
    rgba(5, 8, 20, 0.82) 0%,
    rgba(5, 8, 20, 0.58) 26%,
    rgba(5, 8, 20, 0.22) 48%,
    rgba(5, 8, 20, 0.0) 72%
  );
}

.template-card-link:hover .template-card {
  transform: translateY(-2px);
  border-color: rgba(172, 75, 255, 0.8);
}

.template-preview {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.25);
}

.template-input-badge {
  position: absolute;
  top: 15px;
  left: 15px;
  z-index: 2;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.52);
  border: 1px solid rgba(255, 255, 255, 0.14);
  pointer-events: none;
}

.template-category-badge {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 2;
  display: inline-flex;
  align-items: center;
  max-width: calc(100% - 52px);
  padding: 4px 9px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  font-size: 11px;
  font-weight: 600;
  line-height: 1.15;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
}

.template-input-badge img {
  width: 18px;
  height: 18px;
  object-fit: contain;
  opacity: 0.92;
  filter: brightness(0) invert(1);
}

.template-preview img,
.template-preview video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
}

.template-preview-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255, 255, 255, 0.6);
  font-size: 13px;
}

.template-card-body {
  position: relative;
  z-index: 2;
  padding: 14px;
}

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

.template-card-title-row h3 {
  margin: 0;
  flex: 1;
  min-width: 0;
  font-size: clamp(11px, 2.5vw, 14px);
  font-weight: 400;
  line-height: 1.35;
  color: rgba(255, 255, 255, 0.92);
}

.template-card-link:hover .template-card-title-row h3 {
  color: rgba(255, 255, 255, 0.92);
}

.template-card-link:hover .template-price-value {
  color: rgba(255, 255, 255, 0.92);
}

.template-price-inline {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
  margin-top: 1px;
}

.template-price-value {
  font-size: clamp(11px, 2.5vw, 14px);
  font-weight: 600;
  color: rgba(255, 255, 255, 0.92);
  white-space: nowrap;
}

.template-neuron-icon {
  width: clamp(15px, 3.6vw, 18px);
  height: clamp(15px, 3.6vw, 18px);
  object-fit: contain;
  opacity: 0.9;
  flex-shrink: 0;
}

.templates-empty-state {
  margin-top: 16px;
  padding: 14px;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.templates-history-section {
  margin-top: 8px;
}

.templates-history-status {
  margin: 0 0 10px;
  min-height: 1.25em;
  font-size: 14px;
  color: rgba(255, 255, 255, 0.85);
}

.templates-history-card {
  background: rgba(10, 11, 29, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 16px;
  overflow: hidden;
}

.templates-history-thumb {
  display: block;
  height: 170px;
  background: rgba(0, 0, 0, 0.25);
  color: inherit;
  text-decoration: none;
  position: relative;
}

.templates-history-thumb img,
.templates-history-thumb video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.templates-history-thumb-multi {
  position: absolute;
  right: 8px;
  bottom: 8px;
  min-width: 28px;
  height: 22px;
  padding: 0 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 11px;
  background: rgba(10, 11, 29, 0.78);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.2px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  pointer-events: none;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
}

.templates-history-thumb-loader {
  width: 100%;
  height: 100%;
  min-height: 120px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 16px;
  box-sizing: border-box;
  background: rgba(0, 0, 0, 0.38);
  pointer-events: none;
}

.templates-history-thumb-loader__spinner {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.12);
  border-top-color: rgba(200, 140, 255, 0.95);
  animation: templates-fs-spin 0.85s linear infinite;
  flex-shrink: 0;
}

.templates-history-thumb-loader__text {
  font-size: 12px;
  line-height: 1.3;
  color: rgba(255, 255, 255, 0.82);
  text-align: center;
}

.templates-history-thumb-fallback,
.templates-history-thumb-placeholder {
  width: 100%;
  height: 100%;
  min-height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  color: rgba(255, 255, 255, 0.75);
  padding: 12px;
  text-align: center;
}

.templates-history-thumb-fallback-label {
  font-size: 13px;
  color: rgba(255, 255, 255, 0.72);
  text-align: center;
  padding: 0 8px;
}

.templates-history-body {
  padding: 14px;
}

.templates-history-meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: clamp(8px, 1.2vw, 12px);
  opacity: 0.8;
}

.templates-history-title {
  margin-top: 10px;
  font-size: clamp(10px, 1.2vw, 16px);
  line-height: 1.25;
  font-weight: 500;
}

.templates-history-title a {
  color: inherit;
  text-decoration: none;
  font-weight: 500;
}

.templates-history-title a:hover {
  color: #e8c4ff;
}

.templates-history-status-row {
  margin-top: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.templates-history-status-text {
  font-size: clamp(9px, 1.2vw, 13px);
  line-height: 1.35;
  color: rgba(255, 255, 255, 0.78);
  min-width: 0;
  flex: 1;
}

.templates-history-icon-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.templates-history-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: clamp(16px, 2vw, 32px);
  height: clamp(10px, 1.2vw, 32px);
  padding: 0;
  border: none;
  border-radius: 8px;
  background: transparent;
  cursor: pointer;
}

.templates-history-icon-btn img {
  width: clamp(12px, 1.5vw, 18px);
  height: clamp(12px, 1.5vw, 18px);
  object-fit: contain;
  opacity: 0.8;
  display: block;
}

.templates-history-icon-btn:hover:not(.templates-history-icon-btn--disabled) img {
  opacity: 1;
}

.templates-history-icon-btn--disabled {
  cursor: default;
  pointer-events: none;
}

.templates-history-icon-btn--disabled img {
  opacity: 0.28;
}

.templates-history-icon-btn--link {
  text-decoration: none;
}

.templates-history-card--clickable {
  cursor: pointer;
}

.templates-history-card--clickable:focus-visible {
  outline: 2px solid rgba(200, 140, 255, 0.85);
  outline-offset: 2px;
}

.templates-history-error {
  margin-top: 8px;
  font-size: 12px;
  color: #ffb3b3;
}

.template-back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: clamp(12px, 2vh, 22px);
  margin-bottom: 14px;
  color: #fff;
  font-size: 13px;
  text-decoration: none;
}

.template-detail-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.template-detail-share-btn {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  margin: 0;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.92);
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease, color 0.2s ease;
}

.template-detail-share-btn:hover {
  border-color: rgba(178, 48, 204, 0.75);
  background: rgba(178, 48, 204, 0.22);
  color: #fff;
}

.template-detail-share-btn:focus-visible {
  outline: 2px solid rgba(200, 140, 255, 0.9);
  outline-offset: 2px;
}

.template-detail-share-btn__icon {
  display: block;
}

.template-detail-title-row h1 {
  margin: 0;
  flex: 1;
  min-width: 0;
  font-size: clamp(20px, 4.6vw, 28px);
  font-weight: 500;
  line-height: 1.22;
  color: #fff;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.template-detail-meta-inline {
  flex-shrink: 0;
  font-size: clamp(12px, 2.4vw, 14px);
  font-weight: 400;
  color: rgba(255, 255, 255, 0.72);
  white-space: nowrap;
}

.template-detail-description {
  margin-top: 12px;
  font-size: clamp(14px, 2.6vw, 17px);
  line-height: 1.55;
  color: #fff;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.template-detail-meta-chips {
  margin-top: 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: stretch;
}

.template-detail-chip {
  flex: 1 1 140px;
  min-width: min(100%, 160px);
  max-width: 100%;
  box-sizing: border-box;
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: linear-gradient(145deg, rgba(255, 255, 255, 0.09) 0%, rgba(20, 22, 48, 0.72) 100%);
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.22);
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: relative;
  overflow: hidden;
}

.template-detail-chip::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  border-radius: 14px 0 0 14px;
  background: linear-gradient(180deg, rgba(200, 140, 255, 0.95) 0%, rgba(178, 48, 204, 0.85) 100%);
  opacity: 0.95;
}

.template-detail-chip--credits::before {
  background: linear-gradient(180deg, rgba(120, 220, 255, 0.55) 0%, rgba(178, 48, 204, 0.95) 100%);
}

.template-detail-chip__caption {
  display: block;
  font-size: clamp(11px, 2vw, 12px);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.55);
}

.template-detail-chip__value {
  font-size: clamp(14px, 2.8vw, 17px);
  font-weight: 600;
  color: #fff;
  line-height: 1.25;
  word-break: break-word;
}

.template-detail-chip__line {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.template-detail-chip__value--num {
  font-variant-numeric: tabular-nums;
  font-size: clamp(16px, 3vw, 20px);
}

.template-neuron-icon--chip {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  opacity: 0.95;
  filter: brightness(0) invert(1);
}

.template-detail-card {
  display: grid;
  grid-template-columns: minmax(0, 50%) minmax(0, 1fr);
  gap: 22px;
  align-items: flex-start;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

.template-detail-preview {
  position: relative;
  min-width: 0;
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(0, 0, 0, 0.2);
}

.template-detail-content {
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
  overflow-x: clip;
}

.template-detail-preview img,
.template-detail-preview video {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  max-height: min(72vh, 760px);
  object-fit: cover;
  display: block;
}

.template-form {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 9px;
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
}

.template-form__label,
.template-form label.template-form__label {
  font-size: clamp(14px, 2.5vw, 16px);
  font-weight: 500;
  color: #fff;
}

/* Только textarea: не цеплять input[type=file] — иначе width:100% бьёт .template-file-input по специфичности и рвёт вёрстку */
.template-form textarea,
.template-form-textarea {
  width: 100%;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(0, 0, 0, 0.24);
  color: #fff;
  padding: 9px 10px;
  font-size: 13px;
  box-sizing: border-box;
  max-width: 100%;
}

.template-file-picker {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  min-height: 52px;
}

.template-form .template-file-input,
.template-file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  border: 0;
  padding: 0;
  clip: rect(0 0 0 0);
  overflow: hidden;
  white-space: nowrap;
}

.template-file-picker-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 1 auto;
  min-width: 0;
  max-width: 100%;
  padding: 11px 16px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  font-size: clamp(13px, 2.2vw, 15px);
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.template-file-picker-btn:hover {
  border-color: rgba(178, 48, 204, 0.8);
  background: rgba(178, 48, 204, 0.2);
}

.template-file-preview {
  min-width: 0;
  flex: 0 1 auto;
  display: flex;
  align-items: center;
  justify-content: flex-start;
}

.template-file-thumb {
  flex-shrink: 0;
  display: block;
  max-height: 52px;
  max-width: min(140px, 42vw);
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: rgba(0, 0, 0, 0.28);
}

.template-file-thumb--video {
  object-fit: cover;
}

.template-file-preview__empty {
  text-align: left;
}

.template-file-name {
  min-width: 0;
  font-size: clamp(12px, 2.2vw, 14px);
  color: rgba(255, 255, 255, 0.88);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.template-submit-btn {
  margin-top: 6px;
  border: none;
  border-radius: 12px;
  padding: 11px 16px;
  background: #b230cc;
  color: #fff;
  box-sizing: border-box;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  cursor: pointer;
  font-size: clamp(14px, 2.6vw, 17px);
  font-weight: 600;
}

.template-submit-price {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-weight: 600;
}

.template-neuron-icon--submit {
  width: 18px;
  height: 18px;
}

.template-category-badge--detail {
  top: 12px;
  right: 12px;
  max-width: calc(100% - 24px);
}

.template-related-section {
  margin-top: 16px;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

.template-related-title {
  margin: 0 0 8px;
  font-size: clamp(13px, 2.8vw, 17px);
  font-weight: 500;
  color: rgba(255, 255, 255, 0.88);
}

.template-related-list {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  gap: clamp(8px, 2vw, 14px);
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: clamp(6px, 1.2vw, 10px);
  -webkit-overflow-scrolling: touch;
  scroll-snap-type: x proximity;
  overscroll-behavior-x: contain;
}

.template-related-card {
  flex: 0 0 auto;
  /* Квадрат: от ~92px на узких экранах до ~148px на широких */
  width: clamp(92px, min(24vw, 16vh), 148px);
  scroll-snap-align: start;
  aspect-ratio: 1;
  border-radius: clamp(10px, 2vw, 14px);
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(10, 11, 29, 0.55);
  overflow: hidden;
  text-decoration: none;
  color: #fff;
}

.template-related-card__inner {
  position: relative;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.25);
}

.template-related-card__inner img,
.template-related-card__inner video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.template-related-card__placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(8px, 2vw, 11px);
  padding: 4px;
  text-align: center;
}

.template-category-badge--related {
  top: clamp(4px, 1.2vw, 8px);
  right: clamp(4px, 1.2vw, 8px);
  max-width: calc(100% - 16px);
  padding: clamp(2px, 0.5vw, 4px) clamp(4px, 1.2vw, 8px);
  font-size: clamp(6px, 2.1vw, 8px);
  line-height: 1.1;
}

.template-related-card__title {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  margin: 0;
  padding: clamp(14px, 4vw, 22px) clamp(4px, 1.2vw, 8px) clamp(4px, 1vw, 8px);
  font-size: clamp(9px, 2.6vw, 12px);
  line-height: 1.3;
  font-weight: 600;
  color: #fff;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.9) 0%, rgba(0, 0, 0, 0.35) 50%, transparent 100%);
  display: -webkit-box;
  line-clamp: 2;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.template-job-status {
  margin-top: 12px;
  font-size: clamp(13px, 2.4vw, 15px);
  color: rgba(255, 255, 255, 0.92);
}

.template-job-result {
  margin-top: 10px;
  font-size: clamp(13px, 2.4vw, 15px);
  min-width: 0;
}

.template-job-result img,
.template-job-result video {
  max-width: 100%;
  height: auto;
  display: block;
}

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

/* Модалка «Поделиться» (страница шаблона) */
.template-share-modal {
  position: fixed;
  inset: 0;
  z-index: 10064;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  box-sizing: border-box;
}

.template-share-modal[hidden] {
  display: none !important;
}

.template-share-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(4, 5, 14, 0.82);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.template-share-modal__panel {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 420px;
  padding: 20px 20px 18px;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(14, 15, 28, 0.97);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
  box-sizing: border-box;
}

.template-share-modal__close {
  position: absolute;
  top: 10px;
  right: 12px;
  width: 36px;
  height: 36px;
  margin: 0;
  padding: 0;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: rgba(255, 255, 255, 0.75);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.template-share-modal__close:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.08);
}

.template-share-modal__title {
  margin: 0 36px 16px 0;
  font-size: clamp(17px, 3.2vw, 20px);
  font-weight: 600;
  color: #fff;
}

.template-share-modal__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 18px;
}

.template-share-modal__btn {
  flex: 1 1 140px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 10px 14px;
  border-radius: 12px;
  border: none;
  font-size: 15px;
  font-weight: 600;
  text-decoration: none;
  color: #fff;
  cursor: pointer;
  transition: filter 0.15s ease, transform 0.1s ease;
}

.template-share-modal__btn:hover {
  filter: brightness(1.08);
}

.template-share-modal__btn--tg {
  background: #229ed9;
}

.template-share-modal__btn--vk {
  background: #0077ff;
}

.template-share-modal__copy-block {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.template-share-modal__copy-label {
  font-size: 13px;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.75);
}

.template-share-modal__copy-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: stretch;
}

.template-share-modal__url-input {
  flex: 1 1 160px;
  min-width: 0;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(0, 0, 0, 0.35);
  color: #fff;
  font-size: 13px;
}

.template-share-modal__copy-btn {
  flex: 0 0 auto;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid rgba(178, 48, 204, 0.65);
  background: rgba(178, 48, 204, 0.25);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.template-share-modal__copy-btn:hover {
  background: rgba(178, 48, 204, 0.4);
}

.template-share-modal__hint {
  margin: 0;
  font-size: 13px;
  color: #9cffc1;
}

/* Popover: базовый .template-detail-chip { overflow: hidden } иначе обрезает панель */
.template-detail-chip.template-price-popover {
  overflow: visible;
  z-index: 3;
}

.template-price-popover {
  position: relative;
}

/* «Мостик» наведения: без него курсор теряет hover в зазоре между чипом и панелью */
.template-price-popover::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 100%;
  height: 16px;
  z-index: 39;
}

.template-price-popover__panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 40;
  /* svw — не раздувает layout при вертикальном скроллбаре (в отличие от 100vw) */
  width: min(270px, calc(100svw - 44px));
  padding: 12px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(16, 18, 36, 0.97);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.38);
  opacity: 0;
  visibility: hidden;
  transform: translateY(4px);
  pointer-events: none;
  transition: opacity 0.14s ease, transform 0.14s ease, visibility 0.14s ease;
}

.template-price-popover__panel::before {
  content: "";
  position: absolute;
  top: -6px;
  right: 18px;
  width: 10px;
  height: 10px;
  transform: rotate(45deg);
  background: rgba(16, 18, 36, 0.97);
  border-left: 1px solid rgba(255, 255, 255, 0.18);
  border-top: 1px solid rgba(255, 255, 255, 0.18);
}

.template-price-popover.is-open .template-price-popover__panel,
.template-price-popover:hover .template-price-popover__panel,
.template-price-popover:focus-within .template-price-popover__panel {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
  pointer-events: auto;
}

.template-price-popover__line {
  margin: 0;
  font-size: 13px;
  line-height: 1.4;
  color: rgba(255, 255, 255, 0.9);
}

.template-price-popover__line + .template-price-popover__line {
  margin-top: 6px;
}

.template-price-popover__neu-ico {
  width: 16px;
  height: 16px;
  vertical-align: -0.2em;
  margin: 0 1px;
  display: inline-block;
  object-fit: contain;
  filter: brightness(0) invert(1);
  opacity: 0.92;
}

.template-price-popover__topup-btn {
  margin-top: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  width: 100%;
  box-sizing: border-box;
  padding: 6px 12px;
  border-radius: 10px;
  border: 1px solid rgba(178, 48, 204, 0.72);
  background: rgba(178, 48, 204, 0.28);
  color: #fff;
  text-decoration: none;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.template-price-popover__topup-btn:hover {
  background: rgba(178, 48, 204, 0.42);
}

body.templates-body-no-scroll {
  overflow: hidden;
}

.templates-fullscreen-loader {
  position: fixed;
  inset: 0;
  z-index: 10050;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 24px;
  box-sizing: border-box;
  background: rgba(6, 7, 18, 0.94);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  text-align: center;
}

.templates-fullscreen-loader[hidden] {
  display: none !important;
}

.templates-fullscreen-loader__spinner {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.12);
  border-top-color: rgba(200, 140, 255, 0.95);
  animation: templates-fs-spin 0.85s linear infinite;
}

.templates-fullscreen-loader__text {
  margin: 0;
  max-width: 280px;
  font-size: 16px;
  line-height: 1.45;
  color: rgba(255, 255, 255, 0.92);
}

@keyframes templates-fs-spin {
  to {
    transform: rotate(360deg);
  }
}

.templates-history-card--highlight {
  outline: 2px solid rgba(200, 140, 255, 0.9);
  outline-offset: 3px;
  box-shadow: 0 0 0 4px rgba(178, 48, 204, 0.22);
  transition: outline-color 0.3s ease, box-shadow 0.3s ease;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.templates-result-modal {
  position: fixed;
  inset: 0;
  z-index: 10060;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  box-sizing: border-box;
}

.templates-result-modal[hidden] {
  display: none !important;
}

.templates-result-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(4, 5, 14, 0.82);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.templates-result-modal__panel {
  position: relative;
  z-index: 1;
  max-width: min(960px, calc(100svw - 32px));
  max-height: min(92vh, 900px);
  width: 100%;
  background: rgba(14, 15, 28, 0.96);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.templates-result-modal__close {
  position: absolute;
  top: 8px;
  right: 10px;
  z-index: 2;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.35);
  color: #fff;
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.templates-result-modal__close:hover {
  background: rgba(178, 48, 204, 0.45);
}

.templates-result-modal__body {
  padding: 48px 20px 24px;
  overflow: auto;
  display: block;
  min-height: 120px;
  box-sizing: border-box;
  max-height: min(92vh, 900px);
}

.templates-result-modal__stack {
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: 100%;
  align-items: stretch;
}

.templates-result-modal__meta {
  margin: 0;
}

.templates-result-modal__model,
.templates-result-modal__date {
  margin: 0 0 6px;
  font-size: 13px;
  line-height: 1.4;
  color: rgba(255, 255, 255, 0.88);
}

.templates-result-modal__date {
  margin-bottom: 0;
  color: rgba(255, 255, 255, 0.72);
}

.templates-result-modal__media-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 80px;
}

.templates-result-modal__media {
  max-width: 100%;
  max-height: min(52vh, 560px);
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 8px;
  display: block;
}

.templates-result-modal__gallery {
  display: flex;
  flex-direction: column;
  gap: 18px;
  width: 100%;
}

.templates-result-modal__gallery-item {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
}

.templates-result-modal__gallery-item .templates-result-modal__media-wrap {
  min-height: 60px;
}

.templates-result-modal__gallery-item .templates-result-modal__media {
  max-height: min(40vh, 420px);
  width: 100%;
}

.templates-result-modal__gallery-caption {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.3px;
  color: rgba(255, 255, 255, 0.78);
  text-transform: uppercase;
}

.templates-result-modal__gallery-dl {
  align-self: flex-end;
}

.templates-result-modal__prompt-host {
  margin-top: 2px;
}

.templates-result-modal__prompt-empty {
  margin: 0;
  font-size: 13px;
  color: rgba(255, 255, 255, 0.55);
}

.templates-result-modal__prompt-block {
  margin: 0;
}

.templates-result-modal__prompt-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.templates-result-modal__prompt-label {
  font-size: 13px;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.88);
}

.templates-result-modal__prompt-copy {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: none;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.35);
  cursor: pointer;
}

.templates-result-modal__prompt-copy:hover {
  background: rgba(178, 48, 204, 0.35);
}

.templates-result-modal__prompt-copy img {
  width: 20px;
  height: 20px;
  object-fit: contain;
  opacity: 0.8;
  display: block;
}

.templates-result-modal__prompt-copy:hover img {
  opacity: 1;
}

.templates-result-modal__prompt-details {
  margin: 0;
}

/* Закрытый <details>: текст промпта скрыт (на случай квирков WebView). */
.templates-result-modal__prompt-details:not([open]) > .templates-result-modal__prompt-text {
  display: none;
}

.templates-result-modal__prompt-summary {
  display: block;
  cursor: pointer;
  list-style: none;
  user-select: none;
  padding: 0;
  margin: 0 0 8px;
}

.templates-result-modal__prompt-summary::-webkit-details-marker {
  display: none;
}

.templates-result-modal__prompt-summary-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.templates-result-modal__prompt-summary-text {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: #d8b4ff;
}

.templates-result-modal__prompt-summary-text::after {
  content: "";
  flex-shrink: 0;
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 6px solid rgba(216, 180, 255, 0.92);
  margin-top: 1px;
  transition: transform 0.2s ease;
}

.templates-result-modal__prompt-details[open] .templates-result-modal__prompt-summary-text::after {
  transform: rotate(180deg);
}

.templates-result-modal__prompt-text {
  margin: 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.1);
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 13px;
  line-height: 1.45;
  color: rgba(255, 255, 255, 0.9);
  font-family: inherit;
  max-height: min(40vh, 360px);
  overflow: auto;
}

.templates-result-modal__footer-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  width: 100%;
  gap: clamp(6px, 2.2vw, 10px);
  padding-top: 4px;
  margin-bottom: 12px;
}

.templates-result-modal__action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: clamp(7px, 2vw, 10px) clamp(12px, 4.2vw, 20px);
  min-height: clamp(36px, 9vw, 44px);
  border-radius: clamp(8px, 2vw, 10px);
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: rgba(178, 48, 204, 0.42);
  color: #fff;
  font: inherit;
  font-size: clamp(12px, 3.4vw, 14px);
  font-weight: 500;
  line-height: 1.2;
  cursor: pointer;
  text-decoration: none;
  box-sizing: border-box;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.templates-result-modal__action-btn:hover {
  background: rgba(200, 90, 220, 0.5);
  border-color: rgba(255, 255, 255, 0.35);
  color: #fff;
}

.templates-result-modal__action-btn--danger {
  background: rgba(140, 40, 55, 0.45);
  border-color: rgba(255, 154, 154, 0.35);
  color: #ffe8e8;
}

.templates-result-modal__action-btn--danger:hover {
  background: rgba(170, 55, 70, 0.55);
  border-color: rgba(255, 180, 180, 0.45);
  color: #fff;
}

.templates-result-modal__fallback {
  margin: 0;
  text-align: center;
}

/* Подтверждение удаления генерации (кастомное, в фирменных цветах) */
.templates-confirm-modal {
  position: fixed;
  inset: 0;
  z-index: 100002;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(16px, 4vw, 28px);
  box-sizing: border-box;
}

.templates-confirm-modal[hidden] {
  display: none !important;
}

.templates-confirm-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 5, 20, 0.62);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  cursor: pointer;
}

.templates-confirm-modal__panel {
  position: relative;
  z-index: 1;
  width: min(400px, 100%);
  padding: clamp(18px, 4vw, 24px);
  border-radius: clamp(14px, 3vw, 18px);
  border: 1px solid rgba(178, 48, 204, 0.45);
  background: linear-gradient(155deg, rgba(40, 12, 48, 0.96) 0%, rgba(22, 8, 32, 0.98) 100%);
  box-shadow:
    0 20px 50px rgba(0, 0, 0, 0.45),
    0 0 0 1px rgba(255, 255, 255, 0.06) inset;
  box-sizing: border-box;
}

.templates-confirm-modal__title {
  margin: 0 0 10px;
  font-size: clamp(17px, 4vw, 20px);
  font-weight: 700;
  line-height: 1.25;
  color: #fff;
}

.templates-confirm-modal__message {
  margin: 0 0 clamp(18px, 4vw, 22px);
  font-size: clamp(13px, 3.2vw, 15px);
  line-height: 1.45;
  color: rgba(255, 255, 255, 0.88);
}

.templates-confirm-modal__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.templates-confirm-modal__btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 10px 18px;
  border-radius: 12px;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: 2px solid transparent;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.templates-confirm-modal__btn--secondary {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.22);
  color: rgba(255, 255, 255, 0.92);
}

.templates-confirm-modal__btn--secondary:hover {
  background: rgba(255, 255, 255, 0.14);
  border-color: rgba(255, 255, 255, 0.32);
  color: #fff;
}

.templates-confirm-modal__btn--primary {
  background: #b230cc;
  border-color: #b230cc;
  color: #fff;
}

.templates-confirm-modal__btn--primary:hover {
  background: #9a1fb3;
  border-color: #9a1fb3;
  color: #fff;
}
