/* ═══════════════════════════════ 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;
  padding-left: max(28px, env(safe-area-inset-left)); padding-right: max(28px, env(safe-area-inset-right));
  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; }
/* THE TOOLBAR (owner, Oct 23: "the style and industries should be menus"):
   search · Industry · Style · Horizontal | Vertical, one row that wraps */
.tpl__tools { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 12px; }
/* search (Oct 22): every word must be in the design's name, style, trade or tags */
.tpl__search { flex: 1 1 260px; max-width: 460px; min-width: 0; }
.tpl__searchin {
  width: 100%; min-height: 46px; padding: 10px 16px 10px 42px;
  border: 1.5px solid var(--line-soft); border-radius: 999px;
  background: var(--paper) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%236B6F7B' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E") no-repeat 16px 50%;
  color: var(--ink); font: inherit; font-size: var(--fs-body);
}
.tpl__searchin:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.tpl__found { margin: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; font-size: var(--fs-small); color: var(--ink-70); }
.tpl__found:empty { display: none; }
.tpl__clear { min-height: 32px; padding: 4px 10px; }
/* the menus: a native select laid over a face that shows the choice (its list
   carries the counts, and greys a choice that would show nothing) */
.tpl__menus { display: flex; gap: 10px; flex: 0 1 auto; min-width: 0; }
.tpl__menu { position: relative; flex: 0 1 220px; width: 220px; min-width: 0; }
.tpl__menuface {
  display: block; height: 46px; padding: 0 40px 0 16px;
  border: 1.5px solid var(--line-soft); border-radius: 999px;
  background: var(--paper); color: var(--ink);
  font-size: var(--fs-body); font-weight: 500; line-height: 43px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.tpl__menu::after {
  content: ""; position: absolute; top: 50%; right: 19px;
  width: 7px; height: 7px; margin-top: -6px;
  border-right: 1.8px solid currentColor; border-bottom: 1.8px solid currentColor;
  transform: rotate(45deg); color: var(--ink-70); pointer-events: none;
}
.tpl__select {
  position: absolute; inset: 0; width: 100%; height: 100%;
  opacity: 0; cursor: pointer;
  /* 16px: a phone never zooms in on it */
  font-size: 16px;
}
.tpl__menu:hover .tpl__menuface { border-color: var(--accent-line); }
.tpl__menu:focus-within .tpl__menuface { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.tpl__menu:has(.tpl__select:focus-visible) .tpl__menuface { outline: 2px solid var(--accent); outline-offset: 2px; }
.tpl__menu.is-on .tpl__menuface { border-color: var(--accent); background: var(--accent-soft); font-weight: 600; }
/* SIZE AND FOLD (owner, Oct 26): a row of its own above the search, for the choices that are
   still the customer's to change; the same pill menus, never filled (they filter nothing) */
.tpl__pick { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 12px; }
.tpl__menu--size { flex: 0 1 320px; width: 320px; }
.tpl__menu--fold { flex: 0 1 220px; width: 220px; }
/* Horizontal | Vertical (business cards: made both ways) */
.tpl__way { flex: none; }
.tpl__waybtn svg { flex: none; }
.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; }
.tpl__grid[data-family="business-card"][data-shape="tall"] .tcard__thumb { aspect-ratio: 1 / 1; }
.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));
}
/* BOTH SIDES of a business card (owner, Oct 22): the back behind, the front over it */
.tcard__thumb.is-pair { position: relative; }
.tcard__thumb.is-pair .tcard__img {
  position: absolute; width: 64%; height: 62%; max-width: none; max-height: none;
  object-fit: contain; border-radius: 0; box-shadow: none;
  filter: drop-shadow(0 1px 1px rgba(20, 22, 28, .16)) drop-shadow(0 4px 10px rgba(20, 22, 28, .14));
}
.tcard__img--back { top: 6%; right: 5%; object-position: right top; }
.tcard__img--front { bottom: 6%; left: 5%; object-position: left bottom; }
/* ...an upright card: the two side by side */
.tcard__thumb.is-pair.is-tall .tcard__img { top: 6%; bottom: auto; width: 43%; height: 88%; }
.tcard__thumb.is-pair.is-tall .tcard__img--front { left: 6%; object-position: right center; }
.tcard__thumb.is-pair.is-tall .tcard__img--back { right: 6%; object-position: left center; }
.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 WAYS OUT among the designs (owner, Oct 23, "like Vista"): a tile the
   size of a design. "Upload your own design" on the paper with a thin outline,
   "Have our team design it" in ink with white type ---- */
.tway {
  display: flex; flex-direction: column; align-items: flex-start; gap: 8px;
  min-width: 0; min-height: 200px;
  padding: 22px 22px 20px;
  text-align: left;
  border-radius: var(--r-lg);
  transition: box-shadow .16s ease, transform .16s ease, background-color .16s ease;
}
.tway--upload { background: var(--paper); color: var(--ink); box-shadow: inset 0 0 0 1.5px var(--accent-line); }
.tway--upload:hover:not(:disabled) { box-shadow: inset 0 0 0 1.5px var(--accent); }
.tway--designer { background: var(--ink); color: #fff; }
.tway--designer:hover:not(:disabled) { box-shadow: var(--shadow-pop); transform: translateY(-2px); }
.tway:focus-visible { outline-offset: 3px; }
.tway:disabled { cursor: default; opacity: .6; }
.tway__icon {
  display: grid; place-items: center; width: 46px; height: 46px; margin-bottom: auto;
  border-radius: 50%; background: var(--accent-soft); color: var(--ink);
}
.tway__kicker { margin-bottom: auto; font-size: var(--fs-micro); font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: rgba(255, 255, 255, .7); }
.tway__title { font-size: 19px; font-weight: 700; letter-spacing: -0.01em; line-height: 1.2; }
.tway__text { font-size: var(--fs-small); line-height: 1.45; color: var(--ink-70); }
.tway--designer .tway__text { color: rgba(255, 255, 255, .78); }
.tway__fine { font-size: var(--fs-micro); color: rgba(255, 255, 255, .7); }
.tway__go { display: inline-flex; align-items: center; gap: 8px; margin-top: 4px; font-size: var(--fs-small); font-weight: 600; }
.tway__arrow { font-size: 18px; line-height: 1; transition: transform .2s ease; }
.tway:hover:not(:disabled) .tway__arrow { transform: translateX(4px); }

/* ---- PAGES (owner, Oct 23: "too much scrolling on one page"): 24 designs a
   page, ‹ Prev 1 2 3 4 5 … 14 Next › and "Showing 25–48 of 330" under them ---- */
.tpl__pager {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  margin-top: 22px; padding-top: 22px;
  border-top: 1px solid var(--line-soft);
}
.tpl__pages { display: flex; align-items: center; justify-content: center; gap: 6px; max-width: 100%; }
.tpl__pagenums { display: flex; align-items: center; gap: 4px; }
.tpl__pagebtn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-width: 44px; height: 44px; padding: 0 10px;
  border: 1px solid transparent; border-radius: 999px;
  color: var(--ink); font-size: var(--fs-small); font-weight: 600; font-variant-numeric: tabular-nums;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.tpl__pagebtn:hover:not(:disabled):not(.is-on) { background: var(--accent-soft); }
.tpl__pagebtn.is-on { background: var(--accent); color: var(--accent-ink); cursor: default; }
.tpl__pagestep { padding: 0 16px; border-color: var(--accent-line); background: var(--paper); }
.tpl__pagebtn:disabled { opacity: .4; cursor: default; }
.tpl__pagearrow { font-size: 20px; line-height: 1; margin-top: -2px; }
.tpl__pagegap { min-width: 22px; text-align: center; color: var(--muted); }
.tpl__pagenow { display: none; min-width: 72px; text-align: center; font-size: var(--fs-body); font-weight: 600; font-variant-numeric: tabular-nums; color: var(--ink); }
.tpl__showing { margin: 0; font-size: var(--fs-small); color: var(--ink-70); font-variant-numeric: tabular-nums; }

/* ---- 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);
  /* the one row is held to the window's own max-height, so the facts column
     scrolls inside it instead of running off the bottom (a short window, or a
     phone on its side, used to cut "Use this template" off) */
  grid-template-rows: minmax(0, 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%; }
/* the answer line and the button share a bar; off a phone the bar is not a box at
   all, so the window lays out exactly as it did without it */
.tplmodal__bar { display: contents; }
/* dvh follows the phone's moving address bar; the vh lines above are the fallback */
@supports (height: 100dvh) {
  .tplmodal__box { max-height: calc(100dvh - 48px); }
  .tplmodal__img { max-height: min(64dvh, var(--nat-h, 64dvh)); }
}
.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); }

/* ---- phones and small windows (899: app.css's one phone breakpoint) ---- */
@media (max-width: 899px) {
  /* taps are 44px: the preview's close button and Horizontal | Vertical (the
     menus and the page numbers already are) */
  .tplmodal__close { width: 44px; height: 44px; }
  .tpl__way .segctl__btn { min-height: 44px; }
  /* "Use this template" never scrolls out of reach: the answer line and the
     button stick to the bottom of whatever scrolls (the info column, or on a
     narrow phone the whole window), on the window's own paper */
  .tplmodal__bar {
    display: flex; flex-direction: column; gap: 12px;
    position: sticky; bottom: 0; z-index: 2;
    margin: auto -28px -26px;
    padding: 12px 28px calc(14px + env(safe-area-inset-bottom));
    background: var(--paper);
    box-shadow: 0 -12px 18px -16px rgba(20, 22, 28, .4);
  }
  .tplmodal__use { margin-top: 0; min-height: 52px; }
  .tplmodal { padding-left: max(24px, env(safe-area-inset-left)); padding-right: max(24px, env(safe-area-inset-right)); }
}

@media (max-width: 720px) {
  .page--templates .tpl__inner { padding: 12px 16px 48px; padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
  .tpl__tabs { max-width: 100%; }
  /* the toolbar wraps: the search the full width, the two menus side by side,
     Horizontal | Vertical under them, its halves equal */
  .tpl__search { flex: 1 1 100%; max-width: none; }
  .tpl__menus { flex: 1 1 100%; }
  .tpl__menu { flex: 1 1 0; width: auto; }
  /* Size and Fold: each the full width, so the size is read in full ("Size: 24 × 16 in · landscape") */
  .tpl__pick .tpl__menu { flex: 1 1 100%; }
  .tpl__menuface { padding: 0 34px 0 14px; font-size: 15px; }
  .tpl__menu::after { right: 16px; }
  .tpl__way { display: flex; flex: 1 1 100%; }
  .tpl__way .segctl__btn { flex: 1 1 0; }
  .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; }
  /* a ways-out tile in a phone's half width: its words smaller, the longer line left out */
  .tway { min-height: 168px; padding: 14px 14px 13px; gap: 5px; }
  .tway__icon { width: 38px; height: 38px; }
  .tway__title { font-size: 15.5px; }
  .tway__text { font-size: 12.5px; }
  .tway--designer .tway__text, .tway__more { display: none; }
  .tplmodal { padding: 12px; align-items: center; padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right)); }
  .tplmodal__box, .tplmodal__box[data-family="flyer"], .tplmodal__box[data-family="door-hanger"] {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto;
    max-height: calc(100vh - 24px);
    max-height: calc(100dvh - 24px);
    overflow-y: auto;
    overscroll-behavior: contain;
  }
  .tplmodal__fig { padding: 18px 16px; grid-row: 1; grid-column: 1; }
  .tplmodal__img { max-height: min(40vh, var(--nat-h, 40vh)); }
  .tplmodal__info { padding: 18px 18px 20px; overflow: visible; grid-row: 2; grid-column: 1; }
  .tplmodal__title { font-size: 22px; }
  .tplmodal__bar { margin: auto -18px -20px; padding: 12px 18px calc(14px + env(safe-area-inset-bottom)); }
  /* the close button stays in view however far the window is scrolled: it sits
     in the picture's corner (one cell with it) and sticks to the top of the box */
  .tplmodal__close {
    position: sticky; top: 8px; right: auto; z-index: 3;
    grid-row: 1 / 3; grid-column: 1;
    justify-self: end; align-self: start;
    margin: 8px 8px 0 0;
  }
}
@supports (height: 100dvh) {
  @media (max-width: 720px) {
    .tplmodal__img { max-height: min(40dvh, var(--nat-h, 40dvh)); }
  }
}
/* a phone has no room for every page number: ‹ 3 / 14 › */
@media (max-width: 560px) {
  .tpl__pages { gap: 16px; }
  .tpl__pagenums, .tpl__pageword { display: none; }
  .tpl__pagenow { display: inline-block; }
  .tpl__pagestep { width: 48px; height: 48px; padding: 0; }
}

/* ---- 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; }
}
