.template-picker {
  display: grid;
  gap: 14px;
}

.template-picker-select-wrap.is-hidden,
.template-picker-description.is-hidden {
  display: none;
}

.template-picker-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 14px;
  position: relative;
  overflow: visible;
}

.template-card {
  display: grid;
  gap: 0;
  border: 1px solid rgba(148, 163, 184, 0.28);
  border-radius: 22px;
  background: #fff;
  overflow: visible;
  box-shadow: 0 18px 40px rgba(15, 23, 42, 0.08);
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
  position: relative;
}

.template-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 24px 48px rgba(15, 23, 42, 0.12);
}

.template-card.is-selected {
  border-color: rgba(255, 20, 147, 0.55);
  box-shadow: 0 0 0 3px rgba(255, 20, 147, 0.12), 0 22px 44px rgba(15, 23, 42, 0.14);
}

.template-card-thumb,
.template-card-select {
  appearance: none;
  border: 0;
  margin: 0;
  text-align: left;
  width: 100%;
  background: transparent;
  cursor: pointer;
}

.template-card-thumb[disabled] {
  cursor: default;
  opacity: .72;
}

.template-card-thumb {
  position: relative;
  min-height: 164px;
  padding: 14px;
  color: #fff;
  overflow: hidden;
  border-radius: 22px 22px 0 0;
  background:
    radial-gradient(circle at 16% 18%, rgba(255,255,255,.14), transparent 22%),
    linear-gradient(135deg, #071327 0%, #0f2748 52%, #112f5e 100%);
}

.template-card-thumb-canvas {
  position: absolute;
  inset: 12px;
  border-radius: 18px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,.14);
  background: rgba(15,23,42,.18);
}

.template-card-thumb.has-live-preview .template-card-browser,
.template-card-thumb.has-live-preview .template-card-wireframe {
  opacity: 0;
}

.template-card-theme-ocean {
  background:
    radial-gradient(circle at 15% 20%, rgba(255,255,255,.12), transparent 22%),
    linear-gradient(135deg, #08142c 0%, #0d2e58 48%, #118ab2 100%);
}

.template-card-theme-sunset {
  background:
    radial-gradient(circle at 15% 20%, rgba(255,255,255,.14), transparent 22%),
    linear-gradient(135deg, #26131f 0%, #69314d 42%, #d97706 100%);
}

.template-card-theme-magenta {
  background:
    radial-gradient(circle at 15% 20%, rgba(255,255,255,.14), transparent 22%),
    linear-gradient(135deg, #071327 0%, #122a56 44%, #ff1493 100%);
}

.template-card-theme-ink {
  background:
    radial-gradient(circle at 15% 20%, rgba(255,255,255,.12), transparent 22%),
    linear-gradient(135deg, #091120 0%, #18263d 42%, #35495f 100%);
}

.template-card-theme-slate {
  background:
    radial-gradient(circle at 15% 20%, rgba(255,255,255,.12), transparent 22%),
    linear-gradient(135deg, #111827 0%, #1f2937 48%, #64748b 100%);
}

.template-card-theme-ruby {
  background:
    radial-gradient(circle at 15% 20%, rgba(255,255,255,.14), transparent 22%),
    linear-gradient(135deg, #1f1020 0%, #5b1634 48%, #dc2626 100%);
}

.template-card-browser {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  padding: 6px 8px;
  border-radius: 999px;
  background: rgba(255,255,255,.12);
}

.template-card-browser i {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: rgba(255,255,255,.72);
}

.template-card-wireframe {
  display: grid;
  gap: 10px;
  margin-top: 18px;
  transition: opacity .18s ease;
}

.template-card-wireframe-hero,
.template-card-wireframe-copy,
.template-card-wireframe-cta,
.template-card-wireframe-grid span {
  display: block;
  border-radius: 14px;
  background: rgba(255,255,255,.14);
}

.template-card-wireframe-hero {
  height: 54px;
  width: 74%;
}

.template-card-wireframe-copy {
  height: 12px;
  width: 88%;
}

.template-card-wireframe-copy.short {
  width: 62%;
}

.template-card-wireframe-cta {
  height: 18px;
  width: 42%;
  border-radius: 999px;
  background: rgba(255, 255, 255, .2);
}

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

.template-card-wireframe-grid span {
  height: 34px;
}

.template-card-preview-button {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 2;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border: 1px solid rgba(255,255,255,.35);
  border-radius: 999px;
  background: rgba(15,23,42,.74);
  color: #fff;
  box-shadow: 0 10px 24px rgba(15,23,42,.26);
  cursor: pointer;
}

.template-card-preview-button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.template-card-preview-button[hidden] {
  display: none !important;
}

.template-card-preview-button {
  position: absolute;
  right: 14px;
  top: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 999px;
  background: rgba(255,255,255,.14);
  color: #fff;
  cursor: pointer;
}

.template-card-preview-button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
}

.template-card-select {
  display: grid;
  gap: 10px;
  padding: 16px 16px 18px;
}

.template-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 18px;
}

.template-card-eyebrow {
  font-size: 11px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: #0f5f8d;
}

.template-card-badge {
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(255, 20, 147, .08);
  color: #be185d;
  font-size: 11px;
  font-weight: 700;
}

.template-card-select strong {
  font-size: 17px;
  line-height: 1.2;
  color: #0f172a;
}

.template-card-copy {
  color: #475569;
  font-size: 14px;
  line-height: 1.55;
}

.template-card-tags {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.template-card-tags span {
  padding: 5px 9px;
  border-radius: 999px;
  background: #f8fafc;
  color: #0f172a;
  border: 1px solid #e2e8f0;
  font-size: 12px;
  line-height: 1;
}

.template-picker-popover {
  position: absolute;
  z-index: 30;
  width: min(980px, calc(100vw - 36px));
  padding: 16px;
  border-radius: 24px;
  border: 1px solid rgba(148, 163, 184, 0.22);
  background: rgba(255,255,255,.98);
  box-shadow: 0 28px 72px rgba(15,23,42,.22);
  backdrop-filter: blur(16px);
}

.template-picker-popover[hidden] {
  display: none !important;
}

.template-picker-popover-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
}

.template-picker-popover-head strong {
  display: block;
  color: #0f172a;
  font-size: 15px;
}

.template-picker-popover-head span {
  display: block;
  color: #64748b;
  font-size: 13px;
  margin-top: 4px;
}

.template-picker-popover-close {
  border: 0;
  background: #f8fafc;
  color: #0f172a;
  border-radius: 999px;
  padding: 10px 14px;
  cursor: pointer;
}

.template-picker-popover-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.template-picker-popover-tab {
  border: 1px solid rgba(148, 163, 184, 0.26);
  background: #fff;
  color: #334155;
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.template-picker-popover-tab.is-active {
  border-color: rgba(255, 20, 147, 0.55);
  background: rgba(255, 20, 147, 0.08);
  color: #be185d;
}

.template-picker-popover-body {
  margin-top: 12px;
  min-height: 360px;
  height: 420px;
  overflow: auto;
  padding: 14px;
  border-radius: 20px;
  background: linear-gradient(180deg, rgba(255,255,255,.96), rgba(238,244,255,.96));
  border: 1px solid rgba(148, 163, 184, 0.18);
}

.template-preview-live-scale {
  position: relative;
  transform-origin: top left;
}

.template-preview-live-inner {
  transform-origin: top left;
  width: max-content;
}

.template-card-thumb-canvas .template-preview-stage-head,
.template-card-thumb-canvas .template-preview-lock,
.template-picker-popover-body .template-preview-stage-head,
.template-picker-popover-body .template-preview-lock {
  display: none;
}

.template-card-thumb-canvas .template-preview-page,
.template-picker-popover-body .template-preview-page {
  gap: 0;
}

.template-card-thumb-canvas .template-preview-stage,
.template-picker-popover-body .template-preview-stage {
  gap: 0;
}

.template-card-thumb-canvas .template-preview-stage-surface,
.template-picker-popover-body .template-preview-stage-surface {
  padding: 0;
  border: 0;
  background: transparent;
}

.template-preview-shell {
  width: min(1120px, 92vw);
  max-height: calc(100vh - 80px);
  display: grid;
  gap: 0;
}

.template-preview-shell .modal-card {
  width: 100%;
  max-width: none;
  max-height: calc(100vh - 80px);
  padding: 0;
  overflow: hidden;
}

.template-preview-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 22px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.24);
  background: #fff;
}

.template-preview-modal-head strong {
  display: block;
  color: #0f172a;
}

.template-preview-modal-head span {
  display: block;
  color: #64748b;
  font-size: 13px;
  margin-top: 4px;
}

.template-preview-modal-close {
  border: 0;
  background: #f8fafc;
  color: #0f172a;
  border-radius: 999px;
  padding: 10px 14px;
  cursor: pointer;
}

.template-preview-modal-body {
  background: #eef4ff;
  padding: 18px;
  overflow: auto;
  min-height: 340px;
}

.template-preview-loading {
  display: grid;
  place-items: center;
  min-height: 280px;
  color: #475569;
}

.template-preview-page {
  display: grid;
  gap: 18px;
}

.template-preview-stage {
  display: grid;
  gap: 12px;
}

.template-preview-stage-head strong {
  display: block;
  color: #0f172a;
}

.template-preview-stage-head span {
  display: block;
  color: #64748b;
  font-size: 13px;
  margin-top: 4px;
}

.template-preview-stage-surface {
  padding: 14px;
  border-radius: 24px;
  background: linear-gradient(180deg, rgba(255,255,255,.9), rgba(240,246,255,.96));
  border: 1px solid rgba(148, 163, 184, .22);
  overflow: auto;
}

.template-preview-stage-surface .template-preview-lock {
  font-size: 12px;
  color: #64748b;
  margin-bottom: 10px;
}

.template-preview-stage-surface [data-template-preview-render="1"] a,
.template-preview-stage-surface [data-template-preview-render="1"] button,
.template-preview-stage-surface [data-template-preview-render="1"] input,
.template-preview-stage-surface [data-template-preview-render="1"] textarea,
.template-preview-stage-surface [data-template-preview-render="1"] select {
  pointer-events: none;
}

@media (max-width: 720px) {
  .template-picker-grid {
    grid-template-columns: 1fr;
  }

  .template-picker-popover {
    position: fixed;
    inset: 16px;
    width: auto;
    max-width: none;
  }

  .template-picker-popover-body {
    height: calc(100vh - 220px);
  }

  .template-picker-popover-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .template-preview-modal-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .template-preview-shell {
    width: min(96vw, 96vw);
    max-height: calc(100vh - 32px);
  }
}
