.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

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

.brand-mark {
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #fff;
  font-weight: 700;
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 6px;
}

.brand-title {
  font-weight: 600;
}

.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.workspace {
  flex: 1;
  min-height: 0;
  display: grid;
  gap: 10px;
  padding: 10px;
}

.workspace-4 {
  grid-template-columns: minmax(220px, 260px) minmax(300px, 0.85fr) minmax(520px, 1.8fr);
}

.workspace-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.panel-head-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.workspace-split {
  display: flex;
  flex: 1;
  min-height: 0;
  height: 100%;
}

.workspace-files-pane {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.workspace-preview-pane {
  flex: 1;
  min-height: 0;
  padding: 10px 12px;
}

.file-tree {
  width: min(200px, 32%);
  min-width: 140px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.file-tree-empty {
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.5;
  padding: 12px 8px;
  text-align: center;
}

.ws-root-label,
.file-tree-empty .ws-root {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  opacity: 0.85;
  margin-bottom: 8px;
  padding: 4px 8px;
  word-break: break-all;
  font-family: var(--font-mono, monospace);
}

.file-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  font-size: 12px;
  word-break: break-all;
}

.file-item:hover {
  background: var(--surface-2);
}

.file-item.active {
  border-color: var(--primary);
  background: rgba(236, 72, 153, 0.12);
}

.file-context-menu {
  position: fixed;
  z-index: 80;
  min-width: 118px;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.32);
}

.file-context-menu button {
  width: 100%;
  padding: 7px 9px;
  border-radius: 6px;
  text-align: left;
  font-size: 12px;
}

.file-context-menu button:hover {
  background: var(--surface-2);
}

.file-context-danger {
  color: var(--danger);
}

.file-editor-wrap {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.file-editor-head {
  padding: 8px 12px;
  font-size: 12px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.file-editor-area {
  flex: 1;
  min-height: 280px;
  border: none;
  border-radius: 0;
  resize: none;
  margin: 0;
}

.stack-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  background: transparent;
  border: none;
  overflow: visible;
}

.inner-panel {
  flex: 1;
  min-height: 0;
}

.stack-panel .editor-panel {
  flex: 1.2;
}

.stack-panel .preview-panel {
  flex: 0.8;
}

.stack-panel .preview-body .json-pane {
  min-height: 120px;
}

.stack-panel .editor-area {
  min-height: 140px;
}

.todo-panel .panel-body {
  padding: 10px;
}

@media (max-width: 1200px) {
  .workspace-4 {
    grid-template-columns: 1fr;
    overflow-y: auto;
  }

  body {
    overflow: auto;
  }

  .stack-panel,
  .chat-panel,
  .todo-panel {
    min-height: 360px;
  }
}

.panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.panel-head h2 {
  margin: 0;
  font-size: 15px;
}

.panel-body {
  padding: 12px;
}

@media (max-width: 1200px) {
  .workspace {
    grid-template-columns: 1fr;
    overflow-y: visible;
  }

  .panel {
    min-height: 320px;
  }
}

@media (max-width: 1200px) and (min-width: 760px) and (min-aspect-ratio: 4/3) {
  body {
    overflow: hidden;
  }

  .topbar {
    padding: 6px 8px;
    gap: 8px;
  }

  .brand-title {
    display: none;
  }

  .topbar-actions {
    gap: 5px;
  }

  .topbar-actions .btn,
  .settings-btn {
    min-height: 28px;
    padding: 4px 7px;
    font-size: 11px;
  }

  .workspace,
  .workspace-4 {
    grid-template-columns: minmax(170px, 0.72fr) minmax(250px, 0.95fr) minmax(330px, 1.35fr);
    gap: 7px;
    padding: 7px;
    overflow: hidden;
  }

  .panel {
    min-height: 0;
    border-radius: 8px;
  }

  .panel-head {
    min-height: 34px;
    padding: 6px 8px;
  }

  .panel-head h2 {
    font-size: 13px;
  }

  .panel-head-actions {
    gap: 5px;
  }

  .todo-panel .panel-body,
  .workspace-preview-pane {
    padding: 7px;
  }

  .file-tree {
    width: min(150px, 30%);
    min-width: 104px;
    padding: 6px;
  }

  .file-item {
    padding: 6px 7px;
    font-size: 11px;
  }

  .file-editor-head {
    padding: 6px 8px;
  }

  .file-editor-area {
    min-height: 0;
  }
}
