/* ============================================================================
   ADVOKE CV — gallery.css
   Template gallery layout: filter bar, search, chips, sort, responsive
   card grid with real miniature resume previews, skeleton, empty and error
   states. Mobile-first, container-query aware, GPU-friendly.
   ============================================================================ */

/* ── 1. Gallery header ─────────────────────────────────────────────────── */

.gallery-hero {
  padding-block: clamp(2rem, 4vw, 3.25rem) clamp(1.25rem, 2.5vw, 2rem);
  background:
    radial-gradient(95% 100% at 12% 0%, var(--y-50) 0%, transparent 55%),
    var(--paper);
  border-bottom: 1px solid var(--line-2);
}

.gallery-hero__inner {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--s-5);
  align-items: end;
}

@media (min-width: 900px) {
  .gallery-hero__inner {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: var(--s-6);
  }
}

.gallery-hero h1 {
  font-size: clamp(1.9rem, 4.6vw, 3rem);
  font-weight: var(--fw-extrabold);
  letter-spacing: var(--ls-tighter);
  line-height: 1.08;
  margin: 0 0 var(--s-3);
  text-wrap: balance;
}

.gallery-hero .lede {
  font-size: var(--fs-lg);
  color: var(--ink-2);
  line-height: 1.55;
  max-width: 64ch;
  margin: 0;
}

.gallery-hero__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-3);
}

/* ── 2. Sticky filter bar ──────────────────────────────────────────────── */

.gallery-filters {
  position: sticky;
  top: var(--header-h);
  z-index: var(--z-sticky);
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--line-2);
  contain: layout style;
}

.gallery-filters__inner {
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
  padding-block: var(--s-4);
}

@media (min-width: 900px) {
  .gallery-filters__inner {
    flex-direction: row;
    align-items: center;
    gap: var(--s-5);
  }
}

/* ── 3. Search ─────────────────────────────────────────────────────────── */

.gallery-search {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  max-width: 480px;
}

.gallery-search .input {
  padding-left: 2.6rem;
  padding-right: 2.6rem;
  height: 44px;
  border-radius: var(--r-pill);
  background: var(--paper);
}

.gallery-search__icon {
  position: absolute;
  left: 0.95rem;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  color: var(--ink-4);
  pointer-events: none;
}

.gallery-search__clear {
  position: absolute;
  right: 0.5rem;
  top: 50%;
  transform: translateY(-50%);
  width: 30px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: var(--ink-3);
  transition: background-color var(--t-fast), color var(--t-fast);
}

.gallery-search__clear:hover {
  background: var(--paper-4);
  color: var(--ink);
}

.gallery-search__clear[hidden] {
  display: none;
}

.gallery-search__clear svg {
  width: 16px;
  height: 16px;
}

/* ── 4. Filter chips row ───────────────────────────────────────────────── */

.gallery-chips {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  overflow-x: auto;
  padding-block: 0.15rem;
  scrollbar-width: none;
  -ms-overflow-style: none;
  flex: 1 1 auto;
  min-width: 0;
}

.gallery-chips::-webkit-scrollbar { display: none; }

.gallery-chips .chip {
  flex: 0 0 auto;
}

.gallery-chips__divider {
  flex: 0 0 auto;
  width: 1px;
  height: 22px;
  background: var(--line-2);
  margin-inline: 0.35rem;
}

/* ── 5. Sort + result count ───────────────────────────────────────────── */

.gallery-meta {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.gallery-meta__count {
  font-size: var(--fs-xs);
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.gallery-meta__count b {
  color: var(--ink);
  font-weight: var(--fw-semibold);
}

.gallery-sort {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.gallery-sort .select {
  height: 38px;
  padding-block: 0;
  font-size: var(--fs-xs);
  border-radius: var(--r-pill);
  padding-left: 1rem;
  padding-right: 2.2rem;
  background-position: right 0.75rem center;
  min-width: 150px;
}

/* ── 6. Active filter summary ─────────────────────────────────────────── */

.gallery-active {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2);
  padding-block: var(--s-3);
  border-bottom: 1px solid var(--line-2);
  font-size: var(--fs-xs);
  color: var(--ink-3);
}

.gallery-active[hidden] { display: none; }

.gallery-active__chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.3rem 0.35rem 0.3rem 0.7rem;
  border-radius: var(--r-pill);
  background: var(--y-50);
  border: 1px solid var(--y-200);
  color: var(--y-800);
  font-weight: var(--fw-semibold);
}

.gallery-active__chip button {
  width: 20px;
  height: 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: var(--y-800);
  transition: background-color var(--t-fast);
}

.gallery-active__chip button:hover {
  background: var(--y-200);
}

.gallery-active__chip svg {
  width: 12px;
  height: 12px;
}

.gallery-active__clear {
  color: var(--ink-3);
  text-decoration: underline;
  text-decoration-color: var(--y-400);
  text-underline-offset: 0.2em;
  font-weight: var(--fw-medium);
  padding: 0.3rem 0.2rem;
}

.gallery-active__clear:hover {
  color: var(--ink);
}

/* ── 7. Grid ───────────────────────────────────────────────────────────── */

.gallery {
  padding-block: clamp(1.5rem, 3vw, 2.5rem) clamp(3rem, 6vw, 5rem);
}

.gallery__grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: clamp(1rem, 2.5vw, 1.5rem);
}

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

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

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

/* ── 8. Template card ──────────────────────────────────────────────────── */

.tpl-card {
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  overflow: hidden;
  box-shadow: var(--shadow-xs);
  transition: transform var(--t-base), box-shadow var(--t-base), border-color var(--t-base);
  min-width: 0;
}

.tpl-card:hover {
  transform: translateY(-3px);
  border-color: var(--y-300);
  box-shadow: var(--shadow-lg);
}

.tpl-card:focus-within {
  border-color: var(--y-500);
  box-shadow: var(--focus-ring);
}

/* Thumbnail ----------------------------------------------------------- */

.tpl-card__thumb {
  position: relative;
  aspect-ratio: 210 / 297;
  background: var(--paper-3);
  border-bottom: 1px solid var(--line-2);
  overflow: hidden;
  contain: strict;
}

.tpl-card__canvas {
  position: absolute;
  inset: 0;
  display: block;
  padding: 0;
  pointer-events: none;
}

.tpl-card__canvas > * {
  transform-origin: top left;
  transform: scale(0.4);
  width: calc(100% / 0.4);
  min-height: calc(100% / 0.4);
}

@media (min-width: 480px) {
  .tpl-card__canvas > * {
    transform: scale(0.44);
    width: calc(100% / 0.44);
    min-height: calc(100% / 0.44);
  }
}

@media (min-width: 900px) {
  .tpl-card__canvas > * {
    transform: scale(0.42);
    width: calc(100% / 0.42);
    min-height: calc(100% / 0.42);
  }
}

@media (min-width: 1280px) {
  .tpl-card__canvas > * {
    transform: scale(0.44);
    width: calc(100% / 0.44);
    min-height: calc(100% / 0.44);
  }
}

.tpl-card__skeleton {
  position: absolute;
  inset: 0;
  background: linear-gradient(
    90deg,
    var(--paper-3) 0%,
    var(--paper-2) 50%,
    var(--paper-3) 100%
  );
  background-size: 200% 100%;
  animation: tpl-shimmer 1.6s ease-in-out infinite;
  z-index: 1;
}

.tpl-card__canvas.is-ready + .tpl-card__skeleton,
.tpl-card__skeleton[hidden] {
  display: none;
}

@keyframes tpl-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Badges on the thumbnail ------------------------------------------- */

.tpl-card__badges {
  position: absolute;
  top: 10px;
  left: 10px;
  right: 10px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.4rem;
  z-index: 2;
  pointer-events: none;
  flex-wrap: wrap;
}

.tpl-card__badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.25rem 0.55rem;
  border-radius: var(--r-pill);
  font-size: var(--fs-3xs);
  font-weight: var(--fw-bold);
  letter-spacing: var(--ls-wide);
  text-transform: uppercase;
  background: rgba(15, 23, 42, 0.86);
  color: var(--paper);
  box-shadow: 0 4px 12px -6px rgba(15, 23, 42, 0.4);
  white-space: nowrap;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.tpl-card__badge--ats {
  background: var(--ink);
  color: var(--paper);
}

.tpl-card__badge--recommended {
  background: var(--y-500);
  color: var(--ink);
}

.tpl-card__badge svg {
  width: 11px;
  height: 11px;
}

/* Hover action bar --------------------------------------------------- */

.tpl-card__hover {
  position: absolute;
  inset: auto 0 0 0;
  padding: 0.65rem 0.75rem;
  display: flex;
  gap: 0.4rem;
  justify-content: center;
  align-items: center;
  background: linear-gradient(180deg, transparent 0%, rgba(15, 23, 42, 0.72) 100%);
  transform: translateY(100%);
  transition: transform var(--t-base);
  z-index: 3;
  pointer-events: auto;
}

.tpl-card:hover .tpl-card__hover,
.tpl-card:focus-within .tpl-card__hover {
  transform: translateY(0);
}

@media (pointer: coarse) {
  .tpl-card__hover {
    transform: translateY(0);
    background: linear-gradient(180deg, transparent 0%, rgba(15, 23, 42, 0.78) 100%);
    padding: 0.5rem 0.6rem;
  }
}

.tpl-card__hover .btn {
  box-shadow: none;
  min-height: 34px;
  padding: 0.45rem 0.75rem;
  font-size: var(--fs-2xs);
}

.tpl-card__hover .btn svg { width: 14px; height: 14px; }

/* Card body ---------------------------------------------------------- */

.tpl-card__body {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding: var(--s-4);
  flex: 1 1 auto;
  min-width: 0;
}

.tpl-card__title {
  font-size: var(--fs-md);
  font-weight: var(--fw-bold);
  letter-spacing: var(--ls-tight);
  color: var(--ink);
  line-height: 1.3;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.tpl-card__title a {
  color: inherit;
}

.tpl-card__title a::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
}

.tpl-card__letter {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: var(--r-xs);
  background: var(--y-100);
  color: var(--y-800);
  font-size: var(--fs-3xs);
  font-weight: var(--fw-extrabold);
  flex-shrink: 0;
}

.tpl-card__desc {
  font-size: var(--fs-xs);
  color: var(--ink-3);
  line-height: 1.5;
  margin: 0;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  min-height: 2.7em;
}

.tpl-card__meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.6rem;
  font-size: var(--fs-3xs);
  color: var(--ink-3);
  padding-top: 0.35rem;
  border-top: 1px solid var(--line-2);
  margin-top: 0.35rem;
  align-items: center;
}

.tpl-card__meta-item {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}

.tpl-card__meta-item svg {
  width: 12px;
  height: 12px;
  color: var(--ink-4);
  flex-shrink: 0;
}

.tpl-card__use {
  margin-top: auto;
  padding-top: var(--s-3);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  z-index: 2;
  position: relative;
}

.tpl-card__use-label {
  font-size: var(--fs-3xs);
  color: var(--ink-3);
  font-weight: var(--fw-semibold);
  letter-spacing: var(--ls-wide);
  text-transform: uppercase;
}

.tpl-card__use .btn {
  min-height: 32px;
  padding: 0.35rem 0.7rem;
  font-size: var(--fs-2xs);
}

.tpl-card__use .btn svg { width: 13px; height: 13px; }

/* ── 9. Skeletons ──────────────────────────────────────────────────────── */

.tpl-skeleton {
  border: 1px solid var(--line-2);
  border-radius: var(--r-lg);
  overflow: hidden;
  background: var(--paper);
}

.tpl-skeleton__thumb {
  aspect-ratio: 210 / 297;
  background: linear-gradient(
    90deg,
    var(--paper-4) 0%,
    var(--paper-3) 50%,
    var(--paper-4) 100%
  );
  background-size: 200% 100%;
  animation: tpl-shimmer 1.6s ease-in-out infinite;
}

.tpl-skeleton__body {
  padding: var(--s-4);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.tpl-skeleton__line {
  height: 0.9em;
  border-radius: var(--r-xs);
  background: var(--paper-4);
}

.tpl-skeleton__line--title {
  height: 1.15em;
  width: 70%;
}

.tpl-skeleton__line--short {
  width: 45%;
}

/* ── 10. Empty / error states ─────────────────────────────────────────── */

.gallery-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: var(--s-4);
  padding: clamp(3rem, 8vw, 6rem) var(--s-4);
  max-width: 480px;
  margin-inline: auto;
}

.gallery-state[hidden] { display: none; }

.gallery-state__icon {
  width: 60px;
  height: 60px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--r-lg);
  background: var(--y-100);
  color: var(--y-800);
}

.gallery-state__icon svg {
  width: 28px;
  height: 28px;
}

.gallery-state h3 {
  font-size: var(--fs-xl);
  font-weight: var(--fw-bold);
  letter-spacing: var(--ls-tight);
  margin: 0;
}

.gallery-state p {
  font-size: var(--fs-sm);
  color: var(--ink-3);
  line-height: 1.6;
  margin: 0;
}

.gallery-state__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-3);
  justify-content: center;
}

/* ── 11. Load more ─────────────────────────────────────────────────────── */

.gallery-more {
  display: flex;
  justify-content: center;
  padding-top: clamp(2rem, 4vw, 3rem);
}

.gallery-more[hidden] { display: none; }

/* ── 12. Print: hide gallery when it is only filter + grid ------------- */

@media print {
  .gallery-filters,
  .gallery-meta,
  .gallery-active,
  .gallery-more,
  .tpl-card__hover {
    display: none !important;
  }
  .gallery__grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 6mm;
  }
  .tpl-card {
    break-inside: avoid;
    page-break-inside: avoid;
    box-shadow: none;
  }
}