:root {
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-heading: "Inter", "Plus Jakarta Sans", sans-serif;
  
  /* Light Theme */
  --bg-primary: #ffffff;
  --bg-secondary: #f7f9fa;
  --bg-card: #ffffff;
  --text-primary: #1f2937;
  --text-secondary: #4b5563;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --border-focus: #00a868;
  --accent: #00a868;
  --accent-hover: #008f58;
  --pedia-color: #065f46;
  --notes-color: #00a868;
  --code-bg: #f3f4f6;
}

body.theme-dark {
  /* Dark Theme — Things + Clinical Medical Wiki */
  --bg-primary: #191b1f;
  --bg-secondary: #20242b;
  --bg-card: #252a33;
  --text-primary: #B5BAC2;
  --text-secondary: #8891A0;
  --text-muted: #6b7280;
  --border: rgba(255, 255, 255, 0.08);
  --border-focus: #00a868;
  --accent: #00a868;
  --accent-hover: #34d399;
  --link-custom-color: #60A5FA;
  --pedia-color: #6ee7b7;
  --notes-color: #34d399;
  --code-bg: #20242b;
}

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

body {
  font-family: var(--font-sans);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.68;
  transition: background-color 0.2s, color 0.2s;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-heading);
  color: var(--text-primary);
  letter-spacing: -0.02em;
  line-height: 1.3;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Header */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
}
.header-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.brand-link {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
}
.brand-title {
  font-family: var(--font-heading);
  font-size: 1.5rem;
  font-weight: 800;
}
.brand-title .pedia { color: var(--pedia-color); }
.brand-title .notes { color: var(--notes-color); }

.header-actions { display: flex; align-items: center; gap: 10px; }

.search-trigger-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 0.85rem;
  cursor: pointer;
}
.search-trigger-btn:hover { border-color: var(--border-focus); color: var(--text-primary); }
.search-kbd {
  background: var(--border);
  color: var(--text-muted);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 0.75rem;
}

.icon-btn {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  border-radius: 50%;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
}
.icon-btn:hover { border-color: var(--accent); color: var(--accent); }

/* Sun/Moon Theme visibility */
body.theme-light .moon-icon { display: block; }
body.theme-light .sun-icon { display: none; }
body.theme-dark .sun-icon { display: block; }
body.theme-dark .moon-icon { display: none; }

/* Layout */
.site-layout {
  flex: 1;
  width: 100%;
  box-sizing: border-box;
}

.site-layout.has-sidebar {
  display: flex !important;
  flex-direction: row !important;
  align-items: flex-start !important;
  gap: 2rem !important;
  max-width: 1440px !important;
  width: 100% !important;
  margin: 0 auto !important;
  padding: 1.5rem 1.5rem !important;
  box-sizing: border-box !important;
}

.sidebar-nav {
  width: 280px !important;
  min-width: 280px !important;
  max-width: 280px !important;
  flex-shrink: 0 !important;
  position: sticky !important;
  top: 75px !important;
  height: calc(100vh - 90px) !important;
  overflow-y: auto !important;
  padding-right: 0.75rem !important;
  border-right: 1px solid var(--border) !important;
  scrollbar-width: thin !important;
  box-sizing: border-box !important;
}

.main-content {
  flex: 1 !important;
  min-width: 0 !important;
  width: 100% !important;
}

.site-layout.has-sidebar.sidebar-collapsed .sidebar-nav {
  display: none !important;
}
.note-header { margin-bottom: 2rem; }
.note-title { font-size: 2.25rem; font-weight: 800; margin-bottom: 0.5rem; }
.note-meta { display: flex; align-items: center; gap: 6px; color: var(--text-muted); font-size: 0.85rem; }

.note-body-wrapper {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 260px;
  gap: 40px;
  align-items: start;
}

@media (max-width: 900px) {
  .note-body-wrapper { grid-template-columns: 1fr; }
  .toc-wrapper { display: none; }
}

.note-content { font-size: 1.05rem; line-height: 1.72; color: var(--text-secondary); }
.note-content h1, .note-content h2, .note-content h3, .note-content h4 {
  margin: 1.8rem 0 0.8rem;
  color: var(--text-primary);
}
.note-content p { margin-bottom: 1.2rem; }
.note-content ul, .note-content ol { margin: 0 0 1.2rem 1.6rem; }
.note-content li { margin-bottom: 0.4rem; }

/* Internal Wikilinks */
.internal-link {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 3px;
  font-weight: 500;
}
.internal-link:hover { color: var(--accent-hover); }

/* Breadcrumbs */
.breadcrumb-trail {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 1.5rem;
}
.breadcrumb-separator { opacity: 0.4; font-size: 0.75rem; }
.breadcrumb-current { color: var(--text-primary); font-weight: 600; }

/* TOC */
.toc-wrapper {
  position: sticky;
  top: 80px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem 1.2rem;
  max-height: calc(100vh - 100px);
  overflow-y: auto;
  font-size: 0.88rem;
}
.toc-header { display: flex; align-items: center; gap: 8px; font-weight: 700; margin-bottom: 0.75rem; color: var(--text-primary); }
.toc-body ul { list-style: none; padding-left: 0.8rem; }
.toc-body a { color: var(--text-muted); display: block; padding: 2px 0; }
.toc-body a:hover { color: var(--accent); }

/* Tables */
.note-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.5rem 0;
  font-size: 0.95rem;
  display: block;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 8px;
  border: 1px solid var(--border);
}
.note-content th, .note-content td {
  padding: 8px 12px;
  border: 1px solid var(--border);
}
.note-content th {
  background: var(--bg-secondary);
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
}

/* Callouts */
.callout {
  margin: 1.5rem 0;
  border-radius: 8px;
  border-left: 4px solid var(--accent);
  background: var(--bg-secondary);
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border);
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}
.callout[data-callout="tip"] { border-left-color: #10b981; }
.callout[data-callout="warning"] { border-left-color: #f59e0b; }
.callout[data-callout="danger"] { border-left-color: #ef4444; }
.callout[data-callout="important"] { border-left-color: #8b5cf6; }

.callout-title {
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 1rem;
  color: var(--text-primary);
  margin-bottom: 0.5rem;
  text-transform: capitalize;
}
.callout-content { font-size: 0.95rem; color: var(--text-secondary); }

/* Mermaid */
.mermaid {
  display: block;
  margin: 2rem 0;
  text-align: center;
  background: transparent;
}

/* Footer */
.site-footer {
  border-top: 1px solid var(--border);
  padding: 3rem 1.5rem;
  background: var(--bg-secondary);
  margin-top: auto;
  text-align: center;
}
.footer-container { max-width: 800px; margin: 0 auto; }
.garden-note { font-style: italic; color: var(--text-muted); margin-bottom: 1rem; }
.footer-links { display: flex; justify-content: center; gap: 12px; flex-wrap: wrap; margin-bottom: 1rem; font-weight: 500; }
.disclaimer { font-size: 0.8rem; color: var(--text-muted); line-height: 1.6; }

/* Search Modal */
.search-modal {
  position: fixed;
  inset: 0;
  z-index: 999;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 10vh;
}
.search-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.6); backdrop-filter: blur(4px); }
.search-dialog {
  position: relative;
  width: 90%;
  max-width: 780px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 20px 40px rgba(0,0,0,0.4);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  max-height: 75vh;
}
.search-input-wrapper {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}
.search-input-wrapper input {
  flex: 1;
  background: transparent;
  border: none;
  font-size: 1.1rem;
  color: var(--text-primary);
  outline: none;
  font-family: var(--font-sans);
}
.search-results-wrapper {
  display: grid;
  grid-template-columns: 320px 1fr;
  flex: 1;
  overflow: hidden;
}
@media (max-width: 700px) {
  .search-results-wrapper { grid-template-columns: 1fr; }
  .search-preview-panel { display: none; }
}
.search-results-list { overflow-y: auto; max-height: 55vh; border-right: 1px solid var(--border); }
.search-result-item {
  padding: 12px 16px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}
.search-result-item.active, .search-result-item:hover {
  background: var(--bg-secondary);
}
.search-res-title { font-weight: 600; color: var(--text-primary); font-size: 0.95rem; }
.search-res-cat { font-size: 0.75rem; color: var(--text-muted); margin-top: 2px; }
.search-preview-panel { padding: 1.25rem; overflow-y: auto; max-height: 55vh; font-size: 0.9rem; color: var(--text-secondary); }

/* Home Dashboard */
.home-hero { text-align: center; padding: 4rem 1rem 3rem; }
.hero-badge { display: inline-block; padding: 4px 12px; background: var(--bg-secondary); border: 1px solid var(--border); border-radius: 20px; font-size: 0.8rem; font-weight: 600; color: var(--accent); margin-bottom: 1rem; }
.hero-title { font-size: 3.5rem; font-weight: 800; margin-bottom: 1rem; }
.hero-subtitle { font-size: 1.15rem; color: var(--text-secondary); max-width: 650px; margin: 0 auto 2rem; }
.hero-search-box { display: flex; align-items: center; justify-content: center; gap: 12px; max-width: 550px; margin: 0 auto; padding: 12px 20px; background: var(--bg-secondary); border: 1px solid var(--border); border-radius: 30px; cursor: pointer; color: var(--text-muted); }
.hero-search-box:hover { border-color: var(--border-focus); color: var(--text-primary); }

.categories-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; margin: 1.5rem 0 3rem; }
.category-card { background: var(--bg-secondary); border: 1px solid var(--border); padding: 16px; border-radius: 12px; cursor: pointer; transition: transform 0.2s, border-color 0.2s; }
.category-card:hover { transform: translateY(-2px); border-color: var(--accent); }
.cat-name { font-weight: 700; color: var(--text-primary); font-size: 1.05rem; }
.cat-count { font-size: 0.8rem; color: var(--text-muted); margin-top: 4px; }

.section-title { font-size: 1.6rem; font-weight: 800; margin-bottom: 1rem; }
.notes-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; margin-top: 1rem; }
.note-card { background: var(--bg-secondary); border: 1px solid var(--border); padding: 16px; border-radius: 12px; display: block; text-decoration: none; transition: all 0.2s; }
.note-card:hover { border-color: var(--accent); transform: translateY(-2px); text-decoration: none; }
.note-card-title { font-weight: 700; color: var(--text-primary); margin-bottom: 6px; font-size: 1rem; }
.note-card-snippet { font-size: 0.85rem; color: var(--text-muted); line-height: 1.5; }

/* ── Header Navigation & Left Controls ─────────────────────────────── */
.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.desktop-nav {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  margin-left: 1.5rem;
}
.desktop-nav .nav-link {
  color: var(--text-secondary);
  font-weight: 500;
  font-size: 0.95rem;
  text-decoration: none;
  transition: color 0.15s ease;
}
.desktop-nav .nav-link:hover {
  color: var(--accent);
  text-decoration: none;
}

.mobile-menu-btn {
  display: none;
}

.mobile-menu-drawer {
  display: none;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 1.25rem 1.5rem;
}
.mobile-menu-drawer.is-open {
  display: block;
}
.mobile-menu-section {
  margin-bottom: 1.25rem;
}
.mobile-menu-heading {
  display: block;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}
.mobile-nav-link {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  color: var(--text-primary);
  font-weight: 500;
  text-decoration: none;
}
.mobile-nav-link:hover {
  color: var(--accent);
}
.mobile-drawer-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 10px 14px;
  border-radius: 8px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  color: var(--text-primary);
  font-weight: 600;
  cursor: pointer;
}

/* ── Sidebar Navigation Layout ─────────────────────────────────────── */
.site-layout.has-sidebar {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 2.5rem;
  max-width: 1440px;
  width: 100%;
  margin: 0 auto;
  padding: 1.5rem 1.5rem;
  transition: grid-template-columns 0.2s ease;
}

.site-layout.has-sidebar.sidebar-collapsed {
  grid-template-columns: 0px minmax(0, 1fr);
  gap: 0;
}
.site-layout.has-sidebar.sidebar-collapsed .sidebar-nav {
  display: none;
}

.sidebar-nav {
  position: sticky;
  top: 75px;
  height: calc(100vh - 90px);
  overflow-y: auto;
  padding-right: 0.75rem;
  border-right: 1px solid var(--border);
  scrollbar-width: thin;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 0.75rem;
  margin-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}
.sidebar-title {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text-primary);
}
.sidebar-badge {
  font-size: 0.75rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  padding: 2px 8px;
  border-radius: 12px;
  color: var(--text-muted);
}

.sidebar-section-item {
  margin-bottom: 4px;
}
.sidebar-section-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s;
}
.sidebar-section-header:hover {
  background: var(--bg-secondary);
}
.section-caret {
  display: inline-flex;
  align-items: center;
  transition: transform 0.2s ease;
  color: var(--text-muted);
}
.sidebar-section-item.is-open .section-caret,
.sidebar-section-item.is-active-section .section-caret {
  transform: rotate(90deg);
}
.section-name {
  flex: 1;
  font-size: 0.88rem;
  font-weight: 600;
}
.section-link {
  color: var(--text-primary);
  text-decoration: none;
}
.section-link:hover, .section-link.active {
  color: var(--accent);
  text-decoration: none;
}
.section-count {
  font-size: 0.75rem;
  color: var(--text-muted);
  background: var(--bg-secondary);
  padding: 1px 6px;
  border-radius: 10px;
}

.sidebar-notes-list {
  list-style: none;
  margin: 4px 0 6px 14px;
  padding-left: 10px;
  border-left: 1px solid var(--border);
}
.sidebar-note-item {
  margin-bottom: 2px;
}
.sidebar-note-link {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  border-radius: 6px;
  font-size: 0.83rem;
  color: var(--text-secondary);
  text-decoration: none;
  transition: all 0.15s;
}
.sidebar-note-link:hover {
  background: var(--bg-secondary);
  color: var(--text-primary);
  text-decoration: none;
}
.sidebar-note-link.active {
  background: rgba(0, 168, 104, 0.12);
  color: var(--accent);
  font-weight: 600;
}
.sidebar-note-icon {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  color: var(--text-muted);
}
.sidebar-note-link.active .sidebar-note-icon {
  color: var(--accent);
}

/* ── Image Floating Styles ─────────────────────────────────────────── */
.float-right, img[alt*="right"] {
  float: right !important;
  margin: 0.25rem 0 1rem 1.5rem !important;
  clear: right;
  border-radius: 8px;
}
.float-left, img[alt*="left"] {
  float: left !important;
  margin: 0.25rem 1.5rem 1rem 0 !important;
  clear: left;
  border-radius: 8px;
}

.note-content li {
  overflow: visible;
}
.note-content li::after {
  content: "";
  display: table;
  clear: both;
}

/* ── Search Modal Preview Tables ───────────────────────────────────── */
.search-preview-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0;
  font-size: 0.85rem;
}
.search-preview-body th, .search-preview-body td {
  border: 1px solid var(--border);
  padding: 6px 8px;
  text-align: left;
}
.search-preview-body th {
  background: var(--bg-secondary);
  font-weight: 600;
}

/* ── Search Diagram Badge ──────────────────────────────────────────── */
.search-diagram-badge {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin: 14px 0;
  padding: 10px 18px;
  background: rgba(0, 168, 104, 0.1);
  border: 1.5px dashed var(--accent, #00a868);
  border-radius: 8px;
  color: var(--accent, #00a868);
  font-weight: 600;
  font-size: 0.9rem;
  user-select: none;
}
.search-diagram-icon {
  font-size: 1.25rem;
}
.search-diagram-text {
  letter-spacing: -0.01em;
}

/* ── Responsive Queries ────────────────────────────────────────────── */
@media (max-width: 1024px) {
  .site-layout.has-sidebar {
    grid-template-columns: 1fr;
    gap: 0;
  }
  .sidebar-nav {
    display: none;
    position: fixed;
    top: 60px;
    left: 0;
    bottom: 0;
    width: 310px;
    background: var(--bg-card);
    z-index: 99;
    box-shadow: 0 10px 25px rgba(0,0,0,0.4);
    padding: 1.5rem;
  }
  .sidebar-nav.mobile-open {
    display: block;
  }
  .desktop-nav {
    display: none;
  }
  .mobile-menu-btn {
    display: flex;
  }
}

@media (max-width: 640px) {
  .float-right, .float-left, img[alt*="right"], img[alt*="left"] {
    float: none !important;
    display: block;
    margin: 1rem auto !important;
    max-width: 100% !important;
  }
}
