:root {
  --page-card: #ffffff;
  --page-card-border: #e5e7eb;
  --page-text: #161616;
  --page-muted: #6b7280;
  --page-accent: #337ab7;
}

@keyframes slideUp {
  from {
    max-height: 0;
    opacity: 0;
    transform: translateY(20px);
  }

  to {
    max-height: 500px;
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes slideDown {
  from {
    max-height: 500px;
    opacity: 1;
    transform: translateY(0);
  }

  to {
    max-height: 0;
    opacity: 0;
    transform: translateY(20px);
  }
}

.page-shell {
  color: var(--page-text);
  padding: 0 16px 64px;
}

.page-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 12px 16px;
  border-radius: 12px;
  border: 1px solid var(--page-card-border);
  color: var(--page-text);
  background: #ffffff;
  cursor: pointer;
  transition: transform 120ms ease, background 120ms ease, border-color 120ms ease;
  text-decoration: none;
  font-family: var(--font-sans);
  font-weight: 500;
  font-size: 15px;
}

.page-btn:hover {
  transform: translateY(-2px);
  background: #f3f4f6;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.page-btn--primary {
  background: #337ab7;
  border-color: #337ab7;
  color: #ffffff;
}

.page-btn--primary:hover {
  background: #2563a8;
  border-color: #2563a8;
}

.page-btn--ghost {
  background: transparent;
  border-color: var(--page-card-border);
  color: var(--page-text);
}

.page-btn--ghost:hover {
  background: #f3f4f6;
}

.page-btn--sm {
  padding: 9px 12px;
  border-radius: 10px;
  font-size: 14px;
}

.page-section {
  width: 90%;
  margin: 0 auto;
  padding-top: 0;
}

.page-shell:not(:has(> .fh-page-hero)) .page-section {
  padding-top: 18px;
}

.page-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 32px;
  align-items: start;
}

/* Filter Sidebar */
.filter-sidebar {
  position: sticky;
  top: 24px;
  background: var(--page-card);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  border-radius: 16px;
  border: 1px solid var(--page-card-border);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.03);
}

.filter-sidebar__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--page-card-border);
}

.filter-sidebar__toggle-mobile {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  margin: 0;
  padding: 0;
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--page-text);
  font-family: var(--font-sans);
  transition: color 0.2s ease;
}

.filter-sidebar__toggle-mobile:hover {
  color: var(--page-accent);
}

.filter-sidebar__toggle-mobile-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
}

.filter-sidebar__menu-icon {
  flex-shrink: 0;
  color: var(--page-accent);
}

.filter-sidebar__toggle-label {
  flex: 1;
  text-align: left;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.filter-sidebar__chevron {
  flex-shrink: 0;
  color: var(--page-muted);
  transition: transform 0.25s ease;
}

.filter-sidebar__toggle-mobile[aria-expanded="true"] .filter-sidebar__chevron {
  transform: rotate(180deg);
}

.filter-sidebar__body {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.filter-sidebar__title {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: var(--page-text);
  font-family: var(--font-sans);
  display: flex;
  align-items: center;
  gap: 10px;
}

.filter-sidebar__icon {
  color: var(--page-muted);
}

/* Filter Groups */
.filter-group {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.filter-group__toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: none;
  border: none;
  padding: 8px 0;
  cursor: pointer;
  color: var(--page-text);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.02em;
  transition: color 0.2s ease;
  font-family: var(--font-sans);
}

.filter-group__toggle:hover {
  color: var(--page-accent);
}

.filter-sidebar__reset {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  color: var(--page-muted);
  cursor: pointer;
  font-size: 14px;
  padding: 12px 16px;
  border-radius: 12px;
  transition: all 0.2s ease;
  font-family: var(--font-sans);
  font-weight: 500;
}

.filter-sidebar__reset.visible {
  display: flex;
}

.filter-sidebar__reset:hover {
  background: #f3f4f6;
  border-color: var(--page-text);
  color: var(--page-text);
}

.filter-group__label {
  text-align: left;
}

.filter-group__icon {
  transition: transform 0.2s ease;
  color: var(--page-muted);
}

.filter-group__toggle[aria-expanded="false"] .filter-group__icon {
  transform: rotate(-90deg);
}

.filter-group__content {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-left: 4px;
  max-height: min(70vh, 720px);
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  transition: opacity 0.3s ease, padding 0.3s ease;
  opacity: 1;
}

.filter-group__content--tree {
  gap: 6px;
  padding-left: 0;
}

.filter-group__content[data-collapsed="true"] {
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  padding-top: 0;
  padding-bottom: 0;
}

/* Filter Options */
.filter-category-block {
  border-radius: 12px;
  border: 1px solid transparent;
  background: #fafbfc;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.filter-category-block:hover {
  border-color: #e5e7eb;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.04);
}

.filter-category-block:has(.filter-checkbox:checked) {
  border-color: rgba(51, 122, 183, 0.35);
  background: rgba(51, 122, 183, 0.04);
  box-shadow: 0 2px 10px rgba(51, 122, 183, 0.08);
}

.filter-option {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  padding: 10px 12px;
  border-radius: 10px;
  transition: background 0.2s ease, border-color 0.2s ease;
  position: relative;
  border: 1px solid transparent;
}

.filter-option:hover {
  background: #f1f5f9;
}

.filter-option:has(.filter-checkbox:checked) {
  background: rgba(51, 122, 183, 0.1);
  border-color: rgba(51, 122, 183, 0.15);
}

.filter-option--checkbox {
  gap: 12px;
}

.filter-option--parent .filter-option__label {
  font-size: 14px;
  font-weight: 600;
  color: var(--page-text);
}

/* Hide native checkbox */
.filter-checkbox {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

/* Custom checkbox */
.filter-checkbox__custom {
  width: 18px;
  height: 18px;
  border: 2px solid #d1d5db;
  border-radius: 4px;
  cursor: pointer;
  position: relative;
  transition: all 0.2s ease;
  flex-shrink: 0;
  background: #ffffff;
}

.filter-checkbox:checked+.filter-checkbox__custom {
  border-color: var(--page-accent);
  background: var(--page-accent);
}

.filter-checkbox:checked+.filter-checkbox__custom::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  width: 4px;
  height: 8px;
  border: solid white;
  border-width: 0 2px 2px 0;
  transform: translate(-50%, -60%) rotate(45deg);
}

.filter-checkbox:focus+.filter-checkbox__custom {
  box-shadow: 0 0 0 3px rgba(51, 122, 183, 0.1);
}

.filter-checkbox__custom--sm {
  width: 16px;
  height: 16px;
  border-radius: 3px;
}

.filter-option__label {
  font-size: 14px;
  color: var(--page-muted);
  line-height: 1.4;
  transition: color 0.2s ease;
  font-family: var(--font-sans);
  flex: 1;
  min-width: 0;
}

.filter-option__count {
  flex-shrink: 0;
  min-width: 24px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #e8eef4;
  color: #64748b;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.4;
  text-align: center;
  font-family: var(--font-sans);
  transition: background 0.2s ease, color 0.2s ease;
}

.filter-option:hover .filter-option__count {
  background: #dce6f0;
  color: #475569;
}

.filter-option:has(.filter-checkbox:checked) .filter-option__count {
  background: var(--page-accent);
  color: #ffffff;
}

.filter-option__count--muted {
  opacity: 0.55;
}

.filter-category-block .filter-option--child {
  background: transparent;
  border-color: transparent;
}

.filter-category-block .filter-option--child:hover {
  background: rgba(255, 255, 255, 0.7);
}

.filter-option:hover .filter-option__label,
.filter-checkbox:checked~.filter-option__label {
  color: var(--page-text);
}

.filter-subcategories {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: 0;
  padding: 4px 10px 10px 34px;
  position: relative;
}

.filter-subcategories::before {
  content: "";
  position: absolute;
  left: 22px;
  top: 0;
  bottom: 18px;
  width: 2px;
  border-radius: 2px;
  background: linear-gradient(180deg, #94a3b8 0%, #e2e8f0 85%);
}

.filter-option--child {
  padding: 8px 10px 8px 14px;
  margin-left: 0;
}

.filter-option--child::before {
  content: "";
  position: absolute;
  left: -12px;
  top: 50%;
  width: 10px;
  height: 2px;
  background: #94a3b8;
  border-radius: 1px;
  transform: translateY(-50%);
}

.filter-option--child .filter-option__label {
  font-size: 13px;
  font-weight: 500;
}

/* Templates Content */
.templates-content {
  min-width: 0;
}



.page-empty {
  padding: 32px;
  text-align: center;
  border: 1px solid var(--page-card-border);
  background: var(--page-card);
  border-radius: 16px;
}

.page-empty__title {
  margin: 0 0 8px;
  font-size: 18px;
  color: var(--page-text);
}

.page-empty__desc {
  margin: 0;
  color: var(--page-muted);
}

.page-section__header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.page-section__title {
  margin: 0;
  font-size: 22px;
  font-family: var(--font-sans);
  font-weight: 700;
  color: var(--page-text);
}

.page-section__desc {
  margin: 0;
  color: var(--page-muted);
  max-width: 80ch;
  line-height: 1.5;
  font-family: var(--font-sans);
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 22px;
}

.template-card[data-filtered="true"] {
  display: none;
}

.page-note {
  margin-top: 14px;
  padding: 14px 16px;
  border-radius: 14px;
  border: 1px solid var(--page-card-border);
  background: rgba(0, 0, 0, 0.2);
  color: var(--page-muted);
}

.template-card {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0;
  padding: 0;
  position: relative;
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 14px;
  box-shadow:
    0 1px 2px rgb(15 23 42 / 0.04),
    0 8px 24px rgb(15 23 42 / 0.05);
  overflow: hidden;
  transition:
    border-color 0.2s ease,
    box-shadow 0.25s ease,
    transform 0.25s ease;
}

.template-card:hover {
  transform: translateY(-4px);
  border-color: rgb(51 122 183 / 0.28);
  box-shadow:
    0 4px 12px rgb(15 23 42 / 0.06),
    0 18px 44px rgb(51 122 183 / 0.12);
}

.template-image {
  position: relative;
  height: 192px;
  overflow: hidden;
  margin: 0;
  border-radius: 0;
  border-bottom: 1px solid #e2e8f0;
  background: #f1f5f9;
}

.template-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.35s ease;
}

.template-card:hover .template-image img {
  transform: scale(1.04);
}

.template-content {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
  padding: 18px 20px 14px;
  position: relative;
  align-self: stretch;
  width: 100%;
  flex: 1 1 auto;
}

.template-info {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  position: relative;
  align-self: stretch;
  width: 100%;
}

.template-title {
  position: relative;
  width: fit-content;
  max-width: 100%;
  margin: 0;
  font-family: var(--font-sans);
  font-weight: 700;
  color: #0f172a;
  font-size: 1.05rem;
  letter-spacing: -0.02em;
  line-height: 1.3;
}

.template-description {
  margin: 0;
  font-family: var(--font-sans);
  font-weight: 400;
  color: #64748b;
  font-size: 0.875rem;
  line-height: 1.55;
}

.template-footer {
  display: flex;
  justify-content: stretch;
  padding: 14px 16px 16px;
  position: relative;
  align-self: stretch;
  width: 100%;
  gap: 10px;
  flex-direction: row;
  align-items: stretch;
  margin-top: auto;
  background: #f8fafc;
  border-top: 1px solid #e2e8f0;
}

.template-button--ghost {
  background: rgba(51, 122, 183, 0.1) !important;
  transition: background 0.2s ease, transform 0.2s ease !important;
  color: #337ab7 !important;
}

.template-button--ghost:hover {
  background: rgba(51, 122, 183, 0.18) !important;
  transform: translateY(-1px) !important;
}

.template-button {
  flex: 1 1 0;
  min-width: 0;
  padding: 11px 12px;
  background: linear-gradient(135deg, #337ab7 0%, #2a6599 100%);
  color: #ffffff;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: filter 0.2s ease, transform 0.2s ease;
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: 0.8125rem;
  text-align: center;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.template-button:hover {
  filter: brightness(1.05);
  transform: translateY(-1px);
}

@media (min-width: 720px) {
  .page-shell {
    padding: 0 24px 72px;
  }
}

@media (min-width: 1024px) {
  .card-grid {
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  }
}

@media (max-width: 1024px) {
  .page-layout {
    grid-template-columns: 1fr;
    gap: 24px;
  }

  .filter-sidebar {
    position: static;
    order: -1;
  }

  .card-grid {
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 16px;
  }
}

@media (max-width: 768px) {
  .page-shell {
    padding: 0 16px 48px;
  }

  .card-grid {
    grid-template-columns: 1fr;
  }

  .template-card {
    width: 100%;
    max-width: 100%;
    margin: 0;
  }

  .filter-sidebar__header {
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    padding-bottom: 0;
    margin-bottom: 0;
    border-bottom: none;
  }

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

  .filter-sidebar__toggle-mobile {
    display: flex;
    padding: 14px 16px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    box-shadow: 0 1px 2px rgb(15 23 42 / 0.04);
  }

  .filter-sidebar__toggle-mobile:hover {
    border-color: rgb(51 122 183 / 0.35);
    background: #ffffff;
    color: var(--page-text);
  }

  .filter-sidebar:not(.collapsed) .filter-sidebar__header {
    margin-bottom: 14px;
    padding-bottom: 14px;
    border-bottom: 1px solid #e2e8f0;
  }

  .filter-sidebar__body {
    overflow: hidden;
    max-height: 2200px;
    opacity: 1;
    transition:
      max-height 0.38s ease,
      opacity 0.28s ease,
      margin 0.28s ease;
  }

  .filter-sidebar.collapsed .filter-sidebar__body {
    max-height: 0;
    opacity: 0;
    margin-top: 0;
    pointer-events: none;
  }

  .filter-sidebar.collapsed .filter-sidebar__reset {
    display: none !important;
  }
}

@media (min-width: 769px) {
  .filter-sidebar.collapsed .filter-sidebar__body {
    max-height: none !important;
    opacity: 1 !important;
    margin-top: 0 !important;
    pointer-events: auto !important;
  }
}

@media (max-width: 480px) {
  .filter-sidebar {
    padding: 16px;
  }

  .template-button {
    width: 100%;
  }
}

/* —— Template detail (public) —— */
.template-detail__meta {
  margin: 0;
  color: rgba(255, 255, 255, 0.88);
  font-size: 1rem;
}

.template-detail__body {
  padding-top: 0;
}

.template-detail__category-note {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  margin: 0 0 1.35rem;
  padding: 14px 16px;
  border-radius: 12px;
  border: 1px solid rgb(51 122 183 / 0.2);
  background: linear-gradient(135deg, rgb(239 246 255) 0%, rgb(248 250 252) 100%);
  box-shadow: 0 1px 2px rgb(15 23 42 / 0.04);
}

.template-detail__category-note__icon {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border-radius: 10px;
  background: #ffffff;
  color: #337ab7;
  border: 1px solid rgb(51 122 183 / 0.18);
}

.template-detail__category-note__icon svg {
  display: block;
}

.template-detail__category-note__text {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  padding-top: 1px;
}

.template-detail__category-note__label {
  font-family: var(--font-sans);
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: #2563a8;
}

.template-detail__category-note__value {
  font-family: var(--font-sans);
  font-size: 1.02rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: #0f172a;
  line-height: 1.35;
}

.template-detail__layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) min(320px, 100%);
  gap: 28px;
  max-width: 1180px;
  margin: 0 auto;
}

.template-detail__card {
  background: #ffffff;
  border: 1px solid var(--page-card-border);
  border-radius: 16px;
  padding: 24px 26px;
  box-shadow: 0 8px 28px rgba(15, 23, 42, 0.06);
}

.template-detail__excerpt {
  font-size: 1.125rem;
  color: #374151;
  line-height: 1.55;
  margin: 0 0 1.25rem;
}

.template-detail__content {
  color: var(--page-text);
  line-height: 1.65;
}

.template-detail__content p {
  margin: 0 0 1rem;
}

.template-detail__content ul {
  margin: 0 0 1rem 1.1rem;
}

.template-detail__aside-image {
  margin-bottom: 18px;
}

.template-detail__aside-image img {
  width: 100%;
  height: auto;
  border-radius: 12px;
  object-fit: cover;
  display: block;
}

.template-detail__actions {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.template-detail__btn-full {
  display: inline-flex !important;
  width: 100% !important;
  justify-content: center !important;
  box-sizing: border-box;
  margin-top: 10px !important;
}

.template-detail__btn-full:first-of-type {
  margin-top: 0 !important;
}

.template-footer__actions {
  flex-wrap: wrap;
  justify-content: center;
}

.template-footer__actions .template-button {
  flex: 1 1 30%;
  min-width: min(100px, 90px);
}

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