:root {
  --bg: #f6f3ec; --paper: #fffdf8; --ink: #23201b; --muted: #6f685d; --line: #e2dccf; --line2: #cfc6b4;
  --accent: #8a3b12; --accent-bg: #f3e3d6; --link: #1f5f8b;
  --red: #b3261e; --red-bg: #f8d7d3; --yellow-bg: #fcefc7; --yellow: #8a6100; --green: #2e6b3a; --green-bg: #dcefdc;
  --blue-bg: #e1ecf5; --stop: #5a1010;
  --font: "Segoe UI", system-ui, sans-serif; --serif: Georgia, serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1b1a17; --paper: #24221e; --ink: #ece6da; --muted: #a59d8f; --line: #3a362f; --line2: #4a453c;
    --accent: #e39a6b; --accent-bg: #3d2a1e; --link: #8cc0e8;
    --red: #ff8a80; --red-bg: #4a2320; --yellow-bg: #463a17; --yellow: #f0cf7a; --green: #9fd3a8; --green-bg: #213a26;
    --blue-bg: #1f3242; --stop: #ffb4b4;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.45 var(--font); }
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { font-family: var(--serif); font-weight: 700; line-height: 1.2; }
h1 { font-size: 24px; margin: 4px 0 12px; }
h2 { font-size: 18px; margin: 22px 0 10px; }
h3 { font-size: 15px; margin: 14px 0 6px; }
.wrap { max-width: 1500px; margin: 0 auto; padding: 0 16px 60px; }

header.top { background: var(--paper); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
header.top .wrap, header.top .bar { display: flex; align-items: center; gap: 14px; padding: 8px 16px; flex-wrap: wrap; }
header.top .bar { max-width: none; }
.topsearch { display: flex; gap: 6px; flex: 1; max-width: 640px; min-width: 240px; }
.topsearch input { flex: 1; }
header.top .brand { font-family: var(--serif); font-weight: 700; color: var(--accent); white-space: nowrap; }
header.top nav { display: flex; gap: 2px; flex-wrap: wrap; flex: 1; }
header.top nav a { padding: 5px 9px; border-radius: 6px; color: var(--ink); white-space: nowrap; }
header.top nav a.on, header.top nav a:hover { background: var(--accent-bg); text-decoration: none; }
header.top .me { color: var(--muted); font-size: 13px; white-space: nowrap; }
.count { background: var(--accent); color: var(--paper); border-radius: 9px; padding: 0 6px; font-size: 11px; margin-left: 3px; }
.testbar { background: var(--yellow-bg); color: var(--yellow); text-align: center; font-size: 12px; padding: 3px 16px; }

.flash { margin: 12px 0; padding: 9px 12px; border-radius: 8px; white-space: pre-wrap; word-break: break-word; }
.flash.ok { background: var(--green-bg); color: var(--green); }
.flash.err { background: var(--red-bg); color: var(--red); }

.card { background: var(--paper); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; margin: 12px 0; }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

table { border-collapse: collapse; width: 100%; background: var(--paper); }
th, td { border-bottom: 1px solid var(--line); padding: 6px 8px; text-align: left; vertical-align: top; }
th { font-weight: 700; font-size: 12px; color: var(--muted); background: var(--bg); position: sticky; top: 0; }
tr:hover td { background: color-mix(in srgb, var(--accent-bg) 35%, transparent); }
.tablewrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; }
.tablewrap table { border: 0; }
td.num, th.num { text-align: right; white-space: nowrap; }
tr.group td { background: var(--bg); font-family: var(--serif); font-weight: 700; }

.badge { display: inline-block; padding: 1px 7px; border-radius: 9px; font-size: 12px; background: var(--bg);
  border: 1px solid var(--line); white-space: nowrap; }
.badge.red { background: var(--red-bg); color: var(--red); border-color: transparent; }
.badge.yellow { background: var(--yellow-bg); color: var(--yellow); border-color: transparent; }
.badge.green { background: var(--green-bg); color: var(--green); border-color: transparent; }
.badge.blue { background: var(--blue-bg); border-color: transparent; }
.badge.stop { background: var(--stop); color: var(--paper); border-color: transparent; font-weight: 700; }
.fill { display: inline-block; width: 10px; height: 10px; border-radius: 50%; vertical-align: middle; cursor: help; }
.fill.red { background: var(--red); } .fill.yellow { background: #d9a400; } .fill.ok { background: var(--green); }
td.lvl-red { box-shadow: inset 4px 0 0 var(--red); } td.lvl-yellow { box-shadow: inset 4px 0 0 #d9a400; }
.late { color: var(--red); font-weight: 700; }

form.inline { display: inline; }
label { display: block; font-size: 12px; color: var(--muted); margin: 6px 0 2px; }
input, select, textarea, button { font: inherit; color: inherit; }
input[type=text], input[type=number], input[type=date], input[type=password], input[type=url], input:not([type]), select, textarea {
  width: 100%; padding: 5px 7px; border: 1px solid var(--line2); border-radius: 6px; background: var(--paper); min-width: 0; }
textarea { min-height: 54px; resize: vertical; }
input[type=checkbox] { width: auto; }
button, .btn { display: inline-block; padding: 5px 12px; border-radius: 6px; border: 1px solid var(--line2); background: var(--bg);
  cursor: pointer; white-space: nowrap; color: var(--ink); }
button.primary, .btn.primary { background: var(--accent); color: var(--paper); border-color: var(--accent); }
button.danger { color: var(--red); }
button:hover, .btn:hover { filter: brightness(0.96); text-decoration: none; }
button:disabled { opacity: .5; cursor: not-allowed; }
.fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 0 14px; }
.fields .wide { grid-column: 1 / -1; }
fieldset { border: 1px solid var(--line); border-radius: 8px; margin: 10px 0; padding: 4px 12px 12px; }
legend { font-family: var(--serif); font-weight: 700; padding: 0 6px; }
fieldset[disabled] input, fieldset[disabled] select, fieldset[disabled] textarea { background: var(--bg); }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin: 10px 0 0; flex-wrap: wrap; }
.tabs a { padding: 7px 12px; border-radius: 8px 8px 0 0; color: var(--ink); }
.tabs a.on { background: var(--paper); border: 1px solid var(--line); border-bottom-color: var(--paper); margin-bottom: -1px; }

.notice { border-left: 4px solid var(--accent); background: var(--accent-bg); padding: 8px 12px; border-radius: 0 8px 8px 0; margin: 8px 0; }
.notice.red { border-color: var(--red); background: var(--red-bg); }
.notice.yellow { border-color: #d9a400; background: var(--yellow-bg); }
.stopbar { background: var(--stop); color: var(--paper); padding: 8px 12px; border-radius: 8px; margin: 8px 0; font-weight: 700; }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 3px 14px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; }
.stats { display: flex; gap: 10px; flex-wrap: wrap; }
.stat { background: var(--paper); border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; min-width: 150px; }
.stat b { display: block; font-size: 22px; font-family: var(--serif); }

.gantt td.wk { padding: 2px; min-width: 28px; text-align: center; font-size: 11px; }
.gantt .bar { display: block; height: 16px; border-radius: 3px; background: var(--blue-bg); }
.gantt .bar.done { background: var(--green-bg); } .gantt .bar.late { background: var(--red-bg); }
.gantt .now { box-shadow: inset 2px 0 0 var(--accent); }

details > summary { cursor: pointer; color: var(--link); }
.hist td { font-size: 12px; }
.hist .old { color: var(--muted); text-decoration: line-through; }
code, .mono { font-family: Consolas, "Courier New", monospace; font-size: 12px; }
.login { max-width: 420px; margin: 60px auto; }

@media (max-width: 700px) {
  header.top nav { order: 3; width: 100%; overflow-x: auto; flex-wrap: nowrap; }
  .grid { grid-template-columns: 1fr; }
  h1 { font-size: 20px; }
}

/* ---------------- каркас: боковое меню слева (вид «Б», владелец 15.11.2026) ---------------- */
.shell { display: block; }
body.has-nav .shell { display: grid; grid-template-columns: 236px minmax(0, 1fr); align-items: start; }
body.has-nav .shell > .wrap { max-width: 1500px; width: 100%; margin: 0; padding-top: 6px; }
nav.side { position: sticky; top: 49px; max-height: calc(100vh - 49px); overflow-y: auto; padding: 12px 10px 30px;
  border-right: 1px solid var(--line); background: var(--paper); min-height: calc(100vh - 49px); }
nav.side a { display: flex; align-items: baseline; gap: 6px; padding: 6px 10px; border-radius: 7px; color: var(--ink); }
nav.side a:hover { background: var(--accent-bg); text-decoration: none; }
nav.side a.on { background: var(--accent-bg); font-weight: 600; }
nav.side a .n { margin-left: auto; color: var(--muted); font-size: 12px; font-weight: 400; }
nav.side .grp { margin: 0 0 6px; }
nav.side .grp-t, nav.side summary { font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted);
  font-weight: 700; padding: 12px 10px 4px; }
nav.side summary { cursor: pointer; list-style: revert; }
nav.side .side-close { display: none; }
.bottombar { display: none; }

/* плитки и виджеты главной */
.tiles { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
.tile { background: var(--paper); border: 1px solid var(--line); border-radius: 10px; padding: 11px 14px; display: block; color: var(--ink); }
.tile:hover { border-color: var(--line2); text-decoration: none; }
.tile b { display: block; font-family: var(--serif); font-size: 24px; color: var(--link); line-height: 1.15; }
.tile.warn b { color: var(--red); }
.tile span { color: var(--muted); font-size: 13px; }
.tile span:only-child { color: var(--ink); font-size: 15px; }
.widgets { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); align-items: start; }
.widgets .card { margin: 0; }
.widgets > .wide { grid-column: 1 / -1; }
h2.wh { margin: 0 0 10px; display: flex; gap: 8px; align-items: baseline; }
h2.wh a { margin-left: auto; font-family: var(--font); font-weight: 400; }
b.big { font-family: var(--serif); font-size: 22px; }
form.hero { display: flex; gap: 8px; margin: 6px 0 14px; max-width: 820px; }
form.hero input { flex: 1; font-size: 16px; padding: 10px 14px; border-radius: 9px; }
form.hero button { padding: 9px 18px; }
.card.attention p { margin: 6px 0; }

/* карточка книги: четыре блока */
.bblocks { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); margin: 12px 0 4px; }
.bblock { margin: 0; }
.bblock h3 { margin: 0 0 8px; display: flex; gap: 8px; align-items: baseline; font-size: 16px; }
.bblock h3 a { margin-left: auto; font-family: var(--font); font-weight: 400; }
.bblock p { margin: 6px 0; }
h2.bh { border-top: 1px solid var(--line); padding-top: 14px; margin-top: 26px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); border-radius: 14px; padding: 2px 10px; font-size: 13px; background: var(--bg); }

/* ---------------- телефон ---------------- */
@media (max-width: 800px) {
  body.has-nav .shell { display: block; }
  body.has-nav { padding-bottom: 62px; }
  .topsearch { display: none; }
  header.top .me { display: none; }
  nav.side { display: none; }
  nav.side:target { display: block; position: fixed; inset: 0; z-index: 50; max-height: none; min-height: 0; border: 0;
    padding: 14px 16px 80px; }
  nav.side:target .side-close { display: block; text-align: right; color: var(--link); }
  nav.side a { padding: 10px 10px; font-size: 16px; }
  .bottombar { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; background: var(--paper);
    border-top: 1px solid var(--line); padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); }
  .bottombar a { flex: 1; text-align: center; padding: 10px 2px; color: var(--muted); font-size: 13px; border-radius: 8px; }
  .bottombar a.on { color: var(--accent); font-weight: 700; background: var(--accent-bg); }
  .bottombar a:hover { text-decoration: none; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .widgets, .bblocks { grid-template-columns: 1fr; }
  form.hero { flex-direction: column; }
}
@media (max-width: 700px) {
  /* строки таблиц — карточки «Колонка: значение» (листы реестров остаются таблицей с прокруткой) */
  table.stack thead { display: none; }
  table.stack, table.stack tbody, table.stack tr, table.stack td { display: block; width: 100%; }
  table.stack tr { border-bottom: 1px solid var(--line); padding: 8px 10px; }
  table.stack tr:hover td { background: none; }
  table.stack td { border: 0; padding: 1px 0; text-align: left; white-space: normal; max-width: none; min-width: 0; }
  table.stack td[data-l]:not([data-l=""])::before { content: attr(data-l) ": "; color: var(--muted); font-size: 12px; }
  table.stack td.empty { display: none; }
  table.stack td:first-child { font-weight: 600; }
  table.stack td:first-child::before { display: none; }
  .tablewrap:has(table.stack) { overflow-x: visible; }
  .filters input, .filters select { width: 100% !important; flex: 1 1 100%; }
  .hide-m { display: none; }
  .kv { grid-template-columns: 1fr; gap: 0; }
  .kv dt { margin-top: 7px; font-size: 12px; }
}

/* ---------------- Реестры (/reg) ---------------- */
.hits { background: var(--paper); border: 1px solid var(--line); border-radius: 10px; padding: 6px 12px; }
.hit { padding: 4px 0; border-bottom: 1px solid var(--line); }
.hit:last-child { border-bottom: 0; }
pre.notes { white-space: pre-wrap; word-break: break-word; font: 13px/1.5 var(--font); margin: 0; }
table.reg td { font-size: 13px; }
td.longtext { min-width: 260px; max-width: 520px; font-size: 12px; }
dd.longtext { font-size: 13px; white-space: pre-wrap; }
.filters { margin: 8px 0; }

/* «На решение» */
a.card.decide { display: flex; gap: 14px; align-items: center; color: var(--ink); margin: 0; }
a.card.decide:hover { text-decoration: none; border-color: var(--accent); }
a.card.decide .n { font-family: var(--serif); font-size: 26px; min-width: 70px; text-align: right; }
a.card.decide.yellow { border-left: 4px solid #d9a400; }
a.card.decide.red { border-left: 4px solid var(--red); }

/* решение владельца в карточке договора */
.card.decision { border-left: 4px solid var(--link); }

/* фильтры с галочками и шестерёнка колонок (15.11): в цветах темы, как обычные поля */
details.ms, details.colpick { position: relative; display: inline-block; }
details.ms > summary { cursor: pointer; list-style: none; padding: 5px 26px 5px 9px; border: 1px solid var(--line2); border-radius: 6px;
  background: var(--paper); color: var(--ink); white-space: nowrap; position: relative; user-select: none; }
details.ms > summary::after { content: "▾"; position: absolute; right: 9px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 12px; }
details.ms > summary::-webkit-details-marker, details.colpick > summary::-webkit-details-marker { display: none; }
details.ms.on > summary { border-color: var(--accent); background: var(--accent-bg); }
details.ms[open] > summary { border-color: var(--accent); }
.ms-box, .colpick-box { position: absolute; z-index: 20; margin-top: 4px; min-width: 240px; max-width: 360px; max-height: 340px; overflow: auto;
  padding: 6px 10px 8px; background: var(--paper); color: var(--ink); border: 1px solid var(--line2); border-radius: 8px;
  box-shadow: 0 6px 18px rgba(0,0,0,.25); }
.ms-box label, .colpick-box label { display: flex; gap: 7px; align-items: flex-start; padding: 3px 0; font-size: 14px; white-space: normal; cursor: pointer; }
.ms-box label input, .colpick-box label input { margin-top: 3px; }
.ms-btns { display: flex; gap: 12px; margin: 0 0 6px; padding-bottom: 6px; border-bottom: 1px solid var(--line); }
.ms-btns button { background: none; border: 0; padding: 0; color: var(--link); font-size: 13px; cursor: pointer; }
.ms-btns button:hover { text-decoration: underline; filter: none; }
details.colpick { margin-left: 8px; vertical-align: middle; }
details.colpick > summary { cursor: pointer; list-style: none; display: inline-block; padding: 0 5px; border-radius: 5px; color: var(--muted);
  font-size: 15px; line-height: 1.4; }
details.colpick > summary:hover, details.colpick[open] > summary { color: var(--ink); background: var(--line); }
details.colpick .colpick-box { right: auto; left: 0; }
@media (max-width: 800px) { .ms-box, .colpick-box { position: static; max-width: none; box-shadow: none; }
  details.ms { display: block; } details.ms > summary { width: 100%; } }
/* «Файлы редакции» в карточке книги: версии свежие сверху, раскрываются в файлы */
.edv { border: 1px solid var(--line); border-radius: 8px; margin: 6px 0; background: var(--paper); }
.edv > summary { cursor: pointer; padding: 8px 10px; }
.edv[open] > summary { border-bottom: 1px solid var(--line); }
.edv-body { padding: 4px 10px 8px; }
.ed-sum { margin: 2px 0; overflow-wrap: anywhere; }
