/* Fonts are self-hosted: Google Fonts / third-party CDNs are not guaranteed on RU networks. */
@font-face { font-family: "Golos"; font-weight: 400; font-display: swap; src: url(fonts/golos-text-cyrillic-400-normal.woff2) format("woff2"); unicode-range: U+0400-04FF; }
@font-face { font-family: "Golos"; font-weight: 400; font-display: swap; src: url(fonts/golos-text-latin-400-normal.woff2) format("woff2"); unicode-range: U+0000-03FF, U+2000-206F, U+20AC, U+2116, U+2190-21FF; }
@font-face { font-family: "Golos"; font-weight: 500; font-display: swap; src: url(fonts/golos-text-cyrillic-500-normal.woff2) format("woff2"); unicode-range: U+0400-04FF; }
@font-face { font-family: "Golos"; font-weight: 500; font-display: swap; src: url(fonts/golos-text-latin-500-normal.woff2) format("woff2"); unicode-range: U+0000-03FF, U+2000-206F, U+20AC, U+2116, U+2190-21FF; }
@font-face { font-family: "Golos"; font-weight: 600; font-display: swap; src: url(fonts/golos-text-cyrillic-600-normal.woff2) format("woff2"); unicode-range: U+0400-04FF; }
@font-face { font-family: "Golos"; font-weight: 600; font-display: swap; src: url(fonts/golos-text-latin-600-normal.woff2) format("woff2"); unicode-range: U+0000-03FF, U+2000-206F, U+20AC, U+2116, U+2190-21FF; }
@font-face { font-family: "Golos"; font-weight: 700; font-display: swap; src: url(fonts/golos-text-cyrillic-700-normal.woff2) format("woff2"); unicode-range: U+0400-04FF; }
@font-face { font-family: "Golos"; font-weight: 700; font-display: swap; src: url(fonts/golos-text-latin-700-normal.woff2) format("woff2"); unicode-range: U+0000-03FF, U+2000-206F, U+20AC, U+2116, U+2190-21FF; }
@font-face { font-family: "Unbounded"; font-weight: 500; font-display: swap; src: url(fonts/unbounded-cyrillic-500-normal.woff2) format("woff2"); unicode-range: U+0400-04FF; }
@font-face { font-family: "Unbounded"; font-weight: 500; font-display: swap; src: url(fonts/unbounded-latin-500-normal.woff2) format("woff2"); unicode-range: U+0000-03FF, U+2000-206F; }
@font-face { font-family: "Unbounded"; font-weight: 700; font-display: swap; src: url(fonts/unbounded-cyrillic-700-normal.woff2) format("woff2"); unicode-range: U+0400-04FF; }
@font-face { font-family: "Unbounded"; font-weight: 700; font-display: swap; src: url(fonts/unbounded-latin-700-normal.woff2) format("woff2"); unicode-range: U+0000-03FF, U+2000-206F; }
@font-face { font-family: "Unbounded"; font-weight: 800; font-display: swap; src: url(fonts/unbounded-cyrillic-800-normal.woff2) format("woff2"); unicode-range: U+0400-04FF; }
@font-face { font-family: "Unbounded"; font-weight: 800; font-display: swap; src: url(fonts/unbounded-latin-800-normal.woff2) format("woff2"); unicode-range: U+0000-03FF, U+2000-206F; }
@font-face { font-family: "JB Mono"; font-weight: 400; font-display: swap; src: url(fonts/jetbrains-mono-cyrillic-400-normal.woff2) format("woff2"); unicode-range: U+0400-04FF; }
@font-face { font-family: "JB Mono"; font-weight: 400; font-display: swap; src: url(fonts/jetbrains-mono-latin-400-normal.woff2) format("woff2"); unicode-range: U+0000-03FF, U+2000-206F, U+2116; }
@font-face { font-family: "JB Mono"; font-weight: 600; font-display: swap; src: url(fonts/jetbrains-mono-cyrillic-600-normal.woff2) format("woff2"); unicode-range: U+0400-04FF; }
@font-face { font-family: "JB Mono"; font-weight: 600; font-display: swap; src: url(fonts/jetbrains-mono-latin-600-normal.woff2) format("woff2"); unicode-range: U+0000-03FF, U+2000-206F, U+2116; }

/* Light = drafting film (калька); dark = blueprint (синька). */
:root {
  --paper: #f3efe6;
  --paper-2: #ebe5d8;
  --panel: #fbf9f4;
  --ink: #181b20;
  --ink-2: #4a4f57;
  --ink-3: #7c8089;
  --rule: #cfc7b6;
  --grid: rgba(24, 27, 32, .045);
  --red: #c8321e;
  --red-soft: rgba(200, 50, 30, .09);
  --blue: #1f4e8c;
  --mark: #ffe08a;
  --d1: #c8321e;   /* СП 152 */
  --d2: #1f4e8c;   /* СП 118 */
  --d3: #b7791f;   /* СП 1.13130 */
  --d4: #2f7d4f;   /* ТЗ */
  --shadow: 0 1px 0 rgba(24,27,32,.06), 0 10px 30px -18px rgba(24,27,32,.35);
  --display: "Unbounded", "Golos", sans-serif;
  --body: "Golos", "PT Sans", "Segoe UI", sans-serif;
  --mono: "JB Mono", "PT Mono", ui-monospace, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #0c1f33; --paper-2: #10273f; --panel: #122c47; --ink: #e8f0f9; --ink-2: #b4c6da; --ink-3: #7f97b1;
    --rule: #2a4a6b; --grid: rgba(150, 200, 255, .07); --red: #ff7a59; --red-soft: rgba(255,122,89,.14); --blue: #8cc0ff;
    --mark: #6b5a17; --d1: #ff7a59; --d2: #8cc0ff; --d3: #f0b35a; --d4: #6fd39b;
    --shadow: 0 1px 0 rgba(0,0,0,.2), 0 14px 34px -20px rgba(0,0,0,.8);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #0c1f33; --paper-2: #10273f; --panel: #122c47; --ink: #e8f0f9; --ink-2: #b4c6da; --ink-3: #7f97b1;
  --rule: #2a4a6b; --grid: rgba(150, 200, 255, .07); --red: #ff7a59; --red-soft: rgba(255,122,89,.14); --blue: #8cc0ff;
  --mark: #6b5a17; --d1: #ff7a59; --d2: #8cc0ff; --d3: #f0b35a; --d4: #6fd39b;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background-color: var(--paper);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px),
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 8px 8px, 8px 8px, 40px 40px, 40px 40px;
  color: var(--ink);
  font: 400 15px/1.55 var(--body);
}
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.sheet { max-width: 1480px; margin: 0 auto; padding: 22px 28px 40px; }

/* ── Masthead: compact title + drawing stamp, collapsible ────── */
.masthead {
  border: 2px solid var(--ink); padding: 12px 16px; background: color-mix(in srgb, var(--panel) 70%, transparent);
  position: relative; animation: rise .4s ease-out both;
}
.masthead::before { /* outer frame line like a drawing sheet */
  content: ""; position: absolute; inset: -6px; border: 1px solid var(--rule); pointer-events: none;
}
.mh-row { display: grid; grid-template-columns: auto 1fr auto; gap: 22px; align-items: center; }
.kicker { margin: 0 0 4px; font: 600 10.5px/1 var(--mono); letter-spacing: .14em; text-transform: uppercase; color: var(--red); }
h1 { margin: 0; font: 800 clamp(30px, 3.4vw, 42px)/.95 var(--display); letter-spacing: -.03em; }
h1 .dot { color: var(--red); }
.lede { margin: 0; max-width: 72ch; color: var(--ink-2); font-size: 14px; line-height: 1.45; }
.mh-actions { display: flex; gap: 8px; align-items: center; grid-column: -2; justify-self: end; }
.mh-mini { display: none; min-width: 0; color: var(--ink-2); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.masthead.collapsed .mh-mini { display: block; }
.btn-dl {
  display: inline-flex; align-items: center; gap: 8px; padding: 9px 13px; text-decoration: none; white-space: nowrap;
  background: var(--ink); color: var(--paper); font: 700 12px/1 var(--display); letter-spacing: .02em; transition: background .15s;
}
.btn-dl::before { content: "↓"; font-family: var(--mono); font-size: 14px; }
.btn-dl:hover { background: var(--red); }
.mh-toggle {
  appearance: none; cursor: pointer; border: 1.5px solid var(--ink); background: var(--panel); color: var(--ink);
  padding: 8px 11px; font: 600 12.5px/1 var(--body); white-space: nowrap;
}
.mh-toggle::after { content: " ▴"; font-size: 11px; }
.mh-toggle:hover { background: var(--red-soft); }
.stamp { margin: 12px 0 0; display: grid; grid-template-columns: 1fr repeat(3, minmax(90px, auto)); border: 1.5px solid var(--ink); font-size: 13px; }
.stamp > div { border-right: 1px solid var(--ink); padding: 6px 10px; min-width: 0; }
.stamp > div:last-child { border-right: 0; }
.stamp dt { font: 600 9.5px/1.2 var(--mono); text-transform: uppercase; letter-spacing: .1em; color: var(--ink-3); }
.stamp dd { margin: 2px 0 0; font-weight: 600; overflow-wrap: anywhere; }
/* collapsed: a slim bar with the wordmark, download and expand */
.masthead.collapsed { padding: 7px 12px; }
.masthead.collapsed .mh-more, .masthead.collapsed .kicker { display: none; }
.masthead.collapsed .mh-row { grid-template-columns: auto 1fr auto; }
.masthead.collapsed h1 { font-size: 24px; }
.masthead.collapsed .mh-toggle::after { content: " ▾"; }

/* ── Toolbar ─────────────────────────────────────────────────── */
.toolbar { display: flex; flex-wrap: wrap; gap: 14px; justify-content: space-between; align-items: center; margin: 26px 0 12px; }
.tabs { display: inline-flex; border: 1.5px solid var(--ink); }
.tabs button {
  appearance: none; border: 0; background: transparent; color: var(--ink); cursor: pointer;
  padding: 10px 16px; font: 600 14px/1 var(--body); border-right: 1.5px solid var(--ink);
}
.tabs button:last-child { border-right: 0; }
.tabs button[aria-selected="true"] { background: var(--ink); color: var(--paper); }
.tabs button:not([aria-selected="true"]):hover { background: var(--red-soft); }
.docs { display: flex; flex-wrap: wrap; gap: 8px; }
.doc-toggle {
  appearance: none; cursor: pointer; display: inline-flex; align-items: center; gap: 8px;
  border: 1.5px solid var(--c); background: var(--panel); color: var(--ink); padding: 7px 11px;
  font: 600 13px/1 var(--body);
}
.doc-toggle .n { display: inline-grid; place-items: center; width: 20px; height: 20px; background: var(--c); color: var(--paper); font: 700 11px/1 var(--mono); }
.doc-toggle[aria-pressed="false"] { opacity: .45; border-style: dashed; }

.filters { display: grid; grid-template-columns: minmax(260px, 520px) 1fr; gap: 14px; align-items: start; margin-bottom: 18px; }
.search input {
  width: 100%; border: 1.5px solid var(--ink); background: var(--panel); color: var(--ink);
  padding: 11px 14px; font: 500 15px/1.2 var(--body); border-radius: 0; outline: none;
}
.search input:focus { box-shadow: 4px 4px 0 var(--red); }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag {
  appearance: none; cursor: pointer; border: 1px solid var(--rule); background: var(--panel); color: var(--ink-2);
  padding: 6px 10px; font: 500 12.5px/1 var(--body); border-radius: 999px; transition: all .12s;
}
.tag:hover { border-color: var(--ink); color: var(--ink); }
.tag[aria-pressed="true"] { background: var(--red); border-color: var(--red); color: #fff; }
.tag .ct { font-family: var(--mono); font-size: 11px; opacity: .7; margin-left: 4px; }

/* ── Room view ───────────────────────────────────────────────── */
.view-room { display: grid; grid-template-columns: 330px 1fr; gap: 22px; align-items: start; }
.roomlist { position: sticky; top: 12px; max-height: calc(100vh - 24px); overflow: auto; border: 1.5px solid var(--ink); background: var(--panel); scrollbar-width: thin; }
.cat { border-bottom: 1px solid var(--rule); }
.cat h3 {
  position: sticky; top: 0; margin: 0; padding: 8px 12px; background: var(--paper-2); z-index: 1;
  font: 600 10.5px/1.3 var(--mono); letter-spacing: .1em; text-transform: uppercase; color: var(--ink-2);
}
.cat ul { list-style: none; margin: 0; padding: 4px 0; }
.room-btn {
  appearance: none; width: 100%; text-align: left; border: 0; background: transparent; color: var(--ink); cursor: pointer;
  display: grid; grid-template-columns: 1fr auto; gap: 8px; padding: 6px 12px 6px 14px; font: 400 13.5px/1.3 var(--body);
  border-left: 3px solid transparent;
}
.room-btn:hover { background: var(--red-soft); }
.room-btn[aria-current="true"] { border-left-color: var(--red); background: var(--red-soft); font-weight: 600; }
.room-btn .cnt { font: 400 11px/1.3 var(--mono); color: var(--ink-3); align-self: center; }
.empty-list { padding: 16px; color: var(--ink-3); font-size: 13px; }

.card { background: var(--panel); border: 1.5px solid var(--ink); box-shadow: var(--shadow); min-width: 0; animation: rise .35s ease-out both; }
.card-head { padding: 22px 26px 18px; border-bottom: 1.5px solid var(--ink); position: relative; }
.card-head .cat-l { font: 600 11px/1 var(--mono); letter-spacing: .12em; text-transform: uppercase; color: var(--red); }
.card-head h2 { margin: 10px 0 8px; font: 700 clamp(22px, 2.6vw, 32px)/1.15 var(--display); letter-spacing: -.02em; }
.meta { display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: 13px; color: var(--ink-2); }
.meta b { font-family: var(--mono); font-weight: 600; color: var(--ink); }
.mates { margin-top: 12px; font-size: 13px; color: var(--ink-2); }
.mates a { color: var(--blue); text-decoration: none; border-bottom: 1px dotted currentColor; cursor: pointer; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 14px; }
.chip { font: 600 11.5px/1 var(--body); padding: 6px 9px; border: 1px solid var(--ink); background: var(--paper); }
.chip.muted { border-color: var(--rule); color: var(--ink-3); font-weight: 500; }
.share { position: absolute; top: 18px; right: 20px; }
.icon-btn {
  appearance: none; cursor: pointer; border: 1px solid var(--rule); background: var(--paper); color: var(--ink-2);
  font: 500 12px/1 var(--body); padding: 7px 10px;
}
.icon-btn:hover { border-color: var(--ink); color: var(--ink); }

.docsec { display: grid; grid-template-columns: 54px 1fr; border-bottom: 1px solid var(--rule); }
.docsec:last-child { border-bottom: 0; }
.docsec .rail { border-right: 1px solid var(--rule); display: flex; justify-content: center; padding-top: 18px; }
.docsec .rail span { display: grid; place-items: center; width: 30px; height: 30px; background: var(--c); color: var(--paper); font: 700 13px/1 var(--mono); }
.docsec .body { padding: 16px 22px 18px; min-width: 0; }
.docsec h4 { margin: 0 0 10px; font: 600 14px/1.3 var(--body); color: var(--c); }
.docsec h4 small { display: block; font: 400 12px/1.3 var(--body); color: var(--ink-3); margin-top: 2px; }
.none { color: var(--ink-3); font-style: italic; margin: 0; }
.ex { position: relative; padding: 10px 44px 10px 14px; border-left: 3px solid var(--c); background: color-mix(in srgb, var(--c) 6%, transparent); margin: 0 0 10px; }
.ex .cl { display: inline-block; font: 600 12px/1.2 var(--mono); color: var(--c); margin-bottom: 4px; }
.ex q { quotes: "«" "»"; display: block; }
.ex .note { margin: 6px 0 0; font-size: 12.5px; color: var(--ink-2); font-style: italic; }
.ex .note::before { content: "Прим. составителя: "; font-style: normal; font-weight: 600; }
.copy { position: absolute; top: 8px; right: 8px; appearance: none; border: 1px solid transparent; background: transparent; color: var(--ink-3); cursor: pointer; font: 400 14px/1 var(--mono); padding: 4px 6px; }
.copy:hover { border-color: var(--rule); color: var(--ink); background: var(--panel); }
.pdf-link {
  display: inline-flex; align-items: center; gap: 5px; margin-top: 7px; padding: 4px 8px; text-decoration: none;
  border: 1px solid var(--c); color: var(--c); background: var(--panel); font: 600 11.5px/1 var(--mono);
}
.pdf-link::before { content: "▤"; font-size: 12px; }
.pdf-link:hover { background: var(--c); color: var(--paper); }
details.general { margin-top: 8px; }
details.general summary { cursor: pointer; font: 600 12.5px/1.3 var(--body); color: var(--ink-2); list-style: none; padding: 6px 0; }
details.general summary::-webkit-details-marker { display: none; }
details.general summary::before { content: "+"; display: inline-block; width: 18px; font-family: var(--mono); color: var(--c); }
details.general[open] summary::before { content: "−"; }
details.general .ex { background: transparent; border-left-style: dashed; }
mark { background: var(--mark); color: inherit; padding: 0 1px; }

/* ── Table view ──────────────────────────────────────────────── */
.tablewrap { overflow: auto; border: 1.5px solid var(--ink); background: var(--panel); max-height: calc(100vh - 40px); }
table { border-collapse: separate; border-spacing: 0; width: 100%; }
.grid { min-width: 1180px; font-size: 13px; }
.grid th, .grid td { vertical-align: top; border-right: 1px solid var(--rule); border-bottom: 1px solid var(--rule); padding: 10px 12px; text-align: left; }
.grid thead th { position: sticky; top: 0; z-index: 2; background: var(--ink); color: var(--paper); font: 600 12px/1.3 var(--body); border-color: var(--ink-2); }
.grid thead th .n { display: inline-grid; place-items: center; width: 18px; height: 18px; margin-right: 6px; background: var(--c); color: var(--paper); font: 700 10.5px/1 var(--mono); }
.grid td:first-child, .grid th:first-child { position: sticky; left: 0; z-index: 1; width: 230px; min-width: 200px; }
.grid thead th:first-child { z-index: 3; }
.grid td:first-child { background: var(--paper-2); font-weight: 600; }
.grid td:first-child a { color: var(--ink); text-decoration: none; }
.grid td:first-child a:hover { color: var(--red); }
.grid tr.general td { background: color-mix(in srgb, var(--red) 5%, var(--panel)); }
.grid tr.general td:first-child { background: color-mix(in srgb, var(--red) 10%, var(--paper-2)); }
.grid .ex { padding: 6px 8px; margin-bottom: 8px; }
.grid .ex .copy { display: none; }
.grid .dash { color: var(--ink-3); text-align: center; display: block; }
.hint { margin: 0 0 12px; color: var(--ink-2); font-size: 13px; max-width: 90ch; }

/* ── Matrix view ─────────────────────────────────────────────── */
.matrix { font-size: 13px; min-width: 980px; }
.matrix th, .matrix td { border-right: 1px solid var(--rule); border-bottom: 1px solid var(--rule); padding: 8px 10px; }
.matrix thead th { position: sticky; top: 0; background: var(--ink); color: var(--paper); font: 600 11.5px/1.25 var(--body); text-align: center; z-index: 2; }
.matrix thead th:first-child { text-align: left; left: 0; z-index: 3; }
.matrix td:first-child { position: sticky; left: 0; background: var(--paper-2); font-weight: 600; min-width: 260px; max-width: 340px; z-index: 1; }
.matrix td:first-child a { color: var(--ink); text-decoration: none; cursor: pointer; }
.matrix td:first-child a:hover { color: var(--red); }
.matrix td.m { text-align: center; white-space: nowrap; }
.pip { display: inline-block; width: 11px; height: 11px; margin: 0 1.5px; background: var(--c); vertical-align: middle; }
.pip.off { background: transparent; }
.matrix tr:hover td { background: var(--red-soft); }

.foot { margin-top: 28px; padding-top: 16px; border-top: 1.5px solid var(--ink); font-size: 12.5px; color: var(--ink-2); display: grid; gap: 6px; }
.foot ol { margin: 4px 0 0; padding-left: 18px; }
.foot .theme { justify-self: start; margin-top: 6px; }

.drawer-backdrop { position: fixed; inset: 0; background: rgba(12, 16, 22, .35); z-index: 20; animation: fade .2s ease-out both; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(980px, 60vw); z-index: 21; background: var(--panel);
  border-left: 2px solid var(--ink); box-shadow: -18px 0 40px -24px rgba(0,0,0,.6); animation: slide .22s ease-out both;
}
.drawer iframe { width: 100%; height: 100%; border: 0; display: block; }
body.drawer-open { overflow: hidden; }
@keyframes slide { from { transform: translateX(40px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.toast { position: fixed; left: 50%; bottom: 22px; transform: translate(-50%, 20px); opacity: 0; background: var(--ink); color: var(--paper); padding: 10px 16px; font: 500 13px/1 var(--body); transition: all .2s; pointer-events: none; z-index: 10; }
.toast.on { opacity: 1; transform: translate(-50%, 0); }

@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ── Small screens ───────────────────────────────────────────── */
@media (max-width: 960px) {
  .sheet { padding: 14px 16px 30px; }
  .mh-row { grid-template-columns: 1fr auto; gap: 10px; }
  .mh-row .lede { grid-column: 1 / -1; grid-row: 2; }
  .mh-actions { flex-direction: column; align-items: stretch; }
  .stamp { grid-template-columns: repeat(3, 1fr); }
  .stamp .s-obj { grid-column: 1 / -1; border-right: 0; border-bottom: 1px solid var(--ink); }
  .masthead.collapsed .mh-actions { flex-direction: row; }
  .masthead.collapsed .mh-mini, .dl-long { display: none !important; }
  .masthead.collapsed h1 { font-size: 22px; }
  .tabs { display: flex; width: 100%; }
  .tabs button { flex: 1 1 0; padding: 9px 6px; }
}
@media (max-width: 400px) {
  .mh-toggle { font-size: 0; padding: 8px 11px; }   /* arrow only; the label stays for screen readers */
  .mh-toggle::after { font-size: 13px; content: "▴"; }
  .masthead.collapsed .mh-toggle::after { content: "▾"; }
  .tabs button { font-size: 12.5px; }
  .filters { grid-template-columns: 1fr; }
  .view-room { grid-template-columns: 1fr; }
  .roomlist { position: static; max-height: 300px; }
  .docsec { grid-template-columns: 40px 1fr; }
  .docsec .body { padding: 14px 14px 16px; }
  .card-head { padding: 18px 16px 16px; }
  .share { position: static; margin-top: 12px; }
}

@media print {
  body { background: #fff; }
  .toolbar, .filters, .roomlist, .copy, .share, .btn-dl, .foot .theme, .mh-toggle, .pdf-link, .drawer, .drawer-backdrop { display: none !important; }
  .view-room { display: block; }
  .card, .masthead { box-shadow: none; }
  details.general { display: block; }
  .tablewrap { max-height: none; overflow: visible; }
}
