/* ==========================================
   笔记视图：左侧列表栏常驻 + 右侧富文本编辑
   ========================================== */

/* hidden 属性必须优先于任何 display（否则设置了 display 的元素隐藏失效） */
[hidden] {
  display: none !important;
}

.notes-view {
  height: 100dvh;
  overflow: hidden;
}

.notes-view.active {
  display: flex;
}

/* ---------- 左侧列表栏 ---------- */
.notes-side {
  width: 248px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
  border-right: 1px solid var(--border);
  background: var(--bg-soft);
  min-height: 0;
}

.notes-side-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  padding: 0 4px;
}

.notes-side-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-main);
}

.note-new-btn {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-sub);
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  padding: 5px 11px;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.note-new-btn:hover {
  background: var(--bg-1);
  color: var(--text-main);
  border-color: var(--text-sub);
}

.note-search {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 13px;
  color: var(--text-main);
  outline: none;
  margin-bottom: 10px;
  transition: border-color 0.2s ease;
}

.note-search:focus {
  border-color: var(--text-sub);
}

.note-search::placeholder {
  color: var(--text-faint);
}

.note-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: 0 -6px;
  padding: 0 6px;
}

.note-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background-color 0.15s ease;
  position: relative;
}

.note-item:hover {
  background: var(--bg-1);
}

.note-item.active {
  background: var(--bg-hover-strong);
}

.note-item-main {
  flex: 1;
  min-width: 0;
}

.note-item-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.note-item-excerpt {
  font-size: 11.5px;
  color: var(--text-faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.note-item-time {
  font-size: 10.5px;
  color: var(--text-faint);
  margin-top: 3px;
  opacity: 0.7;
}

.note-item-del {
  border: none;
  background: transparent;
  color: var(--text-faint);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  padding: 3px 5px;
  border-radius: 4px;
  display: none;
}

.note-item:hover .note-item-del {
  display: inline-block;
}

.note-item-del:hover {
  color: #e5484d;
  background: rgba(229, 72, 77, 0.1);
}

/* ---------- 右侧主区 ---------- */
.notes-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  max-width: 860px;
  margin: 0 auto;
  padding: 24px 32px 0;
  width: 100%;
}

/* 无笔记时的空白占位（随机诗词） */
.notes-blank {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  color: var(--text-faint);
  text-align: center;
  padding: 20px;
}

.notes-blank[hidden] {
  display: none;
}

.notes-poem {
  font-size: 16px;
  line-height: 2.2;
  letter-spacing: 2px;
  color: var(--text-sub);
  max-width: 460px;
}

.notes-poem-src {
  font-size: 12px;
  color: var(--text-faint);
  margin-top: 4px;
  font-style: italic;
}

.notes-poem-hint {
  font-size: 12.5px;
  color: var(--text-faint);
  opacity: 0.85;
  margin-top: 4px;
}

/* 顶栏：标题 + 集中操作 */
.notes-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 14px;
}

.note-title-input {
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  font-size: 20px;
  font-weight: 700;
  color: var(--text-main);
  outline: none;
  padding: 4px 0;
}

.note-title-input::placeholder {
  color: var(--text-faint);
  font-weight: 400;
}

.notes-top-ops {
  display: flex;
  align-items: center;
  gap: 8px;
  position: relative;
}

.note-status {
  font-size: 11px;
  color: var(--text-faint);
  white-space: nowrap;
}

.note-op {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-sub);
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  padding: 6px 12px;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
  font-family: inherit;
}

.note-op:hover {
  background: var(--bg-1);
  color: var(--text-main);
  border-color: var(--text-sub);
}

.note-op:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.notes-icon-btn {
  border: none;
  background: transparent;
  color: var(--text-sub);
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.notes-icon-btn:hover {
  background: var(--bg-1);
  color: var(--text-main);
}

/* 上升菜单（AI 辅助 / 更多共用） */
.notes-more-wrap {
  position: relative;
}

.notes-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 150px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.18);
  padding: 6px;
  z-index: 60;
  animation: notes-menu-in 0.16s ease both;
}

[data-theme="dark"] .notes-menu {
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
}

@keyframes notes-menu-in {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: none; }
}

.notes-menu-item {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  color: var(--text-main);
  font-size: 13px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background-color 0.12s ease;
  font-family: inherit;
}

.notes-menu-item:hover {
  background: var(--bg-1);
}

.notes-menu-item.danger {
  color: #e5484d;
}

/* ---------- Tab 切换 ---------- */
.notes-tabs {
  display: flex;
  gap: 22px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 14px;
}

.notes-tab {
  border: none;
  background: transparent;
  color: var(--text-faint);
  font-size: 13.5px;
  font-weight: 600;
  padding: 8px 2px 10px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color 0.15s ease, border-color 0.15s ease;
  font-family: inherit;
}

.notes-tab:hover {
  color: var(--text-sub);
}

.notes-tab.active {
  color: var(--text-main);
  border-bottom-color: var(--text-main);
}

/* ---------- 编辑工具栏 ---------- */
.notes-toolbar {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 4px 0 10px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 10px;
}

.notes-toolbar[hidden] {
  display: none;
}

.notes-tool {
  border: none;
  background: transparent;
  color: var(--text-sub);
  min-width: 30px;
  height: 30px;
  padding: 0 8px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.notes-tool:hover {
  background: var(--bg-1);
  color: var(--text-main);
}

.md-tool-bold { font-weight: 700; }
.md-tool-italic { font-style: italic; }
.md-tool-underline { text-decoration: underline; }
.md-tool-strike { text-decoration: line-through; }
.md-tool-code {
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 11px;
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 0 5px;
  height: 24px;
  align-self: center;
}
.md-tool-heading {
  font-weight: 700;
  font-size: 14px;
}

.notes-tool-sep {
  width: 1px;
  height: 16px;
  background: var(--border);
  margin: 0 6px;
}

/* ---------- 富文本编辑 / 预览 ---------- */
.notes-body {
  flex: 1;
  min-height: 0;
  display: flex;
}

.note-editable,
.note-preview {
  flex: 1;
  min-width: 0;
  min-height: 0;
  overflow-y: auto;
}

.note-editable {
  outline: none;
  font-size: 15px;
  line-height: 1.9;
  padding: 4px 4px 24px;
  color: var(--text-main);
  caret-color: var(--text-main);
  word-break: break-word;
}

.note-editable:empty::before,
.note-editable > br:only-child::before {
  content: "写点什么…";
  color: var(--text-faint);
  pointer-events: none;
}

/* contenteditable 内块级间距 */
.note-editable p { margin: 0 0 10px; }
.note-editable div { margin: 0 0 6px; }
.note-editable h1, .note-editable h2,
.note-editable h3, .note-editable h4,
.note-editable h5 {
  font-weight: 700;
  line-height: 1.4;
  margin: 18px 0 10px;
}
.note-editable h1 { font-size: 26px; }
.note-editable h2 { font-size: 22px; }
.note-editable h3 { font-size: 18px; }
.note-editable h4 { font-size: 16px; }
.note-editable h5 { font-size: 15px; }
.note-editable ul, .note-editable ol { margin: 0 0 10px; padding-left: 22px; }
.note-editable li { margin: 3px 0; }
.note-editable blockquote {
  margin: 0 0 10px;
  padding: 2px 0 2px 14px;
  border-left: 3px solid var(--border);
  color: var(--text-sub);
}
.note-editable pre {
  margin: 4px 0 12px;
  padding: 12px 14px;
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow-x: auto;
  font-size: 13px;
}
.note-editable a { color: var(--accent); }
.note-editable u { text-decoration: underline; }
.note-editable del { text-decoration: line-through; }
.note-editable code {
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.9em;
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
}
.note-editable pre code {
  background: transparent;
  border: none;
  padding: 0;
}
.note-editable table {
  border-collapse: collapse;
  margin: 4px 0 12px;
  width: 100%;
  font-size: 13.5px;
}
.note-editable th, .note-editable td {
  border: 1px solid var(--border);
  padding: 6px 10px;
}
.note-editable th {
  background: var(--bg-1);
  font-weight: 600;
}
.note-editable hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 16px 0;
}
.note-editable .md-formula-inline {
  font-family: "Cambria Math", "STIX Two Math", serif;
  font-style: italic;
  padding: 0 3px;
}
.note-editable .md-formula {
  text-align: center;
  margin: 8px 0 12px;
  font-family: "Cambria Math", "STIX Two Math", serif;
  font-size: 16px;
}

.note-preview {
  padding: 4px 4px 24px;
}

.note-preview:empty::before {
  content: "内容较少，换个姿势写点什么…";
  color: var(--text-faint);
}

/* ---------- 底部信息栏 ---------- */
.notes-footer {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 0 6px;
  border-top: 1px solid var(--border);
  font-size: 11.5px;
  color: var(--text-faint);
  margin-top: 4px;
}

.notes-char {
  white-space: nowrap;
}

.notes-upd {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- 删除确认气泡（定位在删除键旁边） ---------- */
.note-confirm {
  position: fixed;
  z-index: 70;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: 0 10px 34px rgba(0, 0, 0, 0.22);
  padding: 9px 12px;
  font-size: 12.5px;
  color: var(--text-main);
  max-width: 320px;
  animation: notes-menu-in 0.16s ease both;
}

[data-theme="dark"] .note-confirm {
  box-shadow: 0 10px 34px rgba(0, 0, 0, 0.55);
}

.note-confirm-text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.note-confirm-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.note-confirm button {
  border: 1px solid var(--border);
  background: transparent;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-family: inherit;
  padding: 4px 10px;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.note-confirm-ok {
  background: #e5484d;
  border-color: #e5484d;
  color: #fff;
  font-weight: 600;
}

.note-confirm-ok:hover {
  background: #d63d42;
  border-color: #d63d42;
}

.note-confirm-no {
  color: var(--text-sub);
}

.note-confirm-no:hover {
  background: var(--bg-1);
  color: var(--text-main);
}

/* ========== 交互动效（v40） ========== */

/* 列表首项（最新笔记）入场；showPoem 重建节点时自动重播诗句淡入 */
.note-list .note-item:first-child {
  animation: note-in 0.28s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

@keyframes note-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* 空态诗句淡入（innerHTML 重建触发） */
.notes-poem {
  animation: poem-in 0.55s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

@keyframes poem-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.notes-poem-src {
  animation: poem-src-in 0.55s ease 0.12s both;
}

@keyframes poem-src-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* 编辑器打开轻淡入 */
.note-editable {
  animation: editor-in 0.25s ease both;
}

@keyframes editor-in {
  from {
    opacity: 0;
    transform: translateY(3px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}
