/* ==================== RESET & BASE ==================== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  line-height: 1.6;
  color: #c9d1d9;
  background: #0d1117;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a {
  color: #58a6ff;
  text-decoration: none;
}

a:hover {
  color: #79c0ff;
  text-decoration: underline;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
  width: 100%;
}

/* ==================== HEADER ==================== */
.header {
  background: #161b22;
  color: #c9d1d9;
  padding: 0;
  box-shadow: 0 1px 0 rgba(255,255,255,0.04);
  position: sticky;
  top: 0;
  z-index: 100;
  border-bottom: 1px solid #30363d;
}

.header-inner {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 12px 20px;
  flex-wrap: wrap;
}

.logo {
  color: #f0f6fc;
  font-size: 1.4rem;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
}

.logo:hover {
  color: #58a6ff;
  text-decoration: none;
}

.search-form {
  display: flex;
  flex: 1;
  max-width: 400px;
}

.search-form input {
  flex: 1;
  padding: 8px 14px;
  border: 1px solid #30363d;
  border-radius: 6px 0 0 6px;
  font-size: 0.9rem;
  outline: none;
  background: #0d1117;
  color: #c9d1d9;
}

.search-form input::placeholder {
  color: #484f58;
}

.search-form input:focus {
  border-color: #58a6ff;
}

.search-form button {
  padding: 8px 16px;
  background: #238636;
  color: #fff;
  border: none;
  border-radius: 0 6px 6px 0;
  cursor: pointer;
  font-size: 0.9rem;
}

.search-form button:hover {
  background: #2ea043;
}

.header-nav {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
}

.user-name {
  color: #58a6ff;
  font-size: 0.9rem;
}

/* ==================== BUTTONS ==================== */
.btn {
  display: inline-block;
  padding: 7px 16px;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.2s;
  white-space: nowrap;
}

.btn:hover {
  text-decoration: none;
}

.btn-primary {
  background: #238636;
  color: #fff;
  border-color: #238636;
}

.btn-primary:hover {
  background: #2ea043;
  color: #fff;
}

.btn-secondary {
  background: #21262d;
  color: #c9d1d9;
  border-color: #30363d;
}

.btn-secondary:hover {
  background: #30363d;
  color: #f0f6fc;
}

.btn-outline {
  background: transparent;
  color: #c9d1d9;
  border: 1px solid #30363d;
}

.btn-outline:hover {
  background: #21262d;
  color: #f0f6fc;
}

.btn-danger {
  background: #da3633;
  color: #fff;
  border-color: #da3633;
}

.btn-danger:hover {
  background: #f85149;
  color: #fff;
}

.btn-sm {
  padding: 4px 10px;
  font-size: 0.8rem;
}

.btn-block {
  display: block;
  width: 100%;
  text-align: center;
}

/* ==================== LAYOUT ==================== */
.main-layout {
  display: flex;
  gap: 0;
  flex: 1;
}

.sidebar {
  width: 260px;
  flex-shrink: 0;
  background: #161b22;
  border-right: 1px solid #30363d;
  padding: 20px 0;
  min-height: calc(100vh - 53px);
}

.sidebar h3 {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #484f58;
  margin-bottom: 12px;
  padding: 0 16px;
}

.content {
  flex: 1;
  min-width: 0;
  background: #0d1117;
  padding: 30px 40px;
}

/* ==================== TREE NAV ==================== */
.tree-nav {
  list-style: none;
}

.tree-node {
  margin-bottom: 1px;
}

.tree-category {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 12px;
}

.tree-toggle {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: #484f58;
  font-size: 0.7rem;
  flex-shrink: 0;
  border-radius: 3px;
  transition: background 0.15s;
}

.tree-toggle:hover {
  background: #21262d;
  color: #c9d1d9;
}

.tree-toggle::before {
  content: "\25B6";
  display: block;
  transition: transform 0.15s;
}

.tree-toggle.no-children {
  visibility: hidden;
}

.tree-node.open > .tree-category .tree-toggle::before {
  transform: rotate(90deg);
}

.tree-link {
  display: block;
  flex: 1;
  padding: 6px 8px;
  border-radius: 6px;
  color: #c9d1d9;
  font-size: 0.9rem;
  font-weight: 600;
  transition: background 0.15s;
}

.tree-link:hover {
  background: #21262d;
  text-decoration: none;
  color: #f0f6fc;
}

.tree-children {
  list-style: none;
  display: none;
  padding-left: 24px;
}

.tree-node.open > .tree-children {
  display: block;
}

.tree-article {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 12px;
}

.tree-leaf {
  display: block;
  padding: 4px 8px;
  border-radius: 6px;
  color: #8b949e;
  font-size: 0.85rem;
  transition: all 0.15s;
  flex: 1;
}

.tree-leaf:hover {
  background: #21262d;
  text-decoration: none;
  color: #c9d1d9;
}

/* ==================== HOME ==================== */
h1 {
  font-size: 1.8rem;
  margin-bottom: 8px;
  color: #f0f6fc;
}

h2 {
  font-size: 1.3rem;
  margin-top: 30px;
  margin-bottom: 16px;
  color: #f0f6fc;
}

.subtitle {
  color: #8b949e;
  margin-bottom: 24px;
}

.categories-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 10px;
}

.category-card {
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 10px;
  padding: 18px;
  text-align: center;
  transition: all 0.2s;
  color: #c9d1d9;
}

.category-card:hover {
  border-color: #58a6ff;
  box-shadow: 0 0 12px rgba(88, 166, 255, 0.1);
  text-decoration: none;
  color: #58a6ff;
}

.category-card h3 {
  font-size: 1rem;
  margin: 0;
}

/* ==================== ARTICLE LIST ==================== */
.articles-list {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.article-item {
  padding: 14px 0;
  border-bottom: 1px solid #21262d;
}

.article-item:last-child {
  border-bottom: none;
}

.article-item-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.article-item-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.article-title {
  font-size: 1.05rem;
  font-weight: 600;
  color: #58a6ff;
}

.article-title:hover {
  color: #79c0ff;
}

.article-meta {
  display: flex;
  gap: 12px;
  margin-top: 4px;
  font-size: 0.85rem;
  color: #8b949e;
}

.tag {
  background: #1f2a38;
  color: #58a6ff;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.8rem;
}

.tag:hover {
  background: #253347;
  text-decoration: none;
}

/* ==================== ARTICLE VIEW ==================== */
.breadcrumb {
  font-size: 0.85rem;
  color: #8b949e;
  margin-bottom: 16px;
}

.breadcrumb a {
  color: #8b949e;
}

.breadcrumb a:hover {
  color: #58a6ff;
}

.article-title-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.article-date {
  font-size: 0.85rem;
  color: #484f58;
  white-space: nowrap;
}

.article-header {
  margin-bottom: 24px;
  padding-bottom: 20px;
  border-bottom: 1px solid #30363d;
}

.article-header h1 {
  margin-bottom: 4px;
}

.article-header .article-meta {
  margin-bottom: 12px;
}

.article-actions {
  display: flex;
  gap: 8px;
}

.inline-form {
  display: inline;
}

/* ==================== MARKDOWN BODY ==================== */
.markdown-body {
  line-height: 1.7;
  color: #c9d1d9;
}

.markdown-body h1 { font-size: 1.6rem; margin: 28px 0 12px; color: #f0f6fc; }
.markdown-body h2 { font-size: 1.35rem; margin: 24px 0 10px; border-bottom: 1px solid #30363d; padding-bottom: 6px; color: #f0f6fc; }
.markdown-body h3 { font-size: 1.15rem; margin: 20px 0 8px; color: #f0f6fc; }

.markdown-body p {
  margin-bottom: 14px;
}

.markdown-body ul, .markdown-body ol {
  margin-bottom: 14px;
  padding-left: 28px;
}

.markdown-body li {
  margin-bottom: 4px;
}

.markdown-body blockquote {
  border-left: 4px solid #58a6ff;
  padding: 10px 16px;
  margin: 14px 0;
  background: #161b22;
  color: #8b949e;
}

.markdown-body code {
  background: #1f2a38;
  color: #f0883e;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.9em;
  font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
}

.markdown-body pre {
  margin: 16px 0;
  border-radius: 8px;
  overflow-x: auto;
}

.markdown-body pre code {
  display: block;
  padding: 16px 20px;
  background: #161b22;
  color: #c9d1d9;
  font-size: 0.88rem;
  line-height: 1.6;
  border-radius: 8px;
  overflow-x: auto;
  border: 1px solid #30363d;
}

.markdown-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0;
}

.markdown-body th, .markdown-body td {
  border: 1px solid #30363d;
  padding: 8px 12px;
  text-align: left;
}

.markdown-body th {
  background: #161b22;
  font-weight: 600;
  color: #f0f6fc;
}

.markdown-body img {
  max-width: 100%;
  border-radius: 8px;
}

.markdown-body strong {
  color: #f0f6fc;
}

/* ==================== SUBPAGES ==================== */
.subpages {
  margin-top: 30px;
  padding-top: 20px;
  border-top: 1px solid #30363d;
}

.subpages-list {
  list-style: none;
  padding: 0;
}

.subpages-list li {
  padding: 6px 0;
}

.subpages-list a {
  color: #58a6ff;
  font-size: 0.95rem;
}

.subpages-list a:hover {
  color: #79c0ff;
}

/* ==================== highlight.js override ==================== */
.hljs {
  background: #161b22 !important;
  color: #c9d1d9 !important;
}

/* ==================== EDITOR ==================== */
.editor-form .form-group {
  margin-bottom: 18px;
}

.editor-form label {
  display: block;
  font-weight: 600;
  margin-bottom: 6px;
  color: #c9d1d9;
}

.editor-form input[type="text"],
.editor-form select {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid #30363d;
  border-radius: 8px;
  font-size: 1rem;
  outline: none;
  transition: border 0.2s;
  background: #0d1117;
  color: #c9d1d9;
}

.editor-form input[type="text"]:focus,
.editor-form select:focus {
  border-color: #58a6ff;
  box-shadow: 0 0 0 3px rgba(88, 166, 255, 0.1);
}

/* Fallback textarea если WYSIWYG не загрузился */
.editor-fallback {
  width: 100%;
  min-height: 500px;
  padding: 16px;
  border: 1px solid #30363d;
  border-radius: 8px;
  font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
  font-size: 0.9rem;
  line-height: 1.5;
  resize: vertical;
  outline: none;
  tab-size: 2;
  background: #0d1117;
  color: #c9d1d9;
}

.editor-fallback:focus {
  border-color: #58a6ff;
  box-shadow: 0 0 0 3px rgba(88, 166, 255, 0.1);
}

/* Toast UI Editor — подгонка под тёмную тему */
#editor {
  border: 1px solid #30363d;
  border-radius: 8px;
  overflow: hidden;
}

.toastui-editor-dark {
  border-color: #30363d;
}

.toastui-editor-dark .toastui-editor-toolbar {
  background: #161b22;
  border-bottom-color: #30363d;
}

.toastui-editor-dark .toastui-editor-ww-container,
.toastui-editor-dark .toastui-editor-md-container {
  background: #0d1117;
}

.toastui-editor-dark .toastui-editor-mode-switch {
  background: #161b22;
  border-top-color: #30363d;
}

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

/* ==================== LOGIN ==================== */
.login-wrapper {
  max-width: 360px;
  margin: 0 auto;
}

.login-form .form-group {
  margin-bottom: 16px;
}

.login-form label {
  display: block;
  font-weight: 600;
  margin-bottom: 6px;
  color: #c9d1d9;
}

.login-form input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid #30363d;
  border-radius: 8px;
  font-size: 1rem;
  outline: none;
  background: #0d1117;
  color: #c9d1d9;
}

.login-form input:focus {
  border-color: #58a6ff;
  box-shadow: 0 0 0 3px rgba(88, 166, 255, 0.1);
}

.login-form .btn {
  margin-top: 8px;
  padding: 12px;
  font-size: 1rem;
}

/* ==================== TABLE ==================== */
.table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 20px;
}

.table th, .table td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid #30363d;
}

.table th {
  background: #161b22;
  font-weight: 600;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: #8b949e;
}

.table td {
  color: #c9d1d9;
}

.table code {
  background: #1f2a38;
  color: #f0883e;
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 0.85em;
}

.inline-add-form {
  display: flex;
  gap: 10px;
  margin-bottom: 10px;
}

.inline-add-form input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid #30363d;
  border-radius: 8px;
  font-size: 1rem;
  outline: none;
  background: #0d1117;
  color: #c9d1d9;
}

.inline-add-form input:focus {
  border-color: #58a6ff;
}

/* ==================== ALERTS ==================== */
.alert {
  padding: 12px 16px;
  border-radius: 8px;
  margin-bottom: 18px;
  font-size: 0.95rem;
}

.alert-error {
  background: #3d1c1c;
  color: #f85149;
  border: 1px solid #5a2020;
}

/* ==================== EMPTY STATE ==================== */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: #8b949e;
}

.empty-state .btn {
  margin-top: 12px;
}

/* ==================== FOOTER ==================== */
.footer {
  background: #161b22;
  color: #484f58;
  padding: 16px 0;
  text-align: center;
  font-size: 0.85rem;
  margin-top: auto;
  border-top: 1px solid #30363d;
}

/* ==================== RESPONSIVE ==================== */
@media (max-width: 768px) {
  .header-inner {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .header-nav {
    margin-left: 0;
    flex-wrap: wrap;
  }

  .search-form {
    max-width: 100%;
  }

  .main-layout {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    min-height: auto;
    border-right: none;
    border-bottom: 1px solid #30363d;
    padding: 12px 0;
  }

  .content {
    padding: 20px;
  }

  .categories-grid {
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  }
}
