/* Editor de modelos do WhatsApp (modules/templates.js) */
#templates-root {
  --tpl-ok-bg: #ECFDF5; --tpl-ok-fg: #065F46;
  --tpl-warn-bg: #FFFBEB; --tpl-warn-fg: #92400E;
  --tpl-bad-bg: #FEF2F2; --tpl-bad-fg: #991B1B;
  --tpl-pending-bg: #EFF6FF; --tpl-pending-fg: #1E40AF;
  --tpl-chat-bg: #E7DDD3; --tpl-bubble-bg: #FFFFFF;
}
html[data-theme="dark"] #templates-root,
body.dark-theme #templates-root {
  --tpl-ok-bg: rgba(16, 185, 129, .14); --tpl-ok-fg: #6EE7B7;
  --tpl-warn-bg: rgba(245, 158, 11, .14); --tpl-warn-fg: #FCD34D;
  --tpl-bad-bg: rgba(239, 68, 68, .14); --tpl-bad-fg: #FCA5A5;
  --tpl-pending-bg: rgba(59, 130, 246, .16); --tpl-pending-fg: #93C5FD;
  --tpl-chat-bg: #0B141A; --tpl-bubble-bg: #1F2C34;
}

.tpl-grid { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 24px; align-items: start; }
.tpl-form { display: flex; flex-direction: column; gap: 12px; }
.tpl-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.tpl-field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--text); }
.tpl-field > span { color: var(--text-muted); font-size: 12px; }
.tpl-field input, .tpl-field select, .tpl-field textarea {
  width: 100%; box-sizing: border-box; padding: 9px 11px; border: 1px solid var(--border);
  border-radius: 8px; background: var(--surface); color: var(--text); font: inherit; font-size: 14px;
}
.tpl-field textarea { resize: vertical; }
.tpl-examples { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.tpl-hint { margin: 0; font-size: 12px; }
.tpl-feedback, #tpl-result { display: flex; flex-direction: column; gap: 6px; }
.tpl-msg { display: flex; gap: 8px; align-items: flex-start; padding: 8px 10px; border-radius: 8px; font-size: 13px; line-height: 1.4; }
.tpl-msg i { margin-top: 2px; }
.tpl-msg ul { margin: 6px 0 0 18px; padding: 0; }
.tpl-msg.ok { background: var(--tpl-ok-bg); color: var(--tpl-ok-fg); }
.tpl-msg.warn { background: var(--tpl-warn-bg); color: var(--tpl-warn-fg); }
.tpl-msg.bad { background: var(--tpl-bad-bg); color: var(--tpl-bad-fg); }
#tpl-submit:disabled { background: var(--border); color: var(--text-muted); cursor: not-allowed; opacity: 1; }

.tpl-preview-col { position: sticky; top: 16px; display: flex; flex-direction: column; gap: 6px; }
.tpl-preview { background: var(--tpl-chat-bg); border-radius: 12px; padding: 16px; min-height: 120px; display: flex; flex-direction: column; gap: 4px; }
.tpl-bubble { background: var(--tpl-bubble-bg); color: var(--text); border-radius: 8px; padding: 8px 10px; font-size: 14px; line-height: 1.45; overflow-wrap: anywhere; }
.tpl-bubble-header { font-weight: 700; margin-bottom: 4px; }
.tpl-bubble-footer { color: var(--text-muted); font-size: 12px; margin-top: 6px; }
.tpl-bubble-btn { background: var(--tpl-bubble-bg); color: #1B73C5; text-align: center; border-radius: 8px; padding: 8px; font-size: 14px; }
html[data-theme="dark"] .tpl-bubble-btn, body.dark-theme .tpl-bubble-btn { color: #53BDEB; }

.tpl-list-head { display: flex; align-items: center; justify-content: space-between; margin-top: 28px; gap: 12px; }
.tpl-list-head h4 { margin: 0; }
#tpl-list { overflow-x: auto; margin-top: 8px; }
.tpl-status { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.tpl-status.ok { background: var(--tpl-ok-bg); color: var(--tpl-ok-fg); }
.tpl-status.warn { background: var(--tpl-warn-bg); color: var(--tpl-warn-fg); }
.tpl-status.bad { background: var(--tpl-bad-bg); color: var(--tpl-bad-fg); }
.tpl-status.pending { background: var(--tpl-pending-bg); color: var(--tpl-pending-fg); }
.tpl-reason { font-size: 12px; color: var(--text-muted); max-width: 260px; }
.tpl-actions { white-space: nowrap; }
.tpl-actions .secondary-btn { padding: 4px 10px; font-size: 12px; }

@media (max-width: 900px) {
  .tpl-grid { grid-template-columns: 1fr; }
  .tpl-preview-col { position: static; }
}
