:root {
  --bg: #f4f5f7; --panel: #ffffff; --line: #d9dde3; --text: #1f2933; --muted: #6b7684;
  --accent: #2563eb; --err: #b42318;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--text); background: var(--bg); }
a { color: var(--accent); }
h1, h2, h3 { margin: 0 0 8px; }
h1 { font-size: 20px; } h2 { font-size: 17px; } h3 { font-size: 15px; margin-top: 16px; }
.muted { color: var(--muted); }
.error { color: var(--err); }
.pad { padding: 16px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

.card { max-width: 760px; margin: 32px auto; padding: 24px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; }
.card.narrow { max-width: 380px; }
.card label { display: block; margin: 12px 0; }
.card input[type=text], .card input[type=password] { display: block; width: 100%; padding: 8px; margin-top: 4px; border: 1px solid var(--line); border-radius: 6px; font: inherit; }
.project { margin-top: 20px; }

.btn { padding: 6px 12px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); font: inherit; cursor: pointer; color: var(--text); }
.btn:hover { background: #eef1f5; }
.btn[disabled] { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.small { padding: 2px 8px; font-size: 13px; }

/* окно редактора */
.editor-page #editor { display: flex; flex-direction: column; height: 100vh; }
.topbar { display: flex; align-items: center; gap: 14px; padding: 8px 14px; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.topbar .doc-title { margin: 0; font-size: 17px; }
.topbar select, .topbar input[type=search] { padding: 5px 8px; border: 1px solid var(--line); border-radius: 6px; font: inherit; }
.topbar input[type=search] { min-width: 260px; }
.topbar .counter { color: var(--muted); margin-left: auto; }
/* ширина боковых панелей; скрытая панель имеет ширину 0 (классы parts-hidden и hist-hidden ниже) */
#editor { --w-parts: 250px; --w-side: 320px; }
.layout { flex: 1; min-height: 0; display: grid; grid-template-columns: var(--w-parts) minmax(0, 1fr) var(--w-side); }

.parts { overflow-y: auto; background: var(--panel); border-right: 1px solid var(--line); padding: 8px; }
.part { display: block; width: 100%; text-align: left; padding: 8px; margin-bottom: 6px; border: 1px solid transparent; border-radius: 6px; background: none; font: inherit; cursor: pointer; color: var(--text); }
.part:hover { background: #eef1f5; }
.part.active { border-color: var(--accent); background: #eef4ff; }
.part.dim { color: var(--muted); background: #f0f1f3; }
.part-title { display: block; font-weight: 600; }
.part-kind, .part-num { display: block; font-size: 12px; color: var(--muted); }
.bar { height: 6px; margin: 4px 0; background: #e3e7ec; border-radius: 3px; overflow: hidden; }
.bar-fill { height: 100%; background: #2f9e44; }

.center { overflow-y: auto; padding: 8px 12px; }
.para { margin-bottom: 10px; padding-bottom: 6px; border-bottom: 2px solid var(--line); }
.row { position: relative; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 220px; gap: 10px; padding: 6px 8px 6px 12px; border-left: 5px solid #cfd4db; background: var(--panel); }
.row + .row { border-top: 1px solid #eceff3; }
/* цвет строки: --st приходит из справочника статусов (поле color), здесь его нет */
/* подкрашен только перевод; оригинал остаётся на белом (владелец 14.11) */
.row.has-st { border-left-color: var(--st); }
.row.has-st:not(.closed) > .target { padding: 3px 6px; border-radius: 4px; background: color-mix(in srgb, var(--st) 14%, white); }
.row.has-st:not(.closed) > .target.editable:hover { background: color-mix(in srgb, var(--st) 22%, white); }
.row.has-st:not(.closed) > .target.open { padding: 0; background: none; }
.row.has-st .state { color: color-mix(in srgb, var(--st) 75%, black); font-weight: 600; }
/* кнопка статуса в цвете своего статуса (--bst ставит editor.js из справочника); нажатая залита им */
.st-btn { border-color: color-mix(in srgb, var(--bst, var(--line)) 60%, white); }
.st-btn:hover { background: color-mix(in srgb, var(--bst, var(--accent)) 12%, white); }
.st-btn.on { background: color-mix(in srgb, var(--bst, var(--accent)) 28%, white); border-color: var(--bst, var(--accent)); font-weight: 600; }
.row.selected { outline: 2px solid var(--accent); outline-offset: -2px; }
.row.closed { background: #eceef1; color: #5a6470; }
.row.conflict { background: #fff1f0; }
.cell { white-space: pre-wrap; overflow-wrap: anywhere; }
.cell.editable { cursor: text; min-height: 1.4em; }
.cell.editable:hover { background: #f6f8fb; }
.cell.target.open { padding: 0; }
.edit-area { width: 100%; min-height: 3em; padding: 4px 6px; font: inherit; border: 1px solid var(--accent); border-radius: 4px; resize: vertical; }
.meta { display: flex; flex-wrap: wrap; align-content: flex-start; gap: 4px; font-size: 13px; }
.meta .state { color: var(--muted); width: 100%; }
.meta .hist-link { width: 100%; text-align: left; font-size: 12px; color: var(--muted); }
.meta .hist-link:hover { color: var(--accent); }
.conflict-box { grid-column: 1 / -1; padding: 6px 0 0; }
.typed { margin: 4px 0; padding: 4px 8px; background: #fff; border: 1px dashed var(--err); }

/* метка источника перевода */
.badge { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; background: #e5e7eb; color: #374151; }
.o-machine { background: #fde8c4; color: #7a4a00; }
.o-memory { background: #d6e9ff; color: #0b3d91; }
.o-glossary { background: #e5d9fb; color: #4a2a8a; }
.o-hand { background: #d9f2df; color: #14532d; }
.o-replace { background: #fdd9e4; color: #8a1c46; }
.o-revert { background: #e5e7eb; color: #374151; }

.pager { display: flex; align-items: center; justify-content: center; gap: 12px; padding: 12px; }

.side { overflow-y: auto; background: var(--panel); border-left: 1px solid var(--line); padding: 10px; }
.hist { padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.hist-head { display: flex; flex-direction: column; gap: 2px; align-items: flex-start; margin-bottom: 4px; }
.hist-line { white-space: pre-wrap; overflow-wrap: anywhere; }

/* панель замены */
.rpanel { position: fixed; top: 52px; right: calc(var(--w-side, 320px) + 10px); width: 640px; max-width: calc(100vw - 600px); max-height: calc(100vh - 70px); overflow-y: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 8px 28px rgba(0, 0, 0, .18); padding: 14px; z-index: 10; }
.rform { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; margin: 10px 0; }
.rform label { display: block; }
.rform input[type=text], .rform select { display: block; width: 100%; padding: 5px 8px; border: 1px solid var(--line); border-radius: 6px; font: inherit; }
.check { display: inline-flex; align-items: center; gap: 4px; margin-right: 12px; }
.rparts { max-height: 90px; overflow-y: auto; margin: 4px 0 8px; }
.rbtns { display: flex; gap: 8px; margin: 8px 0; }
.rresult { margin: 6px 0; }
.rlist { max-height: 260px; overflow-y: auto; border: 1px solid var(--line); border-radius: 6px; }
.rlist:empty { display: none; }
.ritem { display: flex; gap: 8px; padding: 6px 8px; border-bottom: 1px solid #eceff3; }
.ritem .was { color: var(--muted); white-space: pre-wrap; overflow-wrap: anywhere; }
.ritem .became { white-space: pre-wrap; overflow-wrap: anywhere; }
.op { padding: 4px 0; font-size: 13px; }
.op.undone { color: var(--muted); }

@media (max-width: 1500px) {
  #editor { --w-parts: 220px; --w-side: 280px; }
  .row { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 190px; }
}

.mark-chip { display: inline-block; padding: 0 5px; margin: 0 1px; border-radius: 8px; background: #e3e9f3; color: #2b4a7a; font-size: 0.8em; line-height: 1.5; vertical-align: baseline; white-space: nowrap; }
.mark-chip.clickable { cursor: pointer; background: #d4e1f7; }
.mark-chip.clickable:hover { background: var(--accent); color: #fff; }
.row.has-mark-problems { border-left-color: #c0392b; }
.mark-problems { grid-column: 1 / -1; color: #b3261e; font-size: 0.9em; padding: 2px 0 0; }

/* окно замены: выбор всех, ссылка на глоссарий в верхней полосе */
.rselbar { display: flex; align-items: center; gap: 12px; margin: 4px 0; font-size: 13px; }
.linkbtn { padding: 0; border: 0; background: none; font: inherit; color: var(--accent); cursor: pointer; text-decoration: underline; }
.glossary-links { display: inline-flex; gap: 10px; }

/* вид окна: расположение строки и место истории (классы на #editor ставит editor.js) */
.layout { grid-template-areas: "parts center side"; }
.parts { grid-area: parts; } .center { grid-area: center; } .side { grid-area: side; }
.row { grid-template-areas: "src tgt meta"; }
.row > .source { grid-area: src; } .row > .target { grid-area: tgt; } .row > .meta { grid-area: meta; }
.rows-stack .row { grid-template-columns: minmax(0, 1fr) 220px; grid-template-areas: "src meta" "tgt meta"; }
.rows-stack .row > .target { padding-top: 4px; border-top: 1px dashed var(--line); }
.hist-bottom .layout { grid-template-columns: var(--w-parts) minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) 30%;
  grid-template-areas: "parts center" "parts side"; }
.hist-bottom .side { border-left: 0; border-top: 2px solid var(--line); }
.hist-bottom .rpanel { right: 14px; max-width: calc(100vw - 300px); }
.view-btn { white-space: nowrap; }
.export-btn { white-space: nowrap; text-decoration: none; }
.fn-item { margin-bottom: 10px; }
.fn-src { margin-bottom: 6px; padding: 6px 8px; background: #f4f6f9; border-radius: 6px; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 13px; }
.fn-btns { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.fn-box hr { border: 0; border-top: 1px solid var(--line); margin: 8px 0; }
@media (max-width: 1500px) {
  .rows-stack .row { grid-template-columns: minmax(0, 1fr) 190px; }
}
/* скрытые боковые панели: место отдаётся тексту (после правил ширины, чтобы их перекрыть) */
#editor.parts-hidden { --w-parts: 0px; }
#editor.parts-hidden .parts { display: none; }
#editor.hist-hidden { --w-side: 0px; }
#editor.hist-hidden .side { display: none; }

/* страница «Глоссарий» */
.glossary-page #glossary { display: flex; flex-direction: column; height: 100vh; }
.selbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 6px 14px; background: #f8fafc; border-bottom: 1px solid var(--line); }
.sel-info { font-weight: 600; min-width: 130px; }
.g-result { color: var(--text); }
.g-layout { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) 340px; }
.g-center { overflow-y: auto; overflow-x: hidden; padding: 0 0 8px; }
.g-side { overflow-y: auto; }
.g-msg { padding: 4px 14px; }
.g-msg:empty { display: none; }

.trow { display: grid; align-items: start; gap: 8px; padding: 6px 12px; background: var(--panel); border-bottom: 1px solid #eceff3;
  grid-template-columns: 28px 90px minmax(160px, 1.1fr) 90px minmax(0, 2fr) 270px 112px 296px;
  grid-template-areas: "chk cat term occ cands field status btns"; }
.trow > * { min-width: 0; }
.trow .c-chk { grid-area: chk; } .trow .c-cat { grid-area: cat; } .trow .c-term { grid-area: term; }
.trow .c-occ { grid-area: occ; } .trow .c-cands { grid-area: cands; } .trow .c-field { grid-area: field; }
.trow .c-status { grid-area: status; } .trow .c-btns { grid-area: btns; display: flex; flex-wrap: nowrap; gap: 4px; white-space: nowrap; }
.trow:not(.thead) { cursor: pointer; }
.trow.thead { position: sticky; top: 0; z-index: 2; background: #eef1f5; font-size: 13px; color: var(--muted); cursor: default; align-items: center; }
.trow.has-st { border-left: 5px solid var(--st); background: color-mix(in srgb, var(--st) 10%, white); }
.trow.selected { background: #eef4ff; }
.trow.active { outline: 2px solid var(--accent); outline-offset: -2px; }
.c-cat, .c-occ { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.term-text { font-weight: 600; overflow-wrap: anywhere; }
.term-note { font-size: 12px; overflow-wrap: anywhere; }
.c-cands { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { display: inline-flex; align-items: baseline; gap: 4px; max-width: 100%; padding: 1px 8px; border: 1px solid var(--line); border-radius: 10px; background: #f4f6f9; font: inherit; font-size: 13px; cursor: pointer; color: var(--text); }
.chip:hover { background: #dbeafe; border-color: var(--accent); }
.chip[disabled] { cursor: default; opacity: .7; }
.chip > span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip-text { font-weight: 600; min-width: 0; }
.chip-n { color: var(--muted); flex: none; }
.chip-src { color: var(--muted); font-size: 12px; min-width: 0; max-width: 140px; }
.g-input { display: block; width: 100%; padding: 5px 8px; border: 1px solid var(--line); border-radius: 6px; font: inherit; }
.g-input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.ts-new { background: #e5e7eb; color: #374151; }
.ts-proposed { background: #fde8c4; color: #7a4a00; }
.ts-approved { background: #d9f2df; color: #14532d; }
.ts-keep { background: #d6e9ff; color: #0b3d91; }
.ex { padding: 6px 0; border-bottom: 1px solid #eceff3; font-size: 13px; }
.ex-text { overflow-wrap: anywhere; }
.ex-text mark { background: #fff3a3; }
.ex-q { display: block; width: 100%; padding: 5px 8px; margin: 4px 0; border: 1px solid var(--line); border-radius: 6px; font: inherit; }

@media (max-width: 1600px) {
  .g-layout { grid-template-columns: minmax(0, 1fr) 300px; }
  .trow { grid-template-columns: 28px 80px minmax(140px, 1fr) 84px 240px 104px 286px;
    grid-template-areas: "chk cat term occ field status btns" ". cands cands cands cands cands cands"; }
  .trow.thead { grid-template-areas: "chk cat term occ field status btns"; }
  .trow.thead .c-cands { display: none; }
  .c-cands:empty { display: none; }
}

/* правка и добавление терминов */
.linkbtn.tiny { font-size: 12px; display: block; margin-top: 2px; }
.linkbtn.danger { color: var(--err); margin-top: 6px; }
.error.small { font-size: 12px; }
.edit-form { display: flex; flex-direction: column; gap: 4px; cursor: default; }
.edit-form label { display: flex; flex-direction: column; gap: 2px; font-size: 12px; color: var(--muted); }
.edit-btns { display: flex; gap: 6px; margin-top: 2px; }
.newbox { padding: 8px 14px 10px; background: #f8fafc; border-bottom: 1px solid var(--line); }
.newbox h3 { margin: 0 0 6px; }
.newgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 8px; margin-bottom: 8px; }
.newgrid label { display: flex; flex-direction: column; gap: 2px; font-size: 12px; color: var(--muted); }
.trow.removed { background: #f1f2f4; color: var(--muted); }
.trow.removed .term-text { text-decoration: line-through; }
.ts-removed { background: #e5e7eb; color: #6b7684; }
.hist-note { font-style: italic; }

/* вставить оригинал, пояснение поиска */
.trow .c-field { display: flex; gap: 4px; align-items: flex-start; }
.trow .c-field .g-input { flex: 1; min-width: 0; }
.copy-src { white-space: nowrap; flex: none; }
.cell.target.open .copy-src { margin-top: 4px; }
.small-note { font-size: 12px; margin: 2px 0 6px; }

.btn.danger { color: #b3261e; border-color: #e3b5b1; }
.btn.danger:hover { background: #fdecea; }
