:root {
  --bg: #f6f7ff;
  --panel: #ffffff;
  --primary: #7c3aed;
  --primary-strong: #6d28d9;
  --accent: #14b8a6;
  --muted: #5b6b7b;
  --stroke: #d9e3ea;
  --success: #22c55e;
  --danger: #ef4444;
  --shadow: 0 12px 30px rgba(0, 0, 0, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: radial-gradient(120% 120% at 30% 10%, rgba(124, 58, 237, 0.10), transparent 50%),
    radial-gradient(80% 80% at 80% 0%, rgba(20, 184, 166, 0.10), transparent 40%), var(--bg);
  color: #0f172a;
  font-family: "Nunito", "Trebuchet MS", "Segoe UI", system-ui, -apple-system, sans-serif;
  line-height: 1.4;
}

header {
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  position: sticky;
  top: 0;
  background: rgba(246, 247, 255, 0.92);
  backdrop-filter: blur(10px);
  z-index: 3;
  border-bottom: 1px solid var(--stroke);
}

h1 {
  margin: 0;
  font-size: 20px;
  letter-spacing: 0.3px;
  display: flex;
  align-items: center;
  gap: 8px;
}

h1 .pill {
  background: var(--accent);
  color: #fff;
  border-radius: 12px;
  padding: 2px 8px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

button,
.button {
  border: none;
  background: var(--primary);
  color: #fff;
  padding: 10px 14px;
  border-radius: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.1s ease, box-shadow 0.2s ease, background 0.2s ease;
  box-shadow: 0 6px 16px rgba(124, 58, 237, 0.30);
}

button.secondary,
.button.secondary {
  background: #e2ecf3;
  color: #0f172a;
  box-shadow: none;
}

button.danger {
  background: var(--danger);
  box-shadow: 0 6px 16px rgba(239, 68, 68, 0.25);
}

button:active {
  transform: translateY(1px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  box-shadow: none;
}

main {
  padding: 16px;
  display: grid;
  gap: 14px;
  grid-template-columns: 1fr;
}

.grid {
  display: grid;
  gap: 12px;
}

.panel {
  background: var(--panel);
  border-radius: 18px;
  padding: 14px 16px;
  box-shadow: var(--shadow);
  border: 1px solid var(--stroke);
  position: relative;
}

.panel::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  border-radius: 18px 18px 0 0;
  background: linear-gradient(90deg, rgba(124, 58, 237, 0.8), rgba(20, 184, 166, 0.8));
  opacity: 0.5;
  pointer-events: none;
}

.panel h2,
.panel h3 {
  margin: 0 0 8px 0;
  font-size: 16px;
  display: flex;
  align-items: center;
  gap: 6px;
  letter-spacing: 0.1px;
}

.panel h3 {
  font-size: 15px;
}

.section-row {
  display: grid;
  gap: 12px;
}

@media (min-width: 900px) {
  main {
    grid-template-columns: 1.1fr 1fr;
    max-width: 1100px;
    margin: 0 auto;
  }

  .section-row.top {
    grid-template-columns: 1fr 1fr;
  }

  .section-row.mid {
    grid-template-columns: 1fr;
  }

  .templates-section {
    grid-column: 1 / span 2;
  }
}

label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 4px;
}

input[type="text"],
input[type="number"],
textarea,
select {
  width: 100%;
  border: 1px solid var(--stroke);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 14px;
  background: #f8fafc;
  color: #0f172a;
  transition: border 0.15s ease, box-shadow 0.15s ease;
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.18);
  background: #fff;
}

details.advanced {
  margin-top: 8px;
  border: 1px solid var(--stroke);
  border-radius: 14px;
  padding: 8px 10px;
  background: #fbfbff;
}

details.advanced summary {
  cursor: pointer;
  font-weight: 800;
  color: #0f172a;
  list-style: none;
}

details.advanced summary::-webkit-details-marker {
  display: none;
}

details.advanced summary::after {
  content: "▾";
  float: right;
  color: var(--muted);
}

details.advanced[open] summary::after {
  content: "▴";
}

details.advanced > .inline,
details.advanced > div {
  margin-top: 8px;
}

textarea {
  resize: vertical;
  min-height: 76px;
}

.inline {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  align-items: end;
}

#inputPanel .inline {
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.chip,
.tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #ede9fe;
  color: #0f172a;
  border-radius: 999px;
  padding: 6px 10px;
  font-weight: 700;
  font-size: 12px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.2s ease, border 0.2s ease, transform 0.1s ease;
}

.chip.active,
.tag.active {
  background: #fff;
  border-color: var(--primary);
  transform: translateY(-1px);
}

.template-card {
  border: 1px solid var(--stroke);
  border-radius: 16px;
  padding: 12px;
  background: #fff;
  box-shadow: 0 6px 18px rgba(15, 23, 42, 0.06);
  display: grid;
  gap: 10px;
}

.template-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.template-title {
  font-size: 15px;
  font-weight: 800;
  margin: 0;
}

.note {
  color: var(--muted);
  font-size: 13px;
}

pre.rendered {
  background: #0b1220;
  color: #e2e8f0;
  padding: 10px;
  border-radius: 12px;
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: "JetBrains Mono", "SFMono-Regular", Consolas, monospace;
  font-size: 13px;
  line-height: 1.5;
}

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

.pill-small {
  border-radius: 10px;
  background: #e2ecf3;
  padding: 4px 8px;
  font-size: 12px;
  font-weight: 700;
  color: #0f172a;
}

.status-row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 13px;
}

.toast {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: #0f172a;
  color: #fff;
  padding: 10px 14px;
  border-radius: 12px;
  box-shadow: var(--shadow);
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 5;
  font-weight: 700;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, -4px);
}

.tabs {
  display: inline-flex;
  background: #e2ecf3;
  border-radius: 12px;
  padding: 4px;
  gap: 4px;
}

.tab {
  border-radius: 10px;
  padding: 8px 12px;
  font-weight: 800;
  cursor: pointer;
  font-size: 13px;
  color: #0f172a;
  background: transparent;
  border: none;
  transition: background 0.15s ease, color 0.15s ease;
}

.tab.active {
  background: #fff;
  color: #0f172a;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.hidden {
  display: none !important;
}

.tag-list {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.template-list {
  display: grid;
  gap: 10px;
  max-height: 65vh;
  overflow: auto;
  padding-right: 4px;
}

.inline-tag {
  color: var(--muted);
  font-size: 12px;
  padding: 2px 6px;
  border-radius: 8px;
  background: #ede9fe;
}

.small {
  font-size: 12px;
  color: var(--muted);
}

.hint-desktop {
  display: none;
}

@media (min-width: 700px) {
  .hint-desktop {
    display: block;
  }
}

.muted-strong {
  color: #1f2937;
}

.editor {
  border: 1px solid var(--stroke);
  border-radius: 12px;
  padding: 10px;
  background: #f9fafb;
}

.editor textarea {
  min-height: 180px;
}

.flex-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.badge {
  padding: 3px 8px;
  border-radius: 8px;
  background: #ede9fe;
  font-size: 12px;
  font-weight: 700;
}

.error {
  color: var(--danger);
  font-weight: 700;
}

.success {
  color: var(--success);
  font-weight: 700;
}

.input-preview {
  background: #f5f3ff;
  color: #0f172a;
  padding: 8px 10px;
  border-radius: 12px;
  border: 1px solid var(--stroke);
  font-family: "JetBrains Mono", "SFMono-Regular", Consolas, monospace;
  font-size: 12px;
  max-height: 80px;
  min-height: 44px;
  overflow: auto;
  white-space: pre-wrap;
}

.pill-flag {
  background: #ede9fe;
  padding: 4px 6px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 700;
}

.outline {
  background: #fff;
  border: 1px solid var(--primary);
  color: var(--primary);
  box-shadow: none;
}

.input-with-action {
  display: flex;
  gap: 8px;
  align-items: center;
}

.input-with-action input {
  flex: 1;
}

.small-btn {
  padding: 8px 10px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

@media (max-width: 640px) {
  .small-btn {
    padding: 6px 8px;
    font-size: 11px;
  }
}

.drop-zone {
  margin-top: 8px;
  border: 2px dashed var(--stroke);
  background: #fafafe;
  border-radius: 14px;
  padding: 12px;
  text-align: center;
  color: var(--muted);
  transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
}

.drop-zone.dragover {
  border-color: var(--primary);
  background: #f2eaff;
  color: #0f172a;
}

.drop-title {
  font-weight: 800;
  color: #0f172a;
  margin-bottom: 4px;
}

@media (max-width: 640px) {
  .drop-zone {
    display: none;
  }
}

#variableList {
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
}

#variableList .inline {
  grid-template-columns: 1fr;
}

.divider {
  height: 1px;
  background: var(--stroke);
  margin: 10px 0;
}

.toast-area {
  position: fixed;
  top: 12px;
  right: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 10;
}
