/* ═══════════════════════════════ TEMPLATES ═══════════════════════════════
   The gallery page (opened from the start page's "Choose a template", for the
   product and size already chosen), the compact preview window, and the
   designer's "Loading your template…" state. Tokens and button classes are
   app.css's own. */

/* ---- the gallery page ---- */
.page--templates .tpl__inner {
  width: 100%; max-width: 1120px;
  margin: 0 auto;
  padding: 18px 28px 64px;
  display: flex; flex-direction: column; align-items: stretch; gap: 14px;
  min-width: 0;
}
.page--templates .backlink { align-self: flex-start; min-height: 44px; }
.tpl__title {
  margin: 4px 0 0;
  font-size: clamp(28px, 3.4vw, 42px); font-weight: 700;
  letter-spacing: -0.03em; line-height: 1.08; color: var(--ink);
}
.tpl__title:focus { outline: none; }
.tpl__lead { margin: 0 0 6px; font-size: var(--fs-body); color: var(--ink-70); max-width: 60ch; }
.tpl__leadrow { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; margin-bottom: 4px; }
.tpl__leadrow .tpl__lead { margin: 0; flex: 1 1 320px; }
.tpl__pickchip {
  display: inline-flex; align-items: center; gap: 8px; flex: 0 0 auto;
  padding: 7px 16px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent);
  font-size: var(--fs-small); font-weight: 600; font-variant-numeric: tabular-nums;
}
.tpl__pickdot { opacity: .6; }
.tpl__scratch { flex: 0 0 auto; border: 1px solid var(--accent-line); }
.tplmodal__size { margin: 0; display: flex; align-items: baseline; gap: 10px; }
.tplmodal__size .tplmodal__label { margin: 0; }
.tplmodal__sizeval { font-size: var(--fs-small); font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums; }
.tpl__tabs { align-self: flex-start; overflow-x: auto; scrollbar-width: none; }
.tpl__tabs::-webkit-scrollbar { display: none; }
.tpl__chips { display: flex; flex-wrap: wrap; gap: 8px; }
.tpl__chip { cursor: pointer; }
.tpl__status { margin: 8px 0; font-size: var(--fs-small); color: var(--muted); }

.tpl__grid {
  display: grid; gap: 18px;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  margin-top: 6px;
}
.tpl__grid[data-family="flyer"] { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.tpl__grid[data-family="door-hanger"] { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }

.tcard {
  display: flex; flex-direction: column; align-items: stretch;
  padding: 0; overflow: hidden; min-width: 0;
  text-align: left;
  border: 1.5px solid var(--line-soft);
  border-radius: var(--r-lg);
  background: var(--paper);
  box-shadow: var(--shadow-float);
  transition: border-color .16s ease, transform .16s ease, box-shadow .16s ease;
}
.tcard:hover { border-color: var(--accent); transform: translateY(-2px); box-shadow: var(--shadow-pop); }
.tcard:focus-visible { outline-offset: 3px; }
.tcard__thumb {
  display: flex; align-items: center; justify-content: center;
  aspect-ratio: 3 / 2;
  padding: 14px;
  background: var(--workspace);
}
.tpl__grid[data-family="flyer"] .tcard__thumb { aspect-ratio: 4 / 5; }
.tpl__grid[data-family="door-hanger"] .tcard__thumb { aspect-ratio: 1 / 2; }
.tcard__img {
  display: block; max-width: 100%; max-height: 100%;
  width: auto; height: auto; object-fit: contain;
  border-radius: 3px;
  box-shadow: var(--shadow-paper, 0 1px 3px rgba(20, 22, 28, .18));
}
.tcard__meta { display: flex; flex-direction: column; gap: 2px; padding: 12px 16px 14px; min-width: 0; }
.tcard__name { font-size: 16px; font-weight: 700; letter-spacing: -0.01em; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tcard__trade { font-size: var(--fs-small); color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---- the compact preview window: picture left, facts right ---- */
.tplmodal {
  position: fixed; inset: 0; z-index: 60;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  background: rgba(22, 24, 28, 0.46);
  animation: pageIn .18s var(--ease) both;
}
.tplmodal__box {
  position: relative;
  width: 100%; max-width: 900px;
  max-height: calc(100vh - 48px);
  display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(260px, 1fr);
  overflow: hidden;
  border-radius: var(--r-xl);
  background: var(--paper);
  box-shadow: var(--shadow-pop);
}
.tplmodal__box[data-family="flyer"], .tplmodal__box[data-family="door-hanger"] {
  max-width: 780px; grid-template-columns: minmax(0, 1fr) minmax(260px, 1fr);
}
.tplmodal__fig {
  min-width: 0; min-height: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 28px;
  background: var(--workspace);
}
.tplmodal__img {
  display: block;
  max-width: 100%;
  max-height: min(64vh, var(--nat-h, 64vh));
  width: auto; height: auto;
  border-radius: 4px;
  box-shadow: var(--shadow-paper, 0 2px 8px rgba(20, 22, 28, .22));
}
.tplmodal__info {
  min-width: 0;
  display: flex; flex-direction: column; align-items: stretch; gap: 12px;
  padding: 30px 28px 26px;
  overflow-y: auto;
}
.tplmodal__title { margin: 0; padding-right: 36px; font-size: 26px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.15; color: var(--ink); }
.tplmodal__facts { margin: 0; display: flex; flex-wrap: wrap; gap: 6px; font-size: var(--fs-small); color: var(--muted); }
.tplmodal__trade { font-weight: 600; color: var(--accent); }
.tplmodal__desc { margin: 0; font-size: var(--fs-body); line-height: 1.5; color: var(--ink-70); }
.tplmodal__sides { align-self: flex-start; }
.tplmodal__note { margin: -4px 0 0; font-size: var(--fs-micro); color: var(--muted); }
.tplmodal__label { margin: 0 0 6px; font-size: var(--fs-small); font-weight: 600; color: var(--ink-70); }
.tplmodal__sizelist { justify-content: flex-start; }
.tplmodal__error { margin: 0; font-size: 13px; color: var(--warn-ink); }
.tplmodal__use { margin-top: auto; width: 100%; }
.tplmodal__close {
  position: absolute; top: 12px; right: 12px; z-index: 2;
  width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center;
  color: var(--ink-70); background: color-mix(in srgb, var(--paper) 90%, transparent);
  border: 1px solid var(--line-soft);
}
.tplmodal__close:hover { color: var(--ink); background: var(--paper); }

@media (max-width: 720px) {
  .page--templates .tpl__inner { padding: 12px 16px 48px; }
  .tpl__tabs { max-width: 100%; }
  .tpl__chips { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 0 16px 2px; }
  .tpl__chips::-webkit-scrollbar { display: none; }
  .tpl__chip { flex: 0 0 auto; }
  .tpl__grid { gap: 12px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tpl__grid[data-family="flyer"], .tpl__grid[data-family="door-hanger"] { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tcard__thumb { padding: 10px; }
  .tcard__meta { padding: 9px 11px 11px; }
  .tcard__name { font-size: 14px; }
  .tplmodal { padding: 12px; align-items: center; }
  .tplmodal__box, .tplmodal__box[data-family="flyer"], .tplmodal__box[data-family="door-hanger"] {
    grid-template-columns: 1fr;
    max-height: calc(100dvh - 24px);
    overflow-y: auto;
  }
  .tplmodal__fig { padding: 18px 16px; }
  .tplmodal__img { max-height: min(40vh, var(--nat-h, 40vh)); }
  .tplmodal__info { padding: 18px 18px 20px; overflow: visible; }
  .tplmodal__title { font-size: 22px; }
}

/* ---- the designer while a template's art is on its way (owner, Sept 28:
   "it should say that it's loading your template instead of just being blank").
   Sits over the blank press surface inside #docArt; main.js beginTemplate adds
   it before the designer opens and removes it once the art has landed. ---- */
.doc__tplload {
  position: absolute; inset: 0; z-index: 3;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px;
  background:
    repeating-linear-gradient(45deg, var(--paper) 0 7px, rgba(0, 0, 0, 0.014) 7px 14px);
  animation: pageIn .2s var(--ease) both;
}
.doc__tplload[hidden] { display: none; }
.doc__tplspin {
  width: 30px; height: 30px; border-radius: 50%;
  border: 2.5px solid var(--accent-soft); border-top-color: var(--accent);
  animation: spin .85s linear infinite;
}
.doc__tpltext { font-size: var(--fs-small); font-weight: 500; color: var(--ink-70); }
.doc__art.is-tplloading .doc__blank { visibility: hidden; }
@media (prefers-reduced-motion: reduce) {
  .doc__tplspin { animation-duration: 2.4s; }
}
