:root[data-theme="dark"] {
  --bg-color: #0f1219;
  --surface-color: #171c28;
  --surface-border: #283044;
  --text-main: #e2e8f0;
  --text-muted: #94a3b8;
  --accent-color: #c99a4e;
  --accent-hover: #e6b364;
  --primary-color: #3b82f6;
  --code-bg: #1e2536;
  --tree-hover: #222a3d;
  --tree-active: #2d374d;
}

:root[data-theme="light"] {
  --bg-color: #f8fafc;
  --surface-color: #ffffff;
  --surface-border: #e2e8f0;
  --text-main: #1e293b;
  --text-muted: #64748b;
  --accent-color: #b45309;
  --accent-hover: #d97706;
  --primary-color: #2563eb;
  --code-bg: #f1f5f9;
  --tree-hover: #f1f5f9;
  --tree-active: #e2e8f0;
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background-color: var(--bg-color);
  color: var(--text-main);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
.app-header {
  height: 60px;
  background-color: var(--surface-color);
  border-bottom: 1px solid var(--surface-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-left { display: flex; align-items: center; gap: 12px; }

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: var(--accent-color);
  font-family: 'Cinzel', serif;
  font-weight: 700;
  font-size: 1.25rem;
}

.header-center { flex: 1; max-width: 480px; margin: 0 20px; }

.search-box {
  position: relative;
  display: flex;
  align-items: center;
}

.search-box svg {
  position: absolute;
  left: 12px;
  color: var(--text-muted);
}

.search-box input {
  width: 100%;
  padding: 8px 12px 8px 36px;
  border-radius: 8px;
  border: 1px solid var(--surface-border);
  background: var(--bg-color);
  color: var(--text-main);
  outline: none;
}

.search-results {
  position: absolute;
  top: 45px;
  left: 0;
  right: 0;
  background: var(--surface-color);
  border: 1px solid var(--surface-border);
  border-radius: 8px;
  box-shadow: 0 10px 25px rgba(0,0,0,0.3);
  max-height: 360px;
  overflow-y: auto;
  display: none;
  z-index: 200;
}

.search-item {
  display: block;
  padding: 10px 14px;
  text-decoration: none;
  border-bottom: 1px solid var(--surface-border);
  color: var(--text-main);
}
.search-item:hover { background: var(--tree-hover); }
.search-title { font-weight: 600; color: var(--accent-color); font-size: 0.95rem; }
.search-path { font-size: 0.75rem; color: var(--text-muted); }
.search-snippet { font-size: 0.85rem; margin-top: 4px; color: var(--text-muted); }

.header-right { display: flex; align-items: center; gap: 12px; }

/* Buttons */
.btn {
  padding: 8px 16px;
  border-radius: 6px;
  border: none;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s;
}
.btn-primary { background: var(--accent-color); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--surface-border); color: var(--text-main); }
.btn-secondary:hover { background: var(--tree-active); }
.btn-outline { border: 1px solid var(--surface-border); background: transparent; color: var(--text-main); }
.btn-sm { padding: 6px 12px; font-size: 0.85rem; }

.btn-oauth {
  text-decoration: none;
  justify-content: center;
  margin-bottom: 10px;
  font-size: 0.9rem;
}
.btn-google {
  background: #ffffff;
  color: #3c4043;
  border: 1px solid #dadce0;
}
.btn-google:hover {
  background: #f8f9fa;
  color: #202124;
}
.btn-discord {
  background: #5865F2;
  color: #ffffff;
}
.btn-discord:hover {
  background: #4752C4;
}

.auth-divider {
  display: flex;
  align-items: center;
  text-align: center;
  margin: 16px 0;
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 600;
}
.auth-divider::before, .auth-divider::after {
  content: '';
  flex: 1;
  border-bottom: 1px solid var(--surface-border);
}
.auth-divider span {
  padding: 0 10px;
}

.icon-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
}
.icon-btn:hover { background: var(--tree-hover); color: var(--text-main); }

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

/* User Badge */
.user-badge { display: flex; align-items: center; gap: 10px; font-size: 0.85rem; }
.group-tag {
  background: var(--surface-border);
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 0.75rem;
  color: var(--accent-color);
}

/* Layout Container */
.app-container {
  display: flex;
  flex: 1;
}

/* Sidebar */
.sidebar {
  width: 280px;
  background: var(--surface-color);
  border-right: 1px solid var(--surface-border);
  padding: 16px 12px;
  overflow-y: auto;
}
.sidebar-header { margin-bottom: 12px; padding: 0 8px; }
.sidebar-header h3 {
  font-family: 'Cinzel', serif;
  font-size: 0.9rem;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.05em;
}

.file-tree ul { list-style: none; padding-left: 12px; }
.file-tree > ul { padding-left: 0; }
.file-tree li { margin: 2px 0; }

.file-tree summary {
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 6px;
  font-weight: 500;
  font-size: 0.9rem;
  color: var(--text-main);
}
.file-tree summary:hover { background: var(--tree-hover); }

.file-tree a {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border-radius: 6px;
  text-decoration: none;
  color: var(--text-main);
  font-size: 0.9rem;
}
.file-tree a:hover { background: var(--tree-hover); }
.file-tree li.active > a { background: var(--tree-active); color: var(--accent-color); font-weight: 600; }

/* Main Content */
.main-content {
  flex: 1;
  padding: 24px 32px;
  max-width: 960px;
  margin: 0 auto;
}

.content-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--surface-border);
}

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

/* Markdown Body */
.markdown-body { font-size: 1rem; color: var(--text-main); }
.markdown-body h1, .markdown-body h2, .markdown-body h3 {
  font-family: 'Cinzel', serif;
  color: var(--accent-color);
  margin-top: 1.5em;
  margin-bottom: 0.6em;
  line-height: 1.3;
}
.markdown-body h1 { font-size: 2.2rem; border-bottom: 1px solid var(--surface-border); padding-bottom: 8px; }
.markdown-body h2 { font-size: 1.6rem; }
.markdown-body h3 { font-size: 1.25rem; }

.markdown-body p { margin-bottom: 1.2em; }
.markdown-body img {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  box-shadow: 0 4px 15px rgba(0,0,0,0.2);
  margin: 16px 0;
  display: block;
}

.markdown-body blockquote {
  border-left: 4px solid var(--accent-color);
  padding: 10px 16px;
  background: var(--surface-color);
  margin: 16px 0;
  border-radius: 0 8px 8px 0;
  font-style: italic;
}

.markdown-body code {
  background: var(--code-bg);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'Fira Code', monospace;
  font-size: 0.9em;
}

.markdown-body pre code { display: block; padding: 14px; overflow-x: auto; }

/* Table of Contents Sidebar */
.toc-sidebar {
  width: 240px;
  padding: 24px 16px;
  border-left: 1px solid var(--surface-border);
}
.toc-title { font-weight: 700; font-size: 0.85rem; text-transform: uppercase; color: var(--text-muted); margin-bottom: 12px; }
.toc-list { list-style: none; }
.toc-item { margin: 6px 0; }
.toc-item a { text-decoration: none; color: var(--text-muted); font-size: 0.85rem; }
.toc-item a:hover { color: var(--accent-color); }
.toc-item.level-2 { padding-left: 12px; }
.toc-item.level-3 { padding-left: 24px; }

/* Modal */
.modal-backdrop {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.7);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 500;
  padding: 20px;
}

.modal-card {
  background: var(--surface-color);
  border-radius: 12px;
  width: 100%;
  max-width: 440px;
  border: 1px solid var(--surface-border);
  box-shadow: 0 20px 40px rgba(0,0,0,0.4);
  padding: 24px;
}

.modal-card.modal-lg { max-width: 900px; height: 80vh; display: flex; flex-direction: column; }

.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.modal-header h3 { font-family: 'Cinzel', serif; color: var(--accent-color); }
.close-btn { background: none; border: none; font-size: 1.5rem; color: var(--text-muted); cursor: pointer; }

.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 0.85rem; margin-bottom: 6px; color: var(--text-muted); }
.form-group input {
  width: 100%;
  padding: 10px;
  border-radius: 6px;
  border: 1px solid var(--surface-border);
  background: var(--bg-color);
  color: var(--text-main);
}

.editor-container { flex: 1; display: flex; flex-direction: column; margin-bottom: 16px; }
#editorTextarea {
  flex: 1;
  width: 100%;
  background: var(--bg-color);
  color: var(--text-main);
  border: 1px solid var(--surface-border);
  border-radius: 8px;
  padding: 16px;
  font-family: 'Fira Code', monospace;
  font-size: 0.95rem;
  resize: none;
  outline: none;
}

.modal-footer { display: flex; justify-content: flex-end; gap: 12px; }
.btn-block { width: 100%; }
.error-msg { color: #ef4444; font-size: 0.85rem; margin-bottom: 12px; }

@media (max-width: 992px) {
  .toc-sidebar { display: none; }
  .mobile-menu-toggle { display: block; }
  .sidebar {
    position: fixed;
    top: 60px; bottom: 0; left: -280px;
    z-index: 300;
    transition: left 0.3s ease;
  }
  .sidebar.open { left: 0; }
}

/* Sidebar header with "+" button */
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sidebar-add-btn {
  padding: 4px;
  border-radius: 5px;
  color: var(--text-muted);
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}
.sidebar-add-btn:hover {
  background: var(--tree-hover);
  color: var(--accent-color);
}

/* Context Menu */
.context-menu {
  position: fixed;
  z-index: 1000;
  background: var(--surface-color);
  border: 1px solid var(--surface-border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.35);
  padding: 4px;
  min-width: 160px;
  animation: ctxFadeIn 0.12s ease;
}

@keyframes ctxFadeIn {
  from { opacity: 0; transform: scale(0.96) translateY(-4px); }
  to   { opacity: 1; transform: scale(1)   translateY(0); }
}

.context-menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 12px;
  background: none;
  border: none;
  border-radius: 5px;
  color: var(--text-main);
  font-size: 0.88rem;
  font-family: inherit;
  cursor: pointer;
  text-align: left;
  transition: background 0.12s, color 0.12s;
}
.context-menu-item:hover {
  background: var(--tree-hover);
  color: var(--accent-color);
}
.context-menu-item svg {
  flex-shrink: 0;
  color: var(--text-muted);
}
.context-menu-item:hover svg {
  color: var(--accent-color);
}
