/* Builder layout */
.builder-body {
  margin: 0;
  height: 100vh;
  overflow: hidden;
  color: var(--text-primary);
  display: flex;
  flex-direction: column;
  background: var(--bg-base, #0a0a14);
}

.builder-topbar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 16px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--border);
  background: rgba(10, 10, 20, 0.7);
  backdrop-filter: blur(12px);
  z-index: 5;
}
.builder-brand { display: flex; align-items: center; gap: 12px; }
.builder-brand .logo-icon { width: 32px; height: 32px; }
.brand-title { font-weight: 700; font-size: 15px; }
.brand-sub { font-size: 11px; color: var(--text-secondary); letter-spacing: 0.04em; text-transform: uppercase; }
.link-back { color: var(--text-secondary); font-size: 13px; text-decoration: none; }
.link-back:hover { color: var(--text-primary); }

.builder-prompt-bar {
  display: flex; gap: 8px; align-items: center;
}
.builder-prompt-bar input {
  flex: 1; min-width: 200px;
  padding: 10px 14px;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-primary);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s, background 0.15s;
}
.builder-prompt-bar input:focus { border-color: #a78bfa; background: rgba(139,92,246,0.06); }
.builder-prompt-bar select {
  padding: 9px 10px;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-primary);
  font-size: 13px;
  cursor: pointer;
}
.btn-primary {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 10px 16px;
  background: linear-gradient(135deg, #8b5cf6, #06b6d4);
  border: none;
  border-radius: 10px;
  color: white;
  font-weight: 600; font-size: 13px;
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.15s, opacity 0.15s;
  box-shadow: 0 4px 14px rgba(139,92,246,0.35);
}
.btn-primary:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 6px 18px rgba(139,92,246,0.5); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-ghost {
  width: 100%;
  padding: 8px 10px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  border-radius: 8px;
  font-size: 12px;
  cursor: pointer;
}
.btn-ghost:hover:not(:disabled) { background: rgba(255,255,255,0.04); color: var(--text-primary); }
.btn-ghost:disabled { opacity: 0.4; cursor: not-allowed; }

/* Main 3-column layout */
.builder-main {
  flex: 1;
  display: grid;
  grid-template-columns: 240px 1fr 1fr;
  min-height: 0;
}

.file-explorer {
  display: flex; flex-direction: column;
  border-right: 1px solid var(--border);
  background: rgba(10, 12, 22, 0.5);
  min-height: 0;
}
.explorer-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px;
  font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
}
.icon-mini {
  width: 24px; height: 24px;
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-secondary);
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
}
.icon-mini:hover { background: rgba(139,92,246,0.12); color: #c4b5fd; border-color: var(--border); }
.file-tree { flex: 1; overflow-y: auto; padding: 6px; }
.empty-hint { padding: 20px 12px; color: var(--text-secondary); font-size: 12px; text-align: center; line-height: 1.5; }
.file-item {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px;
  font-family: var(--font-mono); font-size: 12.5px;
  color: var(--text-secondary);
  border-radius: 6px;
  cursor: pointer;
  user-select: none;
}
.file-item:hover { background: rgba(255,255,255,0.04); color: var(--text-primary); }
.file-item.active { background: rgba(139,92,246,0.16); color: #e9d5ff; }
.file-item .file-ext { font-size: 10px; opacity: 0.7; }
.file-item .file-del {
  margin-left: auto;
  background: transparent; border: none; color: inherit;
  opacity: 0; cursor: pointer; font-size: 14px;
}
.file-item:hover .file-del { opacity: 0.6; }
.file-item .file-del:hover { opacity: 1; color: #fca5a5; }
.explorer-footer { padding: 10px; border-top: 1px solid var(--border); }

/* Editor */
.editor-pane {
  display: flex; flex-direction: column;
  border-right: 1px solid var(--border);
  min-height: 0;
}
.editor-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  background: rgba(10, 12, 22, 0.5);
}
.editor-path { font-family: var(--font-mono); font-size: 12px; color: var(--text-secondary); }
.editor-wrap {
  position: relative; flex: 1; min-height: 0;
  background: #0b0f1a;
}
.editor-wrap textarea, .editor-wrap pre {
  position: absolute; inset: 0;
  margin: 0; padding: 14px 16px;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.55;
  white-space: pre;
  overflow: auto;
  border: none; outline: none;
  background: transparent;
}
.editor-wrap textarea {
  color: transparent;
  caret-color: #c4b5fd;
  resize: none;
  z-index: 2;
  -webkit-text-fill-color: transparent;
}
.editor-wrap textarea::selection { background: rgba(139,92,246,0.35); -webkit-text-fill-color: white; color: white; }
.editor-highlight { z-index: 1; pointer-events: none; color: #e2e8f0; }
.editor-highlight code { font-family: var(--font-mono); font-size: 13px; line-height: 1.55; background: transparent !important; padding: 0 !important; }

/* Preview */
.preview-pane { display: flex; flex-direction: column; min-height: 0; }
.preview-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  background: rgba(10, 12, 22, 0.5);
  font-size: 12px; font-weight: 600; color: var(--text-secondary);
  text-transform: uppercase; letter-spacing: 0.08em;
}
.preview-actions { display: flex; gap: 4px; }
.preview-frame-wrap { position: relative; flex: 1; background: white; }
.preview-frame-wrap iframe {
  width: 100%; height: 100%; border: none; background: white;
}
.preview-overlay {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #0a0a14, #131329);
  color: var(--text-primary);
  z-index: 2;
  transition: opacity 0.2s;
}
.preview-overlay.hidden { opacity: 0; pointer-events: none; }
.overlay-content { text-align: center; max-width: 320px; padding: 20px; }
.overlay-icon {
  width: 56px; height: 56px; margin: 0 auto 16px;
  display: flex; align-items: center; justify-content: center;
  font-size: 28px;
  background: linear-gradient(135deg, #8b5cf6, #06b6d4);
  border-radius: 50%;
  box-shadow: 0 10px 30px rgba(139,92,246,0.4);
}
.overlay-title { font-size: 16px; font-weight: 600; margin-bottom: 6px; }
.overlay-sub { font-size: 13px; color: var(--text-secondary); line-height: 1.5; }
.spinner {
  width: 40px; height: 40px; margin: 0 auto 16px;
  border: 3px solid rgba(139,92,246,0.2);
  border-top-color: #a78bfa;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 1100px) {
  .builder-main { grid-template-columns: 200px 1fr 1fr; }
}
@media (max-width: 900px) {
  .builder-topbar { grid-template-columns: 1fr; }
  .builder-main { grid-template-columns: 1fr; grid-template-rows: 180px 1fr 1fr; }
  .file-explorer { border-right: none; border-bottom: 1px solid var(--border); }
}
