*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --sidebar-width: 260px;
  --bg: #f5f5f5;
  --sidebar-bg: #1a1a2e;
  --sidebar-text: #ccc;
  --sidebar-active: #16213e;
  --accent: #0f3460;
  --text: #333;
  --border: #ddd;
  --danger: #e74c3c;
}



body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}

.layout { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-header {
  padding: 16px;
  border-bottom: 1px solid rgba(255,255,255,.1);
}

.sidebar-header h2 { font-size: 18px; margin-bottom: 8px; }

.btn-new {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 6px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  width: 100%;
}

.btn-new:hover { opacity: .85; }

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.sidebar-nav a {
  display: block;
  padding: 8px 16px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 14px;
  border-left: 3px solid transparent;
}

.sidebar-nav a:hover { background: rgba(255,255,255,.05); }
.sidebar-nav a.active {
  background: var(--sidebar-active);
  border-left-color: var(--accent);
  color: #fff;
}

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid rgba(255,255,255,.1);
}

.sidebar-footer a { color: var(--sidebar-text); font-size: 13px; text-decoration: none; }
.sidebar-footer a:hover { color: #fff; }

/* Content */
.content {
  flex: 1;
  padding: 32px;
  max-width: 960px;
}

/* Auth */
.auth-page {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  width: 100%;
}

.auth-form {
  background: #fff;
  padding: 32px;
  border-radius: 8px;
  box-shadow: 0 2px 12px rgba(0,0,0,.1);
  width: 360px;
}

.auth-form h1 { margin-bottom: 4px; font-size: 24px; }
.auth-desc { color: #666; font-size: 14px; margin-bottom: 20px; }

.auth-form input {
  width: 100%;
  padding: 10px 12px;
  margin-bottom: 12px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 14px;
}

.auth-form button {
  width: 100%;
  padding: 10px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 4px;
  font-size: 15px;
  cursor: pointer;
}

.auth-form button:hover { opacity: .9; }

/* QR */
.qr-container { text-align: center; margin-bottom: 16px; }
.qr-container img { width: 200px; height: 200px; }

/* Viewer */
.viewer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.viewer-header h1 { font-size: 28px; }

.viewer-actions { display: flex; gap: 8px; }

.btn {
  display: inline-block;
  padding: 8px 16px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 4px;
  text-decoration: none;
  font-size: 14px;
  cursor: pointer;
}

.btn:hover { opacity: .85; }
.btn-danger { background: var(--danger); }

/* Markdown rendered */
.markdown-body { line-height: 1.7; }
.markdown-body h1 { font-size: 26px; margin: 24px 0 12px; }
.markdown-body h2 { font-size: 22px; margin: 20px 0 10px; }
.markdown-body h3 { font-size: 18px; margin: 16px 0 8px; }
.markdown-body p { margin-bottom: 12px; }
.markdown-body code {
  background: #eee;
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 14px;
}
.markdown-body pre {
  background: #1a1a2e;
  color: #f8f8f2;
  padding: 16px;
  border-radius: 6px;
  overflow-x: auto;
  margin-bottom: 16px;
}
.markdown-body pre code { background: none; padding: 0; color: inherit; }
.markdown-body table {
  border-collapse: collapse;
  width: 100%;
  margin-bottom: 16px;
}
.markdown-body th, .markdown-body td {
  border: 1px solid var(--border);
  padding: 8px 12px;
  text-align: left;
}
.markdown-body th { background: #f0f0f0; font-weight: 600; }
.markdown-body blockquote {
  border-left: 4px solid var(--accent);
  padding-left: 16px;
  color: #666;
  margin-bottom: 16px;
}
.markdown-body ul, .markdown-body ol { margin: 0 0 16px 24px; }
.markdown-body a { color: var(--accent); }
.markdown-body img { max-width: 100%; }

/* Empty state */
.empty-state {
  text-align: center;
  padding: 80px 20px;
  color: #999;
}

.empty-state h2 { font-size: 22px; margin-bottom: 8px; }

/* Editor */
.editor-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.editor-header h2 { font-size: 16px; color: #666; }

.editor-toolbar { display: flex; gap: 8px; align-items: center; }

.autosave-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: #666;
  cursor: pointer;
}

.editor-container { height: calc(100vh - 64px); display: flex; flex-direction: column; }

.status-bar {
  padding: 4px 12px;
  font-size: 13px;
  color: #999;
  text-align: right;
  transition: all .3s;
}

.status-bar.saved { color: #27ae60; }
.status-bar.error { color: var(--danger); }

/* Flashes */
.flashes { margin-bottom: 16px; }
.flash {
  padding: 10px 16px;
  border-radius: 4px;
  margin-bottom: 8px;
  font-size: 14px;
}
.flash.error { background: #fdecea; color: var(--danger); border: 1px solid #f5c6cb; }
.flash.success { background: #d4edda; color: #155724; border: 1px solid #c3e6cb; }

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-content {
  background: #fff;
  padding: 24px;
  border-radius: 8px;
  width: 360px;
}

.modal-content h3 { margin-bottom: 16px; }
.modal-content input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 14px;
  margin-bottom: 16px;
}

.modal-actions { display: flex; gap: 8px; justify-content: flex-end; }
.modal-actions button {
  padding: 8px 16px;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: #fff;
  cursor: pointer;
  font-size: 14px;
}
.modal-actions button[type="submit"] { background: var(--accent); color: #fff; border: none; }
.modal-actions button:hover { opacity: .85; }

/* Tree / Notebook sidebar */
.sidebar-nav ul { list-style: none; padding-left: 0; }
.sidebar-nav ul ul { padding-left: 16px; }

.sidebar-nav li { margin: 0; }

.nb-header {
  display: flex;
  align-items: center;
  padding: 6px 12px;
  cursor: pointer;
  font-size: 13px;
  color: var(--sidebar-text);
  user-select: none;
}

.nb-header:hover { background: rgba(255,255,255,.05); }

.nb-icon {
  font-size: 10px;
  margin-right: 6px;
  width: 10px;
  text-align: center;
  flex-shrink: 0;
}

.nb-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.nb-actions { opacity: 0; margin-left: 4px; flex-shrink: 0; }
.nb-header:hover .nb-actions { opacity: 1; }

.nb-add {
  background: none;
  border: none;
  color: var(--sidebar-text);
  cursor: pointer;
  font-size: 14px;
  padding: 0 4px;
  line-height: 1;
}
.nb-add:hover { color: #fff; }

.nb-children.hidden { display: none; }

.nb-header.open + .nb-children { display: block; }

.sidebar-nav li > a {
  display: block;
  padding: 6px 12px 6px 28px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 13px;
  border-left: 3px solid transparent;
}

.sidebar-nav li > a:hover { background: rgba(255,255,255,.05); }
.sidebar-nav li > a.active {
  background: var(--sidebar-active);
  border-left-color: var(--accent);
  color: #fff;
}

.sidebar-actions { display: flex; gap: 4px; margin-top: 8px; }
.sidebar-actions .btn-new { flex: 1; font-size: 12px; padding: 5px 8px; }

/* Note list (inside a notebook) */
.note-list { display: flex; flex-direction: column; gap: 4px; }
.note-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: #fff;
  border-radius: 6px;
  text-decoration: none;
  color: var(--text);
  border: 1px solid var(--border);
  transition: box-shadow .15s;
}
.note-item:hover { box-shadow: 0 2px 8px rgba(0,0,0,.08); }

/* Multi-select */
.note-link.selected {
  background: rgba(15,52,96,.3) !important;
  border-left-color: #e67e22 !important;
  color: #fff !important;
}

/* Drag & drop */
.drag-over {
  outline: 2px dashed #e67e22;
  outline-offset: -2px;
  border-radius: 4px;
}

.note-link[draggable="true"] {
  cursor: grab;
}
.note-link[draggable="true"]:active {
  cursor: grabbing;
  opacity: .7;
}

/* Selection bar */
.selection-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  background: var(--accent);
  border-bottom: 1px solid rgba(255,255,255,.1);
  flex-wrap: wrap;
}

.sel-count {
  font-size: 12px;
  color: #fff;
  margin-right: auto;
}

.btn-small {
  padding: 4px 8px;
  background: rgba(255,255,255,.15);
  color: #fff;
  border: 1px solid rgba(255,255,255,.2);
  border-radius: 3px;
  cursor: pointer;
  font-size: 11px;
}
.btn-small:hover { background: rgba(255,255,255,.25); }
.btn-small.btn-danger { background: var(--danger); border-color: var(--danger); }

/* Move dialog select */
#move-target {
  background: #f5f5f5;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px;
  font-size: 14px;
}
#move-target option { padding: 6px 8px; }
#move-target option:hover { background: var(--accent); color: #fff; }
.note-icon { font-size: 18px; }
.note-title { font-size: 15px; font-weight: 500; }
