:root {
  --bg: #0c0f14;
  --bg-card: #14181f;
  --bg-card-hover: #1a1f28;
  --bg-input: #1a1f28;
  --bg-input-focus: #1e2430;
  --border: #2a3040;
  --border-focus: #4f8aff;
  --text: #e8ecf4;
  --text-dim: #8892a4;
  --text-muted: #5a6478;
  --accent: #4f8aff;
  --accent-glow: rgba(79,138,255,0.15);
  --accent-soft: #3a6fd8;
  --green: #34d399;
  --green-bg: rgba(52,211,153,0.1);
  --orange: #fb923c;
  --orange-bg: rgba(251,146,60,0.1);
  --red: #f87171;
  --red-bg: rgba(248,113,113,0.1);
  --purple: #a78bfa;
  --purple-bg: rgba(167,139,250,0.1);
  --pink: #f472b6;
  --yellow: #fbbf24;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
  --shadow: 0 4px 24px rgba(0,0,0,0.3);
  --shadow-lg: 0 8px 40px rgba(0,0,0,0.4);
  --transition: 0.2s ease;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: 'DM Sans', -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* Layout */
.container { max-width: 1100px; margin: 0 auto; padding: 0 16px; }

/* =========== HEADER =========== */
.header {
  padding: 40px 0 32px;
  text-align: center;
  position: relative;
}
.header::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 80px;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
}
.header-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 14px;
  background: var(--accent-glow);
  border: 1px solid rgba(79,138,255,0.2);
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: 0.5px;
  text-transform: uppercase;
  margin-bottom: 16px;
}
.header h1 {
  font-size: clamp(24px, 5vw, 36px);
  font-weight: 700;
  letter-spacing: -0.5px;
  margin-bottom: 10px;
  background: linear-gradient(135deg, var(--text) 0%, var(--text-dim) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
.header p {
  color: var(--text-dim);
  font-size: 15px;
  max-width: 560px;
  margin: 0 auto;
}

/* =========== NAV TABS =========== */
.nav-tabs {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  margin: 24px 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.nav-tab {
  flex: 1;
  min-width: 100px;
  padding: 10px 16px;
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
  text-align: center;
}
.nav-tab:hover { color: var(--text); background: var(--bg-input); }
.nav-tab.active {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 2px 12px rgba(79,138,255,0.3);
}

/* =========== SECTIONS =========== */
.section { display: none; animation: fadeIn 0.3s ease; }
.section.active { display: block; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* =========== TEMPLATE CARDS =========== */
.templates-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
  margin-bottom: 32px;
}
.template-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  cursor: pointer;
  transition: var(--transition);
  position: relative;
  overflow: hidden;
}
.template-card:hover {
  background: var(--bg-card-hover);
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 4px 20px rgba(79,138,255,0.1);
}
.template-card.selected {
  border-color: var(--accent);
  background: var(--accent-glow);
}
.template-card .tc-icon {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  margin-bottom: 12px;
}
.template-card .tc-name {
  font-weight: 700;
  font-size: 15px;
  margin-bottom: 4px;
}
.template-card .tc-desc {
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.5;
  margin-bottom: 10px;
}
.template-card .tc-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.template-card .tc-tag {
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  background: var(--bg-input);
  color: var(--text-dim);
}
.template-card .tc-featured {
  position: absolute;
  top: 12px;
  right: 12px;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 700;
  background: var(--green-bg);
  color: var(--green);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.template-card .tc-new {
  position: absolute;
  top: 12px;
  right: 12px;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 700;
  background: var(--orange-bg);
  color: var(--orange);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* =========== EDITOR =========== */
.editor-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin-bottom: 24px;
}
.editor-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}
.editor-header h2 {
  font-size: 16px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}
.editor-body { padding: 20px; }

/* Accordion sections */
.accordion {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 12px;
  overflow: hidden;
}
.accordion-head {
  padding: 14px 16px;
  background: var(--bg-input);
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  user-select: none;
  transition: var(--transition);
}
.accordion-head:hover { background: var(--bg-input-focus); }
.accordion-head h3 {
  font-size: 14px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}
.accordion-head .acc-arrow {
  transition: transform 0.3s;
  color: var(--text-dim);
  font-size: 12px;
}
.accordion.open .acc-arrow { transform: rotate(180deg); }
.accordion-body {
  display: none;
  padding: 16px;
  border-top: 1px solid var(--border);
}
.accordion.open .accordion-body { display: block; }

/* Form fields */
.field-group {
  margin-bottom: 16px;
}
.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
@media (max-width: 600px) {
  .field-row { grid-template-columns: 1fr; }
}
.field-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 6px;
}
.field-label .info-icon {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  color: var(--text-muted);
  cursor: help;
  position: relative;
}
.field-label .info-icon:hover { color: var(--accent); border-color: var(--accent); }
.info-tooltip {
  display: none;
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 400;
  color: var(--text);
  width: 220px;
  z-index: 100;
  box-shadow: var(--shadow);
  line-height: 1.5;
}
.info-icon:hover .info-tooltip { display: block; }

input[type="text"],
input[type="number"],
input[type="url"],
input[type="color"],
select,
textarea {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  transition: var(--transition);
  outline: none;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--border-focus);
  background: var(--bg-input-focus);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
textarea { resize: vertical; min-height: 80px; }
select { cursor: pointer; }
input[type="color"] {
  padding: 4px;
  height: 40px;
  cursor: pointer;
}

.toggle-group {
  display: flex;
  align-items: center;
  gap: 10px;
}
.toggle {
  width: 40px;
  height: 22px;
  background: var(--border);
  border-radius: 11px;
  position: relative;
  cursor: pointer;
  transition: var(--transition);
  flex-shrink: 0;
}
.toggle.on { background: var(--accent); }
.toggle::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  background: #fff;
  border-radius: 50%;
  transition: var(--transition);
}
.toggle.on::after { left: 21px; }
.toggle-label { font-size: 13px; color: var(--text-dim); }

/* =========== STEPS EDITOR =========== */
.step-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  position: relative;
}
.step-card .step-num {
  position: absolute;
  top: -8px;
  left: 16px;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 10px;
  border-radius: 10px;
}
.step-card .step-actions {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  gap: 4px;
}
.step-card .step-actions button {
  width: 28px;
  height: 28px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  border-radius: 6px;
  color: var(--text-dim);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  transition: var(--transition);
}
.step-card .step-actions button:hover { color: var(--red); border-color: var(--red); }
.step-card .step-actions button.move-btn:hover { color: var(--accent); border-color: var(--accent); }

.btn-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 8px;
}
.btn-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 12px;
  color: var(--text-dim);
  cursor: pointer;
  transition: var(--transition);
}
.btn-chip:hover { border-color: var(--accent); color: var(--text); }
.btn-chip .chip-score {
  background: var(--accent-glow);
  color: var(--accent);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 700;
}

/* Button edit modal */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 16px;
  backdrop-filter: blur(4px);
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  max-width: 480px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}
.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.modal-header h3 { font-size: 15px; font-weight: 700; }
.modal-close {
  width: 32px;
  height: 32px;
  border: none;
  background: var(--bg-input);
  border-radius: 8px;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}
.modal-close:hover { color: var(--red); }
.modal-body { padding: 20px; }
.modal-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

/* =========== BUTTONS =========== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 18px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}
.btn-primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 2px 8px rgba(79,138,255,0.3);
}
.btn-primary:hover { background: var(--accent-soft); transform: translateY(-1px); box-shadow: 0 4px 16px rgba(79,138,255,0.4); }
.btn-secondary {
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover { border-color: var(--text-dim); }
.btn-danger {
  background: var(--red-bg);
  color: var(--red);
  border: 1px solid rgba(248,113,113,0.2);
}
.btn-danger:hover { background: rgba(248,113,113,0.2); }
.btn-success {
  background: var(--green);
  color: #0c0f14;
  box-shadow: 0 2px 8px rgba(52,211,153,0.3);
}
.btn-success:hover { transform: translateY(-1px); box-shadow: 0 4px 16px rgba(52,211,153,0.4); }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-lg { padding: 14px 28px; font-size: 15px; }
.btn-block { width: 100%; justify-content: center; }

/* =========== JSON PREVIEW =========== */
.json-preview {
  background: #0d1117;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.json-preview-header {
  padding: 10px 16px;
  background: var(--bg-input);
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.json-preview-header span {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  font-family: 'JetBrains Mono', monospace;
}
.json-preview pre {
  padding: 16px;
  overflow-x: auto;
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  line-height: 1.6;
  color: #c9d1d9;
  max-height: 500px;
  overflow-y: auto;
}

/* =========== GUIDE SECTION =========== */
.guide-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}
.guide-card h3 {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.guide-card p, .guide-card li {
  font-size: 14px;
  color: var(--text-dim);
  line-height: 1.7;
}
.guide-card ol, .guide-card ul {
  padding-left: 20px;
  margin-top: 8px;
}
.guide-card li { margin-bottom: 6px; }
.guide-card .guide-tip {
  margin-top: 12px;
  padding: 10px 14px;
  background: var(--accent-glow);
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 13px;
  color: var(--text);
}

/* =========== ALERT / FEEDBACK =========== */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--green);
  color: #0c0f14;
  padding: 12px 24px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  z-index: 9999;
  transition: transform 0.3s ease;
  box-shadow: var(--shadow-lg);
}
.toast.show { transform: translateX(-50%) translateY(0); }

/* =========== FOOTER =========== */
.footer {
  text-align: center;
  padding: 32px 0;
  color: var(--text-muted);
  font-size: 12px;
  border-top: 1px solid var(--border);
  margin-top: 40px;
}

/* =========== RESPONSIVE =========== */
@media (max-width: 640px) {
  .container { padding: 0 12px; }
  .header { padding: 24px 0 20px; }
  .templates-grid { grid-template-columns: 1fr; }
  .editor-body { padding: 14px; }
  .nav-tabs { gap: 2px; }
  .nav-tab { padding: 8px 10px; font-size: 12px; min-width: 70px; }
  .field-row { grid-template-columns: 1fr; }
  .step-card { padding: 14px 12px; }
}

/* Step add button */
.add-step-btn {
  width: 100%;
  padding: 14px;
  border: 2px dashed var(--border);
  background: transparent;
  border-radius: var(--radius);
  color: var(--text-dim);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.add-step-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-glow);
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-dim);
}
.empty-state .es-icon { font-size: 48px; margin-bottom: 16px; opacity: 0.5; }
.empty-state h3 { font-size: 18px; color: var(--text); margin-bottom: 8px; }
.empty-state p { font-size: 14px; max-width: 400px; margin: 0 auto; }

/* Download banner */
.download-banner {
  background: linear-gradient(135deg, var(--accent-glow) 0%, var(--purple-bg) 100%);
  border: 1px solid rgba(79,138,255,0.2);
  border-radius: var(--radius-lg);
  padding: 24px;
  text-align: center;
  margin: 24px 0;
}
.download-banner h3 { font-size: 18px; font-weight: 700; margin-bottom: 8px; }
.download-banner p { color: var(--text-dim); font-size: 14px; margin-bottom: 16px; }

/* Score badge colors */
.score-hot { background: var(--red-bg); color: var(--red); }
.score-warm { background: var(--orange-bg); color: var(--orange); }
.score-cold { background: rgba(96,165,250,0.1); color: #60a5fa; }

/* =========== MODE BADGES =========== */
.mode-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.mode-ai { background: rgba(167,139,250,0.15); color: var(--purple); }
.mode-guided { background: var(--green-bg); color: var(--green); }
.mode-hybrid { background: var(--orange-bg); color: var(--orange); }

/* Mode Selector in Editor */
.mode-selector {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
}
.mode-option {
  flex: 1;
  padding: 16px;
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: var(--transition);
  text-align: center;
}
.mode-option:hover { border-color: var(--text-dim); background: var(--bg-card-hover); }
.mode-option.active { border-color: var(--accent); background: var(--accent-glow); }
.mode-option .mo-icon { font-size: 28px; margin-bottom: 8px; }
.mode-option .mo-title { font-size: 14px; font-weight: 700; margin-bottom: 4px; }
.mode-option .mo-desc { font-size: 11px; color: var(--text-dim); line-height: 1.4; }
@media (max-width: 640px) {
  .mode-selector { flex-direction: column; }
  .mode-option { padding: 12px; }
}

/* System Prompt */
.prompt-editor {
  min-height: 200px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  line-height: 1.7;
  white-space: pre-wrap;
}
.prompt-tips {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 12px;
}
.prompt-tip {
  padding: 8px 12px;
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  font-size: 12px;
  color: var(--text-dim);
  border-left: 3px solid var(--accent);
}
@media (max-width: 640px) {
  .prompt-tips { grid-template-columns: 1fr; }
}

/* Widget Preview Mini */
.widget-mini-preview {
  background: #fff;
  border-radius: var(--radius);
  padding: 16px;
  max-width: 320px;
  margin: 16px auto 0;
  box-shadow: var(--shadow);
  color: #333;
  font-size: 13px;
}
.wmp-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-bottom: 12px;
  border-bottom: 1px solid #e5e7eb;
  margin-bottom: 12px;
}
.wmp-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 14px;
  font-weight: 700;
}
.wmp-name { font-weight: 600; font-size: 14px; }
.wmp-bubble {
  background: #f3f4f6;
  border-radius: 12px 12px 12px 4px;
  padding: 10px 14px;
  font-size: 13px;
  line-height: 1.5;
  color: #374151;
  margin-bottom: 8px;
}
.wmp-buttons { display: flex; flex-direction: column; gap: 6px; }
.wmp-btn {
  padding: 8px 12px;
  border-radius: 8px;
  text-align: center;
  color: #fff;
  font-size: 12px;
  font-weight: 600;
}
.wmp-input {
  margin-top: 8px;
  padding: 8px 12px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  font-size: 12px;
  color: #9ca3af;
  background: #f9fafb;
}

/* Color swatch row */
.color-row {
  display: flex;
  align-items: center;
  gap: 12px;
}
.color-row input[type="color"] {
  width: 48px;
  height: 40px;
}
.color-hex {
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  color: var(--text-dim);
}

/* Conditional sections */
.section-hidden { display: none !important; }

/* Filter buttons */
.filter-btn {
  background: var(--bg-input);
  color: var(--text-dim);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: var(--transition);
}
.filter-btn:hover { border-color: var(--text-dim); color: var(--text); }
.filter-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* =========== AI GENERATION SECTION =========== */
.ai-gen-section {
  background: var(--bg-card);
  border: 1px solid var(--accent);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 20px;
  position: relative;
  overflow: hidden;
}
.ai-gen-section::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--accent), var(--purple), var(--accent));
  background-size: 200% 100%;
  animation: aiGradient 3s ease infinite;
}
@keyframes aiGradient {
  0%, 100% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
}
.ai-gen-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}
.ai-gen-header h3 {
  font-size: 16px;
  font-weight: 700;
}
.ai-gen-badge {
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 10px;
}
.ai-gen-desc {
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 14px;
  line-height: 1.5;
}

/* API Key Section */
.ai-gen-key-section {
  margin-bottom: 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0;
}
.ai-gen-key-section summary {
  padding: 10px 14px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  list-style: none;
  display: flex;
  align-items: center;
  gap: 6px;
}
.ai-gen-key-section summary::marker,
.ai-gen-key-section summary::-webkit-details-marker { display: none; }
.ai-gen-key-section[open] summary {
  border-bottom: 1px solid var(--border);
  color: var(--text);
}
.ai-gen-key-row {
  display: flex;
  gap: 6px;
  padding: 10px 14px;
  align-items: center;
}
.ai-gen-key-row input {
  flex: 1;
  min-width: 0;
}
.ai-gen-key-hint {
  padding: 0 14px 10px;
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.4;
}
.ai-gen-key-saved {
  color: var(--green);
  font-size: 12px;
  font-weight: 600;
  padding: 10px 14px;
}

/* Prompt Textarea */
#aiPromptInput {
  width: 100%;
  min-height: 80px;
  padding: 12px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  line-height: 1.6;
  resize: vertical;
  transition: var(--transition);
}
#aiPromptInput:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--bg-input-focus);
}
#aiPromptInput::placeholder { color: var(--text-muted); }

/* Actions Row */
.ai-gen-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 10px;
  gap: 12px;
}
.ai-gen-chars {
  font-size: 12px;
  color: var(--text-muted);
  font-family: 'JetBrains Mono', monospace;
}

/* Loading State */
.ai-gen-loading {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  margin-top: 12px;
  background: var(--accent-glow);
  border-radius: var(--radius-sm);
  border: 1px solid rgba(79,138,255,0.2);
}
.ai-gen-loading p {
  font-size: 13px;
  color: var(--accent);
  font-weight: 600;
}
.ai-gen-spinner {
  width: 24px;
  height: 24px;
  border: 3px solid rgba(79,138,255,0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: aiSpin 0.8s linear infinite;
  flex-shrink: 0;
}
@keyframes aiSpin {
  to { transform: rotate(360deg); }
}

/* Error State */
.ai-gen-error {
  margin-top: 12px;
  padding: 12px 14px;
  background: var(--red-bg);
  border: 1px solid rgba(248,113,113,0.2);
  border-left: 3px solid var(--red);
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--red);
  line-height: 1.5;
}

/* Selettore modalità AI nella sezione genera template */
.ai-mode-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-light);
  cursor: pointer;
  transition: all 0.2s;
  border-radius: var(--radius-sm);
  padding: 4px 12px;
}
.ai-mode-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}
.ai-mode-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* AI Generated Template Badge & Delete */
.tc-ai-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(167,139,250,0.15);
  color: var(--purple);
  font-size: 10px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 6px;
  z-index: 1;
}
.tc-delete {
  position: absolute;
  bottom: 8px;
  right: 8px;
  width: 26px;
  height: 26px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  border-radius: 6px;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  transition: var(--transition);
  z-index: 1;
}
.tc-delete:hover {
  color: var(--red);
  border-color: var(--red);
  background: var(--red-bg);
}

@media (max-width: 640px) {
  .ai-gen-section { padding: 14px; }
  .ai-gen-actions { flex-direction: column; align-items: stretch; }
  .ai-gen-actions .btn { width: 100%; justify-content: center; }
  .ai-gen-chars { text-align: right; }
  .ai-gen-key-row { flex-wrap: wrap; }
  .ai-gen-key-row input { width: 100%; }
}

/* =========== SECTION SWITCHER (Documenti / Chatbot) =========== */
.section-switcher {
  display: flex;
  gap: 4px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 4px;
  margin-bottom: 24px;
}
.section-switch-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 16px;
  background: transparent;
  border: none;
  border-radius: var(--radius);
  color: var(--text-dim);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}
.section-switch-btn:hover {
  color: var(--text);
  background: var(--bg-card-hover);
}
.section-switch-btn.active {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 2px 8px rgba(79,138,255,0.3);
}
.switch-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}
.switch-icon svg {
  width: 18px;
  height: 18px;
}

/* =========== FILTER SECTION (Mode + Target) =========== */
.filter-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 20px;
  padding: 14px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.filter-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.filter-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  min-width: 70px;
  flex-shrink: 0;
}
.filter-btn.cat-filter {
  font-size: 12px;
  padding: 5px 12px;
  border-radius: 20px;
}
.filter-btn.cat-filter.active {
  background: var(--green);
  border-color: var(--green);
  color: #0c0f14;
}

/* =========== TARGET BADGES =========== */
.target-badge {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  padding: 2px 8px;
  border-radius: 4px;
}
.target-clienti {
  background: var(--accent-glow);
  color: var(--accent);
}
.target-dal-cliente {
  background: var(--green-bg);
  color: var(--green);
}
.target-segnalatori {
  background: var(--orange-bg);
  color: var(--orange);
}
.target-collaboratori {
  background: var(--purple-bg);
  color: var(--purple);
}
.target-partner {
  background: rgba(244,114,182,0.1);
  color: var(--pink);
}

/* =========== RESPONSIVE: SECTION SWITCHER & FILTERS =========== */
@media (max-width: 640px) {
  .section-switcher { margin-bottom: 16px; }
  .section-switch-btn { padding: 10px 10px; font-size: 13px; gap: 6px; }
  .switch-icon { width: 16px; height: 16px; }
  .switch-icon svg { width: 14px; height: 14px; }
  .filter-section { padding: 10px 12px; gap: 8px; }
  .filter-row {
    gap: 4px;
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 4px;
  }
  .filter-row::-webkit-scrollbar { display: none; }
  .filter-label { min-width: auto; font-size: 11px; flex-shrink: 0; }
  .filter-btn { flex-shrink: 0; }
  .filter-btn.cat-filter { padding: 4px 8px; font-size: 11px; white-space: nowrap; }
  /* Template cards: ensure proper spacing on mobile */
  .template-card { padding: 14px 12px; }
  .tc-tag { font-size: 9px; padding: 2px 5px; }
  .target-badge { font-size: 9px; padding: 1px 6px; }
}
