:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-muted: #f1f5f9;
  --border: #e5e7eb;
  --text: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;
  --accent: #059669;
  --accent-hover: #047857;
  --accent-soft: #d1fae5;
  --accent-text: #065f46;
  --pin-bg: #fef3c7;
  --pin-text: #b45309;
  --danger: #dc2626;
  --heat-0: #eef2f6;
  --heat-1: #a7f3d0;
  --heat-2: #34d399;
  --heat-3: #059669;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 6px 18px rgba(15, 23, 42, 0.04);
}

html[data-theme="dark"] {
  --bg: #0b1120;
  --surface: #151e31;
  --surface-muted: #1e293b;
  --border: #283548;
  --text: #f1f5f9;
  --text-secondary: #cbd5e1;
  --text-muted: #94a3b8;
  --accent: #10b981;
  --accent-hover: #34d399;
  --accent-soft: rgba(16, 185, 129, 0.16);
  --accent-text: #6ee7b7;
  --pin-bg: rgba(245, 158, 11, 0.16);
  --pin-text: #fcd34d;
  --danger: #f87171;
  --heat-0: #1e293b;
  --heat-1: #064e3b;
  --heat-2: #047857;
  --heat-3: #10b981;
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

.hidden {
  display: none !important;
}

.layout {
  max-width: 1080px;
  margin: 0 auto;
  min-height: 100vh;
  display: grid;
  grid-template-columns: 270px minmax(0, 1fr);
  gap: 24px;
  padding: 20px;
}

/* 侧边栏 */
.sidebar {
  display: flex;
  flex-direction: column;
  gap: 14px;
  position: sticky;
  top: 20px;
  max-height: calc(100vh - 40px);
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 2px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-icon {
  width: 34px;
  height: 34px;
  border-radius: 9px;
}

.brand-name {
  font-size: 16px;
  font-weight: 700;
  line-height: 1.2;
}

.brand-sub {
  font-size: 11px;
  color: var(--text-muted);
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
}

.sidebar-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  box-shadow: var(--shadow);
}

.stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  text-align: center;
  margin-bottom: 12px;
}

.stat-item {
  display: flex;
  flex-direction: column;
}

.stat-num {
  font-size: 18px;
  font-weight: 700;
  line-height: 1.2;
}

.stat-label {
  font-size: 11px;
  color: var(--text-muted);
}

.heatmap-grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  grid-template-rows: repeat(7, 1fr);
  grid-auto-flow: column;
  gap: 3px;
}

.heat-cell {
  aspect-ratio: 1;
  border-radius: 3px;
  background: var(--heat-0);
}

.heat-cell[data-level="1"] {
  background: var(--heat-1);
}

.heat-cell[data-level="2"] {
  background: var(--heat-2);
}

.heat-cell[data-level="3"] {
  background: var(--heat-3);
}

.heatmap-legend {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 6px;
}

.nav-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-item {
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  padding: 9px 12px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
}

.nav-item:hover {
  background: var(--surface);
  color: var(--text);
}

.nav-item.active {
  background: var(--accent-soft);
  color: var(--accent-text);
  font-weight: 600;
}

.tags-section {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.tags-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  padding: 4px 6px;
}

.tag-list {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin-top: 4px;
}

.tag-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  text-align: left;
}

.tag-row:hover {
  background: var(--surface);
}

.tag-row.active {
  background: var(--accent-soft);
  color: var(--accent-text);
  font-weight: 600;
}

.tag-count {
  font-size: 11px;
  color: var(--text-muted);
}

.sidebar-footer {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.side-action-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  border-radius: 9px;
  padding: 7px 10px;
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
}

.side-action-btn:hover {
  color: var(--text);
  border-color: var(--accent);
}

.quick-links {
  display: flex;
  justify-content: space-around;
  font-size: 12px;
}

.quick-links a {
  color: var(--text-muted);
  text-decoration: none;
}

.quick-links a:hover {
  color: var(--accent);
}

/* 主区 */
.main-col {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.topbar-left {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
}

.search-box {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0 12px;
  height: 40px;
  color: var(--text-muted);
}

.search-box:focus-within {
  border-color: var(--accent);
}

.search-box input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
}

.icon-btn {
  height: 40px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
}

.icon-btn:hover {
  color: var(--text);
  border-color: var(--accent);
}

.mobile-only {
  display: none;
}

/* 编辑器 */
.composer-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px 16px;
  box-shadow: var(--shadow);
}

.composer-card:focus-within {
  border-color: var(--accent);
}

.note-textarea {
  width: 100%;
  min-height: 74px;
  max-height: 280px;
  border: none;
  outline: none;
  resize: vertical;
  background: transparent;
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
  line-height: 1.65;
}

.pending-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.pending-att {
  position: relative;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  background: var(--surface-muted);
}

.pending-att img {
  display: block;
  width: 72px;
  height: 72px;
  object-fit: cover;
}

.pending-att-file {
  padding: 8px 26px 8px 10px;
  font-size: 12px;
  max-width: 180px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pending-att-rm {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: none;
  background: rgba(15, 23, 42, 0.72);
  color: #ffffff;
  font-size: 13px;
  cursor: pointer;
  line-height: 1;
}

.composer-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.composer-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tool-btn {
  border: 1px solid var(--border);
  background: var(--surface-muted);
  color: var(--text-secondary);
  border-radius: 8px;
  padding: 5px 10px;
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
}

.tool-btn:hover {
  color: var(--text);
  border-color: var(--accent);
}

.publish-btn {
  border: none;
  background: var(--accent);
  color: #ffffff;
  border-radius: 10px;
  padding: 8px 18px;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}

.publish-btn:hover {
  background: var(--accent-hover);
}

.publish-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.filter-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--accent-soft);
  color: var(--accent-text);
  padding: 8px 14px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
}

.link-btn {
  border: none;
  background: transparent;
  color: var(--accent);
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  padding: 0;
}

/* 笔记卡片 */
.notes-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.note-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px 18px;
  box-shadow: var(--shadow);
}

.note-card.pinned {
  border-color: #f59e0b;
}

.note-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.note-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
}

.pin-badge {
  background: var(--pin-bg);
  color: var(--pin-text);
  font-size: 11px;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: 999px;
}

.note-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.card-action {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  padding: 3px 6px;
  border-radius: 6px;
}

.card-action:hover {
  background: var(--surface-muted);
  color: var(--text);
}

.card-action.danger:hover {
  color: var(--danger);
}

.note-body {
  font-size: 15px;
  line-height: 1.7;
  word-break: break-word;
}

.note-body h1,
.note-body h2,
.note-body h3 {
  margin: 6px 0 4px;
  font-size: 16px;
}

.note-body p {
  margin: 0 0 6px;
}

.note-body p:last-child {
  margin-bottom: 0;
}

.note-body a {
  color: var(--accent);
  text-decoration: underline;
}

.note-body code {
  background: var(--surface-muted);
  padding: 1px 6px;
  border-radius: 5px;
  font-size: 13px;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
}

.code-block-wrap {
  position: relative;
  margin: 8px 0;
}

.code-block-wrap pre {
  margin: 0;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  overflow-x: auto;
  font-size: 13px;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  line-height: 1.5;
}

.code-copy-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  border-radius: 6px;
  padding: 2px 8px;
  font-size: 11px;
  cursor: pointer;
}

.inline-tag {
  display: inline-block;
  border: none;
  background: var(--accent-soft);
  color: var(--accent-text);
  padding: 0 7px;
  border-radius: 6px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  margin: 0 1px;
}

.todo-line {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 3px 0;
}

.todo-checkbox {
  margin-top: 5px;
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}

.todo-text.done {
  text-decoration: line-through;
  color: var(--text-muted);
}

.note-images {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.note-img {
  width: 100%;
  height: 140px;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid var(--border);
  cursor: zoom-in;
}

.note-files {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.note-file-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 8px;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 12px;
  text-decoration: none;
}

.edit-box {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.edit-textarea {
  width: 100%;
  min-height: 96px;
  border: 1px solid var(--accent);
  border-radius: 10px;
  padding: 10px 12px;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  line-height: 1.6;
  outline: none;
}

.edit-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.empty-state {
  text-align: center;
  padding: 48px 16px;
  color: var(--text-muted);
}

.empty-title {
  margin: 0 0 6px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-secondary);
}

.empty-desc {
  margin: 0;
  font-size: 13px;
}

/* 弹窗 & 灯箱 */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 60;
}

.modal-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  box-shadow: var(--shadow);
}

.modal-card h2 {
  margin: 0 0 8px;
  font-size: 17px;
}

.modal-tip {
  margin: 0 0 12px;
  font-size: 13px;
  color: var(--text-secondary);
}

.modal-input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  outline: none;
}

.modal-input:focus {
  border-color: var(--accent);
}

.error-text {
  color: var(--danger);
  font-size: 13px;
  margin: 8px 0 0;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  margin-top: 14px;
}

.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 70;
}

.lightbox img {
  max-width: 94vw;
  max-height: 88vh;
  border-radius: 10px;
}

.lightbox-close {
  position: absolute;
  top: 16px;
  right: 20px;
  border: none;
  background: rgba(255, 255, 255, 0.16);
  color: #ffffff;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  font-size: 24px;
  cursor: pointer;
}

.toast {
  position: fixed;
  bottom: 26px;
  left: 50%;
  transform: translateX(-50%);
  background: #0f172a;
  color: #ffffff;
  padding: 8px 18px;
  border-radius: 999px;
  font-size: 13px;
  z-index: 80;
  pointer-events: none;
}

html[data-theme="dark"] .toast {
  background: #f1f5f9;
  color: #0f172a;
}

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  z-index: 40;
}

@media (max-width: 820px) {
  .layout {
    grid-template-columns: 1fr;
    padding: 12px;
    gap: 12px;
  }

  .mobile-only {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 280px;
    max-height: 100vh;
    background: var(--bg);
    padding: 16px;
    z-index: 50;
    transform: translateX(-105%);
    transition: transform 0.2s ease;
  }

  .sidebar.open {
    transform: translateX(0);
  }
}
