:root{
  --bg: #f7f5fc;
  --sidebar-bg: #fcfbff;
  --card: #ffffff;
  --border: #ece6f6;
  --text: #322f3d;
  --muted: #9c95ad;
  --accent: #8a79e8;
  --accent-soft: #efeafd;
  --shadow: 0 1px 3px rgba(60,40,90,.06), 0 6px 18px rgba(60,40,90,.06);
  --radius: 12px;
}

*{ box-sizing: border-box; }
html,body{ height:100%; margin:0; }
body{
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

#app{ display:flex; height:100vh; overflow:hidden; position:relative; }

/* ---------- 侧边栏 ---------- */
#sidebar{
  width: 264px;
  flex: 0 0 264px;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display:flex;
  flex-direction:column;
}
.sidebar-top{ padding: 18px 16px 12px; border-bottom: 1px solid var(--border); }
.app-title{ font-size: 17px; font-weight: 700; display:flex; align-items:center; gap:8px; margin-bottom: 14px; }
.app-logo{ font-size: 20px; display:inline-flex; align-items:center; }
.global-search{
  display:flex; align-items:center; gap:8px;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 10px; padding: 8px 10px;
}
.global-search .gs-icon{ font-size: 13px; opacity:.6; }
.global-search input{ border:none; background:transparent; outline:none; width:100%; font-size:13px; color:var(--text); }

.category-list{ flex:1; overflow-y:auto; padding: 10px 8px; }

.sidebar-footer{
  display:flex; gap:8px; padding: 10px 12px;
  border-top: 1px solid var(--border); background: var(--sidebar-bg);
}
.sidebar-act{
  flex:1; padding: 9px 0; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); border-radius: 9px;
  font-size: 13px; cursor: pointer; transition: background .15s, border-color .15s;
}
.sidebar-act:hover{ background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

.category-item{
  display:flex; align-items:center; gap:6px;
  padding: 9px 8px; border-radius: 10px; cursor:pointer;
  user-select:none; transition: background .15s;
}
.category-item:hover{ background: var(--bg); }
.category-item.active{ background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.category-item.dragging{ opacity:.4; }

.cat-controls{ display:flex; gap:2px; opacity:.22; transition: opacity .15s; }
.category-item:hover .cat-controls{ opacity:.7; }
.cat-controls button{
  width:18px; height:18px; line-height:1; border:none; background:transparent;
  color: var(--muted); cursor:pointer; font-size:15px; border-radius:5px;
  display:flex; align-items:center; justify-content:center;
}
.cat-controls button:hover{ background: rgba(0,0,0,.06); color: var(--text); }

.cat-grip{
  flex:0 0 auto; width:16px; text-align:center; cursor:grab;
  color: var(--muted); font-size:14px; opacity:.28; user-select:none;
  touch-action:none; -webkit-user-select:none;
}
.category-item:hover .cat-grip{ opacity:.6; }
.cat-grip:active{ cursor:grabbing; }
.cat-placeholder{
  border:1px dashed var(--accent); border-radius:10px;
  background: var(--accent-soft); margin:2px 0;
}
.cat-dragging-clone{
  background: var(--card); border:1px solid var(--accent);
  border-radius:10px; opacity:.96;
}
.cat-dragging-clone .cat-grip{ opacity:.7; }

.cat-icon{ font-size: 17px; width:24px; text-align:center; cursor:pointer; flex:0 0 24px; }
.cat-icon-img{ width:22px; height:22px; object-fit:contain; border-radius:5px; flex:0 0 24px; cursor:pointer; display:block; }
.cat-name{ flex:1; font-size:14px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.cat-rename{ flex:1; font-size:14px; border:1px solid var(--accent); border-radius:6px; padding:3px 6px; outline:none; }

.category-add{
  margin-top:6px; padding:9px 10px; border-radius:10px; cursor:pointer;
  color: var(--muted); font-size:13px; border: 1px dashed var(--border);
}
.category-add:hover{ color: var(--accent); border-color: var(--accent); }

/* ---------- 主区域 ---------- */
#main{ flex:1; overflow-y:auto; }
.page-head{
  display:flex; align-items:center; justify-content:space-between;
  padding: 18px 26px; position: sticky; top:0; background: var(--bg);
  z-index: 5; border-bottom: 1px solid var(--border);
}
.page-title{ display:flex; align-items:center; gap:10px; font-size:18px; font-weight:700; }
.page-icon{ font-size:20px; }
.page-icon img.cat-icon-img{ width:22px; height:22px; object-fit:contain; border-radius:5px; vertical-align:middle; }
.page-name{ font-weight:700; }
.page-title .q{ color: var(--accent); }
.cat-switch{
  display:inline-flex; align-items:center; gap:4px; max-width:46vw;
  background:transparent; border:1px solid transparent; border-radius:9px;
  padding:3px 7px; cursor:pointer; color: var(--text); font-size:18px; font-weight:700;
  transition: background .15s, border-color .15s;
}
.cat-switch:hover{ background: var(--accent-soft); border-color: var(--border); }
.cat-switch .page-name{ overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.cat-switch .caret{ font-size:12px; opacity:.55; font-weight:400; }
.cat-switcher-panel{
  position: fixed; z-index:120; background:#fff; border:1px solid var(--border);
  border-radius:11px; padding:6px; width:210px; max-height:60vh; overflow-y:auto;
  box-shadow:0 8px 26px rgba(40,30,70,.18);
}
.cat-switcher-panel.hidden{ display:none; }
.sw-item{
  display:flex; align-items:center; gap:8px; width:100%;
  border:none; background:transparent; cursor:pointer; border-radius:8px;
  padding:8px 9px; text-align:left; color: var(--text); font-size:14px;
}
.sw-item:hover{ background: var(--accent-soft); }
.sw-ico{ width:20px; height:20px; flex:0 0 20px; display:flex; align-items:center; justify-content:center; font-size:16px; }
.sw-ico img{ width:20px; height:20px; object-fit:contain; border-radius:4px; }
.sw-name{ flex:1; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.page-tools{ display:flex; align-items:center; gap:10px; }
.btn-bg{
  border:1px solid var(--border); background:#fff; color: var(--muted);
  border-radius:9px; padding:7px 11px; cursor:pointer; font-size:12.5px;
  display:flex; align-items:center; gap:5px; font-weight:600; margin-left:4px;
}
.btn-bg:hover{ color: var(--accent); border-color: var(--accent); }
.btn-bg-clear{
  border:1px solid var(--border); background:#fff; color: var(--muted);
  border-radius:9px; padding:7px 10px; cursor:pointer; font-size:12.5px; font-weight:600;
}
.btn-bg-clear:hover{ color:#e5484d; border-color:#e5484d; }
.cat-search{
  border:1px solid var(--border); background:#fff; border-radius:9px;
  padding:8px 12px; font-size:13px; outline:none; width:200px;
}
.cat-search:focus{ border-color: var(--accent); }
.btn-add{
  border:none; background: var(--accent); color:#fff; font-weight:600;
  padding:9px 14px; border-radius:9px; cursor:pointer; font-size:13px;
}
.btn-add:hover{ filter: brightness(1.05); }

.notes-wrap{ padding: 22px 26px 60px; }
.notes-list{ display:flex; flex-direction:column; gap:16px; max-width: 760px; margin:0 auto; }
.empty{ color: var(--muted); text-align:center; padding:60px 0; font-size:14px; }

/* ---------- 便签 ---------- */
.note{
  background: var(--card); border:1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 12px 14px 14px; position:relative;
}
.note-source{
  font-size:12px; color: var(--accent); background: var(--accent-soft);
  display:inline-block; padding:3px 9px; border-radius:20px; margin-bottom:8px;
}
.note-head{ display:flex; align-items:center; gap:8px; margin-bottom:6px; }
.note-number{
  width:46px; border:1px solid var(--border); border-radius:7px;
  padding:3px 6px; font-size:13px; text-align:center; color: var(--accent);
  font-weight:700; outline:none;
}
.note-number:focus{ border-color: var(--accent); }
.note-del{
  margin-left:auto; border:none; background:transparent; color: var(--muted);
  font-size:18px; cursor:pointer; width:26px; height:26px; border-radius:7px;
  display:flex; align-items:center; justify-content:center;
}
.note-del:hover{ background:#fff0f0; color:#e5484d; }
.note-content{
  min-height: 44px; font-size:14.5px; line-height:1.7; outline:none;
  padding: 6px 8px; border-radius:8px; color: var(--text);
  word-break: break-word;
}
.note-content:focus{ background:#fafbff; }
.comment-highlight{ background: #fff6cc; border-radius:3px; }
.comment-badge{
  font-size:10px; color:#fff; background: var(--accent);
  border-radius:9px; padding:0 5px; margin-left:1px; cursor:pointer;
  vertical-align: super; font-weight:700; line-height:1.4; position:relative; top:-2px;
}

/* ---------- 选区工具栏 ---------- */
.selection-toolbar{
  position: fixed; z-index: 50; display:flex; align-items:center; gap:2px;
  background:#2b2f38; border-radius:10px; padding:5px; box-shadow:0 6px 20px rgba(0,0,0,.25);
}
.selection-toolbar.hidden{ display:none; }
.selection-toolbar button{
  border:none; background:transparent; color:#fff; cursor:pointer;
  min-width:30px; height:30px; border-radius:7px; font-size:14px;
  display:flex; align-items:center; justify-content:center; padding:0 6px;
}
.selection-toolbar button:hover{ background: rgba(255,255,255,.16); }
.selection-toolbar .act-a{ font-weight:700; color:#ffd54f; }
.selection-toolbar .act-fill{ color:#90caf9; }
.comment-input{ display:flex; align-items:center; gap:4px; padding-left:4px; }
.comment-input input{
  background:#fff; border:none; border-radius:6px; padding:5px 8px;
  font-size:13px; outline:none; width:140px; color:#2b2f38;
}
.comment-input button{
  background: var(--accent); color:#fff; font-weight:600;
}

/* ---------- 颜色面板 ---------- */
.color-palette{
  position: fixed; z-index: 51; background:#fff; border:1px solid var(--border);
  border-radius:10px; padding:8px; display:grid; grid-template-columns:repeat(4,1fr);
  gap:6px; box-shadow:0 6px 20px rgba(0,0,0,.18);
}
.color-palette.hidden{ display:none; }
.color-palette .swatch{ width:26px; height:26px; border-radius:6px; border:1px solid rgba(0,0,0,.08); cursor:pointer; }
.color-palette .swatch:hover{ transform: scale(1.12); }

/* ---------- 图标上传面板 ---------- */
.icon-picker{
  position: fixed; z-index: 110; background:#fff; border:1px solid var(--border);
  border-radius:10px; padding:14px; width:188px; box-shadow:0 6px 20px rgba(0,0,0,.18);
  display:flex; flex-direction:column; align-items:center; gap:10px;
}
.icon-picker.hidden{ display:none; }
.ip-title{ font-size:13px; color: var(--muted); font-weight:600; }
.ip-preview{
  width:66px; height:66px; border-radius:10px; display:flex; align-items:center; justify-content:center;
  background-image:
    linear-gradient(45deg,#eef1f5 25%,transparent 25%),
    linear-gradient(-45deg,#eef1f5 25%,transparent 25%),
    linear-gradient(45deg,transparent 75%,#eef1f5 75%),
    linear-gradient(-45deg,transparent 75%,#eef1f5 75%);
  background-size:14px 14px; background-position:0 0,0 7px,7px -7px,-7px 0;
  border:1px solid var(--border); overflow:hidden;
}
.ip-preview img{ max-width:100%; max-height:100%; object-fit:contain; display:block; }
.ip-preview .ip-emoji{ font-size:30px; }
.ip-upload, .ip-default{
  width:100%; border:none; border-radius:8px; padding:8px; cursor:pointer; font-size:13px; font-weight:600;
}
.ip-upload{ background: var(--accent); color:#fff; }
.ip-upload:hover{ filter: brightness(1.05); }
.ip-default{ background: var(--bg); color: var(--muted); }
.ip-default:hover{ color: var(--text); }

/* ---------- 背景选择面板 ---------- */
.bg-picker{
  position: fixed; z-index: 52; background:#fff; border:1px solid var(--border);
  border-radius:10px; padding:12px; width:236px; box-shadow:0 6px 20px rgba(0,0,0,.18);
}
.bg-picker.hidden{ display:none; }
.bg-grid{ display:grid; grid-template-columns:repeat(4,1fr); gap:8px; margin-bottom:10px; }
.bg-swatch{
  display:flex; flex-direction:column; align-items:center; gap:4px;
  border:1px solid var(--border); background:#fff; border-radius:8px;
  padding:5px 2px; cursor:pointer;
}
.bg-swatch:hover{ border-color: var(--accent); }
.bg-swatch.active{ border-color: var(--accent); box-shadow:0 0 0 2px var(--accent-soft); }
.bg-swatch-prev{ width:100%; height:34px; border-radius:6px; border:1px solid var(--border); }
.bg-swatch-name{ font-size:11px; color: var(--muted); }
.bg-actions{ display:flex; gap:8px; }
.bg-actions .ip-upload, .bg-actions .ip-default{ width:auto; flex:1; }

/* ---------- 备注弹层 ---------- */
.comment-popup{
  position: fixed; z-index: 53; max-width: 240px;
  background: #fbfcfe; border:1px solid var(--border);
  border-radius:10px; padding:10px 12px; font-size:12.5px; line-height:1.6;
  color: #9aa3b2; box-shadow:0 6px 20px rgba(0,0,0,.12);
}
.comment-popup.hidden{ display:none; }

/* ---------- 移动端菜单按钮与遮罩 ---------- */
.menu-btn{
  display:none; border:none; background:transparent; color: var(--text);
  font-size:18px; cursor:pointer; width:30px; height:30px; border-radius:8px;
  align-items:center; justify-content:center; margin-right:2px;
}
.menu-btn:hover{ background: var(--accent-soft); }
.sidebar-overlay{
  display:none; position:fixed; inset:0; background:rgba(30,20,50,.28);
  z-index:90; opacity:0; transition: opacity .25s;
}
.sidebar-overlay.show{ display:block; opacity:1; }

/* ---------- 响应式：手机 ---------- */
@media (max-width: 760px){
  .menu-btn{ display:flex; }
  #sidebar{
    position:fixed; left:0; top:0; bottom:0; width:280px; max-width:80vw;
    transform: translateX(-100%); transition: transform .25s ease;
    z-index:100; box-shadow: 4px 0 24px rgba(40,30,70,.18);
    border-right:none;
  }
  #sidebar.open{ transform: translateX(0); }
  #main{ width:100vw; flex:none; }
  .page-head{ flex-wrap:wrap; gap:12px; padding:14px 16px; }
  .page-title{ font-size:16px; flex-wrap:wrap; gap:8px; max-width:100%; }
  .page-title .btn-bg, .page-title .btn-bg-clear{ font-size:12px; padding:5px 8px; }
  .page-tools{ width:100%; flex-wrap:wrap; gap:8px; }
  .cat-search{ flex:1 1 auto; width:auto; min-width:0; }
  .btn-add{ flex:0 0 auto; }
  .notes-wrap{ padding:14px 14px 40px; }
  .notes-list{ max-width:100%; gap:12px; }
  .note{ width:100%; min-width:0; }
  .note-content{ font-size:15px; }
  .selection-toolbar{ max-width:92vw; flex-wrap:wrap; }
  .bg-picker, .icon-picker{ left:14px !important; right:14px !important; width:auto; max-width:calc(100vw - 28px); }
}
