:root {
  --bg: #f6f5f2;
  --paper: #ffffff;
  --ink: #1f2328;
  --muted: #6b7280;
  --line: #e4e2dc;
  --accent: #2f6f5e;
  --accent-soft: #e6f0ec;
  --warn: #9a6700;
  --warn-soft: #fff4d6;
  --err: #b42318;
  --mark: #fff1b8;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); line-height: 1.55; font-size: 15px; }
a { color: var(--accent); }
code { background: #f0efeb; padding: 1px 4px; border-radius: 4px; font-size: 0.9em; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--err); }

button {
  font: inherit; cursor: pointer; border: 1px solid var(--accent); background: var(--accent);
  color: #fff; border-radius: 6px; padding: 6px 14px;
}
button.ghost { background: transparent; color: var(--accent); }
button.link { border: 0; background: none; color: var(--muted); padding: 0; font-size: 12px; text-decoration: underline; }
button:disabled { opacity: 0.5; cursor: default; }

/* шапка */
.top {
  display: flex; align-items: center; gap: 24px; padding: 0 24px; height: 52px;
  background: var(--paper); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 700; font-size: 18px; color: var(--ink); text-decoration: none; }
.tabs { display: flex; gap: 4px; height: 100%; }
.tabs a {
  display: flex; align-items: center; padding: 0 14px; color: var(--muted); text-decoration: none;
  border-bottom: 2px solid transparent;
}
.tabs a.on { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }
.who { margin-left: auto; color: var(--muted); font-size: 13px; }

/* раскладка */
.layout { display: grid; grid-template-columns: 220px 1fr; gap: 24px; padding: 24px; }
.side { position: sticky; top: 76px; align-self: start; display: flex; flex-direction: column; gap: 2px; }
.side a { padding: 6px 10px; border-radius: 6px; color: var(--ink); text-decoration: none; font-size: 14px; }
.side a.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
main.wide { padding: 24px; max-width: 1500px; margin: 0 auto; }
.path, .crumbs { color: var(--muted); font-size: 13px; margin-bottom: 8px; }

.docwrap { min-width: 0; }
.paper {
  position: relative; background: var(--paper); border: 1px solid var(--line); border-radius: 10px;
  padding: 28px 40px 20px; min-width: 0;
}
.paper.empty { padding: 40px; text-align: center; }
.version {
  position: absolute; top: 12px; right: 16px; font-size: 12px; color: var(--accent);
  background: var(--accent-soft); padding: 2px 10px; border-radius: 999px; font-weight: 600;
}
.hint { color: var(--muted); font-size: 12px; border-top: 1px solid var(--line); padding-top: 10px; margin-top: 24px; }

/* markdown */
.md { overflow-wrap: anywhere; }
.md h1 { font-size: 26px; margin: 0 0 16px; padding-right: 140px; }
.md h2 { font-size: 20px; margin: 28px 0 10px; border-bottom: 1px solid var(--line); padding-bottom: 4px; }
.md h3 { font-size: 17px; margin: 22px 0 8px; }
.md table { border-collapse: collapse; width: 100%; margin: 12px 0; font-size: 14px; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--line); padding: 6px 8px; vertical-align: top; text-align: left; }
.md th { background: #faf9f6; }
.md td:first-child, .md th:first-child { white-space: nowrap; }
.md pre { background: #f6f8fa; padding: 12px; border-radius: 6px; overflow-x: auto; font-size: 13px; }
.md pre.mermaid { background: transparent; text-align: center; }
/* перекрёстные ссылки H/Q/F и блоков, подсветка цели перехода */
.md a.xref { text-decoration: none; border-bottom: 1px dotted var(--accent); }
.md [id] { scroll-margin-top: 72px; }
.md tr:target > td, .md li:target { background: var(--mark); }
.md blockquote { margin: 12px 0; padding: 4px 16px; border-left: 3px solid var(--accent); background: var(--accent-soft); }
.md details { border: 1px solid var(--line); border-radius: 6px; padding: 6px 12px; margin: 12px 0; }
.md summary { cursor: pointer; color: var(--muted); }

/* комментируемые фрагменты */
.cb { border-radius: 4px; transition: background 0.2s; }
.cb:hover { background: #f3f7f5; }
.cb.has-c { background: var(--mark); position: relative; }
p.cb.has-c::after, li.cb.has-c::after, h1.cb.has-c::after, h2.cb.has-c::after, h3.cb.has-c::after {
  content: "💬 " attr(data-c); font-size: 11px; margin-left: 6px; color: var(--warn);
}
.cb.flash { background: #ffd666 !important; }
.plus {
  display: none; position: absolute; z-index: 20; width: 26px; height: 26px; padding: 0;
  border-radius: 50%; font-size: 16px; line-height: 24px;
}

.composer {
  display: none; position: absolute; z-index: 30; width: 420px; background: var(--paper);
  border: 1px solid var(--line); border-radius: 10px; padding: 12px; box-shadow: 0 8px 24px rgba(0,0,0,0.12);
}
.composer .q { font-size: 13px; color: var(--muted); font-style: italic; margin-bottom: 8px; }
.composer textarea { width: 100%; font: inherit; border: 1px solid var(--line); border-radius: 6px; padding: 8px; }
.composer .row { display: flex; gap: 8px; margin-top: 8px; }

/* панель комментариев */
/* выдвижная панель справа, по умолчанию скрыта */
.comments {
  position: fixed; top: 52px; right: 0; bottom: 0; width: 360px; max-width: 100vw; z-index: 25;
  overflow-y: auto; background: var(--paper); border-left: 1px solid var(--line); padding: 14px;
  box-shadow: -8px 0 24px rgba(0,0,0,0.08); transform: translateX(100%); transition: transform 0.2s;
}
.comments.open { transform: none; }
.c-toggle {
  position: fixed; right: 20px; bottom: 20px; z-index: 24; border-radius: 999px; padding: 8px 16px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}
.comments-head { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.comments-head h3 { margin-right: auto; }
.comments-head .close { font-size: 16px; text-decoration: none; }
.comments h3 { margin: 0; font-size: 15px; }
.comments-head button { padding: 3px 10px; font-size: 13px; }
.card { border: 1px solid var(--line); border-radius: 8px; padding: 10px; margin-bottom: 8px; font-size: 14px; }
.card.open { border-left: 3px solid var(--warn); }
.card.resolved { opacity: 0.65; border-left: 3px solid var(--accent); }
.card.declined { opacity: 0.65; border-left: 3px solid var(--muted); }
.card.linked { cursor: pointer; }
.card .q { color: var(--muted); font-style: italic; font-size: 12px; margin-bottom: 4px; }
.card .t { white-space: pre-wrap; }
.card .meta { color: var(--muted); font-size: 12px; margin-top: 6px; }
.card .res { font-size: 12px; margin-top: 6px; background: var(--accent-soft); padding: 4px 6px; border-radius: 4px; }

/* список пациентов */
table.list { width: 100%; border-collapse: collapse; background: var(--paper); border: 1px solid var(--line); border-radius: 10px; }
table.list th, table.list td { padding: 8px 12px; border-bottom: 1px solid var(--line); text-align: left; font-size: 14px; }
table.list tr.dim td { color: var(--muted); }
.dots { white-space: nowrap; }
.dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; background: var(--line); margin-right: 4px; }
.dot.ok { background: var(--accent); }
.badge { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 999px; background: var(--warn-soft); color: var(--warn); }
.badge.ok { background: var(--accent-soft); color: var(--accent); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }

/* шаги пациента */
.stepper { display: flex; gap: 0; list-style: none; padding: 0; margin: 8px 0 16px; counter-reset: s; }
.stepper li { flex: 1; }
.stepper a {
  display: flex; align-items: center; gap: 8px; padding: 10px 12px; text-decoration: none; color: var(--muted);
  border-bottom: 3px solid var(--line);
}
.stepper li.ok a { color: var(--ink); }
.stepper li.on a { border-bottom-color: var(--accent); font-weight: 600; color: var(--accent); }
.stepper .n {
  display: inline-flex; width: 22px; height: 22px; border-radius: 50%; align-items: center; justify-content: center;
  background: var(--line); font-size: 12px; color: var(--ink);
}
.stepper li.ok .n { background: var(--accent-soft); color: var(--accent); }
.stepper li.missing a { opacity: 0.55; }
.approve { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }

/* вход */
.login-body { display: grid; place-items: center; min-height: 100vh; }
.login {
  background: var(--paper); border: 1px solid var(--line); border-radius: 12px; padding: 32px; width: 340px;
  display: flex; flex-direction: column; gap: 12px;
}
.login h1 { margin: 0; }
.login label { display: flex; flex-direction: column; gap: 4px; font-size: 14px; }
.login input { font: inherit; padding: 8px; border: 1px solid var(--line); border-radius: 6px; }

@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; padding: 16px; }
  .side { position: static; flex-direction: row; flex-wrap: wrap; }
  .paper { padding: 20px 16px; }
  main.wide { padding: 16px; }
  .stepper { flex-wrap: wrap; }
  .composer { width: calc(100vw - 32px); }
}
