/* ================== 颜色与变量 ================== */
:root {
  --bg: #ffffff;
  --bg-soft: #f7f9fc;
  --bg-tree: #fafbfc;
  --border: #e3e8ef;
  --border-strong: #c9d3df;
  --text: #1f2937;
  --text-soft: #6b7280;
  --text-faint: #9aa3af;
  --primary: #3b6ea5;
  --primary-hover: #2f5a8a;
  --primary-soft: #e8f0fa;
  --selected: #dce8f5;
  --selected-strong: #c2d6ee;
  --danger: #c75450;
  --danger-soft: #fbecec;
  --success: #4a8a72;
  --success-soft: #ecf5f1;
  --warn: #b48231;
  --warn-soft: #f7f1e3;
  --shadow: 0 2px 8px rgba(31, 41, 55, 0.06);
  --radius: 4px;
}

/* ================== 基础重置 ================== */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  display: grid;
  grid-template-rows: 56px 1fr;
  overflow: hidden;
}

button, input, textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

input, textarea {
  outline: none;
}

/* ================== 顶部工具栏 ================== */
#toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
  background: var(--bg-soft);
  border-bottom: 1px solid var(--border);
  height: 56px;
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.toolbar-label {
  font-size: 12px;
  color: var(--text-soft);
  white-space: nowrap;
}

.toolbar-sep {
  width: 1px;
  height: 24px;
  background: var(--border);
  margin: 0 4px;
}

.toolbar-spacer { flex: 1; }

/* ================== 输入框 ================== */
.input {
  height: 32px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

#input-basename { width: 220px; }
.input-count { width: 72px; }

/* ================== 按钮 ================== */
.btn {
  height: 32px;
  padding: 0 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  white-space: nowrap;
}

.btn:hover {
  background: var(--bg-soft);
  border-color: var(--primary);
  color: var(--primary);
}

.btn:active { transform: translateY(1px); }

.btn-primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.btn-primary:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
  color: #fff;
}

.btn-ghost {
  border-color: transparent;
  background: transparent;
  color: var(--text-soft);
}

.btn-ghost:hover {
  background: var(--bg-tree);
  color: var(--danger);
  border-color: transparent;
}

/* ================== 主体工作区 ================== */
#workspace {
  display: grid;
  grid-template-columns: 320px 1fr;
  overflow: hidden;
  min-height: 0;
}

/* ================== 左侧文件树 ================== */
#tree-panel {
  background: var(--bg-tree);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 10px 14px 8px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  background: var(--bg-soft);
}

.panel-hint {
  font-size: 11px;
  font-weight: 400;
  color: var(--text-faint);
}

#tree-root {
  flex: 1;
  overflow: auto;
  padding: 6px 0 16px;
}

.tree-empty {
  padding: 24px 16px;
  color: var(--text-faint);
  font-size: 12px;
  text-align: center;
  line-height: 1.7;
}

.tree-node {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 14px 4px calc(var(--depth, 0) * 16px + 8px);
  cursor: pointer;
  user-select: none;
  font-size: 13px;
  line-height: 1.5;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tree-node:hover { background: var(--bg-soft); }

.tree-node--selected {
  background: var(--selected) !important;
  color: var(--primary);
  font-weight: 500;
}

.tree-node__icon {
  width: 18px;
  text-align: center;
  font-size: 13px;
  flex-shrink: 0;
}

.tree-node__caret {
  width: 12px;
  text-align: center;
  color: var(--text-faint);
  font-size: 10px;
  flex-shrink: 0;
  transition: transform 0.1s;
}

.tree-node__caret.is-leaf { visibility: hidden; }

.tree-node--folder.collapsed .tree-node__caret {
  transform: rotate(-90deg);
}

.tree-node__name {
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}

.tree-node--drag-over {
  background: var(--primary-soft) !important;
  outline: 1px dashed var(--primary);
  outline-offset: -1px;
}

/* ================== 右侧编辑区 ================== */
#editor-panel {
  display: grid;
  grid-template-rows: 40px 28px 1fr;
  min-height: 0;
  overflow: hidden;
}

.editor-header {
  display: flex;
  align-items: center;
  padding: 0 18px;
  background: var(--bg-soft);
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  color: var(--text);
  font-weight: 500;
}

.editor-header.is-empty {
  color: var(--text-faint);
  font-weight: 400;
  font-style: italic;
}

.editor-stats {
  display: flex;
  align-items: center;
  padding: 0 18px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-soft);
  font-variant-numeric: tabular-nums;
}

.editor-textarea {
  border: none;
  resize: none;
  padding: 14px 18px;
  background: var(--bg);
  color: var(--text);
  font-family: Menlo, Consolas, "Courier New", monospace;
  font-size: 13px;
  line-height: 1.6;
  width: 100%;
  height: 100%;
  display: block;
}

.editor-textarea:focus {
  background: #fdfdfe;
}

.editor-textarea:disabled {
  background: var(--bg-soft);
  color: var(--text-faint);
  cursor: not-allowed;
}

.editor-textarea::placeholder {
  color: var(--text-faint);
}

/* ================== Toast 提示 ================== */
.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  max-width: 360px;
  padding: 10px 16px;
  border-radius: var(--radius);
  background: var(--text);
  color: #fff;
  font-size: 13px;
  box-shadow: var(--shadow);
  z-index: 1000;
  animation: toast-in 0.2s ease-out;
}

.toast--success { background: var(--success); }
.toast--error { background: var(--danger); }
.toast--warn { background: var(--warn); }

.toast.is-leaving {
  animation: toast-out 0.2s ease-in forwards;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes toast-out {
  from { opacity: 1; }
  to   { opacity: 0; transform: translateY(8px); }
}

/* ================== 文件树空态 ================== */
.tree-empty-icon {
  font-size: 28px;
  margin-bottom: 8px;
  opacity: 0.4;
}
