/* ── Notes Surface Styles ─────────────────── */

.notes-app {
  display: flex;
  height: 100%;
  overflow: hidden;
}

/* ── Sidebar ─────────────────────────────── */
.notes-sidebar {
  width: 280px;
  min-width: 220px;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  background: var(--bg-raised);
  flex-shrink: 0;
}
.notes-sidebar__header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.notes-sidebar__title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  flex: 1;
}
.notes-sidebar__count {
  font-size: 12px;
  color: var(--text-3);
}
.notes-sidebar__actions {
  display: flex;
  gap: 4px;
}

/* ── Folder Tree ────────────────────────── */
.folder-tree {
  padding: 4px 0;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  max-height: 40%;
  overflow-y: auto;
}
.folder-tree__item {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 5px 12px;
  font-size: 13px;
  color: var(--text-2);
  cursor: pointer;
  border-radius: var(--radius);
  margin: 1px 6px;
  transition: var(--transition);
  user-select: none;
}
.folder-tree__item:hover {
  background: var(--bg-hover);
  color: var(--text);
}
.folder-tree__item--active {
  background: var(--bg-active);
  color: var(--text);
  font-weight: 500;
}
.folder-tree__toggle {
  width: 14px;
  font-size: 9px;
  text-align: center;
  flex-shrink: 0;
  color: var(--text-3);
}
.folder-tree__icon {
  font-size: 13px;
  flex-shrink: 0;
}
.folder-tree__name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}
.folder-tree__edit {
  flex: 1;
  font-size: 13px;
  padding: 1px 4px;
  border: 1px solid var(--accent);
  border-radius: 3px;
  background: var(--bg-surface);
  color: var(--text);
  font-family: var(--font);
  outline: none;
}
.folder-tree__add {
  padding: 6px 12px;
  font-size: 12px;
  color: var(--text-3);
  cursor: pointer;
  transition: var(--transition);
}
.folder-tree__add:hover {
  color: var(--accent);
}

/* ── Search ──────────────────────────────── */
.notes-search {
  padding: 8px 14px;
  flex-shrink: 0;
}
.notes-search input {
  width: 100%;
  padding: 6px 10px;
  font-size: 13px;
  background: var(--bg-surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--font);
}
.notes-search input:focus {
  outline: none;
  border-color: var(--accent);
}
.notes-search input::placeholder {
  color: var(--text-3);
}

/* ── Note List ───────────────────────────── */
.notes-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px;
}
.notes-list__empty {
  padding: 40px 16px;
  text-align: center;
  color: var(--text-3);
  font-size: 13px;
}
.notes-list__loading {
  padding: 40px 0;
  display: flex;
  justify-content: center;
  color: var(--text-3);
}

/* ── Note Card (sidebar item) ────────────── */
.note-card {
  padding: 10px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: var(--transition);
  margin-bottom: 2px;
}
.note-card:hover {
  background: var(--bg-hover);
}
.note-card--active {
  background: var(--bg-active);
}
.note-card__title {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.note-card__pin {
  font-size: 11px;
  flex-shrink: 0;
}
.note-card__snippet {
  font-size: 12px;
  color: var(--text-3);
  margin-top: 3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.4;
}
.note-card__date {
  font-size: 11px;
  color: var(--text-3);
  margin-top: 3px;
}

/* ── Editor Pane ─────────────────────────── */
.notes-editor {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}
.notes-editor__empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-3);
  font-size: 14px;
}

/* ── Editor Header ───────────────────────── */
.notes-editor__header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.notes-editor__title-input {
  flex: 1;
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
  background: transparent;
  border: none;
  outline: none;
  padding: 4px 0;
  font-family: var(--font);
}
.notes-editor__title-input::placeholder {
  color: var(--text-3);
}
.notes-editor__actions {
  display: flex;
  gap: 6px;
  align-items: center;
}

/* ── Folder select in editor ────────────── */
.notes-editor__folder-select {
  font-size: 12px;
  padding: 3px 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-raised);
  color: var(--text-2);
  font-family: var(--font);
  cursor: pointer;
  max-width: 140px;
}
.notes-editor__folder-select:focus {
  outline: none;
  border-color: var(--accent);
}

/* ── Editor Body ─────────────────────────── */
.notes-editor__body {
  flex: 1;
  display: flex;
  min-height: 0;
  overflow: hidden;
}
.notes-editor__textarea {
  flex: 1;
  resize: none;
  padding: 20px;
  font-size: 14px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg-surface);
  border: none;
  outline: none;
  font-family: var(--mono);
  tab-size: 2;
}
.notes-editor__textarea::placeholder {
  color: var(--text-3);
}

/* ── CodeMirror 6 container ─────────────── */
.notes-editor__cm {
  flex: 1;
  overflow: hidden;
}
.notes-editor__cm .cm-editor {
  height: 100%;
  max-height: none;
}
.notes-editor__cm .cm-scroller {
  overflow: auto;
  padding: 12px 20px;
}

/* ── Preview ─────────────────────────────── */
.notes-preview {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  border-left: 1px solid var(--border);
  background: var(--bg-surface);
}
.notes-preview h1 { font-size: 24px; font-weight: 700; color: var(--text); margin: 0 0 12px; }
.notes-preview h2 { font-size: 20px; font-weight: 600; color: var(--text); margin: 20px 0 8px; }
.notes-preview h3 { font-size: 16px; font-weight: 600; color: var(--text); margin: 16px 0 6px; }
.notes-preview p  { font-size: 14px; color: var(--text); line-height: 1.7; margin: 0 0 10px; }
.notes-preview ul, .notes-preview ol { padding-left: 24px; margin: 0 0 10px; color: var(--text); font-size: 14px; line-height: 1.7; }
.notes-preview li { margin-bottom: 2px; }
.notes-preview code {
  font-family: var(--mono);
  font-size: 13px;
  background: var(--bg-raised);
  padding: 2px 6px;
  border-radius: 3px;
  color: var(--accent);
}
.notes-preview pre {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  overflow-x: auto;
  margin: 0 0 12px;
}
.notes-preview pre code {
  background: none;
  padding: 0;
  color: var(--text);
  font-size: 13px;
}
.notes-preview blockquote {
  border-left: 3px solid var(--accent);
  margin: 0 0 12px;
  padding: 4px 16px;
  color: var(--text-2);
}
.notes-preview a { color: var(--accent); text-decoration: none; }
.notes-preview a:hover { text-decoration: underline; }
.notes-preview hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 16px 0;
}
.notes-preview strong { font-weight: 600; }
.notes-preview em { font-style: italic; }

/* ── Toggle button ───────────────────────── */
.notes-toggle {
  padding: 4px 10px;
  font-size: 12px;
  border: 1px solid var(--border);
  background: var(--bg-raised);
  color: var(--text-2);
  border-radius: var(--radius);
  cursor: pointer;
  transition: var(--transition);
}
.notes-toggle:hover { background: var(--bg-hover); color: var(--text); }
.notes-toggle--active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ── Inline buttons ──────────────────────── */
.notes-btn {
  border: none;
  background: var(--bg-raised);
  color: var(--text-2);
  cursor: pointer;
  border-radius: var(--radius);
  transition: var(--transition);
  padding: 4px 10px;
  font-size: 13px;
}
.notes-btn:hover { background: var(--bg-hover); color: var(--text); }
.notes-btn--danger:hover { background: var(--danger-dim); color: var(--danger); }
.notes-btn--accent { background: var(--accent); color: #fff; }
.notes-btn--accent:hover { opacity: 0.9; color: #fff; }

/* ── Saved indicator ─────────────────────── */
.notes-saved {
  font-size: 12px;
  color: var(--text-3);
  padding: 2px 8px;
}
.notes-saved--dirty {
  color: var(--warning);
}

/* ── Tag Pills (shared) ─────────────────── */
.tag-pill {
  display: inline-block;
  padding: 1px 8px;
  font-size: 11px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-2);
  margin: 2px 2px;
  white-space: nowrap;
  cursor: pointer;
  line-height: 1.6;
  transition: var(--transition);
}
.tag-pill:hover { background: var(--bg-hover); color: var(--text); }
.tag-pill--active { background: var(--accent); color: #fff; border-color: var(--accent); }
.tag-pill__remove {
  margin-left: 4px;
  font-size: 10px;
  opacity: 0.6;
  cursor: pointer;
}
.tag-pill__remove:hover { opacity: 1; }

/* ── Tag Filter (sidebar) ──────────────── */
.tag-filter {
  padding: 6px 14px 4px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.tag-filter__label {
  font-size: 11px;
  color: var(--text-3);
  margin-bottom: 3px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.tag-filter__clear {
  font-size: 10px;
  color: var(--accent);
  cursor: pointer;
  background: none;
  border: none;
  padding: 0;
  font-family: var(--font);
}
.tag-filter__clear:hover { text-decoration: underline; }
.tag-filter__pills {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  max-height: 60px;
  overflow-y: auto;
}
.tag-filter__pills .tag-pill { font-size: 10px; padding: 0 6px; }

/* ── Tag Input (editor) ────────────────── */
.tag-input {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
  padding: 4px 20px 6px;
  border-bottom: 1px solid var(--border);
  position: relative;
}
.tag-input__field {
  border: none;
  outline: none;
  font-size: 12px;
  background: transparent;
  color: var(--text);
  min-width: 80px;
  flex: 1;
  padding: 2px 0;
  font-family: var(--font);
}
.tag-input__field::placeholder { color: var(--text-3); }
.tag-input .tag-pill { font-size: 11px; }

/* ── Tag Autocomplete ──────────────────── */
.tag-autocomplete {
  position: absolute;
  top: 100%;
  left: 20px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-height: 120px;
  overflow-y: auto;
  z-index: 10;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  min-width: 140px;
}
.tag-autocomplete__item {
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
  color: var(--text);
}
.tag-autocomplete__item:hover { background: var(--bg-hover); }

/* ── Note Card Tags ────────────────────── */
.note-card__tags {
  display: flex;
  gap: 3px;
  margin-top: 3px;
  overflow: hidden;
}
.note-card__tags .tag-pill { font-size: 10px; padding: 0 6px; cursor: default; }
.note-card__tags .tag-pill--overflow {
  background: transparent;
  border: none;
  color: var(--text-3);
  padding: 0 2px;
  cursor: default;
}

/* ── Folder Context Menu ───────────────── */
.folder-context-menu {
  position: fixed;
  z-index: 100;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
  min-width: 150px;
  padding: 4px 0;
}
.folder-context-menu__item {
  padding: 6px 14px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  transition: var(--transition);
}
.folder-context-menu__item:hover {
  background: var(--bg-hover);
}
.folder-context-menu__item--danger {
  color: var(--danger);
}
.folder-context-menu__item--danger:hover {
  background: var(--danger-dim);
}

/* ── Drag and Drop ─────────────────────── */
.note-card--dragging { opacity: 0.4; }
.folder-tree__item--drop-target {
  background: color-mix(in srgb, var(--accent) 10%, transparent) !important;
  outline: 2px dashed var(--accent);
  outline-offset: -2px;
}

/* ── Wikilinks ──────────────────────────── */
.wikilink {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px dashed var(--accent);
  cursor: pointer;
}
.wikilink:hover {
  border-bottom-style: solid;
}
.wikilink.wikilink--unresolved {
  color: var(--danger, #e53e3e);
  border-bottom-color: var(--danger, #e53e3e);
  opacity: 0.7;
}
.wikilink.wikilink--unresolved:hover {
  opacity: 1;
}

/* ── Backlinks Panel ────────────────────── */
.backlinks-panel {
  border-top: 1px solid var(--border);
  padding: 10px 16px;
  background: var(--bg-raised);
  flex-shrink: 0;
  max-height: 200px;
  overflow-y: auto;
}
.backlinks-panel__header {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  user-select: none;
}
.backlinks-panel__toggle {
  font-size: 9px;
  color: var(--text-2);
}
.backlinks-panel__count {
  background: var(--bg-hover);
  color: var(--text-2);
  font-size: 10px;
  padding: 0 6px;
  border-radius: 8px;
  line-height: 16px;
}
.backlinks-panel__item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
}
.backlinks-panel__item:hover {
  background: var(--bg-hover);
}
.backlinks-panel__title {
  color: var(--accent);
  font-weight: 500;
}
.backlinks-panel__context {
  color: var(--text-2);
  font-size: 11px;
}

/* ── Responsive ──────────────────────────── */
@media (max-width: 700px) {
  .notes-sidebar { width: 100%; border-right: none; border-bottom: 1px solid var(--border); max-height: 40vh; }
  .notes-app { flex-direction: column; }
  .folder-tree { max-height: 30vh; }
}
