.templatical-composer {
  min-height: calc(100vh - 32px);
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 14px;
}

.templatical-composer .builder-head {
  position: relative;
  z-index: 4;
}

.templatical-toolbar-note {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted, #68766d);
  font-size: 12px;
}

.templatical-toolbar-note::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: #1e684e;
  box-shadow: 0 0 0 3px rgba(30, 104, 78, .12);
}

.templatical-editor-shell {
  min-height: 0;
  height: auto;
  overflow: hidden;
  border: 1px solid rgba(23, 35, 28, .12);
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 18px 50px rgba(23, 35, 28, .08);
}

#templatical-editor {
  width: 100%;
  height: 100%;
  min-height: 0;
  --tpl-user-font-family: "DM Sans", system-ui, sans-serif;
}

.templatical-loading,
.templatical-error {
  height: 100%;
  min-height: 520px;
  display: grid;
  place-content: center;
  gap: 10px;
  padding: 32px;
  text-align: center;
  color: #68766d;
}

.templatical-error strong { color: #8f2f2f; }

.templatical-media-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
  max-height: 430px;
  overflow: auto;
}

.templatical-media-card {
  border: 1px solid rgba(23, 35, 28, .12);
  border-radius: 12px;
  padding: 8px;
  background: #fff;
  text-align: left;
  cursor: pointer;
}

.templatical-media-card img {
  width: 100%;
  aspect-ratio: 4 / 3;
  display: block;
  object-fit: cover;
  border-radius: 8px;
  margin-bottom: 8px;
}

.templatical-media-card strong,
.templatical-media-card small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.templatical-preflight-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 14px 0;
}

.templatical-preflight-stats > div {
  padding: 14px;
  border-radius: 12px;
  background: #f6f4ef;
}

.templatical-preflight-stats strong,
.templatical-preflight-stats span { display: block; }

@media (max-width: 900px) {
  .templatical-composer { min-height: calc(100vh - 24px); grid-template-rows: auto auto minmax(560px, 1fr); }
  .templatical-editor-shell { min-height: 560px; height: auto; border-radius: 10px; }
  .templatical-preflight-stats { grid-template-columns: 1fr; }
}


.arrange-sections-list {
  display: grid;
  gap: 10px;
  max-height: min(58vh, 620px);
  overflow: auto;
  padding: 4px;
}

.arrange-section-row {
  display: grid;
  grid-template-columns: auto 34px minmax(180px, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 13px;
  border: 1px solid rgba(23, 35, 28, .14);
  border-radius: 12px;
  background: #fff;
  transition: border-color .15s ease, background .15s ease, opacity .15s ease;
}

.arrange-section-row.dragging { opacity: .55; }
.arrange-section-row.drag-over { border-color: #1e684e; background: #f1f8f3; }
.arrange-drag-handle { color: #68766d; cursor: grab; font-size: 18px; letter-spacing: -5px; }
.arrange-section-number {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 999px;
  background: #edf4ef;
  color: #1e684e;
  font-weight: 800;
}
.arrange-section-copy { min-width: 0; }
.arrange-section-copy strong,
.arrange-section-copy small { display: block; }
.arrange-section-copy small {
  margin-top: 3px;
  overflow: hidden;
  color: #68766d;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.arrange-section-actions { display: flex; align-items: end; gap: 7px; }
.arrange-section-actions label { display: grid; gap: 3px; color: #68766d; font-size: 11px; }
.arrange-section-actions select {
  min-width: 72px;
  height: 34px;
  border: 1px solid rgba(23, 35, 28, .18);
  border-radius: 8px;
  background: #fff;
  padding: 0 8px;
}
.arrange-empty { display: grid; gap: 4px; padding: 30px; text-align: center; color: #68766d; }

@media (max-width: 760px) {
  .arrange-section-row { grid-template-columns: auto 30px minmax(0, 1fr); }
  .arrange-section-actions { grid-column: 2 / -1; flex-wrap: wrap; }
}


.dynamic-choice-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin: 18px 0;
}

.dynamic-choice-card {
  appearance: none;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  padding: 18px;
  text-align: left;
  cursor: pointer;
  display: grid;
  gap: 9px;
  font: inherit;
}

.dynamic-choice-card:hover,
.dynamic-choice-card:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 14%, transparent);
  outline: none;
}

.dynamic-choice-card > span {
  width: 30px;
  height: 30px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
}

.dynamic-choice-card strong {
  font-size: 15px;
}

.dynamic-choice-card small {
  color: var(--muted);
  line-height: 1.5;
}

.dynamic-section-guide {
  border-radius: 14px;
  background: var(--surface-soft);
  padding: 18px 20px;
}

.dynamic-section-guide ol {
  margin: 12px 0;
  padding-left: 22px;
}

.dynamic-section-guide li,
.dynamic-section-guide p {
  color: var(--muted);
  line-height: 1.55;
}

.variant-creative-note > span:last-child {
  display: flex;
  align-items: center;
  gap: 10px;
}

@media (max-width: 900px) {
  .dynamic-choice-grid {
    grid-template-columns: 1fr;
  }
}


/* Focused command bar: campaign context on the left, three clear actions on the right. */
.templatical-composer .builder-head {
  z-index: 60;
  min-height: 76px;
  padding: 13px 15px;
  flex-wrap: nowrap;
  gap: 20px;
}
.templatical-composer .builder-title { flex: 1 1 auto; max-width: none; gap: 12px; }
.templatical-composer .builder-campaign-copy {
  min-width: 0;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: baseline;
  column-gap: 12px;
}
.templatical-composer .builder-campaign-copy > small { grid-column: 1 / -1; }
.templatical-composer .builder-campaign-copy > strong { min-width: 0; max-width: min(420px, 38vw); }
.templatical-composer .builder-title-meta { min-width: 0; display: inline-flex; align-items: center; gap: 10px; }
.templatical-composer .builder-title-meta .text-link { flex: 0 0 auto; }
.templatical-composer .builder-save-status {
  min-width: 0;
  max-width: 190px;
  padding: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 10px;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.templatical-composer .builder-head-actions { flex: 0 0 auto; gap: 8px; }
.templatical-composer .builder-head-actions > .button,
.templatical-composer .builder-command-menu > summary { min-height: 44px; border-radius: 11px; }
.templatical-composer .builder-head-actions > .button { padding-inline: 16px; font-size: 12px; }
.templatical-composer .builder-review-button { min-width: 126px; }
.templatical-composer .builder-command-menu { position: relative; }
.templatical-composer .builder-command-menu > summary {
  min-width: 92px;
  padding: 0 13px;
  border: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: #fff;
  color: var(--green-dark);
  font-size: 12px;
  font-weight: 800;
  list-style: none;
  cursor: pointer;
  transition: border-color .16s ease, background .16s ease, box-shadow .16s ease;
}
.templatical-composer .builder-command-menu > summary::-webkit-details-marker { display: none; }
.templatical-composer .builder-command-menu > summary:hover { border-color: #9fb2a6; background: #f8faf8; }
.templatical-composer .builder-command-menu[open] > summary {
  border-color: var(--green);
  background: #f1f7f3;
  box-shadow: 0 0 0 3px rgba(30, 96, 73, .09);
}
.builder-command-trigger-icon {
  width: 21px;
  height: 21px;
  border-radius: 7px;
  display: grid;
  place-items: center;
  background: #e7f1eb;
  color: var(--green);
  font-size: 16px;
  font-weight: 600;
  line-height: 1;
}
.builder-command-chevron { color: var(--muted); font-size: 11px; transition: transform .16s ease; }
.builder-command-menu[open] .builder-command-chevron { transform: rotate(180deg); }
.templatical-composer .builder-head:has(.builder-command-menu[open]) .context-tooltip::before,
.templatical-composer .builder-head:has(.builder-command-menu[open]) .context-tooltip::after { display: none !important; }
.templatical-composer .builder-command-panel {
  z-index: 1000;
  top: calc(100% + 10px);
  right: 0;
  width: min(390px, calc(100vw - 40px));
  max-height: min(430px, calc(100dvh - 120px));
  padding: 10px;
  border: 1px solid rgba(23, 35, 28, .14);
  border-radius: 16px;
  gap: 8px;
  overflow-y: auto;
  background: #fffdfa;
  box-shadow: 0 24px 60px rgba(20, 34, 26, .22);
}
.builder-command-heading {
  min-height: 48px;
  padding: 5px 7px 8px;
  border-bottom: 1px solid var(--line-soft);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
}
.builder-command-heading > span { display: grid; gap: 2px; }
.builder-command-heading strong { color: var(--ink); font-size: 13px; }
.builder-command-heading small { color: var(--muted); font-size: 10px; }
.builder-command-heading kbd {
  margin-top: 2px;
  padding: 3px 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f5f4ee;
  color: var(--muted);
  font-family: inherit;
  font-size: 9px;
}
.builder-command-feature,
.builder-command-option {
  min-width: 0;
  border: 0;
  color: var(--ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background .15s ease;
}
.builder-command-feature:hover,
.builder-command-option:hover,
.builder-command-feature:focus-visible,
.builder-command-option:focus-visible { outline: none; background: #edf5f0; }
.builder-command-feature:focus-visible,
.builder-command-option:focus-visible { box-shadow: inset 0 0 0 2px rgba(30, 96, 73, .25); }
.builder-command-feature {
  width: 100%;
  min-height: 62px;
  padding: 10px 12px;
  border-radius: 12px;
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr);
  align-items: center;
  gap: 11px;
  background: #f4f0ff;
}
.builder-command-feature:hover,
.builder-command-feature:focus-visible { background: #ece6ff; }
.builder-command-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.builder-command-option {
  min-height: 66px;
  padding: 9px 10px;
  border-radius: 11px;
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr);
  align-items: center;
  gap: 9px;
  background: transparent;
}
.builder-command-icon {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  background: #eef2ed;
  color: var(--green-dark);
  font-size: 9px;
  font-weight: 900;
  letter-spacing: -.02em;
}
.builder-command-feature .builder-command-icon {
  width: 38px;
  height: 38px;
  border-radius: 11px;
  background: #e2d8ff;
  color: #5d43ad;
  font-size: 10px;
}
.builder-command-feature > span:last-child,
.builder-command-option > span:last-child { min-width: 0; display: grid; gap: 2px; }
.builder-command-feature strong,
.builder-command-option strong {
  overflow: hidden;
  font-size: 11px;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.builder-command-feature small,
.builder-command-option small {
  overflow: hidden;
  color: var(--muted);
  font-size: 9px;
  line-height: 1.3;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.templatical-composer .builder-toolbar,
.templatical-composer .templatical-editor-shell { position: relative; z-index: 1; }
@media (max-width: 1100px) {
  .templatical-composer .builder-head { flex-wrap: wrap; }
  .templatical-composer .builder-title { flex-basis: 100%; }
  .templatical-composer .builder-campaign-copy > strong { max-width: min(560px, 58vw); }
  .templatical-composer .builder-head-actions { width: 100%; justify-content: flex-end; }
}
@media (max-width: 620px) {
  .templatical-composer .builder-head-actions { display: grid; grid-template-columns: auto 1fr 1.2fr; }
  .templatical-composer .builder-head-actions > .button { min-width: 0; padding-inline: 10px; white-space: normal; }
  .templatical-composer .builder-command-panel {
    position: fixed;
    inset: auto 10px 10px;
    width: auto;
    max-height: min(70dvh, 520px);
  }
  .builder-command-grid { grid-template-columns: 1fr; }
}

/* Check & test needs room for readable checks, links, and test-send controls. */
.modal.wide.preflight-modal {
  width: min(1120px, calc(100vw - 40px));
  max-width: 1120px;
  max-height: calc(100dvh - 32px);
  padding: 34px 38px;
}

.preflight-modal .modal-head {
  margin-bottom: 28px;
}

.preflight-modal .templatical-preflight-stats {
  gap: 16px;
  margin: 20px 0 28px;
}

.preflight-modal .templatical-preflight-stats > div {
  min-height: 104px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.preflight-modal section + section {
  margin-top: 26px;
}

.preflight-modal .link-inventory {
  max-height: 360px;
}

.preflight-modal .preflight-section-note {
  max-width: 760px;
  margin: -4px 0 14px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.preflight-modal .link-inventory-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(230px, .44fr);
  align-items: center;
  gap: 18px;
  padding: 14px 16px;
}

.preflight-modal .link-inventory-row > span:first-child {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(150px, .38fr) minmax(0, 1fr);
  align-items: center;
  gap: 14px;
}

.link-reporting-field {
  min-width: 0;
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.link-reporting-field input {
  width: 100%;
  min-width: 0;
  height: 38px;
  border: 1px solid rgba(23, 35, 28, .18);
  border-radius: 9px;
  background: var(--surface, #fff);
  color: var(--ink, #17231c);
  padding: 0 11px;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
}

.link-reporting-field input:focus {
  outline: 3px solid rgba(30, 104, 78, .14);
  border-color: #1e684e;
}

.link-reporting-system {
  color: var(--muted);
  font-size: 11px;
  text-align: right;
}

.preflight-modal .link-inventory-row strong {
  min-width: 0;
  font-size: 13px;
  line-height: 1.35;
}

.preflight-modal .link-inventory-row code {
  min-width: 0;
  overflow: hidden;
  font-size: 11px;
  line-height: 1.4;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.preflight-modal .test-send-panel {
  margin-top: 30px;
  padding: 24px;
  grid-template-columns: minmax(220px, .6fr) minmax(0, 1.4fr);
  gap: 28px;
}

.preflight-modal .test-send-panel h3 {
  font-size: 19px;
}

.preflight-modal .test-send-panel p {
  font-size: 12px;
}

.preflight-modal .test-send-fields {
  grid-template-columns: minmax(190px, 1.2fr) minmax(170px, 1fr) auto;
  gap: 10px;
}

@media (max-width: 1100px) {
  .templatical-composer .builder-head {
    flex-wrap: wrap;
  }

  .templatical-composer .builder-title {
    flex-basis: 100%;
    max-width: none;
  }

  .templatical-composer .builder-head-actions {
    width: 100%;
    justify-content: flex-end;
  }
}

@media (max-width: 760px) {
  .modal.wide.preflight-modal {
    width: calc(100vw - 20px);
    max-height: calc(100dvh - 20px);
    padding: 24px 20px;
  }

  .preflight-modal .link-inventory-row,
  .preflight-modal .link-inventory-row > span:first-child,
  .preflight-modal .test-send-panel,
  .preflight-modal .test-send-fields {
    grid-template-columns: 1fr;
  }

  .link-reporting-system { text-align: left; }

  .preflight-modal .link-inventory-row code {
    white-space: normal;
    overflow-wrap: anywhere;
  }
}


/* In-editor templates and focused AI editing. */
.templatical-composer .builder-templates-button {
  min-width: 94px;
  border-color: #b9c8bf;
  background: #f8faf8;
  color: var(--green-dark);
  font-weight: 800;
}
.templatical-composer .builder-templates-button:hover,
.templatical-composer .builder-templates-button:focus-visible {
  border-color: var(--green);
  background: #eef5f0;
}

.modal.wide.builder-templates-modal,
.modal.wide.ai-part-modal {
  width: min(1040px, calc(100vw - 40px));
  max-width: 1040px;
  max-height: calc(100dvh - 32px);
}

.builder-template-grid {
  margin: 22px 0;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  overflow-y: auto;
  max-height: min(560px, calc(100dvh - 260px));
  padding: 3px;
}

.builder-template-card {
  min-height: 158px;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: 15px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  background: var(--surface);
  color: var(--text);
  text-align: left;
  font: inherit;
  cursor: pointer;
  transition: border-color .16s ease, transform .16s ease, box-shadow .16s ease;
}
.builder-template-card:hover,
.builder-template-card:focus-visible {
  border-color: var(--accent);
  outline: none;
  transform: translateY(-1px);
  box-shadow: 0 10px 28px rgba(23, 35, 28, .1);
}
.builder-template-card strong { font-size: 17px; line-height: 1.25; }
.builder-template-card small { flex: 1; color: var(--muted); line-height: 1.45; }
.builder-template-card > span:last-child { color: var(--accent); font-size: 12px; font-weight: 800; }
.builder-template-category {
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .06em;
  text-transform: uppercase;
}

.template-restore,
.ai-part-promise {
  margin: 18px 0;
  padding: 15px 17px;
  border-radius: 13px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  background: var(--surface-soft);
}
.template-restore > span,
.ai-part-promise { line-height: 1.45; }
.template-restore > span { display: grid; gap: 3px; }
.template-restore small,
.ai-part-promise span { color: var(--muted); font-size: 12px; }
.ai-part-modal .field { margin-top: 18px; }
.ai-part-modal textarea { min-height: 150px; }
.ai-part-promise { align-items: flex-start; justify-content: flex-start; flex-direction: column; gap: 4px; }

@media (max-width: 820px) {
  .builder-template-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 620px) {
  .templatical-composer .builder-head-actions {
    grid-template-columns: auto auto 1fr 1.2fr;
  }
  .templatical-composer .builder-templates-button { min-width: 0; }
  .builder-template-grid { grid-template-columns: 1fr; }
  .template-restore { align-items: stretch; flex-direction: column; }
  .modal.wide.builder-templates-modal,
  .modal.wide.ai-part-modal {
    width: calc(100vw - 20px);
    max-height: calc(100dvh - 20px);
    padding: 24px 20px;
  }
}
