/* === Base === */
:root, [data-theme="light"] {
  --bg: #f5f6f8;
  --bg-surface: #ffffff;
  --bg-hover: #eef0f4;
  --bg-active: #e4e7ed;
  --border: #d8dce6;
  --text: #1a1d27;
  --text-muted: #6b7280;
  --accent: #4f6df5;
  --accent-hover: #3b5bdb;
  --green: #16a34a;
  --red: #dc2626;
  --yellow: #d97706;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --code-bg: #f0f1f4;
  --sidebar-w: 280px;
  --radius: 10px;
  --radius-sm: 6px;
}

[data-theme="dark"] {
  --bg: #0f1117;
  --bg-surface: #1a1d27;
  --bg-hover: #22263a;
  --bg-active: #2a2f45;
  --border: #2d3148;
  --text: #e1e4ed;
  --text-muted: #8b90a5;
  --accent: #6c8dff;
  --accent-hover: #8ba3ff;
  --green: #34d399;
  --red: #f87171;
  --yellow: #fbbf24;
  --shadow: 0 1px 3px rgba(0,0,0,0.3);
  --code-bg: #0f1117;
}

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

html {
  overflow-x: hidden;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  overflow-x: hidden;
  width: 100%;
  max-width: 100%;
}

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

/* === Login === */
.login-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--bg), var(--bg-surface));
}

.login-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2.5rem;
  width: 100%;
  max-width: 400px;
  margin: 0 1rem;
  text-align: center;
}

.login-card h1 { font-size: 2rem; margin-bottom: 0.5rem; }
.login-subtitle { color: var(--text-muted); margin-bottom: 2rem; }

.form-group {
  text-align: left;
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 0.3rem;
}

.form-group input {
  width: 100%;
  padding: 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 1rem;
  outline: none;
  transition: border-color 0.2s;
}

.form-group input:focus { border-color: var(--accent); }

.remember-group { margin-top: 0.5rem; }
.checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--text-muted);
}
.checkbox-label input[type="checkbox"] {
  width: auto;
  accent-color: var(--accent);
  cursor: pointer;
}

.btn {
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover { background: var(--accent-hover); }
.btn-block { width: 100%; margin-top: 1rem; }

.error-msg {
  background: color-mix(in srgb, var(--red) 15%, transparent);
  color: var(--red);
  padding: 0.75rem;
  border-radius: var(--radius-sm);
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

/* === App Layout === */
.app {
  display: flex;
  min-height: 100vh;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

/* === Sidebar === */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
  transition: transform 0.3s ease;
}

.sidebar-header {
  padding: 1.25rem 1rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo { font-size: 1.3rem; font-weight: 700; }

.sidebar-close {
  display: none;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
}

.sidebar-search {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
}

.sidebar-search input {
  width: 100%;
  padding: 0.5rem 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.9rem;
  outline: none;
}

.sidebar-search input:focus { border-color: var(--accent); }

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem 0;
}

.nav-item {
  display: block;
  padding: 0.5rem 1rem;
  color: var(--text);
  font-size: 0.9rem;
  transition: all 0.15s;
  border-left: 3px solid transparent;
}

.nav-item:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.nav-item.active {
  background: var(--bg-active);
  border-left-color: var(--accent);
  color: var(--accent);
}

.nav-home { font-weight: 600; }

.nav-category { margin-top: 0.5rem; }

.nav-category-title {
  display: block;
  padding: 0.4rem 1rem;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  font-weight: 600;
}

.nav-project { padding-left: 2rem; font-size: 0.85rem; }

.sidebar-footer {
  padding: 1rem;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.85rem;
}

.user-badge {
  background: var(--bg-active);
  padding: 0.25rem 0.75rem;
  border-radius: 20px;
  font-size: 0.8rem;
}

.logout-link { color: var(--text-muted); font-size: 0.8rem; }
.logout-link:hover { color: var(--red); }

/* === Content === */
.content {
  flex: 1;
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  min-width: 0;
  max-width: calc(100vw - var(--sidebar-w));
  overflow-x: hidden;
}

.topbar {
  padding: 0.75rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 1rem;
  background: var(--bg-surface);
  position: sticky;
  top: 0;
  z-index: 50;
}

.hamburger {
  display: none;
  background: none;
  border: none;
  color: var(--text);
  font-size: 1.5rem;
  cursor: pointer;
}

.breadcrumbs {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.breadcrumbs a { color: var(--text-muted); }
.breadcrumbs a:hover { color: var(--accent); }
.breadcrumbs strong { color: var(--text); }

.page-content {
  padding: 1.5rem;
  max-width: 1200px;
  min-width: 0;
  overflow-x: hidden;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

/* === Dashboard === */
.categories-grid {
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

.category-section {}

.category-title {
  font-size: 1.1rem;
  margin-bottom: 0.75rem;
  color: var(--text);
  font-weight: 600;
}

.project-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 0.75rem;
}

.project-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  transition: all 0.2s;
  color: var(--text);
  display: block;
}

.project-card:hover {
  border-color: var(--accent);
  background: var(--bg-hover);
  transform: translateY(-1px);
  color: var(--text);
}

.project-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}

.project-name { font-weight: 600; font-size: 1rem; }

.project-desc {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.project-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.link-tag {
  font-size: 0.75rem;
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  padding: 0.15rem 0.5rem;
  border-radius: 12px;
}

/* Status badges */
.status-badge {
  font-size: 0.75rem;
  padding: 0.2rem 0.6rem;
  border-radius: 12px;
  font-weight: 500;
}

.status-active {
  background: color-mix(in srgb, var(--green) 15%, transparent);
  color: var(--green);
}

.status-inactive, .status-failed, .status-dead {
  background: color-mix(in srgb, var(--red) 15%, transparent);
  color: var(--red);
}

.status-unknown {
  background: color-mix(in srgb, var(--text-muted) 15%, transparent);
  color: var(--text-muted);
}

/* === Project Page === */
.project-header {
  margin-bottom: 2rem;
}

.project-header h2 { font-size: 1.5rem; margin-bottom: 0.5rem; }

.project-description {
  color: var(--text-muted);
  font-size: 1rem;
  margin-bottom: 0.75rem;
}

.project-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.meta-tag {
  font-size: 0.8rem;
  color: var(--text-muted);
  background: var(--bg-hover);
  padding: 0.25rem 0.75rem;
  border-radius: 12px;
  word-break: break-all;
  max-width: 100%;
}

.section {
  margin-bottom: 2rem;
}

.section h3 {
  font-size: 1.1rem;
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

.links-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.link-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.6rem 1rem;
  font-size: 0.9rem;
  transition: all 0.2s;
}

.link-card:hover {
  border-color: var(--accent);
  background: var(--bg-hover);
}

/* Docs list */
.docs-list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.doc-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  transition: all 0.15s;
}

.doc-item:hover {
  border-color: var(--accent);
  background: var(--bg-hover);
  color: var(--text);
}

.doc-icon { font-size: 1.2rem; }
.doc-name { flex: 1; font-size: 0.9rem; }
.doc-meta { font-size: 0.75rem; color: var(--text-muted); white-space: nowrap; }

/* Folder tree */
.folder-tree {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1rem;
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 0.85rem;
  max-height: 400px;
  overflow-y: auto;
}

.tree-item {
  padding: 0.15rem 0;
  white-space: nowrap;
}

.tree-dir { color: var(--accent); }
.tree-file { color: var(--text-muted); }

.tree-children { padding-left: 1.5rem; }

/* === Document Page === */
.doc-header {
  margin-bottom: 1.5rem;
}

.doc-header h2 { font-size: 1.3rem; margin-bottom: 0.5rem; }

.doc-header-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

/* Editor styles */
.btn-edit {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 0.35rem 0.8rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 500;
  transition: background 0.15s;
}
.btn-edit:hover { background: var(--accent-hover); }

.btn-edit-sm {
  padding: 0.25rem 0.6rem;
  font-size: 0.78rem;
}

.editor-toolbar {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 0.5rem;
}

.btn-save {
  background: var(--green);
  color: #fff;
  border: none;
  padding: 0.4rem 1rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 500;
}
.btn-save:hover { opacity: 0.9; }

.btn-cancel {
  background: var(--bg-hover);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 0.4rem 1rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.85rem;
}
.btn-cancel:hover { background: var(--bg-active); }

.file-editor {
  width: 100%;
  min-height: 400px;
  background: var(--bg-surface);
  color: var(--text);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 1.2rem;
  font-family: 'SF Mono', 'Consolas', 'Monaco', 'Menlo', monospace;
  font-size: 0.85rem;
  line-height: 1.6;
  resize: vertical;
  box-sizing: border-box;
  tab-size: 2;
  outline: none;
}
.file-editor:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79, 109, 245, 0.15);
}

.save-status {
  font-size: 0.82rem;
  margin-left: 0.5rem;
}
.save-status.saving { color: var(--yellow); }
.save-status.saved { color: var(--green); }
.save-status.error { color: var(--red); }

.markdown-body {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  line-height: 1.7;
  min-width: 0;
  max-width: 100%;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.markdown-body h1, .markdown-body h2, .markdown-body h3,
.markdown-body h4, .markdown-body h5 {
  margin-top: 1.5em;
  margin-bottom: 0.5em;
  color: var(--text);
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.3em;
}

.markdown-body h1 { font-size: 1.5rem; }
.markdown-body h2 { font-size: 1.3rem; }
.markdown-body h3 { font-size: 1.1rem; border-bottom: none; }

.markdown-body p { margin-bottom: 1em; }

.markdown-body ul, .markdown-body ol {
  margin-bottom: 1em;
  padding-left: 2em;
}

.markdown-body li { margin-bottom: 0.3em; }

.markdown-body code {
  background: var(--code-bg, var(--bg));
  padding: 0.15em 0.4em;
  border-radius: 3px;
  font-size: 0.9em;
  font-family: 'SF Mono', 'Fira Code', monospace;
  word-break: break-all;
}

.markdown-body pre {
  background: var(--code-bg, var(--bg));
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1rem;
  overflow-x: auto;
  margin-bottom: 1em;
  white-space: pre;
  word-wrap: normal;
}

.markdown-body pre code {
  background: none;
  padding: 0;
  font-size: 0.85rem;
}

.table-wrap, .pre-wrap {
  overflow-x: auto;
  max-width: 100%;
  margin-bottom: 1em;
  -webkit-overflow-scrolling: touch;
}

.table-wrap table, .pre-wrap pre {
  margin-bottom: 0;
}

.markdown-body table {
  border-collapse: collapse;
  width: max-content;
  min-width: 100%;
}

.markdown-body th, .markdown-body td {
  border: 1px solid var(--border);
  padding: 0.5rem 0.75rem;
  text-align: left;
  font-size: 0.9rem;
}

.markdown-body th {
  background: var(--bg-hover);
  font-weight: 600;
}

.markdown-body a { color: var(--accent); }
.markdown-body a:hover { text-decoration: underline; }

.markdown-body blockquote {
  border-left: 4px solid var(--accent);
  padding-left: 1rem;
  color: var(--text-muted);
  margin-bottom: 1em;
}

.markdown-body img {
  max-width: 100%;
  border-radius: var(--radius-sm);
}

.markdown-body hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1.5em 0;
}

/* === Wiki content === */
.wiki-content {
  margin-bottom: 2rem;
}

.wiki-content .markdown-body h1:first-child {
  margin-top: 0;
  border-bottom: 2px solid var(--accent);
}

.wiki-meta {
  margin-top: 0.5rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: right;
}

.meta-tag-small {
  font-size: 0.7rem;
  background: var(--bg-hover);
  padding: 0.15rem 0.5rem;
  border-radius: 8px;
}

.meta-link {
  color: var(--accent) !important;
  cursor: pointer;
  transition: all 0.15s;
}

.meta-link:hover {
  background: color-mix(in srgb, var(--accent) 20%, transparent);
}

/* Git log */
.git-log {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
}

.git-commit {
  padding: 0.3rem 0;
  font-size: 0.85rem;
  border-bottom: 1px solid var(--border);
  overflow-wrap: break-word;
  word-break: break-word;
}

.git-commit:last-child { border-bottom: none; }

.git-hash {
  color: var(--accent);
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 0.8rem;
  margin-right: 0.5rem;
}

/* Collapsible details */
details.section > summary {
  cursor: pointer;
  padding: 0.5rem 0;
  user-select: none;
  list-style: none;
}

details.section > summary::-webkit-details-marker { display: none; }

details.section > summary::before {
  content: '▶ ';
  font-size: 0.75rem;
  color: var(--text-muted);
}

details.section[open] > summary::before {
  content: '▼ ';
}

/* === Search === */
.search-results {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.search-result {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
}

.search-result-title {
  font-size: 1.1rem;
  font-weight: 600;
  display: block;
  margin-bottom: 0.25rem;
}

.search-result-desc {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.search-result-doc {
  display: block;
  padding: 0.5rem 0.75rem;
  background: var(--bg);
  border-radius: var(--radius-sm);
  margin-top: 0.4rem;
  font-size: 0.85rem;
  color: var(--text);
}

.search-result-doc:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.search-snippet {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
  font-family: monospace;
  white-space: pre-wrap;
  word-break: break-all;
}

.empty-state {
  color: var(--text-muted);
  text-align: center;
  padding: 3rem;
  font-size: 1rem;
}

/* === Sidebar overlay (mobile) === */
.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 99;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
}

.sidebar-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

/* === Mobile === */
@media (max-width: 768px) {
  :root {
    --sidebar-w: 280px;
  }

  .sidebar {
    transform: translateX(-100%);
    width: 85vw;
    max-width: 320px;
  }

  .sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 20px rgba(0,0,0,0.2);
  }

  .sidebar-close { display: block; }
  .hamburger { display: block; }

  .content {
    margin-left: 0;
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
  }

  .topbar {
    padding: 0.5rem 0.75rem;
    gap: 0.5rem;
  }

  .topbar .hamburger {
    flex-shrink: 0;
    padding: 0.25rem;
    font-size: 1.3rem;
  }

  .breadcrumbs {
    font-size: 0.8rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .page-content {
    padding: 0.75rem;
    max-width: 100vw;
    min-width: 0;
  }

  /* Dashboard */
  .categories-grid {
    gap: 1.25rem;
  }

  .category-title {
    font-size: 1rem;
    margin-bottom: 0.5rem;
  }

  .project-cards {
    grid-template-columns: 1fr;
    gap: 0.5rem;
  }

  .project-card {
    padding: 0.75rem 1rem;
  }

  .project-name {
    font-size: 0.95rem;
  }

  .project-desc {
    font-size: 0.8rem;
  }

  .link-tag {
    font-size: 0.7rem;
  }

  /* Project page */
  .project-header {
    margin-bottom: 1rem;
  }

  .project-header h2 {
    font-size: 1.2rem;
  }

  .project-meta {
    gap: 0.35rem;
    max-width: 100%;
  }

  .meta-tag {
    font-size: 0.7rem;
    padding: 0.2rem 0.5rem;
    word-break: break-all;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .status-badge {
    font-size: 0.65rem;
    padding: 0.15rem 0.4rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
  }

  .section {
    margin-bottom: 1.25rem;
  }

  .section h3 {
    font-size: 1rem;
    margin-bottom: 0.5rem;
  }

  /* Wiki / Markdown */
  .markdown-body {
    padding: 0.75rem;
    font-size: 0.9rem;
    border-radius: var(--radius-sm);
    overflow-x: hidden;
    min-width: 0;
  }

  .markdown-body h1 { font-size: 1.25rem; }
  .markdown-body h2 { font-size: 1.1rem; }
  .markdown-body h3 { font-size: 1rem; }

  .markdown-body pre {
    padding: 0.75rem;
    font-size: 0.78rem;
  }

  .markdown-body ul, .markdown-body ol {
    padding-left: 1.25em;
  }

  .markdown-body table {
    font-size: 0.75rem;
  }

  .markdown-body th, .markdown-body td {
    padding: 0.25rem 0.4rem;
    min-width: unset;
    word-break: break-word;
  }

  .markdown-body code {
    font-size: 0.8em;
    word-break: break-all;
  }

  /* Git log */
  .git-log {
    padding: 0.5rem 0.75rem;
  }

  .git-commit {
    font-size: 0.8rem;
    padding: 0.25rem 0;
  }

  .git-hash {
    font-size: 0.75rem;
  }

  /* Docs list */
  .doc-item {
    padding: 0.5rem 0.75rem;
    gap: 0.5rem;
  }

  .doc-name {
    font-size: 0.85rem;
  }

  .doc-meta {
    font-size: 0.7rem;
  }

  /* Document page */
  .doc-header h2 {
    font-size: 1.15rem;
  }

  /* Folder tree */
  .folder-tree {
    padding: 0.75rem;
    font-size: 0.78rem;
    max-height: 300px;
  }

  .tree-children {
    padding-left: 1rem;
  }

  /* Search */
  .search-result {
    padding: 0.75rem;
  }

  .search-result-title {
    font-size: 1rem;
  }

  .search-snippet {
    font-size: 0.75rem;
    word-break: break-word;
  }

  .empty-state {
    padding: 2rem 1rem;
    font-size: 0.9rem;
  }

  /* Modal (category reorg) */
  #reorg-modal > div {
    width: 98% !important;
    max-height: 90vh !important;
    padding: 1rem !important;
  }
}

/* === Small phones (< 400px) === */
@media (max-width: 400px) {
  .login-card {
    margin: 0.5rem;
    padding: 1.5rem;
  }

  .login-card h1 {
    font-size: 1.5rem;
  }

  .page-content {
    padding: 0.5rem;
  }

  .markdown-body {
    padding: 0.5rem;
  }

  .project-card {
    padding: 0.6rem 0.75rem;
  }

  .sidebar {
    width: 90vw;
  }
}

/* === Theme Toggle === */
.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.3rem 0.5rem;
  font-size: 1rem;
  line-height: 1;
  transition: all 0.2s;
}
.theme-toggle:hover {
  color: var(--accent);
  border-color: var(--accent);
}

/* Cards shadow in light theme */
[data-theme="light"] .project-card,
:root .project-card {
  box-shadow: var(--shadow);
}
[data-theme="dark"] .project-card {
  box-shadow: none;
}

[data-theme="light"] .markdown-body,
:root .markdown-body {
  box-shadow: var(--shadow);
}
[data-theme="dark"] .markdown-body {
  box-shadow: none;
}

/* === File Manager === */
.files-header {
  margin-bottom: 1.5rem;
}

.files-header h2 {
  font-size: 1.5rem;
  margin-bottom: 0.5rem;
}

.files-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.files-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.file-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 1rem;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  transition: all 0.15s;
  text-decoration: none;
}

.file-item:hover {
  border-color: var(--accent);
  background: var(--bg-hover);
  color: var(--text);
}

.file-item-parent {
  background: var(--bg);
  border-style: dashed;
}

.file-item-parent:hover {
  background: var(--bg-hover);
}

.file-icon {
  font-size: 1.2rem;
  flex-shrink: 0;
  width: 1.5rem;
  text-align: center;
}

.file-name {
  flex: 1;
  font-size: 0.9rem;
  font-family: 'SF Mono', 'Fira Code', monospace;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-item-dir .file-name {
  font-weight: 600;
  color: var(--accent);
}

.file-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}

.file-view-header {
  margin-bottom: 1.5rem;
}

.file-view-header h2 {
  font-size: 1.3rem;
  margin-bottom: 0.5rem;
}

.nav-files {
  font-weight: 600;
}

@media (max-width: 768px) {
  .file-item {
    padding: 0.5rem 0.75rem;
    gap: 0.5rem;
  }

  .file-name {
    font-size: 0.82rem;
  }

  .file-meta {
    font-size: 0.7rem;
  }

  .files-header h2 {
    font-size: 1.2rem;
  }
}

/* === Admin Panel === */
.admin-header { margin-bottom: 1.5rem; }
.admin-header h2 { font-size: 1.5rem; margin-bottom: 0.25rem; }
.admin-subtitle { color: var(--text-muted); font-size: 0.9rem; }

.admin-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 1rem;
  padding: 0.75rem;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.admin-toolbar-right { margin-left: auto; }
.admin-count { font-size: 0.85rem; color: var(--text-muted); }

.admin-input {
  padding: 0.5rem 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.9rem;
  outline: none;
}
.admin-input:focus { border-color: var(--accent); }

/* Sessions */
.sessions-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.session-item {
  padding: 0.75rem 1rem;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s;
}
.session-item:hover {
  border-color: var(--accent);
  background: var(--bg-hover);
}
.session-active { border-left: 3px solid var(--green); }

.session-item-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.25rem;
}
.session-id {
  font-family: 'SF Mono', monospace;
  font-size: 0.85rem;
  color: var(--accent);
}
.session-item-meta { font-size: 0.75rem; color: var(--text-muted); }
.session-item-badges { display: flex; gap: 0.4rem; margin-bottom: 0.25rem; }
.session-owner {
  font-size: 0.7rem;
  padding: 0.1rem 0.4rem;
  background: color-mix(in srgb, var(--accent) 15%, transparent);
  color: var(--accent);
  border-radius: 8px;
}
.session-preview {
  font-size: 0.8rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Pagination */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin-top: 1rem;
  padding: 0.75rem;
}
.btn-page {
  padding: 0.4rem 0.8rem;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--accent);
  cursor: pointer;
  font-size: 0.85rem;
}
.btn-page:hover { background: var(--bg-hover); }
.page-info { font-size: 0.85rem; color: var(--text-muted); }

/* Admin Modal */
.admin-modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 200;
  display: flex;
  justify-content: center;
  align-items: center;
  backdrop-filter: blur(3px);
}
.admin-modal-content {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 95%;
  max-width: 700px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.admin-modal-wide { max-width: 900px; }

.admin-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
}
.admin-modal-header h3 { margin: 0; font-size: 1.1rem; }
.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.3rem;
  cursor: pointer;
}
.modal-close:hover { color: var(--text); }

.admin-modal-footer {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1.5rem;
  border-top: 1px solid var(--border);
}

/* Session messages */
.session-meta {
  display: flex;
  gap: 1rem;
  padding: 0.5rem 1.5rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}

.session-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.msg {
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}
.msg-user { background: color-mix(in srgb, var(--accent) 8%, var(--bg)); border-left: 3px solid var(--accent); }
.msg-assistant { background: color-mix(in srgb, var(--green) 8%, var(--bg)); border-left: 3px solid var(--green); }
.msg-system { background: var(--bg); border-left: 3px solid var(--text-muted); }
.msg-tool { background: color-mix(in srgb, var(--yellow) 8%, var(--bg)); border-left: 3px solid var(--yellow); }

.msg-header { display: flex; justify-content: space-between; margin-bottom: 0.3rem; }
.msg-role { font-size: 0.75rem; font-weight: 600; text-transform: uppercase; }
.msg-role-user { color: var(--accent); }
.msg-role-assistant { color: var(--green); }
.msg-role-system { color: var(--text-muted); }
.msg-role-tool { color: var(--yellow); }
.msg-time { font-size: 0.7rem; color: var(--text-muted); }
.msg-content {
  font-size: 0.85rem;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.5;
}

/* Chat logs */
.log-entries {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-height: 70vh;
  overflow-y: auto;
  font-family: 'SF Mono', monospace;
  font-size: 0.8rem;
}

.log-line {
  padding: 0.4rem 0.75rem;
  border-bottom: 1px solid color-mix(in srgb, var(--border) 50%, transparent);
}
.log-line:hover { background: var(--bg-hover); }
.log-in { border-left: 3px solid var(--accent); }
.log-out { border-left: 3px solid var(--green); }
.log-raw { border-left: 3px solid var(--text-muted); color: var(--text-muted); }

.log-header { margin-bottom: 0.15rem; }
.log-time { color: var(--text-muted); font-size: 0.75rem; }
.log-dir { color: var(--text-muted); }
.log-sender { color: var(--accent); font-weight: 600; }
.log-text { color: var(--text); word-break: break-word; white-space: pre-wrap; line-height: 1.4; }

/* System monitor */
.system-gauges {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.gauge-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  text-align: center;
}

.gauge-ring {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  background: conic-gradient(var(--color) calc(var(--pct) * 3.6deg), var(--bg) 0);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 0.75rem;
  position: relative;
}
.gauge-ring::before {
  content: '';
  width: 70px;
  height: 70px;
  border-radius: 50%;
  background: var(--bg-surface);
  position: absolute;
}
.gauge-value {
  position: relative;
  z-index: 1;
  font-size: 1.2rem;
  font-weight: 700;
}
.gauge-label { font-weight: 600; margin-bottom: 0.25rem; }
.gauge-detail { font-size: 0.8rem; color: var(--text-muted); }

.system-info-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.info-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1rem;
  display: flex;
  flex-direction: column;
}
.info-label { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 0.25rem; }
.info-value { font-size: 1.1rem; font-weight: 600; }

.section-title {
  font-size: 1.1rem;
  margin: 1.5rem 0 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

.svc-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 0.5rem;
}

.svc-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 1rem;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.svc-icon { flex-shrink: 0; }
.svc-name { flex: 1; font-size: 0.9rem; font-weight: 500; }
.svc-status { font-size: 0.8rem; color: var(--text-muted); }

/* Configs */
.configs-grid {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.config-section {}

.config-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.config-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s;
}
.config-item:hover {
  border-color: var(--accent);
  background: var(--bg-hover);
}
.config-icon { font-size: 1.2rem; }
.config-name { flex: 1; font-weight: 500; }
.config-id { font-size: 0.8rem; color: var(--text-muted); font-family: monospace; }

/* Memory */
.memory-sections {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.memory-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 0.5rem;
}

.memory-item {
  padding: 0.75rem 1rem;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s;
}
.memory-item:hover {
  border-color: var(--accent);
  background: var(--bg-hover);
}

.memory-item-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.25rem; }
.memory-name { font-weight: 600; font-size: 0.95rem; }
.memory-type {
  font-size: 0.7rem;
  padding: 0.1rem 0.5rem;
  border-radius: 8px;
  font-weight: 500;
}
.type-feedback { background: color-mix(in srgb, var(--yellow) 15%, transparent); color: var(--yellow); }
.type-user { background: color-mix(in srgb, var(--accent) 15%, transparent); color: var(--accent); }
.type-project { background: color-mix(in srgb, var(--green) 15%, transparent); color: var(--green); }
.type-reference { background: color-mix(in srgb, var(--red) 15%, transparent); color: var(--red); }

.memory-desc { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 0.25rem; }
.memory-meta { font-size: 0.7rem; color: var(--text-muted); }

/* Tab buttons */
.memory-editor-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
}
.tab-btn {
  padding: 0.5rem 1.5rem;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.9rem;
}
.tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}
.tab-btn:hover { color: var(--text); }

/* Loading */
.loading {
  text-align: center;
  padding: 2rem;
  color: var(--text-muted);
}

/* Admin responsive */
@media (max-width: 768px) {
  .admin-toolbar {
    padding: 0.5rem;
    gap: 0.4rem;
  }
  .admin-input { font-size: 0.85rem; padding: 0.4rem 0.6rem; }
  .session-item { padding: 0.6rem 0.75rem; }
  .admin-modal-content { width: 98%; max-height: 90vh; }
  .admin-modal-wide { max-width: 98%; }
  .system-gauges { grid-template-columns: repeat(3, 1fr); gap: 0.5rem; }
  .gauge-card { padding: 1rem 0.5rem; }
  .gauge-ring { width: 70px; height: 70px; }
  .gauge-ring::before { width: 50px; height: 50px; }
  .gauge-value { font-size: 0.9rem; }
  .svc-grid { grid-template-columns: 1fr; }
  .memory-list { grid-template-columns: 1fr; }
  .log-entries { font-size: 0.7rem; }
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
