/* css/style.css - Стили конструктора электрощитов */

:root {
  --din-mod-width: 54px;
  --din-mod-height: 168px;
  --din-metal-bg: linear-gradient(180deg, #94a3b8 0%, #cbd5e1 30%, #64748b 70%, #475569 100%);
  --cabinet-bg: #f8fafc;
  --cabinet-border: #cbd5e1;
}

/* Общие стили */
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  user-select: none;
}

/* Корпус электрощита */
.din-cabinet-enclosure {
  background: #ffffff;
  border: 2px solid #94a3b8;
  border-radius: 12px;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
  padding: 16px;
  min-width: 720px;
  position: relative;
}

.din-cabinet-header {
  padding-bottom: 12px;
  margin-bottom: 16px;
  border-bottom: 1px solid #e2e8f0;
}

/* Ряд DIN-рейки */
.din-rail-row {
  margin-bottom: 24px;
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 10px;
}

.din-rail-header {
  margin-bottom: 8px;
}

/* Металлическая DIN-рейка */
.din-track-container {
  position: relative;
  min-height: var(--din-mod-height);
  background: #e2e8f0;
  border-radius: 6px;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 0 12px;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* Металлическая полоса рейки (Омега-профиль TS 35) */
.din-metal-rail {
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  height: 35px;
  transform: translateY(-50%);
  background: var(--din-metal-bg);
  border-top: 2px solid #e2e8f0;
  border-bottom: 2px solid #334155;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.25);
  z-index: 1;
}

/* Перфорация на DIN-рейке */
.din-metal-rail::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  height: 8px;
  transform: translateY(-50%);
  background-image: repeating-linear-gradient(
    90deg,
    #1e293b,
    #1e293b 14px,
    transparent 14px,
    transparent 32px
  );
  opacity: 0.45;
}

/* Слот-сетка */
.din-slot-grid {
  position: absolute;
  top: 0;
  left: 12px;
  right: 12px;
  bottom: 0;
  display: flex;
  pointer-events: none;
  z-index: 2;
}

.din-slot-tick {
  width: var(--din-mod-width);
  min-width: var(--din-mod-width);
  border-right: 1px dashed rgba(100, 116, 139, 0.3);
  font-size: 9px;
  color: #64748b;
  padding: 2px 4px;
  font-family: monospace;
}

/* Контейнер модулей на рейке */
.din-modules-container {
  position: relative;
  display: flex;
  min-height: var(--din-mod-height);
  z-index: 10;
  gap: 1px;
}

/* Индикатор места сброса (Drop Placeholder) */
.din-drop-indicator {
  width: 6px;
  margin: 0 2px;
  background: #3b82f6;
  border-radius: 3px;
  box-shadow: 0 0 10px #3b82f6;
  animation: pulseDrop 1s infinite;
  z-index: 20;
  pointer-events: none;
}

@keyframes pulseDrop {
  0%, 100% { opacity: 1; transform: scaleY(1); }
  50% { opacity: 0.6; transform: scaleY(0.95); }
}

/* ----------------------------------------------------
   Визуальное оформление модульного аппарата (1 DIN = 54px)
   ---------------------------------------------------- */
.din-module-unit {
  position: relative;
  height: var(--din-mod-height);
  background: linear-gradient(180deg, #f8fafc 0%, #f1f5f9 45%, #e2e8f0 100%);
  border: 1px solid #94a3b8;
  border-radius: 4px;
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.15), inset 0 1px 0 rgba(255, 255, 255, 0.8);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  cursor: grab;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  user-select: none;
  overflow: hidden;
}

.din-module-unit:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.2);
  z-index: 15;
}

.din-module-unit:active {
  cursor: grabbing;
}

.din-module-unit.is-dragging {
  opacity: 0.4;
  transform: scale(0.95);
}

.din-module-unit.is-selected {
  outline: 3px solid #3b82f6;
  box-shadow: 0 0 0 2px #93c5fd, 0 8px 20px rgba(59, 130, 246, 0.35);
  z-index: 16;
}

/* Клеммы с винтами (верх и низ) */
.mod-terminal {
  height: 18px;
  background: #e2e8f0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-bottom: 1px solid #cbd5e1;
}

.mod-terminal-bottom {
  border-bottom: none;
  border-top: 1px solid #cbd5e1;
}

.screw-slot {
  width: 12px;
  height: 12px;
  background: radial-gradient(circle, #64748b 30%, #334155 70%);
  border-radius: 50%;
  position: relative;
  box-shadow: inset 0 1px 2px rgba(0,0,0,0.5);
}

.screw-slot::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 2px;
  right: 2px;
  height: 2px;
  background: #cbd5e1;
  transform: translateY(-50%) rotate(45deg);
}

/* Верхний шильдик фазы */
.mod-header-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 2px 4px;
  font-size: 9px;
  font-weight: 700;
  background: #f8fafc;
  border-bottom: 1px solid #e2e8f0;
}

.mod-phase-tag {
  padding: 1px 4px;
  border-radius: 2px;
  font-size: 8px;
  color: #fff;
  font-family: monospace;
}

.badge-l1 { background: #b45309; } /* Янтарно-коричневый L1 */
.badge-l2 { background: #047857; } /* Зеленый/черный L2 */
.badge-l3 { background: #b91c1c; } /* Красный/серый L3 */
.badge-3p { background: linear-gradient(90deg, #b45309 0%, #047857 50%, #b91c1c 100%); }

.mod-poles-text {
  font-size: 8px;
  color: #64748b;
}

/* Маркировка характеристик (C16, B10...) */
.mod-specs-area {
  padding: 2px 4px;
  text-align: center;
}

.mod-rating-line {
  font-family: "Courier New", Courier, monospace;
  font-weight: 800;
  font-size: 11px;
  color: #0f172a;
  letter-spacing: -0.5px;
}

.mod-leakage {
  display: block;
  font-size: 8px;
  color: #2563eb;
  font-weight: bold;
}

/* Внутренности автомата АВ */
.mod-interior {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  padding: 4px;
}

.mod-toggle-slot {
  width: 22px;
  height: 38px;
  background: #334155;
  border-radius: 4px;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.6);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.mod-toggle-lever {
  width: 18px;
  height: 22px;
  background: linear-gradient(180deg, #475569 0%, #1e293b 100%);
  border-radius: 3px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.5);
  border-top: 1px solid #94a3b8;
  cursor: pointer;
  transition: transform 0.1s;
}

.mod-toggle-lever.lever-red {
  background: linear-gradient(180deg, #ef4444 0%, #991b1b 100%);
  border-top: 1px solid #fca5a5;
}

/* Окошко индикатора состояния контактов */
.mod-flag-window {
  width: 14px;
  height: 6px;
  background: #1e293b;
  border-radius: 2px;
  margin-top: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.flag-dot {
  width: 10px;
  height: 4px;
  background: #22c55e; /* Зеленый - цепь разомкнута/безопасно или красный */
  border-radius: 1px;
}

/* Кнопка ТЕСТ для УЗО */
.rcd-test-btn {
  width: 16px;
  height: 16px;
  background: #fbbf24;
  border: 1px solid #d97706;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  font-weight: bold;
  color: #78350f;
  box-shadow: 0 1px 2px rgba(0,0,0,0.2);
  margin-bottom: 4px;
  cursor: pointer;
}

/* Цифровой дисплей реле напряжения */
.relay-led-display {
  background: #09090b;
  border: 1px solid #27272a;
  border-radius: 3px;
  padding: 3px 6px;
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 2px;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.8);
  width: 85%;
}

.led-digits {
  color: #22c55e;
  font-family: 'Courier New', Courier, monospace;
  font-weight: bold;
  font-size: 14px;
  text-shadow: 0 0 8px rgba(34, 197, 94, 0.8);
  letter-spacing: 1px;
}

.led-unit {
  color: #15803d;
  font-size: 9px;
  font-weight: bold;
}

.relay-keys {
  display: flex;
  gap: 3px;
  margin-top: 4px;
}

.relay-key {
  font-size: 7px;
  background: #cbd5e1;
  border: 1px solid #94a3b8;
  border-radius: 2px;
  padding: 1px 3px;
  color: #334155;
  font-weight: bold;
}

.relay-leds {
  display: flex;
  gap: 6px;
  margin-top: 3px;
}

.led-dot {
  width: 4px;
  height: 4px;
  border-radius: 50%;
}
.led-dot.green { background: #22c55e; box-shadow: 0 0 4px #22c55e; }
.led-dot.red { background: #ef4444; box-shadow: 0 0 4px #ef4444; }

/* УЗИП */
.spd-cartridge {
  width: 80%;
  height: 36px;
  background: #047857;
  border-radius: 3px;
  display: flex;
  gap: 4px;
  align-items: center;
  justify-content: center;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.3);
}

.spd-flag.green {
  width: 10px;
  height: 6px;
  background: #86efac;
  border-radius: 1px;
}

.spd-label {
  font-size: 8px;
  color: #065f46;
  font-weight: bold;
  margin-top: 4px;
}

/* Счетчик */
.meter-lcd {
  background: #cbd5e1;
  border: 1px solid #64748b;
  font-family: monospace;
  font-size: 9px;
  font-weight: bold;
  padding: 2px 4px;
}

/* Заглушка */
.mod-interior-blank {
  width: 100%;
  height: 100%;
  background: repeating-linear-gradient(
    45deg,
    #cbd5e1,
    #cbd5e1 4px,
    #94a3b8 4px,
    #94a3b8 8px
  );
  opacity: 0.6;
}

/* Розетка на DIN-рейку (Schuko / Europlug / USB) */
.mod-interior-socket {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  padding: 4px;
}

.socket-schuko-well {
  width: 44px;
  height: 44px;
  background: radial-gradient(circle, #f8fafc 40%, #e2e8f0 85%, #cbd5e1 100%);
  border: 1.5px solid #94a3b8;
  border-radius: 50%;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.2), 0 1px 2px rgba(0,0,0,0.05);
}

.socket-ground-ear {
  width: 8px;
  height: 3px;
  background: #d97706;
  border-radius: 0.5px;
  box-shadow: 0 0.5px 1px rgba(0,0,0,0.3);
}

.socket-ground-ear.top {
  position: absolute;
  top: 3px;
}

.socket-ground-ear.bottom {
  position: absolute;
  bottom: 3px;
}

.socket-pin-holes {
  display: flex;
  gap: 12px;
  align-items: center;
}

.socket-hole {
  width: 5px;
  height: 5px;
  background: #0f172a;
  border-radius: 50%;
  box-shadow: inset 0 1px 2px rgba(0,0,0,0.8);
}

.socket-label-mini {
  font-size: 7px;
  font-weight: 800;
  font-family: monospace;
  color: #475569;
  margin-top: 3px;
}

.socket-led-badge {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  margin-bottom: 2px;
  box-shadow: 0 0 4px #22c55e;
}

.socket-led-badge.green {
  background: #22c55e;
  border: 1px solid #16a34a;
}

.socket-fuse-cap {
  font-size: 6px;
  font-weight: 900;
  font-family: monospace;
  background: #1e293b;
  color: #f8fafc;
  padding: 0 4px;
  border-radius: 2px;
  margin-bottom: 2px;
  letter-spacing: -0.5px;
}

.socket-cover-overlay {
  position: absolute;
  inset: -2px;
  background: rgba(56, 189, 248, 0.2);
  border: 1px dashed rgba(2, 132, 199, 0.6);
  border-radius: 4px;
  pointer-events: none;
}

/* 1 DIN Europlug */
.mod-interior-europlug {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 4px;
}

.europlug-contour {
  width: 24px;
  height: 38px;
  background: #f8fafc;
  border: 1.5px solid #94a3b8;
  border-radius: 8px;
  display: flex;
  gap: 6px;
  align-items: center;
  justify-content: center;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.15);
}

/* 1 DIN USB блок питания */
.mod-interior-usb {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 4px;
}

.usb-port-a {
  width: 22px;
  height: 10px;
  background: #e2e8f0;
  border: 1px solid #64748b;
  border-radius: 2px;
  position: relative;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  box-shadow: inset 0 1px 2px rgba(0,0,0,0.4);
}

.usb-tongue {
  width: 16px;
  height: 3px;
  background: #0284c7;
  border-radius: 1px;
}

.usb-port-c {
  width: 14px;
  height: 6px;
  background: #0f172a;
  border: 1px solid #64748b;
  border-radius: 3px;
  box-shadow: inset 0 1px 2px rgba(0,0,0,0.6);
}

.usb-led-dot {
  width: 5px;
  height: 5px;
  background: #22c55e;
  border-radius: 50%;
  box-shadow: 0 0 4px #22c55e;
}

/* Нижняя бирка с названием потребителя */
.mod-label-strip {
  background: #ffffff;
  border-top: 1px solid #cbd5e1;
  padding: 3px 2px;
  display: flex;
  align-items: center;
  gap: 2px;
  justify-content: center;
  min-height: 20px;
}

.mod-icon {
  font-size: 10px;
}

.mod-name-text {
  font-size: 8px;
  font-weight: 600;
  color: #1e293b;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: calc(100% - 14px);
}

/* Быстрое меню действий при наведении на модуль */
.mod-quick-actions {
  position: absolute;
  top: 2px;
  right: 2px;
  display: none;
  gap: 2px;
  z-index: 25;
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(2px);
  padding: 2px;
  border-radius: 4px;
}

.din-module-unit:hover .mod-quick-actions {
  display: flex;
}

.action-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px;
  font-size: 10px;
  line-height: 1;
  border-radius: 2px;
  transition: background 0.1s;
}

.action-btn:hover {
  background: rgba(255, 255, 255, 0.2);
}

.mod-lock-badge {
  position: absolute;
  top: 18px;
  left: 2px;
  font-size: 8px;
  background: #fef08a;
  border-radius: 2px;
  padding: 0 2px;
}

/* ----------------------------------------------------
   Стили наклеек на пластрон (Маркировочная полоса)
   ---------------------------------------------------- */
.stickers-sheet {
  background: #ffffff;
  padding: 20px;
  border-radius: 8px;
  border: 1px solid #e2e8f0;
}

.sticker-rail-container {
  margin-bottom: 24px;
  page-break-inside: avoid;
}

.sticker-rail-title {
  font-size: 11px;
  font-weight: bold;
  color: #475569;
  margin-bottom: 6px;
  text-transform: uppercase;
}

.sticker-rail-strip {
  display: flex;
  border: 1.5px solid #000000;
  background: #ffffff;
  height: 48mm; /* Стандартная высота маркировочного окна пластрона */
  box-sizing: border-box;
}

.sticker-module {
  box-sizing: border-box;
  border-right: 1px solid #64748b;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 2mm 1.5mm;
  font-family: Arial, sans-serif;
  text-align: center;
  position: relative;
  background: #ffffff;
}

.sticker-module:last-child {
  border-right: none;
}

.sticker-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 7pt;
  font-weight: bold;
  border-bottom: 0.5px solid #cbd5e1;
  padding-bottom: 1mm;
}

.sticker-num {
  color: #1e293b;
}

.sticker-phase {
  font-family: monospace;
  font-weight: bold;
}

.sticker-body {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  padding: 1mm 0;
}

.sticker-icon {
  font-size: 14pt;
  margin-bottom: 1mm;
}

.sticker-name {
  font-size: 7pt;
  font-weight: bold;
  color: #0f172a;
  line-height: 1.1;
  word-break: break-word;
  max-height: 12mm;
  overflow: hidden;
}

.sticker-room {
  font-size: 6pt;
  color: #64748b;
  margin-top: 0.5mm;
}

.sticker-footer {
  font-size: 6pt;
  color: #94a3b8;
  border-top: 0.5px solid #e2e8f0;
  padding-top: 0.5mm;
  text-transform: uppercase;
}

.sticker-empty {
  background: #f8fafc;
  color: #94a3b8;
}

.sticker-empty-label {
  font-size: 6pt;
  color: #94a3b8;
}

/* Цвета фаз на наклейках */
.phase-l1 { border-top: 3mm solid #b45309; }
.phase-l2 { border-top: 3mm solid #047857; }
.phase-l3 { border-top: 3mm solid #b91c1c; }
.phase-3p { border-top: 3mm solid #4338ca; }

/* ----------------------------------------------------
   Стили схемы коммутации (Diagram)
   ---------------------------------------------------- */
.diagram-canvas {
  padding: 16px;
  background: #f8fafc;
  border-radius: 8px;
}

.diagram-section {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
}

.diagram-section-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  color: #1e293b;
  background: #e2e8f0;
  padding: 2px 8px;
  border-radius: 4px;
  margin-bottom: 12px;
}

.diagram-nodes-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.diagram-node {
  background: #f1f5f9;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  padding: 8px 12px;
  min-width: 120px;
}

.diagram-connector {
  color: #94a3b8;
  font-weight: bold;
}

.diagram-busbar-line {
  height: 20px;
  background: linear-gradient(90deg, #3b82f6, #60a5fa, #3b82f6);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 10px;
  font-weight: bold;
  margin: 12px 0 20px 0;
  box-shadow: 0 2px 4px rgba(59, 130, 246, 0.3);
}

.diagram-rcd-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.diagram-group-card {
  background: #ffffff;
  border: 1px solid #93c5fd;
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.diagram-rcd-header {
  background: #eff6ff;
  padding: 8px 12px;
  border-bottom: 1px solid #bfdbfe;
}

.diagram-branch-lines {
  padding: 6px 10px;
}

.diagram-circuit-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px dashed #e2e8f0;
}

.diagram-circuit-row:last-child {
  border-bottom: none;
}

.circuit-lead {
  font-family: monospace;
  color: #94a3b8;
  font-weight: bold;
}

.circuit-breaker-tag {
  font-family: monospace;
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 3px;
  color: white;
}

.tag-l1 { background: #b45309; }
.tag-l2 { background: #047857; }
.tag-l3 { background: #b91c1c; }
.tag-direct { background: #64748b; }

.circuit-info {
  flex: 1;
}

.circuit-name {
  font-size: 12px;
  font-weight: 600;
  color: #1e293b;
}

.circuit-details {
  font-size: 10px;
  color: #64748b;
  display: flex;
  gap: 8px;
  margin-top: 2px;
}

/* ----------------------------------------------------
   Стили для печати (@media print)
   ---------------------------------------------------- */
@media print {
  body {
    background: #ffffff !important;
    padding: 0 !important;
  }

  /* Скрываем навигацию, боковые панели, кнопки */
  header,
  aside,
  .no-print,
  #app-sidebar,
  #app-toolbar,
  #right-inspector,
  .tabs-navigation {
    display: none !important;
  }

  main {
    margin: 0 !important;
    padding: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
  }

  .stickers-sheet {
    border: none !important;
    padding: 0 !important;
  }

  .sticker-rail-strip {
    height: 48mm !important;
    page-break-inside: avoid !important;
  }
}

/* ----------------------------------------------------
   Миниатюры приборов в каталоге и инспекторе
   ---------------------------------------------------- */
.device-thumb-box {
  position: relative;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
  overflow: hidden;
}

.device-thumb-box .din-device-vector {
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.08));
}

.catalog-item-card:hover .device-thumb-box {
  transform: scale(1.04);
  box-shadow: 0 4px 8px -2px rgba(0, 0, 0, 0.1);
}

/* ----------------------------------------------------
   Визуализация электрических цепей и трассировки
   ---------------------------------------------------- */
.din-module-unit.in-active-circuit {
  transform: translateY(-5px) scale(1.02);
  box-shadow: 0 0 0 3px #3b82f6, 0 12px 24px -4px rgba(59, 130, 246, 0.45);
  z-index: 25;
}

.din-module-unit.in-active-circuit.is-source-rcd {
  box-shadow: 0 0 0 3px #10b981, 0 12px 24px -4px rgba(16, 185, 129, 0.5);
}

.din-module-unit.in-active-circuit.is-incomer-lead {
  box-shadow: 0 0 0 3px #d97706, 0 12px 24px -4px rgba(217, 119, 6, 0.5);
}

.din-module-unit.dimmed-out {
  opacity: 0.32;
  filter: grayscale(45%);
  transform: scale(0.98);
  transition: opacity 0.2s ease, filter 0.2s ease, transform 0.2s ease;
}

/* Бейджик принадлежности к электрической цепи */
.mod-circuit-pill {
  margin: 1px 3px 2px 3px;
  padding: 1.5px 3px;
  border-radius: 3px;
  font-size: 8px;
  font-weight: 800;
  color: #ffffff;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
  z-index: 6;
  pointer-events: none;
  letter-spacing: -0.2px;
  line-height: 1.2;
}

/* Соединительная гребёнка PIN-шины над клеммами аппаратов */
.din-busbar-bridge {
  position: absolute;
  top: 3px;
  height: 12px;
  border-radius: 3px;
  background: linear-gradient(180deg, #d97706 0%, #b45309 100%);
  border-top: 1px solid #fef08a;
  border-bottom: 1px solid rgba(0, 0, 0, 0.4);
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.35);
  z-index: 22;
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.din-busbar-bridge .busbar-tag {
  font-size: 7.5px;
  font-weight: 900;
  color: #ffffff;
  padding: 0 4px;
  border-radius: 2px;
  white-space: nowrap;
  text-shadow: 0 1px 2px rgba(0,0,0,0.6);
  letter-spacing: -0.2px;
}

/* Тулбар электрических цепей */
.circuit-toolbar {
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-2px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ==========================================================================
   ТЁМНАЯ ТЕМА ОФОРМЛЕНИЯ (DARK THEME)
   ========================================================================== */

.dark {
  --din-metal-bg: linear-gradient(180deg, #334155 0%, #475569 30%, #1e293b 70%, #0f172a 100%);
  --cabinet-bg: #090d16;
  --cabinet-border: #1e293b;
  color-scheme: dark;
}

/* Корпус электрощита и ряды в тёмной теме */
.dark .din-cabinet-enclosure {
  background: #0d131f;
  border-color: #334155;
  box-shadow: 0 20px 30px -10px rgba(0, 0, 0, 0.7), 0 10px 15px -5px rgba(0, 0, 0, 0.5);
}

.dark .din-cabinet-header {
  border-bottom-color: #1e293b;
}

.dark .din-rail-row {
  background: #070b12;
  border-color: #1e293b;
}

.dark .din-track-container {
  background: #030712;
  box-shadow: inset 0 3px 8px rgba(0, 0, 0, 0.85);
}

.dark .din-metal-rail {
  border-top-color: #475569;
  border-bottom-color: #020617;
  box-shadow: 0 3px 7px rgba(0, 0, 0, 0.6);
}

.dark .din-metal-rail::after {
  background-image: repeating-linear-gradient(
    90deg,
    #020617,
    #020617 14px,
    transparent 14px,
    transparent 32px
  );
  opacity: 0.6;
}

.dark .din-slot-tick {
  background: rgba(255, 255, 255, 0.08);
}

.dark .din-slot-num {
  color: #64748b;
}

.dark .din-empty-slot {
  border-color: #1e293b;
  color: #475569;
}

.dark .din-empty-slot:hover {
  border-color: #3b82f6;
  background: rgba(59, 130, 246, 0.08);
}

/* Модули на DIN-рейке остаются классическими светлыми (пластик RAL 7035 / Hager / ABB),
   чтобы они имели четкий контраст и не сливались с тёмным фоном щита и реек */
.dark .din-module-unit {
  background: linear-gradient(180deg, #ffffff 0%, #f8fafc 45%, #e2e8f0 100%);
  border: 1px solid #94a3b8;
  color: #0f172a;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5), 0 1px 3px rgba(0, 0, 0, 0.3);
}

.dark .din-module-unit:hover {
  transform: translateY(-2px);
  border-color: #3b82f6;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.7), 0 0 0 2px #3b82f6;
}

.dark .din-module-unit.is-selected {
  outline: 3px solid #3b82f6;
  box-shadow: 0 0 0 2px #93c5fd, 0 10px 24px rgba(59, 130, 246, 0.45);
}

/* Каталог аппаратов и миниатюры в тёмной теме */
.dark .catalog-item-card {
  background: #0f172a;
  border-color: #1e293b;
  color: #f1f5f9;
}

.dark .catalog-item-card:hover {
  background: #1e293b;
  border-color: #3b82f6;
  box-shadow: 0 4px 12px -2px rgba(0, 0, 0, 0.5);
}

.dark .device-thumb-box {
  background: #1e293b;
  border-color: #334155;
}

/* Тулбар цепей в тёмной теме */
.dark .circuit-toolbar {
  background: #0f172a;
  border-color: #1e293b;
  box-shadow: 0 4px 12px -2px rgba(0, 0, 0, 0.5);
}

/* ==========================================================================
   АДАПТАЦИЯ ДИНАМИЧЕСКИХ ВКЛАДОК (BOM, ESTIMATE, DIAGRAM, INSPECTOR, CROSSCHECK)
   ========================================================================== */

.dark #tab-pane-bom .bg-white,
.dark #tab-pane-estimate .bg-white,
.dark #tab-pane-diagram .bg-white {
  background-color: #0f172a !important;
}

.dark #tab-pane-bom .bg-slate-50,
.dark #tab-pane-estimate .bg-slate-50,
.dark #tab-pane-diagram .bg-slate-50 {
  background-color: #1e293b !important;
}

.dark #tab-pane-bom .bg-slate-100,
.dark #tab-pane-estimate .bg-slate-100,
.dark #tab-pane-diagram .bg-slate-100 {
  background-color: #334155 !important;
}

.dark #tab-pane-bom .border-slate-200,
.dark #tab-pane-estimate .border-slate-200,
.dark #tab-pane-diagram .border-slate-200,
.dark #tab-pane-bom .border-slate-300,
.dark #tab-pane-estimate .border-slate-300 {
  border-color: #1e293b !important;
}

.dark #tab-pane-bom .text-slate-900,
.dark #tab-pane-estimate .text-slate-900,
.dark #tab-pane-diagram .text-slate-900,
.dark #tab-pane-bom .text-slate-800,
.dark #tab-pane-estimate .text-slate-800,
.dark #tab-pane-diagram .text-slate-800 {
  color: #f8fafc !important;
}

.dark #tab-pane-bom .text-slate-700,
.dark #tab-pane-estimate .text-slate-700,
.dark #tab-pane-diagram .text-slate-700 {
  color: #e2e8f0 !important;
}

.dark #tab-pane-bom .text-slate-600,
.dark #tab-pane-estimate .text-slate-600,
.dark #tab-pane-diagram .text-slate-600 {
  color: #cbd5e1 !important;
}

.dark #tab-pane-bom .text-slate-500,
.dark #tab-pane-estimate .text-slate-500,
.dark #tab-pane-diagram .text-slate-500 {
  color: #94a3b8 !important;
}

.dark #tab-pane-bom tr:hover,
.dark #tab-pane-estimate tr:hover {
  background-color: rgba(255, 255, 255, 0.03) !important;
}

/* Инспектор параметров в тёмной теме */
.dark #module-inspector input,
.dark #module-inspector select,
.dark #module-inspector textarea {
  background-color: #1e293b !important;
  border-color: #334155 !important;
  color: #f8fafc !important;
}

.dark #module-inspector .bg-slate-50 {
  background-color: #1e293b !important;
}

.dark #module-inspector .bg-white {
  background-color: #0f172a !important;
}

.dark #module-inspector .border-slate-200 {
  border-color: #1e293b !important;
}

.dark #module-inspector .text-slate-800 {
  color: #f8fafc !important;
}

.dark #module-inspector .text-slate-700 {
  color: #cbd5e1 !important;
}

/* Балансировка фаз в тёмной теме */
.dark #phase-balance-widget .bg-slate-50 {
  background-color: #1e293b !important;
}

.dark #phase-balance-widget .bg-slate-100 {
  background-color: #334155 !important;
}

.dark #phase-balance-widget .border-slate-200 {
  border-color: #1e293b !important;
}

.dark #phase-balance-widget .text-slate-800 {
  color: #f8fafc !important;
}

.dark #phase-balance-widget .text-slate-700 {
  color: #e2e8f0 !important;
}

.dark #phase-balance-widget .text-slate-600 {
  color: #cbd5e1 !important;
}

/* Crosscheck алерты в тёмной теме */
.dark #crosscheck-panel .bg-amber-50 {
  background-color: rgba(245, 158, 11, 0.12) !important;
  border-color: rgba(245, 158, 11, 0.3) !important;
}

.dark #crosscheck-panel .text-amber-900,
.dark #crosscheck-panel .text-amber-800 {
  color: #fde68a !important;
}

.dark #crosscheck-panel .bg-red-50 {
  background-color: rgba(239, 68, 68, 0.12) !important;
  border-color: rgba(239, 68, 68, 0.3) !important;
}

.dark #crosscheck-panel .text-red-900,
.dark #crosscheck-panel .text-red-800 {
  color: #fca5a5 !important;
}

.dark #crosscheck-panel .bg-blue-50 {
  background-color: rgba(59, 130, 246, 0.12) !important;
  border-color: rgba(59, 130, 246, 0.3) !important;
}

.dark #crosscheck-panel .text-blue-900,
.dark #crosscheck-panel .text-blue-800 {
  color: #93c5fd !important;
}

.dark #crosscheck-panel .bg-emerald-50 {
  background-color: rgba(16, 185, 129, 0.12) !important;
  border-color: rgba(16, 185, 129, 0.3) !important;
}

.dark #crosscheck-panel .text-emerald-900,
.dark #crosscheck-panel .text-emerald-800 {
  color: #6ee7b7 !important;
}

/* Карточки каталога проектов в тёмной теме */
.dark #projects-catalog-grid .bg-white {
  background-color: #0f172a !important;
  border-color: #1e293b !important;
}

.dark #projects-catalog-grid .text-slate-800,
.dark #projects-catalog-grid .text-slate-900 {
  color: #f8fafc !important;
}

.dark #projects-catalog-grid .text-slate-600,
.dark #projects-catalog-grid .text-slate-500 {
  color: #94a3b8 !important;
}

.dark #projects-catalog-grid .bg-slate-50 {
  background-color: #1e293b !important;
}

/* ==========================================================================
   ПЕЧАТЬ И ЭКСПОРТ В PDF (ЧИСТЫЙ БЕЛЫЙ ФОН ПРИ ПЕЧАТИ)
   ========================================================================== */

@media print {
  /* Принудительно отключаем тёмную тему при печати на бумаге / в PDF */
  html, body, .dark, .dark body {
    background: #ffffff !important;
    background-color: #ffffff !important;
    color: #000000 !important;
    color-scheme: light !important;
  }

  .dark .din-cabinet-enclosure {
    background: #ffffff !important;
    border: 2px solid #94a3b8 !important;
    box-shadow: none !important;
  }

  .dark .din-rail-row {
    background: #f1f5f9 !important;
    border: 1px solid #e2e8f0 !important;
  }

  .dark .din-track-container {
    background: #e2e8f0 !important;
    box-shadow: none !important;
  }

  .dark .din-metal-rail {
    background: linear-gradient(180deg, #94a3b8 0%, #cbd5e1 30%, #64748b 70%, #475569 100%) !important;
  }

  .dark .din-module-unit {
    background: #f8fafc !important;
    border: 1px solid #cbd5e1 !important;
    color: #0f172a !important;
    box-shadow: none !important;
  }

  .dark .mod-brand-tag,
  .dark .mod-series-tag {
    color: #475569 !important;
  }

  .dark .mod-name-label,
  .dark .mod-rating-badge {
    color: #0f172a !important;
  }

  .dark #tab-pane-estimate .bg-white,
  .dark #tab-pane-bom .bg-white {
    background-color: #ffffff !important;
    color: #000000 !important;
  }

  .dark #tab-pane-estimate .text-slate-800,
  .dark #tab-pane-bom .text-slate-800 {
    color: #000000 !important;
  }

  .no-print {
    display: none !important;
  }
}



