.type-badge {
  background: var(--background);
  border: 1px solid var(--border);
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 11px;
  color: var(--text-secondary);
}

.danger-btn:hover {
  background: var(--danger-light) !important;
  border-color: var(--danger) !important;
  color: var(--danger) !important;
}

/* ── Template Editor Layout ─────────────────────────────────────────── */
.tpl-editor-wrap {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

.tpl-editor-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.tpl-editor-title {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.tpl-editor-name {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tpl-editor-tabs {
  display: flex;
  gap: 0;
  padding: 0 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.tpl-tab {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 12px 18px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s;
  margin-bottom: -1px;
}

.tpl-tab:hover { color: var(--text-primary); }
.tpl-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.tpl-editor-body {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ── Fields Tab ─────────────────────────────────────────────────────── */
.tpl-fields-wrap {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

.tpl-fields-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  background: var(--background);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.tpl-fields-table-wrap {
  flex: 1;
  overflow: auto;
  padding: 16px 24px 24px;
}

.tpl-fields-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.tpl-fields-table thead th {
  background: var(--background);
  border-bottom: 1px solid var(--border);
  padding: 8px 10px;
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-secondary);
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 1;
}

.tpl-fields-table tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}
.tpl-fields-table tbody tr:hover { background: var(--background); }

.tpl-fields-table td {
  padding: 6px 6px;
  vertical-align: middle;
}

.tpl-field-input {
  width: 100%;
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 12.5px;
  background: var(--surface);
  color: var(--text-primary);
  transition: border-color 0.15s;
  min-width: 80px;
}
.tpl-field-input:focus { outline: none; border-color: var(--accent); }
.tpl-id-input { font-family: monospace; font-size: 12px; color: var(--primary-mid); }

.tpl-field-select {
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 12.5px;
  background: var(--surface);
  color: var(--text-primary);
  cursor: pointer;
  width: 100%;
}
.tpl-field-select:focus { outline: none; border-color: var(--accent); }

.tpl-move-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 1px 4px;
  font-size: 9px;
  cursor: pointer;
  color: var(--text-secondary);
  line-height: 1;
  display: block;
  width: 22px;
  text-align: center;
  transition: all 0.1s;
}
.tpl-move-btn:hover { background: var(--background); border-color: var(--accent); color: var(--accent); }

/* ── JSON Tab ───────────────────────────────────────────────────────── */
.tpl-json-wrap {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: 16px 24px 24px;
  gap: 10px;
  overflow: hidden;
}

.tpl-json-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.tpl-json-textarea {
  flex: 1;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  font-family: 'Menlo', 'Monaco', 'Courier New', monospace;
  font-size: 12.5px;
  line-height: 1.6;
  resize: none;
  background: var(--background);
  color: var(--text-primary);
  min-height: 0;
}
.tpl-json-textarea:focus { outline: none; border-color: var(--accent); }

/* ── HTML Tab ───────────────────────────────────────────────────────── */
.tpl-html-wrap {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: 16px 24px 24px;
  gap: 10px;
  overflow: hidden;
}

.tpl-html-textarea {
  flex: 1;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  font-family: 'Menlo', 'Monaco', 'Courier New', monospace;
  font-size: 12.5px;
  line-height: 1.6;
  resize: none;
  background: #1e2130;
  color: #e2e8f0;
  min-height: 0;
  tab-size: 2;
}
.tpl-html-textarea:focus { outline: none; border-color: var(--accent); }
.tpl-html-textarea::placeholder { color: #4a5568; }

.tpl-field-chip {
  background: var(--accent-light);
  border: 1px solid #BFDBFE;
  color: var(--accent);
  border-radius: 4px;
  padding: 3px 8px;
  font-size: 12px;
  font-family: monospace;
  cursor: pointer;
  transition: all 0.1s;
}
.tpl-field-chip:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.tpl-field-picker-title {
  width: 100%;
  margin-bottom: 4px;
  flex-shrink: 0;
}

/* ── Preview Tab ────────────────────────────────────────────────────── */
.tpl-preview-wrap {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  background: var(--background);
}

.tpl-preview-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.tpl-preview-frame-wrap {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px;
  width: 100%;
}

.tpl-preview-iframe {
  border: none;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  background: #fff;
  display: block;
  flex-shrink: 0;
  /* width + zoom set dynamically via JS */
}

.tpl-preview-size.active {
  background: var(--accent-light);
  border-color: var(--accent);
  color: var(--accent);
}

/* ── AI Tab ─────────────────────────────────────────────────────────── */
.tpl-ai-wrap {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  padding: 16px 24px 24px;
  gap: 12px;
}

.tpl-ai-info {
  background: var(--accent-light);
  border: 1px solid #BFDBFE;
  border-radius: var(--radius-lg);
  padding: 12px 16px;
  flex-shrink: 0;
}

.tpl-ai-messages {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  padding-right: 4px;
}

.tpl-ai-empty {
  margin: auto;
  text-align: center;
  padding: 32px;
  line-height: 1.7;
}

.tpl-ai-msg {
  display: flex;
  flex-direction: column;
}

.tpl-ai-msg--user { align-items: flex-end; }
.tpl-ai-msg--ai   { align-items: flex-start; }
.tpl-ai-msg--err  { align-items: flex-start; }

.tpl-ai-bubble {
  max-width: 75%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 13.5px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

.tpl-ai-msg--user .tpl-ai-bubble {
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.tpl-ai-msg--ai .tpl-ai-bubble {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
}
.tpl-ai-msg--err .tpl-ai-bubble {
  background: var(--danger-light);
  border: 1px solid #FCA5A5;
  color: var(--danger);
  border-bottom-left-radius: 4px;
}

.tpl-ai-applied {
  display: inline-block;
  margin-top: 6px;
  font-size: 11px;
  font-weight: 700;
  color: var(--success);
  background: var(--success-light);
  padding: 2px 8px;
  border-radius: 20px;
}

.tpl-ai-input-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  flex-shrink: 0;
}

.tpl-ai-input {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  font-size: 13.5px;
  font-family: var(--font);
  resize: none;
  background: var(--surface);
  color: var(--text-primary);
  line-height: 1.5;
}
.tpl-ai-input:focus { outline: none; border-color: var(--accent); }

/* ── Change Log Tab ── */
.tpl-changelog-wrap {
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  height: 100%;
  overflow: auto;
}

.tpl-changelog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.tpl-changelog-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.tpl-changelog-table th {
  text-align: left;
  padding: 8px 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
  background: var(--surface-raised);
  position: sticky;
  top: 0;
  z-index: 1;
}

.tpl-changelog-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.tpl-changelog-table tr:last-child td {
  border-bottom: none;
}

.tpl-changelog-table tbody tr:hover td {
  background: var(--surface-raised);
}

.changelog-current-row td {
  background: color-mix(in srgb, var(--accent) 5%, transparent);
}

.changelog-current-row:hover td {
  background: color-mix(in srgb, var(--accent) 8%, transparent) !important;
}

.changelog-version {
  font-weight: 700;
  font-family: var(--font-mono, monospace);
  font-size: 13px;
  color: var(--text-primary);
}
