/* Reset & base */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: system-ui, -apple-system, sans-serif; color: #222; background: #fafafa; }
a { color: #2563eb; text-decoration: none; }
a:hover { text-decoration: underline; }

/* Nav */
.site-nav {
  display: flex; align-items: center; gap: 1rem;
  padding: 0.75rem 1.5rem; background: #1e293b; color: #f1f5f9;
}
.nav-brand { font-weight: 700; font-size: 1.1rem; color: #f1f5f9; }
.nav-user { margin-left: auto; font-size: 0.875rem; color: #94a3b8; }
.nav-logout button {
  background: transparent; border: 1px solid #475569; color: #cbd5e1;
  padding: 0.25rem 0.75rem; border-radius: 4px; cursor: pointer; font-size: 0.875rem;
}
.nav-logout button:hover { background: #334155; }

/* Layout */
.layout { display: flex; min-height: calc(100vh - 48px); justify-content: center; }
aside { width: 220px; flex-shrink: 0; background: #f1f5f9; border-right: 1px solid #e2e8f0; padding: 1rem; }
.main-content { flex: 1; padding: 1.5rem 2rem; max-width: 900px; margin: 0 auto; }

/* Sidebar */
.sidebar-tags h3 { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; color: #64748b; margin-bottom: 0.75rem; }
.tag-list { list-style: none; }
.tag-list li + li { margin-top: 0.35rem; }
.tag { color: #2563eb; font-size: 0.875rem; text-decoration: none; }
.tag-colored {
  display: inline-block;
  padding: 0.1rem 0.3rem;
  border-radius: 4px;
  color: #fff;
  text-shadow: 0 1px 1px rgba(0,0,0,0.3);
  transition: opacity 0.15s;
  font-weight: 900;
}
.tag-colored:hover { opacity: 0.85; text-decoration: none; }
.tag-count { color: rgba(255,255,255,0.8); font-size: 0.75rem; margin-left: 0.25rem; }
.tag-all { display: block; margin-top: 1rem; font-size: 0.8rem; color: #64748b; }
.sidebar-archive { display: block; margin-top: 0.5rem; font-size: 0.8rem; color: #94a3b8; }
.sidebar-archive:hover { color: #64748b; }
.sidebar-loading { color: #94a3b8; font-size: 0.875rem; }

/* Color picker for tags */
.tag-color-picker {
  position: absolute;
  z-index: 100;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 0.5rem;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  display: none;
}
.tag-color-picker.active { display: block; }
.tag-color-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.35rem;
}
.tag-color-swatch {
  width: 24px;
  height: 24px;
  border-radius: 4px;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.1s;
}
.tag-color-swatch:hover { transform: scale(1.15); }
.tag-color-swatch.selected { border-color: #1e293b; }

/* Buttons */
.btn { display: inline-block; padding: 0.4rem 0.9rem; border-radius: 5px; font-size: 0.875rem; cursor: pointer; border: none; }
.btn-primary { background: #2563eb; color: #fff; }
.btn-primary:hover { background: #1d4ed8; }
.btn-secondary { background: #e2e8f0; color: #334155; }
.btn-secondary:hover { background: #cbd5e1; }
.btn-danger { background: #fee2e2; color: #dc2626; }
.btn-danger:hover { background: #fecaca; }

/* Login */
.login-container { max-width: 380px; margin: 4rem auto; text-align: center; }
.login-container h1 { font-size: 2rem; margin-bottom: 2rem; color: #1e293b; }
.login-error {
  background: #fef2f2; color: #dc2626; border: 1px solid #fecaca;
  padding: 0.75rem 1rem; border-radius: 6px; margin-bottom: 1.5rem; font-size: 0.875rem;
}
.btn-github {
  display: inline-flex; align-items: center; gap: 0.6rem;
  padding: 0.75rem 1.5rem; background: #24292f; color: #fff;
  border: none; border-radius: 6px; font-size: 1rem; cursor: pointer;
  text-decoration: none; font-weight: 500; transition: background 0.15s;
}
.btn-github:hover { background: #32383f; text-decoration: none; color: #fff; }
.btn-github svg { flex-shrink: 0; }

/* Notes list */
.notes-header { display: flex; align-items: center; gap: 1rem; margin-bottom: 1.5rem; flex-wrap: wrap; }
.notes-header h1 { font-size: 1.5rem; }
.new-note-form { display: flex; gap: 0.5rem; margin-left: auto; }
.new-note-form input { padding: 0.4rem 0.75rem; border: 1px solid #cbd5e1; border-radius: 5px; font-size: 0.875rem; width: 220px; }
.new-note-form button { padding: 0.4rem 0.9rem; background: #2563eb; color: #fff; border: none; border-radius: 5px; cursor: pointer; font-size: 0.875rem; }
.note-list { list-style: none; }
.note-item { padding: 0.75rem 0; border-bottom: 1px solid #e2e8f0; display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.note-content { flex: 1; min-width: 0; }
.note-title { font-weight: 500; font-size: 1rem; }
.note-meta { margin-top: 0.25rem; display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; justify-content: flex-start; }
.note-date { font-size: 0.8rem; color: #94a3b8; text-align: left; }
.note-empty { color: #94a3b8; padding: 1rem 0; }
.btn-archive { padding: 0.3rem 0.6rem; font-size: 0.75rem; background: #f1f5f9; color: #475569; border: 1px solid #cbd5e1; border-radius: 4px; cursor: pointer; flex-shrink: 0; }
.btn-archive:hover { background: #e2e8f0; }
.btn-restore { padding: 0.3rem 0.6rem; font-size: 0.75rem; background: #dcfce7; color: #166534; border: 1px solid #86efac; border-radius: 4px; cursor: pointer; flex-shrink: 0; }
.btn-restore:hover { background: #bbf7d0; }
.archive-tags { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 1rem; align-items: center; }

/* Editor & Reader topbar */
.editor-topbar, .reader-topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 0.75rem;
}
.topbar-back {
  font-size: 0.875rem;
  color: #64748b;
  text-decoration: none;
  white-space: nowrap;
}
.topbar-back:hover { color: #334155; text-decoration: none; }
.topbar-edit {
  font-size: 0.875rem;
  color: #2563eb;
  text-decoration: none;
}
.topbar-edit:hover { text-decoration: underline; }
.save-status {
  margin-left: auto;
  font-size: 0.8rem;
  color: #94a3b8;
  white-space: nowrap;
}
.save-status--saving { color: #94a3b8; }
.save-status--saved { color: #059669; }
.save-status--error { color: #dc2626; }
.topbar-menu { position: relative; }
.topbar-menu-btn {
  background: none;
  border: none;
  font-size: 1.4rem;
  cursor: pointer;
  padding: 0.2rem 0.5rem;
  color: #64748b;
  border-radius: 4px;
  line-height: 1;
}
.topbar-menu-btn:hover { background: #f1f5f9; color: #334155; }
.topbar-dropdown {
  display: none;
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  min-width: 170px;
  z-index: 50;
  padding: 0.25rem 0;
}
.topbar-dropdown.open { display: block; }
.topbar-dropdown button {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  cursor: pointer;
  color: #334155;
}
.topbar-dropdown button:hover { background: #f8fafc; }
.topbar-dropdown button.danger { color: #dc2626; }
.topbar-dropdown button.danger:hover { background: #fef2f2; }
.topbar-dropdown hr { margin: 0.25rem 0; border: none; border-top: 1px solid #e2e8f0; }
.note-title-input { width: 100%; font-size: 1.5rem; font-weight: 600; border: none; border-bottom: 2px solid #e2e8f0; padding: 0.25rem 0; margin-bottom: 0.75rem; background: transparent; outline: none; }
.note-title-input:focus { border-bottom-color: #2563eb; }

/* Editor tag bar */
.editor-tag-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 0.5rem;
  margin-bottom: 0.75rem;
}
.tag-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
  flex: 1;
  min-width: 0;
}
.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  padding: 0.15rem 0.35rem 0.15rem 0.5rem;
  background: #e0e7ff;
  color: #3730a3;
  border-radius: 999px;
  font-size: 0.8125rem;
}
.tag-chip-remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.25rem;
  height: 1.25rem;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: #6366f1;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
}
.tag-chip-remove:hover {
  background: #c7d2fe;
  color: #312e81;
}
.tag-add-wrap {
  flex-shrink: 0;
}
.tag-add-input {
  width: 11rem;
  padding: 0.35rem 0.5rem;
  font-size: 0.875rem;
  border: 1px solid #cbd5e1;
  border-radius: 5px;
  background: #fff;
}
.tag-add-input:focus {
  outline: none;
  border-color: #2563eb;
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}

/* Reader */
.reader-content h1 { font-size: 1.75rem; font-weight: 700; margin-bottom: 0.5rem; }
.reader-tags { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-bottom: 1.5rem; align-items: center; }
.reader-topbar .note-date { margin-left: auto; }
.topbar-actions { display: flex; align-items: center; gap: 0.5rem; }
.btn-delete { padding: 0.3rem 0.6rem; font-size: 0.75rem; background: #fee2e2; color: #dc2626; border: 1px solid #fca5a5; border-radius: 4px; cursor: pointer; flex-shrink: 0; }
.btn-delete:hover { background: #fecaca; }

/* Markdown rendered content */
.markdown-body { line-height: 1.7; }
.markdown-body h1, .markdown-body h2, .markdown-body h3 { margin: 1.25em 0 0.5em; font-weight: 600; }
.markdown-body p { margin: 0.75em 0; }
.markdown-body ul, .markdown-body ol { margin: 0.75em 0 0.75em 1.5em; }
.markdown-body blockquote { border-left: 4px solid #e2e8f0; padding-left: 1rem; color: #64748b; margin: 0.75em 0; }
.markdown-body code { background: #f1f5f9; padding: 0.1em 0.4em; border-radius: 3px; font-size: 0.9em; }
.markdown-body pre { background: #1e293b; color: #f1f5f9; padding: 1rem; border-radius: 6px; overflow-x: auto; margin: 1em 0; }
.markdown-body pre code { background: none; padding: 0; }
.markdown-body img { max-width: 100%; border-radius: 4px; }
.markdown-body a { color: #2563eb; }
.markdown-body table { border-collapse: collapse; width: 100%; margin: 1em 0; }
.markdown-body th, .markdown-body td { border: 1px solid #e2e8f0; padding: 0.5rem 0.75rem; }
.markdown-body th { background: #f8fafc; font-weight: 600; }

/* Backlinks */
.backlinks-section {
  margin-top: 2.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid #e2e8f0;
}
.backlinks-section h3 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #64748b;
  margin-bottom: 0.5rem;
}
.backlinks-list {
  list-style: none;
}
.backlinks-list li {
  padding: 0.25rem 0;
}
.backlinks-list a {
  font-size: 0.9rem;
  color: #2563eb;
}

/* Note link autocomplete */
.note-autocomplete {
  position: absolute;
  z-index: 200;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.12);
  max-height: 200px;
  overflow-y: auto;
  min-width: 220px;
}
.note-autocomplete-item {
  padding: 0.4rem 0.75rem;
  cursor: pointer;
  font-size: 0.875rem;
  color: #334155;
}
.note-autocomplete-item:hover,
.note-autocomplete-item.selected {
  background: #f1f5f9;
}
.note-autocomplete-empty {
  padding: 0.4rem 0.75rem;
  font-size: 0.8rem;
  color: #94a3b8;
  font-style: italic;
}

/* Error pages */
.error-page { text-align: center; padding: 4rem 2rem; }
.error-page h1 { font-size: 2rem; margin-bottom: 1rem; color: #1e293b; }
.error-page p { color: #64748b; margin-bottom: 1.5rem; }

/* Drawing */
.drawing-section-seamless { margin-top: 1.5rem; }
.drawing-canvas {
  height: 500px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid #e2e8f0;
}
.drawing-preview-seamless {
  height: 400px;
  margin-top: 2rem;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid #e2e8f0;
}
.btn-add-drawing {
  display: block;
  background: none;
  border: 2px dashed #e2e8f0;
  border-radius: 8px;
  padding: 1rem;
  width: 100%;
  text-align: center;
  color: #94a3b8;
  cursor: pointer;
  font-size: 0.875rem;
  transition: border-color 0.15s, color 0.15s;
  margin-bottom: 0.75rem;
}
.btn-add-drawing:hover {
  border-color: #2563eb;
  color: #2563eb;
}
.btn-sm {
  padding: 0.25rem 0.6rem;
  font-size: 0.8rem;
}

/* tldraw wrapper overrides */
.tldraw-island-wrapper {
  height: 100%;
  display: flex;
  flex-direction: column;
}
.tldraw-toolbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.75rem;
  background: #f8fafc;
  border-bottom: 1px solid #e2e8f0;
  flex-shrink: 0;
}
.tldraw-save-status {
  font-size: 0.75rem;
  color: #94a3b8;
  margin-right: auto;
}
.tldraw-save-status.saved { color: #059669; }
.tldraw-save-status.error { color: #dc2626; }
.tldraw-canvas-container {
  flex: 1;
  min-height: 0;
}
.tldraw-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: #64748b;
}

/* Fullscreen mode for tldraw (native Fullscreen API) */
.drawing-canvas:fullscreen,
.drawing-preview-seamless:fullscreen {
  width: 100vw;
  height: 100vh;
  border: none;
  border-radius: 0;
  background: #fff;
}

/* Search box */
.search-box {
  margin-bottom: 1rem;
}
.search-box input {
  width: 100%;
  padding: 0.6rem 1rem;
  font-size: 0.95rem;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  background: #fff;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.search-box input:focus {
  outline: none;
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}
.search-box input::placeholder {
  color: #94a3b8;
}

/* Search results */
.search-result {
  cursor: pointer;
  transition: background-color 0.1s;
}
.search-result:hover {
  background-color: #f8fafc;
}
.search-result.selected {
  background-color: #e0e7ff;
  border-color: #c7d2fe;
}
.note-snippet {
  margin-top: 0.35rem;
  font-size: 0.8rem;
  color: #64748b;
  line-height: 1.4;
}

/* Highlight matches */
mark {
  background-color: #fef08a;
  color: inherit;
  padding: 0 0.1em;
  border-radius: 2px;
}
