/* Page glue on top of tokens.css + components.css */
[id] { scroll-margin-top: calc(var(--header-h) + var(--space-4)); }
[hidden] { display: none !important; }

/* Theme menu anchored to its trigger */
.bp-menu-anchor { position: relative; display: inline-flex; }
.bp-menu-anchor > .bp-menu { position: absolute; top: calc(100% + var(--space-2)); right: 0; }

/* Mobile menu sheet + scrim */
.bp-sheet .bp-mobilenav { height: 100%; }
@media (min-width: 1024px) { .bp-sheet, [data-scrim] { display: none !important; } }

/* Contacts with no link list: one column */
.bp-contacts--solo { grid-template-columns: minmax(0, 1fr) !important; }

/* Error pages fill the viewport under the header */
.bp-errpage { min-height: calc(100dvh - var(--header-h)); display: grid; align-items: center; }

/* Spec block status line uses the marker node */
.bp-spec__status { display: inline-flex; align-items: center; gap: var(--space-2); }

/* Session slot in the header (skeleton -> «Войти» or the user menu) */
.bp-authslot { display: inline-flex; align-items: center; min-width: 24px; }
.bp-authslot--mobile { display: block; }
.bp-authslot--mobile:empty { display: none; }
.bp-authslot form, .bp-menu form { display: contents; }

/* /app sidebar: close button and sheet mode below 768px */
.bp-side__close { display: none; margin-left: auto; }
@media (max-width: 767px) {
  .bp-app[data-side="open"] .bp-side { display: flex; position: fixed; inset: 0 auto 0 0; width: min(300px, 86vw); z-index: var(--z-modal); box-shadow: var(--shadow-lg); }
  .bp-app[data-side="open"] .bp-side__close { display: inline-flex; }
  .bp-side__foot { display: none; }
  .bp-usertrigger__name, .bp-usertrigger > .bp-icon { display: none; }
}
#user-menu { min-width: 280px; max-width: 320px; }
.bp-auth__title:focus { outline: none; }

/* Dashboard (cms.js): panels, overview cards, editor grid */
.cms-count { display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 var(--space-1); border-radius: var(--radius-full); background: var(--accent); color: var(--text-on-accent); font: 600 var(--fs-mono-sm)/1 var(--font-mono); }
.cms-dot { display: inline-block; width: 6px; height: 6px; margin-left: var(--space-1); border-radius: var(--radius-full); background: var(--warning); vertical-align: middle; }
.cms-panel { border: var(--border-width) solid var(--border); border-radius: var(--radius-md); background: var(--surface); padding: var(--space-5); min-width: 0; }
.cms-panel > * + * { margin-top: var(--space-3); }
.cms-grid { display: grid; gap: var(--space-4); grid-template-columns: minmax(0, 1fr); margin-block: var(--space-6); }
.cms-cards { display: grid; gap: var(--space-4); grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); list-style: none; padding: 0; margin: 0; }
.cms-card { border: var(--border-width) solid var(--border); border-radius: var(--radius-md); background: var(--surface); padding: var(--space-4); }
.cms-card__num { font: 600 var(--fs-metric)/1.1 var(--font-mono); margin: var(--space-2) 0; }
.cms-changes { list-style: none; padding: 0; margin: 0; display: grid; gap: var(--space-2); }
.cms-changes li { display: flex; gap: var(--space-2); align-items: baseline; flex-wrap: wrap; }
.cms-editor { display: grid; gap: var(--space-4); grid-template-columns: minmax(0, 1fr); align-items: start; }
.cms-pane > * + * { margin-top: var(--space-4); }
.cms-props > * + * { margin-top: var(--space-4); }
@media (min-width: 768px) { .cms-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 1024px) { .cms-editor { grid-template-columns: minmax(0, 1fr) 300px; } }
@media (max-width: 767px) { .cms-hide-sm { display: none; } }
.bp-segmented [data-lang] { white-space: nowrap; }
.bp-dialog .cms-changes { margin-block: var(--space-3) var(--space-4); }
.bp-top .bp-crumbs { min-width: 0; overflow: hidden; }
.bp-top .bp-crumbs ol { flex-wrap: nowrap; }
@media (max-width: 767px) {
  .bp-top .bp-crumbs li:not(:last-child) { display: none; }
  .bp-top .bp-crumbs li:last-child::before { display: none; }
}
.cms-select { appearance: auto; -webkit-appearance: auto; padding-right: var(--space-2); }
.cms-linklist { list-style: none; padding: 0; margin: 0 0 var(--space-2); display: grid; gap: var(--space-2); }
.cms-link { display: grid; grid-template-columns: 1fr auto; gap: var(--space-1); padding: var(--space-2); border: var(--border-width) dashed var(--border); border-radius: var(--radius-sm); }
.cms-link > [data-l="kind"] { grid-column: 1; }
.cms-link > [data-link-remove] { grid-column: 2; grid-row: 1; }
.cms-link > [data-l="url"], .cms-link > [data-l="label"] { grid-column: 1 / -1; }
.cms-editor textarea[id$="body_md"] { font: 400 13px/1.6 var(--font-mono); padding-block: var(--space-2); }

/* Library images on the public site */
.bp-figure { margin-block: var(--space-6); }
.bp-figure img, .bp-gallery img { display: block; width: 100%; height: auto; border: 1px solid var(--border-subtle); border-radius: var(--radius-sm); background: var(--surface-sunken); }
.bp-case__step .bp-figure { margin-block: var(--space-1); }
.bp-pgallery { margin-top: var(--space-8); }
.bp-pgallery > h2 { margin-bottom: var(--space-3); }
.bp-gallery { list-style: none; padding: 0; margin: 0; }
.bp-gallery a { display: block; border-radius: var(--radius-sm); overflow: hidden; aspect-ratio: 4 / 3; cursor: zoom-in; }
.bp-gallery > :first-child a { aspect-ratio: 16 / 9; }
.bp-gallery a img { height: 100%; object-fit: cover; border-radius: 0; }

/* Dashboard media library */
.cms-media { list-style: none; padding: 0; margin: var(--space-4) 0 0; display: grid; gap: var(--space-3); grid-template-columns: repeat(auto-fill, minmax(176px, 1fr)); }
.cms-media > li > a, .cms-pick { display: grid; gap: var(--space-1); align-content: start; width: 100%; padding: var(--space-2); border: var(--border-width) solid var(--border); border-radius: var(--radius-md); background: var(--surface); color: inherit; text-decoration: none; text-align: left; font: inherit; cursor: pointer; }
.cms-media > li > a:hover, .cms-pick:hover { border-color: var(--border-strong); }
.cms-thumb { display: grid; place-items: center; width: 100%; aspect-ratio: 4 / 3; border-radius: var(--radius-xs); overflow: hidden; background: var(--surface-sunken); }
.cms-thumb img { width: 100%; height: 100%; object-fit: contain; }
.cms-thumb__doc { display: grid; justify-items: center; gap: var(--space-1); color: var(--text-subtle); }
.cms-thumb__doc svg { width: 28px; height: 28px; }
.cms-media__name { font: 400 13px/1.4 var(--font-mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cms-media__badges { display: flex; flex-wrap: wrap; gap: var(--space-1); align-items: center; }
.cms-media__filters { justify-content: space-between; flex-wrap: wrap; margin-top: var(--space-6); }
.cms-media__search { max-width: 260px; }
.cms-media--pick { grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); max-height: 60vh; overflow-y: auto; }
.cms-picker { --dialog-w: 760px; }
.cms-uploads { list-style: none; padding: 0; margin: var(--space-3) 0 0; display: grid; gap: var(--space-2); }
.cms-uploads:empty { display: none; }
.bp-upload[data-state="error"] .bp-mono-sm { color: var(--danger); }
.bp-upload[data-state="done"] .cms-bar span { background: var(--success); }
.bp-upload__thumb img { width: 100%; height: 100%; object-fit: cover; }
.cms-bar { height: 4px; margin: 6px 0; border-radius: var(--radius-full); background: var(--surface-sunken); overflow: hidden; }
.cms-bar span { display: block; height: 100%; width: 0; background: var(--accent); transition: width var(--duration-fast) linear; }
.cms-media__big { display: block; border: 1px solid var(--border-subtle); border-radius: var(--radius-sm); overflow: hidden; background: var(--surface-sunken); }
.cms-media__big img { display: block; width: 100%; height: auto; max-height: 60vh; object-fit: contain; }
.cms-snippet { flex-wrap: nowrap; }
.cms-snippet code { flex: 1; min-width: 0; overflow-x: auto; white-space: nowrap; padding: 6px var(--space-2); background: var(--surface-sunken); border-radius: var(--radius-xs); font: 400 13px/1.5 var(--font-mono); }
.cms-dl { display: grid; grid-template-columns: auto 1fr; gap: var(--space-1) var(--space-3); margin: 0; font-size: 14px; }
.cms-dl dt { color: var(--text-subtle); }
.cms-dl dd { margin: 0; overflow-wrap: anywhere; }
.cms-mdbar { display: flex; justify-content: flex-end; margin-bottom: var(--space-1); }
.cms-mone { display: grid; gap: var(--space-2); }
.cms-mone .cms-thumb:empty { display: none; }
.cms-thumbs { list-style: none; padding: 0; margin: 0 0 var(--space-2); display: grid; gap: var(--space-2); grid-template-columns: repeat(3, minmax(0, 1fr)); }
.cms-thumbs:empty { display: none; }
.cms-thumbs li { position: relative; }
.cms-thumbs [data-thumb-remove] { position: absolute; top: 2px; right: 2px; background: var(--surface); }

/* Diagram editor: source and live preview; the picker of diagrams for texts */
.cms-diagram { display: grid; gap: var(--space-5); grid-template-columns: minmax(0, 1fr); align-items: start; }
.cms-diagram__src > * + *, .cms-diagram__out > * + * { margin-top: var(--space-3); }
.cms-editor textarea#f-text { font: 400 13px/1.6 var(--font-mono); padding-block: var(--space-2); white-space: pre; overflow-x: auto; tab-size: 2; }
.cms-diagram__help dl { display: grid; gap: var(--space-1) var(--space-3); margin: var(--space-2) 0 0; font-size: var(--fs-body-sm); }
.cms-diagram__help dt code { font: 400 12px/1.5 var(--font-mono); color: var(--text); }
.cms-diagram__help dd { margin: 0 0 var(--space-2); color: var(--text-muted); }
.cms-diagram__help summary { cursor: pointer; }
.cms-diagram__out .bp-diagram { margin: 0; }
.cms-diagram__out .bp-diagram__svg { min-width: 560px; }
.cms-diagram__stale { opacity: 0.45; transition: opacity var(--duration-base) var(--ease-standard); }
.cms-diagram__meta { display: grid; gap: 0 var(--space-4); grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); margin-top: var(--space-5); padding-top: var(--space-5); border-top: var(--border-width) solid var(--border-subtle); }
.cms-dpick { display: grid; gap: var(--space-2); list-style: none; margin: 0 0 var(--space-4); padding: 0; }
.cms-pick--line .cms-media__name { font: 500 15px/1.4 var(--font-sans); }
.cms-pick--line code { overflow-wrap: anywhere; }
@media (min-width: 1280px) {
  .cms-editor[data-kind="diagrams"] { grid-template-columns: minmax(0, 1fr); }
  .cms-editor[data-kind="diagrams"] .cms-diagram { grid-template-columns: minmax(340px, 1fr) minmax(0, 2fr); }
  .cms-editor[data-kind="diagrams"] .cms-props { display: grid; gap: var(--space-4) var(--space-6); grid-template-columns: repeat(3, minmax(0, 1fr)); align-items: start; }
  .cms-editor[data-kind="diagrams"] .cms-props > * { margin-top: 0; }
  .cms-editor[data-kind="diagrams"] .cms-props > .bp-mono-label { grid-column: 1 / -1; }
  .cms-diagram__out { position: sticky; top: calc(var(--header-h, 56px) + var(--space-4)); }
}
}
