/* ============================================
   studio.css — 可视化开发工作室样式
   左侧：需求面板（窄）
   右侧：预览面板（宽）
   ============================================ */

/* ---------- Design Tokens ---------- */
:root {
  --studio-bg: #0f1117;
  --studio-panel: #161922;
  --studio-surface: #1c2030;
  --studio-surface-hover: #232838;
  --studio-border: rgba(255,255,255,0.07);
  --studio-border-active: rgba(196,30,58,0.4);
  --studio-text: #e2e8f0;
  --studio-text-muted: #6b7280;
  --studio-accent: #c41e3a;
  --studio-accent-light: #e53e4e;
  --studio-gold: #c9922b;
  --studio-success: #27a644;
  --studio-error: #e53e3e;
  --studio-info: #3b82f6;
  --studio-shadow: 0 4px 20px rgba(0,0,0,0.4);
  --studio-r: 6px;
  --studio-r-md: 8px;
  --studio-r-lg: 10px;
}

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

html, body {
  height: 100%;
  overflow: hidden;
  font-family: 'Noto Sans SC', 'Inter', system-ui, sans-serif;
}

body {
  background: var(--studio-bg);
  color: var(--studio-text);
}

/* ---------- Studio Root ---------- */
.studio-root {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ---------- Header ---------- */
.studio-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 50px;
  padding: 0 14px;
  background: var(--studio-panel);
  border-bottom: 1px solid var(--studio-border);
  flex-shrink: 0;
  gap: 12px;
  z-index: 100;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 16px;
  flex: 0 0 auto;
}

.header-logo {
  display: flex;
  align-items: center;
  gap: 7px;
  font-weight: 600;
  font-size: 13px;
  color: var(--studio-text);
  white-space: nowrap;
}

.header-right {
  display: flex;
  gap: 8px;
  flex: 0 0 auto;
}

.header-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 12px;
  border: 1px solid var(--studio-border);
  border-radius: var(--studio-r);
  background: rgba(255,255,255,0.04);
  color: var(--studio-text);
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s;
}

.header-btn:hover { background: rgba(255,255,255,0.08); }

.header-btn.primary {
  background: var(--studio-accent);
  border-color: var(--studio-accent);
  color: white;
}

.header-btn.primary:hover { background: var(--studio-accent-light); }

/* ---------- Project Selector ---------- */
.project-selector {
  position: relative;
}

.project-dropdown-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--studio-border);
  border-radius: var(--studio-r);
  color: var(--studio-text);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
  min-width: 130px;
}

.project-dropdown-btn:hover {
  background: rgba(255,255,255,0.08);
  border-color: rgba(255,255,255,0.15);
}

.project-dropdown-btn .chevron {
  margin-left: auto;
  transition: transform 0.2s;
}

.project-dropdown-btn.open .chevron {
  transform: rotate(180deg);
}

.project-dropdown-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  min-width: 200px;
  background: var(--studio-panel);
  border: 1px solid var(--studio-border);
  border-radius: var(--studio-r-md);
  box-shadow: var(--studio-shadow);
  z-index: 1000;
  display: none;
  max-height: 300px;
  overflow-y: auto;
}

.project-dropdown-menu.show { display: block; }

.project-dropdown-menu::-webkit-scrollbar { width: 5px; }
.project-dropdown-menu::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 3px; }

.project-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 12px;
  cursor: pointer;
  transition: background 0.12s;
  border-bottom: 1px solid var(--studio-border);
}

.project-item:last-child { border-bottom: none; }
.project-item:hover { background: var(--studio-surface-hover); }
.project-item.active { background: rgba(196,30,58,0.12); }

.project-item-name { font-size: 12px; color: var(--studio-text); font-weight: 500; }
.project-item-date { font-size: 10px; color: var(--studio-text-muted); margin-top: 1px; }

.project-item-actions { display: flex; gap: 3px; opacity: 0; transition: opacity 0.12s; }
.project-item:hover .project-item-actions { opacity: 1; }

.project-action-btn {
  width: 22px; height: 22px;
  border: none; border-radius: 4px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.12s;
}

.project-action-btn.delete {
  background: rgba(239,68,68,0.15);
  color: #ef4444;
}

.project-action-btn.delete:hover { background: rgba(239,68,68,0.3); }

.project-dropdown-divider { height: 1px; background: var(--studio-border); margin: 3px 0; }

.project-create-new {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 9px 12px;
  cursor: pointer;
  color: var(--studio-accent);
  font-size: 12px;
  font-weight: 500;
  transition: background 0.12s;
}

.project-create-new:hover { background: rgba(196,30,58,0.08); }

.project-create-form { padding: 10px 12px; border-bottom: 1px solid var(--studio-border); }

.project-create-input {
  width: 100%; padding: 7px 9px;
  background: rgba(0,0,0,0.3);
  border: 1px solid var(--studio-border);
  border-radius: var(--studio-r);
  color: var(--studio-text); font-size: 12px;
  outline: none; transition: border-color 0.15s;
}

.project-create-input:focus { border-color: var(--studio-accent); }
.project-create-input::placeholder { color: var(--studio-text-muted); }

.project-create-btns { display: flex; gap: 6px; margin-top: 7px; }
.project-create-btns button { flex: 1; padding: 5px 0; border: none; border-radius: 4px; font-size: 11px; cursor: pointer; transition: all 0.12s; }

.btn-create-confirm { background: var(--studio-accent); color: white; }
.btn-create-confirm:hover { background: var(--studio-accent-light); }
.btn-create-cancel { background: rgba(255,255,255,0.06); color: var(--studio-text-muted); }
.btn-create-cancel:hover { background: rgba(255,255,255,0.1); }

/* ---------- Workspace ---------- */
.studio-workspace {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ---------- Left: Demand Panel ---------- */
.demand-panel {
  width: 320px;
  flex-shrink: 0;
  background: var(--studio-panel);
  border-right: 1px solid var(--studio-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.demand-project-section {
  padding: 16px 14px 12px;
  border-bottom: 1px solid var(--studio-border);
  flex-shrink: 0;
}

.section-label {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--studio-text-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 10px;
}

.project-select-area {
  display: flex;
  gap: 8px;
  align-items: center;
}

.project-select {
  flex: 1;
  padding: 7px 10px;
  background: var(--studio-surface);
  border: 1px solid var(--studio-border);
  border-radius: var(--studio-r);
  color: var(--studio-text);
  font-size: 12px;
  font-family: inherit;
  outline: none;
  cursor: pointer;
  transition: border-color 0.15s;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='11' height='11' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
}

.project-select:focus { border-color: var(--studio-accent); }
.project-select option { background: var(--studio-panel); color: var(--studio-text); }

.btn-confirm-project {
  padding: 7px 12px;
  background: var(--studio-accent);
  border: none;
  border-radius: var(--studio-r);
  color: white;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s;
  font-family: inherit;
}

.btn-confirm-project:hover { background: var(--studio-accent-light); }
.btn-confirm-project:disabled { opacity: 0.4; cursor: not-allowed; }

.project-hint {
  margin-top: 8px;
  font-size: 11px;
  color: var(--studio-text-muted);
  line-height: 1.5;
}

.demand-divider {
  padding: 8px 14px;
  background: rgba(196,30,58,0.06);
  border-bottom: 1px solid rgba(196,30,58,0.1);
  font-size: 11px;
  color: var(--studio-text-muted);
  flex-shrink: 0;
}

.demand-divider strong { color: var(--studio-text); }

.selected-element-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  background: rgba(196,30,58,0.1);
  border-bottom: 1px solid rgba(196,30,58,0.2);
  flex-shrink: 0;
  gap: 8px;
  animation: slideDown 0.2s ease;
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}

.element-info {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
}

.element-tag {
  font-family: 'JetBrains Mono', monospace;
  background: var(--studio-accent);
  color: white;
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 10px;
}

.element-selector {
  font-family: 'JetBrains Mono', monospace;
  color: var(--studio-text-muted);
  font-size: 11px;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.clear-sel-btn {
  width: 22px; height: 22px;
  border: none; border-radius: 4px;
  background: rgba(239,68,68,0.15);
  color: #ef4444;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.12s;
  flex-shrink: 0;
}

.clear-sel-btn:hover { background: #ef4444; color: white; }

.demand-input-section {
  flex: 1;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: hidden;
}

.demand-textarea {
  flex: 1;
  width: 100%;
  padding: 10px 12px;
  background: var(--studio-surface);
  border: 1px solid var(--studio-border);
  border-radius: var(--studio-r-md);
  color: var(--studio-text);
  font-size: 12px;
  font-family: inherit;
  line-height: 1.6;
  resize: none;
  outline: none;
  transition: border-color 0.15s;
  min-height: 120px;
}

.demand-textarea:focus { border-color: var(--studio-accent); }
.demand-textarea::placeholder { color: var(--studio-text-muted); }

.btn-send-demand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 10px;
  background: var(--studio-accent);
  border: none;
  border-radius: var(--studio-r-md);
  color: white;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
  flex-shrink: 0;
}

.btn-send-demand:hover { background: var(--studio-accent-light); }
.btn-send-demand:disabled { opacity: 0.5; cursor: not-allowed; }

.demand-footer {
  padding: 10px 14px;
  border-top: 1px solid var(--studio-border);
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 11px;
  color: var(--studio-text-muted);
  flex-shrink: 0;
}

.status-indicator {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--studio-info);
  flex-shrink: 0;
}

.status-indicator.success { background: var(--studio-success); }
.status-indicator.error { background: var(--studio-error); }
.status-indicator.loading { background: var(--studio-gold); }

@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Right: Preview Panel ---------- */
.preview-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--studio-bg);
  position: relative;
}

.preview-empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--studio-text-muted);
}

.empty-icon {
  opacity: 0.15;
  color: var(--studio-accent);
}

.empty-title { font-size: 16px; font-weight: 600; color: var(--studio-text); opacity: 0.6; }
.empty-desc { font-size: 12px; }

.preview-wrapper {
  flex: 1;
  overflow: hidden;
  background: #ffffff;
}

#previewFrame {
  width: 100%;
  height: 100%;
  border: none;
  background: white;
}

/* ---------- Loading Overlay ---------- */
.loading-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(22,33,62,0.95);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  z-index: 9999;
  transition: opacity 0.3s;
}

.loading-spinner {
  width: 32px; height: 32px;
  border: 3px solid rgba(196,30,58,0.2);
  border-top-color: #c41e3a;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.loading-text { font-size: 12px; color: var(--studio-text-muted); }

/* ---------- Scrollbar ---------- */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.08); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.15); }