/* ============================================================
   云笔记记事本 · 设计 Token
   ============================================================ */
:root {
  /* 背景层级：浅灰画布 + 白色卡片 */
  --bg: #eef1f6;            /* 整体画布（浅灰） */
  --panel: #ffffff;         /* 卡片 / 面板（白） */
  --fill-soft: #f4f6fb;     /* 控件浅底 */

  /* 描边 */
  --border: #e6eaf2;
  --border-strong: #d6dce8;

  /* 文字 */
  --text: #1f2733;
  --text-strong: #0f172a;
  --muted: #8a94a6;
  --muted-2: #aab2c0;

  /* 品牌 / 语义色 */
  --primary: #3b6ef6;
  --primary-dark: #2f59d6;
  --primary-soft: #eaf0ff;
  --success: #1aa971;
  --success-dark: #15824f;
  --success-soft: #e6f7ef;
  --danger: #ef4444;
  --danger-soft: #fdecec;

  /* 圆角规范 */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-pill: 999px;

  /* 阴影分级 */
  --shadow-sm: 0 1px 3px rgba(17, 28, 45, .06), 0 1px 2px rgba(17, 28, 45, .04);
  --shadow-md: 0 6px 18px rgba(17, 28, 45, .08);
  --shadow-lg: 0 12px 32px rgba(17, 28, 45, .12);
  --shadow-primary: 0 6px 16px rgba(59, 110, 246, .35);
  --shadow-success: 0 6px 16px rgba(26, 169, 113, .30);

  /* 动效 */
  --t-fast: .14s ease;
  --t: .2s cubic-bezier(.4, 0, .2, 1);
}

/* ============================================================
   深色主题（深蓝科技风）
   仅在 [data-theme="dark"] 时覆盖变量
   ============================================================ */
[data-theme="dark"] {
  --bg: #0e1525;
  --panel: #182236;
  --fill-soft: #21304a;
  --border: #26344c;
  --border-strong: #344661;
  --text: #e7edf5;
  --text-strong: #ffffff;
  --muted: #93a0b4;
  --muted-2: #6c7a90;
  --primary: #4f8bff;
  --primary-dark: #3b6ef6;
  --primary-soft: #1d2c4d;
  --success: #2ecc8f;
  --success-dark: #1aa971;
  --success-soft: #14302a;
  --danger: #ff5c5c;
  --danger-soft: #3a2128;
}
[data-theme="dark"] ::-webkit-scrollbar-thumb { background: #344661; }
[data-theme="dark"] ::-webkit-scrollbar-thumb:hover { background: #45587a; }

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* 通用滚动条美化 */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb {
  background: #cfd6e2;
  border-radius: var(--radius-pill);
  border: 2px solid transparent;
  background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover { background: #b4bdcf; background-clip: content-box; }
::-webkit-scrollbar-track { background: transparent; }

/* ============================================================
   顶栏
   ============================================================ */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 22px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
  z-index: 5;
}

.search { flex: 1; position: relative; }
.search input {
  width: 100%;
  padding: 11px 14px 11px 40px;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  font-size: 14px;
  outline: none;
  background: var(--fill-soft) url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238a94a6' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><circle cx='11' cy='11' r='7'/><line x1='21' y1='21' x2='16.65' y2='16.65'/></svg>") no-repeat 14px center;
  color: var(--text);
  transition: border-color var(--t-fast), box-shadow var(--t-fast), background var(--t-fast);
}
.search input::placeholder { color: var(--muted-2); }
.search input:focus {
  border-color: var(--primary);
  background-color: var(--panel);
  box-shadow: 0 0 0 4px var(--primary-soft);
}

.actions { display: flex; gap: 10px; }

/* ============================================================
   按钮
   ============================================================ */
.btn {
  border: none;
  border-radius: var(--radius-md);
  padding: 10px 18px;
  font-size: 14px;
  cursor: pointer;
  transition: transform var(--t-fast), box-shadow var(--t-fast), background var(--t-fast), border-color var(--t-fast), color var(--t-fast);
  font-weight: 600;
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn.primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  box-shadow: var(--shadow-primary);
}
.btn.primary:hover { transform: translateY(-1px); box-shadow: 0 8px 22px rgba(59, 110, 246, .42); }
.btn.primary:active { transform: translateY(0); }
.btn.success {
  background: linear-gradient(135deg, var(--success), var(--success-dark));
  color: #fff;
  box-shadow: var(--shadow-success);
}
.btn.success:hover { transform: translateY(-1px); box-shadow: 0 8px 22px rgba(26, 169, 113, .38); }
.btn.success:active { transform: translateY(0); }
.btn.muted-btn {
  background: var(--panel);
  color: var(--muted);
  border: 1px solid var(--border);
}
.btn.muted-btn:hover { border-color: var(--border-strong); color: var(--text); transform: translateY(-1px); }
.btn.danger { background: var(--panel); color: var(--danger); border: 1px solid var(--danger); }
.btn.danger:hover { background: var(--danger); color: #fff; transform: translateY(-1px); }
.btn.ghost { background: var(--panel); color: var(--text); border: 1px solid var(--border); box-shadow: var(--shadow-sm); }
.theme-toggle { background: var(--panel); color: var(--text); border: 1px solid var(--border); box-shadow: var(--shadow-sm); }
.theme-toggle:hover { border-color: var(--border-strong); color: var(--text-strong); transform: translateY(-1px); }
.user-chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 7px 12px; border-radius: var(--radius-pill);
  background: var(--fill-soft); border: 1px solid var(--border);
  color: var(--text); font-size: 13px; font-weight: 600;
  white-space: nowrap; max-width: 140px; overflow: hidden; text-overflow: ellipsis;
}
.btn.admin-link {
  background: var(--primary-soft); color: var(--primary);
  border: 1px solid var(--primary-soft); text-decoration: none;
}
.btn.admin-link:hover { border-color: var(--primary); transform: translateY(-1px); }
.btn.logout-btn {
  background: var(--panel); color: var(--muted);
  border: 1px solid var(--border);
}
.btn.logout-btn:hover { border-color: var(--danger); color: var(--danger); transform: translateY(-1px); }
.btn.ghost:hover { border-color: var(--primary); color: var(--primary); transform: translateY(-1px); box-shadow: var(--shadow-md); }

/* ============================================================
   布局 & 分隔条
   ============================================================ */
.layout { flex: 1; display: flex; min-height: 0; }

/* 左右可拖动分隔条 */
.resizer {
  flex: 0 0 6px;
  width: 6px;
  cursor: col-resize;
  background: transparent;
  position: relative;
  transition: background var(--t-fast);
}
.resizer::before {
  content: "";
  position: absolute;
  inset: 0 2px;
  background: var(--border);
  border-radius: var(--radius-pill);
  transition: background var(--t-fast), box-shadow var(--t-fast);
}
.resizer:hover::before, .resizer.active::before {
  background: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-soft);
}
.resizer::after {
  content: "";
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  width: 3px; height: 26px;
  background: rgba(255, 255, 255, .9);
  border-radius: 2px;
  opacity: 0;
  transition: opacity var(--t-fast);
}
.resizer:hover::after, .resizer.active::after { opacity: 1; }
body.resizing { user-select: none; cursor: col-resize; }
body.resizing * { cursor: col-resize !important; }

/* ============================================================
   侧边栏（浅灰画布 + 白色卡片）
   ============================================================ */
.sidebar {
  width: 300px;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  box-shadow: 1px 0 0 rgba(17, 28, 45, .02);
  padding: 6px 0 10px;
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px 8px;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted-2);
  text-transform: uppercase;
  letter-spacing: 1.5px;
}
.count {
  background: var(--primary-soft);
  color: var(--primary);
  border-radius: var(--radius-pill);
  padding: 2px 9px;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0;
}

.category-list, .note-list { list-style: none; overflow-y: auto; }

/* 筛选方式切换 → 分段控件 */
.filter-tabs {
  display: flex;
  gap: 4px;
  padding: 10px 14px 12px;
  background: var(--fill-soft);
  margin: 0 12px;
  border-radius: var(--radius-md);
}
.filter-tab {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--muted);
  border-radius: var(--radius-sm);
  padding: 8px 0;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--t-fast);
  font-family: inherit;
}
.filter-tab:hover { color: var(--text); }
.filter-tab.active {
  background: var(--panel);
  color: var(--primary);
  box-shadow: var(--shadow-sm);
}

/* 日期筛选：常显月历 */
.date-panel { padding: 6px 14px 12px; }
.cal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.cal-title { font-size: 13px; font-weight: 700; color: var(--text-strong); }
.cal-nav {
  width: 28px; height: 28px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--panel);
  color: var(--text);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  transition: all var(--t-fast);
  box-shadow: var(--shadow-sm);
}
.cal-nav:hover { border-color: var(--primary); color: var(--primary); transform: translateY(-1px); }
.cal-week {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  text-align: center;
  font-size: 11px;
  color: var(--muted-2);
  margin-bottom: 4px;
  font-weight: 600;
}
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  row-gap: 4px;
  column-gap: 2px;
}
.cal-day {
  position: relative;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12.5px;
  color: var(--text);
  border-radius: var(--radius-sm);
  cursor: pointer;
  user-select: none;
  transition: background var(--t-fast), color var(--t-fast);
}
.cal-day:hover { background: var(--panel); box-shadow: var(--shadow-sm); }
.cal-day.other { color: var(--muted-2); }
.cal-day.today {
  border: 1.5px solid var(--primary);
  color: var(--primary);
  font-weight: 700;
  background: var(--primary-soft);
}
.cal-day.selected {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  font-weight: 700;
  box-shadow: var(--shadow-primary);
}
.cal-day.selected:hover { background: linear-gradient(135deg, var(--primary), var(--primary-dark)); opacity: .92; }
.cal-dot {
  position: absolute;
  bottom: 4px;
  left: 50%;
  transform: translateX(-50%);
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--primary);
  pointer-events: none;
}
.cal-day.selected .cal-dot { background: rgba(255, 255, 255, .9); }
.cal-day.today .cal-dot { background: var(--primary); }
.cal-foot {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}
.cal-foot-btn {
  flex: 1;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
  padding: 7px 0;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-family: inherit;
  transition: all var(--t-fast);
  box-shadow: var(--shadow-sm);
}
.cal-foot-btn:hover { border-color: var(--primary); color: var(--primary); transform: translateY(-1px); }

/* 分类列表 → 白色卡片 */
.category-list { padding: 2px 14px 8px; }
.category-list li {
  position: relative;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 13.5px;
  color: var(--text);
  cursor: pointer;
  margin-bottom: 6px;
  background: var(--panel);
  box-shadow: var(--shadow-sm);
  transition: transform var(--t-fast), box-shadow var(--t-fast), background var(--t-fast), color var(--t-fast);
  display: flex;
  align-items: center;
}
.category-list li::before {
  content: "";
  position: absolute;
  left: 0; top: 50%;
  transform: translateY(-50%);
  width: 3px; height: 0;
  border-radius: var(--radius-pill);
  background: var(--primary);
  transition: height var(--t-fast);
}
.category-list li:hover { transform: translateY(-1px); box-shadow: var(--shadow-md); }
.category-list li.active {
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 700;
}
.category-list li.active::before { height: 60%; }
.category-list li .c-count {
  margin-left: auto;
  color: var(--muted);
  font-weight: 600;
  background: var(--fill-soft);
  border-radius: var(--radius-pill);
  padding: 1px 9px;
  font-size: 12px;
}
.category-list li.active .c-count { background: #fff; color: var(--primary); }

/* 笔记列表 → 白色卡片 */
.note-list { flex: 1; padding: 4px 14px 14px; }
.note-item {
  position: relative;
  padding: 13px 14px 13px 16px;
  border-radius: var(--radius-md);
  cursor: pointer;
  margin-bottom: 8px;
  background: var(--panel);
  box-shadow: var(--shadow-sm);
  border: 1px solid transparent;
  transition: transform var(--t-fast), box-shadow var(--t-fast), background var(--t-fast);
  overflow: hidden;
}
.note-item::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 4px;
  background: transparent;
  transition: background var(--t-fast);
}
.note-item:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.note-item.active {
  background: var(--primary-soft);
  border-color: var(--border-strong);
}
.note-item.active::before { background: var(--primary); }
.note-item .n-title {
  font-size: 14.5px;
  font-weight: 700;
  color: var(--text-strong);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: .2px;
}
.note-item .n-sub {
  font-size: 12px;
  color: var(--muted);
  margin-top: 5px;
  display: flex;
  gap: 8px;
  align-items: center;
}
.note-item .n-sub .n-cat {
  color: var(--primary);
  background: var(--primary-soft);
  border-radius: var(--radius-pill);
  padding: 1px 8px;
  font-weight: 600;
}
.note-item .n-sub:last-child { color: var(--muted-2); }

/* 已完成的笔记：标题划线 + 绿色徽标 */
.note-item.done .n-title { text-decoration: line-through; color: var(--muted); }
.done-badge {
  font-size: 10.5px;
  color: var(--success-dark);
  background: var(--success-soft);
  border-radius: var(--radius-pill);
  padding: 1px 8px;
  margin-left: 6px;
  font-weight: 700;
  letter-spacing: .3px;
}

/* 右键菜单 */
.ctx-menu {
  position: fixed;
  z-index: 9999;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: 6px;
  min-width: 160px;
}
.ctx-item {
  padding: 9px 12px;
  font-size: 13px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--t-fast);
}
.ctx-item:hover { background: var(--fill-soft); }
.ctx-item.danger { color: var(--danger); }
.ctx-item.danger:hover { background: var(--danger-soft); }

/* ============================================================
   编辑区（浅灰画布 + 白色内容卡片）
   ============================================================ */
.editor { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--bg); }
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  gap: 14px;
}
.empty-state .empty-icon {
  font-size: 64px;
  filter: drop-shadow(0 6px 14px rgba(17, 28, 45, .12));
}

.editor-panel { flex: 1; display: flex; flex-direction: column; padding: 24px 32px; min-height: 0; }
.editor-meta { margin-bottom: 16px; }
.title-input {
  width: 100%;
  border: none;
  font-size: 26px;
  font-weight: 800;
  outline: none;
  background: transparent;
  color: var(--text-strong);
  letter-spacing: .3px;
  padding: 4px 2px;
}
.title-input::placeholder { color: var(--muted-2); }

.editor-tags { display: flex; gap: 14px; margin-bottom: 18px; }
.meta-input {
  flex: 1;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 13.5px;
  outline: none;
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow-sm);
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.meta-input::placeholder { color: var(--muted-2); }
.meta-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px var(--primary-soft);
}

.content-input {
  flex: 1;
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px 24px;
  font-size: 15px;
  line-height: 1.8;
  outline: none;
  font-family: inherit;
  background: var(--panel);
  box-shadow: var(--shadow-sm);
  overflow-y: auto;
  min-height: 200px;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.content-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px var(--primary-soft);
}
.content-input:empty:before {
  content: attr(data-placeholder);
  color: var(--muted-2);
  pointer-events: none;
}
.content-input img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius-md);
  margin: 10px 0;
  display: block;
  box-shadow: var(--shadow-md);
  cursor: pointer;
}
/* 已被手动缩放（带内联 width）的图片，解除容器宽度限制，按用户设定尺寸显示（可超出容器横向滚动） */
.content-input img[style*="width"] { max-width: none; }
.content-input img.img-selected {
  outline: 2px solid var(--primary);
  outline-offset: 3px;
}
.content-input a { color: var(--primary); text-decoration: none; }
.content-input a:hover { text-decoration: underline; }

/* 图片缩放浮层（点击图片后显示，右下角手柄等比例缩放） */
.img-resize-box {
  position: fixed;
  border: 1.5px dashed var(--primary);
  border-radius: 4px;
  pointer-events: none;
  z-index: 1000;
}
.img-resize-handle {
  position: absolute;
  right: -9px;
  bottom: -9px;
  width: 16px;
  height: 16px;
  background: var(--primary);
  border: 2px solid #fff;
  border-radius: 4px;
  cursor: nwse-resize;
  pointer-events: auto;
  box-shadow: var(--shadow-md);
}
.img-resize-size {
  position: absolute;
  top: -26px;
  left: 0;
  font-size: 11px;
  line-height: 1.6;
  color: #fff;
  background: var(--primary);
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  pointer-events: none;
  font-weight: 600;
}

.editor-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 16px;
}
.save-hint { font-size: 13px; color: var(--muted); font-weight: 500; }
.foot-actions { display: flex; gap: 10px; }

/* 移动端返回按钮：默认隐藏（仅窄屏媒体查询内显示） */
.mobile-back { display: none; }

.hidden { display: none !important; }

/* ============================================================
   移动端响应式（≤768px）
   左右分栏在窄屏会把编辑区挤没 → 改为「列表 / 编辑」单栏切换
   ============================================================ */
@media (max-width: 768px) {
  /* 用动态视口高度，规避手机地址栏伸缩导致的错位 */
  body { height: 100dvh; }

  /* 顶栏收缩 */
  .topbar { gap: 8px; padding: 10px 12px; }
  .search input { padding: 9px 12px 9px 34px; font-size: 13px; }
  .actions { gap: 6px; }
  .actions .btn { padding: 9px 11px; font-size: 12.5px; }
  .user-chip { display: none; } /* 窄屏隐藏用户名，避免顶栏溢出 */

  /* 单栏切换：默认显示列表，编辑区隐藏 */
  .resizer { display: none; }
  .sidebar {
    width: 100% !important;   /* 覆盖 JS 写入的内联宽度 */
    min-width: 0;
    border-right: none;
    box-shadow: none;
    padding-bottom: 14px;
  }
  .editor { min-width: 0; }
  body:not(.mobile-detail) .editor { display: none; }
  body.mobile-detail .sidebar { display: none; }
  body.mobile-detail .editor { display: flex; }

  /* 编辑区顶部返回按钮 */
  .mobile-back {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    align-self: flex-start;
    flex-shrink: 0;
    border: none;
    background: var(--panel);
    color: var(--primary);
    border-radius: var(--radius-pill);
    padding: 7px 15px;
    margin-bottom: 8px;
    font-size: 13px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    box-shadow: var(--shadow-sm);
  }
  .mobile-back:active { transform: translateY(1px); }

  /* 编辑区内边距与字号收紧 */
  .editor-panel { padding: 14px 16px; }
  .title-input { font-size: 21px; }
  .editor-tags { flex-direction: column; gap: 10px; margin-bottom: 14px; }
  .content-input { padding: 15px 16px; font-size: 14px; }
  .editor-foot { align-items: stretch; flex-direction: column; gap: 10px; }
  .foot-actions { justify-content: flex-end; flex-wrap: wrap; }
  .empty-state .empty-icon { font-size: 52px; }
}
