/*
 * Оформление портала Itemika — фирменный стиль itemika.ru.
 * Цвета и логотип взяты с корпоративного сайта: тёплый «бумажный» фон,
 * терракота, горчичный, шалфейный, песочный; заголовки — RF Dewi / TildaSans.
 */

/* ---------- шрифты ---------- */

@font-face {
  font-family: 'TildaSans';
  font-style: normal;
  font-weight: 250 1000;
  font-display: swap;
  src: url('/assets/TildaSans-VF.woff2') format('woff2-variations');
}

/* ---------- переменные ---------- */

:root,
:root[data-theme='dark'] {
  color-scheme: light;
  --paper: #fefaf1;
  --paper-2: #f7f2e6;
  --paper-3: #f3efe3;
  --ink: #141414;
  --ink-soft: #2b2b2b;
  --muted: #79715e;
  --muted-2: #939598;
  --line: #e6dcc6;
  --line-soft: #eee6d4;
  --terra: #c36249;
  --terra-dark: #a84f39;
  --mustard: #c09530;
  --olive: #eeedda;
  --sand: #c7bda5;
  --sage: #91b3bd;
  --success: #3f7d4f;
  --danger: #b0422f;
  --accent-soft: rgba(195, 98, 73, 0.1);

  --bg: var(--paper);
  --bg-sidebar: var(--paper-2);
  --bg-elevated: #fffdf8;
  --bg-hover: #f4eddd;
  --bg-active: #f1e7d2;
  --border: var(--line);
  --border-strong: #d9cdb3;
  --text-normal: #2b2b2b;
  --text-muted: #79715e;
  --text-faint: #9a917d;
  --heading: #141414;
  --link: #b0553e;
  --link-hover: #8f412f;
  --accent: #c36249;
  --danger-c: var(--danger);
  --ok: var(--success);
  --shadow: 0 12px 34px rgba(60, 40, 10, 0.12);
  --callout-note: #79715e;
  --callout-info: #6f8fa0;
  --callout-tip: #4f7d5a;
  --callout-warning: #b3862a;
  --callout-danger: #b0422f;
  --callout-example: #9a7b3f;
  --radius: 8px;
  --radius-lg: 14px;
  --sidebar-width: 300px;
  --font-body: 'TildaSans', 'RFDewi', 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
  --font-display: 'RFDewi', 'TildaSans', 'Segoe UI', Arial, sans-serif;
  --font-mono: 'Cascadia Mono', 'Consolas', 'JetBrains Mono', monospace;
  --topbar-h: 64px;
}

:root[data-theme='light'] {
  color-scheme: light;
  --paper: #ffffff;
  --paper-2: #fcfaf5;
  --paper-3: #f6f3ea;
  --bg-sidebar: #fcfaf5;
  --bg-elevated: #ffffff;
  --bg-hover: #f6f1e6;
  --line: #e9e1d0;
}

/* ---------- база ---------- */

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

html {
  scroll-behavior: smooth;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  background:
    radial-gradient(1200px 500px at 110% -10%, rgba(227, 207, 164, 0.35), transparent 60%),
    radial-gradient(900px 420px at -10% 0%, rgba(214, 155, 168, 0.16), transparent 55%),
    var(--bg);
  color: var(--text-normal);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--link);
  text-decoration: none;
  transition: color 0.15s ease;
}

a:hover {
  color: var(--link-hover);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.inline-form {
  display: inline;
  margin: 0;
}

.muted {
  color: var(--text-muted);
}

.small {
  font-size: 0.85em;
}

/* ---------- кнопки ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1.5px solid var(--ink);
  background: transparent;
  color: var(--ink);
  border-radius: 10px;
  padding: 7px 15px;
  font: inherit;
  font-size: 0.92em;
  font-weight: 550;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s, transform 0.1s;
  text-decoration: none;
  white-space: nowrap;
}

.btn:hover {
  background: var(--ink);
  color: #fff;
  text-decoration: none;
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  background: var(--terra);
  border-color: var(--terra);
  color: #fff;
}

.btn-primary:hover {
  background: var(--terra-dark);
  border-color: var(--terra-dark);
  color: #fff;
}

.btn-ghost {
  border-color: transparent;
  color: var(--text-muted);
}

.btn-ghost:hover {
  border-color: var(--line);
  background: var(--bg-hover);
  color: var(--ink);
}

.btn.danger,
.btn-ghost.danger:hover {
  color: var(--danger);
}

.btn.danger:hover {
  border-color: var(--danger);
  background: var(--danger);
  color: #fff;
}

.btn-full {
  width: 100%;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  color: var(--text-muted);
  transition: background 0.15s, color 0.15s;
}

.icon-btn:hover {
  background: var(--bg-hover);
  color: var(--ink);
  text-decoration: none;
}

.link-btn {
  border: none;
  background: none;
  padding: 0;
  font: inherit;
  color: var(--link);
  cursor: pointer;
  text-align: left;
}

.link-btn:hover {
  color: var(--link-hover);
  text-decoration: underline;
}

/* ---------- верхняя панель ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 14px;
  height: var(--topbar-h);
  padding: 0 22px;
  background: rgba(254, 250, 241, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

:root[data-theme='light'] .topbar {
  background: rgba(255, 255, 255, 0.94);
}

.brand {
  display: inline-flex;
  align-items: center;
  text-decoration: none !important;
  flex-shrink: 0;
}

.logo-img {
  height: 34px;
  width: auto;
  display: block;
}

/* запасной логотип из букв RF Dewi, если картинка не задана */
.logo {
  display: inline-flex;
  align-items: center;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 24px;
  letter-spacing: 0.02em;
  color: var(--ink);
}

.logo-chunks {
  display: inline-flex;
  align-items: center;
  gap: 1px;
}

.logo-chunk {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 34px;
  min-width: 24px;
  padding: 0 3px;
  background: var(--bg, #e9e0cc);
  color: var(--ink);
  border: 2px solid var(--ink);
  border-radius: 3px;
  font-size: 20px;
  line-height: 1;
}

.logo-chunk + .logo-chunk {
  margin-left: -3px;
}

.brand-divider {
  width: 1px;
  height: 24px;
  background: var(--line);
  margin: 0 4px;
}

.brand-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 16px;
  color: var(--muted);
  white-space: nowrap;
}

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

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

.top-search input,
.tree-search input {
  font: inherit;
  font-size: 0.9em;
  color: var(--text-normal);
  background: var(--bg-elevated);
  border: 1.5px solid var(--line);
  border-radius: 10px;
  padding: 7px 12px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.top-search input:focus,
.tree-search input:focus {
  border-color: var(--terra);
  box-shadow: 0 0 0 3px rgba(195, 98, 73, 0.12);
}

.top-search .search-icon {
  position: absolute;
  left: 10px;
  color: var(--text-faint);
  display: inline-flex;
  pointer-events: none;
}

.top-search input {
  width: 300px;
  padding-left: 34px;
}

/* меню пользователя */
.user-menu {
  display: flex;
  align-items: center;
  gap: 4px;
}

.user-drop {
  position: relative;
}

.user-drop > summary {
  list-style: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 10px 5px 6px;
  border-radius: 10px;
  cursor: pointer;
  color: var(--ink);
  font-size: 0.92em;
  transition: background 0.15s;
}

.user-drop > summary::-webkit-details-marker {
  display: none;
}

.user-drop > summary:hover {
  background: var(--bg-hover);
}

.user-drop[open] > summary {
  background: var(--bg-hover);
}

.user-name {
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-drop-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  min-width: 230px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  z-index: 40;
}

.user-drop-panel a,
.user-drop-panel .link-btn {
  display: block;
  padding: 7px 10px;
  border-radius: 8px;
  color: var(--text-normal);
  font-size: 0.92em;
}

.user-drop-panel a:hover,
.user-drop-panel .link-btn:hover {
  background: var(--bg-hover);
  text-decoration: none;
  color: var(--ink);
}

.drop-head {
  padding: 4px 10px 10px;
  margin-bottom: 4px;
  border-bottom: 1px solid var(--line-soft);
  font-weight: 600;
  color: var(--ink);
}

.nav-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  width: 36px;
  height: 36px;
  padding: 0 8px;
  background: none;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
}

.nav-toggle span {
  display: block;
  height: 2px;
  background: var(--ink);
  border-radius: 2px;
}

/* ---------- раскладка ---------- */

.app {
  display: flex;
  min-height: calc(100vh - var(--topbar-h));
}

.sidebar {
  position: sticky;
  top: var(--topbar-h);
  flex: 0 0 var(--sidebar-width);
  width: var(--sidebar-width);
  height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
  padding: 16px 14px 28px;
  border-right: 1px solid var(--line);
  background: var(--bg-sidebar);
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

.sidebar::-webkit-scrollbar {
  width: 8px;
}

.sidebar::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 4px;
}

.sidebar-tools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 2px 12px;
}

/* переключатель темы: тёплый, в стиле сайта */
.theme-toggle {
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
}

.theme-toggle-track {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 22px;
  border-radius: 11px;
  background: var(--olive);
  border: 1.5px solid var(--border-strong);
  transition: background 0.15s;
}

.theme-toggle-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--terra);
  transition: left 0.16s ease;
}

:root[data-theme='light'] .theme-toggle-thumb {
  left: 20px;
  background: var(--mustard);
}

.tree-search {
  position: relative;
  display: flex;
  align-items: center;
  margin: 0 0 12px;
  cursor: text;
}

.tree-search > svg {
  position: absolute;
  left: 10px;
  color: var(--text-faint);
  pointer-events: none;
}

.tree-search input {
  width: 100%;
  height: 36px;
  padding-left: 34px;
  font-size: 0.88em;
  background: var(--bg-elevated);
}

.sidebar-foot {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: 18px 0 0;
  padding-top: 14px;
  border-top: 1px solid var(--line-soft);
  font-size: 0.88em;
}

.sidebar-foot a {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 8px;
  color: var(--text-muted);
}

.sidebar-foot a:hover {
  background: var(--bg-hover);
  color: var(--ink);
  text-decoration: none;
}

.sidebar-backdrop {
  display: none;
}

/* ---------- дерево ---------- */

.tree {
  font-size: 13.5px;
  line-height: 1.45;
}

.tree ul {
  margin: 0;
  padding: 0;
  list-style: none;
}

.tree-li {
  margin: 1px 0;
}

.tree-row {
  display: flex;
  align-items: center;
  border-radius: 8px;
  padding-right: 2px;
}

.tree-row:hover {
  background: var(--bg-hover);
}

.tree-caret {
  flex: 0 0 20px;
  width: 20px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  padding: 0;
  color: var(--text-faint);
  cursor: pointer;
  transition: transform 0.14s ease;
}

.tree-li.open > .tree-row .tree-caret {
  transform: rotate(90deg);
}

.tree-caret svg {
  display: block;
}

.tree-link {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: 1;
  min-width: 0;
  padding: 4px 6px;
  color: var(--text-normal);
  border-radius: 8px;
}

.tree-link:hover {
  color: var(--ink);
  text-decoration: none;
}

.tree-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}

.tree-li.note > .tree-link {
  padding-left: 22px;
  color: var(--text-muted);
}

.tree-li.note > .tree-link:hover,
.tree-li.note > .tree-link.active {
  color: var(--ink);
  background: var(--bg-hover);
}

.tree-li.note > .tree-link.active {
  background: var(--accent-soft);
  color: var(--link);
  font-weight: 600;
  box-shadow: inset 3px 0 0 var(--terra);
}

.tree-li.folder > .tree-row .folder-link {
  font-weight: 600;
  color: var(--ink-soft);
}

.tree-li.open > .tree-row .folder-link {
  color: var(--ink);
}

.tree .pin {
  color: var(--mustard);
  margin-right: 4px;
  display: inline-flex;
}

.tree .lock {
  color: var(--text-faint);
  display: inline-flex;
  margin-left: 6px;
  opacity: 0.8;
}

.tree-children {
  margin-left: 10px !important;
  border-left: 1px solid var(--line-soft);
  padding-left: 4px !important;
}

.tree-root {
  margin-bottom: 2px !important;
}

/* ---------- контент ---------- */

.content {
  flex: 1 1 auto;
  min-width: 0;
  padding: 30px 34px 90px;
}

.content-inner {
  max-width: 900px;
  margin: 0 auto;
}

.page-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
  min-height: 30px;
  flex-wrap: wrap;
}

.crumbs {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px;
  font-size: 0.88em;
  color: var(--text-muted);
  min-width: 0;
}

.crumb-sep {
  margin: 0 5px;
  color: var(--text-faint);
}

.crumb.last {
  color: var(--text-muted);
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.page-actions {
  display: flex;
  gap: 8px;
  margin-left: auto;
  flex-wrap: wrap;
  align-items: center;
}

.note-title {
  font-family: var(--font-display);
  font-size: 2.1em;
  line-height: 1.18;
  color: var(--heading);
  margin: 0 0 10px;
  font-weight: 750;
  letter-spacing: -0.01em;
  word-wrap: break-word;
}

.note-header {
  margin-bottom: 28px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.note-meta {
  color: var(--text-faint);
  font-size: 0.85em;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.note-meta .dot {
  color: var(--line-soft);
}

.vis-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  padding: 1px 10px;
  font-size: 0.98em;
  font-weight: 550;
}

.vis-badge.public {
  color: var(--success);
  border-color: rgba(63, 125, 79, 0.35);
  background: rgba(63, 125, 79, 0.07);
}

.vis-badge.private {
  color: var(--mustard);
  border-color: rgba(179, 134, 42, 0.35);
  background: rgba(179, 134, 42, 0.08);
}

.notice {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  background: var(--accent-soft);
  border: 1px solid rgba(195, 98, 73, 0.3);
  border-radius: var(--radius-lg);
  padding: 12px 16px;
  margin-bottom: 20px;
  font-size: 0.92em;
}

.notice-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-left: auto;
}

.section-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.76em;
  letter-spacing: 0.16em;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  margin: 42px 0 14px;
}

.section-label::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--line);
}

.section-label .count {
  letter-spacing: 0;
  font-weight: 600;
  color: var(--text-faint);
}

.empty-note {
  color: var(--text-faint);
  font-style: italic;
}

/* ---------- markdown ---------- */

.markdown-body {
  font-size: 16.5px;
  line-height: 1.68;
  color: var(--text-normal);
  word-wrap: break-word;
}

.markdown-body > *:first-child {
  margin-top: 0;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4,
.markdown-body h5,
.markdown-body h6 {
  font-family: var(--font-display);
  color: var(--heading);
  font-weight: 720;
  line-height: 1.28;
  margin: 1.7em 0 0.6em;
  position: relative;
  scroll-margin-top: calc(var(--topbar-h) + 12px);
  letter-spacing: -0.005em;
}

.markdown-body h1 {
  font-size: 1.7em;
  padding-bottom: 0.3em;
  border-bottom: 1px solid var(--line);
}

.markdown-body h2 {
  font-size: 1.4em;
}

.markdown-body h3 {
  font-size: 1.18em;
}

.markdown-body h4 {
  font-size: 1.05em;
}

.markdown-body h1::before,
.markdown-body h2::before {
  content: '';
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-right: 10px;
  border-radius: 2px;
  background: var(--terra);
  transform: translateY(-2px) rotate(-6deg);
}

.markdown-body h3::before {
  content: '';
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 9px;
  background: var(--mustard);
  transform: translateY(-2px);
}

.heading-anchor {
  margin-left: 8px;
  opacity: 0;
  color: var(--text-faint) !important;
  transition: opacity 0.15s;
  font-weight: 400;
  text-decoration: none !important;
}

.heading:hover .heading-anchor {
  opacity: 1;
}

.markdown-body p {
  margin: 0.75em 0;
}

.markdown-body .internal-link {
  color: var(--link);
  background: linear-gradient(to top, rgba(195, 98, 73, 0.16) 0 38%, transparent 38%);
  padding: 0 1px;
  border-radius: 2px;
}

.markdown-body .internal-link:hover {
  color: var(--link-hover);
  background: linear-gradient(to top, rgba(195, 98, 73, 0.28) 0 45%, transparent 45%);
  text-decoration: none;
}

.unresolved-link {
  color: var(--text-muted);
  border-bottom: 1px dashed var(--text-faint);
  cursor: help;
}

.embed-inline {
  color: var(--text-muted);
  border-bottom: 1px dotted var(--text-faint);
  cursor: help;
}

.markdown-body ul,
.markdown-body ol {
  margin: 0.65em 0;
  padding-left: 1.55em;
}

.markdown-body li {
  margin: 0.28em 0;
}

.markdown-body li::marker {
  color: var(--terra);
}

.markdown-body li > p {
  margin: 0.2em 0;
}

.markdown-body li.task-item {
  list-style: none;
  margin-left: -1.35em;
}

.task-item label {
  display: inline-flex;
  align-items: flex-start;
  gap: 8px;
  cursor: default;
}

.task-item input {
  margin-top: 5px;
  accent-color: var(--terra);
}

.task-done {
  color: var(--text-muted);
  text-decoration: line-through;
}

.markdown-body blockquote {
  margin: 1em 0;
  padding: 0.25em 0 0.25em 1.1em;
  border-left: 3px solid var(--sand);
  color: var(--text-muted);
  font-style: italic;
}

.markdown-body hr {
  border: none;
  height: 1px;
  background: var(--line);
  margin: 2em 0;
}

.markdown-body mark {
  background: #f3e3b4;
  color: inherit;
  padding: 0 3px;
  border-radius: 3px;
}

.spoiler {
  background: var(--ink-soft);
  color: transparent;
  border-radius: 3px;
  cursor: pointer;
}

.spoiler:hover {
  color: var(--olive);
}

.markdown-body code {
  font-family: var(--font-mono);
  font-size: 0.87em;
  background: var(--paper-3);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 1px 6px;
  color: #8f412f;
}

.markdown-body pre.code-block {
  background: #1d1c19;
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  overflow-x: auto;
  margin: 1.1em 0;
}

.markdown-body pre code {
  background: none;
  border: none;
  padding: 0;
  color: #f1ebdd;
  font-size: 0.88em;
}

.markdown-body img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius);
}

.markdown-body .embedded-image {
  display: inline-block;
  margin: 5px 0;
  border: 1px solid var(--line);
  box-shadow: 0 2px 10px rgba(60, 40, 10, 0.06);
}

.markdown-body .attachment {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.markdown-body .attachment::before {
  content: '📎';
}

.markdown-body .table-wrap,
.table-wrap {
  overflow-x: auto;
  margin: 1.1em 0;
  max-width: 100%;
  border-radius: var(--radius);
}

.markdown-body table,
.table-wrap table {
  border-collapse: collapse;
  width: auto;
  max-width: 100%;
  font-size: 0.94em;
}

.markdown-body th,
.markdown-body td,
.table-wrap th,
.table-wrap td {
  border: 1px solid var(--line);
  padding: 7px 11px;
  vertical-align: top;
}

.markdown-body thead th,
.table-wrap thead th {
  background: var(--olive);
  color: var(--ink);
  font-weight: 650;
  border-color: #ddd8bd;
}

.markdown-body tbody tr:nth-child(even) td {
  background: rgba(243, 239, 227, 0.45);
}

.html-block {
  margin: 1.1em 0;
}

.html-block > *:first-child {
  margin-top: 0;
}

/* ---------- callouts (спокойный стиль сайта) ---------- */

.callout {
  border-radius: var(--radius-lg);
  padding: 12px 16px;
  margin: 1.2em 0;
  border: 1px solid var(--line);
  border-left: 4px solid var(--callout-note);
  background: var(--bg-elevated);
}

.callout-title {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 650;
  color: var(--callout-note);
  margin-bottom: 3px;
}

.callout-icon {
  width: 15px;
  height: 15px;
  flex: 0 0 15px;
  border-radius: 3px;
  background: var(--callout-note);
  transform: rotate(-8deg);
}

.callout-content > *:first-child {
  margin-top: 0.25em;
}

.callout-content > *:last-child {
  margin-bottom: 0;
}

.callout.note {
  background: #fbf8ee;
  border-left-color: #b9a88a;
}

.callout.note .callout-title,
.callout.note .callout-icon {
  color: #8a7a5c;
  background-color: transparent;
}

.callout.note .callout-icon {
  background: #b9a88a;
}

.callout.info {
  background: #f1f6f7;
  border-left-color: var(--callout-info);
}

.callout.info .callout-title {
  color: #4f7286;
}

.callout.info .callout-icon {
  background: var(--callout-info);
}

.callout.tip,
.callout.success {
  background: #f2f7f1;
  border-left-color: var(--callout-tip);
}

.callout.tip .callout-title,
.callout.success .callout-title {
  color: #3f6b48;
}

.callout.tip .callout-icon,
.callout.success .callout-icon {
  background: var(--callout-tip);
}

.callout.warning,
.callout.caution {
  background: #fbf5e4;
  border-left-color: var(--callout-warning);
}

.callout.warning .callout-title,
.callout.caution .callout-title {
  color: #8d6617;
}

.callout.warning .callout-icon,
.callout.caution .callout-icon {
  background: var(--callout-warning);
}

.callout.danger,
.callout.failure {
  background: #fbeeea;
  border-left-color: var(--callout-danger);
}

.callout.danger .callout-title,
.callout.failure .callout-title {
  color: #8f3223;
}

.callout.danger .callout-icon,
.callout.failure .callout-icon {
  background: var(--callout-danger);
}

.callout.example {
  background: #f8f3ea;
  border-left-color: var(--callout-example);
}

.callout.example .callout-title {
  color: #7a5e2b;
}

.callout.example .callout-icon {
  background: var(--callout-example);
}

.callout.important,
.callout.todo,
.callout.abstract,
.callout.question {
  background: #faf6ea;
}

details.callout {
  display: block;
}

details.callout > summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 650;
  color: var(--callout-note);
}

details.callout > summary::-webkit-details-marker {
  display: none;
}

details.callout > summary::before {
  content: '▸';
  color: var(--text-muted);
}

details.callout[open] > summary::before {
  content: '▾';
}

/* ---------- оглавление, ссылки, граф ---------- */

.toc {
  margin-top: 46px;
  padding: 18px 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--bg-elevated);
  font-size: 0.93em;
}

.toc summary {
  cursor: pointer;
  font-size: 0.8em;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 700;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
}

.toc summary::-webkit-details-marker {
  display: none;
}

.toc summary::before {
  content: '▸';
  transition: transform 0.15s;
}

.toc[open] summary::before {
  transform: rotate(90deg);
}

.toc ul {
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
}

.toc li.lvl3 {
  padding-left: 18px;
}

.toc a {
  color: var(--text-muted);
  display: inline-block;
  padding: 2px 0;
}

.toc a:hover {
  color: var(--ink);
  text-decoration: none;
}

.backlinks {
  margin-top: 40px;
}

.backlink-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.backlink-list li {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg-elevated);
  font-size: 0.92em;
}

.backlink-list li:hover {
  border-color: var(--terra);
}

.star {
  display: inline-flex;
  color: var(--mustard);
  font-size: 0.85em;
}

.local-graph {
  margin-top: 8px;
}

.mini-graph {
  position: relative;
  width: 100%;
  height: 180px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--bg-elevated);
  overflow: hidden;
}

.graph-full {
  position: relative;
  width: 100%;
  min-height: 460px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--bg-elevated);
  overflow: hidden;
}

.graph-canvas {
  display: block;
  touch-action: none;
}

/* ---------- главная ---------- */

.home {
  max-width: 1000px;
}

.home-title {
  font-family: var(--font-display);
  font-size: 2.6em;
  margin: 10px 0 6px;
  color: var(--ink);
  letter-spacing: -0.015em;
  font-weight: 780;
  line-height: 1.1;
}

.home-sub {
  color: var(--muted);
  margin: 0 0 24px;
  font-size: 1.02em;
}

.card-grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}

.card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  height: 100%;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--bg-elevated);
  color: var(--text-normal);
  box-shadow: 0 1px 0 rgba(60, 40, 10, 0.03);
  transition: border-color 0.15s, transform 0.15s, box-shadow 0.15s;
}

.card:hover {
  border-color: var(--terra);
  text-decoration: none;
  transform: translateY(-2px);
  box-shadow: 0 10px 24px rgba(195, 98, 73, 0.12);
}

.card-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 620;
  color: var(--ink);
  line-height: 1.35;
}

.card-icon {
  display: inline-flex;
  color: var(--terra);
  flex-shrink: 0;
}

.card-meta {
  color: var(--text-faint);
  font-size: 0.82em;
  padding-left: 24px;
}

.item-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--bg-elevated);
  overflow: hidden;
}

.item-list .item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line-soft);
}

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

.item-list .item:hover {
  background: var(--bg-hover);
}

.item-list .internal-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text-normal);
  font-weight: 520;
}

.item-icon {
  display: inline-flex;
  color: var(--terra);
}

.item-lock {
  display: inline-flex;
  color: var(--text-faint);
}

.item-meta {
  color: var(--text-faint);
  font-size: 0.82em;
  white-space: nowrap;
}

.folder-h {
  font-size: 0.8em;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
  margin-top: 28px;
}

/* ---------- поиск ---------- */

.search-results {
  list-style: none;
  margin: 0;
  padding: 0;
}

.search-result {
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.result-title {
  font-size: 1.03em;
  font-weight: 620;
}

.snippet {
  color: var(--text-muted);
  font-size: 0.9em;
  margin-top: 3px;
}

.snippet mark,
.search-result mark {
  background: #f3e3b4;
  color: var(--ink);
  padding: 0 2px;
  border-radius: 3px;
}

/* ---------- формы ---------- */

.login-box {
  max-width: 400px;
  margin: 48px auto;
  padding: 30px 32px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--bg-elevated);
  box-shadow: var(--shadow);
}

.login-title {
  margin: 0 0 6px;
  font-family: var(--font-display);
  color: var(--ink);
  font-size: 1.6em;
  font-weight: 750;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 13px;
  margin-top: 18px;
}

.stack.narrow {
  max-width: 380px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 0.88em;
  color: var(--muted);
  font-weight: 550;
}

.field input,
.field select,
input.input-sm,
select.select-sm {
  font: inherit;
  font-size: 15px;
  font-weight: 400;
  color: var(--text-normal);
  background: var(--paper);
  border: 1.5px solid var(--line);
  border-radius: 10px;
  padding: 8px 11px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.field input:focus,
.field select:focus,
input.input-sm:focus,
.select-sm:focus {
  border-color: var(--terra);
  box-shadow: 0 0 0 3px rgba(195, 98, 73, 0.12);
}

.form-error,
.flash.err {
  background: #fbeeea;
  border: 1px solid rgba(176, 66, 47, 0.35);
  color: #8f3223;
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 0.92em;
}

.flash,
.flash.ok {
  background: #f2f7f1;
  border: 1px solid rgba(63, 125, 79, 0.35);
  color: #35603f;
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 16px;
  font-size: 0.92em;
}

.kv {
  display: grid;
  grid-template-columns: 150px 1fr;
  gap: 8px 16px;
  margin: 18px 0;
}

.kv dt {
  color: var(--muted);
}

.kv dd {
  margin: 0;
  font-weight: 550;
}

/* ---------- админка ---------- */

.admin-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.admin-head h1 {
  font-family: var(--font-display);
  font-size: 1.75em;
  font-weight: 760;
  margin: 0;
  color: var(--ink);
}

.admin-user {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.9em;
}

.admin-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 22px;
  flex-wrap: wrap;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg-elevated);
  width: fit-content;
}

.admin-tab {
  padding: 7px 14px;
  border-radius: 9px;
  color: var(--muted);
  font-size: 0.92em;
  font-weight: 550;
}

.admin-tab:hover {
  color: var(--ink);
  background: var(--bg-hover);
  text-decoration: none;
}

.admin-tab.active {
  background: var(--terra);
  color: #fff;
}

.admin-tab.active:hover {
  background: var(--terra-dark);
  color: #fff;
}

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

.stat {
  display: flex;
  flex-direction: column;
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--bg-elevated);
}

.stat-num {
  font-family: var(--font-display);
  font-size: 2em;
  font-weight: 760;
  color: var(--terra);
  line-height: 1.1;
}

.stat-label {
  color: var(--muted);
  font-size: 0.82em;
  margin-top: 2px;
}

.admin-sub {
  font-size: 1.08em;
  color: var(--ink);
  margin: 28px 0 12px;
  font-weight: 650;
}

.admin-form input,
.admin-form select,
.admin-form textarea {
  font: inherit;
  font-size: 15px;
  color: var(--text-normal);
  background: var(--paper);
  border: 1.5px solid var(--line);
  border-radius: 10px;
  padding: 8px 11px;
  outline: none;
}

.admin-form input:focus,
.admin-form select:focus {
  border-color: var(--terra);
}

.inline-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  align-items: end;
}

.fieldset {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 14px 18px 18px;
  margin: 0 0 18px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px 16px;
  background: var(--bg-elevated);
}

.fieldset legend {
  color: var(--muted);
  font-size: 0.78em;
  padding: 0 8px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-weight: 650;
}

.check-line {
  grid-column: 1 / -1;
  display: flex;
  align-items: flex-start;
  gap: 9px;
  color: var(--text-normal);
  font-size: 0.93em;
}

.check-line input {
  margin-top: 4px;
  accent-color: var(--terra);
}

.switch {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.88em;
  color: var(--muted);
  white-space: nowrap;
}

.switch input {
  accent-color: var(--terra);
}

.users-table input.input-sm,
.users-table select.select-sm {
  max-width: 170px;
  width: 100%;
  padding: 6px 8px;
  font-size: 14px;
}

.row-actions {
  white-space: nowrap;
}

.badge {
  font-size: 0.75em;
  border: 1px solid var(--terra);
  color: var(--terra);
  border-radius: 999px;
  padding: 0 7px;
  margin-left: 4px;
}

.kv-list {
  margin: 8px 0 18px;
  padding-left: 20px;
}

.steps {
  padding-left: 22px;
  color: var(--text-normal);
}

.steps li {
  margin: 9px 0;
}

.steps code,
.muted code,
.flash code {
  background: var(--paper-3);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 1px 6px;
  font-size: 0.88em;
  word-break: break-all;
  color: #8f412f;
}

.backup-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.backup-item {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 10px 0;
  border-bottom: 1px solid var(--line-soft);
}

.backup-name {
  font-family: var(--font-mono);
  font-size: 0.86em;
}

.table-wrap table {
  background: var(--bg-elevated);
}

.history-table td,
.history-table th {
  font-size: 14px;
}

/* ---------- фильтр в дереве ---------- */

.tree-filter-results {
  margin: 0 0 8px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  box-shadow: var(--shadow);
}

.tree-filter-results .tree-link {
  font-size: 13px;
  padding: 5px 7px;
}

/* ---------- подвал ---------- */

.site-footer {
  border-top: 1px solid var(--line);
  color: var(--text-faint);
  font-size: 0.85em;
  padding: 18px 34px;
  background: var(--bg-sidebar);
}

.error-page .note-title {
  font-size: 3.2em;
  color: var(--terracotta, #c36249);
  opacity: 0.35;
}

/* ---------- адаптивность ---------- */

@media (max-width: 980px) {
  .top-search {
    display: none;
  }

  .nav-toggle {
    display: inline-flex;
  }

  .topbar {
    padding: 0 14px;
  }

  .content {
    padding: 20px 16px 80px;
  }

  .sidebar {
    position: fixed;
    top: var(--topbar-h);
    left: 0;
    z-index: 35;
    transform: translateX(-102%);
    transition: transform 0.2s ease;
    box-shadow: var(--shadow);
    width: min(330px, 88vw);
    flex-basis: auto;
  }

  body.nav-open .sidebar {
    transform: translateX(0);
  }

  body.nav-open .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: var(--topbar-h) 0 0 0;
    background: rgba(20, 20, 20, 0.32);
    z-index: 25;
    backdrop-filter: blur(1px);
  }

  .page-head {
    flex-wrap: wrap;
  }

  .page-actions {
    margin-left: 0;
  }

  .note-title {
    font-size: 1.65em;
  }

  .home-title {
    font-size: 2em;
  }

  .user-name {
    display: none;
  }
}

@media print {
  .topbar,
  .sidebar,
  .page-actions,
  .toc,
  .backlinks,
  .local-graph {
    display: none;
  }

  body {
    background: #fff;
    color: #000;
  }
}
