.template-category-container {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 14px;
  padding: 16px 18px 18px;
  box-shadow: 0 2px 10px rgba(15, 23, 42, 0.04);
}

.template-category-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding-bottom: 12px;
}

.template-category-row + .template-category-row {
  border-top: 1px solid #f1f5f9;
  padding-top: 12px;
}

.template-parent-row {
  display: none;
}

.template-child-row {
  border-top: none;
  padding-top: 0;
  padding-bottom: 12px;
  align-items: flex-start;
}

.template-category-label {
  width: 38px;
  flex: 0 0 38px;
  line-height: 32px;
  color: #111827;
  font-size: 14px;
  font-weight: 600;
}

.template-category-tabs {
  --template-child-tabs-collapsed-height: 34px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 32px;
  flex: 1 1 auto;
  min-width: 0;
}

#templateChildTabs {
  position: relative;
}

#templateChildTabs.has-more.is-collapsed::after {
  content: '';
  position: absolute;
  right: 0;
  bottom: 0;
  width: 72px;
  height: 30px;
  pointer-events: none;
  background: linear-gradient(90deg, rgba(255, 255, 255, 0), #fff 72%);
}

#templateChildTabs.is-collapsed {
  max-height: var(--template-child-tabs-collapsed-height);
  overflow: hidden;
}

#templateChildTabs.is-expanded,
#templateChildTabs.is-measuring {
  max-height: none;
  overflow: visible;
}

.template-category-tab {
  border: 1px solid transparent;
  background: transparent;
  color: #374151;
  border-radius: 999px;
  padding: 6px 12px;
  line-height: 18px;
  font-size: 14px;
  transition: all 0.2s ease;
}

.template-category-tab:hover {
  color: #E53E3E;
  background: rgba(229, 62, 62, 0.08);
}

.template-category-tab.active {
  color: #E53E3E;
  background: rgba(229, 62, 62, 0.12);
  border-color: rgba(229, 62, 62, 0.25);
  font-weight: 600;
}

.template-category-more-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex: 0 0 auto;
  border: 1px solid rgba(229, 62, 62, 0.28);
  background: linear-gradient(135deg, rgba(229, 62, 62, 0.08), rgba(229, 62, 62, 0.14));
  color: #E53E3E;
  border-radius: 999px;
  padding: 6px 12px;
  line-height: 18px;
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  box-shadow: 0 4px 12px rgba(229, 62, 62, 0.08);
  transition: all 0.2s ease;
}

.template-category-more-arrow {
  width: 7px;
  height: 7px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
  transform-origin: center;
  transition: transform 0.2s ease;
}

.template-category-more-btn[aria-expanded="true"] .template-category-more-arrow {
  transform: rotate(225deg);
}

.template-category-more-btn[aria-expanded="true"] {
  color: #6b7280;
  border-color: rgba(107, 114, 128, 0.22);
  background: linear-gradient(135deg, rgba(107, 114, 128, 0.08), rgba(107, 114, 128, 0.14));
  box-shadow: none;
}

.template-category-more-btn.hidden {
  display: none !important;
}

.template-category-more-btn:hover {
  background: linear-gradient(135deg, rgba(229, 62, 62, 0.12), rgba(229, 62, 62, 0.2));
  transform: translateY(-1px);
}

.template-category-more-btn[aria-expanded="true"]:hover {
  background: linear-gradient(135deg, rgba(107, 114, 128, 0.12), rgba(107, 114, 128, 0.18));
}

.template-cards-grid {
  column-count: 4;
  column-gap: 14px;
  margin-top: 12px;
}

.center-mode #sampleGalleryWrap {
  max-width: 100%;
  margin-top: 2rem;
}

.explore-template-grid {
  width: 100%;
}

#mainContent.instant-view-switch,
#mainContent.instant-view-switch #welcomeArea,
#mainContent.instant-view-switch #chatArea,
#mainContent.instant-view-switch #bottomBar,
#mainContent.instant-view-switch #discoverPanel,
#mainContent.instant-view-switch #sampleGalleryWrap {
  transition: none !important;
}

@media (min-width: 768px) {
  #mainContent.explore-scroll-mode {
    justify-content: flex-start;
    height: calc(100vh - 72px);
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
  }

  #mainContent.explore-scroll-mode #welcomeArea,
  #mainContent.explore-scroll-mode #chatArea {
    flex: 0 0 auto;
    width: 100%;
    overflow: visible;
  }

  #mainContent.explore-scroll-mode #sampleGalleryWrap {
    flex: 0 0 auto;
    padding-bottom: 32px;
  }
}

.template-card {
  display: inline-block;
  width: 100%;
  break-inside: avoid;
  -webkit-column-break-inside: avoid;
  page-break-inside: avoid;
  margin: 0 0 14px;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  background: #fff;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.04);
  cursor: pointer;
  transition: all 0.2s ease;
}

.template-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.1);
  border-color: rgba(229, 62, 62, 0.3);
}

.template-card-thumb {
  position: relative;
  width: 100%;
  line-height: 0;
  background: #fff;
}

.template-card-thumb img {
  width: 100%;
  height: auto;
  object-fit: contain;
  display: block;
}

.template-card-overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.85) 0%, rgba(0, 0, 0, 0.4) 52%, transparent 100%);
  opacity: 0;
  transition: opacity 0.25s ease;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px;
}

.template-card:hover .template-card-overlay {
  opacity: 1;
}

.template-card-overlay-title {
  margin: 0;
  color: #fff;
  font-size: 12px;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.template-card-make-btn {
  width: 100%;
  border: none;
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 12px;
  line-height: 1.2;
  font-weight: 600;
  color: #fff;
  cursor: pointer;
  background: linear-gradient(135deg, #E53E3E 0%, #C53030 100%);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.template-card-make-btn:hover {
  transform: scale(1.03);
  box-shadow: 0 4px 12px rgba(229, 62, 62, 0.4);
}

.template-card-meta {
  padding: 8px 9px 9px;
}

.template-card-title {
  font-size: 13px;
  line-height: 1.4;
  color: #1f2937;
  margin: 0;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
}

.template-empty {
  text-align: center;
  color: #9ca3af;
  font-size: 13px;
  padding: 24px 0 16px;
}

@media (max-width: 1400px) {
  .template-cards-grid {
    column-count: 4;
  }
}

@media (max-width: 1100px) {
  .template-cards-grid {
    column-count: 3;
  }
}

@media (max-width: 900px) {
  .template-cards-grid {
    column-count: 2;
  }
}

@media (max-width: 767px) {
  .template-category-container {
    padding: 12px;
  }

  .template-child-row {
    gap: 8px;
  }

  .template-category-tabs {
    --template-child-tabs-collapsed-height: 70px;
  }

  .template-category-label {
    width: 32px;
    flex-basis: 32px;
    line-height: 30px;
    font-size: 13px;
  }

  .template-category-tab {
    padding: 5px 10px;
    font-size: 13px;
  }

  .template-category-more-btn {
    padding: 5px 10px;
    font-size: 13px;
  }

  .template-cards-grid {
    column-count: 1;
    column-gap: 10px;
  }
}
