/* Template gallery (live thumbnails) and full-screen preview. Classes prefixed tg- and tp-. Loaded last. */

/* --- Gallery ----------------------------------------------------------------------------------------------- */
.tg-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 16px;
}
.tg-card {
  position: relative;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--si-line);
  border-radius: 14px;
  background: #fff;
  transition:
    box-shadow 0.2s,
    transform 0.2s;
}
.tg-card[hidden] {
  display: none;
}
.tg-card:hover {
  box-shadow: 0 12px 30px rgb(20 40 60 / 15%);
  transform: translateY(-2px);
}
.tg-card.is-chosen {
  border-color: var(--si-accent);
  box-shadow: 0 0 0 2px var(--si-accent);
}
.tg-chosen {
  position: absolute;
  z-index: 3;
  top: 10px;
  right: 10px;
  padding: 3px 11px;
  border-radius: 999px;
  background: var(--si-accent);
  color: #fff;
  font:
    700 12px/1.5 system-ui,
    sans-serif;
}
.tg-thumb {
  position: relative;
  padding: 12px 12px 0;
  background: linear-gradient(var(--si-soft), #e6edf2);
}
.tg-phone {
  overflow: hidden;
  border: 1px solid rgb(0 0 0 / 10%);
  border-bottom: 0;
  border-radius: 14px 14px 0 0;
  background: #fff;
}
.tg-screen {
  position: relative;
  width: 100%;
  aspect-ratio: 390 / 500;
  overflow: hidden;
  pointer-events: none;
}
.tg-scale {
  position: absolute;
  top: 0;
  left: 0;
  width: 390px;
  transform: scale(var(--k, 0.45));
  transform-origin: 0 0;
}
/*
 * A thumbnail is a still picture of the finished page; its animations play (from the start) only while the
 * card is hovered or focused, in the gallery as in the administrator's library. The still state is set with
 * :where(), so it has no weight: as soon as the card is hovered the page's own animations take over.
 */
:where(.tg-card:not(:hover):not(:focus-within), .tl-card:not(:hover):not(:focus-within)) .tg-screen * {
  animation: none !important;
}
:where(.tg-card:not(:hover):not(:focus-within), .tl-card:not(:hover):not(:focus-within))
  .tg-screen
  .dc-balloon {
  opacity: 0.95;
}
:where(.tg-card:not(:hover):not(:focus-within), .tl-card:not(:hover):not(:focus-within))
  .tg-screen
  .dc-balloon-1 {
  bottom: 20%;
}
:where(.tg-card:not(:hover):not(:focus-within), .tl-card:not(:hover):not(:focus-within))
  .tg-screen
  .dc-balloon-2 {
  bottom: 52%;
}
:where(.tg-card:not(:hover):not(:focus-within), .tl-card:not(:hover):not(:focus-within))
  .tg-screen
  .dc-balloon-3 {
  bottom: 30%;
}
:where(.tg-card:not(:hover):not(:focus-within), .tl-card:not(:hover):not(:focus-within))
  .tg-screen
  .dc-balloon-4 {
  bottom: 60%;
}
:where(.tg-card:not(:hover):not(:focus-within), .tl-card:not(:hover):not(:focus-within))
  .tg-screen
  .dc-balloon-5 {
  bottom: 44%;
}
:where(.tg-card:not(:hover):not(:focus-within), .tl-card:not(:hover):not(:focus-within))
  .tg-screen
  .dc-balloon-6 {
  bottom: 14%;
}
.tg-hit {
  position: absolute;
  inset: 0;
  display: grid;
  align-items: end;
  justify-items: center;
  padding: 0 0 14px;
  border: 0;
  background: transparent;
  cursor: zoom-in;
}
.tg-hit-label {
  padding: 7px 14px;
  border-radius: 999px;
  background: rgb(20 40 60 / 82%);
  color: #fff;
  font:
    700 12.5px/1.2 system-ui,
    sans-serif;
  opacity: 0;
  transform: translateY(6px);
  transition:
    opacity 0.2s,
    transform 0.2s;
}
.tg-card:hover .tg-hit-label,
.tg-hit:focus-visible .tg-hit-label {
  opacity: 1;
  transform: none;
}
.tg-hit:focus-visible {
  outline: 3px solid #86b6d2;
  outline-offset: -3px;
}
.tg-body {
  display: grid;
  gap: 6px;
  padding: 12px 14px 14px;
}
.tg-title {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 6px;
}
.tg-title h3 {
  margin: 0;
  font-size: 15px;
}
.tg-title .tl-badge {
  margin-left: 0;
}
.tg-meta {
  margin: 0;
  color: var(--si-muted);
  font-size: 13px;
}
.tg-body .tl-tags {
  margin-top: 0;
}
.tg-actions {
  display: flex;
  gap: 8px;
  margin-top: 6px;
}
.tg-actions .btn {
  flex: 1;
  min-height: 40px;
  padding: 0 10px;
  font-size: 13.5px;
}
/* Library (administrator): the same thumbnail, a little larger */
.tl-stage .tg-phone {
  width: min(100%, 230px);
  margin: 0 auto;
  border-bottom: 1px solid rgb(0 0 0 / 10%);
  border-radius: 14px;
}

/* --- Full-screen preview ------------------------------------------------------------------------------------ */
body.tp-open {
  overflow: hidden;
}
.tp {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  flex-direction: column;
  background: #1c2b38;
  color: #fff;
}
.tp-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 16px;
  padding: 10px 18px;
  background: #fff;
  color: var(--si-ink);
}
.tp-name {
  display: grid;
  min-width: 140px;
}
.tp-name b {
  font-size: 17px;
}
.tp-name small {
  color: var(--si-muted);
}
.tp-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-left: auto;
}
.tp-device [aria-pressed='true'] {
  background: #dff2fc;
  border-color: #7dbbde;
}
.tp-stage {
  display: grid;
  flex: 1;
  grid-template-columns: 56px minmax(0, 1fr) 56px;
  grid-template-rows: minmax(0, 1fr);
  align-items: center;
  min-height: 0;
  padding: 16px 8px 4px;
}
.tp-nav {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  margin: auto;
  border: 0;
  border-radius: 50%;
  background: rgb(255 255 255 / 14%);
  color: #fff;
  font-size: 30px;
  line-height: 1;
  cursor: pointer;
}
.tp-nav:hover {
  background: rgb(255 255 255 / 28%);
}
.tp-nav:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 2px;
}
.tp-nav[hidden] {
  display: none;
}
.tp-phone {
  height: 100%;
  max-height: 820px;
  margin: 0 auto;
}
.tp-phone[data-device='mobile'] {
  width: min(390px, 100%);
}
.tp-phone[data-device='desktop'] {
  width: min(1100px, 100%);
}
/* A transformed ancestor makes the opening screen (fixed) fill the phone, not the whole window. */
.tp-screen {
  position: relative;
  height: 100%;
  overflow-y: auto;
  overscroll-behavior: contain;
  transform: translateZ(0);
}
.tp-screen:has(.invite-opening) {
  overflow: hidden;
}
.tp-screen:focus-visible {
  outline: 3px solid #86b6d2;
  outline-offset: -3px;
}
.tp-screen .invitation {
  min-height: 100%;
  border-radius: 0;
}
.tp-note {
  margin: 0;
  padding: 8px 16px 14px;
  color: rgb(255 255 255 / 70%);
  font-size: 13px;
  text-align: center;
}
@media (max-width: 700px) {
  .tp-head {
    padding: 8px 12px;
  }
  .tp-stage {
    grid-template-columns: 0 minmax(0, 1fr) 0;
    padding: 8px 0 0;
  }
  .tp-nav {
    position: fixed;
    z-index: 2;
    bottom: 56px;
    width: 52px;
    height: 52px;
    background: rgb(20 40 60 / 80%);
  }
  .tp-prev {
    left: 12px;
  }
  .tp-next {
    right: 12px;
  }
  /* The arrows are fixed, so the phone is the only item left in the grid: it must be put in the wide middle column */
  .tp-phone {
    grid-column: 2;
  }
  .tp-phone[data-device='mobile'] {
    height: 100%;
    border-width: 4px;
    border-radius: 22px;
  }
  .tp-device {
    display: none;
  }
}
@media (prefers-reduced-motion: reduce) {
  .tg-card,
  .tg-hit-label,
  .tp-phone {
    transition: none;
  }
}

/* Library: a deactivated template shows its thumbnail dimmed, like before. */
.tl-card.is-off .tg-phone {
  opacity: 0.5;
  filter: grayscale(0.7);
}

/* Preview bar: icons first (names stay in the tooltips and for screen readers). */
.tp-ibtn {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid var(--si-line);
  border-radius: 10px;
  background: #fff;
  color: var(--si-ink);
  cursor: pointer;
}
.tp-ibtn:hover {
  background: var(--si-soft);
}
.tp-ibtn:focus-visible {
  outline: 3px solid #86b6d2;
  outline-offset: 1px;
}
.tp-ibtn .icon,
.tp-nav .icon {
  width: 20px;
  height: 20px;
}
.tp-nav .icon {
  width: 26px;
  height: 26px;
}
.tp-device {
  display: inline-flex;
}
.tp-device .tp-ibtn:first-child {
  border-radius: 10px 0 0 10px;
}
.tp-device .tp-ibtn:last-child {
  margin-left: -1px;
  border-radius: 0 10px 10px 0;
}
.tp-device .tp-ibtn[aria-pressed='true'] {
  position: relative;
  background: #dff2fc;
  border-color: #7dbbde;
  color: #1f4f6e;
}
