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

:root {
  --bg: #f8f9fa;
  --sidebar-bg: #ffffff;
  --header-bg: #1a1a2e;
  --header-text: #e0e0e0;
  --accent: #4a6fa5;
  --accent-hover: #3a5a8a;
  --text: #2d3436;
  --text-light: #636e72;
  --border: #e0e0e0;
  --code-bg: #f1f3f5;
  --sidebar-width: 280px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

/* === Header === */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--header-bg);
  color: var(--header-text);
  padding: 0 20px;
  height: 52px;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
}

.header-left { display: flex; align-items: center; gap: 12px; }
.header-center { flex: 1; max-width: 400px; margin: 0 20px; }
.header-right { display: flex; align-items: center; gap: 12px; }

.logo {
  color: #fff;
  text-decoration: none;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: 0.5px;
}

.sidebar-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--header-text);
  font-size: 22px;
  cursor: pointer;
  padding: 4px 8px;
}

.user-name { font-size: 13px; color: #b0b0b0; }

.btn-logout {
  color: #b0b0b0;
  text-decoration: none;
  font-size: 13px;
  padding: 4px 10px;
  border: 1px solid #444;
  border-radius: 4px;
  transition: all 0.2s;
}
.btn-logout:hover { color: #fff; border-color: #888; }

/* === Search === */
.search-box { position: relative; }

.search-box input {
  width: 100%;
  padding: 7px 14px;
  border: 1px solid #444;
  border-radius: 6px;
  background: #2a2a3e;
  color: #e0e0e0;
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
}
.search-box input::placeholder { color: #888; }
.search-box input:focus { border-color: var(--accent); }

.search-results {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-top: 4px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.15);
  max-height: 400px;
  overflow-y: auto;
  z-index: 200;
}

.search-item {
  display: block;
  padding: 10px 14px;
  text-decoration: none;
  color: var(--text);
  border-bottom: 1px solid #f0f0f0;
  transition: background 0.15s;
}
.search-item:hover { background: #f5f7ff; }
.search-item:last-child { border-bottom: none; }
.search-item-title { font-weight: 600; font-size: 14px; }
.search-item-snippet { font-size: 12px; color: var(--text-light); margin-top: 2px; }

/* === Layout === */
.container {
  display: flex;
  margin-top: 52px;
  min-height: calc(100vh - 52px);
}

.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  padding: 20px 0;
  overflow-y: auto;
  position: fixed;
  top: 52px;
  left: 0;
  bottom: 0;
  z-index: 50;
}

.content {
  flex: 1;
  margin-left: var(--sidebar-width);
  padding: 30px 40px;
  max-width: 900px;
}

/* === Navigation === */
.nav-list {
  list-style: none;
  padding: 0;
}

.nav-root > li { margin-bottom: 2px; }

.nav-folder-title {
  padding: 6px 16px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-light);
  cursor: pointer;
  user-select: none;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  transition: color 0.2s;
}
.nav-folder-title:hover { color: var(--text); }

.folder-icon {
  display: inline-block;
  width: 14px;
  font-size: 11px;
}

.nav-folder > .nav-list { display: none; }
.nav-folder.open > .nav-list { display: block; }

.nav-page a {
  display: block;
  padding: 5px 16px 5px 32px;
  text-decoration: none;
  color: var(--text);
  font-size: 14px;
  border-left: 3px solid transparent;
  transition: all 0.15s;
}
.nav-page a:hover {
  background: #f0f2ff;
  color: var(--accent);
}
.nav-page.active a {
  color: var(--accent);
  border-left-color: var(--accent);
  background: #f0f2ff;
  font-weight: 500;
}

/* Nested folder indentation */
.nav-list .nav-list .nav-page a { padding-left: 48px; }
.nav-list .nav-list .nav-list .nav-page a { padding-left: 64px; }

/* === Breadcrumbs === */
.breadcrumbs {
  font-size: 13px;
  color: var(--text-light);
  margin-bottom: 20px;
}
.breadcrumbs a {
  color: var(--accent);
  text-decoration: none;
}
.breadcrumbs a:hover { text-decoration: underline; }

/* === Article content === */
.article h1 { font-size: 28px; margin-bottom: 16px; color: var(--text); border-bottom: 2px solid var(--border); padding-bottom: 8px; }
.article h2 { font-size: 22px; margin: 28px 0 12px; color: var(--text); }
.article h3 { font-size: 18px; margin: 24px 0 8px; }
.article h4 { font-size: 16px; margin: 20px 0 8px; }

.article p { margin-bottom: 12px; }

.article ul, .article ol { margin: 0 0 16px 24px; }
.article li { margin-bottom: 4px; }

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

.article code {
  background: var(--code-bg);
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 0.9em;
  font-family: 'JetBrains Mono', 'Fira Code', Consolas, monospace;
}

.article pre {
  background: #1e1e2e;
  color: #cdd6f4;
  padding: 16px 20px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 16px 0;
  line-height: 1.5;
}
.article pre code {
  background: none;
  padding: 0;
  color: inherit;
}

.article table {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0;
}
.article th, .article td {
  border: 1px solid var(--border);
  padding: 8px 12px;
  text-align: left;
}
.article th { background: var(--code-bg); font-weight: 600; }
.article tr:hover { background: #fafafa; }

.article blockquote {
  border-left: 4px solid var(--accent);
  padding: 8px 16px;
  margin: 16px 0;
  background: #f0f2ff;
  color: var(--text);
}

.article img {
  max-width: 100%;
  border-radius: 6px;
  margin: 12px 0;
}

.article hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 24px 0;
}

/* === Login page === */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #1a1a2e 0%, #2a2a4e 100%);
}

.login-card {
  background: #fff;
  padding: 40px;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
  width: 100%;
  max-width: 380px;
  text-align: center;
}

.login-card h1 {
  color: var(--header-bg);
  margin-bottom: 4px;
  font-size: 24px;
}

.login-subtitle {
  color: var(--text-light);
  margin-bottom: 24px;
  font-size: 14px;
}

.form-group {
  margin-bottom: 16px;
  text-align: left;
}

.form-group label {
  display: block;
  margin-bottom: 4px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-light);
}

.form-group input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 15px;
  outline: none;
  transition: border-color 0.2s;
}
.form-group input:focus { border-color: var(--accent); }

.btn-login {
  width: 100%;
  padding: 10px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s;
  margin-top: 8px;
}
.btn-login:hover { background: var(--accent-hover); }

.error {
  color: #e74c3c;
  font-size: 14px;
  margin-bottom: 12px;
}

/* === Admin buttons in sidebar === */
.admin-buttons {
  display: flex;
  gap: 8px;
  padding: 8px 16px 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
}

.btn-admin {
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 500;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  text-decoration: none;
  background: var(--accent);
  color: #fff;
  transition: background 0.2s;
}
.btn-admin:hover { background: var(--accent-hover); }
.btn-admin-secondary {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
}
.btn-admin-secondary:hover {
  background: var(--accent);
  color: #fff;
}

/* === Edit button on page === */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}

.btn-edit {
  padding: 5px 14px;
  font-size: 13px;
  color: var(--accent);
  text-decoration: none;
  border: 1px solid var(--accent);
  border-radius: 4px;
  transition: all 0.2s;
  white-space: nowrap;
}
.btn-edit:hover {
  background: var(--accent);
  color: #fff;
}

/* === Editor === */
.editor-container { max-width: 100%; }
.editor-form .form-group { margin-bottom: 12px; }
.editor-form label { display: block; margin-bottom: 4px; font-size: 13px; font-weight: 500; color: var(--text-light); }
.editor-form input[type="text"],
.editor-form input[type="number"],
.editor-form select {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
}
.editor-form input[type="text"]:focus,
.editor-form select:focus { border-color: var(--accent); }
.editor-form input[type="text"] { width: 100%; }
.editor-form select { width: 100%; }

.editor-top { margin-bottom: 16px; }
.editor-meta { display: flex; gap: 16px; margin-top: 8px; }
.editor-meta .form-group { flex: 1; }
.editor-meta .form-group:last-child { flex: 0 0 100px; }

.editor-tabs {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--border);
  margin-bottom: 0;
}

.editor-tab {
  padding: 8px 20px;
  background: none;
  border: none;
  font-size: 14px;
  cursor: pointer;
  color: var(--text-light);
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all 0.2s;
}
.editor-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}
.editor-tab:hover { color: var(--text); }

#editor-textarea {
  width: 100%;
  min-height: 450px;
  padding: 16px;
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 6px 6px;
  font-family: 'JetBrains Mono', 'Fira Code', Consolas, monospace;
  font-size: 14px;
  line-height: 1.6;
  resize: vertical;
  outline: none;
  tab-size: 2;
}
#editor-textarea:focus { border-color: var(--accent); }

#editor-preview {
  padding: 20px;
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 6px 6px;
  min-height: 450px;
  background: #fff;
}

.editor-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 16px;
}

.btn-save {
  padding: 8px 24px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s;
}
.btn-save:hover { background: var(--accent-hover); }

.btn-cancel {
  color: var(--text-light);
  text-decoration: none;
  font-size: 14px;
}
.btn-cancel:hover { color: var(--text); }

.btn-delete {
  margin-left: auto;
  padding: 8px 16px;
  background: none;
  color: #e74c3c;
  border: 1px solid #e74c3c;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-delete:hover { background: #e74c3c; color: #fff; }

/* === Modal === */
.modal {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
}

.modal-content {
  background: #fff;
  padding: 28px;
  border-radius: 10px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}
.modal-content h3 { margin-bottom: 16px; }
.modal-content .form-group { margin-bottom: 12px; }
.modal-content label { display: block; margin-bottom: 4px; font-size: 13px; font-weight: 500; color: var(--text-light); }
.modal-content input,
.modal-content select {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  outline: none;
}
.modal-content input:focus,
.modal-content select:focus { border-color: var(--accent); }

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}

/* === Mobile === */
@media (max-width: 768px) {
  .sidebar-toggle { display: block; }

  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.25s ease;
  }

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

  .content {
    margin-left: 0;
    padding: 20px 16px;
  }

  .header-center { max-width: 200px; }
}
