/* TEMPLATES PAGE */

.tpl-hero {
  position: relative;
  padding: 4.5rem 0 3rem;
  overflow: hidden;
}
.tpl-hero-inner { position: relative; z-index: 2; text-align: center; }

.tpl-filters {
  position: sticky;
  top: var(--nav-h);
  z-index: 50;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--border-soft);
  padding: 0.875rem 0;
}
.tpl-filters-inner { display: flex; align-items: center; gap: 1.5rem; }
.tpl-chips { display: flex; flex-wrap: wrap; gap: 0.4rem; flex: 1; }
.tpl-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.75rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: white;
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: inherit;
}
.tpl-chip:hover { border-color: var(--border-strong); color: var(--ink); }
.tpl-chip.active {
  background: var(--ink);
  color: white;
  border-color: var(--ink);
}
.tpl-chip-count { font-family: var(--font-mono); font-size: 11px; opacity: 0.55; }
.tpl-chip.active .tpl-chip-count { opacity: 0.85; }

.tpl-search {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.75rem;
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--r-2);
  color: var(--ink-muted);
  min-width: 240px;
  box-shadow: var(--shadow-xs);
}
.tpl-search:focus-within {
  border-color: var(--purple);
  box-shadow: 0 0 0 3px rgba(99,91,255,0.12);
}
.tpl-search input {
  background: transparent;
  border: 0;
  outline: 0;
  color: var(--ink);
  font-size: 14px;
  flex: 1;
  font-family: inherit;
}
.tpl-search input::placeholder { color: var(--ink-light); }

.tpl-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1.5rem;
}

.tpl-card {
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--r-5);
  overflow: hidden;
  cursor: pointer;
  transition: all 0.25s ease;
  box-shadow: var(--shadow-xs);
}
.tpl-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
  border-color: var(--border-strong);
}
.tpl-thumb {
  position: relative;
  aspect-ratio: 612/792;
  background: #fafaf9;
  overflow: hidden;
  border-bottom: 1px solid var(--border-soft);
}
.tpl-svg-wrap { width: 100%; height: 100%; pointer-events: none; }
.tpl-svg-wrap svg { width: 100%; height: 100%; }
.tpl-overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(255,255,255,0) 50%, rgba(10,37,64,0.85) 100%);
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 1rem;
  opacity: 0;
  transition: opacity 0.2s ease;
}
.tpl-card:hover .tpl-overlay { opacity: 1; }
.tpl-overlay .btn { width: 100%; font-size: 13px; padding: 0.5rem 0.875rem; }

.tpl-meta {
  padding: 0.875rem 1rem;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
}
.tpl-name { font-size: 14.5px; font-weight: 600; color: var(--ink); margin: 0 0 0.125rem; letter-spacing: -0.01em; }
.tpl-role { font-size: 12.5px; color: var(--ink-muted); margin: 0; }
.tpl-tag {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.04em;
  color: var(--tpl-accent, var(--purple));
  padding: 0.2rem 0.4rem;
  border: 1px solid currentColor;
  border-radius: 4px;
  white-space: nowrap;
  flex-shrink: 0;
  background: white;
  font-weight: 500;
}

.tpl-lb {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  opacity: 0;
  transition: opacity 0.24s ease;
}
.tpl-lb.open { opacity: 1; }
.tpl-lb-bg { position: absolute; inset: 0; background: rgba(10,37,64,0.6); backdrop-filter: blur(8px); }
.tpl-lb-content { position: relative; max-width: 1100px; width: 100%; max-height: 90vh; }
.tpl-lb-close {
  position: absolute;
  top: -3rem;
  right: 0;
  background: white;
  border: 1px solid var(--border);
  color: var(--ink);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow);
}
.tpl-lb-close:hover { color: var(--purple); border-color: var(--purple); }

.tpl-lb-inner {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2rem;
  background: white;
  border-radius: var(--r-5);
  padding: 2rem;
  max-height: 86vh;
  overflow: hidden;
  box-shadow: var(--shadow-xl);
}
.tpl-lb-preview {
  background: #fafaf9;
  border-radius: var(--r-2);
  border: 1px solid var(--border);
  overflow: hidden;
  aspect-ratio: 612/792;
  max-height: 76vh;
}
.tpl-lb-preview svg { width: 100%; height: 100%; }
.tpl-lb-info { display: flex; flex-direction: column; gap: 0.75rem; overflow-y: auto; }
.tpl-lb-name { font-size: 1.875rem; font-weight: 300; letter-spacing: -0.025em; color: var(--ink); margin: 0.5rem 0 0; }
.tpl-lb-role { font-size: 1rem; color: var(--ink-soft); margin: 0; }
.tpl-lb-desc { color: var(--ink-soft); font-size: 14.5px; line-height: 1.55; margin: 0.5rem 0; }
.tpl-lb-feats { list-style: none; padding: 0; margin: 0.5rem 0 1.5rem; display: flex; flex-direction: column; gap: 0.5rem; }
.tpl-lb-feats li { color: var(--ink-soft); font-size: 14px; display: flex; align-items: center; gap: 0.5rem; }
.tpl-lb-feats li::before {
  content: '';
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'><path fill='%23009f6b' d='M10 0a10 10 0 1 0 0 20 10 10 0 0 0 0-20zm5.3 7.7-6 6a1 1 0 0 1-1.4 0l-3-3a1 1 0 1 1 1.4-1.4L9 11.6l5.3-5.3a1 1 0 1 1 1.4 1.4z'/></svg>");
  background-repeat: no-repeat;
}

@media (max-width: 900px) {
  .tpl-filters-inner { flex-direction: column; align-items: stretch; gap: 0.75rem; }
  .tpl-chips { overflow-x: auto; flex-wrap: nowrap; padding-bottom: 0.5rem; }
  .tpl-chip { flex-shrink: 0; }
  .tpl-search { min-width: 0; }
  .tpl-lb-inner { grid-template-columns: 1fr; overflow-y: auto; padding: 1.5rem; }
  .tpl-lb-preview { max-height: 50vh; }
}
@media (max-width: 600px) {
  .tpl-overlay { opacity: 1; background: linear-gradient(180deg, rgba(255,255,255,0) 60%, rgba(10,37,64,0.85) 100%); }
}

/* ============================================================
   TEMPLATES PAGE — MOBILE OPTIMIZATION (v7.2)
   ============================================================ */
@media (max-width: 900px) {
  .tpl-filters {
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 0.5rem;
  }
  .tpl-filters::-webkit-scrollbar { display: none; }
  .tpl-chip { flex-shrink: 0; font-size: 13px; padding: 8px 14px; }
  .tpl-grid {
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
  }
}

@media (max-width: 640px) {
  .tpl-grid { grid-template-columns: 1fr; gap: 1rem; }
  .tpl-card { padding: 0.875rem; }
  .tpl-card-title { font-size: 1rem; }
  .tpl-card-role { font-size: 0.85rem; }
  /* Lightbox: full screen on mobile */
  .tpl-lb {
    padding: 1rem;
    align-items: flex-start;
  }
  .tpl-lb-content {
    flex-direction: column;
    max-height: 92vh;
    overflow-y: auto;
  }
  .tpl-lb-preview { padding: 1.5rem; }
  .tpl-lb-meta { padding: 1.25rem; }
  .tpl-lb-close { top: 0.5rem; right: 0.5rem; }
}

@media (max-width: 380px) {
  .tpl-chip { font-size: 12px; padding: 6px 12px; }
}

/* ============================================================
   LAZY LOADING — Skeleton placeholders + scroll sentinel (v7.4)
   ============================================================ */
.tpl-card-lazy {
  /* While the SVG hasn't been rendered yet, keep card shape with skeleton */
  position: relative;
}
.tpl-card-lazy[data-svg-pending="1"] .tpl-svg-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16% 12%;
}

/* Skeleton inside thumbnail — fake CV structure with shimmer */
.tpl-skeleton {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}
.tpl-skel-bar {
  height: 10px;
  border-radius: 5px;
  background: linear-gradient(90deg, #eef0f6 0%, #f8f9fc 50%, #eef0f6 100%);
  background-size: 200% 100%;
  animation: skelShimmer 1.4s linear infinite;
}
.tpl-skel-bar-1 { width: 60%; height: 14px; }
.tpl-skel-bar-2 { width: 40%; height: 8px; margin-bottom: 8px; }
.tpl-skel-bar-3 { width: 90%; }
.tpl-skel-bar-4 { width: 75%; }
.tpl-skel-block {
  height: 50px;
  border-radius: 6px;
  background: linear-gradient(90deg, #eef0f6 0%, #f8f9fc 50%, #eef0f6 100%);
  background-size: 200% 100%;
  animation: skelShimmer 1.4s linear infinite 0.2s;
  margin: 4px 0 8px;
}
@keyframes skelShimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Fade-in when SVG renders */
.tpl-card-lazy .tpl-svg-wrap {
  transition: opacity 0.35s ease;
}
.tpl-card-lazy[data-svg-pending="1"] .tpl-svg-wrap {
  opacity: 1; /* skeleton always visible */
}
.tpl-card-loaded .tpl-svg-wrap {
  animation: fadeSvgIn 0.4s ease-out;
}
@keyframes fadeSvgIn {
  from { opacity: 0; transform: scale(0.98); }
  to { opacity: 1; transform: scale(1); }
}

/* Sentinel: invisible trigger element at the bottom of the grid */
.tpl-sentinel {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2.5rem 0;
  min-height: 60px;
  width: 100%;
  grid-column: 1 / -1;
}
.tpl-loader {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.tpl-loader span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--purple);
  opacity: 0.4;
  animation: dotBounce 1.2s ease-in-out infinite;
}
.tpl-loader span:nth-child(2) { animation-delay: 0.15s; }
.tpl-loader span:nth-child(3) { animation-delay: 0.3s; }
@keyframes dotBounce {
  0%, 100% { transform: translateY(0); opacity: 0.4; }
  50% { transform: translateY(-6px); opacity: 1; }
}
