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

/* Prevent horizontal bounce on iOS */
html {
  overflow-x: hidden;
  overscroll-behavior-x: none;
}

/* Layout */
body {
  display: flex;
  height: 100vh;
  overflow: hidden;
  overflow-x: hidden;
  overscroll-behavior-x: none;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  color: #1a1a2e;
  background: #f8f9fa;
}

/* SPA root container inherits flex layout from body */
#root {
  display: flex;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

/* ===========================
   SIDEBAR
   =========================== */
#sidebar {
  width: 280px;
  min-width: 280px;
  background: #ffffff;
  border-right: 1px solid #e2e8f0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-head {
  flex-shrink: 0;
  border-bottom: 1px solid #e2e8f0;
}

.sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding: 0.25rem 0;
}

.sidebar-foot {
  flex-shrink: 0;
  border-top: 1px solid #e2e8f0;
  padding: 0.6rem;
}

.sidebar-header {
  padding: 1.25rem 1rem 0.75rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sidebar-header a {
  font-size: 1.15rem;
  font-weight: 700;
  color: #0f172a;
  text-decoration: none;
  letter-spacing: -0.02em;
}

#sidebar-toggle {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.1rem;
  color: #64748b;
  padding: 0.3rem;
  border-radius: 6px;
  line-height: 1;
  transition: color 0.15s, background 0.15s;
}

#sidebar-toggle:hover {
  color: #1e293b;
  background: #f1f5f9;
}

/* Sidebar open button (hamburger) */
#sidebar-open {
  display: none;
  position: fixed;
  top: 0.75rem;
  left: 0.75rem;
  z-index: 100;
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1.25rem;
  color: #475569;
  padding: 0.35rem 0.6rem;
  line-height: 1;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  transition: color 0.15s, background 0.15s;
}

#sidebar-open:hover {
  color: #1e293b;
  background: #f8fafc;
}

/* Hide backdrop on desktop */
#sidebar-backdrop {
  display: none !important;
}

/* Collapsed state */
.sidebar-collapsed #sidebar {
  display: none;
}

.sidebar-collapsed #sidebar-open {
  display: block;
}

.sidebar-collapsed main {
  padding-left: 3.5rem;
}

/* Sidebar search */
.sidebar-search {
  padding: 0.5rem 0.75rem 0.6rem;
  position: relative;
  flex-shrink: 0;
}

#search-input {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  font-size: 0.8rem;
  font-family: inherit;
  color: #1e293b;
  background: #f8fafc;
  outline: none;
  transition: border-color 0.15s, background 0.15s;
}

#search-input:focus {
  border-color: #667eea;
  background: #ffffff;
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

#search-input::placeholder {
  color: #94a3b8;
}

/* Search results dropdown */
#search-results {
  position: absolute;
  top: calc(100% - 0.1rem);
  left: 0.75rem;
  right: 0.75rem;
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.1);
  max-height: 400px;
  overflow-y: auto;
  z-index: 500;
}

#search-results.hidden {
  display: none;
}

.search-result {
  display: block;
  padding: 0.6rem 0.75rem;
  text-decoration: none;
  border-bottom: 1px solid #f1f5f9;
  color: inherit;
  transition: background 0.1s;
}

.search-result:last-child {
  border-bottom: none;
}

.search-result:hover,
.search-result.focused {
  background: #f8fafc;
}

.search-result-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: #1e293b;
  margin-bottom: 0.15rem;
}

.search-result-snippet {
  font-size: 0.75rem;
  color: #64748b;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.search-result-snippet mark {
  background: #fef9c3;
  color: #854d0e;
  padding: 0 0.1em;
  border-radius: 2px;
}

.search-result-pills {
  display: flex;
  gap: 0.25rem;
  margin-top: 0.3rem;
}

/* Sidebar nav (Search, Filter, Graph, Shares) — icon-only row */
.sidebar-nav {
  padding: 0.4rem 0.75rem;
  display: flex;
  flex-direction: row;
  gap: 4px;
}

#search-toggle {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0;
}

/* Search panel (collapsible) */
.sidebar-search.hidden { display: none; }

#sidebar .sidebar-nav-item {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  color: #64748b;
  text-decoration: none;
  border-radius: 8px;
  transition: background 0.15s, color 0.15s;
}

#sidebar .sidebar-nav-item:hover {
  background: #f1f5f9;
  color: #1e293b;
}

#sidebar .sidebar-nav-item.active {
  background: #eef2ff;
  color: #4338ca;
}

.sidebar-nav-item svg {
  flex-shrink: 0;
  opacity: 0.6;
}

#sidebar .sidebar-nav-item:hover svg {
  opacity: 1;
}

#sidebar .sidebar-nav-item.active svg {
  opacity: 1;
  color: #4338ca;
}

/* Sidebar nav tree */
#sidebar ul { list-style: none; padding-left: 0; }

#sidebar > .sidebar-content > div > ul {
  padding: 0.25rem 0;
}

#sidebar ul ul {
  padding-left: 0.75rem;
  border-left: 1px solid #e2e8f0;
  margin-left: 0.75rem;
}

#sidebar li { margin: 0; }

#sidebar a:not(.sidebar-nav-item):not(.sidebar-user-link):not(.sidebar-tool-link) {
  display: block;
  padding: 0.3rem 1rem;
  color: #64748b;
  text-decoration: none;
  font-size: 0.85rem;
  border-radius: 4px;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#sidebar a:not(.sidebar-nav-item):not(.sidebar-user-link):not(.sidebar-tool-link):hover {
  background: #f1f5f9;
  color: #1e293b;
}

#sidebar a:not(.sidebar-nav-item):not(.sidebar-user-link):not(.sidebar-tool-link).active {
  background: #eef2ff;
  color: #4338ca;
  font-weight: 600;
}

#sidebar details > summary {
  cursor: pointer;
  padding: 0.3rem 1rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: #334155;
  list-style: none;
  user-select: none;
}

#sidebar details > summary::-webkit-details-marker { display: none; }

#sidebar details > summary::before {
  content: "\25B8 ";
  font-size: 0.7rem;
  color: #94a3b8;
}

#sidebar details[open] > summary::before {
  content: "\25BE ";
}

/* Sidebar user (bottom) — now inside .sidebar-foot */

.sidebar-user-link {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.5rem 0.6rem;
  text-decoration: none;
  color: #334155;
  border-radius: 8px;
  transition: background 0.15s;
}

.sidebar-user-link:hover {
  background: #f1f5f9;
}

.sidebar-user-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 700;
  flex-shrink: 0;
}

.sidebar-user-name {
  font-size: 0.85rem;
  font-weight: 500;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-user-dots {
  color: #94a3b8;
  flex-shrink: 0;
  transition: color 0.15s;
}

.sidebar-user-link:hover .sidebar-user-dots {
  color: #64748b;
}

/* Sidebar footer (for public share views) */
.sidebar-footer {
  margin-top: auto;
  padding: 0.75rem;
  border-top: 1px solid #e2e8f0;
}

/* sidebar-tool-link (used in share nav) */
#sidebar .sidebar-tool-link {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 0.75rem;
  color: #64748b;
  text-decoration: none;
  font-size: 0.8rem;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}

#sidebar .sidebar-tool-link:hover {
  background: #f1f5f9;
  color: #1e293b;
}

.sidebar-tool-link svg {
  flex-shrink: 0;
}

.mini-pill {
  display: inline-block;
  padding: 0.1rem 0.4rem;
  border-radius: 999px;
  font-size: 0.65rem;
  font-weight: 500;
}

.mini-pill.status-seedling { background: #fef9c3; color: #854d0e; }
.mini-pill.status-growing { background: #dcfce7; color: #166534; }
.mini-pill.status-evergreen { background: #065f46; color: #ecfdf5; }
.mini-pill.type { background: #fef3c7; color: #92400e; }

.search-empty {
  padding: 1rem;
  text-align: center;
  color: #94a3b8;
  font-size: 0.8rem;
}

/* ===========================
   MAIN CONTENT
   =========================== */
main {
  flex: 1;
  min-width: 0;
  padding: 2.5rem 3rem;
  max-width: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: none contain;
  -webkit-overflow-scrolling: touch;
}

article {
  max-width: 820px;
  margin: 0 auto;
  position: relative;
  padding-bottom: 5rem;
}

/* Wide article — for filter/graph pages */
article.wide {
  max-width: 100%;
}

/* ===========================
   NOTE METADATA (FRONTMATTER)
   =========================== */
.note-meta {
  margin-bottom: 2rem;
  padding-bottom: 1.5rem;
  border-bottom: 2px solid #e2e8f0;
}

.note-meta .note-title {
  font-size: 2rem;
  font-weight: 700;
  color: #0f172a;
  margin: 0 0 0.75rem;
  padding: 0;
  border: none;
}

/* Pills row */
.meta-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.6rem;
}

.meta-pill {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.01em;
  text-decoration: none;
  transition: opacity 0.15s, filter 0.15s;
}

a.meta-pill:hover {
  opacity: 0.8;
  filter: brightness(0.95);
}

.meta-pill.date {
  background: #f1f5f9;
  color: #64748b;
}

.meta-pill.para {
  background: #eff6ff;
  color: #1e40af;
}

.meta-pill.distill {
  background: #f0fdf4;
  color: #166534;
}

.meta-pill.type {
  background: #fef3c7;
  color: #92400e;
}

.meta-pill.status {
  font-weight: 600;
}

.meta-pill.status-seedling {
  background: #fef9c3;
  color: #854d0e;
}

.meta-pill.status-growing {
  background: #dcfce7;
  color: #166534;
}

.meta-pill.status-evergreen {
  background: #065f46;
  color: #ecfdf5;
}

/* Details row */
.meta-details {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 0.6rem;
  font-size: 0.8rem;
  color: #64748b;
}

.meta-detail {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}

.meta-label {
  font-weight: 600;
  color: #94a3b8;
  text-transform: uppercase;
  font-size: 0.65rem;
  letter-spacing: 0.05em;
}

.meta-detail.due {
  color: #dc2626;
  font-weight: 500;
}

.meta-detail.rating {
  color: #f59e0b;
  font-size: 0.85rem;
  letter-spacing: 0.1em;
}

/* Tags (clickable) */
.meta-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 0.5rem;
}

.meta-tag {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  background: #faf5ff;
  color: #7c3aed;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 500;
  text-decoration: none;
  transition: background 0.15s;
}

a.meta-tag:hover {
  background: #ede9fe;
}

/* Source */
.meta-source {
  font-size: 0.8rem;
  color: #64748b;
  margin-bottom: 0.3rem;
}

.meta-source a {
  color: #2563eb;
  text-decoration: none;
}

.meta-source a:hover {
  text-decoration: underline;
}

/* Links */
.meta-links {
  font-size: 0.8rem;
  color: #64748b;
}

.meta-link {
  color: #2563eb;
  text-decoration: none;
}

.meta-link:hover {
  text-decoration: underline;
}

/* ===========================
   TYPOGRAPHY
   =========================== */
article h1 { font-size: 2rem; font-weight: 700; margin: 0 0 1rem; color: #0f172a; border-bottom: 2px solid #e2e8f0; padding-bottom: 0.5rem; }
article h2 { font-size: 1.5rem; font-weight: 700; margin: 2rem 0 0.75rem; color: #1e293b; }
article h3 { font-size: 1.2rem; font-weight: 600; margin: 1.5rem 0 0.5rem; color: #334155; }
article h4 { font-size: 1.05rem; font-weight: 600; margin: 1.25rem 0 0.4rem; color: #475569; }
article h5, article h6 { font-size: 0.95rem; font-weight: 600; margin: 1rem 0 0.3rem; color: #64748b; }

article p { margin: 0 0 1rem; }

article a { color: #2563eb; text-decoration: none; }
article a:hover { text-decoration: underline; }

article strong { font-weight: 600; }

/* Lists */
article ul, article ol {
  margin: 0 0 1rem;
  padding-left: 1.5rem;
}

article li { margin: 0.2rem 0; }
article li > ul, article li > ol { margin: 0.2rem 0 0; }

/* Task lists */
article ul li input[type="checkbox"] {
  margin-right: 0.4rem;
}

/* Tables */
article .table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 1rem 0 1.5rem;
}

article table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

article th, article td {
  text-align: left;
  padding: 0.6rem 0.8rem;
  border: 1px solid #e2e8f0;
}

article th {
  background: #f1f5f9;
  font-weight: 600;
  color: #334155;
}

article tr:nth-child(even) { background: #f8fafc; }
article tr:hover { background: #f1f5f9; }

/* Code */
article code {
  font-family: "SF Mono", "Fira Code", "JetBrains Mono", Menlo, monospace;
  font-size: 0.875em;
  background: #f1f5f9;
  padding: 0.15em 0.35em;
  border-radius: 4px;
  color: #be185d;
}

article pre {
  margin: 1rem 0 1.5rem;
  padding: 1rem 1.25rem;
  background: #1e293b;
  border-radius: 8px;
  overflow-x: auto;
  position: relative;
}

/* Copy to clipboard button */
article pre .copy-btn {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 6px;
  color: #94a3b8;
  cursor: pointer;
  padding: 0.3rem 0.5rem;
  font-size: 0.75rem;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  display: flex;
  align-items: center;
  gap: 0.3rem;
  opacity: 0;
  transition: opacity 0.15s, background 0.15s, color 0.15s;
  z-index: 1;
}

article pre:hover .copy-btn {
  opacity: 1;
}

article pre .copy-btn:hover {
  background: rgba(255, 255, 255, 0.2);
  color: #e2e8f0;
}

article pre .copy-btn.copied {
  color: #4ade80;
  border-color: rgba(74, 222, 128, 0.3);
  background: rgba(74, 222, 128, 0.1);
}

article pre code {
  background: none;
  color: #e2e8f0;
  padding: 0;
  font-size: 0.85rem;
  line-height: 1.5;
}

/* Mermaid diagrams */
article pre.mermaid {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 1.5rem;
  margin: 1.5rem 0;
  overflow-x: auto;
  text-align: center;
}

article pre.mermaid svg {
  max-width: 100%;
  height: auto;
}

/* Blockquotes */
article blockquote {
  margin: 1rem 0 1.5rem;
  padding: 0.75rem 1.25rem;
  border-left: 4px solid #3b82f6;
  background: #eff6ff;
  color: #1e40af;
  border-radius: 0 6px 6px 0;
}

article blockquote p:last-child { margin-bottom: 0; }

/* Horizontal rules */
article hr {
  border: none;
  border-top: 1px solid #e2e8f0;
  margin: 2rem 0;
}

/* Images */
article img {
  max-width: 100%;
  border-radius: 8px;
  transition: filter 0.15s;
}

article img:hover {
  filter: brightness(0.92);
}

/* ===========================
   LIGHTBOX
   =========================== */
#lightbox {
  position: fixed;
  inset: 0;
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: center;
}

#lightbox.lightbox-hidden {
  display: none;
}

#lightbox.lightbox-visible {
  animation: lightbox-in 0.2s ease;
}

@keyframes lightbox-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

#lightbox-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}

#lightbox-img-wrap {
  position: relative;
  z-index: 1;
  max-width: 92vw;
  max-height: 88vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

#lightbox-img {
  max-width: 92vw;
  max-height: 88vh;
  object-fit: contain;
  border-radius: 6px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.4);
  user-select: none;
  -webkit-user-drag: none;
}

#lightbox-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  z-index: 2;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

#lightbox-close:hover {
  background: rgba(255, 255, 255, 0.3);
}

#lightbox-prev,
#lightbox-next {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 2;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-size: 1.75rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

#lightbox-prev { left: 1rem; }
#lightbox-next { right: 1rem; }

#lightbox-prev:hover,
#lightbox-next:hover {
  background: rgba(255, 255, 255, 0.25);
}

#lightbox-counter {
  position: absolute;
  bottom: 1.25rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2;
  color: rgba(255, 255, 255, 0.7);
  font-size: 0.8rem;
  font-weight: 500;
  letter-spacing: 0.05em;
  user-select: none;
}

@media (max-width: 768px) {
  #lightbox-prev,
  #lightbox-next {
    width: 36px;
    height: 36px;
    font-size: 1.5rem;
  }

  #lightbox-prev { left: 0.5rem; }
  #lightbox-next { right: 0.5rem; }

  #lightbox-close {
    top: 0.5rem;
    right: 0.5rem;
  }
}

/* ==highlights== from progressive summarization */
article mark {
  background: #fef08a;
  padding: 0.1em 0.2em;
  border-radius: 2px;
}

/* ===========================
   READING NAVIGATION (liquid glass)
   =========================== */
#reading-nav {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  z-index: 200;
}

#reading-nav button {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: #475569;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
}

#reading-nav button:hover {
  background: rgba(0, 0, 0, 0.06);
  color: #1e293b;
}

#reading-nav button:active {
  background: rgba(0, 0, 0, 0.1);
  transform: scale(0.92);
}

#btn-top {
  background: rgba(255, 255, 255, 0.5);
  backdrop-filter: blur(16px) saturate(1.8);
  -webkit-backdrop-filter: blur(16px) saturate(1.8);
  border: 1px solid rgba(255, 255, 255, 0.6);
  border-radius: 50%;
  box-shadow:
    0 4px 24px rgba(0, 0, 0, 0.06),
    0 1px 3px rgba(0, 0, 0, 0.04),
    inset 0 1px 0 rgba(255, 255, 255, 0.7);
  opacity: 0;
  pointer-events: none;
  transform: translateY(6px);
  transition: opacity 0.25s, transform 0.25s, background 0.15s, color 0.15s;
}

#btn-top.visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

#btn-top:hover {
  background: rgba(255, 255, 255, 0.7);
}

#reading-nav-paging {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  padding: 0.3rem;
  background: rgba(255, 255, 255, 0.5);
  backdrop-filter: blur(16px) saturate(1.8);
  -webkit-backdrop-filter: blur(16px) saturate(1.8);
  border: 1px solid rgba(255, 255, 255, 0.6);
  border-radius: 14px;
  box-shadow:
    0 4px 24px rgba(0, 0, 0, 0.06),
    0 1px 3px rgba(0, 0, 0, 0.04),
    inset 0 1px 0 rgba(255, 255, 255, 0.7);
}

/* ===========================
   PWA / OFFLINE
   =========================== */
#offline-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  background: #f59e0b;
  color: #78350f;
  text-align: center;
  padding: 0.35rem 1rem;
  font-size: 0.8rem;
  font-weight: 600;
}

#offline-bar.hidden { display: none; }

/* Push layout down when offline bar is visible */
#offline-bar:not(.hidden) ~ #sidebar,
#offline-bar:not(.hidden) ~ main {
  margin-top: 2rem;
}
#offline-bar:not(.hidden) ~ #sidebar {
  height: calc(100vh - 2rem);
}

#offline-actions {
  padding: 0.5rem 0.75rem;
}

#offline-actions.hidden { display: none; }

#btn-cache-all {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.5rem 0.75rem;
  background: #eef2ff;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  color: #4338ca;
  cursor: pointer;
  font-size: 0.8rem;
  font-family: inherit;
  font-weight: 500;
  transition: background 0.15s, border-color 0.15s;
}

#btn-cache-all:hover {
  background: #e0e7ff;
  border-color: #a5b4fc;
}

#btn-cache-all:disabled {
  opacity: 0.7;
  cursor: wait;
}

#cache-progress {
  margin-top: 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

#cache-progress.hidden { display: none; }

#cache-progress-bar {
  flex: 1;
  height: 4px;
  background: #e2e8f0;
  border-radius: 2px;
  overflow: hidden;
}

#cache-progress-fill {
  height: 100%;
  background: #2563eb;
  border-radius: 2px;
  transition: width 0.3s;
  width: 0%;
}

#cache-progress-text {
  font-size: 0.7rem;
  color: #94a3b8;
  white-space: nowrap;
}

/* ===========================
   EDITOR MODE
   =========================== */
.article-actions {
  position: absolute;
  top: 0;
  right: 0;
  z-index: 10;
  display: flex;
  gap: 0.4rem;
}

.edit-btn {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  color: #64748b;
  cursor: pointer;
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
  font-family: inherit;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.edit-btn:hover {
  color: #1e40af;
  border-color: #93c5fd;
  background: #eff6ff;
}

.edit-btn.copied {
  color: #16a34a;
  border-color: #86efac;
  background: #f0fdf4;
}

#editor-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 1rem;
  background: #1e293b;
  color: #e2e8f0;
  border-radius: 8px 8px 0 0;
  font-size: 0.85rem;
  gap: 0.5rem;
}

#editor-toolbar.hidden {
  display: none;
}

.toolbar-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}

#editor-filepath {
  font-family: "SF Mono", "Fira Code", Menlo, monospace;
  font-size: 0.8rem;
  color: #94a3b8;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#editor-status {
  font-size: 0.75rem;
  color: #fbbf24;
  white-space: nowrap;
}

.toolbar-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.toolbar-btn {
  padding: 0.35rem 0.85rem;
  border: 1px solid #475569;
  border-radius: 6px;
  background: transparent;
  color: #e2e8f0;
  cursor: pointer;
  font-size: 0.8rem;
  font-family: inherit;
  transition: background 0.15s;
}

.toolbar-btn:hover {
  background: #334155;
}

.toolbar-btn-primary {
  background: #2563eb;
  border-color: #2563eb;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.toolbar-btn-primary:hover {
  background: #1d4ed8;
}

.toolbar-btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* Split pane container */
#editor-container {
  display: flex;
  height: calc(100vh - 3.5rem);
  border: 1px solid #e2e8f0;
  border-top: none;
  border-radius: 0 0 8px 8px;
  overflow: hidden;
  background: #fff;
}

#editor-container.hidden {
  display: none;
}

#editor-pane {
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

#editor-pane .cm-editor {
  height: 100%;
}

#editor-pane .cm-scroller {
  font-family: "SF Mono", "Fira Code", "JetBrains Mono", Menlo, monospace;
  font-size: 0.875rem;
  line-height: 1.65;
}

#editor-pane .cm-content {
  padding: 1rem 0;
}

#editor-pane .cm-gutters {
  border-right: 1px solid #e2e8f0;
  background: #f8fafc;
}

#editor-resize-handle {
  width: 5px;
  cursor: col-resize;
  background: #e2e8f0;
  flex-shrink: 0;
  transition: background 0.15s;
}

#editor-resize-handle:hover,
#editor-resize-handle.dragging {
  background: #3b82f6;
}

#preview-pane {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  padding: 2rem 2.5rem;
  background: #fafbfc;
  border-left: none;
}

#preview-pane article {
  max-width: none;
}

body.editing main {
  padding: 1rem;
  max-width: 100%;
}

body.editing main > article {
  display: none;
}

body.editing #editor-toolbar {
  display: flex;
}

body.editing #editor-container {
  display: flex;
}

body.editing #reading-nav {
  display: none;
}

/* ===========================
   FILTER PAGE
   =========================== */
.filter-page {
  padding: 0;
}

.filter-page h1 {
  font-size: 1.75rem;
  font-weight: 700;
  color: #0f172a;
  margin-bottom: 1.5rem;
  border: none;
  padding: 0;
}

.filter-controls {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
  padding: 1.25rem;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
}

.filter-group {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
}

.filter-group-label {
  flex-shrink: 0;
  width: 80px;
  font-size: 0.75rem;
  font-weight: 600;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding-top: 0.3rem;
}

.filter-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.filter-pill {
  display: inline-block;
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 500;
  border: 1px solid #e2e8f0;
  background: #fff;
  color: #475569;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s;
}

.filter-pill:hover {
  border-color: #93c5fd;
  background: #eff6ff;
  color: #1e40af;
}

.filter-pill.active {
  background: #2563eb;
  color: #fff;
  border-color: #2563eb;
}

/* Colored filter pills by type */
.filter-pill.tag.active { background: #7c3aed; border-color: #7c3aed; }
.filter-pill.status.active { background: #059669; border-color: #059669; }
.filter-pill.type.active { background: #d97706; border-color: #d97706; }
.filter-pill.para.active { background: #1e40af; border-color: #1e40af; }
.filter-pill.distill_level.active { background: #166534; border-color: #166534; }

.filter-summary {
  font-size: 0.85rem;
  color: #64748b;
  margin-bottom: 1rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid #e2e8f0;
}

#filter-count {
  font-weight: 700;
  color: #1e293b;
}

/* Note cards in filter results */
#filter-results {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 0.75rem;
}

.note-card {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 1rem 1.25rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.note-card:hover {
  border-color: #93c5fd;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.note-card-title {
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 0.3rem;
}

.note-card-title a {
  color: #1e293b;
  text-decoration: none;
}

.note-card-title a:hover {
  color: #2563eb;
}

.note-card-preview {
  font-size: 0.8rem;
  color: #64748b;
  line-height: 1.5;
  margin-bottom: 0.5rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.note-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}

/* ===========================
   KNOWLEDGE GRAPH PAGE
   =========================== */
.graph-page {
  padding: 0;
}

.graph-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.graph-header h1 {
  font-size: 1.75rem;
  font-weight: 700;
  color: #0f172a;
  border: none;
  padding: 0;
  margin: 0;
}

.graph-controls select {
  padding: 0.4rem 0.75rem;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  font-size: 0.8rem;
  font-family: inherit;
  background: #fff;
  color: #334155;
  cursor: pointer;
  outline: none;
}

.graph-controls select:focus {
  border-color: #93c5fd;
}

#graph-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
  padding: 0.5rem 0;
  min-height: 1.5rem;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.8rem;
  color: #475569;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  padding: 0.3rem 0.6rem;
}

.legend-label {
  font-weight: 600;
  text-transform: capitalize;
}

.legend-desc {
  display: none;
}

.legend-item:hover .legend-desc {
  display: inline;
}

.legend-item:hover .legend-label {
  display: none;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

#graph-container {
  width: 100%;
  height: calc(100vh - 240px);
  min-height: 400px;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  overflow: hidden;
}

#graph-container svg {
  width: 100%;
  height: 100%;
}

#graph-tooltip {
  position: fixed;
  z-index: 300;
  padding: 0.6rem 0.85rem;
  background: rgba(15, 23, 42, 0.92);
  color: #f1f5f9;
  border-radius: 6px;
  font-size: 0.8rem;
  pointer-events: none;
  max-width: 260px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  backdrop-filter: blur(8px);
}

#graph-tooltip.hidden {
  display: none;
}

.tooltip-title {
  font-weight: 600;
  margin-bottom: 0.2rem;
}

.tooltip-meta {
  font-size: 0.7rem;
  color: #94a3b8;
}

/* Graph nodes and edges */
.graph-node {
  cursor: pointer;
  stroke: #fff;
  stroke-width: 1.5;
  transition: opacity 0.2s;
}

.graph-node:hover {
  stroke-width: 2.5;
}

.graph-label {
  font-size: 10px;
  fill: #475569;
  pointer-events: none;
  text-anchor: middle;
  dominant-baseline: central;
}

.graph-edge {
  stroke: #cbd5e1;
  stroke-opacity: 0.4;
  fill: none;
}

.graph-dimmed {
  opacity: 0.15;
}

.graph-highlighted {
  opacity: 1;
}

.graph-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: #94a3b8;
  font-size: 0.9rem;
}

/* ===========================
   LOGIN PAGE
   =========================== */
.login-page {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f8f9fa;
  padding: 1.5rem;
  z-index: 100;
}

.login-card {
  width: 100%;
  max-width: 340px;
}

.login-logo {
  margin-bottom: 1.25rem;
}

.login-card h1 {
  font-size: 1.5rem;
  font-weight: 700;
  color: #1a1a2e;
  margin-bottom: 0.25rem;
}

.login-subtitle {
  font-size: 0.85rem;
  color: #94a3b8;
  margin-bottom: 2rem;
}

.login-error {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #991b1b;
  padding: 0.6rem 0.85rem;
  border-radius: 6px;
  font-size: 0.8rem;
  margin-bottom: 1.25rem;
}

.login-card label {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  color: #475569;
  margin-bottom: 0.35rem;
}

.login-card input {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  font-size: 0.9rem;
  font-family: inherit;
  margin-bottom: 1rem;
  box-sizing: border-box;
  background: #fff;
  color: #1a1a2e;
  transition: border-color 0.15s;
}

.login-card input:focus {
  outline: none;
  border-color: #667eea;
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.login-card input::placeholder {
  color: #cbd5e1;
}

.login-card button[type="submit"] {
  width: 100%;
  padding: 0.65rem;
  background: #667eea;
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s;
  margin-top: 0.25rem;
}

.login-card button[type="submit"]:hover {
  background: #5568d3;
}

.login-card button[type="submit"]:disabled {
  opacity: 0.6;
  cursor: wait;
}

/* ===========================
   RESPONSIVE
   =========================== */
@media (max-width: 768px) {
  body { flex-direction: row; }

  #sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 280px;
    min-width: 280px;
    height: 100vh;
    height: 100dvh;
    max-height: none;
    z-index: 200;
    border-right: none;
    border-bottom: none;
    box-shadow: 4px 0 24px rgba(0,0,0,0.08);
    transition: transform 0.25s ease;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .sidebar-collapsed #sidebar {
    display: flex;
    transform: translateX(-100%);
  }

  body:not(.sidebar-collapsed) #sidebar {
    transform: translateX(0);
  }

  /* Backdrop overlay */
  #sidebar-backdrop {
    display: none !important;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.25);
    z-index: 199;
  }

  body:not(.sidebar-collapsed) #sidebar-backdrop {
    display: block !important;
  }

  main {
    padding: 1.5rem 1rem;
    width: 100%;
    margin-left: 0;
  }

  .sidebar-collapsed main {
    padding-left: 1rem;
  }

  #sidebar-open {
    position: fixed;
    bottom: 1.25rem;
    left: 1.25rem;
    top: auto;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255,255,255,0.45);
    color: #1a1a2e;
    border: 1px solid rgba(255,255,255,0.5);
    box-shadow: 0 4px 16px rgba(0,0,0,0.1), inset 0 1px 1px rgba(255,255,255,0.6);
    font-size: 1.25rem;
    z-index: 199;
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    backdrop-filter: blur(20px) saturate(180%);
    transition: transform 0.15s, box-shadow 0.15s;
  }

  #sidebar-open:hover, #sidebar-open:active {
    background: rgba(255,255,255,0.6);
    color: #1a1a2e;
    transform: scale(1.05);
    box-shadow: 0 6px 20px rgba(0,0,0,0.15), inset 0 1px 1px rgba(255,255,255,0.7);
  }

  /* PWA standalone: lift floating elements above home indicator */
  @media (display-mode: standalone) {
    #sidebar-open {
      bottom: 2.5rem;
    }

    #reading-nav {
      bottom: 2.5rem;
    }
  }

  /* Filter responsive */
  .filter-group {
    flex-direction: column;
    gap: 0.3rem;
  }

  .filter-group-label {
    width: auto;
  }

  #filter-results {
    grid-template-columns: 1fr;
  }

  /* Graph responsive */
  #graph-container {
    height: calc(100vh - 300px);
    min-height: 300px;
  }

  .graph-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
  }

  /* Editor responsive */
  body.editing main {
    padding: 0.5rem;
  }

  #editor-container {
    flex-direction: column;
    height: auto;
  }

  #editor-pane {
    height: 50vh;
    width: 100% !important;
    flex: none !important;
    border-right: none;
    border-bottom: 1px solid #e2e8f0;
  }

  #editor-resize-handle {
    display: none;
  }

  #preview-pane {
    height: 50vh;
    padding: 1rem;
  }

  #editor-toolbar {
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .article-actions {
    top: -0.25rem;
    right: -0.25rem;
  }
}

/* (sidebar-footer already defined above) */

/* ===========================
   SHARE PAGE NAV
   =========================== */
.nav-section {
  padding: 0.75rem 0;
}

.nav-section h3 {
  padding: 0 1rem;
  font-size: 0.65rem;
  font-weight: 600;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 0.4rem;
}

.nav-section ul {
  list-style: none;
  padding: 0;
}

.nav-section ul li a {
  display: block;
  padding: 0.35rem 1rem;
  color: #64748b;
  text-decoration: none;
  font-size: 0.85rem;
  border-radius: 4px;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-section ul li a:hover {
  background: #f1f5f9;
  color: #1e293b;
}

.nav-section ul li a.active {
  background: #eef2ff;
  color: #4338ca;
  font-weight: 600;
}

/* Wikilinks */
a.wikilink {
  color: #16a34a;
  text-decoration: underline;
  text-decoration-style: dotted;
  text-underline-offset: 2px;
}
a.wikilink:hover {
  text-decoration-style: solid;
}
span.wikilink.broken {
  color: #94a3b8;
  text-decoration: underline;
  text-decoration-style: dashed;
  text-underline-offset: 2px;
  cursor: help;
}
