.template-detail-page {
  --site-page-background: #f7f8fa;
  background: var(--site-page-background);
}

.template-detail-page .site-header {
  background: #fff;
}

.template-detail-page .site-nav .site-nav__link[aria-current='location']:not(:hover, :focus-visible) {
  color: inherit;
  font-weight: inherit;
}

.template-detail-layout {
  position: relative;
  width: min(750px, 100% - var(--site-gutter) * 2);
  margin-inline: auto;
}

.template-detail-layout {
  padding-block: 24px 116px;
}

.template-detail-summary {
  padding: 20px clamp(16px, 4vw, 32px);
  background: #fff;
  overflow-wrap: anywhere;
}

.template-detail-summary h1 {
  margin: 0 0 8px;
  color: var(--color-ink);
  font-size: clamp(20px, 3vw, 24px);
}

.template-detail-summary p {
  margin: 0;
  color: #666;
}

.template-button {
  display: inline-flex;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px 16px;
  border: 1px solid #ddd;
  border-radius: 8px;
  background: #fff;
  color: #555;
  font: inherit;
  line-height: 1.5;
  white-space: nowrap;
  cursor: pointer;
}

.template-button:hover {
  background: #fff8e8;
}

.template-button--primary {
  border-color: var(--color-accent);
  background: var(--color-accent);
  color: #fff;
}

.template-button--primary:hover {
  border-color: #ec9c00;
  background: #ec9c00;
}

.template-button--outlined,
.template-button--icon {
  border-color: var(--color-accent);
  color: #956000;
}

.template-button--icon {
  width: 40px;
  padding-inline: 0;
  border-color: transparent;
  color: var(--color-accent);
}

.template-detail-controls {
  position: absolute;
  z-index: 3;
  top: 24px;
  left: calc(100% + 24px);
  display: grid;
  justify-items: start;
  gap: 16px;
}

.template-detail-controls > .template-popover > summary,
.template-detail-use > .template-button--primary {
  width: 112px;
}

.template-detail-controls > .template-popover > .template-button--outlined {
  color: var(--color-accent);
}

.template-detail-use {
  display: flex;
  gap: 8px;
}

.template-devices {
  display: inline-flex;
  width: fit-content;
  padding: 8px;
  border-radius: 8px;
  background: #fff;
}

.template-devices button {
  display: grid;
  width: 48px;
  height: 40px;
  padding: 0;
  place-items: center;
  border: 0;
  background: #f7f8fa;
  color: #555;
  cursor: pointer;
}

.template-devices button:first-child {
  border-radius: 6px 0 0 6px;
}

.template-devices button:last-child {
  border-radius: 0 6px 6px 0;
}

.template-devices button[aria-pressed='true'] {
  background: var(--color-accent);
  color: #fff;
}

.template-device-icon {
  position: relative;
  display: block;
  border: 2px solid currentColor;
}

.template-device-icon--mobile {
  width: 12px;
  height: 18px;
  border-radius: 3px;
}

.template-device-icon--mobile::after {
  position: absolute;
  bottom: 1px;
  left: calc(50% - 1px);
  width: 2px;
  height: 2px;
  border-radius: 50%;
  background: currentColor;
  content: '';
}

.template-device-icon--desktop {
  width: 18px;
  height: 13px;
  margin-bottom: 3px;
  border-radius: 2px;
}

.template-device-icon--desktop::after {
  position: absolute;
  bottom: -5px;
  left: calc(50% - 3px);
  width: 6px;
  height: 2px;
  background: currentColor;
  content: '';
}

.template-menu-icon {
  width: 16px;
  height: 2px;
  border-radius: 2px;
  background: currentColor;
  box-shadow: 0 -5px currentColor, 0 5px currentColor;
}

.template-star-icon {
  font-size: 26px;
  line-height: 1;
}

.template-popover {
  position: relative;
}

.template-popover summary {
  list-style: none;
}

.template-popover summary::-webkit-details-marker {
  display: none;
}

.template-popover__panel {
  position: absolute;
  z-index: 2;
  top: calc(100% + 8px);
  left: 0;
  display: grid;
  width: max-content;
  padding: 6px;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 4px 20px rgb(0 0 0 / 16%);
}

.template-detail-use > .template-button--primary + .template-popover > .template-popover__panel,
.template-preview__actions [data-template-management] > .template-popover__panel {
  inset-inline: auto 0;
}

.template-popover__panel :is(a, form button) {
  padding: 8px 12px;
  border-radius: 4px;
}

.template-popover__panel :is(a, form button):hover {
  background: #f7f8fa;
}

.template-popover__qr {
  justify-items: center;
  gap: 8px;
  padding: 10px;
  color: #666;
  font-size: 13px;
}

.template-example {
  background: #fff;
}

.template-example[data-mode='mobile'] {
  padding: 36px 12px;
}

.template-example[hidden],
.template-live-status[hidden],
#slot-page[hidden] {
  display: none;
}

.template-live-window {
  min-width: 0;
  overflow-x: auto;
}

.template-example[data-mode='mobile'] .template-live-frame {
  /* Visible dimensions of the old phone frame, excluding the shadow. */
  position: relative;
  display: grid;
  grid-template-rows: minmax(0, 1fr);
  width: min(369px, 100%);
  aspect-ratio: 369 / 760;
  margin-inline: auto;
  padding: clamp(10px, 4.75%, 17.5px) clamp(10px, 4.6%, 17px);
  border-radius: 14% / 7%;
  background: #fff;
  box-shadow: 0 0 30px rgb(0 0 0 / 10%);
}

.template-example[data-mode='mobile'] .template-live-frame::before,
.template-example[data-mode='mobile'] .template-live-frame::after {
  position: absolute;
  width: 3px;
  border-radius: 2px;
  content: '';
  pointer-events: none;
}

.template-example[data-mode='mobile'] .template-live-frame::before {
  top: 20%;
  right: calc(100% - 1px);
  height: 24%;
  background: linear-gradient(#fff 14%, transparent 14% 29%, #fff 29% 59%, transparent 59% 70%, #fff 70%);
}

.template-example[data-mode='mobile'] .template-live-frame::after {
  top: 30%;
  left: calc(100% - 1px);
  height: 11.5%;
  background: #fff;
}

.template-example[data-mode='mobile'] .template-live-window {
  overflow: hidden auto;
  border: 1px solid #eee;
  border-radius: 10% / 4.7%;
  background: #f6f7fb;
  scrollbar-width: none;
}

.template-example[data-mode='mobile']:is(:not([data-template-method]), [data-template-method=''], [data-preview-unavailable]) .template-live-frame {
  aspect-ratio: auto;
  border-radius: 32px;
}

.template-phone-chrome {
  display: none;
}

.template-detail-page .template-example[data-mode='mobile']:not([hidden]) {
  display: grid;
  height: 900px;
  grid-template-rows: minmax(0, 1fr);
  overflow: hidden;
  padding: 24px 12px 0;
}

.template-detail-page .template-example[data-mode='mobile'] .template-live-frame {
  width: min(399px, 100%);
  min-height: 0;
  aspect-ratio: auto;
  padding: 12px 12px 0;
  border-radius: 40px 40px 0 0;
}

.template-detail-page .template-example[data-mode='mobile'] .template-live-frame::before,
.template-detail-page .template-example[data-mode='mobile'] .template-live-frame::after {
  content: none;
}

.template-detail-page .template-example[data-mode='mobile'] .template-live-window {
  border-color: #ddd;
  border-radius: 32px 32px 0 0;
}

.template-detail-page .template-example[data-mode='mobile']:not([data-preview-unavailable]) .template-phone-chrome {
  display: block;
  background: #fff;
}

.template-phone-chrome img {
  display: block;
  width: 100%;
  height: auto;
}

.template-detail-page .template-example[data-mode='mobile']:is(:not([data-template-method]), [data-template-method=''], [data-preview-unavailable]) {
  height: auto;
  padding-bottom: 24px;
}

.template-detail-page .template-example[data-mode='mobile']:is(:not([data-template-method]), [data-template-method=''], [data-preview-unavailable]) .template-live-frame {
  padding-bottom: 12px;
  border-radius: 28px;
}

.template-detail-page .template-example[data-mode='mobile']:is(:not([data-template-method]), [data-template-method=''], [data-preview-unavailable]) .template-live-window {
  border-radius: 22px;
}

.template-live-status {
  display: grid;
  min-height: 140px;
  align-content: center;
  justify-items: center;
  gap: 8px;
  padding: 20px;
  color: #666;
  text-align: center;
}

.template-live-status p {
  margin: 0;
}

.template-live-status a {
  color: #956000;
  text-decoration: underline;
  text-underline-offset: 3px;
}

#slot-page,
#slot-page [class$='-template-page'],
#slot-page [class*='-template-page '],
#slot-page .feedback-detail-content,
#slot-page .feedback-summary-content {
  max-width: 100%;
  min-width: 0;
}

.template-related {
  margin-top: 8px;
  padding: 24px 32px 32px;
  background: #fff;
}

.template-related h2 {
  margin: 0 0 16px;
  font-size: 16px;
  font-weight: 400;
  line-height: 24px;
}

.template-related h2::before {
  display: inline-block;
  width: 4px;
  height: 16px;
  margin-right: 8px;
  border-radius: 2px;
  background: var(--color-accent);
  vertical-align: -2px;
  content: '';
}

.template-related ul {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.template-related a {
  display: block;
  overflow: hidden;
  padding: 8px 12px;
  border-radius: 6px;
  background: #f7f8fa;
  color: #526fa3;
  font-size: 14px;
  line-height: 24px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.template-related a:hover {
  background: #edf3ff;
}

.template-detail-page .template-related a {
  color: #426bc0;
  font-size: clamp(14px, 1.5vw, 16px);
}

.template-preview-page {
  display: grid;
  min-height: 100dvh;
  place-items: start center;
  padding: clamp(12px, 4vh, 42px) var(--site-gutter);
  background: #242424;
}

.template-preview {
  display: flex;
  width: min(750px, 100%);
  max-height: calc(100dvh - 2 * clamp(12px, 4vh, 42px));
  overflow: auto;
  flex-direction: column;
  border-radius: 8px;
  background: #f7f8fa;
  overscroll-behavior: contain;
}

.template-preview > * {
  flex: none;
}

.template-preview__header,
.template-preview__actions {
  position: sticky;
  z-index: 4;
  display: flex;
  min-height: 56px;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-inline: 32px;
  background: #fff;
}

.template-preview__header {
  top: 0;
  border-bottom: 1px solid #f2f2f2;
}

.template-preview__header h1 {
  margin: 0;
  color: #555;
  font-size: 16px;
  font-weight: 400;
}

.template-preview__header h1 span {
  font-size: 22px;
  vertical-align: -1px;
}

.template-preview__header .template-devices {
  position: absolute;
  left: 50%;
  padding: 0;
  transform: translateX(-50%);
}

.template-preview__header .template-devices button {
  width: 54px;
  background: transparent;
}

.template-preview__header .template-devices button[aria-pressed='true'] {
  color: var(--color-accent);
}

.template-preview__close {
  padding: 4px;
  color: #555;
  font-size: 24px;
  line-height: 1;
}

.template-preview .template-example {
  background: #f7f8fa;
}

.template-preview__actions {
  bottom: 0;
  min-height: 88px;
  justify-content: flex-start;
  margin-top: 8px;
  padding-block: 16px;
  border-top: 1px solid #f2f2f2;
}

.template-preview__actions .template-popover__panel {
  top: auto;
  bottom: calc(100% + 8px);
}

.template-preview__use {
  margin-inline-start: auto;
}

@media (max-width: 1240px) {
  .template-detail-controls {
    position: relative;
    top: auto;
    left: auto;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin-bottom: 16px;
  }

  .template-detail-controls > .template-popover > summary {
    width: auto;
  }
}

@media (max-width: 620px) {
  .template-detail-layout {
    padding-block: 16px 72px;
  }

  .template-detail-controls > .template-popover:has(> .template-popover__qr) {
    position: static;
  }

  .template-detail-controls .template-popover__qr {
    inset-inline: auto 0;
  }

  .template-example[data-mode='mobile'] {
    padding: 24px 8px;
  }

  .template-detail-page .template-example[data-mode='mobile'] {
    height: 800px;
    padding: 16px 8px 0;
  }

  .template-detail-page .template-example[data-mode='mobile'] .template-live-frame {
    padding-inline: 8px;
    border-start-start-radius: 28px;
    border-start-end-radius: 28px;
  }

  .template-detail-page .template-example[data-mode='mobile'] .template-live-window {
    border-start-start-radius: 22px;
    border-start-end-radius: 22px;
  }

  .template-related {
    padding: 20px 16px;
  }

  .template-related ul {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .template-preview__header,
  .template-preview__actions {
    padding-inline: 12px;
  }

  .template-preview__header .template-devices button {
    width: 42px;
  }

  .template-preview__actions {
    min-height: auto;
    flex-wrap: wrap;
  }

  .template-preview__actions .template-button {
    min-height: 34px;
    padding-inline: 10px;
    font-size: 13px;
  }

  .template-preview__use {
    margin-inline-start: 0;
  }
}

.template-devices[hidden] {
  display: none;
}

.template-fallback-title {
  color: var(--color-ink);
  font-size: 20px;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.template-popover__panel form button {
  display: block;
  width: 100%;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-align: start;
  cursor: pointer;
}

.template-popover__panel [data-template-delete] button {
  color: #b02a37;
}

.template-action-status {
  position: fixed;
  z-index: 30;
  inset-block-start: max(16px + env(safe-area-inset-top), min(150px, 18dvh));
  left: 50%;
  display: flex;
  width: max-content;
  min-width: min(208px, calc(100% - 32px));
  max-width: min(360px, calc(100% - 32px));
  min-height: 50px;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: 0;
  padding: 10px 18px;
  transform: translateX(-50%);
  border: 1px solid rgb(255 255 255 / 14%);
  border-radius: 12px;
  background: #202936;
  box-shadow: 0 8px 24px rgb(15 23 42 / 32%);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  line-height: 1.5;
  overflow-wrap: anywhere;
  opacity: 0;
  pointer-events: none;
}

.template-action-status[data-kind] {
  opacity: 1;
}

.template-action-status__icon {
  display: grid;
  width: 24px;
  height: 24px;
  flex: none;
  place-items: center;
  border-radius: 50%;
  font-weight: 700;
}

.template-action-status[data-kind='success'] .template-action-status__icon {
  background: #86efac;
  color: #14532d;
}

.template-action-status[data-kind='success'] .template-action-status__icon::before {
  content: '✓';
}

.template-action-status[data-kind='error'] .template-action-status__icon {
  background: #fecaca;
  color: #7f1d1d;
}

.template-action-status[data-kind='error'] .template-action-status__icon::before {
  content: '!';
}

@media (max-width: 380px) {
  .template-preview__header .template-devices {
    position: static;
    transform: none;
  }
}
