:root {
  --bg: #eef1ef;
  --panel: #ffffff;
  --head: #f6f8f7;
  --line: #e3e7e4;
  --lineStrong: #cfd6d1;
  --ink: #1f2a24;
  --muted: #6b776f;
  --accent: #2f7d4f;
  --accentDark: #24623d;
  --accentSoft: #e8f3ec;
  --amber: #b46a12;
  --danger: #b3261e;
  --radius: 8px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
}

.noSelect { user-select: none; }
.muted { color: var(--muted); font-size: 12px; }

/* ================= ВЕРХНЯЯ ПАНЕЛЬ ================= */
#topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 48px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  z-index: 1000;
}
.brand {
  font-weight: 700;
  font-size: 17px;
  color: var(--accentDark);
  letter-spacing: .01em;
  margin-right: 10px;
}
.toolGroup { display: flex; align-items: center; gap: 4px; }
.toolSep { width: 1px; height: 24px; background: var(--line); margin: 0 6px; }
.toolSpacer { flex: 1 1 auto; }

.tool {
  height: 34px;
  min-width: 34px;
  padding: 0 8px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: #33443a;
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background .12s, border-color .12s, opacity .12s;
}
.tool:hover { background: #eef3ef; border-color: var(--line); }
.tool.btnOn { opacity: 1; }
.tool.btnOff { opacity: .35; }
.tool.btnAct { background: var(--accentSoft); border-color: var(--accent); color: var(--accentDark); }
.toolText { font-size: 12px; font-weight: 700; letter-spacing: .03em; padding: 0 12px; }

.statusText { color: var(--muted); font-size: 12px; margin-left: 14px; white-space: nowrap; }

/* ================= РАБОЧАЯ ОБЛАСТЬ ================= */
#workspace {
  position: fixed;
  top: 48px; left: 0; right: 0; bottom: 0;
  display: flex;
  align-items: stretch;
  overflow: hidden;
  background: var(--bg);
}
.panel {
  flex: 0 0 auto;
  min-width: 0;
  height: 100%;
  background: var(--panel);
  overflow: hidden;
}
.panelScroll { overflow: auto; }
.panelFlex { display: flex; flex-direction: column; }
.panelMap { overflow: hidden; padding: 0; }

.divFrame {
  flex: 0 0 6px;
  cursor: col-resize;
  background: var(--line);
  transition: background .12s;
}
.divFrame:hover { background: var(--accent); }

/* ================= СПИСОК ОПИСАНИЙ ================= */
.gbo {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  font-size: 13px;
  color: var(--ink);
}
.gbo:hover { background: #f3f7f4; }
.gboOff { background: var(--panel); }
.gboOn {
  background: var(--accentSoft);
  border-left: 3px solid var(--accent);
  font-weight: 600;
  padding-left: 9px;
}
.gboName { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gboPage {
  flex: 0 0 auto;
  padding: 1px 7px;
  border-radius: 10px;
  background: var(--accentSoft);
  color: var(--accentDark);
  font-size: 11px;
  font-weight: 600;
}

/* ================= ФОРМА ОПИСАНИЯ ================= */
.strings {
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 30px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  overflow: hidden;
}
.string-head {
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 6px 10px;
  background: var(--head);
  border-top: 1px solid var(--line);
  font-size: 13px;
  font-weight: 600;
  color: var(--accentDark);
}
.string-name {
  flex: 0 0 40%;
  display: flex;
  align-items: center;
  padding: 6px 10px;
  color: #3d4b43;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.string-input,
.string-textarea {
  flex: 1 1 auto;
  min-width: 0;
  margin: 5px 10px;
  padding: 6px 10px;
  border: 1px solid var(--lineStrong);
  border-radius: 6px;
  background: #fff;
  font: 14px/1.35 "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  color: var(--ink);
  outline: none;
  transition: border-color .12s, box-shadow .12s;
}
.string-input:hover, .string-textarea:hover { border-color: #b9c4bc; }
.string-input:focus, .string-textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accentSoft);
}
.strings-multiline { align-items: stretch; }
.strings-multiline .string-name { padding-top: 13px; }
.string-textarea {
  resize: vertical;
  min-height: 76px;
  font-family: inherit;
  line-height: 1.45;
}
input[readonly], textarea[readonly] { background: #f7f8f7; color: #4a564e; }

.cells {
  display: inline-block;
  height: 28px;
  margin: 2px 0;
  padding: 3px 6px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--panel);
  font: 13px/1.2 "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  color: var(--ink);
  text-align: center;
  outline: none;
  overflow: hidden;
}
.cells:focus { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accentSoft); }
.cell-head {
  background: var(--head);
  border-color: transparent;
  font-family: inherit;
  font-weight: 600;
  color: var(--muted);
}
/* Заголовок всегда readOnly — сохраняем его вид, а не вид поля. */
input.cell-head[readonly] { background: var(--head); color: var(--muted); }
.cell-head:focus { border-color: transparent; box-shadow: none; }
.btnAddLine {
  width: 100%;
  padding: 7px;
  border: none;
  background: var(--accentSoft);
  color: var(--accentDark);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.btnAddLine:hover { background: #dcece2; }
.btn-mini {
  flex: 0 0 auto;
  width: 26px;
  height: 26px;
  border: 1px solid var(--lineStrong);
  border-radius: 6px;
  background: var(--panel);
  color: var(--accentDark);
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.btn-mini:hover { background: var(--accentSoft); border-color: var(--accent); }

#divSave {
  display: flex;
  width: 100%;
  min-height: 52px;
  margin-top: 22px;
  border-top: 1px solid var(--line);
  background: var(--head);
}
.btnSaveDescription {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 12px;
  border: none;
  border-right: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
}
.btnSaveDescription:first-child { background: var(--accent); color: #fff; }
.btnSaveDescription:first-child:hover { background: var(--accentDark); }
.btnSaveDescription:hover { background: #eef3ef; }

/* ================= КАРТА ================= */
#map { width: 100%; height: 100%; }
.leaflet-container { font-size: 12px; }

/* ================= ПАНЕЛЬ PDF ================= */
.panelHead {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--head);
  font-size: 13px;
  font-weight: 600;
  color: var(--accentDark);
  white-space: nowrap;
  overflow: hidden;
}
.panelTitle { flex: 0 0 auto; }
.panelHead #pdfName {
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: right;
}
.pdfUsed { flex: 0 0 auto; font-size: 11px; font-weight: 600; color: var(--muted); }
.pdfUsed.pdfUsedOn {
  color: var(--accentDark);
  background: var(--accentSoft);
  padding: 2px 8px;
  border-radius: 10px;
}
.panelFoot {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 6px 8px;
  border-top: 1px solid var(--line);
  background: var(--head);
  flex-wrap: wrap;
}
.footSpacer { flex: 1 1 auto; }
.pdfWrap {
  flex: 1 1 auto;
  position: relative;
  overflow: auto;
  padding: 10px;
  background: #e7ebe8;
}
.pdfWrap.pdfScrollable { cursor: grab; }
.pdfWrap.pdfPanning { cursor: grabbing; }
.pdfWrap.pdfPanning #pdfCanvas { cursor: grabbing; }
#pdfCanvas {
  display: none;
  margin: 0 auto;
  background: #fff;
  box-shadow: 0 2px 12px rgba(0,0,0,.18);
}
.pdfWrap.hasPdf #pdfCanvas { display: block; }
.placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
  overflow: auto;
}
.placeholderBox {
  max-width: 340px;
  padding: 20px 22px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 8px 26px rgba(0, 0, 0, .07);
  text-align: left;
}
.placeholderTitle {
  font-size: 16px;
  font-weight: 700;
  color: var(--accentDark);
  margin-bottom: 10px;
}
.placeholderBox p { margin: 0 0 10px; font-size: 13px; line-height: 1.45; color: var(--ink); }
.placeholderBox code {
  padding: 1px 5px;
  background: var(--head);
  border: 1px solid var(--line);
  border-radius: 4px;
  font-size: 12px;
}
.miniBtn {
  height: 28px;
  min-width: 28px;
  padding: 0 7px;
  border: 1px solid var(--lineStrong);
  border-radius: 6px;
  background: var(--panel);
  color: var(--ink);
  font-size: 13px;
  cursor: pointer;
}
.miniBtn:hover { background: var(--accentSoft); border-color: var(--accent); }
.pageInput {
  width: 54px;
  height: 28px;
  padding: 0 4px;
  border: 1px solid var(--lineStrong);
  border-radius: 6px;
  text-align: center;
  font-size: 13px;
}

/* ================= АВТОДОПОЛНЕНИЕ ================= */
.autocomplete {
  position: fixed;
  z-index: 2000;
  max-height: 240px;
  overflow: auto;
  background: #fff;
  border: 1px solid var(--lineStrong);
  border-radius: 8px;
  box-shadow: 0 12px 30px rgba(0,0,0,.18);
}
.autocomplete-item { padding: 5px 10px; cursor: pointer; font: italic 13px/1.3 Georgia, serif; }
.autocomplete-item:hover, .autocomplete-item.active { background: var(--accentSoft); }

/* ================= МОДАЛЬНЫЕ ОКНА ================= */
.modal {
  width: min(760px, 92vw);
  max-height: 88vh;
  padding: 0;
  border: none;
  border-radius: 14px;
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 24px 70px rgba(0,0,0,.30);
  overflow: hidden;
}
.modalWide { width: min(680px, 92vw); }
.modal::backdrop { background: rgba(20, 30, 24, .45); }
.modalHead {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
}
.modalHead h2 { margin: 0; font-size: 18px; color: var(--ink); }
.modalClose {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
}
.modalClose:hover { color: var(--ink); }
.modalHint { margin: 12px 20px 0; color: var(--muted); font-size: 13px; }
.modalBody { padding: 16px 20px; overflow: auto; max-height: calc(88vh - 150px); }
.modalFoot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 20px;
  border-top: 1px solid var(--line);
  background: var(--head);
}
.btnPrimary {
  padding: 9px 18px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.btnPrimary:hover { background: var(--accentDark); }
.btnGhost {
  padding: 9px 18px;
  border: 1px solid var(--lineStrong);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  font-size: 14px;
  cursor: pointer;
}
.btnGhost:hover { background: #eef3ef; }

/* ================= НАСТРОЙКИ ================= */
.customsBlock { margin-bottom: 18px; }
.customsBlockHead {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--accentDark);
  cursor: pointer;
}
.customsGrid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 3px 18px;
  margin-left: 8px;
}
.customsField {
  display: grid;
  grid-template-columns: 18px 1fr 110px;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--ink);
}
.customsName { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.customsDef {
  width: 100%;
  padding: 3px 6px;
  border: 1px solid var(--line);
  border-radius: 5px;
  font-size: 12px;
  color: var(--ink);
}
.customsDef:focus { outline: none; border-color: var(--accent); }

/* ================= СПРАВКА ================= */
.helpHead { font-size: 26px; font-weight: 700; color: var(--accentDark); text-align: center; }
.helpSub { text-align: center; color: var(--muted); margin: 2px 0; }
.helpVersion { text-align: center; font-size: 12px; color: var(--muted); margin-bottom: 14px; }
.helpKeys { display: grid; grid-template-columns: 1fr 1fr; gap: 7px 18px; margin: 14px 0; }
.helpKey { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.keycap {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  height: 28px;
  padding: 0 7px;
  background: var(--head);
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink);
}
.modalBody a { color: var(--accentDark); }
.modalBody code {
  padding: 1px 5px;
  background: var(--head);
  border: 1px solid var(--line);
  border-radius: 4px;
  font-size: 12px;
}
