/* ==========================================================================
   应用外壳：顶栏 / 工作区 / 弹窗 / Toast / 启动画面
   ========================================================================== */

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  min-width: 900px;
  background: var(--bg);
}

/* ---------------------------- 顶栏 ---------------------------- */

#topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  height: var(--topbar-h);
  flex: none;
  padding: 0 12px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  position: relative;
  z-index: 50;
  user-select: none;
}

.topbar-left,
.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: none;
}
.topbar-center {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  min-width: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-right: 6px;
}
.brand-logo {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: linear-gradient(140deg, #6366f1, #8b5cf6 55%, #06b6d4);
  color: #fff;
  box-shadow: 0 3px 12px rgba(99, 102, 241, 0.35);
}
.brand-logo svg {
  width: 17px;
  height: 17px;
}
.brand-name {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.brand-version {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-faint);
  padding: 1px 5px;
  border: 1px solid var(--border);
  border-radius: 999px;
  margin-top: -6px;
}

.topbar-divider {
  width: 1px;
  height: 22px;
  background: var(--border);
  flex: none;
}

/* 工程名 + 保存状态 */
.project-meta {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
}
.project-name-input {
  width: 180px;
  height: 28px;
  padding: 0 7px;
  border: 1px solid transparent;
  border-radius: var(--radius-s);
  background: transparent;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  outline: none;
  transition:
    border-color 0.14s var(--ease),
    background 0.14s var(--ease),
    width 0.14s var(--ease);
}
.project-name-input:hover {
  background: var(--bg-elev);
}
.project-name-input:focus {
  width: 230px;
  background: var(--bg-inset);
  border-color: var(--accent);
}
.save-state {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--text-faint);
  white-space: nowrap;
  cursor: default;
}
.save-state .dot {
  width: 6px;
  height: 6px;
}
.save-state.is-saving .dot {
  animation: pulse-dot 1.1s infinite;
}
.save-state.is-error {
  color: #fca5a5;
}

@keyframes pulse-dot {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.3;
  }
}

/* Tab 导航 */
.tabs {
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 3px;
  border-radius: var(--radius-m);
  background: var(--bg-inset);
  border: 1px solid var(--border);
}
.tab {
  display: flex;
  align-items: center;
  gap: 7px;
  height: 30px;
  padding: 0 14px;
  border: none;
  border-radius: var(--radius-s);
  background: transparent;
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition:
    background 0.14s var(--ease),
    color 0.14s var(--ease);
}
.tab svg {
  opacity: 0.75;
}
.tab:hover {
  color: var(--text);
  background: var(--bg-hover);
}
.tab.active {
  background: var(--bg-elev);
  color: var(--text);
  box-shadow: var(--shadow-1);
}
.tab.active svg {
  color: var(--accent-hover);
  opacity: 1;
}
.tab-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--accent-weak);
  color: var(--accent-text);
  font-size: 10px;
  font-weight: 700;
}

/* 顶栏按钮与下拉 */
.topbar-right .btn {
  height: 30px;
}
.collab-slot {
  display: flex;
  align-items: center;
  gap: 6px;
}
.collab-slot:empty {
  display: none;
}

.dropdown {
  position: fixed;
  z-index: 400;
  min-width: 220px;
  padding: 5px;
  border: 1px solid var(--border);
  border-radius: var(--radius-m);
  background: var(--bg-elev);
  box-shadow: var(--shadow-2);
  animation: dropdown-in 0.13s var(--ease);
}
@keyframes dropdown-in {
  from {
    opacity: 0;
    transform: translateY(-4px) scale(0.99);
  }
  to {
    opacity: 1;
    transform: none;
  }
}
.dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border: none;
  border-radius: var(--radius-s);
  background: transparent;
  color: var(--text);
  font-size: 13px;
  text-align: left;
  cursor: pointer;
}
.dropdown-item:hover {
  background: var(--bg-hover);
}
.dropdown-item.danger {
  color: #fca5a5;
}
.dropdown-item.danger:hover {
  background: var(--danger-weak);
}
.dropdown-item svg {
  flex: none;
  color: var(--text-dim);
}
.dropdown-item.danger svg {
  color: #fca5a5;
}
.dropdown-item-body {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}
.dropdown-item-label {
  font-size: 13px;
  line-height: 1.3;
}
.dropdown-item-hint {
  font-size: 11px;
  color: var(--text-faint);
  line-height: 1.3;
}
.dropdown-sep {
  height: 1px;
  margin: 4px 6px;
  background: var(--border);
}
.dropdown-label {
  padding: 7px 10px 4px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--text-faint);
  text-transform: uppercase;
}

/* ---------------------------- 工作区 ---------------------------- */

#workspaces {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}
.workspace {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}
.workspace.active {
  display: flex;
}
/* 防止工作区模块自身的 display 规则（如 .builder-workspace）覆盖隐藏状态 */
.workspace:not(.active) {
  display: none !important;
}
.workspace-error {
  margin: auto;
  max-width: 560px;
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: var(--radius-m);
  background: var(--bg-panel);
  color: var(--danger);
  font-family: var(--font-code);
  font-size: 12px;
  line-height: 1.6;
  white-space: pre-wrap;
  overflow: auto;
}

.workspace-loading {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: auto;
  color: var(--text-dim);
  font-size: 13px;
}

/* ---------------------------- 弹窗 ---------------------------- */

#modal-root {
  position: fixed;
  inset: 0;
  z-index: 300;
  pointer-events: none;
}
.modal-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px;
  background: rgba(4, 6, 10, 0.55);
  backdrop-filter: blur(3px);
  pointer-events: auto;
  animation: overlay-in 0.14s var(--ease);
}
html[data-theme="light"] .modal-overlay {
  background: rgba(20, 30, 55, 0.32);
}
@keyframes overlay-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}
.modal-dialog {
  display: flex;
  flex-direction: column;
  width: min(520px, 100%);
  max-height: min(82vh, 900px);
  border: 1px solid var(--border);
  border-radius: var(--radius-l);
  background: var(--bg-elev);
  box-shadow: var(--shadow-2);
  pointer-events: auto;
  animation: dialog-in 0.16s var(--ease);
  overflow: hidden;
}
@keyframes dialog-in {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.985);
  }
  to {
    opacity: 1;
    transform: none;
  }
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex: none;
  padding: 15px 16px 12px 18px;
  border-bottom: 1px solid var(--border);
}
.modal-title {
  font-size: 15px;
  font-weight: 700;
}
.modal-close {
  flex: none;
}
.modal-body {
  padding: 16px 18px;
  overflow: auto;
  font-size: 13.5px;
  line-height: 1.65;
  color: var(--text-dim);
}
.modal-body strong {
  color: var(--text);
}
.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex: none;
  padding: 12px 16px 14px;
  border-top: 1px solid var(--border);
  background: var(--bg-panel);
}
.modal-message {
  color: var(--text-dim);
  line-height: 1.7;
  white-space: pre-wrap;
}
.modal-confirm-danger {
  color: var(--danger);
}

/* 帮助弹窗内容 */
.help-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
.help-section {
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-m);
  background: var(--bg-panel);
}
.help-section h4 {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 7px;
  font-size: 13px;
  color: var(--text);
}
.help-section ul {
  margin: 0;
  padding-left: 17px;
  color: var(--text-dim);
  font-size: 12px;
  line-height: 1.9;
}
.help-section kbd {
  margin: 0 1px;
}
.help-footer {
  margin-top: 14px;
  font-size: 12px;
  color: var(--text-faint);
  line-height: 1.7;
}
.help-footer a {
  color: var(--accent-hover);
}

/* ---------------------------- Toast ---------------------------- */

#toast-root {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 500;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 9px;
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  min-width: 220px;
  max-width: 400px;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-m);
  background: var(--bg-elev);
  box-shadow: var(--shadow-2);
  color: var(--text);
  font-size: 13px;
  line-height: 1.5;
  pointer-events: auto;
  animation: toast-in 0.18s var(--ease);
}
.toast.leaving {
  animation: toast-out 0.16s var(--ease) forwards;
}
@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: none;
  }
}
@keyframes toast-out {
  to {
    opacity: 0;
    transform: translateY(6px) scale(0.98);
  }
}
.toast-icon {
  flex: none;
  margin-top: 1px;
}
.toast-icon.is-success {
  color: var(--success);
}
.toast-icon.is-warn {
  color: var(--warn);
}
.toast-icon.is-error {
  color: var(--danger);
}
.toast-icon.is-info {
  color: var(--accent-hover);
}
.toast-body {
  flex: 1;
  min-width: 0;
  white-space: pre-wrap;
  word-break: break-word;
}
.toast-close {
  flex: none;
  opacity: 0.5;
}
.toast-close:hover {
  opacity: 1;
}

/* ---------------------------- 启动画面 ---------------------------- */

#boot-screen {
  position: fixed;
  inset: 0;
  z-index: 900;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  background:
    radial-gradient(900px 600px at 50% 18%, rgba(99, 102, 241, 0.16), transparent 70%),
    var(--bg);
  transition: opacity 0.25s var(--ease);
}
#boot-screen.fade-out {
  opacity: 0;
  pointer-events: none;
}
.boot-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.boot-logo {
  width: 58px;
  height: 58px;
  color: var(--accent-hover);
  filter: drop-shadow(0 6px 20px rgba(99, 102, 241, 0.45));
  animation: boot-float 2.6s ease-in-out infinite;
}
@keyframes boot-float {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-6px);
  }
}
.boot-title {
  margin-top: 8px;
  font-size: 24px;
  font-weight: 800;
  letter-spacing: 0.01em;
  background: linear-gradient(90deg, #c7d2fe, #818cf8 45%, #67e8f9);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.boot-sub {
  font-size: 12px;
  color: var(--text-faint);
  letter-spacing: 0.14em;
}
.boot-spinner {
  margin-top: 22px;
  width: 20px;
  height: 20px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
.boot-hint {
  margin-top: 10px;
  font-size: 12px;
  color: var(--text-faint);
}
.boot-error {
  max-width: 640px;
  max-height: 40vh;
  overflow: auto;
  margin: 10px 24px 0;
  padding: 14px 16px;
  border: 1px solid rgba(239, 68, 68, 0.45);
  border-radius: var(--radius-m);
  background: var(--danger-weak);
  color: #fecaca;
  font-family: var(--font-code);
  font-size: 12px;
  line-height: 1.6;
  white-space: pre-wrap;
}

/* 拖放导入提示 */
.drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 12, 18, 0.72);
  border: 3px dashed var(--accent);
  backdrop-filter: blur(3px);
  color: var(--accent-text);
  font-size: 17px;
  font-weight: 600;
  pointer-events: none;
}
