:root {
  --bg: #0f1115;
  --panel: #161923;
  --panel-2: #1c202c;
  --border: #2a2f3d;
  --text: #e8eaf0;
  --muted: #8b91a3;
  --accent: #f5a623;
  --accent-2: #4fd1c5;
  --danger: #f0576b;
  --mono: "SF Mono", "JetBrains Mono", "Fira Code", ui-monospace, Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, #14161e, #0f1115);
}

.brand { display: flex; align-items: baseline; gap: 10px; }
.brand-mark { color: var(--accent); font-size: 1.3rem; }
.brand-name { font-weight: 700; font-size: 1.15rem; letter-spacing: -0.01em; }
.brand-sub { color: var(--muted); font-size: 0.85rem; }

.repo-link {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.85rem;
  border: 1px solid var(--border);
  padding: 5px 12px;
  border-radius: 6px;
}
.repo-link:hover { color: var(--accent-2); border-color: var(--accent-2); }

.layout {
  display: grid;
  grid-template-columns: minmax(320px, 1fr) minmax(400px, 1.4fr);
  gap: 1px;
  background: var(--border);
  min-height: calc(100vh - 110px);
}

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

.editor-pane, .result-pane {
  background: var(--panel);
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
}

.pane-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  flex-wrap: wrap;
  gap: 8px;
}

.pane-head h2 {
  font-size: 1rem;
  font-weight: 600;
  margin: 0;
}

.muted { color: var(--muted); font-weight: 400; }

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

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font-size: 0.85rem;
  cursor: pointer;
  text-decoration: none;
  font-family: var(--sans);
}
.btn:hover { border-color: var(--accent-2); }
.btn.primary {
  background: var(--accent);
  color: #1a1200;
  border-color: var(--accent);
  font-weight: 600;
}
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }

textarea#yaml_text {
  width: 100%;
  flex: 1;
  min-height: 420px;
  background: #0b0d12;
  color: #d7e4ff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  font-family: var(--mono);
  font-size: 0.85rem;
  line-height: 1.5;
  resize: vertical;
  tab-size: 2;
}
textarea#yaml_text:focus { outline: none; border-color: var(--accent-2); }

.save-row {
  display: flex;
  gap: 8px;
  margin-top: 14px;
  align-items: center;
}
.save-row input {
  flex: 1;
  background: #0b0d12;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 7px 10px;
  border-radius: 6px;
  font-family: var(--sans);
  font-size: 0.85rem;
}
.save-status { font-size: 0.8rem; }
.save-status.ok { color: var(--accent-2); }
.save-status.err { color: var(--danger); }

.library { margin-top: 18px; }
.library h3 {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 8px;
}
.library ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.library li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
}
.library a { color: var(--text); text-decoration: none; font-size: 0.87rem; }
.library a:hover { color: var(--accent-2); }
.del-btn {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 2px 6px;
}
.del-btn:hover { color: var(--danger); }

.canvas {
  flex: 1;
  background: #0b0d12;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px;
  overflow: auto;
  display: flex;
  align-items: flex-start;
  justify-content: center;
}

.svg-wrap { width: 100%; }
.svg-wrap svg { max-width: 100%; height: auto; }

.empty-state, .error-box {
  color: var(--muted);
  max-width: 480px;
  margin: auto;
  text-align: center;
}
.error-box { color: var(--danger); text-align: left; }
.error-box pre {
  white-space: pre-wrap;
  background: #1a0f13;
  border: 1px solid #3a1c24;
  padding: 12px;
  border-radius: 6px;
  font-size: 0.8rem;
  margin-top: 10px;
}

.footer {
  text-align: center;
  padding: 12px;
  color: var(--muted);
  font-size: 0.78rem;
  border-top: 1px solid var(--border);
}

/* AI Assistant panel */
.ai-panel {
  position: fixed;
  top: 0;
  right: -420px;
  width: 400px;
  height: 100vh;
  background: var(--panel-bg, #1a1a1a);
  border-left: 1px solid rgba(255,255,255,0.1);
  box-shadow: -8px 0 24px rgba(0,0,0,0.4);
  display: flex;
  flex-direction: column;
  padding: 16px;
  gap: 12px;
  transition: right 0.2s ease;
  z-index: 1000;
}
.ai-panel.open {
  right: 0;
}
.ai-hint {
  font-size: 0.85rem;
  line-height: 1.4;
}
.ai-log {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-right: 4px;
}
.ai-msg {
  display: flex;
  flex-direction: column;
}
.ai-msg.ai-user {
  align-items: flex-end;
}
.ai-msg.ai-assistant {
  align-items: flex-start;
}
.ai-bubble {
  max-width: 90%;
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 0.88rem;
  line-height: 1.4;
  white-space: pre-wrap;
}
.ai-user .ai-bubble {
  background: #2b5d8a;
  color: #fff;
}
.ai-assistant .ai-bubble {
  background: rgba(255,255,255,0.08);
}
.ai-thinking .ai-bubble {
  font-style: italic;
  opacity: 0.7;
}
.ai-extra {
  margin-top: 6px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: flex-start;
}
.ai-bom {
  font-size: 0.75rem;
  background: rgba(255,255,255,0.06);
  padding: 8px;
  border-radius: 6px;
  max-width: 100%;
  overflow-x: auto;
  white-space: pre;
}
.ai-input-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.ai-input-row textarea {
  resize: vertical;
  min-height: 60px;
  padding: 8px;
  border-radius: 6px;
  border: 1px solid rgba(255,255,255,0.15);
  background: rgba(255,255,255,0.04);
  color: inherit;
  font-family: inherit;
  font-size: 0.88rem;
}

.ai-svg-preview {
  max-width: 100%;
  overflow: auto;
  background: rgba(255,255,255,0.04);
  border-radius: 6px;
  padding: 6px;
}
.ai-svg-preview svg {
  max-width: 100%;
  height: auto;
}

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