/* ==========================================================================
   Hikvision FaceID — документация
   Дизайн-система: светлая, минималистичная, без градиентов и лишнего декора
   ========================================================================== */

/* ---------- Design tokens ---------- */
:root {
  --bg: #f5f6f9;
  --surface: #ffffff;
  --surface-alt: #f8f9fb;
  --border: #e6e8ee;
  --border-strong: #d9dce4;

  --text: #171b23;
  --text-secondary: #4b5262;
  --muted: #8891a0;

  --accent: #0e7c86;
  --accent-dark: #0a5f67;
  --accent-soft: #e9f5f6;
  --accent-contrast: #ffffff;

  --warn-bg: #fff8ea;
  --warn-border: #f3dfa4;
  --warn-text: #7a5b06;
  --caution: #b7791f;

  --danger: #d1373f;
  --danger-soft: #fdeceb;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;

  --shadow-sm: 0 1px 2px rgba(20, 24, 34, 0.05);
  --shadow-md: 0 8px 24px rgba(20, 24, 34, 0.08);
  --shadow-lg: 0 16px 40px rgba(20, 24, 34, 0.12);

  --header-h: 64px;
  --sidebar-w: 280px;
  --content-max: 860px;

  --mark-bg: #ffe58f;
  --mark-text: #171b23;

  font-size: 16px;
}

/* ---------- Reset ---------- */
* {
  box-sizing: border-box;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4 {
  font-weight: 650;
  line-height: 1.25;
  color: var(--text);
}

p {
  margin: 0 0 14px;
}

img {
  max-width: 100%;
}

button, textarea, input {
  font-family: inherit;
}

a {
  color: var(--accent-dark);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

a:focus-visible,
button:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.skip-link {
  position: absolute;
  left: -999px;
  top: auto;
  background: var(--accent);
  color: #fff;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  z-index: 2000;
}

.skip-link:focus {
  left: 12px;
  top: 12px;
}

/* ---------- Header ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 900;
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  max-width: 1320px;
  height: 100%;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  align-items: center;
  gap: 14px;
}

.nav-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  flex: none;
}

.nav-toggle:hover {
  background: var(--surface-alt);
  border-color: var(--border-strong);
}

.nav-toggle svg {
  width: 20px;
  height: 20px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #fff;
  flex: none;
}

.brand-mark svg {
  width: 18px;
  height: 18px;
}

.brand-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.25;
}

.brand-text strong {
  font-size: 15px;
  font-weight: 650;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand-text span {
  font-size: 12.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- Shell / layout ---------- */
.shell {
  max-width: 1320px;
  margin: 0 auto;
  padding: 32px 20px 96px;
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  gap: 36px;
  align-items: start;
}

.backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 18, 26, 0.45);
  z-index: 950;
}

.backdrop.is-visible {
  display: block;
}

/* ---------- Sidebar ---------- */
.sidebar {
  position: sticky;
  top: calc(var(--header-h) + 20px);
  max-height: calc(100vh - var(--header-h) - 40px);
  display: flex;
  flex-direction: column;
  gap: 18px;
  overflow-y: auto;
  padding-bottom: 8px;
}

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

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

/* ---------- Search ---------- */
.search-box {
  position: relative;
}

#searchForm {
  display: flex;
  gap: 8px;
}

.search-field {
  position: relative;
  flex: 1;
  min-width: 0;
}

.search-field svg {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--muted);
  pointer-events: none;
}

#searchInput {
  width: 100%;
  height: 40px;
  padding: 0 34px 0 34px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  font-size: 14px;
  color: var(--text);
}

#searchInput:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.search-clear {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 24px;
  height: 24px;
  border: none;
  background: transparent;
  color: var(--muted);
  border-radius: 6px;
  display: none;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.search-clear.is-visible {
  display: flex;
}

.search-clear:hover {
  background: var(--surface-alt);
  color: var(--text);
}

.search-clear svg {
  width: 14px;
  height: 14px;
}

/* ---------- Shared buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 40px;
  padding: 0 16px;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  font-size: 14px;
  font-weight: 550;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
}

.btn:hover {
  text-decoration: none;
}

.btn:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-contrast);
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-dark);
}

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}

.btn-secondary:hover {
  background: var(--surface-alt);
  border-color: var(--border-strong);
}

.btn-sm {
  height: 34px;
  padding: 0 13px;
  font-size: 13.5px;
}

.search-results {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  max-height: 70vh;
  overflow-y: auto;
  z-index: 970;
  padding: 6px;
}

.search-results[hidden] {
  display: none;
}

.search-results-heading {
  padding: 8px 10px 6px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
}

.search-result {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  color: var(--text);
}

.search-result:hover,
.search-result:focus-visible {
  background: var(--accent-soft);
  text-decoration: none;
}

.search-result-title {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
}

.search-result-snippet {
  font-size: 12.5px;
  color: var(--text-secondary);
  line-height: 1.45;
}

.search-result-snippet mark,
.search-result-title mark {
  background: var(--mark-bg);
  color: var(--mark-text);
  border-radius: 3px;
  padding: 0 2px;
}

.search-empty {
  padding: 22px 14px;
  text-align: center;
  color: var(--text-secondary);
}

.search-empty svg {
  width: 26px;
  height: 26px;
  color: var(--muted);
  margin-bottom: 8px;
}

.search-empty p {
  margin: 0 0 4px;
  font-weight: 600;
  color: var(--text);
}

.search-empty span {
  font-size: 13px;
  color: var(--muted);
}

/* ---------- TOC ---------- */
.toc-nav {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 10px;
}

.toc-group {
  margin-bottom: 4px;
}

.toc-group:last-child {
  margin-bottom: 0;
}

.toc-group + .toc-group {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.toc-link {
  display: block;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 13.5px;
  line-height: 1.35;
}

.toc-link.toc-top {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.toc-link.toc-sub {
  padding-left: 20px;
  font-size: 13px;
}

.toc-link:hover {
  background: var(--surface-alt);
  color: var(--accent-dark);
  text-decoration: none;
}

.toc-link.is-active {
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-weight: 600;
  position: relative;
}

.toc-link.is-active::before {
  content: "";
  position: absolute;
  left: -1px;
  top: 8px;
  bottom: 8px;
  width: 3px;
  border-radius: 3px;
  background: var(--accent);
}

/* ---------- Main content ---------- */
.content {
  min-width: 0;
}

.doc {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px clamp(20px, 4vw, 56px);
  max-width: var(--content-max);
}

.doc-section {
  padding-top: 8px;
  scroll-margin-top: calc(var(--header-h) + 16px);
}

.doc-section + .doc-section {
  margin-top: 56px;
  padding-top: 40px;
  border-top: 1px solid var(--border);
}

.doc-section h2 {
  font-size: 22px;
  margin: 0 0 14px;
}

.doc-section h3 {
  font-size: 17px;
  margin: 28px 0 10px;
}

.doc-section > p,
.doc-section > div > p {
  color: var(--text-secondary);
  line-height: 1.7;
  font-size: 15px;
}

.doc-section ul,
.doc-section ol {
  margin: 0 0 14px;
  padding-left: 22px;
}

.doc-section li[id] {
  list-style: none;
  scroll-margin-top: calc(var(--header-h) + 16px);
}

.doc-section ul.step-list {
  padding-left: 0;
}

ul.step-list > li[id] {
  margin: 28px 0;
  padding: 20px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

ul.step-list > li[id]:first-child {
  margin-top: 20px;
}

.step-eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 10px;
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--accent-dark);
}

.step-eyebrow::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
}

/* section-level flash highlight when navigating via TOC/search */
.section-flash {
  animation: flash-bg 1.1s ease;
  border-radius: var(--radius-md);
}

@keyframes flash-bg {
  0% { background: var(--accent-soft); }
  100% { background: transparent; }
}

.hero {
  margin: 16px 0;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--surface-alt);
}

.hero img {
  display: block;
  width: 100%;
  height: auto;
}

.hero-row {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: flex-start;
}

.hero-row .hero {
  flex: 1 1 260px;
  margin: 0;
}

.hero-row p {
  flex: 1 1 260px;
  margin: 0;
}

.imp {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  color: var(--warn-text);
  padding: 12px 14px;
  border-radius: var(--radius-md);
  margin: 14px 0;
  font-size: 13.5px;
  line-height: 1.55;
}

.imp svg {
  flex: none;
  width: 16px;
  height: 16px;
  margin-top: 2px;
  color: #b8860b;
}

.imp a {
  color: var(--accent-dark);
  font-weight: 600;
}

.doc-footer {
  margin-top: 64px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

/* ---------- To-top button ---------- */
.to-top {
  position: fixed;
  right: 20px;
  bottom: 20px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  cursor: pointer;
  z-index: 800;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 180ms ease, transform 180ms ease, background 150ms ease;
  pointer-events: none;
}

.to-top svg {
  width: 18px;
  height: 18px;
}

.to-top.is-visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.to-top:hover {
  background: var(--surface-alt);
  border-color: var(--border-strong);
}

/* ==========================================================================
   Комментарии
   ========================================================================== */

#comments-container {
  margin: 0 0 8px;
}

#comments-container > p {
  color: var(--text-secondary);
  font-size: 14.5px;
  line-height: 1.6;
}

.comments-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 20px;
}

.no-comments {
  color: var(--muted);
  font-style: italic;
  padding: 26px 10px;
  text-align: center;
  background: var(--surface-alt);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-md);
}

.comment {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
}

.comment-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.comment-avatar {
  flex: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.comment-main {
  flex: 1;
  min-width: 0;
}

.comment-header {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 4px;
}

.comment-author {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.badge-admin {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px 2px 6px;
  border-radius: 999px;
}

.comment-time {
  font-size: 12px;
  color: var(--muted);
}

.comment-text {
  font-size: 14.5px;
  color: var(--text-secondary);
  line-height: 1.6;
  margin: 4px 0 10px;
  word-break: break-word;
}

.comment-actions {
  display: flex;
  align-items: center;
  gap: 16px;
}

.action-btn {
  border: none;
  background: none;
  padding: 0;
  font: inherit;
  font-size: 13px;
  font-weight: 550;
  color: var(--muted);
  cursor: pointer;
}

.action-btn:hover {
  color: var(--accent-dark);
  text-decoration: underline;
}

.children-comments {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 12px 0 0 48px;
  padding-left: 14px;
  border-left: 2px solid var(--border);
}

.children-comments[hidden] {
  display: none;
}

.reply-form-container:not(:empty) {
  margin-top: 10px;
}

#new-comment-section {
  margin-top: 24px;
}

.comment-form {
  margin-top: 14px;
  padding: 16px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

.field {
  margin-bottom: 12px;
}

.field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.field input[type="text"],
.field textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  box-sizing: border-box;
  background: var(--surface);
  color: var(--text);
}

.field textarea {
  resize: vertical;
  min-height: 90px;
}

.field input[type="text"]:focus,
.field textarea:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.field-meta {
  display: flex;
  align-items: center;
  margin-top: 4px;
  min-height: 16px;
}

.field-error {
  font-size: 12px;
  color: var(--danger);
}

.char-counter {
  font-size: 12px;
  color: var(--muted);
  margin-left: auto;
}

.char-counter.is-near-limit {
  color: var(--caution);
}

.form-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.loader {
  font-size: 13px;
  color: var(--muted);
}

/* ---------- Responsive ---------- */
@media (max-width: 980px) {
  .shell {
    grid-template-columns: 1fr;
    gap: 0;
    padding: 20px 16px 80px;
  }

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

  .sidebar {
    position: fixed;
    top: 0;
    left: -320px;
    width: min(320px, 86vw);
    height: 100vh;
    max-height: none;
    background: var(--surface);
    border-right: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
    padding: 16px;
    z-index: 960;
    transition: left 220ms ease;
    overflow-y: auto;
  }

  .sidebar.is-open {
    left: 0;
  }

  .doc {
    padding: 28px 18px;
    border-radius: var(--radius-md);
    max-width: 100%;
  }

  ul.step-list > li[id] {
    padding: 16px;
  }

  .children-comments {
    margin-left: 28px;
  }
}

@media (max-width: 560px) {
  .brand-text span {
    display: none;
  }

  #searchForm {
    flex-direction: column;
  }

  .btn-search {
    width: 100%;
  }

  .doc-section h2 {
    font-size: 20px;
  }

  .to-top {
    right: 14px;
    bottom: 14px;
  }

  .comment-row {
    gap: 10px;
  }

  .children-comments {
    margin-left: 16px;
    padding-left: 10px;
  }
}
