.templates-layout {
  padding: 0;
  display: grid;
  grid-template-columns: 360px 1fr;
  min-height: calc(100vh - 96px);
  height: calc(100vh - 96px);
  background: #f8fbff;
}

.templates-list,
.templates-detail {
  min-height: 0;
}

.templates-list {
  border-right: 1px solid #dbe4f0;
  display: grid;
  grid-template-rows: auto auto auto 1fr;
  background: #fff;
}

.templates-detail {
  display: grid;
  grid-template-rows: auto 1fr;
  background: linear-gradient(180deg, #f8fbff 0%, #fdfefe 100%);
}

.templates-head {
  padding: 14px 16px;
  border-bottom: 1px solid #dbe4f0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.templates-head-copy {
  display: grid;
  gap: 4px;
}

.templates-head-copy strong {
  color: #153d77;
  font-size: 17px;
}

.templates-head-copy small {
  color: #627896;
  line-height: 1.45;
}

.templates-head-actions {
    display: flex;
    align-items: center;
    gap: 6px; 
    flex-wrap: wrap;
}

.templates-mini-select {
    height: 28px;
    padding: 2px 8px;
    font-size: 12px;
    border-radius: 6px;
}

.templates-head-actions .btn {
    height: 28px;
    padding: 0 10px;
    font-size: 12px;
    border-radius: 6px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.templates-searchbar {
  padding: 10px 16px;
  border-bottom: 1px solid #e6eef8;
  background: #f8fbff;
}

.templates-searchbar input {
  width: 100%;
  border: 1px solid #d8e4f2;
  border-radius: 12px;
  padding: 10px 13px;
  font-size: 14px;
  min-height: 42px;
  background: #fff;
}

.templates-groups {
  padding: 10px 16px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  border-bottom: 1px solid #eef3fa;
  background: #fff;
}

.template-group-pill,
.template-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  border: 1px solid #d9e4f2;
  background: #f5f9ff;
  color: #224c86;
  font-size: 12px;
  font-weight: 700;
  padding: 5px 10px;
}

.template-chip--crm {
  background: #eef6ff;
  color: #1052a8;
}

.template-chip--meta {
  background: #eefaf3;
  color: #177245;
}

.template-chip--active {
  background: #effaf3;
  color: #1b7d47;
}

.template-chip--inactive {
  background: #fff4f4;
  color: #a23d3d;
}

.template-chip--soft {
  background: #f7f9fc;
  color: #59708f;
}

.template-chip--meta-review-ok {
  background: #eef8f1;
  border-color: #bfe4cc;
  color: #1f7b49;
}

.template-chip--meta-review-warn {
  background: #fff8ec;
  border-color: #f2d7a6;
  color: #9a6a1d;
}

.template-chip--meta-review-bad {
  background: #fff1f1;
  border-color: #efc5c5;
  color: #a23d3d;
}

.template-chip--meta-review-draft {
  background: #f3f6fb;
  border-color: #d9e4f2;
  color: #5b7190;
}

.templates-items {
  overflow: auto;
  min-height: 0;
  padding: 14px 12px 18px;
}

.template-list-skeleton {
  display: grid;
  gap: 10px;
}

.template-list-skeleton__item {
  height: 110px;
  border-radius: 14px;
  border: 1px solid #e6edf7;
  background: linear-gradient(90deg, #f1f5fb 0%, #e8f0fb 45%, #f1f5fb 100%);
  background-size: 200% 100%;
  animation: templateSkeletonPulse 1.15s linear infinite;
}

.template-section {
  display: grid;
  gap: 8px;
}

.template-section + .template-section {
  margin-top: 14px;
}

.template-section-head {
  padding: 0 4px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.template-section-head strong {
  color: #153d77;
  font-size: 13px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.template-section-head small {
  color: #6a819f;
}

.template-section-items {
  display: grid;
  gap: 8px;
}

.template-item {
  width: 100%;
  border: 1px solid #e6edf7;
  border-radius: 16px;
  background: #fff;
  text-align: left;
  padding: 12px;
  cursor: pointer;
  display: grid;
  gap: 10px;
  box-shadow: 0 8px 22px rgba(17, 63, 135, 0.04);
}

.template-item:hover {
  border-color: #bfd3f1;
  box-shadow: 0 12px 30px rgba(17, 63, 135, 0.08);
  transform: translateY(-1px);
}

.template-item.is-active {
  border-color: #3b82f6;
  background: #f7fbff;
  box-shadow: 0 14px 30px rgba(37, 99, 235, 0.1);
}

.template-item-head,
.template-item-meta,
.template-viewer-head,
.template-panel-head,
.template-preview-head,
.template-suggestion-item,
.template-viewer-actions,
.template-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.template-item-head-copy {
  min-width: 0;
  display: grid;
  gap: 3px;
}

.template-item-head-copy strong {
  color: #113f87;
  font-size: 15px;
}

.template-item-head-copy small,
.template-item-meta small,
.template-side-tip,
.template-editor-tip span {
  color: #607692;
}

.template-item-badges,
.template-viewer-badges {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.template-item-preview {
  display: flex;
}

.template-item-bubble {
  max-width: min(420px, 100%);
  border-radius: 18px 18px 6px 18px;
  background: linear-gradient(180deg, #dff8ea 0%, #d4f4e2 100%);
  color: #163d2d;
  padding: 12px 14px;
  line-height: 1.5;
  box-shadow: 0 10px 20px rgba(20, 93, 62, 0.08);
}

.template-item-meta {
  flex-wrap: wrap;
}

.template-item-meta small {
  display: inline-flex;
  align-items: center;
}

.template-empty,
.template-viewer {
  padding: 16px;
  overflow: auto;
}

.template-viewer.is-loading {
  opacity: 0.75;
  pointer-events: none;
}

@keyframes templateSkeletonPulse {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.template-empty-state {
  min-height: 100%;
  border: 1px dashed #cfddf1;
  border-radius: 18px;
  background: linear-gradient(180deg, #fbfdff 0%, #f5f9ff 100%);
  display: grid;
  align-content: center;
  justify-items: start;
  gap: 8px;
  padding: 28px;
}

.template-empty-state strong,
.template-viewer-head-copy strong {
  color: #153d77;
}

.template-empty-state p {
  color: #637999;
  max-width: 520px;
}

.template-viewer-card {
  padding: 18px;
  display: grid;
  gap: 18px;
  box-shadow: 0 16px 40px rgba(17, 63, 135, 0.07);
}

.template-viewer-head {
  align-items: flex-start;
}

.template-viewer-head-copy {
  display: grid;
  gap: 8px;
}

.template-viewer-head-copy strong {
  font-size: 22px;
}

.template-viewer-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.template-viewer-grid > div,
.template-viewer-grid > div {
  border: 1px solid #dce6f2;
  border-radius: 14px;
  overflow: hidden;
  background: #fff;
}
.template-viewer-grid > div {
  padding: 14px;
  display: grid;
  gap: 4px;
}

.template-viewer-grid strong {
  color: #183c6d;
}

.template-viewer-panels {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(280px, 0.85fr);
  gap: 16px;
}

.template-viewer-body-wrap {
  display: grid;
  gap: 10px;
}

.template-viewer-side {
  display: grid;
  gap: 12px;
}

.template-side-card,
.template-preview,
.template-vars-panel {
  padding: 14px;
  display: grid;
  gap: 12px;
}

.template-chat-preview {
  overflow: hidden;
  background: #f7fafc;
}

.template-chat-preview {
  border: 1px solid #dce6f2;
  border-radius: 12px;
  overflow: hidden;
  background: #efe7dc;
  max-width: 330px;
  margin: 0 auto;
}

.template-chat-preview__bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  background: linear-gradient(135deg, #008f7a, #00a884);
  color: #fff;
  border-bottom: none;
}

.template-chat-preview__bar span {
  font-weight: 700;
  font-size: 14px;
}

.template-chat-preview__bar small {
  display: block;
  font-size: 11px;
  opacity: 0.85;
  font-weight: 500;
}

#metaWizardPreviewBody,
#viewTemplateBody,
#templatePreviewBody {
  padding: 16px;
  min-height: 380px;
  background:
    radial-gradient(circle at 10px 10px, rgba(0,0,0,.03) 1px, transparent 1px),
    #efe7dc;
  background-size: 18px 18px;
}

.template-form {
  padding: 16px;
  overflow: auto;
  display: grid;
  gap: 2px;
  align-content: start;
}

.template-editor-modal {
  width: min(1120px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
  display: grid;
  grid-template-rows: auto 1fr;
}

.template-form-header,
.template-meta-fields,
.template-preview-vars {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.template-meta-fields {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.meta-wizard {
  display: grid;
  gap: 14px;
}

.meta-wizard-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.meta-wizard-steps {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.meta-step {
  border: 1px solid #d5e4f7;
  background: #f5f9ff;
  color: #355c91;
  border-radius: 999px;
  min-height: 38px;
  padding: 7px 12px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.meta-step span {
  width: 22px;
  height: 22px;
  border-radius: 999px;
  border: 1px solid #9db9e5;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
}

.meta-step.is-active {
  border-color: #2e67d1;
  background: #eaf1ff;
  color: #1a4da9;
}

.meta-step.is-active span {
  border-color: #2e67d1;
  color: #1a4da9;
  background: #fff;
}

.meta-step.is-done {
  border-color: #9dd8b2;
  background: #edf9f1;
  color: #1f7a49;
}

.meta-step.is-done span {
  border-color: #72c694;
  color: #1f7a49;
  background: #fff;
}

.meta-wizard-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(290px, 0.85fr);
  gap: 14px;
}

.meta-wizard-main {
  border: 1px solid #e1eaf6;
  border-radius: 16px;
  background: #fff;
  padding: 14px;
  display: grid;
  gap: 14px;
}

.meta-pane {
  display: none;
  gap: 12px;
}

.meta-pane.is-active {
  display: grid;
}

.meta-pane h3 {
  color: #173f78;
  margin: 0;
}

.meta-form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.meta-category-picker {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.meta-category {
  border: 1px solid #d5e4f7;
  border-radius: 12px;
  background: #fff;
  min-height: 42px;
  color: #2d5288;
  font-weight: 700;
}

.meta-category.is-active {
  border-color: #2e67d1;
  background: #2e67d1;
  color: #fff;
  box-shadow: 0 8px 20px rgba(31, 84, 176, 0.18);
}

.meta-category-hint {
  margin: 0;
  color: #607692;
  border: 1px solid #e1eaf6;
  border-radius: 10px;
  background: #f8fbff;
  padding: 9px 11px;
}

.meta-review-list {
  border: 1px solid #e1eaf6;
  border-radius: 14px;
  background: #fbfdff;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  padding: 12px;
}

.meta-review-list > div {
  display: grid;
  gap: 3px;
}

.meta-review-list span {
  color: #6b819e;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.meta-review-list strong {
  color: #173f78;
}

.template-meta-note {
  margin: 0;
}

.meta-wizard-actions {
  border-top: 1px solid #ecf2fa;
  padding-top: 12px;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.meta-wizard-preview {
  padding: 14px;
  display: grid;
  gap: 12px;
  align-content: start;
  box-shadow: 0 10px 24px rgba(17, 63, 135, 0.05);
}

.meta-preview-meta {
  display: grid;
  gap: 7px;
  color: #274975;
}

.meta-preview-meta strong {
  color: #163f76;
}

.template-form-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) 320px;
  gap: 16px;
}

.template-form-main,
.template-form-side {
  display: grid;
  gap: 14px;
  min-width: 0;
}

.template-form textarea {
  width: 100%;
  border: 1px solid #dbe4f0;
  border-radius: 12px;
  padding: 12px 13px;
  font-size: 14px;
  resize: vertical;
  min-height: 150px;
}

.template-var-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.template-check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.template-check input {
  width: auto;
  margin: 0;
}

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

.template-variable-card {
  border: 1px solid #e5edf7;
  border-radius: 14px;
  background: #f9fbff;
  padding: 12px;
  display: grid;
  gap: 5px;
}

.template-variable-card.is-used {
  border-color: #b9d2f8;
  background: #eef6ff;
}

.template-variable-card code {
  color: #1b4e97;
  font-weight: 700;
}

.template-variable-card small {
  color: #637997;
  line-height: 1.4;
}

.template-editor-tip-list {
  display: grid;
  gap: 10px;
}

.template-editor-tip {
  display: grid;
  grid-template-columns: 18px 1fr;
  align-items: start;
  gap: 10px;
  color: #264d82;
}

.template-editor-tip .ui-icon {
  margin-top: 1px;
}

.template-actions {
  padding-top: 4px;
}

.template-actions-main {
  margin-right: auto;
}

.template-suggestions {
  display: grid;
  gap: 8px;
}

.template-suggestion-item {
  width: 100%;
  border: 1px solid #e5edf7;
  border-radius: 14px;
  background: #fff;
  padding: 12px;
  text-align: left;
  cursor: pointer;
}

.template-suggestion-item:hover {
  border-color: #bfd3f1;
  background: #f8fbff;
}

.template-suggestion-item strong {
  color: #153d77;
  display: block;
  margin-bottom: 3px;
}

.template-suggestion-item small {
  color: #617998;
}

.template-delete-modal {
  width: min(520px, calc(100vw - 24px));
}

.template-delete-copy {
  color: #516983;
  line-height: 1.6;
  margin: 0 0 14px;
}

.template-delete-options {
  display: grid;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid #e5edf7;
  border-radius: 12px;
  background: #f9fcff;
  margin-bottom: 12px;
}

.template-delete-choice {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: #294a77;
  font-weight: 600;
}

.template-delete-choice input {
  width: auto;
  margin: 0;
}

.btn-icon-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.btn-danger-soft {
  border-color: #efc5c5;
  color: #a03f3f;
  background: #fff8f8;
}

.btn-danger {
  background: linear-gradient(180deg, #e24c4c 0%, #c53b3b 100%);
  border-color: #b43333;
}

.ui-icon {
  width: 16px;
  height: 16px;
  display: inline-flex;
  flex: 0 0 16px;
  align-items: center;
  justify-content: center;
}

.ui-icon svg {
  width: 16px;
  height: 16px;
}

.help-list {
  margin: 0;
  padding-left: 18px;
  color: #2b4266;
  display: grid;
  gap: 6px;
}

@media (max-width: 1180px) {
  .templates-layout {
    grid-template-columns: 340px 1fr;
  }

  .template-form-layout {
    grid-template-columns: 1fr;
  }

  .template-viewer-panels {
    grid-template-columns: 1fr;
  }

  .meta-wizard-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 980px) {
  .templates-layout {
    grid-template-columns: 1fr;
    min-height: auto;
    height: auto;
  }

  .templates-list {
    border-right: 0;
    border-bottom: 1px solid #dbe4f0;
  }

  .template-viewer-grid,
  .template-form-header,
  .template-preview-vars,
  .template-meta-fields,
  .template-variable-grid,
  .meta-form-grid,
  .meta-category-picker,
  .meta-review-list {
    grid-template-columns: 1fr;
  }
}
/* Rediseño 2026-04-29: Templates board style */
.templates-layout {
  background: #f4f7fc;
  grid-template-columns: minmax(360px, 43%) minmax(480px, 57%);
  gap: 0;
  border-radius: 18px;
  overflow: hidden;
}

.templates-list {
  background: #ffffff;
  border-right: 1px solid #e1e9f5;
}

.templates-detail {
  background: #f8fbff;
}

.templates-head {
  padding: 14px 18px;
  border-bottom: 1px solid #e3ebf7;
  align-items: center;
}

.templates-head-copy strong {
  font-size: 18px;
  letter-spacing: -0.02em;
  color: #0f2f63;
}

.templates-head-copy small {
  font-size: 13px;
  color: #6981a3;
}

.templates-head-actions .btn {
  min-height: 42px;
  border-radius: 12px;
}

.templates-head-actions .btn-primary {
  padding-inline: 18px;
  font-weight: 800;
}

.templates-searchbar {
  background: #fff;
  padding: 14px 18px 10px;
  border-bottom: 0;
}

.templates-searchbar input {
  min-height: 48px;
  border-radius: 14px;
  border: 1px solid #d6e1f0;
  background: #fbfdff;
  color: #163f74;
}

.templates-searchbar input:focus {
  outline: none;
  border-color: #7ea6e8;
  box-shadow: 0 0 0 3px rgba(32, 98, 211, 0.14);
}

.templates-groups {
  padding: 0 18px 12px;
  border-bottom: 1px solid #ebf1fa;
}

.template-group-pill {
  background: #f4f8ff;
  border-color: #d5e2f5;
  color: #264c81;
  font-weight: 700;
}

.template-group-pill.is-active,
.template-group-pill[aria-pressed='true'] {
  background: linear-gradient(180deg, #2f72de 0%, #1f61ce 100%);
  border-color: #1f61ce;
  color: #fff;
}

.templates-items {
  padding: 12px 14px 18px;
  background: linear-gradient(180deg, #fbfdff 0%, #f8fbff 100%);
}

.template-item {
  border-radius: 14px;
  border: 1px solid #dbe6f5;
  box-shadow: none;
  padding: 14px;
  background: #fff;
}

.template-item:hover {
  border-color: #9ec0ee;
  box-shadow: 0 10px 24px rgba(18, 66, 139, 0.08);
}

.template-item.is-active {
  border-color: #2f74df;
  box-shadow: 0 0 0 2px rgba(47, 116, 223, 0.2);
  background: #f7fbff;
}

.template-item-head-copy strong {
  color: #123b76;
  font-size: 17px;
  line-height: 1.15;
}

.template-item-head-copy small {
  color: #617b9d;
  font-size: 14px;
  line-height: 1.35;
}

.template-chip,
.template-group-pill {
  border-radius: 999px;
}

.template-viewer {
  padding: 14px;
}

.template-viewer-card {
  border: 1px solid #dfe9f6;
  border-radius: 16px;
  box-shadow: none;
  padding: 0;
  overflow: hidden;
  background: #fff;
}

.template-viewer-head {
  padding: 16px;
  border-bottom: 1px solid #e6eef9;
  background: #fff;
}

.template-viewer-head-copy strong {
  font-size: 30px;
  color: #0f3368;
}

.template-viewer-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr)); /* más compactas */
    gap: 8px; /* menos separación */
    padding: 0 12px 10px;
}

.template-viewer-grid > div {
    padding: 6px 8px; /* antes seguro era más grande */
    font-size: 12px; /* reduce todo */
    line-height: 1.2;
}

.template-viewer-grid .muted {
    font-size: 10px;
    display: block;
    margin-bottom: 2px;
}

.template-viewer-grid strong {
    font-size: 12px;
    font-weight: 600;
}

.template-viewer-panels {
  padding: 0 16px 16px;
  grid-template-columns: 1fr;
}

.template-viewer-body-wrap {
  border: 1px solid #e1e9f6;
  border-radius: 14px;
  overflow: hidden;
}

.template-panel-head {
  padding: 10px 12px;
  border-bottom: 1px solid #e8eef7;
  background: #fbfdff;
}

.template-panel-head strong {
  color: #19509a;
}

.template-chat-preview {
  border: 0;
  border-radius: 0;
}

.template-preview-body--chat {
  position: relative;
  max-width: 85%;
  margin-left: auto;
  background: #d9fdd3;
  color: #202c33;
  padding: 12px 12px 24px;
  border-radius: 10px 0 10px 10px;
  font-size: 14px;
  line-height: 1.45;
  box-shadow: 0 1px 1px rgba(0,0,0,.08);
  border: none;
}

.template-preview-body--chat::after {
  content: "";
  position: absolute;
  top: 0;
  right: -8px;
  border-top: 10px solid #d9fdd3;
  border-right: 10px solid transparent;
}
.template-empty-state {
  background: #fff;
  border: 1px dashed #cddcf1;
}

@media (max-width: 1200px) {
  .templates-layout {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 0;
  }

  .templates-list {
    border-right: 0;
    border-bottom: 1px solid #e1e9f5;
  }

  .template-viewer-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .templates-head {
    flex-direction: column;
    align-items: flex-start;
  }

  .templates-head-copy strong {
    font-size: 22px;
  }

  .template-item-head-copy strong {
    font-size: 15px;
  }

  .template-viewer-head-copy strong {
    font-size: 22px;
  }

  .template-viewer-grid {
    grid-template-columns: 1fr;
  }
}
/* Modal redesign for create/edit template */
#templateEditorModal .template-editor-modal {
  width: min(1320px, calc(100vw - 28px));
  max-height: calc(100vh - 26px);
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 26px 54px rgba(15, 41, 78, 0.2);
}

#templateEditorModal .modal-head {
  padding: 10px 14px;
  border-bottom: 1px solid #dfe8f5;
  background: #fff;
}

#templateEditorModal .modal-head strong {
  font-size: 20px;
  color: #0f2f62;
  font-weight: 800;
}

#templateEditorModal .template-form {
  padding: 0;
  overflow: hidden;
  grid-template-rows: 1fr auto;
}

#templateEditorModal .template-form-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 290px;
  gap: 8px;
  padding: 9px 10px 8px;
  overflow: auto;
  background: #fff;
}

#templateEditorModal .template-form-main {
  display: grid;
  gap: 14px;
}

#templateEditorModal .template-form-side {
  align-content: start;
}

#templateEditorModal .template-vars-panel {
  border: 1px solid #dbe6f5;
  border-radius: 12px;
  background: #fff;
  padding: 10px;
}

#templateEditorModal .template-variable-card {
  border-radius: 12px;
  border: 1px solid #dfe8f6;
  background: #fbfdff;
}

#templateEditorModal .meta-wizard {
  border: 1px solid #dbe6f5;
  border-radius: 12px;
  padding: 10px;
  background: #fff;
}

#templateEditorModal .meta-wizard-head {
  border-bottom: 1px solid #e6eef9;
  padding-bottom: 10px;
}

#templateEditorModal .meta-step {
  min-height: 34px;
  background: #fff;
  border-color: #ccdcf5;
  min-width: 130px;
  justify-content: flex-start;
}

#templateEditorModal .meta-step.is-active {
  background: #eef4ff;
  border-color: #1f67d8;
  color: #1f67d8;
}

#templateEditorModal .meta-wizard-layout {
  grid-template-columns: minmax(0, 1fr) 290px;
  gap: 10px;
}

#templateEditorModal .meta-wizard-main {
  display: grid;
  gap: 10px;
}

#templateEditorModal .meta-pane h3 {
  color: #143b74;
}

#templateEditorModal .meta-pane .field > span,
#templateEditorModal .field > span {
  color: #183d72;
  font-weight: 700;
}

#templateEditorModal .field input,
#templateEditorModal .field select,
#templateEditorModal .field textarea {
  border: 1px solid #d4e0f1;
  border-radius: 10px;
  min-height: 36px;
  padding: 7px 9px;
  font-size: 13px;
  color: #153967;
  background: #fff;
}

#templateEditorModal .field textarea {
  min-height: 120px;
}

#templateEditorModal .meta-wizard-preview {
  border-radius: 12px;
  border: 1px solid #dbe6f5;
  padding: 8px;
}

#templateEditorModal .template-chat-preview {
  border-radius: 10px;
  border: 1px solid #e2eaf6;
}

#templateEditorModal .template-preview-body {
  min-height: 210px;
}

#templateEditorModal .template-chat-preview {
  border-radius: 12px;
  border: 1px solid #dce6f2;
}

#templateEditorModal .template-preview-body {
  min-height: 380px;
}

#templateEditorModal .template-actions .btn {
  min-height: 34px;
  border-radius: 10px;
  font-size: 13px;
}

#templateEditorModal .template-actions .btn-primary {
  font-weight: 800;
  padding-inline: 14px;
}

#templateEditorModal .template-var-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 2px 0 2px;
}

#templateEditorModal .template-var-toolbar .btn-mini {
  min-height: 30px;
  border-radius: 10px;
  padding: 5px 8px;
  font-weight: 700;
}

#templateEditorModal .template-variable-card {
  min-height: 46px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 9px;
}

#templateEditorModal .template-variable-card code {
  font-size: 13px;
  font-weight: 800;
  color: #1f67d8;
}

#templateEditorModal .template-editor-tip-list {
  margin-top: 8px;
  border-top: 1px solid #e7eef9;
  padding-top: 10px;
}

@media (max-width: 1320px) {
  #templateEditorModal .template-form-layout {
    grid-template-columns: 1fr;
  }

  #templateEditorModal .meta-wizard-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 820px) {
  #templateEditorModal .modal-head strong {
    font-size: 24px;
  }

  #templateEditorModal .template-form-header,
  #templateEditorModal .template-preview-vars,
  #templateEditorModal .meta-form-grid {
    grid-template-columns: 1fr;
  }
}
#templateEditorModal .template-editor-intro {
  padding: 2px 10px 2px;
  border-bottom: 1px solid #e6edf8;
  background: #fff;
  display: grid;
  gap: 0px;
}

#templateEditorModal .template-editor-steps-static {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

#templateEditorModal .template-editor-step {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: #355a8b;
  font-weight: 700;
}

#templateEditorModal .template-editor-step b {
  width: 24px;
  height: 24px;
  border-radius: 999px;
  border: 1px solid #b9cde9;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  background: #fff;
}

#templateEditorModal .template-editor-step.is-active {
  color: #1f67d8;
}

#templateEditorModal .template-editor-step.is-active b {
  background: #1f67d8;
  border-color: #1f67d8;
  color: #fff;
}

#templateEditorModal .template-crm-stage {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 250px;
  gap: 8px;
  align-items: start;
}

#templateEditorModal .template-crm-editor {
  display: grid;
  gap: 12px;
}

#templateEditorModal .template-crm-stage .template-preview {
  position: sticky;
  top: 8px;
}

@media (max-width: 1320px) {
  #templateEditorModal .template-crm-stage {
    grid-template-columns: 1fr;
  }

  #templateEditorModal .template-crm-stage .template-preview {
    position: static;
  }
}

.wa-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  background: #fff;
  padding: 3px;
  box-shadow: 0 2px 6px rgba(0,0,0,.15);
}

.template-preview-body--chat {
  background:
    radial-gradient(circle at 10px 10px, rgba(0,0,0,.035) 1px, transparent 1px),
    #efe7dc;
  background-size: 18px 18px;
  padding: 16px;
  min-height: 380px;
  display: block;
}

.wa-message-bubble {
  position: relative;
  max-width: 85%;
  margin-left: auto;
  background: #d9fdd3;
  color: #202c33;
  padding: 12px 12px 26px;
  border-radius: 10px 0 10px 10px;
  font-size: 14px;
  line-height: 1.45;
  box-shadow: 0 1px 1px rgba(0,0,0,.08);
}

.wa-message-bubble::after {
  content: "";
  position: absolute;
  top: 0;
  right: -8px;
  border-top: 10px solid #d9fdd3;
  border-right: 10px solid transparent;
}

.wa-time {
  position: absolute;
  right: 10px;
  bottom: 6px;
  font-size: 11px;
  color: #667781;
}

.wa-time span {
  color: #34b7f1;
}

/* Compact mode for CRM/Meta template modals */
#templateEditorModal .template-editor-modal {
  max-height: calc(100vh - 40px);
}

#templateEditorModal .template-editor-intro {
  padding: 6px 10px 2px;
  gap: 6px;
}

#templateEditorModal .template-form-layout {
  gap: 6px;
  padding: 8px;
}

#templateEditorModal .template-form-main,
#templateEditorModal .template-form-side,
#templateEditorModal .meta-wizard,
#templateEditorModal .meta-wizard-main,
#templateEditorModal .meta-pane,
#templateEditorModal .template-crm-editor {
  gap: 8px;
}

#templateEditorModal .template-form-header,
#templateEditorModal .template-meta-fields,
#templateEditorModal .template-preview-vars,
#templateEditorModal .meta-form-grid,
#templateEditorModal .meta-category-picker,
#templateEditorModal .meta-review-list {
  gap: 8px;
}

#templateEditorModal .meta-wizard-layout {
  grid-template-columns: minmax(0, 1fr) 270px;
  gap: 8px;
}

#templateEditorModal .template-crm-stage {
  grid-template-columns: minmax(0, 1fr) 230px;
  gap: 8px;
}

#templateEditorModal .meta-wizard-preview,
#templateEditorModal .template-vars-panel,
#templateEditorModal .meta-wizard-main {
  padding: 8px;
}

#templateEditorModal .field textarea {
  min-height: 92px;
}

#templateEditorModal .template-preview-body,
#templateEditorModal .template-preview-body--chat,
#templateEditorModal #metaWizardPreviewBody,
#templateEditorModal #templatePreviewBody {
  min-height: 240px;
  padding: 12px;
}

@media (max-width: 1320px) {
  #templateEditorModal .meta-wizard-layout,
  #templateEditorModal .template-crm-stage {
    grid-template-columns: 1fr;
  }
}
