/* DynamicDoc - тема «Наборный справочник».
   Светлая тема по умолчанию, тёмная через [data-theme=dark].
   Шрифты: PT Serif (текст статей), PT Sans (интерфейс), PT Mono (код и числа).
   Движение: 120-180мс ease-out, только смена состояний. */

:root {
  --bg: #F5F5F3;
  --panel: #FFFFFF;
  --panel-2: #EFEFEB;
  --border: #DEDEDA;
  --border-soft: #E8E8E4;
  --text: #26282A;
  --text-soft: #33363A;
  --muted: #6B6E70;
  --faint: #8A8C8A;
  --accent: #3B6EA5;
  --accent-hover: #2C5480;
  --accent-soft: #B7C8DA;
  --accent-bg: rgba(59, 110, 165, .10);
  --add: #4A7A44;
  --add-bg: rgba(74, 122, 68, .12);
  --del: #A4524A;
  --del-bg: rgba(164, 82, 74, .11);
  --code-text: #35507A;
  --code-bg: #EFF1F3;
  --shadow: 0 4px 14px rgba(0, 0, 0, .12);
  /* совместимость со старыми именами (инлайн-стили в app.js) */
  --red: var(--del);
  --green: var(--add);
  --bg-elev: var(--panel);
  --bg-elev2: var(--panel-2);
  --text-dim: var(--muted);
  /* цвета типов узлов графа */
  --area: #3B6EA5;
  --feature: #6B6E70;
  --integration: #7A5A88;
  --root: #A5691F;
  --term: #4A7A44;
  --external: #3E8E8E;
}
:root[data-theme="dark"] {
  --bg: #1E1F21;
  --panel: #242528;
  --panel-2: #2B2D31;
  --border: #3A3C40;
  --border-soft: #2E2F32;
  --text: #E4E4E2;
  --text-soft: #D6D6D2;
  --muted: #9EA0A3;
  --faint: #6C6E72;
  --accent: #6E9ECF;
  --accent-hover: #8FB4D9;
  --accent-soft: #3E5266;
  --accent-bg: rgba(110, 158, 207, .13);
  --add: #8FBF8A;
  --add-bg: rgba(143, 191, 138, .12);
  --del: #C98A83;
  --del-bg: rgba(201, 138, 131, .12);
  --code-text: #AFC6DC;
  --code-bg: #1A1B1D;
  --shadow: 0 4px 14px rgba(0, 0, 0, .45);
  --area: #6E9ECF;
  --feature: #9EA0A3;
  --integration: #A98FBC;
  --root: #D19C5E;
  --term: #8FBF8A;
  --external: #5FB3B3;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font: 13.5px/1.5 "PT Sans", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; }
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; padding: 0; }
input, textarea {
  font: 13px/1.4 "PT Sans", sans-serif;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 7px 10px;
  outline: none;
  transition: border-color 140ms ease-out;
}
input:focus, textarea:focus { border-color: var(--accent); }
input:disabled, textarea:disabled { color: var(--faint); background: var(--panel-2); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: "PT Mono", monospace; }

/* Рубрикатор разделов: 10.5px, разрядка */
.rubric {
  font: 700 10.5px "PT Sans", sans-serif;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--faint);
}

/* --- Кнопки --- */
.btn-primary {
  height: 34px;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  border-radius: 3px;
  color: #fff;
  font: 700 13px "PT Sans", sans-serif;
  transition: background 140ms ease-out;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { background: var(--panel-2); color: var(--faint); cursor: default; }
.btn-second {
  height: 30px;
  padding: 0 10px;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--accent-soft);
  border-radius: 3px;
  color: var(--accent);
  font: 13px "PT Sans", sans-serif;
  transition: border-color 140ms ease-out, color 140ms ease-out;
}
.btn-second:hover { border-color: var(--accent); }
.mini-btn {
  font-size: 12.5px;
  color: var(--accent);
  transition: color 120ms ease-out;
}
.mini-btn:hover { text-decoration: underline; }
.mini-btn.ok { color: var(--add); }
.mini-btn.danger { color: var(--del); }
.mini-btn.quiet { color: var(--muted); }
.mini-btn.quiet:hover { color: var(--text); text-decoration: none; }
.icon-btn {
  width: 28px; height: 28px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 3px;
  color: var(--muted);
  font-size: 16px;
  transition: color 120ms ease-out, background 120ms ease-out;
}
.icon-btn:hover { color: var(--text); background: var(--panel-2); }
.text-btn {
  color: var(--muted);
  font-size: 12.5px;
  transition: color 120ms ease-out;
}
.text-btn:hover { color: var(--text); }

/* --- Экран входа --- */
.login-screen {
  height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
}
.login-card { width: 280px; display: flex; flex-direction: column; }
.login-brand {
  font: 700 20px "PT Serif", serif;
  color: var(--text);
  margin-bottom: 4px;
}
.login-brand span { color: var(--accent); }
.login-sub { font-size: 12.5px; color: var(--faint); margin: 0 0 32px; }
.field-label {
  font: 700 11px "PT Sans", sans-serif;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--faint);
  margin-bottom: 6px;
}
.login-card input {
  height: 36px;
  font-family: "PT Mono", monospace;
  margin-bottom: 16px;
}
.login-card .btn-primary { height: 38px; margin-top: 8px; }
.login-error { color: var(--del); font-size: 12.5px; min-height: 18px; margin-top: 10px; }
.login-foot { margin-top: 20px; font: 11.5px "PT Mono", monospace; color: var(--faint); }

/* --- Каркас --- */
.app { height: 100vh; display: flex; flex-direction: column; }
.topbar {
  height: 46px;
  flex: none;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  color: var(--muted);
  font-size: 12.5px;
}
.topbar-spacer { flex: 1; }
.topbar-div { width: 1px; height: 18px; background: var(--border); }
.brand {
  font: 700 15px "PT Serif", serif;
  color: var(--text);
  white-space: nowrap;
}
.brand span { color: var(--accent); }
.brand:hover { text-decoration: none; color: var(--text); }
#btn-sidebar { display: none; }

.search-wrap { position: relative; width: 340px; }
.search-hint {
  position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  font: 12px "PT Mono", monospace; color: var(--faint);
  pointer-events: none;
}
#search {
  width: 100%; height: 28px;
  padding-left: 26px;
  background: var(--panel);
  font-size: 12.5px;
}
.search-results {
  position: absolute; top: 34px; left: 0;
  width: 480px; max-height: 480px; overflow: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 3px;
  box-shadow: var(--shadow);
  z-index: 60;
}
.search-item { padding: 12px 16px; border-bottom: 1px solid var(--border-soft); cursor: pointer; transition: background 120ms ease-out; }
.search-item:last-child { border-bottom: none; }
.search-item:hover { background: var(--panel-2); }
.search-item .st { font: 700 14px "PT Serif", serif; color: var(--text); }
.search-item .sp { font-size: 11.5px; color: var(--faint); margin-top: 1px; }
.search-item .ss { font: 13px/1.55 "PT Serif", serif; color: var(--muted); margin-top: 4px; }

/* Чекбоксы слоёв */
.layer-toggles { display: flex; gap: 14px; align-items: center; }
.layer-btn {
  display: inline-flex; gap: 6px; align-items: center;
  color: var(--text);
  font-size: 12.5px;
  transition: color 120ms ease-out;
}
.layer-btn .box {
  width: 13px; height: 13px;
  border: 1px solid var(--border);
  border-radius: 2px;
  background: var(--panel);
  display: inline-flex; align-items: center; justify-content: center;
  font: 700 9px "PT Sans", sans-serif;
  color: transparent;
  transition: background 120ms ease-out, border-color 120ms ease-out;
}
.layer-btn.on .box { background: var(--accent); border-color: var(--accent); color: #fff; }
.layer-btn:not(.on) { color: var(--faint); }
.layer-btn.locked { color: var(--faint); cursor: default; opacity: .6; }

.topnav { display: flex; gap: 22px; align-items: center; }
.nav-link {
  color: var(--muted);
  font-size: 12.5px;
  padding-bottom: 14px;
  margin-bottom: -15px;
  border-bottom: 1px solid transparent;
  transition: color 120ms ease-out;
}
.nav-link:hover { color: var(--text); text-decoration: none; }
.nav-link.active { color: var(--text); border-bottom-color: var(--accent); }
.nav-btn { padding-bottom: 14px; margin-bottom: -15px; }
.user-menu { position: relative; }
.user-btn { font: 12px "PT Mono", monospace; color: var(--faint); }
.user-btn:hover { color: var(--text); }
.dropdown {
  position: absolute; right: 0; top: 32px;
  min-width: 140px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 3px;
  box-shadow: var(--shadow);
  padding: 10px 12px;
  display: flex; flex-direction: column; gap: 8px;
  z-index: 70;
}
.dropdown button { text-align: left; color: var(--accent); font-size: 13px; }

.body { flex: 1; display: flex; min-height: 0; }

/* --- Дерево --- */
.sidebar {
  width: 264px; flex: none;
  border-right: 1px solid var(--border-soft);
  overflow-y: auto;
  padding: 16px 0 24px;
}
.tree { font-size: 13.5px; color: var(--muted); }
.tree-rubric { padding: 0 20px 8px; }
.tree-sep { margin: 14px 20px 8px; border-top: 1px solid var(--border-soft); }
.tree-head {
  display: flex; gap: 8px; align-items: baseline;
  padding: 5px 20px;
  cursor: pointer;
  color: var(--text);
  transition: background 120ms ease-out;
}
.tree-head:hover { background: var(--panel-2); }
.tree-head .caret { font-size: 10px; color: var(--faint); width: 10px; transition: transform 120ms ease-out; }
.tree-head .count { margin-left: auto; font: 12px "PT Mono", monospace; color: var(--faint); }
.tree-section.collapsed .tree-items { display: none; }
.tree-section.collapsed .caret { transform: rotate(-90deg); }
.tree-items { display: flex; flex-direction: column; }
.tree-item {
  display: block;
  padding: 4px 20px 4px 40px;
  color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  transition: background 120ms ease-out, color 120ms ease-out;
}
.tree-item:hover { color: var(--text); text-decoration: none; background: var(--panel-2); }
.tree-item.active {
  color: var(--text);
  background: var(--panel-2);
  border-right: 2px solid var(--accent);
}

/* Оглавление документа в дереве */
.tree-item { position: relative; }
.tree-doc-caret {
  position: absolute; left: 24px; top: 5px;
  color: var(--faint); font-size: 10px;
  opacity: 0;
  transition: opacity 120ms ease-out;
}
.tree-item:hover .tree-doc-caret { opacity: 1; }
.tree-outline { display: flex; flex-direction: column; }
.tree-outline a {
  padding: 3px 20px 3px 56px;
  color: var(--faint);
  font-size: 12.5px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tree-outline a:hover { color: var(--text); text-decoration: none; }

/* --- Полоса чтения --- */
.main { flex: 1; overflow-y: auto; min-width: 0; position: relative; }
.doc-view { min-height: 100%; }
.doc-wrap {
  display: flex;
  justify-content: center;
  gap: 36px;
  padding: 36px 32px 64px;
}
.doc-col { width: 700px; flex: none; min-width: 0; }
.doc-loading { color: var(--faint); padding: 20px 0; }
.doc-breadcrumb { font-size: 12.5px; color: var(--faint); margin-bottom: 10px; }
.doc-breadcrumb a { color: var(--faint); }
.doc-breadcrumb a:hover { color: var(--accent); }
.doc-title {
  font: 700 30px/1.25 "PT Serif", serif;
  color: var(--text);
  margin: 0 0 10px;
}
.doc-meta {
  font-size: 12.5px;
  color: var(--faint);
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border-soft);
  margin-bottom: 26px;
  display: flex; flex-wrap: wrap; gap: 6px; align-items: baseline;
}
.doc-meta .mono { font-size: 12px; }
.doc-meta .chip {
  font-size: 11px;
  padding: 1px 7px;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--muted);
}
.doc-meta .chip.status-verified { border-color: var(--add); color: var(--add); }
.doc-meta .chip.status-draft { border-color: var(--root); color: var(--root); }
.doc-actions { display: inline-flex; gap: 12px; margin-left: auto; }

/* --- Типографика статьи --- */
.markdown {
  font: 16.5px/1.68 "PT Serif", serif;
  color: var(--text-soft);
}
.markdown h1 { display: none; }
.markdown h2 { font: 700 21px/1.3 "PT Serif", serif; color: var(--text); margin: 34px 0 14px; }
.markdown h3 { font: 700 17px/1.35 "PT Serif", serif; color: var(--text); margin: 26px 0 12px; }
.markdown h4 { font: 700 14px/1.4 "PT Sans", sans-serif; color: var(--text); margin: 22px 0 10px; }
.markdown p { margin: 0 0 18px; }
.markdown ul, .markdown ol { margin: 0 0 18px; padding-left: 26px; }
.markdown li { margin-bottom: 6px; }
.markdown blockquote {
  margin: 0 0 18px;
  padding: 2px 0 2px 14px;
  border-left: 2px solid var(--accent-soft);
  color: var(--muted);
  font-style: italic;
}
.markdown a { border-bottom: 1px solid var(--accent-soft); }
.markdown a:hover { text-decoration: none; border-bottom-color: var(--accent); }
.markdown img {
  max-width: 100%;
  border: 1px solid var(--border);
  border-radius: 3px;
  cursor: zoom-in;
}
.markdown code {
  font: 14px "PT Mono", monospace;
  color: var(--code-text);
  background: var(--code-bg);
  padding: 1px 5px;
  border-radius: 2px;
}
.markdown pre {
  margin: 0;
  padding: 14px 16px;
  overflow-x: auto;
  font: 13px/1.6 "PT Mono", monospace;
  color: var(--text-soft);
}
.markdown pre code { background: none; padding: 0; color: inherit; font: inherit; }
.codebox {
  background: var(--code-bg);
  border: 1px solid var(--border-soft);
  border-radius: 3px;
  margin: 0 0 24px;
}
.codebox-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 5px 12px;
  border-bottom: 1px solid var(--border-soft);
  font: 11.5px "PT Mono", monospace;
  color: var(--faint);
}
.codebox-head button { font: 11.5px "PT Mono", monospace; color: var(--faint); }
.codebox-head button:hover { color: var(--accent); }
.markdown table {
  width: 100%;
  border-collapse: collapse;
  font: 14px/1.5 "PT Sans", sans-serif;
  color: var(--text-soft);
  margin: 0 0 26px;
  display: block; overflow-x: auto;
}
.markdown th {
  text-align: left;
  font: 700 11px "PT Sans", sans-serif;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--faint);
  padding: 8px 12px 8px 0;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.markdown td {
  padding: 8px 12px 8px 0;
  border-bottom: 1px solid var(--border-soft);
  vertical-align: top;
}
.markdown hr { border: none; border-top: 1px solid var(--border-soft); margin: 26px 0; }
.mermaid-box { margin: 0 0 24px; overflow-x: auto; }
.mermaid-box svg { max-width: 100%; height: auto; }

/* Строки документа: действия у абзаца */
.md-line { position: relative; }
.line-actions {
  position: absolute;
  right: -34px; top: 2px;
  display: none;
  flex-direction: column;
  gap: 2px;
}
.md-line:hover .line-actions { display: flex; }
.line-btn {
  width: 24px; height: 22px;
  font-size: 12px;
  color: var(--faint);
  border-radius: 3px;
  transition: color 120ms ease-out;
}
.line-btn:hover { color: var(--accent); }
.line-comment-dot { color: var(--accent); font-size: 14px; line-height: 0; }
.note-drift { font-size: 11px; color: var(--root); padding: 2px 14px 0; opacity: .85; }

/* Смена варианта текста при переключении слоёв: совпавшие блоки не
   трогаются, прокрутка якорится за видимый блок, новые блоки подсвечиваются
   на секунду при появлении. Никаких анимаций высоты - положение элементов
   не плавает. */
.layer-new { animation: layer-new 1s ease-out; border-radius: 3px; }
@keyframes layer-new {
  0% { opacity: 0; background-color: var(--accent-bg); }
  18% { opacity: 1; background-color: var(--accent-bg); }
  70% { background-color: var(--accent-bg); }
  100% { background-color: transparent; }
}
/* Однократная вспышка применённой правки */
.flash { animation: flash 600ms ease-out; }
@keyframes flash { from { background: var(--accent-bg); } to { background: transparent; } }

/* --- Заметки на полях --- */
.margin-notes {
  width: 312px; flex: none;
  padding-top: 120px;
  display: flex; flex-direction: column; gap: 16px;
  font-size: 13.5px;
}
.note-card {
  border: 1px solid var(--border);
  border-radius: 3px;
  background: var(--panel);
  transition: border-color 140ms ease-out;
}
.note-card.closed { opacity: .82; background: var(--bg); }
.note-card.conflict { border-color: var(--root); }
.note-head {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 10px 14px 0;
  font-size: 12px; color: var(--faint);
  gap: 8px;
}
.note-head .author { color: var(--text-soft); }
.note-head .state { white-space: nowrap; }
.note-head .state.proposed, .note-head .state.conflict { color: var(--accent); }
.note-head .state.applied { color: var(--add); }
.note-head .state.rejected { color: var(--del); }
.note-body { padding: 8px 14px 12px; font-size: 13.5px; line-height: 1.5; color: var(--text-soft); }
.note-quote {
  margin: 0 14px 8px;
  padding-left: 10px;
  border-left: 2px solid var(--border);
  font: italic 12.5px/1.5 "PT Serif", serif;
  color: var(--muted);
}
.note-diff {
  margin: 0 14px 10px;
  border: 1px solid var(--border-soft);
  border-radius: 2px;
  font: 12px/1.55 "PT Mono", monospace;
  overflow: hidden;
}
.note-diff .del { display: block; padding: 4px 10px; background: var(--del-bg); color: var(--del); }
.note-diff .add { display: block; padding: 4px 10px; background: var(--add-bg); color: var(--add); }
.note-actions { display: flex; gap: 16px; padding: 0 14px 12px; font-size: 12.5px; }
.note-replies { border-top: 1px solid var(--border-soft); margin-top: 2px; padding-bottom: 4px; }
.note-form { display: flex; gap: 8px; align-items: center; }
.note-form input { flex: 1; height: 32px; background: var(--bg); }
.margin-notes .rp-empty { color: var(--faint); font-size: 12.5px; }
sup.note-ref {
  font: 11px "PT Mono", monospace;
  color: var(--accent);
  cursor: pointer;
}

/* --- Карточка термина --- */
.term-card {
  position: fixed;
  width: 360px;
  max-height: 420px;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 3px;
  box-shadow: var(--shadow);
  z-index: 80;
  padding: 14px 16px;
}
.term-card .tc-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; }
.term-card .tc-title { font: 700 16px "PT Serif", serif; color: var(--text); }
.term-card .tc-body { font: 13.5px/1.55 "PT Serif", serif; color: var(--text-soft); }
.term-card .tc-foot { margin-top: 10px; display: flex; gap: 14px; }
.markdown a.termlink { border-bottom: 1px dotted var(--accent); }

/* --- Граф --- */
.graph-view { height: 100%; display: flex; flex-direction: column; position: relative; }
.graph-toolbar {
  height: 46px; flex: none;
  display: flex; align-items: center; gap: 14px;
  padding: 0 20px;
  border-bottom: 1px solid var(--border-soft);
  font-size: 13px;
}
.graph-toolbar input { width: 200px; height: 28px; margin-left: auto; }
.zoomer {
  display: flex; align-items: center;
  border: 1px solid var(--border);
  border-radius: 3px;
  overflow: hidden;
  font: 13px "PT Mono", monospace;
  color: var(--muted);
}
.zoomer button { padding: 3px 12px; color: var(--muted); transition: color 120ms ease-out; }
.zoomer button:hover { color: var(--text); }
.zoomer span { padding: 3px 12px; background: var(--panel-2); border-left: 1px solid var(--border); border-right: 1px solid var(--border); }
#graph-svg { flex: 1; width: 100%; height: 100%; display: block; }
.g-link { stroke: var(--border); stroke-width: 1.2; transition: stroke 150ms ease-out, stroke-opacity 150ms ease-out; }
.g-link.hot { stroke: var(--accent); stroke-opacity: .65; stroke-width: 1.5; }
.g-link.dim { stroke-opacity: .25; }
.g-node { transition: opacity 150ms ease-out; }
.g-node text {
  font: 11.5px "PT Sans", sans-serif;
  fill: var(--muted);
  paint-order: stroke;
  stroke: var(--bg);
  stroke-width: 3px;
}
.g-node.hot text { fill: var(--text); font-weight: 700; }
.g-node text.g-scheme { font-size: 9.5px; fill: var(--external); font-weight: 700; }
.g-node.dim { opacity: .25; }
.graph-tip {
  position: absolute;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 3px;
  box-shadow: var(--shadow);
  padding: 8px 12px;
  font: 12px/1.5 "PT Sans", sans-serif;
  color: var(--muted);
  pointer-events: none;
  z-index: 40;
}
.graph-tip b { color: var(--text); display: block; }
.graph-tip .mono { font-size: 11px; color: var(--faint); }
.graph-legend {
  position: absolute; left: 20px; bottom: 16px;
  display: flex; gap: 18px; align-items: center;
  font-size: 11.5px; color: var(--faint);
}
.graph-legend .sw { display: inline-flex; gap: 6px; align-items: center; }

/* --- История --- */
.changelog-view { height: 100%; display: flex; min-height: 0; }
.cl-list {
  width: 440px; flex: none;
  border-right: 1px solid var(--border-soft);
  overflow-y: auto;
  padding: 8px 0;
}
.commit-row {
  padding: 10px 20px;
  cursor: pointer;
  transition: background 120ms ease-out;
  border-right: 2px solid transparent;
}
.commit-row:hover { background: var(--panel-2); }
.commit-row.active { background: var(--panel-2); border-right-color: var(--accent); }
.commit-row .commit-top { display: flex; justify-content: space-between; font: 12px "PT Mono", monospace; color: var(--muted); }
.commit-row.active .commit-top { color: var(--accent); }
.commit-subj { font-size: 13.5px; color: var(--text-soft); margin: 3px 0 2px; }
.commit-meta { font-size: 12px; color: var(--faint); }
.commit-sha { font-family: "PT Mono", monospace; }
.cl-diff { flex: 1; overflow: auto; padding: 16px 20px; }

.diff {
  font: 12.5px/1.7 "PT Mono", monospace;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--muted);
}
.diff .add { display: block; background: var(--add-bg); color: var(--add); }
.diff .del { display: block; background: var(--del-bg); color: var(--del); }
.diff .hunk { display: block; color: var(--accent); }
.diff .meta { display: block; color: var(--faint); }

/* --- Панель ИИ --- */
.ai-panel {
  position: fixed;
  right: 0; top: 46px; bottom: 0;
  width: 440px;
  background: var(--panel);
  border-left: 1px solid var(--border);
  display: flex; flex-direction: column;
  z-index: 50;
  animation: ai-in 180ms ease-out;
}
@keyframes ai-in { from { transform: translateX(12px); opacity: 0; } to { transform: none; opacity: 1; } }
.ai-head {
  height: 44px; flex: none;
  display: flex; justify-content: space-between; align-items: center;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  font: 700 13px "PT Sans", sans-serif;
  color: var(--text);
}
.ai-context {
  flex: none;
  margin: 12px 16px 0;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: var(--bg);
  padding: 10px 12px;
  font-size: 11.5px;
  color: var(--muted);
}
.ai-quote {
  border-left: 2px solid var(--border);
  padding-left: 10px;
  font: italic 13px/1.5 "PT Serif", serif;
  color: var(--muted);
}
.ai-messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.ai-empty { color: var(--faint); font-size: 12.5px; text-align: center; margin-top: 30px; line-height: 1.7; }
.ai-msg.user {
  align-self: flex-end;
  max-width: 85%;
  background: var(--panel-2);
  border-radius: 3px;
  padding: 9px 12px;
  font-size: 13.5px; line-height: 1.5;
  color: var(--text-soft);
  white-space: pre-wrap;
}
.ai-msg.assistant {
  font: 14px/1.62 "PT Serif", serif;
  color: var(--text-soft);
  white-space: pre-wrap;
}
.ai-msg.assistant .cursor {
  display: inline-block; width: 8px; height: 16px;
  background: var(--accent);
  vertical-align: -3px; margin-left: 2px;
  animation: caret 1s step-end infinite;
}
@keyframes caret { 0%, 45% { opacity: 1; } 55%, 100% { opacity: 0; } }
.ai-form {
  flex: none;
  display: flex; gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}
.ai-form textarea { flex: 1; resize: none; background: var(--bg); }
.ai-form .btn-primary { align-self: flex-end; }

/* --- Меню выделения --- */
.sel-menu {
  position: absolute;
  display: flex; gap: 1px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 3px;
  box-shadow: var(--shadow);
  z-index: 90;
  overflow: hidden;
}
.sel-menu button { padding: 8px 12px; font-size: 12.5px; color: var(--text-soft); transition: background 120ms ease-out; }
.sel-menu button:hover { background: var(--panel-2); color: var(--accent); }

/* --- Модальное окно --- */
.modal {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, .35);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.modal-card {
  width: min(860px, 92vw);
  max-height: 86vh;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 3px;
  box-shadow: var(--shadow);
  display: flex; flex-direction: column;
}
.modal-head {
  flex: none;
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font: 700 13.5px "PT Sans", sans-serif;
}
.modal-body { overflow: auto; padding: 16px; }
.modal-body img { max-width: 100%; }
.suggest-editor textarea {
  width: 100%;
  font: 13px/1.6 "PT Mono", monospace;
  background: var(--bg);
}
.suggest-editor input { width: 100%; margin-bottom: 8px; }
.suggest-editor .btn-primary { margin-top: 10px; }

/* --- Тост --- */
.toast {
  position: fixed;
  bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 9px 16px;
  border-radius: 3px;
  font-size: 13px;
  z-index: 110;
  animation: toast-in 180ms ease-out;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 6px); } to { opacity: 1; transform: translate(-50%, 0); } }
.toast.ok { background: var(--add); color: #fff; }
.toast.err { background: var(--del); color: #fff; }

/* Карточки в модалках и списках */
.card {
  border: 1px solid var(--border);
  border-radius: 3px;
  background: var(--panel);
  padding: 10px 14px;
  margin-bottom: 10px;
}
.card.resolved { opacity: .75; }
.card .who { font-size: 12.5px; color: var(--text-soft); }
.card .when { color: var(--faint); font-size: 12px; }
.card .cline {
  font: italic 12.5px "PT Serif", serif;
  color: var(--muted);
  border-left: 2px solid var(--border);
  padding-left: 8px;
  margin: 6px 0;
}
.card .ctext { font-size: 13.5px; line-height: 1.5; margin: 6px 0; }
.card-actions { display: flex; gap: 14px; margin-top: 6px; }
.status-badge { font-size: 11px; color: var(--muted); }
.status-badge.status-pending { color: var(--accent); }
.status-badge.status-applied { color: var(--add); }
.status-badge.status-rejected { color: var(--del); }
.rp-empty { color: var(--faint); padding: 10px 0; }

/* --- Адаптив --- */
#btn-notes { display: none; }
@media (max-width: 1280px) {
  .doc-wrap { gap: 0; }
  .margin-notes { display: none; }
  .margin-notes.open {
    display: flex;
    position: fixed; right: 0; top: 46px; bottom: 46px;
    width: 340px;
    background: var(--panel);
    border-left: 1px solid var(--border);
    padding: 16px 16px 24px;
    overflow-y: auto;
    z-index: 45;
  }
  #btn-notes {
    display: flex;
    position: fixed; left: 0; right: 0; bottom: 0;
    height: 46px;
    align-items: center;
    padding: 0 18px;
    border-top: 1px solid var(--border);
    background: var(--bg);
    color: var(--muted);
    font-size: 13px;
    z-index: 44;
  }
  #btn-notes span { color: var(--accent); font-family: "PT Mono", monospace; margin-left: 4px; }
  .doc-wrap { padding-bottom: 80px; }
}
@media (max-width: 1100px) {
  .search-wrap { width: 220px; }
  .layer-toggles { gap: 10px; }
}
@media (max-width: 900px) {
  #btn-sidebar { display: inline-flex; font-size: 17px; }
  .sidebar {
    position: fixed; left: 0; top: 46px; bottom: 0;
    background: var(--bg);
    z-index: 45;
    transform: translateX(-100%);
    transition: transform 160ms ease-out;
  }
  .sidebar.open { transform: none; }
  .doc-wrap { padding: 20px 18px 56px; }
  .doc-col { width: 100%; }
  .doc-title { font-size: 22px; }
  .ai-panel { width: 100%; }
  .search-wrap { display: none; }
  .topnav { gap: 14px; }
}

/* --- Движение отключено --- */
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
