/*
 * Оформление docs.wacis.ru.
 *
 * Тёмная и светлая темы задаются переменными: страницу читают и днём с
 * телефона, и ночью в терминале рядом с логами.
 */

:root {
    --bg:        #ffffff;
    --bg-soft:   #f6f7f9;
    --bg-code:   #f4f5f7;
    --line:      #e3e6ea;
    --text:      #1c2024;
    --muted:     #6b7280;
    --link:      #2c5fd6;
    --link-h:    #1a3f9e;
    --accent:    #6b4be8;

    --warn-bg:   #fff8e6;  --warn-line:   #e6b800;
    --danger-bg: #fdeeee;  --danger-line: #d64545;
    --tip-bg:    #eef7f0;  --tip-line:    #3d9160;
    --note-bg:   #eef2fb;  --note-line:   #4a6fc4;
    --why-bg:    #f4f0fd;  --why-line:    #6b4be8;

    --head-h: 56px;
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg:      #16181d;
        --bg-soft: #1c1f26;
        --bg-code: #12141a;
        --line:    #2b303a;
        --text:    #dfe3ea;
        --muted:   #9aa3b2;
        --link:    #7ba7ff;
        --link-h:  #a3c2ff;

        --warn-bg:   #2a2412;  --warn-line:   #b58a00;
        --danger-bg: #2c1a1a;  --danger-line: #c25050;
        --tip-bg:    #16241c;  --tip-line:    #4a9e6d;
        --note-bg:   #171d2c;  --note-line:   #5b7fd0;
        --why-bg:    #1f1a2e;  --why-line:    #8b6ef0;
    }
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; scroll-padding-top: calc(var(--head-h) + 16px); }

body {
    margin: 0;
    font-family: var(--font);
    font-size: 16px;
    line-height: 1.65;
    color: var(--text);
    background: var(--bg);
    -webkit-text-size-adjust: 100%;
}

a { color: var(--link); text-decoration: none; }
a:hover { color: var(--link-h); text-decoration: underline; }

.skip {
    position: absolute; left: -9999px;
    background: var(--accent); color: #fff; padding: 10px 16px; z-index: 100;
}
.skip:focus { left: 8px; top: 8px; }

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

.head {
    position: sticky; top: 0; z-index: 50;
    height: var(--head-h);
    background: var(--bg);
    border-bottom: 1px solid var(--line);
}
.head__in {
    max-width: 1400px; margin: 0 auto; padding: 0 20px;
    height: var(--head-h);
    display: flex; align-items: center; gap: 16px;
}
.logo {
    font-weight: 700; font-size: 19px; color: var(--text); letter-spacing: -.02em;
    white-space: nowrap;
}
.logo:hover { text-decoration: none; }
.logo span { color: var(--accent); margin-left: 3px; font-weight: 500; }

.burger {
    display: none;
    background: none; border: 1px solid var(--line); border-radius: 6px;
    color: var(--text); font-size: 17px; padding: 4px 10px; cursor: pointer;
}

.search { position: relative; flex: 1; max-width: 460px; margin-left: auto; }
.search input {
    width: 100%; padding: 7px 12px;
    font: inherit; font-size: 14px;
    color: var(--text); background: var(--bg-soft);
    border: 1px solid var(--line); border-radius: 8px;
}
.search input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.search__out {
    position: absolute; top: calc(100% + 6px); left: 0; right: 0;
    max-height: 70vh; overflow-y: auto;
    background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
    box-shadow: 0 8px 32px rgba(0,0,0,.14);
    padding: 6px;
}
.search__out a {
    display: block; padding: 8px 10px; border-radius: 7px; color: var(--text);
}
.search__out a:hover, .search__out a.is-active { background: var(--bg-soft); text-decoration: none; }
.search__out .r-t { font-weight: 600; font-size: 14px; }
.search__out .r-s { font-size: 12px; color: var(--muted); }
.search__out .r-b { font-size: 13px; color: var(--muted); margin-top: 2px; }
.search__out mark { background: rgba(107,75,232,.22); color: inherit; border-radius: 2px; }
.search__out .empty { padding: 10px; color: var(--muted); font-size: 14px; }

.head__link { font-size: 14px; color: var(--muted); white-space: nowrap; }

/* ------------------------------------------------------------ сетка */

.shell {
    max-width: 1400px; margin: 0 auto; padding: 0 20px;
    display: grid;
    grid-template-columns: 250px minmax(0, 1fr) 220px;
    gap: 36px;
    align-items: start;
}

.side {
    position: sticky; top: var(--head-h);
    max-height: calc(100vh - var(--head-h));
    overflow-y: auto;
    padding: 24px 0 40px;
}

.main { min-width: 0; padding: 28px 0 60px; }

.toc {
    position: sticky; top: var(--head-h);
    max-height: calc(100vh - var(--head-h));
    overflow-y: auto;
    padding: 32px 0 40px;
    font-size: 13.5px;
}

/* ---------------------------------------------------------- разделы */

.nav__section { margin-bottom: 4px; }
.nav__title {
    display: block; padding: 6px 10px; border-radius: 7px;
    color: var(--text); font-weight: 600; font-size: 14.5px;
}
.nav__title:hover { background: var(--bg-soft); text-decoration: none; }
.nav__title.is-current { background: var(--bg-soft); color: var(--accent); }

.nav__pages { list-style: none; margin: 2px 0 10px; padding: 0 0 0 10px; display: none; }
.nav__section.is-open .nav__pages { display: block; }
.nav__pages a {
    display: block; padding: 5px 10px; border-radius: 6px;
    color: var(--muted); font-size: 14px;
    border-left: 2px solid var(--line); margin-left: 0;
}
.nav__pages a:hover { color: var(--text); text-decoration: none; }
.nav__pages a.is-current {
    color: var(--accent); border-left-color: var(--accent); font-weight: 600;
    background: var(--bg-soft);
}

/* ------------------------------------------------------ оглавление */

.toc__title {
    font-size: 12px; text-transform: uppercase; letter-spacing: .06em;
    color: var(--muted); margin-bottom: 8px; font-weight: 600;
}
.toc ul { list-style: none; margin: 0; padding: 0; }
.toc li { margin: 2px 0; }
.toc a {
    display: block; padding: 3px 0 3px 10px; color: var(--muted);
    border-left: 2px solid var(--line); line-height: 1.4;
}
.toc a:hover { color: var(--text); text-decoration: none; border-left-color: var(--muted); }
.toc a.is-active { color: var(--accent); border-left-color: var(--accent); }
.toc__l3 a { padding-left: 20px; font-size: 13px; }

/* ------------------------------------------------------ содержимое */

.crumb {
    font-size: 13px; color: var(--muted); text-transform: uppercase;
    letter-spacing: .05em; margin-bottom: 6px; font-weight: 600;
}

.doc { max-width: 860px; }

.doc h1 {
    font-size: 33px; line-height: 1.2; margin: 0 0 20px;
    letter-spacing: -.02em; font-weight: 700;
}
.doc h2 {
    font-size: 24px; line-height: 1.3; margin: 44px 0 14px;
    padding-top: 14px; border-top: 1px solid var(--line);
    letter-spacing: -.01em; font-weight: 650;
}
.doc h3 { font-size: 19px; margin: 30px 0 10px; font-weight: 650; }
.doc h4 { font-size: 16px; margin: 24px 0 8px; font-weight: 650; }

.doc h1, .doc h2, .doc h3, .doc h4 { position: relative; scroll-margin-top: 80px; }

.anchor {
    position: absolute; left: -22px; top: 0;
    color: var(--line); font-weight: 400; opacity: 0;
    text-decoration: none; padding-right: 6px;
}
h1:hover .anchor, h2:hover .anchor, h3:hover .anchor, h4:hover .anchor { opacity: 1; }
.anchor:hover { color: var(--accent); text-decoration: none; }

.doc p { margin: 0 0 14px; }
.doc ul, .doc ol { margin: 0 0 16px; padding-left: 24px; }
.doc li { margin: 5px 0; }
.doc li > ul, .doc li > ol { margin: 6px 0 4px; }

.doc img { max-width: 100%; height: auto; border-radius: 8px; display: block; }

figure {
    margin: 22px 0;
    border: 1px solid var(--line); border-radius: 10px; overflow: hidden;
    background: var(--bg-soft);
}
figure img { border-radius: 0; }
figcaption {
    padding: 9px 14px; font-size: 13.5px; color: var(--muted);
    border-top: 1px solid var(--line);
}

/* Обещанный, но ещё не снятый скриншот. Пустое место молчит, а такая
   рамка честно говорит, чего здесь не хватает. */
.shot-todo {
    border: 1px dashed var(--line); border-radius: 10px;
    padding: 22px; margin: 22px 0;
    background: var(--bg-soft); color: var(--muted); font-size: 14px;
}
.shot-todo b { color: var(--text); }

code {
    font-family: var(--mono); font-size: .875em;
    background: var(--bg-code); border: 1px solid var(--line);
    border-radius: 5px; padding: 1px 5px;
    word-break: break-word;
}

.code {
    margin: 0 0 18px; position: relative;
    background: var(--bg-code); border: 1px solid var(--line); border-radius: 9px;
}
.code pre { margin: 0; padding: 14px 16px; overflow-x: auto; }
.code code {
    background: none; border: 0; padding: 0; font-size: 13.5px; line-height: 1.55;
    white-space: pre; display: block;
}
.code[data-lang]::before {
    content: attr(data-lang);
    position: absolute; top: 0; right: 0;
    font-family: var(--mono); font-size: 11px; color: var(--muted);
    padding: 4px 10px; text-transform: uppercase; letter-spacing: .05em;
}
.copy {
    position: absolute; top: 6px; right: 6px;
    font: inherit; font-size: 12px; padding: 3px 9px;
    color: var(--muted); background: var(--bg); cursor: pointer;
    border: 1px solid var(--line); border-radius: 6px;
    opacity: 0; transition: opacity .12s;
}
.code:hover .copy, .copy:focus { opacity: 1; }
.code[data-lang]:hover::before { display: none; }

blockquote {
    margin: 0 0 18px; padding: 2px 0 2px 16px;
    border-left: 3px solid var(--line); color: var(--muted);
}
blockquote p:last-child { margin-bottom: 0; }

kbd {
    font-family: var(--mono); font-size: 12.5px;
    background: var(--bg-soft); border: 1px solid var(--line);
    border-bottom-width: 2px; border-radius: 5px; padding: 1px 6px;
    white-space: nowrap;
}

hr { border: 0; border-top: 1px solid var(--line); margin: 34px 0; }

.table-wrap { overflow-x: auto; margin: 0 0 20px; }
table { border-collapse: collapse; width: 100%; font-size: 14.5px; }
th, td { text-align: left; padding: 9px 12px; border: 1px solid var(--line); vertical-align: top; }
th { background: var(--bg-soft); font-weight: 650; }
td code, th code { white-space: nowrap; }

/* -------------------------------------------------------- врезки */

.callout {
    margin: 0 0 20px; padding: 14px 16px;
    border-left: 3px solid; border-radius: 0 9px 9px 0;
    font-size: 15px;
}
.callout__title { font-weight: 650; margin-bottom: 6px; font-size: 14px; }
.callout p:last-child, .callout ul:last-child, .callout ol:last-child { margin-bottom: 0; }
.callout .code:last-child { margin-bottom: 0; }

.callout--warn   { background: var(--warn-bg);   border-color: var(--warn-line); }
.callout--danger { background: var(--danger-bg); border-color: var(--danger-line); }
.callout--tip    { background: var(--tip-bg);    border-color: var(--tip-line); }
.callout--note   { background: var(--note-bg);   border-color: var(--note-line); }
.callout--why    { background: var(--why-bg);    border-color: var(--why-line); }

.callout--warn   .callout__title { color: var(--warn-line); }
.callout--danger .callout__title { color: var(--danger-line); }
.callout--tip    .callout__title { color: var(--tip-line); }
.callout--note   .callout__title { color: var(--note-line); }
.callout--why    .callout__title { color: var(--why-line); }

/* --------------------------------------------------- листалка, низ */

.pager {
    display: flex; justify-content: space-between; gap: 16px;
    margin-top: 48px; padding-top: 22px; border-top: 1px solid var(--line);
}
.pager a {
    flex: 0 1 48%; padding: 12px 16px;
    border: 1px solid var(--line); border-radius: 10px;
    color: var(--text); font-weight: 600; font-size: 15px;
}
.pager a:hover { border-color: var(--accent); text-decoration: none; }
.pager span { display: block; font-size: 12px; color: var(--muted); font-weight: 400; }
.pager__next { text-align: right; margin-left: auto; }

.foot { border-top: 1px solid var(--line); margin-top: 20px; }
.foot__in {
    max-width: 1400px; margin: 0 auto; padding: 20px;
    display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap;
    font-size: 13.5px; color: var(--muted);
}

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

/* ------------------------------------------------------- карточки */

.cards {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 14px; margin: 24px 0;
}
.card {
    display: block; padding: 16px 18px;
    border: 1px solid var(--line); border-radius: 11px;
    color: var(--text);
}
.card:hover { border-color: var(--accent); text-decoration: none; }
.card b { display: block; font-size: 16px; margin-bottom: 4px; }
.card span { font-size: 14px; color: var(--muted); line-height: 1.5; }

/* -------------------------------------------------------- телефон */

@media (max-width: 1180px) {
    .shell { grid-template-columns: 230px minmax(0, 1fr); }
    .toc { display: none; }
}

@media (max-width: 860px) {
    .shell { grid-template-columns: 1fr; gap: 0; }
    .burger { display: block; order: -1; }
    .head__link { display: none; }

    .side {
        display: none;
        position: static; max-height: none; overflow: visible;
        padding: 14px 0; border-bottom: 1px solid var(--line);
    }
    .side.is-open { display: block; }
    .nav__pages { display: block; }

    .doc h1 { font-size: 27px; }
    .doc h2 { font-size: 21px; }
    .pager { flex-direction: column; }
    .pager a { flex: none; }
    .pager__next { text-align: left; }
}

@media print {
    .head, .side, .toc, .pager, .foot, .skip { display: none; }
    .shell { display: block; }
    body { font-size: 12pt; }
}

/* =========================================================================
   ВКЛАДКИ С КОДОМ

   Разметка приходит простая: несколько .code подряд внутри .tabs.
   Кнопки дорисовывает скрипт — без него видны все блоки сразу, один
   под другим. Это и есть запасной вид: длиннее, но ничего не потеряно.
   ========================================================================= */
.tabs { margin: 0 0 18px; }
.tabs .code { margin: 0; }

/* Пока скрипт не отработал, блоки идут как обычно — с отступом между
   ними. Признак ставит сам скрипт, и только тогда включается вид с
   вкладками: иначе при выключенном JS блоки слиплись бы в один. */
.tabs[data-ready] .code { border-top-left-radius: 0; border-top-right-radius: 0; }
.tabs:not([data-ready]) .code + .code { margin-top: 10px; }

.tabs__bar {
    display: flex; flex-wrap: wrap; gap: 2px;
    border: 1px solid var(--line); border-bottom: 0;
    border-radius: 9px 9px 0 0;
    background: var(--bg-soft); padding: 4px 4px 0;
}
.tabs__btn {
    font: inherit; font-size: 12.5px; line-height: 1;
    padding: 8px 12px; cursor: pointer;
    color: var(--muted); background: none;
    border: 0; border-radius: 6px 6px 0 0;
}
.tabs__btn:hover { color: var(--text); }
.tabs__btn[aria-selected="true"] {
    color: var(--text); background: var(--bg-code);
    box-shadow: inset 0 -1px 0 var(--bg-code);
}
.tabs__btn:focus-visible { outline: 2px solid var(--link); outline-offset: -2px; }

/* У блока внутри вкладок метка языка не нужна: её роль играет кнопка */
.tabs[data-ready] .code[data-lang]::before { content: none; }

/* =========================================================================
   ПЕСОЧНИЦА API

   Поля, кнопка, ответ и вкладки с кодом. Всё считается в браузере:
   серверной части у этой страницы нет вовсе.
   ========================================================================= */
.pg { margin: 0 0 26px; }
.pg__form {
    border: 1px solid var(--line); border-radius: 10px;
    background: var(--bg-soft); padding: 16px;
}
.pg__row { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 12px; }

/* Скрытое должно быть скрыто.
   display у .pg__f и .pg__row задан явно, а он сильнее встроенного
   правила для [hidden] — без этой строки поля «Запись №» и «Тело
   запроса» оставались на виду при любой операции, хотя скрипт честно
   выставлял им признак. */
.pg [hidden] { display: none; }
.pg__f { display: flex; flex-direction: column; gap: 5px; flex: 1 1 150px; min-width: 0; }
.pg__f--wide { flex: 1 1 280px; }
.pg__f--num  { flex: 0 1 130px; }
.pg__f > span { font-size: 12.5px; color: var(--muted); }

.pg__f input[type="text"], .pg__f input[type="url"], .pg__f input[type="password"],
.pg__f input[type="number"], .pg__f select, .pg__f textarea {
    font: inherit; font-size: 14px; color: var(--text);
    background: var(--bg); border: 1px solid var(--line); border-radius: 7px;
    padding: 8px 10px; width: 100%; min-width: 0;
}
.pg__f textarea { font-family: var(--mono); font-size: 13px; resize: vertical; }
.pg__f input:focus, .pg__f select:focus, .pg__f textarea:focus {
    outline: 2px solid var(--link); outline-offset: -1px; border-color: transparent;
}

.pg__f--check { flex-direction: row; align-items: center; gap: 8px; flex: 1 1 200px; }
.pg__f--check input { width: auto; }
.pg__f--check span { font-size: 13px; color: var(--text); }

.pg__f--body { margin-bottom: 12px; }

.pg__go { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.pg__run {
    font: inherit; font-size: 14px; font-weight: 600; cursor: pointer;
    color: #fff; background: var(--link); border: 0; border-radius: 7px;
    padding: 9px 20px;
}
.pg__run:hover { background: var(--link-h); }
.pg__run:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }

/* Адрес запроса рядом с кнопкой: видно, что уйдёт, до нажатия */
.pg__url {
    font-family: var(--mono); font-size: 12px; color: var(--muted);
    overflow-wrap: anywhere; min-width: 0;
}

.pg__out {
    margin-top: 14px; border: 1px solid var(--line); border-radius: 9px;
    background: var(--bg-code); overflow: hidden;
}
.pg__out-h {
    font-size: 13px; font-weight: 600; padding: 9px 14px;
    border-bottom: 1px solid var(--line);
}
.pg__out pre {
    margin: 0; padding: 12px 14px; overflow-x: auto;
    font-family: var(--mono); font-size: 13px; line-height: 1.5;
    max-height: 380px; overflow-y: auto;
}
.pg__out--ok  .pg__out-h { background: var(--tip-bg);    color: var(--tip-line); }
.pg__out--bad .pg__out-h { background: var(--danger-bg); color: var(--danger-line); }
.pg__out--wait .pg__out-h { color: var(--muted); }

.pg__h { font-size: 17px; margin: 22px 0 10px; }

@media (max-width: 620px) {
    .pg__f--num { flex: 1 1 100px; }
}
