/* ===== 基础重置与全局 ===== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/* 主题 CSS 变量（默认明亮） */
:root,
:root[data-theme="light"] {
  --toolbar-bg: rgba(255, 255, 255, 0.92);
  --toolbar-text: #555;
  --toolbar-text-hover: #333;
  --panel-bg: #ffffff;
  --panel-text: #444;
  --panel-border: rgba(0, 0, 0, 0.08);
  --note-text: #444;
}

:root[data-theme="dark"] {
  --toolbar-bg: rgba(30, 30, 46, 0.92);
  --toolbar-text: #bbb;
  --toolbar-text-hover: #fff;
  --panel-bg: #2a2a3c;
  --panel-text: #ddd;
  --panel-border: rgba(255, 255, 255, 0.1);
  --note-text: #e8e8f0;
}

:root[data-theme="retro"] {
  --toolbar-bg: rgba(245, 236, 215, 0.92);
  --toolbar-text: #6b5b45;
  --toolbar-text-hover: #3a2e1e;
  --panel-bg: #faf3e3;
  --panel-text: #5a4a32;
  --panel-border: rgba(120, 90, 50, 0.15);
  --note-text: #5a4a32;
}

:root[data-theme="nature"] {
  --toolbar-bg: rgba(232, 245, 233, 0.92);
  --toolbar-text: #3d5c43;
  --toolbar-text-hover: #1e3d24;
  --panel-bg: #f1f8e9;
  --panel-text: #2e4d33;
  --panel-border: rgba(56, 120, 70, 0.15);
  --note-text: #2e4d33;
}

body {
  font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', sans-serif;
  overflow: hidden;
  height: 100vh;
  background: #faf8f5;
}

/* ===== 工具栏 ===== */
#toolbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 48px;
  display: flex;
  align-items: center;
  background: var(--toolbar-bg);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
  z-index: 1000;
  padding: 0 16px;
  gap: 4px;
  transition: background 0.3s ease;
}

#toolbar button {
  padding: 6px 14px;
  border-radius: 8px;
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 13px;
  color: var(--toolbar-text);
  transition: all 0.2s;
  white-space: nowrap;
}

#toolbar button:hover {
  background: rgba(0, 0, 0, 0.05);
  color: var(--toolbar-text-hover);
}

/* 自动滚动按钮激活态 */
#btn-auto-scroll.active {
  background: rgba(56, 142, 60, 0.15);
  color: #2e7d32;
  box-shadow: inset 0 0 0 1px rgba(56, 142, 60, 0.4);
}

#toolbar button:active {
  transform: scale(0.95);
}

#toolbar button:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  transform: none;
  background: transparent;
  color: #aaa;
}

#toolbar button:disabled:hover {
  background: transparent;
  color: #aaa;
}

.toolbar-divider {
  width: 1px;
  height: 24px;
  background: rgba(0, 0, 0, 0.1);
  margin: 0 6px;
}

/* ===== 画布容器 ===== */
#board-container {
  position: fixed;
  top: 80px;  /* 48px toolbar + 32px filter bar */
  left: 0;
  right: 0;
  bottom: 0;
  overflow: hidden;
  cursor: default;
}

/* ===== 画布网格层 ===== */
.board-grid {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
  z-index: 0;
}

/* ===== 便签卡片 ===== */
.note-card {
  position: absolute;
  width: 220px;
  min-height: 140px;
  border-radius: 12px;
  padding: 12px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06), 0 0 0 1px rgba(0, 0, 0, 0.04);
  transition: box-shadow 0.25s, transform 0.15s;
  z-index: 10;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.note-card:hover {
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12), 0 0 0 1px rgba(0, 0, 0, 0.08);
}

.note-card.dragging {
  z-index: 100;
  cursor: grabbing;
}

/* ===== 便签标题栏 ===== */
.note-title-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
}

/* ===== 拖拽手柄 ===== */
.drag-handle {
  cursor: grab;
  font-size: 16px;
  color: #ccc;
  user-select: none;
  padding: 0 2px;
}

.drag-handle:hover {
  color: #999;
}

/* ===== 便签标题输入 ===== */
.note-title-input {
  flex: 1;
  border: none;
  background: transparent;
  font-size: 14px;
  font-weight: 600;
  color: #444;
  outline: none;
  padding: 2px 4px;
}

.note-title-input:focus {
  background: rgba(255, 255, 255, 0.4);
  border-radius: 4px;
}

/* ===== 删除按钮 ===== */
.note-delete-btn {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: #bbb;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.note-delete-btn:hover {
  background: rgba(255, 0, 0, 0.08);
  color: #e55;
}

/* ===== 颜色选择按钮 ===== */
.note-color-btn {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: none;
  background: transparent;
  font-size: 13px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.note-color-btn:hover {
  background: rgba(0, 0, 0, 0.05);
}

/* ===== 便签颜色选择器 ===== */
.note-color-picker {
  position: absolute;
  top: 8px;
  right: 30px;
  display: flex;
  gap: 3px;
  background: white;
  padding: 4px;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
  z-index: 50;
  display: none;
}

.note-color-picker.open {
  display: flex;
}

/* ===== 颜色选项 ===== */
.color-dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid transparent;
}

.color-dot:hover {
  border-color: #aaa;
}

.color-dot.selected {
  border-color: #555;
}

/* ===== 便签内容 ===== */
.note-content {
  font-size: 13px;
  line-height: 1.55;
  color: #666;
  word-break: break-word;
  margin-bottom: 8px;
  cursor: text;
  min-height: 20px;
  outline: none;
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}

.note-content.collapsed {
  max-height: 48px;
  overflow: hidden;
}

/* ===== 折叠按钮 ===== */
.note-toggle-btn {
  display: block;
  width: 100%;
  padding: 4px;
  border: none;
  background: rgba(0, 0, 0, 0.03);
  color: #999;
  font-size: 12px;
  cursor: pointer;
  border-radius: 0 0 8px 8px;
}

.note-toggle-btn:hover {
  background: rgba(0, 0, 0, 0.06);
  color: #666;
}

/* ===== 调整手柄 ===== */
.note-resize-handle {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 16px;
  height: 16px;
  cursor: nwse-resize;
  background: linear-gradient(135deg, transparent 50%, rgba(0, 0, 0, 0.12) 50%);
  border-radius: 0 0 8px 0;
}

/* ===== 标签栏 ===== */
.note-tag-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
}

/* ===== 标签徽章 ===== */
.tag-badge {
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  white-space: nowrap;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}

/* ===== 分组容器 ===== */
.group-container {
  position: absolute;
  border: 2px dashed;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.15);
  z-index: 5;
  overflow: hidden;
  transition: height 0.3s ease;
}

/* ===== 分组标题栏 ===== */
.group-header {
  height: 32px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  border-radius: 14px 14px 0 0;
  cursor: move;
}

/* ===== 分组折叠按钮 ===== */
.group-toggle-btn {
  width: 20px;
  height: 20px;
  border-radius: 4px;
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 12px;
  color: #888;
}

.group-toggle-btn:hover {
  background: rgba(0, 0, 0, 0.05);
}

/* ===== 分组标题输入 ===== */
.group-title-input {
  flex: 1;
  border: none;
  background: transparent;
  font-size: 13px;
  font-weight: 500;
  color: #555;
  outline: none;
}

/* ===== 分组删除按钮 ===== */
.group-delete-btn {
  width: 20px;
  height: 20px;
  border-radius: 4px;
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 13px;
  color: #aaa;
  line-height: 1;
  flex-shrink: 0;
}

.group-delete-btn:hover {
  background: rgba(220, 60, 60, 0.12);
  color: #d44;
}

/* ===== 子便签指示（有父级的便签） ===== */
.note-card.has-parent {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08), 0 0 0 2px rgba(0, 120, 255, 0.15);
}

.note-card.has-children::after {
  content: "⤷";
  position: absolute;
  top: 4px;
  right: 28px;
  font-size: 12px;
  color: rgba(0, 120, 255, 0.6);
  pointer-events: none;
}

/* ===== 分组内容 ===== */
.group-body {
  padding: 8px;
}

/* ===== 右键菜单 ===== */
.context-menu {
  position: fixed;
  background: white;
  border-radius: 10px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.12);
  min-width: 160px;
  padding: 4px;
  z-index: 2000;
}

.context-menu-item {
  padding: 10px 16px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  color: #444;
}

.context-menu-item:hover {
  background: #f5f5f5;
}

/* ===== 标签抽屉遮罩 ===== */
.tag-drawer-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.2);
  z-index: 3000;
  display: none;
}

.tag-drawer-overlay.open {
  display: block;
}

/* ===== 标签抽屉 ===== */
.tag-drawer {
  position: fixed;
  right: 0;
  top: 0;
  height: 100%;
  width: 320px;
  background: white;
  box-shadow: -4px 0 24px rgba(0, 0, 0, 0.1);
  z-index: 3001;
  transform: translateX(100%);
  transition: transform 0.3s ease;
  display: flex;
  flex-direction: column;
}

.tag-drawer.open {
  transform: translateX(0);
}

/* ===== 标签抽屉标题 ===== */
.tag-drawer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px;
  border-bottom: 1px solid #eee;
}

.tag-drawer-header h3 {
  font-size: 16px;
  margin: 0;
}

/* ===== 标签抽屉关闭按钮 ===== */
.tag-drawer-close {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: #f0f0f0;
  cursor: pointer;
  font-size: 18px;
  color: #888;
}

.tag-drawer-close:hover {
  background: #e0e0e0;
}

/* ===== 标签抽屉 body ===== */
.tag-drawer-body {
  padding: 16px;
  flex: 1;
  overflow-y: auto;
}

/* ===== 标签输入表单 ===== */
.tag-add-form {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

/* ===== 标签路径输入 ===== */
.tag-path-input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  font-size: 13px;
  outline: none;
}

.tag-path-input:focus {
  border-color: #aac;
}

/* ===== 添加按钮 ===== */
.tag-add-btn {
  padding: 8px 16px;
  border: none;
  border-radius: 8px;
  background: #7c8;
  color: white;
  font-size: 13px;
  cursor: pointer;
}

.tag-add-btn:hover {
  background: #6b7;
}

/* ===== 标签列表 ===== */
.tag-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* ===== 标签列表项 ===== */
.tag-list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px;
  border-radius: 8px;
  background: #f9f9f9;
}

.tag-list-item .tag-badge {
  flex: 1;
}

.tag-remove-btn {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: #bbb;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.tag-remove-btn:hover {
  background: rgba(255, 0, 0, 0.08);
  color: #e55;
}

/* ===== 分组创建预览 ===== */
.group-create-preview {
  position: absolute;
  border: 2px dashed rgba(100, 150, 255, 0.6);
  background: rgba(100, 150, 255, 0.08);
  border-radius: 8px;
  pointer-events: none;
  z-index: 500;
}

/* ===== 便签 transform 层 ===== */
.board-transform-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 0;
  height: 0;
}

/* ===== 标签筛选栏 ===== */
#tag-filter-bar {
  position: fixed;
  top: 48px;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 16px;
  background: rgba(255,255,255,0.85);
  border-bottom: 1px solid rgba(0,0,0,0.04);
  overflow-x: auto;
  white-space: nowrap;
  z-index: 999;
  min-height: 32px;
}
.tag-filter-btn {
  padding: 4px 12px;
  border-radius: 12px;
  border: 1px solid #e0e0e0;
  background: #fff;
  font-size: 12px;
  color: #666;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
  flex-shrink: 0;
}
.tag-filter-btn:hover {
  border-color: #aaa;
  color: #333;
}
.tag-filter-btn.active {
  background: #6b8;
  color: #fff;
  border-color: #6b8;
}

/* ===== 主题设置面板 ===== */
.theme-panel {
  position: fixed;
  top: 56px;
  right: 16px;
  width: 300px;
  max-height: calc(100vh - 80px);
  overflow-y: auto;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.16);
  z-index: 2000;
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.theme-panel.hidden {
  opacity: 0;
  transform: translateY(-8px);
  pointer-events: none;
}

.tp-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--panel-border);
  font-size: 14px;
  font-weight: 600;
  color: var(--panel-text);
}

.tp-close {
  border: none;
  background: transparent;
  font-size: 18px;
  color: var(--panel-text);
  cursor: pointer;
  width: 26px;
  height: 26px;
  border-radius: 6px;
}

.tp-close:hover {
  background: rgba(0, 0, 0, 0.08);
}

.tp-body {
  padding: 12px 16px;
  color: var(--panel-text);
}

.tp-section {
  margin-bottom: 16px;
}

.tp-section h4 {
  font-size: 12px;
  font-weight: 600;
  color: var(--panel-text);
  margin-bottom: 8px;
  opacity: 0.8;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.tp-section h4 span {
  font-weight: 400;
  font-size: 12px;
  color: #6b8;
}

.tp-radio {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  font-size: 13px;
  cursor: pointer;
}

.tp-radio input {
  accent-color: #6b8;
}

.tp-hint {
  font-size: 11px;
  color: var(--panel-text);
  opacity: 0.55;
  margin-top: 4px;
}

.tp-section select {
  width: 100%;
  padding: 6px 10px;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  background: var(--panel-bg);
  color: var(--panel-text);
  font-size: 13px;
  outline: none;
}

.tp-section input[type="range"] {
  width: 100%;
  accent-color: #6b8;
}

/* 主题色板 */
.tp-swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tp-swatch {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  cursor: pointer;
  border: 2px solid transparent;
  transition: transform 0.15s ease, border-color 0.15s ease;
  position: relative;
}

.tp-swatch:hover {
  transform: scale(1.08);
}

.tp-swatch.active {
  border-color: #6b8;
}

.tp-swatch.active::after {
  content: "✓";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
}

/* 便签内容文字颜色跟随主题 */
.note-content {
  color: var(--note-text);
}
