:root {
  --bg: #0e1116;
  --bg-elev: #161b22;
  --bg-subtle: #1c222b;
  --border: #2a323e;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #4c9aff;
  --accent-hover: #6cb0ff;
  --danger: #f85149;
  --code-bg: #161b22;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
  --radius: 8px;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

[data-theme="light"] {
  --bg: #ffffff;
  --bg-elev: #f6f8fa;
  --bg-subtle: #eef2f6;
  --border: #d8dee4;
  --text: #1f2328;
  --muted: #656d76;
  --accent: #0969da;
  --accent-hover: #0550ae;
  --danger: #cf222e;
  --code-bg: #f6f8fa;
  --shadow: 0 10px 28px rgba(31, 35, 40, 0.12);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.6;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, pre { font-family: var(--font-mono); }

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.full-width { width: 100%; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 6px;
  border: 1px solid transparent;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
}
.btn-sm { padding: 5px 11px; font-size: 13px; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--bg-subtle); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { border-color: var(--accent); }
.btn-ghost { background: transparent; color: var(--muted); border-color: var(--border); }
.btn-ghost:hover { color: var(--text); background: var(--bg-subtle); }
.btn-danger { background: transparent; color: var(--danger); border-color: var(--border); }
.btn-danger:hover { background: rgba(248, 81, 73, 0.12); border-color: var(--danger); }

.icon-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  width: 32px;
  height: 32px;
  cursor: pointer;
  font-size: 15px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:hover { background: var(--bg-subtle); }

/* Login */
.login-view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px;
  box-shadow: var(--shadow);
}
.brand-row { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.brand-row h1 { margin: 0; font-size: 22px; }
.brand-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  display: inline-block;
}

form label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 14px;
  font-size: 13px;
  font-weight: 500;
}
input[type="email"],
input[type="password"],
input[type="text"],
input[type="search"] {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 14px;
  outline: none;
}
input:focus { border-color: var(--accent); }

.error-msg {
  background: rgba(248, 81, 73, 0.12);
  border: 1px solid rgba(248, 81, 73, 0.4);
  color: var(--danger);
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 13px;
  margin-bottom: 12px;
}

/* App Shell */
.app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.topbar {
  height: 52px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  gap: 12px;
}
.topbar-left, .topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-weight: 700;
  font-size: 15px;
  flex-shrink: 0;
}
.brand:hover { text-decoration: none; }

.breadcrumbs {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-badge {
  font-size: 12.5px;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  color: var(--muted);
}
.user-badge strong { color: var(--text); font-weight: 600; }

/* Workspace */
.workspace {
  display: flex;
  flex: 1;
  min-height: 0;
  position: relative;
}

.sidebar {
  width: 270px;
  flex-shrink: 0;
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 12px;
  overflow-y: auto;
}
.sidebar-top {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}
.search-input { width: 100%; min-width: 0; padding: 6px 10px; font-size: 13px; }

.search-results {
  margin-bottom: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  overflow: hidden;
}
.search-hit {
  display: block;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}
.search-hit:last-child { border-bottom: none; }
.search-hit:hover { background: var(--bg-subtle); text-decoration: none; }
.search-hit-title { font-weight: 600; font-size: 13.5px; }
.search-hit-snippet { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* Page Tree */
.tree-folder { margin-bottom: 4px; }
.tree-folder-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 6px 6px;
  cursor: pointer;
  text-align: left;
  border-radius: 5px;
}
.tree-folder-btn:hover { background: var(--bg-subtle); color: var(--text); }
.tree-children { padding-left: 12px; }

.tree-item {
  display: block;
  padding: 6px 10px;
  border-radius: 6px;
  color: var(--text);
  font-size: 14px;
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tree-item:hover { background: var(--bg-subtle); text-decoration: none; }
.tree-item.active {
  background: rgba(76, 154, 255, 0.15);
  color: var(--accent);
  font-weight: 600;
}

/* Main Content */
.main {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.read-view {
  max-width: 860px;
  width: 100%;
  margin: 0 auto;
  padding: 24px 32px 64px;
}
.page-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 14px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.page-meta { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.slug-pill {
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 5px;
  background: var(--bg-subtle);
  color: var(--muted);
}
.page-actions { display: flex; gap: 8px; }

/* Markdown Typography */
.markdown-body h1, .markdown-body h2, .markdown-body h3, .markdown-body h4 {
  margin-top: 1.5em;
  margin-bottom: 0.6em;
  line-height: 1.25;
  font-weight: 650;
}
.markdown-body h1 { font-size: 2em; margin-top: 0; padding-bottom: 0.3em; border-bottom: 1px solid var(--border); }
.markdown-body h2 { font-size: 1.45em; padding-bottom: 0.25em; border-bottom: 1px solid var(--border); }
.markdown-body h3 { font-size: 1.2em; }
.markdown-body p { margin: 0 0 1em; }
.markdown-body ul, .markdown-body ol { padding-left: 1.6em; margin: 0 0 1em; }
.markdown-body li { margin: 0.25em 0; }
.markdown-body hr { border: none; border-top: 1px solid var(--border); margin: 1.6em 0; }
.markdown-body blockquote {
  margin: 0 0 1em;
  padding: 6px 14px;
  border-left: 3px solid var(--accent);
  background: var(--bg-elev);
  color: var(--muted);
  border-radius: 0 6px 6px 0;
}
.markdown-body :not(pre) > code {
  background: var(--bg-subtle);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.88em;
}
.code-block {
  position: relative;
  margin: 0 0 1.1em;
}
.code-block pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  overflow-x: auto;
  margin: 0;
  font-size: 13.5px;
  line-height: 1.5;
}
.copy-code-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  background: var(--bg-subtle);
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 3px 8px;
  font-size: 11.5px;
  cursor: pointer;
}
.copy-code-btn:hover { color: var(--text); border-color: var(--accent); }

.markdown-body table {
  border-collapse: collapse;
  width: 100%;
  margin: 0 0 1.2em;
  display: block;
  overflow-x: auto;
}
.markdown-body th, .markdown-body td {
  border: 1px solid var(--border);
  padding: 8px 12px;
  text-align: left;
}
.markdown-body th { background: var(--bg-elev); font-weight: 600; }
.markdown-body img { max-width: 100%; border-radius: var(--radius); }
.task-item { list-style: none; margin-left: -1.3em; }
.task-item input { margin-right: 6px; }

/* Editor */
.edit-view {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}
.editor-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  padding: 10px 16px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
}
.editor-path { display: flex; align-items: center; gap: 8px; }
.dirty-dot { color: var(--accent); font-size: 14px; }
.editor-toolbar { display: flex; gap: 4px; flex-wrap: wrap; }
.tool-btn {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 4px 8px;
  font-size: 12.5px;
  cursor: pointer;
}
.tool-btn:hover { border-color: var(--accent); }
.editor-actions { display: flex; gap: 8px; }

.editor-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  flex: 1;
  min-height: 0;
}
.editor-textarea {
  width: 100%;
  height: 100%;
  resize: none;
  border: none;
  border-right: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 1.65;
  padding: 20px;
  outline: none;
}
.editor-preview-pane {
  overflow-y: auto;
  padding: 14px 24px 48px;
  background: var(--bg);
}
.preview-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 12px;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 50;
}
.modal-card {
  width: 100%;
  max-width: 420px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 22px;
  box-shadow: var(--shadow);
}
.modal-card h2 { margin: 0 0 14px; font-size: 18px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }

/* Toast */
.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--bg-elev);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 10px 16px;
  border-radius: 8px;
  box-shadow: var(--shadow);
  font-size: 13.5px;
  z-index: 60;
}

.mobile-only { display: none; }

@media (max-width: 860px) {
  .mobile-only { display: inline-flex; }
  .sidebar {
    position: fixed;
    top: 52px;
    bottom: 0;
    left: 0;
    z-index: 40;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop {
    position: fixed;
    inset: 52px 0 0 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 30;
  }
  .read-view { padding: 18px 18px 48px; }
  .editor-split { grid-template-columns: 1fr; }
  .editor-preview-pane { display: none; }
  .breadcrumbs { display: none; }
}

