/* =========================================================================
   Raschet — стили
   ========================================================================= */
* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  font-family: -apple-system, "Segoe UI", Roboto, sans-serif;
  color: #222;
  background: #f4f5f7;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
body {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}
/* Освобождаем 32 px снизу под фиксированный module-footer (.rs-mfoot),
   чтобы вкладки страниц (.page-tabs, bottom:0 в #canvas-wrap) и нижний
   край инспектора не перекрывались строкой версии/changelog. Класс
   body.rs-with-mfoot добавляется mountFooter() в module-footer.js. */
body.rs-with-mfoot {
  padding-bottom: 32px;
}
button { font: inherit; cursor: pointer; }
input, select { font: inherit; }
.hidden { display: none !important; }
.muted { color: #9aa3b5; font-size: 13px; }

/* v0.59.685: Иконка «?» с подсказкой/справкой по параметру.
   Пользователь: «подсказки и справку показывай только в всплывающем окне
   над параметром или над знаком вопроса в кружке после названия параметра».
   Используется через helpIcon(tip) из js/engine/utils.js. Tooltip — нативный
   браузерный (атрибут title). */
.help-icon {
  display: inline-block;
  width: 14px;
  height: 14px;
  line-height: 14px;
  text-align: center;
  background: #bbdefb;
  color: #1565c0;
  border-radius: 50%;
  font-size: 10px;
  font-weight: 700;
  margin-left: 4px;
  cursor: help;
  user-select: none;
  vertical-align: middle;
  font-family: -apple-system, sans-serif;
}
.help-icon:hover, .help-icon:focus {
  background: #90caf9;
  outline: none;
}

/* v0.59.713: кликабельные строки чеклиста проектирования */
.checklist-row {
  border-radius: 3px;
  padding: 2px 4px;
  margin: 0 -4px;
  transition: background 0.1s;
}
.checklist-row:hover {
  background: rgba(0, 0, 0, 0.04);
}

/* ================= Header ================= */
#header {
  flex: none;
  height: 56px;
  background: #fff;
  border-bottom: 1px solid #e0e3ea;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  gap: 12px;
  z-index: 100;
}
.hdr-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.hdr-right { display: flex; align-items: center; gap: 8px; }
.hdr-title {
  font-size: 18px;
  font-weight: 700;
  color: #1f2430;
  letter-spacing: 0.3px;
}
.hdr-project {
  color: #5a6271;
  font-size: 14px;
  padding-left: 12px;
  border-left: 1px solid #e0e3ea;
  max-width: 40vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.icon-btn {
  width: 36px;
  height: 36px;
  border: 1px solid #e0e3ea;
  background: #fafbfc;
  border-radius: 6px;
  color: #5a6271;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:hover { background: #eef1f5; }
.hdr-btn {
  padding: 8px 14px;
  border: 1px solid #e0e3ea;
  background: #fff;
  border-radius: 6px;
  color: #2b303b;
  font-size: 13px;
  font-weight: 500;
}
.hdr-btn:hover { background: #f4f6f9; }
.hdr-btn.primary { background: #1976d2; color: #fff; border-color: #1976d2; }
.hdr-btn.primary:hover { background: #1565c0; }
.hdr-btn.disabled { opacity: 0.5; cursor: not-allowed; }

/* Индикаторы состояния автосохранения на кнопке «Сохранить» */
.hdr-btn.dirty { background: #ef6c00; border-color: #ef6c00; }
.hdr-btn.dirty:hover { background: #e65100; }
.hdr-btn.saving { background: #607d8b; border-color: #607d8b; cursor: wait; }
.hdr-btn.saved { background: #43a047; border-color: #43a047; }
.hdr-btn.save-error { background: #c62828; border-color: #c62828; }

.notif-btn { position: relative; }
.notif-badge {
  position: absolute;
  top: -3px;
  right: -3px;
  background: #e53935;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #fff;
  line-height: 1;
  box-sizing: content-box;
}

/* User menu */
.user-menu { position: relative; }
.user-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px 4px 4px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 999px;
  color: #2b303b;
}
.user-btn:hover { border-color: #e0e3ea; background: #fafbfc; }
.user-btn img, .user-btn .avatar-letter {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: #9c27b0;
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 14px;
  object-fit: cover;
}
.user-name {
  font-size: 13px;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.user-dropdown {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 6px;
  background: #fff;
  border: 1px solid #e0e3ea;
  border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.12);
  min-width: 220px;
  padding: 8px 0;
  display: none;
  z-index: 110;
}
.user-menu.open .user-dropdown { display: block; }
.udd-info { padding: 8px 14px; border-bottom: 1px solid #eef0f4; }
.udd-name { font-weight: 600; font-size: 13px; }
.udd-email { font-size: 12px; color: #8a93a7; }
.udd-item {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  padding: 10px 14px;
  font-size: 13px;
  color: #2b303b;
}
.udd-item:hover { background: #f4f6f9; }

/* ================= Screens ================= */
.screen {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  position: relative;
}
.center-box {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  color: #5a6271;
}
.spinner {
  width: 40px; height: 40px;
  border: 3px solid #e0e3ea;
  border-top-color: #1976d2;
  border-radius: 50%;
  margin: 0 auto 12px;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ================= Projects screen ================= */
#screen-projects {
  overflow-y: auto;
  background: #f4f5f7;
}
.projects-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 32px 24px 80px;
}
.projects-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  gap: 16px;
  flex-wrap: wrap;
}
.projects-header h1 { font-size: 28px; margin: 0; color: #1f2430; }
.projects-toolbar { display: flex; gap: 8px; flex-wrap: wrap; }
.projects-toolbar button {
  padding: 9px 16px;
  border: 1px solid #e0e3ea;
  background: #fff;
  color: #2b303b;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
}
.projects-toolbar button:hover { background: #f4f6f9; }
.projects-toolbar button.primary { background: #1976d2; color: #fff; border-color: #1976d2; }
.projects-toolbar button.primary:hover { background: #1565c0; }

.projects-tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid #e0e3ea;
  margin-bottom: 20px;
  overflow-x: auto;
}
.tab {
  background: transparent;
  border: none;
  padding: 12px 18px;
  font-size: 14px;
  color: #5a6271;
  position: relative;
  white-space: nowrap;
}
.tab:hover { color: #1f2430; }
.tab.active { color: #1976d2; font-weight: 600; }
.tab.active::after {
  content: '';
  position: absolute;
  left: 12px; right: 12px; bottom: -1px;
  height: 2px;
  background: #1976d2;
}
.count {
  display: inline-block;
  background: #ef6c00;
  color: #fff;
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 10px;
  margin-left: 6px;
  font-weight: 600;
}

.projects-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}
.project-card {
  background: #fff;
  border: 1px solid #e0e3ea;
  border-radius: 10px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.project-card:hover { border-color: #cbd0d9; box-shadow: 0 4px 12px rgba(0,0,0,0.05); }
.pc-head { display: flex; justify-content: space-between; align-items: start; gap: 10px; }
.pc-name {
  font-size: 15px;
  font-weight: 600;
  color: #1f2430;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.pc-role {
  font-size: 10px;
  padding: 3px 8px;
  border-radius: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  flex: none;
}
.pc-role-owner  { background: #e8f5e9; color: #2e7d32; }
.pc-role-editor { background: #fff3e0; color: #ef6c00; }
.pc-role-viewer { background: #e3f2fd; color: #1565c0; }
.pc-meta {
  font-size: 11px;
  color: #8a93a7;
}
.pc-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.pc-actions button {
  background: #fafbfc;
  border: 1px solid #e0e3ea;
  border-radius: 5px;
  padding: 6px 12px;
  font-size: 12px;
  color: #2b303b;
}
.pc-actions button:hover { background: #eef1f5; }
.pc-actions .pc-open {
  background: #1976d2;
  color: #fff;
  border-color: #1976d2;
}
.pc-actions .pc-open:hover { background: #1565c0; }
.pc-actions .pc-delete { color: #c62828; border-color: #f4bebe; }
.pc-actions .pc-delete:hover { background: #fde8e8; }

.projects-empty {
  text-align: center;
  padding: 60px 20px;
  color: #8a93a7;
  font-size: 14px;
}

/* Access request cards */
.req-card {
  background: #fff;
  border: 1px solid #e0e3ea;
  border-radius: 10px;
  padding: 14px 16px;
  margin-bottom: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.req-title { font-weight: 600; font-size: 14px; }
.req-sub { font-size: 12px; color: #8a93a7; }
.req-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.req-actions button {
  padding: 7px 12px;
  border: 1px solid #e0e3ea;
  background: #fff;
  border-radius: 5px;
  font-size: 12px;
}
.req-actions .btn-approve { background: #e8f5e9; color: #2e7d32; border-color: #bfe3c4; }
.req-actions .btn-deny { color: #c62828; border-color: #f4bebe; }

/* ================= Editor screen ================= */
#screen-editor {
  background: #fafbfc;
}
#screen-editor #app {
  display: grid;
  /* Ширина палитры регулируется через CSS variable --palette-w (по умолчанию 320px) */
  grid-template-columns: var(--palette-w, 320px) 1fr 300px;
  height: 100%;
}

/* ---------- Palette (left) ---------- */
#palette {
  position: relative;
  background: #1f2430;
  color: #d9dde5;
  padding: 16px 14px;
  overflow-y: auto;
  border-right: 1px solid #141822;
}
/* Ручка ресайза — узкая полоска по правому краю */
#palette-resizer {
  position: absolute;
  top: 0; right: 0;
  width: 5px;
  height: 100%;
  cursor: ew-resize;
  background: transparent;
  transition: background .15s;
  z-index: 20;
}
#palette-resizer:hover,
#palette-resizer.dragging { background: #2979ff; }
#palette .brand { font-size: 20px; font-weight: 700; color: #fff; letter-spacing: 0.5px; }
#palette .subtitle { font-size: 11px; color: #7d8597; margin-bottom: 18px; text-transform: uppercase; letter-spacing: 0.8px; }
#palette h3 { font-size: 11px; font-weight: 600; color: #9aa3b5; text-transform: uppercase; margin: 18px 0 8px; letter-spacing: 0.8px; }

.pal-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: #2a3140;
  border: 1px solid #353c4d;
  border-radius: 6px;
  margin-bottom: 6px;
  font-size: 13px;
  cursor: grab;
  user-select: none;
  transition: background .12s, border-color .12s;
}
.pal-item:hover { background: #323a4d; border-color: #4a5369; }
.pal-item:active { cursor: grabbing; }
.pal-item .chip { width: 14px; height: 14px; border-radius: 3px; display: inline-block; }
.chip.src { background: #4caf50; }
.chip.gen { background: #ff9800; }
.chip.pnl { background: #607d8b; }
.chip.ups { background: #9c27b0; }
.chip.cns { background: #1976d2; }
.chip.chn { background: #795548; }
.chip.zne { background: #00838f; }
.chip.utl { background: #455a64; }

/* Расширяемая группа палитры (burger) */
.pal-group { margin-bottom: 6px; }
.pal-item.pal-item-head { margin-bottom: 0; position: relative; }
.pal-item.pal-item-head .pal-expand {
  margin-left: auto;
  background: transparent;
  border: none;
  color: #9aa3b5;
  cursor: pointer;
  font-size: 14px;
  padding: 2px 6px;
  line-height: 1;
  border-radius: 3px;
}
.pal-item.pal-item-head .pal-expand:hover { background: #353c4d; color: #fff; }
.pal-group.expanded .pal-expand { transform: rotate(90deg); display: inline-block; }
.pal-sub {
  display: none;
  margin: 4px 0 6px 14px;
  padding-left: 10px;
  border-left: 2px solid #3a4150;
}
.pal-group.expanded .pal-sub { display: block; }
.pal-item.pal-item-sub {
  padding: 7px 10px;
  margin-bottom: 4px;
  font-size: 12px;
  background: #242a37;
}
.pal-item.pal-item-sub:hover { background: #2c3444; }
.pal-item.pal-item-sub .pal-sub-icon {
  width: 10px; height: 10px; border-radius: 50%;
  display: inline-block; margin-right: 4px;
}
.pal-sub-icon.src { background: #4caf50; }
.pal-sub-icon.utl { background: #455a64; }
.pal-sub-icon.oth { background: #8a94a6; }

/* Модалка управления ИБП */
.ups-ctl-grid { display: flex; flex-direction: column; gap: 6px; }
.ups-ctl-row {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 12px;
  background: #f5f7fa;
  border: 1px solid #e0e3ea;
  border-radius: 5px;
  font-size: 13px;
}
.ups-ctl-label { flex: 1; font-weight: 600; color: #2b303b; }
.ups-ctl-nominal { min-width: 110px; color: #546e7a; font-size: 12px; }
.ups-ctl-current { min-width: 130px; color: #1565c0; font-size: 12px; }
.ups-ctl-toggle {
  min-width: 70px;
  padding: 6px 12px;
  border-radius: 4px;
  border: 1px solid transparent;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  color: #fff;
}
.ups-ctl-toggle.on { background: #43a047; border-color: #2e7d32; }
.ups-ctl-toggle.on:hover { background: #388e3c; }
.ups-ctl-toggle.off { background: #9aa3b5; border-color: #78859c; }
.ups-ctl-toggle.off:hover { background: #78859c; }

.ups-modules {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  gap: 6px;
}
.ups-module {
  padding: 10px;
  text-align: center;
  font-size: 12px;
  font-weight: 700;
  border: 2px solid transparent;
  border-radius: 4px;
  cursor: pointer;
}
.ups-module.on { background: #c8e6c9; border-color: #43a047; color: #1b5e20; }
.ups-module.on:hover { background: #a5d6a7; }
.ups-module.off { background: #eceff1; border-color: #b0bec5; color: #78849d; }
.ups-module.off:hover { background: #cfd8dc; }
.ups-module .muted { font-size: 10px; font-weight: 400; display: block; color: inherit; opacity: 0.7; }

/* Поиск по библиотеке */
.pal-search-wrap { margin: 4px 0 10px; }
#palette-search {
  width: 100%;
  background: #1d222d;
  border: 1px solid #353c4d;
  border-radius: 6px;
  padding: 7px 10px;
  color: #cfd4e0;
  font-size: 12px;
  outline: none;
}
#palette-search:focus { border-color: #2979ff; }
#palette-search::placeholder { color: #6b7280; }

/* Секции по типам (collapsible) */
.pal-type { margin-bottom: 8px; }
.pal-type-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 4px;
  font-size: 11px;
  font-weight: 700;
  color: #9aa3b5;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  cursor: pointer;
  user-select: none;
  border-bottom: 1px solid #2a3140;
}
.pal-type-head:hover { color: #cfd4e0; }
.pal-type-head .chip { width: 10px; height: 10px; border-radius: 2px; }
.pal-type-head .pal-type-arrow { margin-left: auto; font-size: 10px; color: #6b7280; }
.pal-type.collapsed .pal-type-head .pal-type-arrow { transform: rotate(-90deg); display: inline-block; }
.pal-type-items { padding: 6px 0 2px; }
.pal-type.collapsed .pal-type-items { display: none; }
.pal-type.hidden { display: none; }

/* Пресеты внутри секции */
.pal-presets { display: flex; flex-direction: column; gap: 4px; margin-top: 2px; }
.pal-preset {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  background: #242a37;
  border: 1px solid #2f3646;
  border-radius: 5px;
  font-size: 12px;
  cursor: grab;
  user-select: none;
}
.pal-preset:hover { background: #2c3444; border-color: #3d4560; }
.pal-preset:active { cursor: grabbing; }
.pal-preset .pp-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #cfd4e0; }
.pal-preset .pp-meta { font-size: 10px; color: #6b7280; margin-left: 4px; }
.pal-preset .pp-actions {
  display: none;
  gap: 2px;
  margin-left: 4px;
}
.pal-preset:hover .pp-actions { display: flex; }
.pal-preset .pp-btn {
  background: transparent;
  border: none;
  color: #9aa3b5;
  cursor: pointer;
  padding: 2px 5px;
  border-radius: 3px;
  font-size: 11px;
  line-height: 1;
}
.pal-preset .pp-btn:hover { background: #353c4d; color: #fff; }
.pal-preset .pp-btn.pp-del:hover { background: #4a1c1c; color: #ff8a80; }
.pal-preset.user-preset { border-left: 2px solid #2979ff; }
.pal-preset.hidden { display: none; }
.pal-item.hidden { display: none; }

.stats {
  font-size: 12px;
  color: #c3c9d6;
  background: #2a3140;
  border-radius: 6px;
  padding: 10px 12px;
  border: 1px solid #353c4d;
  line-height: 1.7;
}
.stats .row { display: flex; justify-content: space-between; }
.stats .warn { color: #ff7373; font-weight: 600; }
.stats .ok { color: #7ddc7d; }

.hints { margin: 0; padding-left: 18px; font-size: 11px; color: #8a93a7; line-height: 1.6; }
.hints li { margin-bottom: 4px; }

/* Modes list */
#modes-list { margin-bottom: 8px; }
.mode-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  background: #2a3140;
  border: 1px solid #353c4d;
  border-radius: 5px;
  margin-bottom: 4px;
  font-size: 12px;
}
.mode-row.active { background: #34506b; border-color: #1976d2; }
.mode-row input[type=radio] { margin: 0; cursor: pointer; accent-color: #1976d2; }
.mode-row input.mode-name {
  flex: 1;
  background: transparent;
  border: none;
  color: #e6eaf2;
  font: inherit;
  padding: 2px 4px;
  min-width: 0;
  border-radius: 3px;
}
.mode-row input.mode-name:focus { background: #1f2430; outline: 1px solid #4a5369; }
.mode-row .mode-del {
  background: transparent;
  border: none;
  color: #7d8597;
  font-size: 14px;
  line-height: 1;
  padding: 2px 5px;
  border-radius: 3px;
  cursor: pointer;
}
.mode-row .mode-del:hover { color: #ff7373; background: #3a2a30; }
.mode-row .mode-del[disabled] { visibility: hidden; }
.full-btn {
  width: 100%;
  padding: 7px;
  background: #2a3140;
  border: 1px dashed #4a5369;
  color: #a9b2c5;
  font-size: 12px;
  border-radius: 5px;
  margin-bottom: 4px;
}
.full-btn:hover { background: #323a4d; color: #fff; border-color: #6a7388; }

/* ---------- Canvas (center) ---------- */
#canvas-wrap { position: relative; background: #fafbfc; overflow: hidden; }
#toolbar {
  position: absolute;
  top: 12px; left: 12px;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 6px;
  background: #fff;
  padding: 6px 8px;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08), 0 0 0 1px rgba(0,0,0,0.04);
  flex-wrap: wrap;
  max-width: calc(100% - 24px);
}
#toolbar button {
  background: #f4f5f7;
  border: 1px solid #dfe2e8;
  border-radius: 5px;
  padding: 6px 10px;
  font-size: 12px;
  color: #2b303b;
}
#toolbar button:hover { background: #e8ebf0; }
#toolbar button:disabled { opacity: 0.35; cursor: not-allowed; background: #f4f5f7; }
#toolbar button:disabled:hover { background: #f4f5f7; }
#toolbar button.danger { color: #c62828; }
#toolbar button.danger:hover { background: #fde8e8; border-color: #f4bebe; }
#toolbar .sep { width: 1px; height: 20px; background: #e0e3ea; margin: 0 2px; }
#btn-undo, #btn-redo { font-size: 15px; line-height: 1; min-width: 28px; }

/* Группировка команд в тулбаре */
#toolbar .tb-toggle {
  background: #eef1f6 !important;
  font-size: 15px;
  min-width: 32px;
  font-weight: 700;
}
#toolbar .tb-body { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
#toolbar.collapsed .tb-body { display: none; }
#toolbar .tb-group { display: flex; align-items: center; gap: 4px; padding: 2px 4px; border: 1px solid #eef1f6; border-radius: 6px; background: #fafbfd; }
#toolbar .tb-group .tb-head {
  background: transparent !important;
  border: none !important;
  padding: 4px 6px;
  font-size: 11px;
  color: #546e7a;
  font-weight: 600;
  letter-spacing: 0.2px;
}
#toolbar .tb-group .tb-head:hover { color: #2b303b; background: transparent !important; }
#toolbar .tb-group .tb-items { display: flex; align-items: center; gap: 4px; }
#toolbar .tb-group.collapsed .tb-items { display: none; }
#toolbar .tb-group.collapsed .tb-head::after { content: ''; }

#canvas { width: 100%; height: 100%; display: block; cursor: default; touch-action: none; }
#canvas.panning { cursor: grabbing; }
#canvas.connecting { cursor: crosshair; }

/* ---------- Nodes ---------- */
.node { cursor: grab; }
.node.dragging { cursor: grabbing; }
.node-body { stroke-width: 1.5; rx: 8; ry: 8; filter: drop-shadow(0 2px 3px rgba(0,0,0,0.08)); }

.node.source   .node-body { fill: #e8f5e9; stroke: #4caf50; }
.node.generator .node-body { fill: #fff3e0; stroke: #ff9800; }
.node.utility { cursor: move; }
.node.utility .node-tag { font: 700 11px -apple-system, sans-serif; fill: #455a64; text-anchor: middle; }
.node.panel    .node-body { fill: #eceff1; stroke: #607d8b; }
.node.ups      .node-body { fill: #f3e5f5; stroke: #9c27b0; }
/* v0.60.192: интегрированный ИБП (kind='ups-integrated') — секция шкафа MR33
   наряду с PDM-IT/AC/Bypass. Все секции должны выглядеть единообразно
   (как панели), чтобы внутри integrated-ups-shell цвета были консистентные. */
.node.ups.ups-integrated .node-body { fill: #eceff1; stroke: #607d8b; }
.node.consumer .node-body { fill: #e3f2fd; stroke: #1976d2; }
.node.channel  .node-body { fill: #efebe9; stroke: #795548; stroke-dasharray: 4 2; }
.channel-snap-point { cursor: crosshair; pointer-events: all; }
.channel-rotate-handle { cursor: grab; pointer-events: all; }
.channel-rotate-handle:hover { fill: #e65100; r: 6; }
.channel-length-handle { cursor: ns-resize; pointer-events: all; }
.channel-length-handle:hover { fill: #0d47a1; r: 6; }

.node.selected .node-body { stroke-width: 2.5; }
.node.selected.source   .node-body { stroke: #2e7d32; }
.node.selected.generator .node-body { stroke: #ef6c00; }
.node.selected.panel    .node-body { stroke: #37474f; }
.node.selected.ups      .node-body { stroke: #6a1b9a; }
.node.selected.consumer .node-body { stroke: #0d47a1; }

.node.ups.onbattery .node-body { stroke-dasharray: 6 3; }
.node.ups.onbypass .node-body { fill: #fce4ec; stroke: #ec407a; }
.node.panel.manual .node-body { stroke-dasharray: 6 3; }
/* Щит: номинал < макс.тока — красный (перегруз) */
.node.panel.undersize .node-body { fill: #ffebee; stroke: #c62828 !important; stroke-width: 2.2; }
.node.panel.undersize.selected .node-body { stroke: #b71c1c !important; }
/* Щит: номинал > макс.тока на 30%+ — фиолетовый (избыточный запас) */
.node.panel.oversize .node-body { fill: #e3f2fd; stroke: #1565c0 !important; stroke-width: 2.2; }
.node.panel.oversize.selected .node-body { stroke: #0d47a1 !important; }

/* Margin warning badge: yellow triangle with '!' */
.margin-warn-tri {
  fill: #fdd835;
  stroke: #f57f17;
  stroke-width: 1.5;
  stroke-linejoin: round;
  cursor: help;
}
.margin-warn-bang {
  font: 800 11px -apple-system, "Segoe UI", sans-serif;
  fill: #3e2723;
  text-anchor: middle;
  pointer-events: none;
}

/* Zones */
.node.zone .zone-body {
  stroke: #bbb;
  stroke-width: 1;
  stroke-dasharray: 6 4;
  rx: 6;
  ry: 6;
  pointer-events: none;
}
.node.zone .zone-drag-handle {
  fill: transparent;
  cursor: grab;
  pointer-events: all;
}
/* Выделенная зона — толстая рамка и видимые зоны ресайза */
.node.zone.selected .zone-body { stroke-width: 2.5; stroke: #006064; stroke-dasharray: 8 5; }
.zone-resize {
  fill: transparent;
  stroke: none;
  pointer-events: all;
  opacity: 0; /* невидимы по умолчанию */
}
.node.zone.selected .zone-resize { opacity: 1; fill: #00838f; fill-opacity: 0.15; stroke: #00838f; stroke-width: 0.5; }
.zone-prefix, .zone-name {
  pointer-events: none;
}
.zone-prefix {
  font: 700 14px -apple-system, "Segoe UI", sans-serif;
  fill: #888;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}
.node.zone.selected .zone-prefix { fill: #006064; }
.zone-name {
  font: 11px -apple-system, "Segoe UI", sans-serif;
  fill: #999;
}
.node.zone.selected .zone-name { fill: #00838f; }
}

/* Connection waypoints */
.conn-waypoint {
  fill: #1976d2;
  stroke: #fff;
  stroke-width: 2;
  cursor: grab;
}
.conn-waypoint:hover { fill: #0d47a1; r: 6; }
.conn-waypoint-del {
  fill: #fff; stroke: #e53935; stroke-width: 1.5;
  cursor: pointer; opacity: 0.6; pointer-events: all;
}
.conn-waypoint-del:hover { fill: #ffebee; opacity: 1; r: 6; }
.conn-waypoint-del-text {
  font-size: 9px; fill: #e53935; text-anchor: middle;
  pointer-events: none; font-weight: bold;
}
.conn-waypoint-add {
  fill: #fff;
  stroke: #1976d2;
  stroke-width: 1.5;
  stroke-dasharray: 2 2;
  cursor: copy;
}
.conn-waypoint-add:hover { fill: #e3f2fd; }

/* Breaker badge on line near 'from' end */
.breaker-badge {
  font: 700 10px -apple-system, "Segoe UI", sans-serif;
  fill: #ef6c00;
  pointer-events: none;
  text-anchor: middle;
  paint-order: stroke;
  stroke: #fafbfc;
  stroke-width: 3;
  stroke-linejoin: round;
}
.breaker-badge.overload { fill: #c62828; }

/* Full properties block */
.inspector-section.full-props h4 { color: #6b7385; }
.fp-table {
  width: 100%;
  font: 11px ui-monospace, "Cascadia Mono", Consolas, monospace;
  border-collapse: collapse;
}
.fp-table td {
  padding: 3px 6px;
  border-bottom: 1px solid #eef0f4;
  vertical-align: top;
}
.fp-table .fp-k {
  color: #6b7385;
  width: 40%;
  word-break: break-all;
}
.fp-table .fp-v {
  color: #1f2430;
  word-break: break-all;
}
.fp-table .fp-sep {
  color: #9aa3b5;
  text-align: center;
  padding: 6px 0 3px;
  border-bottom: none;
  font-style: italic;
}
.node.overload .node-body { fill: #ffebee; stroke: #c62828 !important; }
.node.unpowered .node-body { fill: #f5f5f5; stroke: #bdbdbd; }
/* v0.60.395: потребитель/контейнер, отключённый Пользователем (тумблер
   «В работе») — серая заливка чуть насыщеннее, чем у unpowered, чтобы
   визуально отличаться от «нет питания». Поверх иконки рисуется знак
   запрета (см. node-icon-banned). */
.node.disabled-by-user .node-body { fill: #e5e7eb; stroke: #94a3b8 !important; stroke-dasharray: 5 3; }
.node.disabled-by-user .node-title,
.node.disabled-by-user .node-sub,
.node.disabled-by-user .node-load { opacity: 0.55; }
.node-icon-banned { pointer-events: none; }
.node-icon-banned circle, .node-icon-banned line { vector-effect: non-scaling-stroke; }
/* v0.60.398: визуал «недостаток резервирования» — оранжевая обводка
   контейнера + жирный warning-stroke. Member в стoby reserve — серый
   пунктир. Member, который должен был работать но не работает (shortage)
   — оранжевая обводка как у контейнера. */
.node.redundancy-shortage .node-body { stroke: #ea580c !important; stroke-width: 2.5; stroke-dasharray: 6 3; }
.node.standby-reserve .node-body { fill: #fef3c7; stroke: #d97706 !important; stroke-dasharray: 4 2; }
.node.standby-reserve .node-title,
.node.standby-reserve .node-sub,
.node.standby-reserve .node-load { opacity: 0.7; }

.node-tag   { font: 700 10px -apple-system, "Segoe UI", sans-serif; fill: #8a93a7; letter-spacing: 0.4px; pointer-events: none; text-transform: uppercase; }
.node-title { font: 600 13px -apple-system, "Segoe UI", sans-serif; fill: #1f2430; pointer-events: none; }
.node-sub   { font: 11px -apple-system, "Segoe UI", sans-serif; fill: #5a6271; pointer-events: none; }
.node-load  { font: 600 11px -apple-system, "Segoe UI", sans-serif; fill: #1976d2; pointer-events: none; }
.node-load.overload { fill: #c62828; }
.node-load.off { fill: #9e9e9e; }
/* v0.59.651: 2-3-строчный блок «текущая/макс/номин» в карточке узла. */
.node-load.node-load-row { font-size: 10px; font-weight: 500; fill: #475569; }
.node-load.node-load-row.overload { fill: #c62828; font-weight: 600; }
.node-load.node-load-status { font-size: 10px; fill: #6b7280; font-style: italic; }
.node-load.node-load-status.off { fill: #9e9e9e; font-style: italic; }
.node-load.node-load-status.overload { fill: #c62828; font-style: italic; font-weight: 600; }

.port {
  fill: #fff;
  stroke: #8a94a6;
  stroke-width: 1.5;
  cursor: crosshair;
}
.port:hover, .port.hot { fill: #1976d2; stroke: #0d47a1; }
.port-label { font: 10px -apple-system, sans-serif; fill: #8a94a6; pointer-events: none; text-anchor: middle; }
.node-icon { pointer-events: none; }
.node-icon-letter { font: 700 12px -apple-system, sans-serif; fill: #ff9800; text-anchor: middle; pointer-events: none; }

/* ---------- Connections ---------- */
.conn {
  fill: none;
  stroke: #b0b5bf;
  stroke-width: 2;
  marker-end: url(#arr);
  cursor: pointer;
}
.conn:hover { stroke: #ef6c00; }
.conn.active {
  stroke: #e53935;
  stroke-width: 2.8;
  marker-end: url(#arrActive);
}
.conn.powered {
  stroke: #e53935;
  stroke-width: 2.4;
  marker-end: url(#arrActive);
}
.conn.dead { stroke: #d0d4db; }
.conn.damaged { stroke: #c62828; stroke-dasharray: 6 4; stroke-width: 2.5; }
.conn.disabled { stroke: #bdbdbd; stroke-width: 1.5; }
.conn.selected { stroke: #2979ff !important; stroke-width: 5; filter: drop-shadow(0 0 3px rgba(41,121,255,0.5)); }

.conn-hit { fill: none; stroke: transparent; stroke-width: 14; cursor: pointer; }
/* v0.59.143: patch-link'и инфо-портов (RJ45/SFP/слаботочка/видео). Тонкая цветная линия — «патчкорд» 1:1 между двумя кружками-коннекторами. Цвет задаётся в render.js per-линия (совпадает с цветом кружков). */
.sys-patch-link { pointer-events: stroke; cursor: pointer; opacity: 0.85; }
.sys-patch-link:hover { opacity: 1; stroke-width: 2.5; }
.sys-port-connector { cursor: pointer; }
.sys-port-connector:hover { r: 4.5; }
.conn-link-label { font: 600 10px -apple-system, "Segoe UI", sans-serif; fill: #1565c0; cursor: pointer; }
.conn-link-label:hover { fill: #0d47a1; text-decoration: underline; }
/* В режиме "Показать все" подсвечиваем связи с linkMode=true: штрих + свечение.
   ПКМ по такой связи восстанавливает её нормальный вид (снимает linkMode). */
.conn.link-hidden {
  stroke-dasharray: 10 6 !important;
  filter: drop-shadow(0 0 3px rgba(255,152,0,0.8));
  opacity: 0.85;
}

/* Вкладки страниц (как в drawio) — снизу холста */
#canvas-wrap { position: relative; }
.page-tabs {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 28px;
  display: flex;
  align-items: center;
  background: #fafbfd;
  border-top: 1px solid #e0e3ea;
  padding: 0 6px;
  z-index: 5;
  gap: 4px;
  overflow-x: auto;
}
.page-tabs-list { display: flex; gap: 2px; align-items: center; flex: 1; min-width: 0; }
.page-tab {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px;
  font-size: 12px;
  color: #546e7a;
  background: #f0f2f6;
  border: 1px solid #dfe2e8;
  border-radius: 4px 4px 0 0;
  border-bottom: none;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.page-tab:hover { background: #e8ebf0; }
.page-tab.active {
  background: #fff;
  color: #2b303b;
  font-weight: 600;
  border-bottom: 2px solid #2979ff;
  margin-bottom: -1px;
}
.page-tab.linked { border-left: 3px solid #9c27b0; }
.page-tab .page-tab-type { font-size: 9px; color: #999; text-transform: uppercase; }
.page-tab.linked .page-tab-type { color: #9c27b0; }
.page-tab .page-tab-kind { font-size: 13px; margin-right: 2px; opacity: 0.85; }
/* v0.60.176: × close-button на каждой вкладке (Chrome-стиль). По репорту
   Пользователя «не могу страницы удалять» — кнопка делает удаление
   очевидным (раньше только через right-click → меню). Скрывается на
   единственной странице. */
.page-tab .page-tab-close {
  margin-left: 4px;
  width: 16px; height: 16px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%;
  font-size: 14px; line-height: 1;
  color: #94a3b8;
  cursor: pointer;
  opacity: 0.5;
  transition: opacity 0.15s, background 0.15s, color 0.15s;
}
.page-tab:hover .page-tab-close { opacity: 0.9; }
.page-tab .page-tab-close:hover {
  background: #fee2e2;
  color: #dc2626;
  opacity: 1;
}
/* Phase 2.1: баннер вида страницы поверх холста (для layout/mechanical/…) */
.page-kind-banner {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  padding: 4px 12px;
  border-radius: 14px;
  background: rgba(255, 193, 7, 0.92);
  color: #333;
  font-size: 12px;
  font-weight: 600;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
  pointer-events: none;
  white-space: nowrap;
}
.page-kind-banner .pkb-icon { margin-right: 6px; font-size: 14px; }
/* Phase 2.?: tabs-bar в модалках параметров (consumer / source / panel / ...) */
.tp-tabs {
  display: flex;
  flex-wrap: wrap;           /* v0.58.40: при переполнении — на новую строку */
  gap: 2px;
  row-gap: 0;
  margin: 10px 0 14px;
  border-bottom: 1px solid #e0e4ea;
}
.tp-tab {
  padding: 6px 14px;
  font-size: 12px;
  font-weight: 500;
  background: transparent;
  border: 0;
  border-bottom: 2px solid transparent;
  color: #666;
  cursor: pointer;
  transition: color 0.12s, border-color 0.12s;
}
.tp-tab:hover { color: #2979ff; }
.tp-tab.active { color: #2979ff; border-bottom-color: #2979ff; }

/* v0.58.51 (roadmap 1.22.3): единый стиль содержимого вкладок инспектора.
   Первая .inspector-section в панели — без верхней разделительной линии,
   чтобы не дублировать границу .tp-tabs. Остальные секции остаются как есть. */
.tp-panel { padding-top: 2px; }
.tp-panel > .inspector-section:first-child,
.tp-panel > details.inspector-section:first-child {
  border-top: 0;
  margin-top: 0;
  padding-top: 0;
}
/* Системные вкладки: цветная полоса слева у всей панели (по sys-color).
   Задаётся inline-стилем на .tp-panel[data-panel^="sys:"] через JS — здесь
   только скелет для будущего использования. */
.tp-panel[data-sys-accent] {
  border-left: 3px solid var(--sys-accent, #e0e4ea);
  padding-left: 8px;
  margin-left: -2px;
}

/* v0.59.88: стабильная высота модалок параметров узла — чтобы переключение
   вкладок не «прыгало». Минимум подобран под самую длинную вкладку.
   Если контента меньше — остаётся пустое пространство внизу вместо скачка. */
#panel-params-body,
#consumer-params-body,
#source-params-body {
  min-height: 560px;
}

/* Phase 2.3: линейка с мм-делениями поверх холста */
.layout-ruler {
  position: absolute;
  top: 0; left: 0;
  pointer-events: none;
  z-index: 5;
  user-select: none;
}
/* v0.58.40: сами полосы линеек и угол принимают клики (drag + установка 0). */
.layout-ruler [data-ruler] {
  pointer-events: auto;
}
/* Phase 2.3 (v0.58.3): на layout-странице (расстановка) нет коннекторов —
   скрываем порты. v0.59.380: #layer-conns больше НЕ скрываем — там теперь
   рендерятся географические линии между футпринтами (см. _renderConnsLayout). */
svg.layout-mode .port,
svg.layout-mode .port.in,
svg.layout-mode .port.out,
svg.layout-mode .port-btn,
svg.layout-mode .port-lamp,
svg.layout-mode .port-lamp-core { display: none; }
.page-kind-banner .pkb-beta {
  margin-left: 8px;
  font-weight: 400;
  font-size: 10px;
  text-transform: uppercase;
  opacity: 0.75;
  letter-spacing: 0.5px;
}
.page-tab-add {
  background: #f0f2f6;
  border: 1px solid #dfe2e8;
  border-radius: 4px;
  width: 24px; height: 20px;
  font-size: 14px;
  cursor: pointer;
  color: #546e7a;
  padding: 0;
  line-height: 1;
}
.page-tab-add:hover { background: #e8ebf0; }
/* Сдвигаем svg, чтобы вкладки не перекрывали */
#canvas-wrap > svg#canvas { bottom: 28px !important; }

/* Inline-редактирование названия вкладки */
.page-tab input.page-tab-rename {
  background: #fff;
  border: 1px solid #2979ff;
  border-radius: 3px;
  font: inherit;
  font-size: 12px;
  color: #2b303b;
  padding: 1px 4px;
  width: 120px;
  outline: none;
}

/* Контекстное меню вкладки (как в drawio) */
.page-tab-menu {
  position: fixed;
  z-index: 100;
  min-width: 180px;
  background: #fff;
  border: 1px solid #dfe2e8;
  border-radius: 6px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.15);
  padding: 4px 0;
  font-size: 12px;
  user-select: none;
}
.page-tab-menu .pm-item {
  padding: 6px 14px;
  cursor: pointer;
  color: #2b303b;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.page-tab-menu .pm-item:hover { background: #eef5ff; }
.page-tab-menu .pm-item .pm-shortcut { color: #9aa0a6; font-size: 11px; }
.page-tab-menu .pm-item.pm-danger { color: #c62828; }
.page-tab-menu .pm-item.pm-danger:hover { background: #ffebee; }
.page-tab-menu .pm-item.pm-checked::before { content: '✓ '; color: #2979ff; font-weight: 700; }
.page-tab-menu .pm-sep { height: 1px; background: #eef1f6; margin: 4px 0; }
.page-tab-menu .pm-group-label {
  padding: 4px 14px 2px;
  font-size: 10px;
  color: #9aa0a6;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.conn-label {
  font: 600 11px -apple-system, "Segoe UI", sans-serif;
  fill: #c62828;
  pointer-events: none;
  text-anchor: middle;
  paint-order: stroke;
  stroke: #fafbfc;
  stroke-width: 3;
  stroke-linejoin: round;
}

.conn-label-sub {
  font: 10px -apple-system, "Segoe UI", sans-serif;
  fill: #8a93a7;
  pointer-events: none;
  text-anchor: middle;
  paint-order: stroke;
  stroke: #fafbfc;
  stroke-width: 3;
  stroke-linejoin: round;
}

.conn-handle {
  fill: #ef6c00;
  stroke: #fff;
  stroke-width: 2;
  cursor: grab;
}
.conn-handle:hover { fill: #ff9800; }

/* Control-линии (запуск генератора от триггера) */
.control-line {
  stroke: #9aa3b5;
  stroke-width: 1.5;
  stroke-dasharray: 6 4;
  fill: none;
  pointer-events: none;
  opacity: 0.7;
}
.control-line.started {
  stroke: #ff9800;
  stroke-width: 2.2;
  opacity: 1;
  animation: ctrlBlink 1.2s ease-in-out infinite;
}
@keyframes ctrlBlink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}
.control-label {
  font: 600 10px -apple-system, "Segoe UI", sans-serif;
  fill: #9aa3b5;
  text-anchor: middle;
  pointer-events: none;
  paint-order: stroke;
  stroke: #fafbfc;
  stroke-width: 3;
  stroke-linejoin: round;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.control-label.started { fill: #ef6c00; }

.port-lamp {
  stroke: #fff;
  stroke-width: 1.5;
  pointer-events: none;
}
.port-lamp.green {
  fill: #43a047;
  filter: drop-shadow(0 0 3px rgba(67, 160, 71, 0.9));
}
.port-lamp.red {
  fill: #e53935;
  filter: drop-shadow(0 0 3px rgba(229, 57, 53, 0.9));
}
.port-lamp-core { pointer-events: none; }
.port-lamp-core.green { fill: #c8f7d0; }
.port-lamp-core.red   { fill: #ffd7d7; }

.pending-line {
  fill: none;
  stroke: #1976d2;
  stroke-width: 2;
  stroke-dasharray: 5 4;
  pointer-events: none;
}
.rubber-band {
  fill: rgba(25, 118, 210, 0.08);
  stroke: #1976d2;
  stroke-width: 1;
  stroke-dasharray: 4 3;
  pointer-events: none;
}
.node.multi-selected .node-body {
  stroke: #1976d2 !important;
  stroke-width: 3;
  stroke-dasharray: 6 3;
}

/* ---------- Inspector (right) ---------- */
#inspector {
  background: #fff;
  border-left: 1px solid #e0e3ea;
  padding: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
#inspector .insp-panel {
  padding: 14px 16px;
  overflow-y: auto;
  flex: 1 1 auto;
}
.insp-tabs {
  display: flex;
  border-bottom: 1px solid #e0e3ea;
  background: #f7f8fa;
  flex: 0 0 auto;
  position: sticky; top: 0; z-index: 2;
}
.insp-tab {
  flex: 1 1 auto;
  background: transparent;
  border: 0;
  border-bottom: 2px solid transparent;
  padding: 8px 6px;
  font-size: 11px;
  font-weight: 600;
  color: #6b7385;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}
.insp-tab:hover { background: #eef0f4; }
.insp-tab.active {
  color: #1e40af;
  border-bottom-color: #1e40af;
  background: #fff;
}
.insp-tab-count {
  background: #e0e3ea;
  color: #374151;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 8px;
  min-width: 16px;
  text-align: center;
}
.insp-tab.active .insp-tab-count { background: #dbeafe; color: #1e40af; }

.pal-unplaced-item, .pal-reg-item {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 8px;
  border: 1px solid #e0e3ea;
  border-radius: 4px;
  margin-bottom: 4px;
  background: #fff;
  font-size: 12px;
  cursor: grab;
  user-select: none;
}
.pal-unplaced-item:hover, .pal-reg-item:hover { background: #f4f6fa; border-color: #b8c3d9; }
.pal-unplaced-icon { font-size: 14px; flex: 0 0 auto; }
.pal-unplaced-tag { font-weight: 700; color: #1e40af; flex: 0 0 auto; }
.pal-unplaced-name { color: #374151; flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pal-reg-badge {
  font-size: 10px; font-weight: 700;
  padding: 1px 6px; border-radius: 8px;
  flex: 0 0 auto;
}
.pal-reg-badge-none { background: #fef3c7; color: #92400e; }
.pal-reg-badge-pages { background: #d1fae5; color: #065f46; }
.pal-reg-place, .pal-reg-del {
  border: 1px solid #d1d5db; background: #fff; border-radius: 3px;
  width: 20px; height: 20px; font-size: 13px; line-height: 1;
  cursor: pointer; padding: 0; flex: 0 0 auto; color: #374151;
}
.pal-reg-place:hover { background: #d1fae5; border-color: #10b981; color: #065f46; }
.pal-reg-del:hover { background: #fee2e2; border-color: #ef4444; color: #991b1b; }
.pal-reg-group { margin-bottom: 10px; }
.pal-reg-group-head {
  font-size: 10px; font-weight: 700; color: #6b7385;
  text-transform: uppercase; letter-spacing: 0.6px;
  margin: 8px 0 4px; padding: 0 2px;
}
/* v0.58.18: цветные точки-системы в палитре/реестре */
.pal-sys-dots {
  display: inline-flex; gap: 2px; align-items: center; flex: 0 0 auto;
}
.pal-sys-dot {
  width: 8px; height: 8px; border-radius: 50%;
  border: 1px solid rgba(0,0,0,0.15);
  display: inline-block;
}
.sys-chip:hover { background: #f4f6fa; }


#inspector h3 {
  font-size: 11px; font-weight: 600; color: #6b7385; text-transform: uppercase;
  margin: 0 0 14px; letter-spacing: 0.8px;
}

.field { margin-bottom: 12px; }
.field label {
  display: block;
  font-size: 11px;
  color: #6b7385;
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  font-weight: 600;
}
.field input[type=text], .field input[type=number], .field input[type=email], .field select {
  width: 100%;
  padding: 8px 10px;
  font: 13px inherit;
  border: 1px solid #d6dae2;
  border-radius: 5px;
  background: #fafbfc;
  color: #222;
}
.field input:focus, .field select:focus {
  outline: none; border-color: #1976d2; background: #fff;
}
.field input:disabled, .field select:disabled {
  background: #eef0f4;
  color: #8a93a7;
  cursor: not-allowed;
  border-color: #d6dae2;
}
.field.check { display: flex; align-items: center; gap: 8px; }
.field.check label { margin: 0; text-transform: none; font-weight: 500; font-size: 13px; color: #222; letter-spacing: 0; }
.field.check input { width: 16px; height: 16px; }
.field .row { display: flex; gap: 6px; }
.field .row input[type=text], .field .row input[type=email] { flex: 1; min-width: 0; }
.field .hint { font-size: 11px; color: #8a93a7; margin-top: 4px; }

.inspector-section {
  border-top: 1px solid #eef0f4;
  padding-top: 12px;
  margin-top: 12px;
}
.inspector-section h4 {
  font-size: 11px; color: #6b7385; margin: 0 0 8px;
  text-transform: uppercase; letter-spacing: 0.5px;
}

.btn-delete {
  margin-top: 16px;
  width: 100%;
  padding: 9px;
  background: #fde8e8;
  border: 1px solid #f4bebe;
  color: #c62828;
  border-radius: 5px;
  font-size: 12px;
  font-weight: 600;
}
.btn-delete:hover { background: #fbd6d6; }

.badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.badge.on  { background: #e8f5e9; color: #2e7d32; }
.badge.off { background: #ffebee; color: #c62828; }
.badge.backup { background: #fff3e0; color: #ef6c00; }

/* ---------- Read-only mode ---------- */
body.read-only .pal-item,
body.read-only #toolbar button.danger,
body.read-only #btn-save-local,
body.read-only #btn-load-local,
body.read-only #btn-import,
body.read-only #btn-new-mode,
body.read-only .btn-delete,
body.read-only .mode-del {
  display: none !important;
}
body.read-only .pal-item { pointer-events: none; opacity: 0.4; }
body.read-only #inspector input,
body.read-only #inspector select,
body.read-only #palette input,
body.read-only #palette select { pointer-events: none; background: #f4f5f7; }

/* ================= Mobile toggle buttons ================= */
.mobile-toggle {
  display: none;
  position: fixed;
  bottom: 16px;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: #1976d2;
  color: #fff;
  border: none;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  z-index: 40;
  align-items: center;
  justify-content: center;
}
.mobile-toggle.left  { left: 16px; }
.mobile-toggle.right { right: 16px; }
.mobile-toggle:active { transform: scale(0.95); }

/* ================= Modals ================= */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(30, 40, 55, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 16px;
}
.modal-box {
  background: #fff;
  border-radius: 12px;
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 10px 40px rgba(0,0,0,0.3);
}
.modal-box.modal-wide { max-width: 760px; }
/* v0.60.364: extra-wide для табличных модалок (контейнер с членами,
   debug-таблица всех узлов и т.п.) — чтобы колонки нормально вмещались
   без горизонтального скролла на стандартных мониторах. */
.modal-box.modal-xwide { max-width: 1200px; }
.modal-box.modal-resizable { resize: both; overflow: auto; min-width: 360px; min-height: 300px; }
.modal-box.modal-fullscreen {
  width: 96vw !important; height: 92vh !important;
  max-width: 96vw !important; max-height: 92vh !important;
  margin: 4vh auto !important;
  position: relative !important;
  left: 0 !important; top: 0 !important;
}

.field textarea {
  width: 100%;
  padding: 9px 11px;
  font: 12px/1.5 ui-monospace, "Cascadia Mono", Consolas, monospace;
  border: 1px solid #d6dae2;
  border-radius: 5px;
  background: #fafbfc;
  color: #222;
  resize: vertical;
}
.field textarea:focus { outline: none; border-color: #1976d2; background: #fff; }

/* Presets list */
.presets-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 8px;
  max-height: 60vh;
  overflow-y: auto;
}
.preset-group { grid-column: 1 / -1; }
.preset-group h4 {
  margin: 12px 0 6px;
  font-size: 11px;
  font-weight: 700;
  color: #6b7385;
  text-transform: uppercase;
  letter-spacing: 0.6px;
}
.preset-card {
  background: #fafbfc;
  border: 1px solid #e0e3ea;
  border-radius: 6px;
  padding: 8px 10px;
  cursor: grab;
  transition: border-color .12s, transform .12s;
  display: flex;
  align-items: center;
  gap: 8px;
}
.preset-card:hover { border-color: #1976d2; background: #fff; transform: translateY(-1px); }
.preset-card .pc-body { flex: 1; min-width: 0; }
.preset-card .pc-title { font-size: 13px; font-weight: 600; color: #1f2430; }
.preset-card .pc-desc { font-size: 11px; color: #8a93a7; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.preset-card .pc-actions { display: flex; gap: 2px; flex-shrink: 0; }
.pc-btn {
  background: none; border: none; cursor: pointer; padding: 4px 6px;
  font-size: 14px; color: #999; border-radius: 4px;
  transition: background .1s, color .1s;
}
.pc-btn:hover { background: #e3f2fd; color: #1976d2; }
.pc-del:hover { background: #ffebee; color: #d32f2f; }

/* Report */
.report-body {
  font: 12px/1.55 ui-monospace, "Cascadia Mono", Consolas, monospace;
  color: #1f2430;
  /* pre (не pre-wrap): длинные строки не переносятся, появляется
     горизонтальная прокрутка. BOM-таблица кабелей ~120 символов
     должна помещаться без налезания. */
  white-space: pre;
  background: #fafbfc;
  border: 1px solid #e0e3ea;
  border-radius: 6px;
  padding: 14px;
  max-height: 65vh;
  overflow: auto;
}
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 20px 12px;
}
.modal-head h2 { margin: 0; font-size: 18px; color: #1f2430; }
.modal-close {
  background: transparent;
  border: none;
  font-size: 22px;
  line-height: 1;
  color: #8a93a7;
  padding: 4px 10px;
  border-radius: 6px;
}
.modal-close:hover { background: #f4f6f9; color: #2b303b; }
.modal-body {
  padding: 4px 20px 12px;
  overflow-y: auto;
}
.modal-body h3 {
  font-size: 13px;
  color: #2b303b;
  margin: 14px 0 8px;
  font-weight: 600;
}
.modal-body p { color: #5a6271; font-size: 14px; line-height: 1.5; }
.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 20px 18px;
  border-top: 1px solid #eef0f4;
  margin-top: 4px;
}
.modal-foot button, .modal-body .primary, .modal-body button {
  padding: 9px 16px;
  border: 1px solid #e0e3ea;
  background: #fff;
  color: #2b303b;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
}
.modal-foot button:hover { background: #f4f6f9; }
.modal-foot .primary, button.primary {
  background: #1976d2;
  color: #fff;
  border-color: #1976d2;
}
.modal-foot .primary:hover, button.primary:hover { background: #1565c0; }

/* Share members rows */
.share-members {
  border: 1px solid #eef0f4;
  border-radius: 6px;
  padding: 4px;
  background: #fafbfc;
  max-height: 240px;
  overflow-y: auto;
}
.share-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 5px;
}
.share-row:hover { background: #fff; }
.share-who { flex: 1; min-width: 0; }
.share-name { font-size: 13px; font-weight: 500; color: #1f2430; }
.share-email { font-size: 11px; color: #8a93a7; }
.share-role-label { font-size: 11px; color: #8a93a7; text-transform: uppercase; letter-spacing: 0.3px; }
.share-role-sel {
  padding: 4px 6px;
  font-size: 12px;
  border: 1px solid #d6dae2;
  border-radius: 4px;
  background: #fff;
}
.share-remove {
  background: transparent;
  border: none;
  color: #8a93a7;
  font-size: 18px;
  padding: 2px 8px;
  border-radius: 4px;
}
.share-remove:hover { color: #c62828; background: #fde8e8; }

/* ================= Flash messages ================= */
.flash {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #323a4d;
  color: #fff;
  padding: 10px 18px;
  border-radius: 6px;
  font-size: 13px;
  z-index: 300;
  box-shadow: 0 4px 16px rgba(0,0,0,0.25);
  animation: flash-in 0.2s ease;
}
.flash.error { background: #c62828; }
@keyframes flash-in { from { opacity: 0; transform: translate(-50%, 10px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ================= Responsive ================= */
@media (max-width: 960px) {
  #screen-editor #app {
    grid-template-columns: 1fr;
    height: 100%;
  }
  #canvas-wrap {
    position: absolute;
    inset: 0;
  }
  #palette, #inspector {
    position: fixed;
    top: 56px;
    bottom: 0;
    width: 280px;
    max-width: 85vw;
    z-index: 50;
    transition: transform 0.22s ease;
    box-shadow: 0 0 20px rgba(0,0,0,0.15);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  #palette {
    left: 0;
    transform: translateX(-100%);
  }
  #inspector {
    right: 0;
    transform: translateX(100%);
  }
  body.palette-open   #palette   { transform: translateX(0); }
  body.inspector-open #inspector { transform: translateX(0); }
  .mobile-toggle { display: inline-flex; }

  /* При открытом слайдере затемняем канву */
  body.palette-open #canvas-wrap::after,
  body.inspector-open #canvas-wrap::after {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(30, 40, 55, 0.25);
    z-index: 30;
    cursor: pointer;
  }
  /* Клик на затемнение закроет drawer через JS (уже обработано btn-toggle) */

  #toolbar {
    top: 8px;
    left: 8px;
    right: 8px;
    max-width: none;
  }
  #toolbar button { padding: 8px 10px; font-size: 11px; }
}

@media (max-width: 640px) {
  #header { padding: 0 10px; gap: 8px; }
  .hdr-title { font-size: 16px; }
  .hdr-project { max-width: 30vw; font-size: 12px; padding-left: 8px; }
  .hdr-btn { padding: 7px 10px; font-size: 12px; }
  .user-name { max-width: 80px; font-size: 12px; }
  .user-btn img, .user-btn .avatar-letter { width: 28px; height: 28px; font-size: 12px; }

  .projects-container { padding: 20px 14px 80px; }
  .projects-header h1 { font-size: 22px; }
  .projects-grid { grid-template-columns: 1fr; }

  .modal-box { border-radius: 10px; max-height: 95vh; }
  .modal-head { padding: 14px 16px 8px; }
  .modal-head h2 { font-size: 16px; }
  .modal-body { padding: 4px 16px 10px; }
  .modal-foot { padding: 10px 16px 14px; }

  .field .row { flex-wrap: wrap; }

  /* Больше тап-таргета */
  #toolbar button { min-height: 36px; }
  .port { r: 8; }
  .conn-hit { stroke-width: 20; }
}

/* Safe area для iPhone с «челкой» */
@supports (padding: max(0px)) {
  #header { padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
  .mobile-toggle.left  { left: max(16px, env(safe-area-inset-left)); }
  .mobile-toggle.right { right: max(16px, env(safe-area-inset-right)); }
  .mobile-toggle { bottom: max(16px, env(safe-area-inset-bottom)); }
}

/* ================= Палитра цветов зоны (инспектор) ================= */
.zone-palette {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 4px;
  margin-top: 4px;
}
.zone-swatch {
  width: 100%;
  aspect-ratio: 1 / 1;
  border: 1px solid rgba(0,0,0,0.15);
  border-radius: 4px;
  cursor: pointer;
  padding: 0;
  transition: transform 0.1s, border-color 0.1s;
}
.zone-swatch:hover {
  transform: scale(1.12);
  border-color: #1976d2;
}
.zone-swatch.sel {
  border: 2px solid #1976d2;
  box-shadow: 0 0 0 2px rgba(25,118,210,0.25);
}

/* ================= Кнопки +/- портов щита ================= */
.port-btn circle {
  fill: #fff;
  stroke: #90a4ae;
  stroke-width: 1.5;
  transition: fill 0.12s, stroke 0.12s;
}
.port-btn line {
  stroke: #546e7a;
  stroke-width: 1.8;
  stroke-linecap: round;
  pointer-events: none;
}
.port-btn { cursor: pointer; }
.port-btn:hover circle { fill: #e3f2fd; stroke: #1976d2; }
.port-btn:hover line { stroke: #1976d2; }
.port-btn-add:hover circle { fill: #e8f5e9; stroke: #2e7d32; }
.port-btn-add:hover line { stroke: #2e7d32; }
.port-btn-del:hover circle { fill: #ffebee; stroke: #c62828; }
.port-btn-del:hover line { stroke: #c62828; }

/* ================= Раздел отчётов ================= */
.reports-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.reports-list .rpt-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: start;
  padding: 12px 14px;
  border: 1px solid #e0e3ea;
  border-radius: 8px;
  background: #fff;
  transition: box-shadow 0.15s, border-color 0.15s;
}
.reports-list .rpt-item:hover {
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
  border-color: #c8d0dc;
}
.reports-list .rpt-item__main {
  min-width: 0;
}
.reports-list .rpt-item__title {
  font-size: 14px;
  font-weight: 600;
  color: #1f2430;
  margin-bottom: 4px;
}
.reports-list .rpt-item__desc {
  font-size: 12px;
  color: #6b7280;
  line-height: 1.4;
  margin-bottom: 6px;
}
.reports-list .rpt-item__tpl {
  font-size: 11px;
  color: #8a94a6;
}
.reports-list .rpt-item__tpl b {
  color: #546e7a;
  font-weight: 600;
}
.reports-list .rpt-item__actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 110px;
}
.reports-list .rpt-item__actions button {
  padding: 6px 12px;
  font-size: 12px;
  border: 1px solid #c8d0dc;
  background: #fff;
  color: #1f2430;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}
.reports-list .rpt-item__actions button:hover {
  background: #f1f3f7;
  border-color: #8a94a6;
}
.reports-list .rpt-item__actions button.primary {
  background: #1976d2;
  color: #fff;
  border-color: #1976d2;
}
.reports-list .rpt-item__actions button.primary:hover {
  background: #1565c0;
  border-color: #1565c0;
}

/* v0.59.358: deep-link focus highlight (для ?focusNode=…) */
@keyframes rs-focus-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(34,197,94,0.0); outline-color: rgba(34,197,94,0); }
  20% { box-shadow: 0 0 0 6px rgba(34,197,94,0.45); outline-color: rgba(34,197,94,0.85); }
  60% { box-shadow: 0 0 0 12px rgba(34,197,94,0.0); outline-color: rgba(34,197,94,0.5); }
}
.rs-flash-focus {
  outline: 3px solid rgba(34,197,94,0.85) !important;
  outline-offset: 3px;
  animation: rs-focus-pulse 1.1s ease-in-out 2;
}
