/* ═══════════════════════════════════════════════════════════════════════════
   YEMA STUDIO – Main Stylesheet
   ═══════════════════════════════════════════════════════════════════════════ */

/* ─── CSS Variables ──────────────────────────────────────────────────────── */
:root {
  --bg-0: #0f0f10;
  --bg-1: #161618;
  --bg-2: #1e1e21;
  --bg-3: #27272b;
  --bg-4: #313136;
  --text-0: #f0f0f2;
  --text-1: #c0c0c8;
  --text-2: #80808a;
  --text-3: #505058;
  --accent: #7c6af7;
  --accent-hover: #9585ff;
  --accent-muted: rgba(124,106,247,0.15);
  --danger: #f7506a;
  --success: #5cf790;
  --warning: #f7c250;
  --border: rgba(255,255,255,0.07);
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.4);
  --shadow-md: 0 8px 24px rgba(0,0,0,0.5);
  --shadow-lg: 0 16px 48px rgba(0,0,0,0.6);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-mono: 'Cascadia Code', 'Fira Code', monospace;
  --sidebar-w: 260px;
  --topbar-h: 52px;
  --transition: 180ms ease;
}

[data-theme="light"] {
  --bg-0: #f8f8fa;
  --bg-1: #ffffff;
  --bg-2: #f0f0f4;
  --bg-3: #e4e4ea;
  --bg-4: #d8d8e0;
  --text-0: #111114;
  --text-1: #383842;
  --text-2: #70707a;
  --text-3: #a0a0aa;
  --border: rgba(0,0,0,0.08);
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.08);
  --shadow-md: 0 8px 24px rgba(0,0,0,0.12);
  --shadow-lg: 0 16px 48px rgba(0,0,0,0.16);
}

/* ─── Reset ──────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: var(--font);
  font-size: 14px;
  color: var(--text-0);
  background: var(--bg-0);
  display: flex;
}
button { font-family: var(--font); cursor: pointer; border: none; background: none; }
input, textarea { font-family: var(--font); }
ul { list-style: none; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ─── Scrollbar ──────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg-4); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-3); }

/* ═══════════════════════════════════════════════════════════════════════════
   SIDEBAR
   ═══════════════════════════════════════════════════════════════════════════ */
#sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  height: 100%;
  background: var(--bg-1);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: width var(--transition), min-width var(--transition), opacity var(--transition);
  overflow: hidden;
  position: relative;
  z-index: 10;
}

#sidebar.collapsed {
  width: 0;
  min-width: 0;
  opacity: 0;
  pointer-events: none;
}

/* Sidebar Header */
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 14px 12px;
  flex-shrink: 0;
}
.workspace-logo {
  display: flex;
  align-items: center;
  gap: 8px;
}
.logo-icon {
  width: 28px; height: 28px;
  background: var(--accent);
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 14px;
  color: #fff;
  font-weight: bold;
}
.logo-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-0);
  white-space: nowrap;
}

/* Search */
.sidebar-search {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 10px 8px;
  padding: 8px 10px;
  background: var(--bg-2);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  flex-shrink: 0;
}
.sidebar-search i { color: var(--text-2); font-size: 12px; flex-shrink: 0; }
.sidebar-search input {
  background: none;
  border: none;
  outline: none;
  font-size: 13px;
  color: var(--text-0);
  width: 100%;
}
.sidebar-search input::placeholder { color: var(--text-2); }

/* Quick actions */
.sidebar-quick {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0 10px 8px;
  flex-shrink: 0;
}
.quick-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-1);
  font-size: 13px;
  transition: background var(--transition), color var(--transition);
}
.quick-btn:hover {
  background: var(--bg-3);
  color: var(--text-0);
}
.quick-btn i { width: 16px; text-align: center; color: var(--text-2); }

/* Nav */
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 0 6px;
}
.nav-section-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-3);
  padding: 4px 8px 4px;
  margin-bottom: 2px;
}
#pages-list { display: flex; flex-direction: column; gap: 1px; }

.page-item {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-1);
  font-size: 13px;
  transition: background var(--transition), color var(--transition);
  position: relative;
  user-select: none;
}
.page-item:hover { background: var(--bg-2); color: var(--text-0); }
.page-item.active { background: var(--accent-muted); color: var(--accent); }
.page-item .page-icon { font-size: 14px; flex-shrink: 0; width: 18px; text-align: center; }
.page-item .page-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.page-item .page-type-tag {
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 3px;
  background: var(--bg-4);
  color: var(--text-2);
  flex-shrink: 0;
}
.page-item .page-more {
  opacity: 0;
  flex-shrink: 0;
  padding: 2px 4px;
  border-radius: 4px;
  color: var(--text-2);
  font-size: 12px;
  transition: opacity var(--transition);
}
.page-item:hover .page-more { opacity: 1; }
.page-item .page-more:hover { background: var(--bg-4); color: var(--text-0); }

/* Sidebar Footer */
.sidebar-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.sync-dot {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
}
.sync-dot i { font-size: 8px; }
.sync-connecting { color: var(--warning); }
.sync-online { color: var(--success); }
.sync-offline { color: var(--danger); }

/* ═══════════════════════════════════════════════════════════════════════════
   MAIN
   ═══════════════════════════════════════════════════════════════════════════ */
#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  background: var(--bg-0);
}

/* ─── Topbar ──────────────────────────────────────────────────────────────── */
#topbar {
  height: var(--topbar-h);
  min-height: var(--topbar-h);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-1);
  flex-shrink: 0;
}
#topbar-breadcrumb {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
#page-icon-display { font-size: 16px; flex-shrink: 0; }
#page-title-display {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-1);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.autosave-saved { color: var(--text-3); font-size: 12px; display: flex; align-items: center; gap: 5px; }
.autosave-saving { color: var(--warning); font-size: 12px; display: flex; align-items: center; gap: 5px; }

/* ─── Buttons ──────────────────────────────────────────────────────────────── */
.icon-btn {
  width: 30px; height: 30px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  font-size: 13px;
  transition: background var(--transition), color var(--transition);
}
.icon-btn:hover { background: var(--bg-3); color: var(--text-0); }
.icon-btn.danger:hover { background: rgba(247,80,106,0.12); color: var(--danger); }

.primary-btn {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 20px;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 500;
  transition: background var(--transition), transform 80ms;
}
.primary-btn:hover { background: var(--accent-hover); }
.primary-btn:active { transform: scale(0.97); }

.secondary-btn {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 20px;
  background: var(--bg-3);
  color: var(--text-0);
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 500;
  border: 1px solid var(--border);
  transition: background var(--transition);
}
.secondary-btn:hover { background: var(--bg-4); }

/* ═══════════════════════════════════════════════════════════════════════════
   WELCOME SCREEN
   ═══════════════════════════════════════════════════════════════════════════ */
#welcome-screen {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
.welcome-content {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}
.welcome-logo {
  width: 72px; height: 72px;
  background: var(--accent);
  border-radius: var(--radius-lg);
  display: flex; align-items: center; justify-content: center;
  font-size: 32px;
  color: #fff;
  box-shadow: 0 8px 32px rgba(124,106,247,0.4);
  margin-bottom: 8px;
}
.welcome-content h1 { font-size: 32px; font-weight: 700; color: var(--text-0); }
.welcome-content p { color: var(--text-2); font-size: 15px; line-height: 1.6; }
.welcome-actions { display: flex; gap: 12px; margin-top: 8px; }

/* ═══════════════════════════════════════════════════════════════════════════
   NOTE EDITOR
   ═══════════════════════════════════════════════════════════════════════════ */
#note-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.note-container {
  flex: 1;
  overflow-y: auto;
  padding: 48px max(48px, calc(50% - 380px)) 0;
}

.note-container::after {
  content: '';
  display: block;
  height: 400px;
}

.note-header {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 8px;
}
.icon-picker-btn {
  font-size: 36px;
  width: 52px; height: 52px;
  border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  transition: background var(--transition);
  flex-shrink: 0;
  cursor: pointer;
  line-height: 1;
}
.icon-picker-btn:hover { background: var(--bg-3); }

.note-title {
  flex: 1;
  font-size: 36px;
  font-weight: 700;
  color: var(--text-0);
  outline: none;
  line-height: 1.2;
  padding: 6px 0;
  min-height: 52px;
  word-break: break-word;
}
.note-title:empty::before {
  content: attr(data-placeholder);
  color: var(--text-3);
  pointer-events: none;
}

/* Toolbar */
.editor-toolbar {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 6px 8px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-bottom: 16px;
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 5;
}
.toolbar-btn {
  width: 30px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--text-1);
  font-size: 13px;
  font-weight: 500;
  transition: background var(--transition), color var(--transition);
}
.toolbar-btn:hover { background: var(--bg-4); color: var(--text-0); }
.toolbar-btn.active { background: var(--accent-muted); color: var(--accent); }
.toolbar-sep {
  width: 1px;
  height: 20px;
  background: var(--border);
  margin: 0 4px;
}
#toolbar-color {
  width: 28px; height: 28px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: none;
  cursor: pointer;
}

/* Content area */
.note-content {
  flex: 1;
  outline: none;
  font-size: 15px;
  line-height: 1.75;
  color: var(--text-0);
  min-height: 400px;
  word-break: break-word;
}
.note-content:empty::before {
  content: attr(data-placeholder);
  color: var(--text-3);
  pointer-events: none;
}
.note-content h1 { font-size: 28px; font-weight: 700; margin: 20px 0 8px; }
.note-content h2 { font-size: 22px; font-weight: 600; margin: 16px 0 6px; }
.note-content h3 { font-size: 18px; font-weight: 600; margin: 14px 0 4px; }
.note-content p { margin-bottom: 10px; }
.note-content ul, .note-content ol { padding-left: 24px; margin-bottom: 10px; }
.note-content li { margin-bottom: 4px; }
.note-content blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 12px;
  color: var(--text-2);
  margin: 10px 0;
}
.note-content code {
  background: var(--bg-3);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--accent-hover);
}
.note-content pre {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px;
  margin: 12px 0;
  overflow-x: auto;
}
.note-content pre code { background: none; padding: 0; }
.note-content img { max-width: 100%; border-radius: var(--radius-md); margin: 8px 0; }
.note-content a { color: var(--accent); }

/* ═══════════════════════════════════════════════════════════════════════════
   CANVAS
   ═══════════════════════════════════════════════════════════════════════════ */
#canvas-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

.canvas-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background: var(--bg-1);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 20;
}
.canvas-tools {
  display: flex;
  align-items: center;
  gap: 2px;
}
.canvas-tool {
  width: 34px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  font-size: 13px;
  transition: background var(--transition), color var(--transition);
}
.canvas-tool:hover { background: var(--bg-3); color: var(--text-0); }
.canvas-tool.active { background: var(--accent-muted); color: var(--accent); }
.canvas-info { font-size: 12px; color: var(--text-2); }

.canvas-header-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 20px 4px;
  flex-shrink: 0;
  background: var(--bg-0);
  z-index: 5;
  position: relative;
}
.canvas-header-bar .icon-picker-btn { font-size: 24px; width: 36px; height: 36px; }
.canvas-title-input {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-0);
  outline: none;
}
.canvas-title-input:empty::before {
  content: attr(data-placeholder);
  color: var(--text-3);
  pointer-events: none;
}

/* Canvas container */
#canvas-container {
  flex: 1;
  position: relative;
  overflow: hidden;
  cursor: default;
  background: var(--bg-0);
}
#canvas-container.panning { cursor: grabbing; }
#canvas-container.tool-text { cursor: crosshair; }
#canvas-container.tool-sticky { cursor: crosshair; }
#canvas-container.tool-shape { cursor: crosshair; }
#canvas-container.tool-arrow { cursor: crosshair; }
#canvas-container.tool-image { cursor: crosshair; }

/* Dot grid background */
#canvas-bg {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none;
}

/* Canvas world (transforms applied here) */
#canvas-world {
  position: absolute;
  top: 0; left: 0;
  transform-origin: 0 0;
  width: 1px; height: 1px;
  overflow: visible;
}

/* SVG arrows layer */
#canvas-arrows {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  overflow: visible;
}

/* ─── Canvas Nodes ───────────────────────────────────────────────────────── */
.cn {
  position: absolute;
  user-select: none;
  transform-origin: top left;
  box-sizing: border-box;
}

/* Text node */
.cn-text {
  min-width: 120px;
  min-height: 40px;
  padding: 10px 14px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-0);
  box-shadow: var(--shadow-sm);
  cursor: move;
}
.cn-text.selected { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-muted); }

/* Sticky note */
.cn-sticky {
  min-width: 160px;
  min-height: 120px;
  padding: 12px;
  border-radius: var(--radius-md);
  cursor: move;
  box-shadow: var(--shadow-md);
}
.cn-sticky.selected { outline: 2px solid var(--accent); }

/* Sticky colors */
.cn-sticky.color-yellow { background: #2d2a12; color: #f7e06a; }
.cn-sticky.color-blue   { background: #0d1a2d; color: #6ab4f7; }
.cn-sticky.color-green  { background: #0d2016; color: #6af7a8; }
.cn-sticky.color-pink   { background: #2d0d1a; color: #f76ab4; }
.cn-sticky.color-purple { background: #1a0d2d; color: #b46af7; }

[data-theme="light"] .cn-sticky.color-yellow { background: #fef9c3; color: #92400e; }
[data-theme="light"] .cn-sticky.color-blue   { background: #dbeafe; color: #1d4ed8; }
[data-theme="light"] .cn-sticky.color-green  { background: #dcfce7; color: #166534; }
[data-theme="light"] .cn-sticky.color-pink   { background: #fce7f3; color: #9d174d; }
[data-theme="light"] .cn-sticky.color-purple { background: #ede9fe; color: #6d28d9; }

/* Shared inner content - overflow here instead of on the parent so resize handle/ports aren't clipped */
.cn-inner {
  width: 100%;
  height: 100%;
  overflow: hidden;
  word-break: break-word;
  white-space: pre-wrap;
  font-size: 14px;
  line-height: 1.5;
  pointer-events: none;
  border-radius: inherit;
}

/* Text edit textarea overlay - colors set dynamically to match the node */
.cn-edit-textarea {
  position: fixed;
  z-index: 2000;
  border: 2px solid var(--accent);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  resize: none;
  outline: none;
  box-sizing: border-box;
  box-shadow: 0 0 0 3px var(--accent-muted);
  overflow: auto;
}

/* Shape */
.cn-shape {
  min-width: 80px; min-height: 60px;
  background: var(--accent-muted);
  border: 2px solid var(--accent);
  border-radius: var(--radius-md);
  cursor: move;
  display: flex; align-items: center; justify-content: center;
  color: var(--accent);
  font-weight: 500;
  padding: 8px;
  text-align: center;
}
.cn-shape.selected { box-shadow: 0 0 0 2px var(--accent); }
.cn-shape .cn-inner { text-align: center; display:flex; align-items:center; justify-content:center; }

/* Image node */
.cn-image {
  cursor: move;
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-md);
  min-width: 80px; min-height: 60px;
  background: var(--bg-2);
  border: 1px solid var(--border);
}
.cn-image img {
  width: 100%; height: 100%;
  object-fit: contain;
  display: block;
  pointer-events: none;
}
.cn-image.selected { outline: 2px solid var(--accent); }

/* Resize handle */
.cn-resize {
  position: absolute;
  right: -5px; bottom: -5px;
  width: 12px; height: 12px;
  background: var(--accent);
  border-radius: 2px;
  cursor: se-resize;
  opacity: 0;
  transition: opacity var(--transition);
}
.cn:hover .cn-resize, .cn.selected .cn-resize { opacity: 1; }

/* Connection port */
.cn-port {
  position: absolute;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg-1);
  cursor: crosshair;
  opacity: 0;
  transition: opacity var(--transition);
  z-index: 10;
}
.cn:hover .cn-port, .cn.selected .cn-port { opacity: 1; }
.cn-port.port-top    { top: -5px;    left: 50%;      transform: translateX(-50%); }
.cn-port.port-bottom { bottom: -5px; left: 50%;      transform: translateX(-50%); }
.cn-port.port-left   { left: -5px;   top: 50%;       transform: translateY(-50%); }
.cn-port.port-right  { right: -5px;  top: 50%;       transform: translateY(-50%); }

/* Selection box */
#canvas-selection-box {
  position: absolute;
  border: 1.5px solid var(--accent);
  background: var(--accent-muted);
  pointer-events: none;
  z-index: 50;
  display: none;
}

/* ─── Arrow temp line ───────────────────────────────────────────────────── */
#arrow-temp-line {
  stroke: var(--accent);
  stroke-width: 2;
  stroke-dasharray: 6 4;
  fill: none;
  marker-end: url(#arrowhead);
}

/* ═══════════════════════════════════════════════════════════════════════════
   MODALS
   ═══════════════════════════════════════════════════════════════════════════ */
.modal {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(4px);
  z-index: 1000;
  animation: fadeIn 150ms ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }

.modal-box {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  animation: slideUp 150ms ease;
  overflow: hidden;
}
.modal-box.small { width: 380px; max-height: 440px; display: flex; flex-direction: column; }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 14px;
}

/* Emoji grid */
.emoji-grid {
  padding: 12px;
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 4px;
  overflow-y: auto;
}
.emoji-btn {
  font-size: 22px;
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition), transform 80ms;
}
.emoji-btn:hover { background: var(--bg-4); transform: scale(1.15); }

/* ─── Context menu ───────────────────────────────────────────────────────── */
#context-menu {
  position: fixed;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  z-index: 2000;
  overflow: hidden;
  min-width: 160px;
  animation: slideUp 120ms ease;
}
#context-menu ul { padding: 4px; }
#context-menu li {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  cursor: pointer;
  color: var(--text-1);
  transition: background var(--transition), color var(--transition);
}
#context-menu li:hover { background: var(--bg-3); color: var(--text-0); }
#context-menu li.danger:hover { background: rgba(247,80,106,0.12); color: var(--danger); }
#context-menu li i { width: 16px; text-align: center; color: var(--text-2); }
#context-menu li.danger i { color: var(--danger); }

/* ─── Animations ─────────────────────────────────────────────────────────── */
.fade-in { animation: fadeIn 200ms ease both; }

/* ─── Utility ─────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }
.no-select { user-select: none; }

/* ═══════════════════════════════════════════════════════════════════════════
   TAGS
   ═══════════════════════════════════════════════════════════════════════════ */
/* Tag row in note editor */
.note-tags-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 0 14px;
  min-height: 28px;
}
.note-tags-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.note-tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  background: var(--accent-muted);
  color: var(--accent);
  border: 1px solid rgba(124,106,247,0.3);
  cursor: default;
  user-select: none;
}
.note-tag .tag-remove {
  display: flex; align-items: center;
  cursor: pointer;
  opacity: 0.6;
  font-size: 11px;
  margin-left: 2px;
  border-radius: 50%;
  padding: 1px 2px;
  transition: opacity var(--transition), background var(--transition);
}
.note-tag .tag-remove:hover { opacity: 1; background: rgba(124,106,247,0.2); }
.note-tag-input {
  background: none;
  border: none;
  outline: none;
  font-size: 12px;
  color: var(--text-2);
  min-width: 120px;
  padding: 3px 4px;
}
.note-tag-input::placeholder { color: var(--text-3); }
.note-tag-input:focus { color: var(--text-0); }

/* Tags in sidebar */
.page-tags {
  display: flex;
  gap: 3px;
  flex-wrap: nowrap;
  overflow: hidden;
  max-width: 80px;
}
.page-tag-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
  opacity: 0.8;
}

/* ═══════════════════════════════════════════════════════════════════════════
   EXPORT MODAL
   ═══════════════════════════════════════════════════════════════════════════ */
.export-options {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.export-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  background: var(--bg-3);
  border: 1px solid var(--border);
  color: var(--text-0);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
  text-align: left;
}
.export-btn:hover { background: var(--bg-4); border-color: var(--accent); }
.export-btn i { color: var(--accent); font-size: 16px; width: 20px; text-align: center; }
.export-btn small { display: block; color: var(--text-2); font-size: 11px; font-weight: 400; margin-top: 1px; }

/* ═══════════════════════════════════════════════════════════════════════════
   PRINT STYLES (note → PDF via window.print)
   ═══════════════════════════════════════════════════════════════════════════ */
@media print {
  body > * { display: none !important; }
  body { background: #fff; color: #111; }
  #print-frame {
    display: block !important;
    position: fixed; inset: 0;
    background: #fff;
    padding: 40px 60px;
    font-family: 'Segoe UI', system-ui, sans-serif;
    font-size: 14px;
    line-height: 1.75;
    color: #111;
    overflow: visible;
  }
  #print-frame h1 { font-size: 28px; margin-bottom: 6px; }
  #print-frame .print-tags { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 18px; }
  #print-frame .print-tag {
    padding: 2px 10px; border-radius: 999px;
    background: #ede9fe; color: #5b21b6;
    font-size: 11px; font-weight: 600;
  }
}

/* ═══════════════════════════════════════════════════════════════════════════
   SIDEBAR ENHANCEMENTS: FOLDERS, PINS, DRAG, TRASH
   ═══════════════════════════════════════════════════════════════════════════ */
.nav-section-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.nav-section-label .icon-btn.tiny {
  width: 22px; height: 22px;
  font-size: 12px; opacity: 0.5;
}
.nav-section-label .icon-btn.tiny:hover { opacity: 1; }

.section-divider {
  list-style: none;
  padding: 10px 10px 2px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-3);
}

/* ── Folders (visual tree) ── */
.folder-row {
  list-style: none;
  user-select: none;
}
.folder-row-inner {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 8px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: background var(--transition);
  position: relative;
}
.folder-row-inner:hover { background: var(--bg-3); }
.folder-row.drag-over > .folder-row-inner {
  background: var(--accent-muted);
  outline: 1px dashed var(--accent);
  border-radius: var(--radius-sm);
}
.folder-icon {
  font-size: 13px;
  flex-shrink: 0;
  width: 16px;
  text-align: center;
  transition: transform var(--transition);
}
.folder-name-text {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-1);
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.folder-rename-input {
  flex: 1;
  min-width: 0;
  font-size: 12.5px;
  font-weight: 600;
  background: var(--bg-1);
  border: 1px solid var(--accent);
  color: var(--text-1);
  border-radius: 4px;
  padding: 1px 5px;
  outline: none;
  font-family: inherit;
}
.folder-count {
  font-size: 10px;
  background: var(--bg-3);
  color: var(--text-3);
  padding: 1px 6px;
  border-radius: 999px;
  flex-shrink: 0;
  min-width: 18px;
  text-align: center;
}
.folder-arrow {
  font-size: 9px;
  color: var(--text-3);
  transition: transform var(--transition);
  flex-shrink: 0;
  margin-left: 2px;
}
.folder-row.collapsed > .folder-row-inner .folder-arrow {
  transform: rotate(-90deg);
}
/* Tree children container */
.folder-children-wrap {
  position: relative;
  padding-left: 14px;
  margin-left: 10px;
  border-left: 1px solid var(--border);
  list-style: none;
  padding-bottom: 2px;
}
.folder-children-wrap .page-item {
  position: relative;
}
.folder-children-wrap .page-item::before {
  content: '';
  position: absolute;
  left: -14px;
  top: 50%;
  width: 12px;
  height: 1px;
  background: var(--border);
}
/* Folder context button */
.folder-menu-btn {
  opacity: 0;
  transition: opacity var(--transition);
  flex-shrink: 0;
}
.folder-row-inner:hover .folder-menu-btn { opacity: 1; }
/* Empty folder placeholder */
.folder-empty-hint {
  font-size: 11px;
  color: var(--text-3);
  padding: 4px 6px;
  font-style: italic;
}

/* Pin indicator */
.page-item.pinned .page-name::after {
  content: ' 📌';
  font-size: 10px;
  opacity: 0.6;
}

/* Footer actions group */
.footer-actions { display: flex; gap: 2px; align-items: center; }

/* Trash badge */
.trash-badge {
  position: absolute;
  top: 1px; right: 1px;
  min-width: 14px; height: 14px;
  background: var(--danger);
  color: #fff;
  border-radius: 999px;
  font-size: 9px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  padding: 0 3px;
  pointer-events: none;
}

/* Trash section */
.trash-header {
  padding: 6px 12px 2px;
  font-size: 11px;
  color: var(--text-2);
}
.btn-empty-trash {
  background: none; border: none;
  font-size: 11px; color: var(--danger);
  cursor: pointer; padding: 2px 6px;
  border-radius: var(--radius-sm);
  font-family: inherit;
}
.btn-empty-trash:hover { background: rgba(255,80,80,0.12); }
#trash-list .page-item { opacity: 0.65; }
#trash-list .page-restore-btn {
  background: none; border: none;
  font-size: 11px; color: var(--accent);
  cursor: pointer; padding: 2px 6px;
  border-radius: var(--radius-sm);
  white-space: nowrap; font-family: inherit;
  flex-shrink: 0;
}
#trash-list .page-restore-btn:hover { background: var(--accent-muted); }

/* Drag & drop */
.page-item.dragging { opacity: 0.35; }
.page-item.drag-over { border-top: 2px solid var(--accent); }

/* ═══════════════════════════════════════════════════════════════════════════
   NOTE FOOTER (word count)
   ═══════════════════════════════════════════════════════════════════════════ */
.note-footer {
  display: flex;
  justify-content: flex-end;
  padding: 6px 0 0;
  border-top: 1px solid var(--border);
  margin-top: 12px;
}
.word-count {
  font-size: 11px;
  color: var(--text-3);
  user-select: none;
}

/* ═══════════════════════════════════════════════════════════════════════════
   @-MENTION DROPDOWN
   ═══════════════════════════════════════════════════════════════════════════ */
.mention-dropdown {
  position: fixed;
  z-index: 5000;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  min-width: 220px;
  max-height: 240px;
  overflow-y: auto;
  padding: 4px;
}
.mention-item {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer; font-size: 13px;
  color: var(--text-0);
}
.mention-item:hover, .mention-item.active { background: var(--bg-3); }
.mention-icon { font-size: 16px; flex-shrink: 0; }
.mention-title { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mention-type {
  font-size: 10px; color: var(--text-3);
  background: var(--bg-4);
  padding: 1px 5px; border-radius: 3px;
}
a.page-link {
  color: var(--accent);
  background: var(--accent-muted);
  border-radius: 4px;
  padding: 1px 6px;
  text-decoration: none;
  font-weight: 500;
  cursor: pointer;
}
a.page-link:hover { background: rgba(124,106,247,0.3); }

/* ═══════════════════════════════════════════════════════════════════════════
   CANVAS: MINIMAP
   ═══════════════════════════════════════════════════════════════════════════ */
.minimap {
  position: absolute;
  bottom: 16px; right: 16px;
  width: 160px; height: 100px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  cursor: pointer;
  z-index: 200;
  opacity: 0.85;
  transition: opacity var(--transition);
}
.minimap:hover { opacity: 1; }

/* ═══════════════════════════════════════════════════════════════════════════
   CANVAS: MULTI-SELECT
   ═══════════════════════════════════════════════════════════════════════════ */
.cn.selected {
  box-shadow: 0 0 0 2px var(--accent), 0 4px 20px rgba(124,106,247,0.25) !important;
}

/* ═══════════════════════════════════════════════════════════════════════════
   VERSION HISTORY MODAL
   ═══════════════════════════════════════════════════════════════════════════ */
.history-list {
  padding: 12px;
  overflow-y: auto;
  flex: 1;
}
.history-empty {
  text-align: center; color: var(--text-3);
  font-size: 13px; padding: 32px 0;
}
.history-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  margin-bottom: 6px; gap: 12px;
  transition: background var(--transition);
}
.history-item:hover { background: var(--bg-3); }
.history-meta { flex: 1; min-width: 0; }
.history-date  { font-size: 12px; font-weight: 600; color: var(--text-0); display: block; }
.history-preview { font-size: 11px; color: var(--text-2); display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.history-actions { flex-shrink: 0; }
.secondary-btn.small { padding: 4px 12px; font-size: 12px; }

/* ═══════════════════════════════════════════════════════════════════════════
   ZEN MODE
   ═══════════════════════════════════════════════════════════════════════════ */
body.zen-mode #sidebar   { display: none; }
body.zen-mode #topbar    { display: none; }
body.zen-mode #main      { height: 100vh; }
body.zen-mode #btn-show-sidebar { display: none !important; }
body.zen-mode .note-container  { max-width: 740px; padding: 60px 40px 80px; }
body.zen-mode #canvas-view .canvas-toolbar,
body.zen-mode #canvas-view .canvas-header-bar {
  opacity: 0; pointer-events: none;
  transition: opacity 0.25s;
}
body.zen-mode #canvas-view:hover .canvas-toolbar,
body.zen-mode #canvas-view:hover .canvas-header-bar {
  opacity: 1; pointer-events: auto;
}

/* ═══════════════════════════════════════════════════════════════════════════
   FILE VIEWER
   ═══════════════════════════════════════════════════════════════════════════ */
#file-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.file-container {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding: 32px 40px;
  max-width: 1000px;
  width: 100%;
  margin: 0 auto;
}
.file-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
  flex-shrink: 0;
}
.file-meta {
  font-size: 12px;
  color: var(--text-3);
  margin-bottom: 16px;
  display: flex;
  gap: 12px;
  flex-shrink: 0;
}
.file-meta span { display: flex; align-items: center; gap: 4px; }
.file-content-area {
  flex: 1;
  overflow: auto;
  border-radius: var(--radius-lg);
  background: var(--bg-2);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 200px;
}
.file-content-area img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: var(--radius-md);
  display: block;
}
.file-content-area iframe {
  width: 100%;
  height: 100%;
  min-height: 500px;
  border: none;
  border-radius: var(--radius-lg);
}
.file-download-hint {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  color: var(--text-2);
  font-size: 14px;
  padding: 40px;
  text-align: center;
}
.file-download-hint i { font-size: 52px; color: var(--text-3); }
.file-download-hint .file-dl-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  transition: background var(--transition);
}
.file-download-hint .file-dl-btn:hover { background: var(--accent-hover); text-decoration: none; }

/* Import button accent */
#btn-import-file { border-top: 1px solid var(--border); margin-top: 4px; padding-top: 8px; }
#btn-import-file i { color: var(--accent); }

/* File type badge in sidebar */
.page-type-tag.type-file { background: #1e293b; color: #60a5fa; }
[data-theme="light"] .page-type-tag.type-file { background: #dbeafe; color: #1d4ed8; }

/* ── Folder picker modal ── */
.folder-picker-list {
  max-height: 260px;
  overflow-y: auto;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.folder-picker-item {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  color: var(--text-1);
  transition: background var(--transition);
  user-select: none;
}
.folder-picker-item:hover { background: var(--bg-3); color: var(--text-0); }
.folder-picker-item.active { background: var(--accent-muted); color: var(--accent); font-weight: 500; }
.folder-picker-footer { padding: 6px; border-top: 1px solid var(--border); }
.folder-picker-new-btn {
  display: flex; align-items: center; gap: 8px;
  width: 100%;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--accent);
  cursor: pointer;
  transition: background var(--transition);
  font-family: inherit;
  background: none; border: none;
}
.folder-picker-new-btn:hover { background: var(--accent-muted); }
