:root {
  --bg: #ffffff;
  --bg-alt: #f7f7f8;
  --bg-soft: #fafafa;
  --bg-hover: #ececf1;
  --bg-active: #e4e4e7;
  --border: #e5e5e7;
  --border-strong: #d1d5db;
  --text: #111827;
  --text-muted: #6b7280;
  --text-faint: #9ca3af;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: #dbeafe;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --success: #16a34a;
  --warning: #f59e0b;
  --tag-bg: #e0e7ff;
  --tag-text: #3730a3;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 10px 40px rgba(0,0,0,0.15);
}
[data-theme="dark"] {
  --bg: #1a1a1a;
  --bg-alt: #1f1f23;
  --bg-soft: #232326;
  --bg-hover: #2d2d33;
  --bg-active: #36363d;
  --border: #2d2d33;
  --border-strong: #3a3a40;
  --text: #f3f4f6;
  --text-muted: #9ca3af;
  --text-faint: #6b7280;
  --accent: #3b82f6;
  --accent-hover: #60a5fa;
  --accent-soft: #1e3a8a;
  --danger: #ef4444;
  --danger-soft: #450a0a;
  --success: #22c55e;
  --warning: #fbbf24;
  --tag-bg: #312e81;
  --tag-text: #c7d2fe;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
  --shadow-lg: 0 10px 40px rgba(0,0,0,0.6);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

button { font-family: inherit; font-size: inherit; cursor: pointer; }
input, textarea { font-family: inherit; font-size: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* === AUTH === */
.auth-screen {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.auth-card {
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-lg);
}
.auth-icon { text-align: center; font-size: 48px; margin-bottom: 8px; }
.auth-card h2 { text-align: center; margin-bottom: 8px; font-size: 22px; }
.auth-card p { text-align: center; color: var(--text-muted); font-size: 14px; margin-bottom: 24px; line-height: 1.5; }
.auth-card input {
  width: 100%; padding: 12px 14px; border: 1px solid var(--border);
  border-radius: 8px; background: var(--bg); font-size: 14px; outline: none; margin-bottom: 12px;
}
.auth-card input:focus { border-color: var(--accent); }
.auth-card button {
  width: 100%; padding: 12px; background: var(--accent); color: white;
  border: none; border-radius: 8px; font-size: 14px; font-weight: 600;
}
.auth-card button:hover { background: var(--accent-hover); }
.auth-card button:disabled { opacity: 0.6; cursor: wait; }
.auth-error { color: var(--danger); font-size: 13px; text-align: center; margin-bottom: 12px; min-height: 18px; }
.auth-warning {
  background: var(--danger-soft); border: 1px solid var(--danger); color: var(--danger);
  padding: 10px; border-radius: 6px; font-size: 12px; margin-top: 16px; line-height: 1.4;
}
.auth-actions { display: flex; gap: 8px; margin-top: 12px; }
.btn-secondary {
  background: transparent !important; color: var(--text-muted) !important;
  border: 1px solid var(--border) !important;
}
.btn-secondary:hover {
  background: var(--bg-hover) !important; color: var(--text) !important;
}
.pwd-strength { height: 4px; background: var(--border); border-radius: 2px; overflow: hidden; margin: -8px 0 12px; }
.pwd-strength-bar { height: 100%; transition: width .2s, background .2s; width: 0; background: var(--danger); }

/* === APP LAYOUT === */
.app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* === SIDEBAR === */
.sidebar {
  width: 280px;
  border-right: 1px solid var(--border);
  background: var(--bg-alt);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}
.sidebar-top {
  padding: 12px;
  border-bottom: 1px solid var(--border);
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 6px;
  margin-bottom: 8px;
}
.brand-icon { font-size: 20px; }
.brand-name { font-weight: 700; font-size: 16px; flex: 1; }
.icon-btn {
  background: none; border: none; color: var(--text); padding: 6px;
  border-radius: 6px; display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:hover { background: var(--bg-hover); }
.search-wrap { position: relative; }
.search-wrap input {
  width: 100%; padding: 7px 10px; border: 1px solid var(--border);
  border-radius: 6px; background: var(--bg); font-size: 13px; outline: none;
}
.search-wrap input:focus { border-color: var(--accent); }
.search-results {
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: var(--shadow-md);
  max-height: 400px;
  overflow-y: auto;
  z-index: 100;
}
.search-results:empty { display: none; }
.search-result {
  padding: 8px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}
.search-result:last-child { border-bottom: none; }
.search-result:hover { background: var(--bg-hover); }
.search-result-title { font-weight: 500; font-size: 13px; margin-bottom: 2px; }
.search-result-meta { font-size: 11px; color: var(--text-muted); }
.search-result mark {
  background: var(--warning); color: var(--text); padding: 0 2px; border-radius: 2px;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 8px 6px;
}
.nav-section-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-faint);
  padding: 12px 10px 4px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  color: var(--text);
  margin-bottom: 1px;
  transition: background 0.1s;
}
.nav-item:hover { background: var(--bg-hover); }
.nav-item.active { background: var(--bg-active); font-weight: 500; }
.nav-item-icon { font-size: 15px; flex-shrink: 0; width: 20px; text-align: center; }
.nav-item-title {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.nav-item-pin { color: var(--warning); font-size: 12px; }

.sidebar-bottom {
  padding: 8px;
  border-top: 1px solid var(--border);
  position: relative;
}
.add-page-btn {
  width: 100%; padding: 8px; background: var(--accent); color: white;
  border: none; border-radius: 6px; font-weight: 500; font-size: 13px;
  margin-bottom: 6px;
}
.add-page-btn:hover { background: var(--accent-hover); }
.add-page-menu {
  position: absolute;
  bottom: calc(100% - 4px);
  left: 8px; right: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow-md);
  padding: 4px;
  z-index: 50;
}
.add-page-menu button {
  width: 100%; text-align: left; padding: 8px 10px;
  background: none; border: none; color: var(--text);
  border-radius: 4px; font-size: 13px;
}
.add-page-menu button:hover { background: var(--bg-hover); }
.sidebar-actions {
  display: flex;
  gap: 4px;
  justify-content: center;
}

/* === MAIN === */
.main {
  flex: 1;
  overflow-y: auto;
  background: var(--bg);
  display: flex;
  flex-direction: column;
}

/* Page header (shared by all page types) */
.page-header {
  padding: 24px 48px 12px;
  border-bottom: 1px solid var(--border);
}
.page-meta-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  color: var(--text-muted);
  font-size: 12px;
}
.page-meta-row .grow { flex: 1; }
.page-title-row {
  display: flex;
  align-items: center;
  gap: 12px;
}
.page-icon-btn {
  font-size: 36px;
  background: none; border: none;
  padding: 4px; border-radius: 6px;
  line-height: 1;
}
.page-icon-btn:hover { background: var(--bg-hover); }
.page-title-input {
  flex: 1;
  border: none;
  background: none;
  font-size: 32px;
  font-weight: 700;
  outline: none;
  color: var(--text);
  padding: 4px 0;
}
.page-action-btn {
  padding: 6px 12px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
}
.page-action-btn:hover { background: var(--bg-hover); }
.page-action-btn.danger { color: var(--danger); border-color: var(--border); }
.page-action-btn.danger:hover { background: var(--danger); color: white; border-color: var(--danger); }
.page-action-btn.active { background: var(--accent); color: white; border-color: var(--accent); }

.page-body {
  flex: 1;
  padding: 24px 48px;
}

/* === DASHBOARD === */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
  margin-top: 20px;
}
.widget {
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
}
.widget h3 {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 12px;
}
.widget-stat {
  font-size: 32px;
  font-weight: 700;
  color: var(--text);
}
.widget-stat-label {
  font-size: 12px;
  color: var(--text-muted);
}
.widget-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.widget-list-item {
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}
.widget-list-item:hover { background: var(--bg-hover); }
.widget-list-item-meta {
  margin-left: auto;
  color: var(--text-faint);
  font-size: 11px;
}
.dashboard-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
}
.stat-card {
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
}

/* === DOC === */
.doc-toolbar {
  display: flex;
  gap: 4px;
  padding: 6px 48px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-alt);
}
.doc-body {
  flex: 1;
  display: flex;
  overflow: hidden;
  min-height: 0;
}
.doc-pane, .doc-preview {
  flex: 1;
  overflow-y: auto;
  padding: 20px 48px;
}
.doc-pane { border-right: 1px solid var(--border); }
.doc-pane textarea {
  width: 100%;
  min-height: 100%;
  border: none;
  background: none;
  font-family: "SF Mono", "Monaco", Consolas, monospace;
  font-size: 14px;
  line-height: 1.65;
  outline: none;
  resize: none;
}
.doc-preview h1 { font-size: 28px; margin: 16px 0 10px; }
.doc-preview h2 { font-size: 22px; margin: 16px 0 8px; }
.doc-preview h3 { font-size: 18px; margin: 14px 0 6px; }
.doc-preview p { line-height: 1.65; margin: 8px 0; }
.doc-preview code {
  background: var(--bg-alt); padding: 2px 6px; border-radius: 4px;
  font-family: "SF Mono", Monaco, Consolas, monospace; font-size: 13px;
}
.doc-preview pre {
  background: var(--bg-alt); padding: 12px; border-radius: 6px;
  overflow-x: auto; margin: 10px 0;
}
.doc-preview pre code { background: none; padding: 0; }
.doc-preview ul, .doc-preview ol { margin: 8px 0 8px 24px; }
.doc-preview blockquote {
  border-left: 3px solid var(--border-strong);
  padding-left: 14px;
  color: var(--text-muted);
  margin: 10px 0;
}
.doc-preview table { border-collapse: collapse; margin: 10px 0; }
.doc-preview th, .doc-preview td { border: 1px solid var(--border); padding: 6px 12px; }
.doc-pane.full { border-right: none; }
.doc-preview.hidden { display: none; }

/* === BOOKMARKS === */
.bookmarks-toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.bookmarks-toolbar input {
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  outline: none;
  font-size: 13px;
}
.bookmarks-toolbar input:focus { border-color: var(--accent); }
.bookmarks-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}
.bookmark-card {
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: relative;
  transition: border-color 0.1s, transform 0.1s;
}
.bookmark-card:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}
.bookmark-header {
  display: flex;
  align-items: center;
  gap: 8px;
}
.bookmark-favicon {
  width: 18px; height: 18px;
  border-radius: 4px;
  background: var(--bg-soft);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px;
  flex-shrink: 0;
}
.bookmark-title {
  font-weight: 600;
  font-size: 14px;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.bookmark-actions {
  display: none;
  gap: 4px;
}
.bookmark-card:hover .bookmark-actions { display: flex; }
.bookmark-url {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.bookmark-url a { color: inherit; }
.bookmark-desc {
  font-size: 13px;
  color: var(--text);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.bookmark-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
}
.tag-pill {
  background: var(--tag-bg);
  color: var(--tag-text);
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
}
.tag-pill.clickable { cursor: pointer; }
.tag-pill.active { outline: 2px solid var(--accent); }

/* === TASKS / KANBAN === */
.kanban {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  overflow-x: auto;
  padding-bottom: 16px;
}
.kanban-col {
  flex: 0 0 280px;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 75vh;
}
.kanban-col-header {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
}
.kanban-col-title {
  font-weight: 600;
  font-size: 14px;
  flex: 1;
  display: flex;
  align-items: center;
  gap: 6px;
}
.kanban-col-count {
  background: var(--bg-soft);
  color: var(--text-muted);
  border-radius: 10px;
  padding: 1px 8px;
  font-size: 11px;
  font-weight: 500;
}
.kanban-col-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow-y: auto;
  flex: 1;
}
.task-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
  cursor: pointer;
  font-size: 13px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.task-card:hover { border-color: var(--accent); }
.task-title {
  font-weight: 500;
}
.task-meta {
  display: flex;
  gap: 6px;
  align-items: center;
  font-size: 11px;
  color: var(--text-muted);
}
.task-priority {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
}
.task-priority.high { background: var(--danger); }
.task-priority.med { background: var(--warning); }
.task-priority.low { background: var(--success); }
.task-due { font-size: 11px; }
.task-due.overdue { color: var(--danger); font-weight: 500; }
.task-card.done { opacity: 0.6; }
.task-card.done .task-title { text-decoration: line-through; }
.kanban-add {
  background: none;
  border: 1px dashed var(--border-strong);
  color: var(--text-muted);
  padding: 8px;
  border-radius: 6px;
  font-size: 12px;
}
.kanban-add:hover {
  background: var(--bg-hover);
  color: var(--text);
}

/* === BOARD (sticky notes) === */
.board {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}
.sticky {
  background: #fef3c7;
  color: #1f2937;
  padding: 14px;
  border-radius: 6px;
  box-shadow: var(--shadow-sm);
  min-height: 140px;
  font-size: 13px;
  white-space: pre-wrap;
  line-height: 1.5;
  position: relative;
  cursor: pointer;
}
.sticky:nth-child(4n+1) { background: #fef3c7; }
.sticky:nth-child(4n+2) { background: #dcfce7; }
.sticky:nth-child(4n+3) { background: #dbeafe; }
.sticky:nth-child(4n+4) { background: #fce7f3; }
.sticky-actions {
  position: absolute; top: 6px; right: 6px;
  display: none; gap: 2px;
}
.sticky:hover .sticky-actions { display: flex; }
.sticky-actions button {
  padding: 2px 6px;
  border: none;
  background: rgba(0,0,0,0.05);
  border-radius: 4px;
  font-size: 11px;
  color: #1f2937;
}
.sticky-actions button:hover { background: rgba(0,0,0,0.15); }

/* === MODAL === */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 500;
}
.modal {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  width: 100%;
  max-width: 500px;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}
.modal h3 { margin-bottom: 16px; font-size: 18px; }
.modal label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 4px;
  margin-top: 12px;
}
.modal label:first-child { margin-top: 0; }
.modal input, .modal textarea, .modal select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  font-size: 13px;
  outline: none;
}
.modal input:focus, .modal textarea:focus, .modal select:focus { border-color: var(--accent); }
.modal textarea { resize: vertical; min-height: 80px; font-family: inherit; }
.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 20px;
}
.modal-actions button {
  padding: 8px 14px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
}
.modal-actions button.primary {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}
.modal-actions button.primary:hover { background: var(--accent-hover); }
.modal-actions button.danger {
  background: var(--danger);
  color: white;
  border-color: var(--danger);
}

/* === EMPTY STATES === */
.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 60px 20px;
}
.empty-state .emoji { font-size: 48px; margin-bottom: 12px; }
.empty-state h3 { color: var(--text); margin-bottom: 8px; font-size: 18px; }
.empty-state p { font-size: 13px; margin-bottom: 16px; }
.empty-state button {
  padding: 8px 16px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
}

/* === SCROLLBARS === */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-faint); }

/* === RESPONSIVE === */
@media (max-width: 768px) {
  .sidebar { width: 240px; }
  .page-header, .doc-toolbar { padding-left: 20px; padding-right: 20px; }
  .page-body, .doc-pane, .doc-preview { padding-left: 20px; padding-right: 20px; }
  .doc-body { flex-direction: column; }
  .doc-pane { border-right: none; border-bottom: 1px solid var(--border); }
}
