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

:root {
  --bg: #1e1e2e;
  --surface: #2a2a3e;
  --surface2: #33334d;
  --border: #3e3e5e;
  --text: #e0e0f0;
  --text-muted: #8888aa;
  --primary: #3b82f6;
  --danger: #ef4444;
  --radius: 8px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
header h1 {
  font-size: 1.2rem;
  white-space: nowrap;
}
#search-area {
  position: relative;
  flex: 1;
  max-width: 400px;
}
#search-input {
  width: 100%;
  padding: 6px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font-size: 0.85rem;
  outline: none;
}
#search-input:focus {
  border-color: var(--primary);
}
#search-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0 0 var(--radius) var(--radius);
  max-height: 300px;
  overflow-y: auto;
  z-index: 10;
}
#search-results.hidden {
  display: none;
}
.search-result-item {
  padding: 8px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}
.search-result-item:last-child {
  border-bottom: none;
}
.search-result-item:hover {
  background: var(--surface2);
}
.search-result-item .snippet {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 2px;
}

button {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.85rem;
}
button:hover {
  background: var(--primary);
  border-color: var(--primary);
}
button.primary {
  background: var(--primary);
  border-color: var(--primary);
}
button.danger {
  color: var(--danger);
}
button.danger:hover {
  background: var(--danger);
  color: #fff;
}

#content {
  display: flex;
  flex: 1;
  overflow: hidden;
}

#sidebar {
  width: 220px;
  min-width: 220px;
  overflow-y: auto;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 8px 0;
}
.category-group {
  margin-bottom: 4px;
}
.category-header {
  padding: 6px 14px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.05em;
}
.page-link {
  display: block;
  padding: 5px 14px 5px 24px;
  font-size: 0.85rem;
  cursor: pointer;
  color: var(--text);
  text-decoration: none;
  border-left: 2px solid transparent;
}
.page-link:hover {
  background: var(--surface2);
}
.page-link.active {
  border-left-color: var(--primary);
  background: var(--surface2);
}
.index-link {
  font-weight: 600;
  border-left-color: transparent;
  margin-bottom: 6px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
}

.wiki-link {
  color: var(--primary);
  text-decoration: underline;
  cursor: pointer;
}
.wiki-link:hover {
  opacity: 0.8;
}
.wiki-link-broken {
  color: var(--danger);
  text-decoration: underline dotted;
  cursor: default;
}

#page-area {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

#page-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
}

#page-view-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}
#page-title-display {
  font-size: 1.5rem;
  font-weight: 700;
}
#page-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 16px;
}
#page-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.hidden { display: none !important; }

#page-view .markdown-body {
  max-width: 80ch;
}

.markdown-body p { margin-bottom: 8px; line-height: 1.6; }
.markdown-body h1, .markdown-body h2, .markdown-body h3 { margin: 16px 0 8px; }
.markdown-body h1 { font-size: 1.4rem; }
.markdown-body h2 { font-size: 1.2rem; }
.markdown-body ul, .markdown-body ol { padding-left: 24px; margin-bottom: 8px; }
.markdown-body code {
  background: var(--surface2);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 0.85rem;
}
.markdown-body pre {
  background: var(--surface2);
  padding: 12px;
  border-radius: var(--radius);
  overflow-x: auto;
  margin-bottom: 12px;
}
.markdown-body blockquote {
  border-left: 3px solid var(--primary);
  padding-left: 12px;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.markdown-body a { color: var(--primary); }

#editor-title {
  width: 100%;
  font-size: 1.3rem;
  font-weight: 600;
  padding: 8px 12px;
  margin-bottom: 10px;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  outline: none;
}
#editor-title:focus {
  border-color: var(--primary);
}
.editor-meta {
  display: flex;
  gap: 10px;
  margin-bottom: 10px;
}
.editor-meta input {
  flex: 1;
  padding: 6px 10px;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  font-size: 0.85rem;
  outline: none;
}
.editor-meta input:focus {
  border-color: var(--primary);
}
.editor-body-area {
  display: flex;
  gap: 10px;
  margin-bottom: 12px;
}
.editor-body-area textarea {
  flex: 1;
  height: 50vh;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px;
  border-radius: var(--radius);
  font-family: monospace;
  font-size: 0.85rem;
  resize: vertical;
  outline: none;
}
.editor-body-area textarea:focus {
  border-color: var(--primary);
}
.editor-body-area .markdown-body {
  flex: 1;
  height: 50vh;
  overflow-y: auto;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
}
.editor-actions {
  display: flex;
  gap: 8px;
}

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

@media (max-width: 768px) {
  #sidebar { display: none; }
  #content { flex-direction: column; }
  .editor-body-area { flex-direction: column; }
  .editor-body-area textarea,
  .editor-body-area .markdown-body { height: 40vh; }
  .editor-meta { flex-direction: column; gap: 6px; }
}
