/* --- AI NODE CANVAS ENGINE STYLES --- */

#screen-canvas {
  padding: 0 !important;
  margin: 0;
  height: calc(100vh - 74px);
  position: relative;
  overflow: hidden;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #0b0c10;
  width: 100%;
}

.canvas-layout {
  display: flex;
  height: 100%;
  width: 100%;
  position: relative;
}

.canvas-panel {
  width: 200px;
  background: #12131a;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 12px 10px;
  z-index: 25;
  overflow-y: auto;
  overflow-x: hidden;
  flex-shrink: 0;
  transition: width 0.22s cubic-bezier(0.4, 0, 0.2, 1), padding 0.22s ease;
  user-select: none;
  box-sizing: border-box;
}

.sidebar-top-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  gap: 6px;
  width: 100%;
}

.canvas-panel.collapsed {
  width: 54px;
  padding: 12px 7px;
  align-items: center;
}

.canvas-panel.collapsed .btn-label,
.canvas-panel.collapsed .canvas-panel-title,
.canvas-panel.collapsed .sidebar-help-box {
  display: none !important;
}

.canvas-panel.collapsed .sidebar-top-row {
  flex-direction: column;
  gap: 6px;
  margin-bottom: 8px;
}

.canvas-panel.collapsed .btn-sidebar-toggle {
  display: flex;
  width: 38px;
  height: 30px;
  justify-content: center;
  align-items: center;
  border-radius: 6px;
}

.canvas-panel.collapsed .btn-new-project,
.canvas-panel.collapsed .sidebar-btn {
  width: 38px;
  height: 38px;
  padding: 0;
  justify-content: center;
  border-radius: 8px;
}

.canvas-panel-title {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  margin-bottom: 6px;
  margin-top: 4px;
  font-weight: 700;
  padding-left: 2px;
}

.sidebar-btn-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
  width: 100%;
}

.sidebar-btn {
  width: 100%;
  height: 34px;
  border-radius: 6px;
  background: #181a24;
  border: 1px solid var(--border);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding: 0 8px;
  gap: 8px;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  box-sizing: border-box;
  text-align: left;
}

.sidebar-btn:hover {
  background: rgba(197, 160, 89, 0.14);
  border-color: var(--accent);
  color: #fff;
  transform: translateY(-1px);
}

.sidebar-btn:active {
  transform: translateY(0);
}

.btn-icon {
  font-size: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  flex-shrink: 0;
}

.btn-label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 11px;
}

.btn-new-project {
  flex: 1;
  height: 34px;
  background: linear-gradient(135deg, #c5a059 0%, #a8843c 100%);
  color: #0c0e14;
  font-weight: 700;
  font-size: 11px;
  border-radius: 6px;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  box-shadow: 0 3px 10px rgba(197, 160, 89, 0.2);
  transition: all 0.15s;
  box-sizing: border-box;
}
.btn-new-project:hover {
  filter: brightness(1.1);
  transform: translateY(-1px);
}

.btn-sidebar-toggle {
  width: 28px;
  height: 34px;
  background: #181a24;
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  font-family: inherit;
  transition: all 0.15s;
  flex-shrink: 0;
}
.btn-sidebar-toggle:hover {
  color: #fff;
  border-color: var(--accent);
  background: rgba(197, 160, 89, 0.12);
}

.sidebar-bottom-section {
  margin-top: auto;
  padding-top: 10px;
  border-top: 1px solid rgba(255,255,255,0.06);
  width: 100%;
  display: flex;
  flex-direction: column;
}

.sidebar-help-box {
  margin-top: 8px;
  font-size: 9px;
  color: var(--text-dim);
  line-height: 1.5;
  background: rgba(255,255,255,0.02);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
}

.canvas-viewport {
  flex: 1;
  height: 100%;
  position: relative;
  overflow: hidden;
  background-color: #0b0c10;
  background-image: radial-gradient(circle, rgba(255,255,255,0.08) 1px, transparent 1px);
  background-size: 24px 24px;
  cursor: grab;
}
.canvas-viewport.panning {
  cursor: grabbing;
}

.canvas-transform-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  transform-origin: 0 0;
}

.connections-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 6000px;
  height: 4000px;
  pointer-events: none;
  z-index: 15;
}

.wire-group {
  cursor: pointer;
  pointer-events: all;
}
.wire-hitbox {
  fill: none;
  stroke: transparent;
  stroke-width: 26;
  cursor: pointer;
}
.wire-path {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2.8;
  stroke-linecap: round;
  filter: drop-shadow(0 0 6px var(--accent-glow));
  transition: stroke 0.15s, stroke-width 0.15s;
  pointer-events: none;
}
.wire-path.flow {
  stroke-dasharray: 6, 6;
  animation: wireFlow 1.2s linear infinite;
}
.wire-group:hover .wire-path {
  stroke: #ff4757 !important;
  stroke-width: 4 !important;
  filter: drop-shadow(0 0 12px rgba(255,71,87,0.85)) !important;
}
.wire-delete-badge {
  opacity: 0;
  pointer-events: all;
  transition: opacity 0.15s, transform 0.15s;
  cursor: pointer;
}
.wire-group:hover .wire-delete-badge {
  opacity: 1;
  transform: scale(1.1);
}

.node {
  position: absolute;
  background: #181a24;
  border: 1px solid var(--border);
  border-radius: 12px;
  min-width: 260px;
  min-height: 140px;
  box-shadow: 0 12px 32px rgba(0,0,0,0.55);
  z-index: 20;
  transition: box-shadow 0.15s, border-color 0.15s;
  cursor: default;
  display: flex;
  flex-direction: column;
}
.node:hover, .node.selected {
  border-color: var(--accent);
  box-shadow: 0 12px 28px var(--accent-glow);
}

.node-header {
  padding: 8px 12px;
  background: #1f2230;
  border-top-left-radius: 11px;
  border-top-right-radius: 11px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: move;
  user-select: none;
}
.node-title {
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 6px;
  color: #fff;
}
.node-badge {
  font-size: 9px;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(197,160,89,0.14);
  color: var(--accent);
  font-weight: 600;
}

/* Node Help Button & Hover Tooltip */
.node-help-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 17px;
  height: 17px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: var(--text-dim);
  font-size: 10px;
  font-weight: 700;
  cursor: help;
  transition: all 0.15s ease;
  position: relative;
  user-select: none;
}
.node-help-btn:hover {
  background: var(--accent);
  color: #0c0e14;
  border-color: var(--accent);
  transform: scale(1.15);
  box-shadow: 0 0 10px var(--accent-glow);
}
.node-help-btn[data-tip]::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%) scale(0.9);
  background: rgba(18, 20, 28, 0.97);
  backdrop-filter: blur(14px);
  color: #e6e7eb;
  border: 1px solid rgba(212, 175, 55, 0.35);
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 11px;
  line-height: 1.45;
  font-weight: 400;
  white-space: normal;
  width: max-content;
  max-width: 250px;
  text-align: left;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.85), 0 0 15px rgba(212, 175, 55, 0.15);
  z-index: 1000;
}
.node-help-btn:hover[data-tip]::after {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) scale(1);
}

.node-body {
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.node-resizer {
  position: absolute;
  right: 2px;
  bottom: 2px;
  width: 18px;
  height: 18px;
  cursor: nwse-resize;
  z-index: 35;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.45;
  transition: opacity 0.15s, transform 0.15s;
  user-select: none;
}
.node-resizer:hover, .node-resizer.resizing {
  opacity: 1;
  transform: scale(1.2);
}
.node-resizer::after {
  content: '';
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--accent);
  border-bottom: 2px solid var(--accent);
  border-bottom-right-radius: 2px;
}

.node-pin {
  position: absolute;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #0e1017;
  box-shadow: 0 0 8px var(--accent-glow);
  top: 50%;
  transform: translateY(-50%);
  cursor: crosshair;
  z-index: 40;
  transition: transform 0.2s, box-shadow 0.2s, background-color 0.2s;
}
.node-pin:hover, .node-pin.pin-active {
  transform: translateY(-50%) scale(1.45);
  box-shadow: 0 0 12px var(--accent), 0 0 18px var(--accent-glow);
}
.node-pin.pin-compatible {
  animation: pinPulse 0.8s infinite alternate;
}
@keyframes pinPulse {
  from { transform: translateY(-50%) scale(1.2); box-shadow: 0 0 10px #2ed573; border-color:#2ed573; }
  to { transform: translateY(-50%) scale(1.6); box-shadow: 0 0 22px #2ed573, 0 0 32px #2ed573; border-color:#2ed573; }
}

.node-pin.pin-in { left: -7px; }
.node-pin.pin-out { right: -7px; }

.node-pin.pin-incompatible {
  background: var(--error) !important;
  box-shadow: 0 0 12px var(--error) !important;
  opacity: 0.4;
  cursor: not-allowed;
}

/* Pin Port Colors */
.node-pin[data-type="audio"] { background: var(--wire-audio); box-shadow: 0 0 8px rgba(197, 160, 89, 0.45); }
.node-pin[data-type="prompt"] { background: var(--wire-prompt); box-shadow: 0 0 8px var(--wire-prompt); }
.node-pin[data-type="video"] { background: var(--wire-video); box-shadow: 0 0 8px var(--wire-video); }
.node-pin[data-type="vision"] { background: var(--wire-vision); box-shadow: 0 0 8px var(--wire-vision); }
.node-pin[data-type="render"] { background: var(--wire-render); box-shadow: 0 0 8px var(--wire-render); }

.canvas-bottom-bar {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(24, 26, 36, 0.92);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border);
  border-radius: 30px;
  padding: 4px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  z-index: 30;
  box-shadow: 0 8px 24px rgba(0,0,0,0.6);
}

/* Canvas Minimap */
.minimap-container {
  position: absolute;
  bottom: 16px;
  right: 16px;
  width: 160px;
  height: 110px;
  background: rgba(18, 20, 28, 0.85);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  z-index: 30;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  cursor: pointer;
  transition: opacity 0.2s, transform 0.2s, border-color 0.2s;
  user-select: none;
}
.minimap-container:hover {
  border-color: var(--accent);
}
.minimap-canvas {
  width: 100%;
  height: 100%;
  display: block;
}
.minimap-viewport-rect {
  position: absolute;
  border: 1.5px solid var(--accent);
  background: rgba(197, 160, 89, 0.12);
  border-radius: 3px;
  pointer-events: none;
}

/* --- МОБИЛЬНАЯ АДАПТАЦИЯ ДЛЯ СМАРТФОНОВ И ПЛАНШЕТОВ (< 768px) --- */
@media (max-width: 768px) {
  #screen-canvas {
    height: calc(100vh - 62px);
    border-radius: 0;
    border-left: none;
    border-right: none;
  }
  
  /* Боковая панель переходит в выезжающий drawer поверх холста */
  .canvas-panel {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    width: 230px;
    z-index: 60;
    background: rgba(14, 15, 22, 0.98);
    backdrop-filter: blur(20px);
    box-shadow: 6px 0 25px rgba(0, 0, 0, 0.85);
    border-right: 1px solid var(--border);
  }
  
  .canvas-panel.collapsed {
    width: 0px !important;
    padding: 0 !important;
    border-right: none !important;
    overflow: hidden !important;
  }
  
  /* Нижняя панель управления на мобильных */
  .canvas-bottom-bar {
    bottom: 12px;
    padding: 4px 8px;
    gap: 4px;
    max-width: 95%;
    background: rgba(18, 20, 28, 0.95);
  }
  
  .canvas-bottom-bar .tool-btn {
    padding: 4px 7px;
    font-size: 11px;
    min-height: 32px;
  }
  
  /* Скрываем мини-карту на мобильных, освобождая полезное пространство */
  .minimap-container {
    display: none !important;
  }
  
  /* Ноды на мобильных устройствах */
  .node {
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.85);
  }
  
  .node-title {
    font-size: 12px;
  }
}

