:root {
  --bg: #f7f6f3;
  --card: #ffffff;
  --border: #dcd9d2;
  --text: #1f2328;
  --muted: #6b6f76;
  --blue: #2b6fd9;
  --blue-soft: #e6effc;
  --blue-border: #8fb3ee;
  --warn-bg: #fbf1d4;
  --warn-border: #e4cf8c;
  --warn-text: #7a5a10;
  --err-bg: #fdecec;
  --err-border: #e7a8a8;
  --err-text: #8c2323;
  --radius: 10px;
}
* { box-sizing: border-box; }
html { font-size: 16px; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "DejaVu Sans", sans-serif;
  line-height: 1.45;
}
a { color: var(--blue); }
h1 { font-size: 1.5rem; margin: 0 0 .5rem; }
h2 { font-size: 1.25rem; margin: 1.6rem 0 .4rem; }
h3 { font-size: 1.05rem; margin: 1.2rem 0 .4rem; }
.muted { color: var(--muted); }
.container { max-width: 1100px; margin: 0 auto; padding: 1.25rem 1rem 3rem; }
.narrow { max-width: 420px; margin-top: 4rem; }

/* шапка */
.topbar { background: var(--card); border-bottom: 1px solid var(--border); }
.topbar-inner { max-width: 1100px; margin: 0 auto; padding: .6rem 1rem; display: flex; gap: 1.5rem; align-items: center; flex-wrap: wrap; }
.brand { font-weight: 700; color: var(--text); text-decoration: none; }
.menu { display: flex; gap: 1rem; flex: 1; }
.menu a { color: var(--muted); text-decoration: none; padding: .2rem 0; border-bottom: 2px solid transparent; }
.menu a.active { color: var(--text); border-bottom-color: var(--blue); }
.topbar-user { display: flex; gap: .8rem; align-items: center; color: var(--muted); }
form.inline { display: inline; margin: 0; }
.link-btn { background: none; border: 0; color: var(--blue); cursor: pointer; font: inherit; padding: 0; }

/* карточки, уведомления */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.25rem; margin: 1rem 0; }
.notice { border: 1px solid var(--border); background: var(--card); border-radius: var(--radius); padding: .7rem 1rem; margin: 1rem 0; }
.notice.ok { background: #e9f6ec; border-color: #a9d7b3; }
.notice.error { background: var(--err-bg); border-color: var(--err-border); color: var(--err-text); }
.notice.warn { background: var(--warn-bg); border-color: var(--warn-border); color: var(--warn-text); }
.frame-text { border-left: 3px solid var(--blue-border); padding: .1rem 0 .1rem 1rem; color: #3a3f46; }
.frame-text p { margin: .5rem 0; }

/* кнопки и поля */
.btn { display: inline-block; font: inherit; border: 1px solid var(--border); background: var(--card); color: var(--text); border-radius: 8px; padding: .5rem .9rem; cursor: pointer; text-decoration: none; }
.btn:hover { border-color: #b9b5aa; }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; font-weight: 600; }
.btn.primary:hover { background: #2561c0; }
.btn[disabled] { opacity: .6; cursor: default; }
input[type=text], input[type=password], textarea, select {
  font: inherit; color: inherit; background: #fff; border: 1px solid var(--border); border-radius: 8px; padding: .45rem .6rem; max-width: 100%;
}
textarea { width: 100%; min-height: 5.5rem; resize: vertical; }
label.field { display: block; margin: .8rem 0; }
label.field span { display: block; margin-bottom: .25rem; color: var(--muted); }
label.field input { width: 100%; }

/* таблицы-списки */
table.list { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); }
table.list th, table.list td { text-align: left; padding: .6rem .8rem; border-bottom: 1px solid #ece9e2; vertical-align: top; }
table.list th { color: var(--muted); font-weight: 600; background: #f3f1ec; }
.scroll-x { overflow-x: auto; }

/* ───── редактор ───── */
.editor-head { background: var(--card); border-bottom: 1px solid var(--border); }
.editor-head-inner { max-width: 1100px; margin: 0 auto; padding: .8rem 1rem; display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; }
.editor-head .crumbs { color: var(--muted); font-size: .9rem; }
.editor-head h1 { margin: 0; }
.editor-title { flex: 1; min-width: 14rem; }
.badge { display: inline-block; border-radius: 999px; padding: .1rem .7rem; font-size: .85rem; background: var(--warn-bg); border: 1px solid var(--warn-border); color: var(--warn-text); }
.save-state { color: var(--muted); }
.save-state.error { color: var(--err-text); font-weight: 600; }
.editor-title-row { display: flex; align-items: center; gap: .8rem; flex-wrap: wrap; }
.editor-section-title { font-size: 1.2rem; margin: 2rem 0 .3rem; }
.hint { color: var(--muted); margin: .2rem 0 .8rem; }
.scale-line { color: var(--muted); margin: .2rem 0 .8rem; }
.scale-line .info { background: none; border: 1px solid var(--muted); color: var(--muted); border-radius: 50%; width: 1.3rem; height: 1.3rem; cursor: pointer; font-size: .8rem; line-height: 1; padding: 0; margin-left: .3rem; }
.scale-full { margin: .4rem 0 1rem; padding: .6rem 1rem; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); }
.scale-full div { margin: .2rem 0; }

table.matrix { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); }
table.matrix thead th { text-align: left; padding: .6rem .8rem; background: #f3f1ec; color: var(--muted); font-weight: 600; border-bottom: 1px solid var(--border); }
table.matrix td { padding: .5rem .8rem; border-bottom: 1px solid #ece9e2; vertical-align: middle; }
table.matrix tbody.m-row:last-of-type td { border-bottom: 0; }
.m-name { min-width: 12rem; }
.m-name input { width: 100%; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg-btn { background: #fff; border: 0; border-right: 1px solid var(--border); padding: .35rem .65rem; font: inherit; color: var(--muted); cursor: pointer; }
.seg-btn:last-child { border-right: 0; }
.seg-btn[aria-pressed=true] { background: var(--blue); color: #fff; font-weight: 700; }
.m-target-cell { white-space: nowrap; color: var(--muted); }
.m-target-cell select { color: var(--blue); font-weight: 700; padding: .25rem .3rem; border-color: transparent; background: transparent; }
.m-comment-btn { background: none; border: 0; cursor: pointer; font-size: 1.2rem; opacity: .55; }
.m-comment-btn.has-comment { opacity: 1; }
.m-comment-row td { padding-top: 0; }
.m-tool-custom { margin-top: .3rem; display: block; }
.matrix-footer { padding: .7rem .8rem; background: var(--card); border: 1px solid var(--border); border-top: 0; border-radius: 0 0 var(--radius) var(--radius); }
.add-row { background: none; border: 0; color: var(--blue); cursor: pointer; font: inherit; padding: 0; }
.remove-row { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 1.1rem; }

.cat { margin: 1.2rem 0; }
.cat-toggle, .cat-toggle-extra { display: flex; gap: .6rem; align-items: baseline; width: 100%; background: none; border: 0; padding: .3rem 0; cursor: pointer; font: inherit; text-align: left; color: var(--muted); }
.cat-name { font-weight: 700; letter-spacing: .04em; text-transform: uppercase; font-size: .95rem; }
.cat-meta { font-size: .9rem; }
.cat-arrow { font-size: .9rem; }
.cat-head { display: flex; align-items: center; gap: .6rem; }
.cat-head .cat-toggle { flex: none; width: auto; }
.cat-head .cat-toggle-extra { flex: 1; width: auto; }
.cat-head .cat-name { margin: 0; }
.help { flex: none; width: 1.4rem; height: 1.4rem; padding: 0; border-radius: 50%; border: 1px solid var(--border); background: var(--card); color: var(--muted); font: inherit; font-size: .8rem; font-weight: 700; line-height: 1; cursor: help; }
.help:hover, .help:focus-visible { border-color: var(--blue); color: var(--blue); }
.cat-head .help[data-tip]::after { max-width: min(22rem, 80vw); }
.cat-body[hidden] { display: none; }
.tool-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); margin: .6rem 0; }
.tool-head { display: flex; align-items: center; gap: .6rem; padding: .7rem 1rem; justify-content: space-between; }
.tool-head label { display: flex; align-items: center; gap: .6rem; font-weight: 600; flex: 1; }
.tool-card:not(.on) .tool-head label { font-weight: 400; }
.tool-head input[type=checkbox] { width: 1.15rem; height: 1.15rem; }
.tool-card[data-custom] .tool-head { align-items: flex-start; justify-content: flex-start; }
.tool-card[data-custom] .tool-head label { flex: none; padding-top: .45rem; }
.tool-card[data-custom] .tool-head .tool-status { padding-top: .45rem; margin-left: auto; }
.tool-head .custom-name { flex: 1; min-width: 12rem; max-width: 36rem; min-height: 3.6rem; border-style: dashed; overflow: hidden; resize: vertical; }
.custom-title { white-space: pre-line; }
.add-custom-tool { margin: .3rem 0 .2rem; }
.tool-status { color: var(--muted); font-size: .9rem; }
.tool-fields { padding: .3rem 1rem 1rem; border-top: 1px dashed var(--border); }
.tool-fields[hidden], .f-row[hidden] { display: none; }
.f-row { display: grid; grid-template-columns: 9.5rem 1fr; gap: .5rem 1rem; align-items: center; margin: .55rem 0; }
.f-label { color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: .45rem; }
.chip { font: inherit; background: #fff; border: 1px solid var(--border); border-radius: 999px; padding: .2rem .85rem; color: #4a4f57; cursor: pointer; }
.chip[aria-pressed=true], .chip.ro.on { background: var(--blue-soft); border-color: var(--blue); color: var(--blue); font-weight: 600; }
.chip.ro { cursor: default; }
.chip[data-tip], .help[data-tip] { position: relative; }
.chip[data-tip]::after, .help[data-tip]::after {
  content: attr(data-tip); position: absolute; left: 0; top: calc(100% + .4rem); z-index: 20;
  width: max-content; max-width: min(19rem, 80vw); padding: .5rem .7rem; border-radius: 8px;
  background: #1f2328; color: #fff; font-size: .85rem; font-weight: 400; line-height: 1.35; text-align: left;
  box-shadow: 0 4px 14px rgba(0,0,0,.18); pointer-events: none; opacity: 0; visibility: hidden; transition: opacity .12s;
}
.chip[data-tip]:last-child::after { left: auto; right: 0; }
.chip[data-tip]:hover::after, .chip[data-tip]:focus-visible::after, .help[data-tip]:hover::after, .help[data-tip]:focus-visible::after, .cat-toggle:hover + .help[data-tip]::after, .cat-name:hover + .help[data-tip]::after { opacity: 1; visibility: visible; transition-delay: .25s; }
.chip.ro:not(.on) { display: none; }
.note { border-radius: 8px; padding: .6rem .9rem; }
.note.warn { background: var(--warn-bg); border: 1px solid var(--warn-border); color: var(--warn-text); }
.note textarea { margin-top: .4rem; min-height: 3.5rem; }
.sticky-foot { position: sticky; bottom: 0; background: var(--card); border-top: 1px solid var(--border); margin-top: 2rem; }
.sticky-foot-inner { max-width: 1100px; margin: 0 auto; padding: .7rem 1rem; display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; }
.sticky-foot .versions { flex: 1; color: var(--muted); }
.sticky-foot .versions strong { color: var(--text); }
.editor-errors ul { margin: .3rem 0 0 1.2rem; padding: 0; }

/* ───── чтение снимка ───── */
.ro-tool { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: .7rem 1rem; margin: .6rem 0; }
.ro-tool h4 { margin: 0 0 .4rem; font-size: 1rem; }
.ro-tool .f-row { margin: .3rem 0; }
.ro-quit { color: var(--warn-text); }
.pre { white-space: pre-wrap; }
.level-cell { white-space: nowrap; }
.empty { color: var(--muted); font-style: italic; }

@media (max-width: 720px) {
  .f-row { grid-template-columns: 1fr; }
  table.matrix thead { display: none; }
  table.matrix, table.matrix tbody, table.matrix tr, table.matrix td { display: block; width: 100%; }
  table.matrix td { border-bottom: 0; padding: .3rem .8rem; }
  table.matrix tbody.m-row { border-bottom: 1px solid var(--border); padding: .4rem 0; display: block; }
  .m-name { font-weight: 600; }
}
[hidden] { display: none !important; }
table.matrix .m-name { width: 22%; }
table.matrix .m-freq, table.matrix .m-tool { max-width: 13rem; }
table.matrix th:nth-child(4) { white-space: nowrap; }

/* Теги моделей: поле ввода с автодополнением */
.tags { max-width: 34rem; }
.tag-list { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: .4rem; }
.tag-list:not(:empty) { margin-bottom: .45rem; }
.tag { display: inline-flex; align-items: center; gap: .15rem; background: var(--blue-soft); border: 1px solid var(--blue-border); color: var(--blue); border-radius: 999px; padding: .1rem .2rem .1rem .75rem; font-weight: 600; }
.tag-remove { font: inherit; line-height: 1; background: none; border: 0; color: inherit; cursor: pointer; border-radius: 50%; width: 1.5rem; height: 1.5rem; }
.tag-remove:hover, .tag-remove:focus-visible { background: rgba(43, 111, 217, .18); }
.tag-box { position: relative; }
.tag-input { width: 100%; }
.suggest { position: absolute; left: 0; right: 0; top: calc(100% + .2rem); z-index: 15; margin: 0; padding: .25rem; list-style: none; background: #fff; border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 4px 14px rgba(0,0,0,.14); max-height: 15rem; overflow-y: auto; }
.suggest[hidden] { display: none; }
.suggest li { padding: .3rem .6rem; border-radius: 6px; cursor: pointer; }
.suggest li:hover, .suggest li.active { background: var(--blue-soft); color: var(--blue); }
