* { margin: 0; padding: 0; box-sizing: border-box; }
html { touch-action: manipulation; overflow: hidden; width: 100%; }
html, body { max-width: 100vw; overflow-x: hidden; }
:root {
  --bg: #1e1e2e; --surface: #252536; --surface2: #2d2d44;
  --border: #3a3a5c; --text: #e0e0f0; --text2: #a0a0c0;
  --accent: #7c6ff7; --accent2: #9d8fff; --danger: #f77;
  --match-bg: #7c6ff744; --match-active: #7c6ff7aa;
  --unread: #ff4444;
}
[data-theme="light"] {
  --bg: #f5f5f7; --surface: #ffffff; --surface2: #eeeef2;
  --border: #d4d4d8; --text: #1e1e2e; --text2: #6b6b80;
  --accent: #6c5ce7; --accent2: #7c6ff7; --danger: #e55;
  --match-bg: #6c5ce744; --match-active: #6c5ce7aa;
  --unread: #e53e3e;
}
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: var(--bg); color: var(--text); height: 100vh; overflow: hidden; }
#app { display: flex; height: 100vh; overflow: hidden; max-width: 100vw; }

/* --- Left Sidebar --- */
#sidebar { width: 320px; min-width: 200px; max-width: 500px; background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; position: relative; transition: width 0.15s ease, min-width 0.15s ease; }
#sidebar.collapsed { width: 0 !important; min-width: 0 !important; overflow: hidden; border-right: none; }
#sidebar-resize { position: absolute; right: -3px; top: 0; bottom: 0; width: 6px; cursor: col-resize; z-index: 10; }
#sidebar-resize:hover { background: var(--accent); opacity: 0.3; }
#sidebar-toggle { width: 22px; min-width: 22px; background: var(--surface); border: none; border-right: 1px solid var(--border); cursor: pointer; color: var(--text2); font-size: 11px; display: flex; align-items: center; justify-content: center; }
#sidebar-toggle:hover { background: var(--accent); color: #fff; }
#sidebar-header { padding: 16px; border-bottom: 1px solid var(--border); }
#sidebar-header h1 { font-size: 18px; cursor: pointer; }
#sidebar-header h1:hover { color: var(--accent2); }
#sidebar-title-row { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
#sidebar-title-row h1 { font-size: 18px; cursor: pointer; flex: 1; margin: 0; line-height: 1.2; }
#back-to-libs { background: var(--surface2); border: 1px solid var(--border); border-radius: 6px; padding: 4px 8px; cursor: pointer; font-size: 16px; color: var(--text2); line-height: 1; }
#back-to-libs:hover { background: var(--accent); color: #fff; }
#search-input { width: 100%; padding: 8px 12px; background: var(--surface2); border: 1px solid var(--border); border-radius: 6px; color: var(--text); font-size: 13px; outline: none; }
#search-input:focus { border-color: var(--accent); }

/* Sort + tree controls bar */
#sort-bar { display: flex; align-items: center; gap: 4px; padding: 6px 8px; border-bottom: 1px solid var(--border); font-size: 11px; color: var(--text2); flex-wrap: nowrap; }
#sort-bar select { background: var(--surface2); border: 1px solid var(--border); color: var(--text); font-size: 11px; padding: 2px 4px; border-radius: 4px; outline: none; cursor: pointer; }
#sort-bar button { background: none; border: none; color: var(--text2); cursor: pointer; font-size: 11px; padding: 2px 4px; }
#sort-bar button:hover { color: var(--accent2); }
.sort-spacer { flex: 1; }

#tree { flex: 1; overflow-y: auto; padding: 8px; }
.tree-item { user-select: none; }
.tree-row { display: flex; align-items: center; padding: 4px 8px; border-radius: 4px; cursor: pointer; font-size: 13px; gap: 6px; }
.tree-row:hover { background: var(--surface2); }
.tree-row.active { background: var(--accent); color: #fff; }
.tree-row.selected { background: rgba(124,111,247,0.3); }
.tree-row.multi-selected { outline: 2px solid var(--accent2); outline-offset: -2px; background: rgba(124,111,247,0.2); }
.tree-row.drag-over { outline: 2px dashed var(--accent2); outline-offset: -2px; }
.tree-row.drag-above { border-top: 2px solid var(--accent2) !important; }
.tree-row.drag-below { border-bottom: 2px solid var(--accent2) !important; }
.tree-icon { width: 16px; height: 16px; flex-shrink: 0; }
.tree-icon.folder-icon { color: #ffd84d; }
.tree-icon.note-icon { color: #6fb3f7; }
.tree-row .arrow { font-size: 10px; width: 14px; text-align: center; flex-shrink: 0; transition: transform 0.15s; }
.tree-row .arrow.open { transform: rotate(90deg); }
.tree-row .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-row .unread-badge { width: 8px; height: 8px; border-radius: 50%; background: var(--unread); flex-shrink: 0; }
.note-ts { font-size: 10px; color: var(--text2); opacity: 0.6; flex-shrink: 0; margin-left: 4px; white-space: nowrap; }
.tree-row .folder-badge { min-width: 18px; height: 16px; border-radius: 8px; background: var(--unread); color: #fff; font-size: 10px; font-weight: 700; display: flex; align-items: center; justify-content: center; padding: 0 4px; flex-shrink: 0; }
.tree-children { padding-left: 16px; }
.tree-children.collapsed { display: none; }
.note-info { font-size: 10px; color: var(--text2); padding: 0 8px 0 36px; margin-top: -2px; margin-bottom: 2px; opacity: 0.7; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Sidebar footer */
#sidebar-footer { border-top: 1px solid var(--border); padding: 8px; display: flex; flex-direction: column; gap: 6px; }
#action-buttons { display: flex; gap: 4px; }
#action-buttons button { display: flex; align-items: center; gap: 3px; padding: 5px 8px; background: var(--surface2); border: 1px solid var(--border); color: var(--text2); border-radius: 5px; cursor: pointer; font-size: 11px; white-space: nowrap; flex: 1; justify-content: center; }
#action-buttons button:hover { background: var(--accent); color: #fff; }
#action-buttons button svg { width: 13px; height: 13px; flex-shrink: 0; }
#sidebar-bottom-row { display: flex; gap: 4px; }
#sidebar-bottom-row button, #sidebar-bottom-row .btn { flex: 1; padding: 5px; background: var(--surface2); border: 1px solid var(--border); color: var(--text2); border-radius: 5px; cursor: pointer; font-size: 11px; text-align: center; display: flex; align-items: center; justify-content: center; gap: 3px; }
#sidebar-bottom-row button:hover, #sidebar-bottom-row .btn:hover { background: var(--accent); color: #fff; }
#sidebar-bottom-row svg { width: 12px; height: 12px; }

/* --- Main area --- */
#main { flex: 1; display: flex; flex-direction: column; overflow: hidden; position: relative; }
#empty-state { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--text2); }
#empty-state .hint { font-size: 13px; margin-top: 8px; opacity: 0.6; }
.empty-actions { display: flex; gap: 8px; margin-top: 16px; }
.empty-actions button { padding: 8px 16px; background: var(--surface2); border: 1px solid var(--border); border-radius: 6px; color: var(--text); font-size: 13px; cursor: pointer; }
.empty-actions button:hover { background: var(--accent); color: #fff; border-color: var(--accent); }
.empty-state-card { text-align: center; padding: 40px; color: var(--text2); }
.empty-state-card button { margin-top: 16px; padding: 10px 20px; background: var(--accent); border: none; border-radius: 6px; color: #fff; font-size: 14px; cursor: pointer; font-weight: 600; }
.empty-state-card button:hover { opacity: 0.9; }

/* Editor */
#editor-area { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
#editor-toolbar { display: flex; align-items: center; justify-content: space-between; padding: 8px 16px; border-bottom: 1px solid var(--border); background: var(--surface); }
#toolbar-left { display: flex; align-items: center; gap: 8px; }
#menu-toggle { display: none; background: var(--surface2); border: 1px solid var(--border); color: var(--text); padding: 4px 10px; border-radius: 4px; cursor: pointer; font-size: 16px; }
#note-path { font-size: 12px; color: var(--text2); }
#last-saved { font-size: 11px; color: var(--text2); }
#last-edited-by { font-size: 11px; color: var(--accent2); margin-left: 8px; }
#toolbar-right { display: flex; align-items: center; gap: 8px; }
.toolbar-btn { background: var(--surface2); border: 1px solid var(--border); border-radius: 6px; padding: 4px 10px; cursor: pointer; font-size: 14px; color: var(--text); position: relative; transition: background 0.15s; }
.toolbar-btn:hover { background: var(--accent); color: #fff; }
#export-menu { position: relative; }
#export-btn { background: var(--surface2); border: 1px solid var(--border); color: var(--text2); padding: 4px 10px; border-radius: 4px; cursor: pointer; font-size: 11px; }
#export-btn:hover { background: var(--accent); color: #fff; }
#export-dropdown { position: absolute; right: 0; top: 100%; margin-top: 4px; background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 4px; min-width: 100px; box-shadow: 0 4px 16px rgba(0,0,0,0.4); z-index: 50; }
#comment-toggle-btn { position: relative; }
#tinymce-wrap { flex: 1; overflow: hidden; }

/* --- Folder Browser (Finder view) --- */
#folder-browser { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
#folder-browser-header { padding: 12px 16px; border-bottom: 1px solid var(--border); background: var(--surface); display: flex; align-items: center; gap: 8px; }
#folder-browser-header h2 { font-size: 16px; font-weight: 600; flex: 1; }
#folder-browser-header .fb-path { font-size: 12px; color: var(--text2); }
.fb-breadcrumb { display: flex; align-items: center; flex-wrap: wrap; gap: 2px; flex: 1; }
.fb-crumb { font-size: 15px; color: var(--accent2); cursor: pointer; font-weight: 500; }
.fb-crumb:hover { text-decoration: underline; color: var(--text); }
.fb-crumb-sep { font-size: 13px; color: var(--text2); }
.fb-crumb-current { font-size: 16px; font-weight: 600; color: var(--text); }
#fb-table-wrap { flex: 1; overflow-y: auto; }
table.fb-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.fb-table th { position: sticky; top: 0; background: var(--surface); padding: 8px 12px; text-align: left; font-weight: 600; font-size: 12px; color: var(--text2); border-bottom: 1px solid var(--border); cursor: pointer; user-select: none; white-space: nowrap; }
.fb-table th:hover { color: var(--accent2); }
.fb-table th .sort-arrow { font-size: 10px; margin-left: 4px; }
.fb-table td { padding: 6px 12px; border-bottom: 1px solid var(--border); }
.fb-table tr:hover { background: var(--surface2); }
.fb-table tr.fb-active { background: var(--accent); color: #fff; }
.fb-table tr.fb-selected { background: rgba(124,111,247,0.25); }
.fb-table tr.fb-selected .fb-meta { color: var(--text); }
.fb-table tr { cursor: pointer; }
.fb-table .fb-icon { width: 18px; display: inline-block; vertical-align: middle; margin-right: 6px; }
.fb-table .fb-name { font-weight: 500; }
.fb-table .fb-meta { color: var(--text2); font-size: 12px; }
.fb-table tr.fb-active .fb-meta { color: rgba(255,255,255,0.7); }
.fb-subfolder-row { opacity: 0.85; }

/* --- Right Comments Sidebar --- */
#comments-sidebar { width: 0; min-width: 0; background: var(--surface); border-left: 1px solid var(--border); display: flex; flex-direction: column; overflow: hidden; transition: width 0.2s ease, min-width 0.2s ease; }
#comments-sidebar.open { width: 320px; min-width: 320px; }
.cs-header { padding: 10px 16px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; font-size: 14px; font-weight: 600; }
.cs-close { background: none; border: none; color: var(--text2); cursor: pointer; font-size: 16px; padding: 2px 6px; }
.cs-close:hover { color: var(--text); }
.cs-body { flex: 1; overflow-y: auto; display: flex; flex-direction: column; }
.comment-input-wrap { padding: 12px; display: flex; flex-direction: column; gap: 8px; position: relative; border-bottom: 1px solid var(--border); }
.comment-input { width: 100%; padding: 8px 10px; background: var(--surface2); border: 1px solid var(--border); border-radius: 6px; color: var(--text); font-size: 13px; resize: none; outline: none; font-family: inherit; min-height: 60px; }
.comment-input:focus { border-color: var(--accent); }
.comment-send { align-self: flex-end; padding: 6px 16px; background: var(--accent); border: none; border-radius: 6px; color: #fff; font-size: 12px; cursor: pointer; }
.comment-send:hover { opacity: 0.9; }
.mention-autocomplete { position: absolute; top: calc(100% + 2px); left: 12px; background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 4px; min-width: 160px; box-shadow: 0 4px 16px rgba(0,0,0,0.4); z-index: 200; }
.mention-option { padding: 5px 10px; font-size: 12px; cursor: pointer; border-radius: 4px; color: var(--accent2); }
.mention-option:hover { background: var(--accent); color: #fff; }
.comments-list { flex: 1; padding: 8px 12px; }
.comment-item { padding: 8px 0; border-bottom: 1px solid var(--border); }
.comment-item:last-child { border-bottom: none; }
.comment-meta { font-size: 11px; color: var(--text2); margin-bottom: 3px; }
.comment-meta strong { color: var(--text); }
.comment-delete { cursor: pointer; float: right; opacity: 0.4; font-size: 12px; }
.comment-delete:hover { opacity: 1; }
.comment-text { font-size: 13px; line-height: 1.5; }
.comment-text .mention { color: var(--accent2); font-weight: 600; }
.comment-anchor-preview { font-size: 12px; color: var(--accent2); padding: 6px 8px; background: rgba(124,111,247,0.1); border-radius: 4px; margin-bottom: 6px; line-height: 1.4; }
.comment-anchor-preview.hidden { display: none; }
.comment-anchor-preview .anchor-clear { cursor: pointer; margin-left: 6px; opacity: 0.6; }
.comment-anchor-preview .anchor-clear:hover { opacity: 1; }
.comment-anchor-btn { width: 100%; padding: 5px 8px; background: var(--surface2); border: 1px solid var(--border); border-radius: 4px; color: var(--text2); font-size: 11px; cursor: pointer; margin-bottom: 6px; }
.comment-anchor-btn:hover { background: var(--accent); color: #fff; }
.comment-anchor-ref { font-size: 11px; color: var(--accent2); padding: 3px 0; cursor: pointer; line-height: 1.3; }
.comment-anchor-ref:hover { text-decoration: underline; }
.comment-anchored { border-left: 2px solid var(--accent2); padding-left: 10px; }

#sidebar-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 49; }

/* Mobile nav bar */
#mobile-nav { display: none; }

@media (max-width: 768px) {
  /* Safe area for Dynamic Island / notch */
  #app { flex-direction: column; height: 100vh; height: 100dvh; padding-top: env(safe-area-inset-top, 0px); }

  /* Libraries screen */
  #libraries-screen { padding: 16px; flex: 1; overflow-y: auto; }
  #lib-header { flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
  #lib-header h1 { font-size: 20px; width: 100%; }
  #lib-header > div { flex-wrap: wrap; gap: 6px; }
  #lib-header .toolbar-btn { padding: 6px 10px; font-size: 13px; }
  #lib-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
  #lib-search { font-size: 16px; padding: 12px 36px 12px 14px; }

  /* Workspace layout */
  #app-workspace { flex-direction: column; flex: 1; display: flex; overflow: hidden; max-width: 100vw; }
  #app-workspace.hidden { display: none !important; }
  #main { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0; }

  /* Mobile nav bar — only visible inside workspace */
  #mobile-nav { display: none; align-items: center; padding: 8px 12px; background: var(--surface); border-bottom: 1px solid var(--border); gap: 8px; z-index: 40; flex-shrink: 0; }
  #app-workspace:not(.hidden) #mobile-nav { display: flex !important; }
  #mobile-menu-btn { background: var(--surface2); border: 1px solid var(--border); color: var(--text); padding: 6px 12px; border-radius: 6px; cursor: pointer; font-size: 14px; }
  #mobile-title { flex: 1; font-size: 15px; font-weight: 600; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  #mobile-comment-btn { background: var(--surface2); border: 1px solid var(--border); color: var(--text); padding: 6px 10px; border-radius: 6px; cursor: pointer; font-size: 14px; }

  /* Sidebar as overlay */
  #sidebar { position: fixed; left: -320px; top: env(safe-area-inset-top, 0px); bottom: 0; width: 300px !important; min-width: 300px !important; max-width: 300px !important; z-index: 50; transition: left 0.25s ease; }
  #sidebar.open { left: 0; }
  #sidebar.collapsed { left: -320px; }
  #sidebar-resize, #sidebar-toggle, #menu-toggle { display: none; }

  /* Editor toolbar — compact */
  #editor-toolbar { padding: 6px 10px; flex-shrink: 0; overflow: hidden; }
  #toolbar-left { display: none; }
  #toolbar-right { gap: 4px; }
  .desktop-only { display: none !important; }
  #toolbar-overflow { display: block; position: relative; }
  #toolbar-overflow-menu { position: absolute; right: 0; top: 100%; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 4px; min-width: 180px; box-shadow: 0 4px 16px rgba(0,0,0,0.4); z-index: 100; margin-top: 4px; }
  #export-menu { display: none; }

  /* Tree / sidebar items */
  .tree-row { padding: 10px 10px; font-size: 15px; gap: 8px; min-height: 40px; }
  .tree-icon { width: 20px; height: 20px; }
  .note-ts { font-size: 11px; }
  #action-buttons button { padding: 8px 10px; font-size: 12px; }
  #sidebar-bottom-row button, #sidebar-bottom-row .btn { padding: 8px; font-size: 12px; }
  #sort-bar { padding: 8px; }
  #sort-bar select, #sort-bar button { font-size: 12px; padding: 4px 6px; }

  /* Context menu / colors */
  .ctx-item { padding: 12px 14px; font-size: 15px; }
  .color-option { width: 32px; height: 32px; margin: 3px; }

  /* Comments full-screen */
  #comments-sidebar.open { width: 100%; min-width: 100%; position: fixed; right: 0; top: env(safe-area-inset-top, 0px); bottom: 0; z-index: 50; }
  .comment-input { font-size: 14px; min-height: 50px; }
  .comment-send { padding: 10px 18px; font-size: 14px; }

  /* Folder browser */
  .fb-table th { padding: 10px 8px; font-size: 13px; }
  .fb-table td { padding: 10px 8px; font-size: 14px; }
  .fb-breadcrumb, .fb-crumb { font-size: 14px; }
  .fb-crumb-current { font-size: 16px; }

  /* Misc */
  .tp-item { padding: 10px 12px; font-size: 14px; }
  #empty-state { padding: 20px; text-align: center; flex: 1; }
  #editor-area { flex: 1; }
}

/* Search results */
#search-results { flex: 1; padding: 20px; overflow-y: auto; }
#search-results h2 { font-size: 16px; margin-bottom: 12px; color: var(--text2); }
.search-result { background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 12px; margin-bottom: 8px; cursor: pointer; }
.search-result:hover { border-color: var(--accent); }
.search-result .sr-path { font-size: 11px; color: var(--text2); margin-bottom: 4px; }
.search-result .sr-title { font-size: 14px; font-weight: 600; margin-bottom: 6px; }
.search-result .sr-snippet { font-size: 12px; color: var(--text2); line-height: 1.5; }
.search-result .sr-snippet mark { background: var(--match-bg); color: var(--text); padding: 1px 2px; border-radius: 2px; }

/* Context menu */
#context-menu { position: fixed; background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 4px; min-width: 180px; box-shadow: 0 4px 16px rgba(0,0,0,0.4); z-index: 100; }
.ctx-item { padding: 6px 12px; font-size: 13px; cursor: pointer; border-radius: 4px; display: flex; align-items: center; gap: 8px; }
.ctx-item:hover { background: var(--accent); color: #fff; }
.ctx-item.danger { color: var(--danger); }
.ctx-item.danger:hover { background: var(--danger); color: #fff; }
.ctx-sub { position: relative; }
.ctx-sub .ctx-submenu { display: none; position: absolute; left: 100%; top: -4px; background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 6px; min-width: 140px; box-shadow: 0 4px 16px rgba(0,0,0,0.4); }
.ctx-sub:hover .ctx-submenu { display: block; }
.color-option { display: inline-flex; align-items: center; justify-content: center; width: 20px; height: 20px; border-radius: 50%; cursor: pointer; border: 2px solid transparent; margin: 2px; vertical-align: middle; }
.color-option:hover { border-color: #fff; transform: scale(1.2); }
.color-option.active { border-color: #fff; }
.hidden { display: none !important; }

/* Template picker */
.template-picker { padding: 6px; background: var(--surface); border: 1px solid var(--border); border-radius: 6px; margin: 4px 0; }
.tp-label { font-size: 11px; color: var(--text2); padding: 2px 6px 6px; }
.tp-list { display: flex; flex-direction: column; gap: 2px; }
.tp-item { padding: 6px 10px; font-size: 12px; cursor: pointer; border-radius: 4px; color: var(--text); }
.tp-item:hover { background: var(--accent); color: #fff; }

/* Libraries screen */
#libraries-screen { flex: 1; padding: 40px; overflow-y: auto; }
#lib-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; }
#lib-header h1 { font-size: 24px; }
#lib-header > div { display: flex; gap: 8px; align-items: center; }
/* Help button - now uses .toolbar-btn */

/* Help modal */
#help-modal { position: fixed; top: 0; right: 0; bottom: 0; z-index: 200; display: flex; justify-content: flex-end; }
#help-panel { width: 420px; max-width: 90vw; background: var(--bg); border-left: 1px solid var(--border); display: flex; flex-direction: column; box-shadow: -4px 0 24px rgba(0,0,0,0.4); }
#help-header { display: flex; align-items: center; justify-content: space-between; padding: 10px 16px; border-bottom: 1px solid var(--border); font-size: 15px; font-weight: 600; }
#help-header > div { display: flex; gap: 8px; align-items: center; }
.help-expand { color: var(--text2); text-decoration: none; font-size: 16px; padding: 2px 4px; }
.help-expand:hover { color: var(--accent2); }
.help-close { background: none; border: none; color: var(--text2); font-size: 18px; cursor: pointer; padding: 2px 6px; }
.help-close:hover { color: var(--text); }
#help-iframe { flex: 1; border: none; width: 100%; }
#new-lib-btn { padding: 8px 16px; background: var(--accent); border: none; border-radius: 6px; color: #fff; font-size: 14px; cursor: pointer; font-weight: 600; }
#new-lib-btn:hover { opacity: 0.9; }
#logout-btn { padding: 8px 16px; background: var(--surface2); border: 1px solid var(--border); border-radius: 6px; color: var(--text2); font-size: 13px; cursor: pointer; }
#logout-btn:hover { background: var(--danger); color: #fff; border-color: var(--danger); }
#lib-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }
#lib-search-wrap { position: relative; margin-bottom: 16px; }
#lib-search { width: 100%; padding: 10px 36px 10px 14px; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; color: var(--text); font-size: 14px; box-sizing: border-box; }
#lib-search:focus { outline: none; border-color: var(--accent); }
#lib-search-clear { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); cursor: pointer; color: var(--text2); font-size: 14px; }
#lib-search-results { margin-bottom: 20px; }
.lib-sr-item { display: flex; align-items: center; gap: 12px; padding: 10px 14px; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; margin-bottom: 6px; cursor: pointer; transition: border-color 0.15s; }
.lib-sr-item:hover { border-color: var(--accent); }
.lib-sr-name { font-weight: 600; font-size: 14px; }
.lib-sr-path { font-size: 12px; color: var(--text2); }
.lib-sr-snippet { font-size: 12px; color: var(--text2); margin-top: 2px; }
.lib-sr-snippet mark { background: rgba(124,111,247,0.3); color: var(--text); border-radius: 2px; }
.lib-card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 20px; cursor: pointer; transition: border-color 0.15s, transform 0.15s; }
.lib-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.lib-card .lib-icon { font-size: 32px; margin-bottom: 10px; }
.lib-card .lib-name { font-size: 16px; font-weight: 600; margin-bottom: 6px; }
.lib-card .lib-meta { font-size: 12px; color: var(--text2); }
#app-workspace { display: flex; flex: 1; overflow: hidden; width: 100%; }

/* Login */
#login-screen { display: flex; align-items: center; justify-content: center; height: 100vh; background: var(--bg); }
#login-box { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 40px; width: 320px; text-align: center; }
#login-box h2 { margin-bottom: 24px; font-size: 22px; }
#login-box input { width: 100%; padding: 10px 12px; margin-bottom: 12px; background: var(--surface2); border: 1px solid var(--border); border-radius: 6px; color: var(--text); font-size: 14px; outline: none; }
#login-box input:focus { border-color: var(--accent); }
#login-btn { width: 100%; padding: 10px; background: var(--accent); border: none; border-radius: 6px; color: #fff; font-size: 14px; cursor: pointer; font-weight: 600; }
#login-btn:hover { opacity: 0.9; }
.login-divider { display: flex; align-items: center; margin: 12px 0; color: var(--text2); font-size: 12px; }
.login-divider::before, .login-divider::after { content: ''; flex: 1; border-top: 1px solid var(--border); }
.login-divider span { padding: 0 10px; }
#sso-btn { width: 100%; padding: 10px; background: var(--surface2); border: 1px solid var(--border); border-radius: 6px; color: var(--text); font-size: 14px; cursor: pointer; font-weight: 600; }
#sso-btn:hover { background: var(--accent); color: #fff; }
#login-error { color: var(--danger); font-size: 12px; margin-top: 8px; }

/* Toast notifications */
#toast-container { position: fixed; bottom: 20px; right: 20px; z-index: 10000; display: flex; flex-direction: column-reverse; gap: 8px; pointer-events: none; }
.toast { pointer-events: auto; padding: 10px 16px; background: var(--surface2); border: 1px solid var(--border); border-radius: 8px; color: var(--text); font-size: 13px; display: flex; align-items: center; gap: 10px; box-shadow: 0 4px 12px rgba(0,0,0,0.3); animation: toastIn 0.2s ease-out; max-width: 360px; }
.toast.toast-out { animation: toastOut 0.2s ease-in forwards; }
.toast-error { border-color: var(--danger); }
.toast-success { border-color: #6fcf6f; }
.toast .toast-undo { color: var(--accent2); cursor: pointer; font-weight: 600; white-space: nowrap; }
.toast .toast-undo:hover { text-decoration: underline; }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toastOut { from { opacity: 1; } to { opacity: 0; transform: translateY(10px); } }

/* Save indicator */
#save-indicator { font-size: 12px; color: #6fcf6f; transition: opacity 0.3s; }
#save-indicator.saving { color: var(--text2); }
#save-indicator.hidden { display: none; }

/* Keyboard shortcuts modal */
#shortcuts-modal { position: fixed; inset: 0; background: rgba(0,0,0,0.6); z-index: 9999; display: flex; align-items: center; justify-content: center; }
#shortcuts-modal.hidden { display: none; }
#shortcuts-modal .modal-content { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 24px; max-width: 480px; width: 90%; max-height: 80vh; overflow-y: auto; }
#shortcuts-modal h2 { margin-bottom: 16px; font-size: 18px; }
#shortcuts-modal .shortcut-row { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
#shortcuts-modal .shortcut-row:last-child { border-bottom: none; }
#shortcuts-modal kbd { background: var(--surface2); border: 1px solid var(--border); border-radius: 4px; padding: 2px 6px; font-family: monospace; font-size: 12px; }

/* Theme toggle */
/* Theme toggle - now uses .toolbar-btn */

/* Skeleton loading */
.skeleton { background: linear-gradient(90deg, var(--surface2) 25%, var(--border) 50%, var(--surface2) 75%); background-size: 200% 100%; animation: skeleton-pulse 1.5s infinite; border-radius: 4px; }
.skeleton-row { height: 28px; margin: 6px 12px; }
.skeleton-block { height: 120px; margin: 16px; border-radius: 8px; }
@keyframes skeleton-pulse { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* Comment badge */
#comment-toggle-btn { position: relative; }
#comment-badge { position: absolute; top: -4px; right: -4px; min-width: 16px; height: 16px; background: var(--accent); color: #fff; font-size: 10px; font-weight: 700; border-radius: 8px; display: flex; align-items: center; justify-content: center; padding: 0 4px; }
#comment-badge.hidden { display: none; }
#comment-badge.has-mentions { background: var(--danger); }

/* Clickable breadcrumbs */
#note-path { display: flex; align-items: center; gap: 2px; flex-wrap: wrap; }
#note-path .bc-seg { cursor: pointer; color: var(--text2); transition: color 0.15s; }
#note-path .bc-seg:hover { color: var(--accent2); text-decoration: underline; }
#note-path .bc-sep { color: var(--text2); margin: 0 2px; font-size: 11px; }
#note-path .bc-current { color: var(--text); }

/* Zen / focus mode */
.zen-mode #sidebar, .zen-mode #sidebar-resize, .zen-mode #sidebar-toggle, .zen-mode #editor-toolbar, .zen-mode #comments-sidebar, .zen-mode #mobile-nav, .zen-mode #folder-browser, .zen-mode #empty-state, .zen-mode #search-results, .zen-mode #libraries-screen, .zen-mode #editor-feedback-bar { display: none !important; }
.zen-mode #app-workspace, .zen-mode #main, .zen-mode #editor-area { display: flex !important; flex: 1 !important; flex-direction: column !important; }
.zen-mode #editor-area { border: none !important; }
.zen-mode .tox .tox-editor-header { display: none !important; }
.zen-mode #tinymce-wrap { max-width: 740px; margin: 0 auto; width: 100%; flex: 1; display: flex; flex-direction: column; }
.zen-mode #tinymce-wrap .tox-tinymce { flex: 1 !important; height: 100% !important; }
.zen-mode #tinymce-wrap .tox .tox-edit-area { flex: 1; }
#zen-exit { position: fixed; top: 12px; right: 16px; z-index: 9999; background: var(--surface2); border: 1px solid var(--border); border-radius: 8px; padding: 6px 14px; color: var(--text2); font-size: 12px; cursor: pointer; display: none; }
.zen-mode #zen-exit { display: block; }
#zen-btn { position: relative; }

/* Mention notifications */
#mentions-btn { position: relative; }
#mentions-btn .mention-count { position: absolute; top: -6px; right: -6px; min-width: 16px; height: 16px; background: var(--danger); color: #fff; font-size: 10px; font-weight: 700; border-radius: 8px; display: flex; align-items: center; justify-content: center; padding: 0 4px; }
#mentions-panel { position: absolute; top: 100%; right: 0; width: 320px; max-height: 400px; overflow-y: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 4px 16px rgba(0,0,0,0.3); z-index: 100; margin-top: 4px; }
.mention-item { padding: 10px 14px; border-bottom: 1px solid var(--border); cursor: pointer; font-size: 13px; }
.mention-item:hover { background: var(--surface2); }
.mention-item .mi-note { font-weight: 600; }
.mention-item .mi-text { color: var(--text2); margin-top: 2px; font-size: 12px; }
.mention-item .mi-meta { color: var(--text2); font-size: 11px; margin-top: 2px; }

/* Desktop: hide overflow menu, show individual buttons */
@media (min-width: 769px) {
  #toolbar-overflow { display: none; }
}

/* --- Smooth CSS transitions --- */
#sidebar { transition: width 0.2s ease, min-width 0.2s ease; }
#sidebar.collapsed { transition: width 0.2s ease, min-width 0.2s ease; }
#comments-sidebar { transition: width 0.2s ease, min-width 0.2s ease; }
#help-modal { transition: opacity 0.15s ease; }
#sidebar-toggle { transition: background 0.15s ease, color 0.15s ease; }
.lib-card { transition: border-color 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease; }
.lib-card:hover { box-shadow: 0 4px 16px rgba(0,0,0,0.3); }
.tree-row { transition: background 0.1s ease; }
.toolbar-btn { transition: background 0.15s ease, color 0.15s ease; }
.ctx-item { transition: background 0.1s ease; }
.toast { transition: opacity 0.2s ease, transform 0.2s ease; }

/* --- Presence indicator --- */
#presence-indicator { display: flex; gap: 4px; align-items: center; }
#presence-indicator.hidden { display: none; }
.presence-dot { width: 24px; height: 24px; border-radius: 50%; background: var(--accent); color: #fff; font-size: 9px; font-weight: 700; display: flex; align-items: center; justify-content: center; cursor: default; }

/* --- Feedback bar --- */
#feedback-bar, #editor-feedback-bar { display: flex; gap: 8px; padding: 8px 16px; border-top: 1px solid var(--border); }
#feedback-bar { margin-top: 24px; padding: 16px 0 0; }
#feedback-input, #editor-feedback-input { flex: 1; padding: 8px 12px; background: var(--surface); border: 1px solid var(--border); border-radius: 6px; color: var(--text); font-size: 13px; outline: none; }
#feedback-input:focus, #editor-feedback-input:focus { border-color: var(--accent); }
#feedback-bar button, #editor-feedback-bar button { padding: 8px 16px; background: var(--accent); border: none; border-radius: 6px; color: #fff; font-size: 13px; cursor: pointer; font-weight: 600; }
#feedback-bar button:hover, #editor-feedback-bar button:hover { opacity: 0.9; }
#editor-feedback-bar { flex-shrink: 0; background: var(--surface); }

/* --- Favicon badge (canvas-generated, no CSS needed) --- */

/* --- Admin panel --- */
#admin-panel { flex: 1; padding: 40px; overflow-y: auto; }
#admin-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; }
#admin-header h2 { font-size: 20px; }
#admin-header button { padding: 8px 16px; background: var(--surface2); border: 1px solid var(--border); border-radius: 6px; color: var(--text2); font-size: 13px; cursor: pointer; }
#admin-header button:hover { background: var(--danger); color: #fff; border-color: var(--danger); }
#admin-content { display: flex; flex-direction: column; gap: 32px; }
#admin-users h3, #admin-feedback h3 { font-size: 16px; margin-bottom: 12px; color: var(--text2); }
#admin-user-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.admin-user-row { display: flex; align-items: center; justify-content: space-between; padding: 8px 12px; background: var(--surface); border: 1px solid var(--border); border-radius: 6px; font-size: 13px; }
.admin-user-row .admin-tag { font-size: 10px; background: var(--accent); color: #fff; padding: 2px 6px; border-radius: 4px; margin-left: 8px; }
.admin-user-row button { background: none; border: none; color: var(--danger); cursor: pointer; font-size: 12px; opacity: 0.6; }
.admin-user-row button:hover { opacity: 1; }
#admin-add-user { display: flex; gap: 8px; }
#admin-new-user { flex: 1; padding: 8px 12px; background: var(--surface); border: 1px solid var(--border); border-radius: 6px; color: var(--text); font-size: 13px; outline: none; }
#admin-new-user:focus { border-color: var(--accent); }
#admin-add-user button { padding: 8px 16px; background: var(--accent); border: none; border-radius: 6px; color: #fff; font-size: 13px; cursor: pointer; font-weight: 600; }
.admin-fb-row { padding: 10px 12px; background: var(--surface); border: 1px solid var(--border); border-radius: 6px; margin-bottom: 6px; font-size: 13px; }
.admin-fb-row .fb-meta { font-size: 11px; color: var(--text2); margin-top: 4px; }
.admin-fb-row .fb-delete { float: right; background: none; border: none; color: var(--danger); cursor: pointer; font-size: 11px; opacity: 0.6; }
.admin-fb-row .fb-delete:hover { opacity: 1; }

/* --- Access denied --- */
#access-denied { display: flex; align-items: center; justify-content: center; flex: 1; }
#access-denied-box { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 40px; text-align: center; max-width: 400px; }
#access-denied-box h2 { margin-bottom: 12px; font-size: 20px; }
#access-denied-box p { color: var(--text2); font-size: 14px; margin-bottom: 20px; line-height: 1.6; }
#access-denied-box button { padding: 10px 24px; background: var(--surface2); border: 1px solid var(--border); border-radius: 6px; color: var(--text); font-size: 14px; cursor: pointer; }
#access-denied-box button:hover { background: var(--danger); color: #fff; border-color: var(--danger); }
