* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  font-family: "Microsoft YaHei", "PingFang SC", "Segoe UI", sans-serif;
  font-size: 13px;
  color: #222;
  overflow: hidden;
}

:root {
  --sidebar-width: 300px;
}

.app {
  display: flex;
  height: 100vh;
  width: 100%;
}

.sidebar {
  position: relative;
  width: var(--sidebar-width);
  min-width: 200px;
  max-width: 75vw;
  flex: 0 0 var(--sidebar-width);
  display: flex;
  flex-direction: column;
  background: #f0f0f0;
  border-right: 1px solid #b0b0b0;
  overflow: hidden;
}

.sidebar-resizer {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 8px;
  cursor: col-resize;
  z-index: 20;
  background: transparent;
  touch-action: none;
}

.sidebar-resizer:hover,
.sidebar-resizer.dragging {
  background: rgba(0, 102, 204, 0.35);
}

body.is-resizing,
body.is-resizing * {
  cursor: col-resize !important;
  user-select: none !important;
}

.resize-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  cursor: col-resize;
  touch-action: none;
}

.sidebar-header {
  background: linear-gradient(180deg, #e8e8e8 0%, #d4d4d4 100%);
  border-bottom: 1px solid #a8a8a8;
  flex-shrink: 0;
}

.tabs {
  display: flex;
}

.tab {
  flex: 1;
  padding: 8px 12px;
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 13px;
  color: #333;
  border-bottom: 2px solid transparent;
}

.tab:hover {
  background: rgba(255, 255, 255, 0.4);
}

.tab.active {
  background: #f0f0f0;
  border-bottom-color: #0066cc;
  font-weight: 600;
  color: #0066cc;
}

.panel {
  display: none;
  flex: 1;
  flex-direction: column;
  overflow: hidden;
}

.panel.active {
  display: flex;
}

/* ???? */
.tree-wrap {
  flex: 1;
  overflow: auto;
  padding: 6px 4px;
}

.tree ul {
  list-style: none;
  padding-left: 16px;
}

.tree > ul {
  padding-left: 4px;
}

.tree-item {
  user-select: none;
}

.tree-row {
  display: flex;
  align-items: center;
  padding: 3px 4px;
  border-radius: 3px;
  cursor: pointer;
  line-height: 1.4;
  min-width: 0;
  overflow: hidden;
  flex-wrap: nowrap;
}

.tree-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tree-row:hover {
  background: #dde8f7;
}

.tree-row.selected {
  background: #0066cc;
  color: #fff;
}

.tree-row.search-hit {
  background: #fff3cd;
}

.tree-row.search-hit.selected {
  background: #0066cc;
  color: #fff;
}

.tree-toggle {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  color: #666;
  margin-right: 2px;
}

.tree-toggle.empty {
  visibility: hidden;
}

.tree-icon {
  margin-right: 4px;
  flex-shrink: 0;
  font-size: 12px;
}

.tree-children.collapsed {
  display: none;
}

/* ???? */
.search-box {
  padding: 8px;
  background: #e8e8e8;
  border-bottom: 1px solid #ccc;
  flex-shrink: 0;
}

.search-box input {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid #aaa;
  border-radius: 3px;
  font-size: 13px;
  margin-bottom: 6px;
}

.search-box input:focus {
  outline: 2px solid #0066cc;
  border-color: #0066cc;
}

.search-actions {
  display: flex;
  gap: 6px;
}

.search-actions button {
  width: 100%;
  padding: 5px 10px;
  border: 1px solid #888;
  background: linear-gradient(180deg, #fafafa, #e0e0e0);
  border-radius: 3px;
  cursor: pointer;
  font-size: 12px;
}

.search-actions button:hover {
  background: linear-gradient(180deg, #fff, #e8e8e8);
}

.search-actions button.primary {
  background: linear-gradient(180deg, #4a9eff, #0066cc);
  color: #fff;
  border-color: #0055aa;
}

.search-actions button.primary:hover {
  background: linear-gradient(180deg, #5aadff, #0077dd);
}

.search-results {
  flex: 1;
  overflow: auto;
  padding: 6px 8px;
}

.search-summary {
  color: #666;
  font-size: 12px;
  margin-bottom: 8px;
  padding-bottom: 6px;
  border-bottom: 1px dashed #ccc;
}

.search-group {
  margin-bottom: 10px;
}

.search-group-title {
  font-weight: 600;
  color: #0066cc;
  margin-bottom: 4px;
  font-size: 12px;
}

.search-result-item {
  padding: 5px 6px;
  margin: 2px 0;
  border-radius: 3px;
  cursor: pointer;
  line-height: 1.35;
}

.search-result-item:hover {
  background: #dde8f7;
}

.search-result-item.selected {
  background: #0066cc;
  color: #fff;
}

.search-result-item.selected .title {
  color: #fff;
}

.search-result-item.selected mark {
  background: #ffeb3b;
  color: #222;
}

.search-result-item .title {
  color: #0066cc;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.search-result-item .snippet {
  font-size: 12px;
  color: #444;
  margin-top: 3px;
}

.search-result-item mark {
  background: #ffeb3b;
  padding: 0 1px;
}

.toast {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.82);
  color: #fff;
  padding: 8px 16px;
  border-radius: 4px;
  font-size: 13px;
  z-index: 2000;
  max-width: 90%;
  text-align: center;
  pointer-events: none;
}

.search-empty {
  color: #888;
  text-align: center;
  padding: 24px 12px;
}

/* ??????? */
.content {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #fff;
  min-width: 0;
}

.editor-badge {
  margin-left: 10px;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: normal;
  color: #fff;
  background: #c62828;
  border-radius: 3px;
  vertical-align: middle;
}

.editor-badge[hidden] {
  display: none;
}

.content-toolbar {
  height: 28px;
  background: #f5f5f5;
  border-bottom: 1px solid #ddd;
  display: flex;
  align-items: center;
  padding: 0 12px;
  font-size: 12px;
  color: #555;
  flex-shrink: 0;
}

.content-toolbar .title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.content-frame {
  flex: 1;
  border: none;
  width: 100%;
  background: #fff;
}

.welcome {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  color: #888;
  gap: 12px;
}

.welcome h2 {
  font-size: 18px;
  color: #444;
  font-weight: normal;
}

.welcome p {
  font-size: 13px;
}

.tree-toolbar {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 4px 8px;
  background: #e4e4e4;
  border-bottom: 1px solid #ccc;
  flex-shrink: 0;
  font-size: 11px;
  color: #555;
}

.tree-status {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tree-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  flex-shrink: 0;
}

.btn-tree {
  flex: 1 1 auto;
  min-width: 56px;
  padding: 3px 6px;
  font-size: 11px;
  border: 1px solid #999;
  background: linear-gradient(180deg, #fafafa, #e8e8e8);
  border-radius: 3px;
  cursor: pointer;
  color: #333;
}

.btn-tree:hover {
  background: linear-gradient(180deg, #fff, #f0f0f0);
  border-color: #0066cc;
  color: #0066cc;
}

.btn-tree.primary {
  background: linear-gradient(180deg, #4a9eff, #0066cc);
  color: #fff;
  border-color: #0055aa;
}

.btn-tree.primary:hover {
  background: linear-gradient(180deg, #5aadff, #0077dd);
  color: #fff;
}

.order-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.order-modal[hidden] {
  display: none !important;
}

.order-dialog {
  background: #fff;
  border-radius: 6px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.25);
  width: 100%;
  max-width: 420px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.order-dialog h3 {
  margin: 0;
  padding: 12px 14px 6px;
  font-size: 15px;
  font-weight: 600;
}

.order-hint {
  margin: 0;
  padding: 0 14px 10px;
  font-size: 12px;
  color: #666;
  line-height: 1.5;
}

.order-list {
  list-style: none;
  margin: 0;
  padding: 0 8px;
  overflow: auto;
  flex: 1;
}

.order-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 4px;
  border-bottom: 1px solid #eee;
}

.order-item-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.order-item-btns {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
}

.order-item-btns button {
  width: 28px;
  height: 26px;
  padding: 0;
  border: 1px solid #aaa;
  background: #f5f5f5;
  border-radius: 3px;
  cursor: pointer;
  font-size: 12px;
  line-height: 1;
}

.order-item-btns button:hover {
  background: #e8f0ff;
  border-color: #0066cc;
}

.order-actions {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid #ddd;
  background: #f5f5f5;
}

.order-actions .btn-tree {
  flex: 1;
}

.welcome .hint {
  font-size: 12px;
  color: #aaa;
}
