/* тема: default */
/* Основная тема справки: светлая и тёмная в одной, читатель переключает сам.
   Обезличенная база: фирменный цвет задаётся в настройках проекта и
   подставляется поверх. Названия продуктов здесь быть не должно. */

:root {
  color-scheme: dark;

  --bg:            #0a0a0c;
  --bg-raised:     #121215;
  --bg-hover:      #18191b;
  --bg-sunken:     #08080a;
  --border:        #24262b;
  --border-soft:   #1b1d21;

  --text:          #e8eaed;
  --text-dim:      #9aa0a8;
  --text-faint:    #6d737c;

  --accent:        #4a7fd0;
  --accent-soft:   #4a7fd026;
  --accent-text:   #86a9dd;

  --note:          #4a8cff;
  --warn:          #f0a33b;
  --tip:           #35c07a;

  --radius:   10px;
  --radius-s: 6px;

  --sidebar-w: 292px;
  --toc-w:     236px;
  --header-h:  56px;

  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
}

:root[data-theme="light"] {
  color-scheme: light;

  --bg:            #ffffff;
  --bg-raised:     #f7f8fa;
  --bg-hover:      #eef0f4;
  --bg-sunken:     #f2f3f6;
  --border:        #dfe2e8;
  --border-soft:   #e9ebf0;

  --text:          #16181d;
  --text-dim:      #5b626c;
  --text-faint:    #858c96;

  --accent:        #2d5da8;
  --accent-soft:   #2d5da814;
  --accent-text:   #2d5da8;

  --note:          #1657c8;
  --warn:          #b26a00;
  --tip:           #17794a;
}

/* ------------------------------------------------------------ базовое */

* { box-sizing: border-box; }

html { scroll-behavior: smooth; scroll-padding-top: calc(var(--header-h) + 16px); }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.65 var(--sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

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

svg.i { width: 18px; height: 18px; flex: 0 0 18px; }

::selection { background: var(--accent); color: #fff; }

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

/* ------------------------------------------------------------ шапка */

.header {
  position: sticky; top: 0; z-index: 40;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-soft);
}
/* Шапка тянется на всю ширину, а её содержимое выровнено по странице:
   иначе логотип уезжает к краю экрана, а текст остаётся посередине. */
.header-inner {
  height: var(--header-h);
  max-width: 1560px; margin: 0 auto;
  padding: 0 20px;
  display: flex; align-items: center; gap: 14px;
}

.brand {
  display: flex; align-items: center; gap: 10px;
  color: var(--text); font-weight: 600; font-size: 14.5px; letter-spacing: -0.01em;
  white-space: nowrap;
}
.brand:hover { text-decoration: none; }
.brand svg { color: var(--accent); }
.brand .ver {
  font-weight: 500; font-size: 11px; color: var(--text-faint);
  border: 1px solid var(--border); border-radius: 20px; padding: 1px 7px;
}

.header-spacer { flex: 1; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; padding: 0;
  background: transparent; border: 1px solid transparent; border-radius: var(--radius-s);
  color: var(--text-dim); cursor: pointer;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }
.icon-btn svg[hidden] { display: none; }
#nav-toggle { display: none; }

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

.search {
  position: relative;
  width: min(420px, 42vw);
}
.search svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--text-faint); pointer-events: none; }
.search input {
  width: 100%; height: 34px;
  padding: 0 46px 0 34px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  color: var(--text); font: inherit; font-size: 14px;
}
.search input::placeholder { color: var(--text-faint); }
.search input:focus { outline: none; border-color: var(--accent); background: var(--bg); }
.search kbd {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  font: 11px/1 var(--mono); color: var(--text-faint);
  border: 1px solid var(--border); border-radius: 4px; padding: 3px 5px;
  pointer-events: none;
}
.search input:focus ~ kbd { display: none; }

/* Выдача шире строки поиска, поэтому крепится к правому её краю, а не к
   левому: строка стоит у правого края шапки, и панель, растущая вправо,
   вылезала за окно на 132 px при любой его ширине — вместе с полосой
   прокрутки вбок на всей странице. Растёт влево, там место есть. */
.results {
  position: absolute; top: calc(100% + 8px); left: auto; right: 0;
  width: min(620px, 78vw); max-width: calc(100vw - 24px);
  max-height: min(66vh, 560px); overflow-y: auto;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 16px 48px rgba(0, 0, 0, .45);
  padding: 6px;
  display: none;
}
.results[data-open="1"] { display: block; }
.results .hit {
  display: block; padding: 9px 11px; border-radius: var(--radius-s);
  color: var(--text); text-decoration: none;
}
.results .hit:hover, .results .hit.sel { background: var(--bg-hover); text-decoration: none; }
.results .hit-top { display: flex; align-items: baseline; gap: 8px; }
.results .hit-title { font-weight: 550; font-size: 14px; }
.results .hit-sec { font-size: 11.5px; color: var(--text-faint); margin-left: auto; white-space: nowrap; }
.results .hit-snip { font-size: 12.5px; color: var(--text-dim); margin-top: 2px; line-height: 1.5; }
.results mark { background: var(--accent-soft); color: var(--accent-text); border-radius: 3px; padding: 0 2px; }
.results .empty { padding: 18px 12px; color: var(--text-dim); font-size: 13.5px; text-align: center; }

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

.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  align-items: start;
  max-width: 1560px;
  margin: 0 auto;
}

.sidebar {
  position: sticky; top: var(--header-h);
  height: calc(100vh - var(--header-h));
  overflow-y: auto; overscroll-behavior: contain;
  padding: 18px 12px 40px;
  border-right: 1px solid var(--border-soft);
}
.sidebar::-webkit-scrollbar, .results::-webkit-scrollbar { width: 10px; }
.sidebar::-webkit-scrollbar-thumb, .results::-webkit-scrollbar-thumb {
  background: var(--border); border-radius: 8px; border: 3px solid var(--bg);
}

.nav-section > summary {
  display: flex; align-items: center; gap: 9px;
  padding: 7px 10px; border-radius: var(--radius-s);
  color: var(--text); font-size: 13.5px; font-weight: 550;
  cursor: pointer; list-style: none; user-select: none;
}
.nav-section > summary::-webkit-details-marker { display: none; }
.nav-section > summary:hover { background: var(--bg-hover); }
.nav-section > summary svg:first-child { color: var(--text-dim); }
.nav-section .chev { margin-left: auto; width: 14px; height: 14px; flex: 0 0 14px; color: var(--text-faint); transition: transform .16s ease; }
.nav-section[open] > summary .chev { transform: rotate(90deg); }
.nav-section[open] > summary svg:first-child { color: var(--accent); }

.nav-section ul { list-style: none; margin: 2px 0 8px; padding: 0 0 0 27px; }
.nav-section li a {
  display: block; padding: 5px 10px; border-radius: var(--radius-s);
  color: var(--text-dim); font-size: 13.5px; line-height: 1.45;
  border-left: 2px solid transparent; margin-left: -1px;
}
.nav-section li a:hover { color: var(--text); background: var(--bg-hover); text-decoration: none; }
.nav-section li a.active {
  color: var(--accent-text); background: var(--accent-soft);
  border-left-color: var(--accent); font-weight: 550;
}

/* ------------------------------------------------------------ страница */

.main { min-width: 0; display: grid; grid-template-columns: minmax(0, 1fr) var(--toc-w); gap: 40px; padding: 30px 40px 80px; }
.main.no-toc { grid-template-columns: minmax(0, 1fr); }
.article { min-width: 0; max-width: 780px; }

.crumbs { font-size: 12.5px; color: var(--text-faint); margin-bottom: 14px; }
.crumbs a { color: var(--text-dim); }
.crumbs .sep { margin: 0 7px; opacity: .5; }

.article h1 {
  font-size: 30px; line-height: 1.2; letter-spacing: -0.022em;
  font-weight: 620; margin: 0 0 6px;
}
.lede { color: var(--text-dim); font-size: 15.5px; margin: 0 0 26px; }

.article h2 {
  font-size: 20px; line-height: 1.3; letter-spacing: -0.015em; font-weight: 600;
  margin: 40px 0 12px; padding-top: 14px; border-top: 1px solid var(--border-soft);
}
.article h3 { font-size: 16.5px; font-weight: 600; margin: 28px 0 10px; letter-spacing: -0.01em; }
.article h2:first-of-type { border-top: none; padding-top: 0; margin-top: 26px; }

.article p { margin: 0 0 14px; }
.article ul, .article ol { margin: 0 0 14px; padding-left: 24px; }
.article li { margin: 5px 0; }
.article li > ul, .article li > ol { margin: 5px 0 0; }
.article ol { counter-reset: step; list-style: none; padding-left: 0; }
.article ol > li {
  counter-increment: step; position: relative; padding-left: 34px; margin: 9px 0;
}
.article ol > li::before {
  content: counter(step);
  position: absolute; left: 0; top: 1px;
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--bg-hover); border: 1px solid var(--border);
  color: var(--text-dim); font-size: 11.5px; font-weight: 600;
  display: flex; align-items: center; justify-content: center;
}
.article ol ol { padding-left: 0; margin-top: 8px; }

.article strong { font-weight: 600; color: var(--text); }
.article hr { border: none; border-top: 1px solid var(--border-soft); margin: 32px 0; }

.article blockquote {
  margin: 0 0 16px; padding: 2px 0 2px 16px;
  border-left: 2px solid var(--border); color: var(--text-dim);
}

/* код */
.article code {
  font: 0.875em/1.5 var(--mono);
  background: var(--bg-raised); border: 1px solid var(--border-soft);
  border-radius: 4px; padding: 1px 5px;
}
.article pre {
  background: var(--bg-sunken); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px; overflow-x: auto;
  margin: 0 0 16px;
}
.article pre code { background: none; border: none; padding: 0; font-size: 12.8px; line-height: 1.6; }

/* таблицы */
.table-wrap {
  overflow-x: auto; margin: 0 0 18px;
  border: 1px solid var(--border); border-radius: var(--radius);
}
.article table { border-collapse: collapse; width: 100%; font-size: 14px; }
.article th, .article td {
  text-align: left; vertical-align: top;
  padding: 9px 14px; border-bottom: 1px solid var(--border-soft);
}
.article thead th {
  background: var(--bg-raised); color: var(--text-dim);
  font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em;
  white-space: nowrap;
}
.article tbody tr:last-child td { border-bottom: none; }
.article tbody tr:hover td { background: color-mix(in srgb, var(--bg-hover) 55%, transparent); }
.article td:first-child { color: var(--text); }

/* изображения */
.fig { margin: 0 0 20px; }
.fig-body { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-start; }
.fig-link { display: block; flex: 1 1 auto; min-width: 0; line-height: 0; }
.fig img.shot {
  display: block; width: 100%; height: auto;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg-sunken);
}
/* мелкие фрагменты интерфейса не растягиваем на всю колонку */
.fig-link { max-width: 100%; }
.fig-link:hover img { border-color: var(--accent); }
.fig figcaption { margin-top: 8px; font-size: 12.5px; color: var(--text-faint); line-height: 1.5; }

img.ic {
  display: inline-block; vertical-align: -0.28em;
  height: 1.45em; width: auto; max-width: 220px;
  border: 1px solid var(--border-soft); border-radius: 4px;
  background: var(--bg-sunken); padding: 1px;
}
td img.ic, th img.ic { max-width: 200px; }
.img-missing { color: var(--warn); font-size: 12.5px; }

/* лайтбокс */
.lightbox {
  position: fixed; inset: 0; z-index: 90;
  display: none; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, .86); padding: 64px 32px 32px; cursor: zoom-out;
}
.lightbox[data-open="1"] { display: flex; }
.lightbox img {
  max-width: 100%; max-height: 100%; cursor: default;
  border-radius: var(--radius); box-shadow: 0 24px 70px rgba(0, 0, 0, .6);
}
.lightbox-close {
  position: absolute; top: 16px; right: 16px;
  width: 40px; height: 40px; padding: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(255, 255, 255, .12); color: #fff;
  border: 1px solid rgba(255, 255, 255, .22); border-radius: 50%;
  cursor: pointer;
}
.lightbox-close:hover { background: rgba(255, 255, 255, .22); }
.lightbox-close svg { width: 20px; height: 20px; }

/* выноски */
.callout {
  margin: 0 0 18px; padding: 13px 16px;
  background: var(--bg-raised);
  border: 1px solid var(--border-soft);
  border-left: 3px solid var(--note);
  border-radius: var(--radius-s);
}
.callout > :last-child { margin-bottom: 0; }
.callout-title {
  font-size: 11.5px; font-weight: 650; text-transform: uppercase; letter-spacing: .06em;
  color: var(--note); margin: 0 0 5px;
}
.callout-warning { border-left-color: var(--warn); }
.callout-warning .callout-title { color: var(--warn); }
.callout-tip { border-left-color: var(--tip); }
.callout-tip .callout-title { color: var(--tip); }

/* содержание страницы */
.toc {
  position: sticky; top: calc(var(--header-h) + 30px);
  max-height: calc(100vh - var(--header-h) - 60px); overflow-y: auto;
  font-size: 13px; padding-left: 18px; border-left: 1px solid var(--border-soft);
}
.toc-title {
  font-size: 11px; font-weight: 650; text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-faint); margin-bottom: 10px;
}
.toc ul { list-style: none; margin: 0; padding: 0; }
.toc li { margin: 0; }
.toc li.lvl3 { padding-left: 13px; }
.toc a {
  display: block; padding: 4px 0; color: var(--text-dim); line-height: 1.45;
}
.toc a:hover { color: var(--text); text-decoration: none; }
.toc a.active { color: var(--accent-text); font-weight: 550; }

/* переход по страницам */
.pager { display: flex; gap: 12px; margin-top: 48px; padding-top: 22px; border-top: 1px solid var(--border-soft); }
.pager-link {
  flex: 1 1 0; min-width: 0;
  display: flex; flex-direction: column; gap: 3px;
  padding: 12px 15px; border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text); background: var(--bg-raised);
}
.pager-link:hover { border-color: var(--accent); text-decoration: none; }
.pager-link small { font-size: 11.5px; color: var(--text-faint); }
.pager-link span { font-size: 14px; font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pager-link.next { text-align: right; }

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

.home { padding: 0 40px 90px; max-width: 1180px; margin: 0 auto; }
.hero { padding: 56px 0 40px; border-bottom: 1px solid var(--border-soft); margin-bottom: 40px; }
.hero h1 { font-size: 40px; line-height: 1.12; letter-spacing: -0.03em; font-weight: 650; margin: 0 0 12px; }
.hero p { font-size: 17px; color: var(--text-dim); margin: 0; max-width: 620px; }
.hero .stats { margin-top: 22px; display: flex; gap: 26px; font-size: 13px; color: var(--text-faint); flex-wrap: wrap; }
.hero .stats b { color: var(--text); font-weight: 600; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.card {
  padding: 18px 20px 16px;
  background: var(--bg-raised);
  border: 1px solid var(--border-soft); border-radius: var(--radius);
}
.card:hover { border-color: var(--border); }
.card h2 { display: flex; align-items: center; gap: 9px; font-size: 16px; font-weight: 600; margin: 0 0 4px; }
.card h2 svg { color: var(--accent); }
.card h2 a { color: var(--text); }
.card .blurb { font-size: 13px; color: var(--text-dim); margin: 0 0 12px; line-height: 1.5; }
.card ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 1px; }
.card li a {
  display: block; padding: 4px 8px; margin: 0 -8px; border-radius: 5px;
  font-size: 13.5px; color: var(--text-dim);
}
.card li a:hover { background: var(--bg-hover); color: var(--text); text-decoration: none; }

/* ------------------------------------------------------------ адаптив */

@media (max-width: 1180px) {
  .main { grid-template-columns: minmax(0, 1fr); padding: 28px 32px 70px; }
  .toc { display: none; }
}

@media (max-width: 900px) {
  #nav-toggle { display: inline-flex; }
  .layout { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed; top: var(--header-h); left: 0; z-index: 35;
    width: min(320px, 86vw); height: calc(100dvh - var(--header-h));
    background: var(--bg); border-right: 1px solid var(--border);
    transform: translateX(-101%); transition: transform .2s ease;
  }
  body[data-nav="open"] .sidebar { transform: none; box-shadow: 0 0 60px rgba(0, 0, 0, .5); }
  body[data-nav="open"]::after {
    content: ""; position: fixed; inset: var(--header-h) 0 0; z-index: 30;
    background: rgba(0, 0, 0, .5);
  }
  .main, .home { padding-left: 20px; padding-right: 20px; }
  .search { width: auto; flex: 1; }
  .search kbd { display: none; }
  .results { width: min(560px, 92vw); right: 0; left: auto; }
  .brand span.name, .brand .ver { display: none; }
  .article h1 { font-size: 25px; }
  .hero { padding: 36px 0 28px; }
  .hero h1 { font-size: 30px; }
  .pager { flex-direction: column; }
}

@media print {
  .header, .sidebar, .toc, .pager, .lightbox { display: none !important; }
  .layout, .main { display: block; }
  body { background: #fff; color: #000; }
  .article { max-width: none; }
}

/* Логотип проекта: подгоняется по высоте строки шапки. */
.logo-img { width: auto; height: 22px; max-width: 150px; object-fit: contain; display: block; }

/* фирменный цвет проекта */
:root, :root[data-theme="dark"] {
  --accent: #4579d3;
  --accent-soft: #4579d326;
  --accent-text: #7fa3e1;
}
:root[data-theme="light"] {
  --accent: #1657c8;
  --accent-soft: #1657c814;
  --accent-text: #1657c8;
}
