/* Тема документации ArchMap. Палитра и типографика — как у приложения (frontend/src/ui/styles.ts,
   pageChrome.ts, LoginPage.css): одна светлая тема, slate-нейтрали, синий акцент #2563eb,
   системный шрифт, радиусы 6–12, мягкие тени. Дерево страниц слева повторяет дерево объектов
   продукта (NodeTreePanel.css: строки .nt-*, шеврон-зона, направляющая вложенности). */
:root {
  --ink: #0f172a;
  --ink-2: #1e293b;
  --ink-3: #334155;
  --mute: #475569;
  --mute-2: #64748b;
  --faint: #94a3b8;
  --line: #e2e8f0;
  --line-soft: #eef2f6;
  --panel: #f8fafc;
  --panel-2: #f1f5f9;
  --paper: #fff;
  --blue: #2563eb;
  --blue-ink: #1d4ed8;
  --blue-soft: #eff6ff;
  --blue-mark: #dbeafe;
  --blue-line: #93c5fd;
  --code-bg: #0f172a;
  --sans: system-ui, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "JetBrains Mono", Consolas, monospace;
  --top-h: 56px;
  --side-w: 300px;
  --gut: clamp(16px, 3vw, 32px);
  color-scheme: light;
}

* { box-sizing: border-box; }

html { scroll-padding-top: calc(var(--top-h) + 20px); }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font: 16px/1.6 var(--sans);
  color: var(--ink-2);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: var(--blue); }

:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; border-radius: 6px; }

/* Кнопки — как в приложении (ui/styles.ts, index.css .btn-soft) */
.btn-primary, .btn-soft, .btn-danger {
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.1;
  padding: 9px 18px;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--blue-ink); }
.btn-soft { background: var(--panel-2); color: var(--mute); border-color: var(--line); }
.btn-soft:hover:not(:disabled) { background: var(--line); border-color: #cbd5e1; }
.btn-danger { background: #fff; color: #dc2626; border-color: #fecaca; }
.btn-danger:hover:not(:disabled) { background: #fef2f2; border-color: #fca5a5; }
button:disabled { opacity: 0.55; cursor: not-allowed; }

/* ── Шапка ──────────────────────────────────────────────────────────────────── */
.top {
  position: sticky;
  top: 0;
  z-index: 40;
  height: var(--top-h);
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}
.top-in {
  height: 100%;
  padding: 0 var(--gut);
  display: flex;
  align-items: center;
  gap: 14px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 3px 6px;
  margin: -3px -6px;
  border-radius: 8px;
  color: var(--ink);
  text-decoration: none;
  white-space: nowrap;
}
.brand:hover { background: var(--panel-2); }
.logo {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: var(--blue);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  box-shadow: 0 1px 2px rgba(37, 99, 235, 0.35);
}
.brand-word { font-size: 16.5px; font-weight: 700; letter-spacing: -0.01em; }
.brand-word b { color: var(--blue); font-weight: inherit; }
.brand-div { width: 1px; height: 22px; background: var(--line); margin: 0 4px; }
.brand-sub { font-size: 14.5px; font-weight: 600; color: var(--mute); }

.top-right { display: flex; align-items: center; gap: 10px; margin-left: auto; min-width: 0; flex: 1 1 auto; justify-content: flex-end; }

.menu-btn {
  display: none;
  width: 36px;
  height: 36px;
  margin-left: -8px;
  padding: 0;
  border: none;
  border-radius: 8px;
  background: none;
  color: var(--ink-3);
  cursor: pointer;
  align-items: center;
  justify-content: center;
}
.menu-btn:hover { background: var(--panel-2); }

/* Авторский режим: кнопки появляются только у вошедшего автора (их ставит docs.js) */
.author-slot { display: flex; align-items: center; gap: 8px; }
.author-slot:empty { display: none; }
.author-btn {
  font: inherit;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--blue-ink);
  background: var(--blue-soft);
  border: 1px solid var(--blue-line);
  border-radius: 8px;
  padding: 6px 12px;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}
.author-btn:hover { background: var(--blue-mark); }
.author-menu { position: relative; }
.author-menu-btn {
  font: inherit;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--mute);
  background: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 10px;
  cursor: pointer;
}
.author-menu-btn:hover { background: var(--panel-2); color: var(--ink); }
.author-menu-pop {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 200px;
  padding: 6px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.14);
  z-index: 50;
}
.author-menu-pop[hidden] { display: none; }
.author-menu-item {
  display: block;
  width: 100%;
  text-align: left;
  font: inherit;
  font-size: 14px;
  color: var(--ink-3);
  background: none;
  border: none;
  border-radius: 7px;
  padding: 8px 10px;
  cursor: pointer;
  text-decoration: none;
}
.author-menu-item:hover { background: var(--panel-2); color: var(--ink); }

/* Поиск */
.search { position: relative; flex: 0 1 300px; min-width: 150px; }
.search input {
  width: 100%;
  height: 34px;
  padding: 0 60px 0 34px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--panel);
  font: inherit;
  font-size: 14px;
  color: var(--ink);
  transition: border-color 0.12s ease, box-shadow 0.12s ease, background 0.12s ease;
}
.search input::placeholder { color: var(--faint); }
.search input:focus { outline: none; border-color: var(--blue-line); background: var(--paper); box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12); }
.search input::-webkit-search-cancel-button { display: none; }
.search-ico { position: absolute; left: 11px; top: 9px; color: var(--faint); pointer-events: none; }
.search-kbd {
  position: absolute;
  right: 8px;
  top: 8px;
  font: 600 10.5px/1 var(--sans);
  color: var(--faint);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 3px 5px;
  background: var(--paper);
  pointer-events: none;
}
.search-pop {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  width: min(520px, calc(100vw - 2 * var(--gut)));
  max-height: min(60vh, 520px);
  overflow: auto;
  padding: 6px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.14);
  z-index: 50;
}
.search-pop[hidden] { display: none; }
.sr { display: block; padding: 8px 10px; border-radius: 8px; color: var(--ink); text-decoration: none; }
.sr:hover, .sr[aria-selected="true"] { background: var(--blue-soft); }
.sr-head { display: flex; align-items: baseline; gap: 8px; font-size: 14px; }
.sr-title { font-weight: 600; }
.sr-sec { color: var(--mute); }
.sr-sec::before { content: "›"; margin-right: 6px; color: var(--faint); }
.sr-guide { margin-left: auto; font-size: 11.5px; font-weight: 600; color: var(--mute-2); background: var(--panel-2); border-radius: 6px; padding: 1px 7px; white-space: nowrap; }
.sr-snip {
  font-size: 12.5px;
  line-height: 1.45;
  color: var(--mute);
  margin-top: 2px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.sr mark { background: rgba(37, 99, 235, 0.14); color: inherit; border-radius: 3px; padding: 0 1px; }
.sr-empty { padding: 14px 12px; font-size: 14px; color: var(--mute-2); }

/* ── Каркас: дерево · статья ────────────────────────────────────────────────── */
.shell {
  flex: 1 0 auto;
  width: 100%;
  display: grid;
  grid-template-columns: var(--side-w) minmax(0, 1fr);
  align-items: start;
}
.main { min-width: 0; padding: 26px var(--gut) 56px; }
.article { max-width: 780px; }

/* Панель дерева — как NodeTreePanel: фон #fbfcfd, правая граница, строки .nt-* */
.side {
  position: sticky;
  top: var(--top-h);
  height: calc(100vh - var(--top-h));
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 10px 0 40px;
  background: #fbfcfd;
  border-right: 1px solid var(--line);
  scrollbar-width: thin;
}
.tree { display: block; }
.nt-row {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 7px 8px 7px 2px;
  margin: 0 6px;
  border-radius: 6px;
  font-size: 13px;
  line-height: 1.4;
  color: var(--ink-3);
  cursor: pointer;
}
.nt-row:hover { background: var(--blue-soft); }
.nt-row:hover .nt-name, .nt-row:hover .nt-glyph { color: var(--blue-ink); }
.nt-row--current, .nt-row--current:hover { background: var(--blue-mark); box-shadow: inset 2px 0 0 var(--blue); }
.nt-row--current .nt-name, .nt-row--current .nt-glyph { color: var(--blue-ink); font-weight: 600; }
/* Длинные названия переносятся (в дереве объектов продукта — усечение, но названия
   страниц документации длиннее имён узлов и должны читаться целиком) */
.nt-link { display: flex; align-items: flex-start; gap: 7px; flex: 1; min-width: 0; color: inherit; text-decoration: none; }
.nt-name { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.nt-name--container { font-weight: 600; color: var(--ink-2); }
.nt-glyph { flex: none; display: inline-flex; align-items: center; margin-top: 3px; color: var(--mute-2); }
.nt-glyph--lead { width: 26px; justify-content: center; }
.nt-chevzone {
  width: 26px;
  align-self: stretch;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: -7px 0;
  padding: 0;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--faint);
}
.nt-chevhit { display: flex; align-items: center; justify-content: center; width: 22px; height: 22px; border-radius: 6px; transition: background 0.12s ease, color 0.12s ease; }
.nt-chevzone:hover .nt-chevhit { background: var(--blue-mark); color: var(--blue-ink); }
.nt-chev { display: inline-block; line-height: 1; transition: transform 0.12s ease; }
.nt-chev svg { display: block; }
.nt-node--open > .nt-row .nt-chev { transform: rotate(90deg); }
.nt-chevspacer { width: 26px; flex: none; }
.nt-children { margin-left: 21px; padding-left: 6px; border-left: 1px solid #e6eaf0; }
.nt-children[hidden] { display: none; }

/* Крошки */
.crumbs {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px 6px;
  margin-bottom: 18px;
  font-size: 13px;
  color: var(--mute-2);
}
.crumbs a { color: var(--mute); text-decoration: none; padding: 2px 6px; margin: -2px -6px; border-radius: 6px; }
.crumbs a:hover { background: var(--blue-soft); color: var(--blue-ink); }
.crumb-sep { color: var(--faint); }

/* ── Статья ─────────────────────────────────────────────────────────────────── */
.article h1 {
  margin: 0 0 10px;
  font-size: 32px;
  line-height: 1.15;
  font-weight: 800;
  letter-spacing: -0.025em;
  color: var(--ink);
  text-wrap: balance;
}
.lead { margin: 0 0 22px; font-size: 17px; line-height: 1.55; color: var(--mute); }
.article h2 {
  margin: 42px 0 12px;
  padding-top: 22px;
  border-top: 1px solid var(--line-soft);
  font-size: 22px;
  line-height: 1.25;
  font-weight: 700;
  letter-spacing: -0.015em;
  color: var(--ink);
}
.article h3 { margin: 28px 0 8px; font-size: 17.5px; line-height: 1.3; font-weight: 700; color: var(--ink); }
.article h4 { margin: 22px 0 6px; font-size: 15.5px; font-weight: 700; color: var(--ink); }
.h-anchor {
  margin-left: 8px;
  font-weight: 500;
  color: var(--faint);
  text-decoration: none;
  opacity: 0;
  transition: opacity 0.12s ease;
}
.article h2:hover .h-anchor, .article h3:hover .h-anchor, .article h4:hover .h-anchor, .h-anchor:focus-visible { opacity: 1; }
.h-anchor:hover { color: var(--blue); }

.article p { margin: 0 0 14px; }
.article ul, .article ol { margin: 0 0 14px; padding-left: 26px; }
.article li { margin: 4px 0; }
.article li > p { margin-bottom: 6px; }
.article a { text-decoration: underline; text-decoration-color: rgba(37, 99, 235, 0.35); text-underline-offset: 2px; }
.article a:hover { color: var(--blue-ink); text-decoration-color: currentColor; }
.article strong { color: var(--ink); font-weight: 600; }
.article hr { margin: 28px 0; border: none; border-top: 1px solid var(--line); }
.article blockquote { margin: 0 0 14px; padding: 2px 0 2px 16px; border-left: 3px solid var(--line); color: var(--mute); }
.article blockquote p:last-child { margin-bottom: 0; }

.article code {
  font-family: var(--mono);
  font-size: 0.9em;
  padding: 1px 6px;
  border-radius: 6px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--ink);
  overflow-wrap: anywhere;
}
.article kbd {
  font-family: var(--sans);
  font-size: 0.82em;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 6px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  background: var(--paper);
  color: var(--ink-3);
}
.article pre {
  position: relative;
  margin: 0 0 16px;
  padding: 14px 16px;
  border-radius: 10px;
  background: var(--code-bg);
  color: #e2e8f0;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 13.5px;
  line-height: 1.6;
}
.article pre code { font: inherit; padding: 0; border: none; background: none; color: inherit; }
.article pre[data-lang]::before {
  content: attr(data-lang);
  position: absolute;
  right: 12px;
  top: 8px;
  font: 600 10.5px/1 var(--sans);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: rgba(226, 232, 240, 0.45);
}
.copy-btn {
  position: absolute;
  right: 10px;
  bottom: 10px;
  padding: 4px 9px;
  border: 1px solid rgba(226, 232, 240, 0.25);
  border-radius: 7px;
  background: rgba(15, 23, 42, 0.8);
  color: #e2e8f0;
  font: 600 12px/1.2 var(--sans);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.12s ease, background 0.12s ease;
}
.article pre:hover .copy-btn, .copy-btn:focus-visible, .copy-btn.done { opacity: 1; }
.copy-btn:hover { background: rgba(30, 41, 59, 0.95); }
.copy-btn.done { border-color: rgba(134, 239, 172, 0.5); color: #86efac; }

.table-wrap { margin: 0 0 16px; overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; }
.article table { width: 100%; border-collapse: collapse; font-size: 15px; }
.article th, .article td { padding: 9px 12px; border-top: 1px solid var(--line); text-align: left; vertical-align: top; }
.article th { border-top: none; background: var(--panel); font-size: 13px; font-weight: 700; color: var(--mute); }
.article tr:nth-child(even) td { background: #fcfdfe; }

.fig { margin: 20px 0 22px; }
.fig img {
  display: block;
  max-width: 100%;
  height: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.06);
}
.fig figcaption { margin-top: 8px; font-size: 13.5px; line-height: 1.45; color: var(--mute-2); }
.article img:not(.fig img) { max-width: 100%; height: auto; }

.callout { margin: 0 0 16px; padding: 12px 16px 2px; border-radius: 10px; border-left: 3px solid var(--blue); background: var(--blue-soft); }
.callout-title { margin: 0 0 6px !important; font-size: 13px; font-weight: 700; letter-spacing: 0.02em; color: var(--blue-ink); }
.callout p { margin-bottom: 10px; }
.callout-tip { border-left-color: #10b981; background: #ecfdf5; }
.callout-tip .callout-title { color: #047857; }
.callout-warning { border-left-color: #f59e0b; background: #fffbeb; }
.callout-warning .callout-title { color: #b45309; }
.callout-danger { border-left-color: #dc2626; background: #fef2f2; }
.callout-danger .callout-title { color: #b91c1c; }

.details { margin: 0 0 16px; padding: 0 16px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); }
.details summary { padding: 11px 0; font-weight: 600; color: var(--ink); cursor: pointer; }
.details[open] summary { border-bottom: 1px solid var(--line); margin-bottom: 12px; }

/* Списки разделов (главная, титульная руководства) */
.sections { margin-top: 32px; }
.sections-title { margin-bottom: 10px !important; }
.sec-list { list-style: none; margin: 0; padding: 0; }
.sec-list li { padding: 9px 0; border-top: 1px solid var(--line-soft); display: flex; flex-direction: column; gap: 2px; }
.sec-list li:first-child { border-top: none; }
.sec-list a { font-weight: 600; text-decoration: none; }
.sec-desc { font-size: 14px; line-height: 1.45; color: var(--mute); }

/* Соседи страницы */
.pager { display: flex; justify-content: space-between; gap: 16px; max-width: 780px; margin-top: 40px; padding-top: 16px; border-top: 1px solid var(--line-soft); font-size: 14px; }
.pager a { text-decoration: none; font-weight: 600; color: var(--blue-ink); }
.pager a:hover { text-decoration: underline; }
.pager-next { text-align: right; margin-left: auto; }

/* Подвал сайта */
.foot { border-top: 1px solid var(--line); background: var(--panel); font-size: 13px; color: var(--mute-2); }
.foot-in { padding: 14px var(--gut); display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.foot-links { display: flex; gap: 18px; }
.foot a { color: var(--mute); text-decoration: none; }
.foot a:hover { color: var(--blue-ink); }

/* ── Вход автора ────────────────────────────────────────────────────────────── */
.login-page { background: var(--panel); }
.login-main { flex: 1 0 auto; display: flex; align-items: flex-start; justify-content: center; padding: 64px var(--gut); }
.login-card {
  width: min(420px, 100%);
  padding: 28px 28px 24px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.06);
}
.login-card h1 { margin: 0 0 8px; font-size: 22px; font-weight: 800; letter-spacing: -0.02em; color: var(--ink); }
.login-hint { margin: 0 0 18px; font-size: 14px; line-height: 1.5; color: var(--mute); }
.login-form { display: flex; flex-direction: column; gap: 8px; }
.login-form label { font-size: 13px; font-weight: 600; color: var(--mute); }
.login-form input {
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
  font-size: 14px;
  color: var(--ink);
}
.login-form input:focus { outline: none; border-color: var(--blue-line); box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12); }
.login-form .btn-primary { margin-top: 8px; align-self: flex-start; }
.login-error { margin: 4px 0 0; font-size: 13.5px; color: #dc2626; }
.login-error code { font-family: var(--mono); font-size: 0.92em; }

/* ── Адаптив ────────────────────────────────────────────────────────────────── */
@media (max-width: 1180px) {
  .search-kbd { display: none; }
  .search input { padding-right: 12px; }
}

@media (max-width: 920px) {
  :root { --side-w: 300px; }
  .shell { grid-template-columns: minmax(0, 1fr); }
  .menu-btn { display: inline-flex; }
  .side {
    position: fixed;
    left: 0;
    top: var(--top-h);
    width: min(var(--side-w), 88vw);
    box-shadow: 0 12px 30px rgba(15, 23, 42, 0.16);
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    z-index: 35;
  }
  body.menu-open .side { transform: none; }
  .side-backdrop { position: fixed; inset: var(--top-h) 0 0; background: rgba(15, 23, 42, 0.3); opacity: 0; pointer-events: none; transition: opacity 0.2s ease; z-index: 34; }
  body.menu-open .side-backdrop { opacity: 1; pointer-events: auto; }
  body.menu-open { overflow: hidden; }
}

@media (max-width: 760px) {
  .brand-div, .brand-sub { display: none; }
  .search { flex: 1 1 auto; }
  .search-pop { position: fixed; left: var(--gut); right: var(--gut); top: calc(var(--top-h) + 4px); width: auto; }
  .article h1 { font-size: 27px; }
  .main { padding-top: 18px; }
  .author-btn { padding: 6px 9px; }
}

@media (max-width: 420px) {
  .brand-word { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
