/**
 * Node Editor Styles
 * 
 * Styles for the visual node-based rules editor including:
 * - Node components (header, body, connection points)
 * - Block palette and properties panel
 * - SVG connections
 * - Hover and selection states
 * - Validation error styles
 */

/* ============================================================================
   LAYOUT
   ============================================================================ */

.node-editor-container {
  display: flex;
  height: calc(100vh - 200px);
  min-height: 600px;
  background-color: #f8f9fa;
  border: 1px solid #dee2e6;
  border-radius: 0.375rem;
  overflow: hidden;
}

/* Block Palette Sidebar */
.block-palette-sidebar {
  width: 250px;
  background-color: #ffffff;
  border-right: 1px solid #dee2e6;
  overflow-y: auto;
  padding: 1rem;
  flex-shrink: 0;
}

/* Canvas Area */
.canvas-area {
  flex: 1;
  position: relative;
  overflow: hidden;
  background-color: #f8f9fa;
  background-image: 
    linear-gradient(rgba(0, 0, 0, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0, 0, 0, 0.05) 1px, transparent 1px);
  background-size: 20px 20px;
}

/* Properties Panel Sidebar */
.properties-panel-sidebar {
  width: 300px;
  background-color: #ffffff;
  border-left: 1px solid #dee2e6;
  overflow-y: auto;
  padding: 1rem;
  flex-shrink: 0;
}

/* ============================================================================
   NODE CANVAS
   ============================================================================ */

#node-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
}

#connections-svg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
}

#connections-svg .connection-line {
  pointer-events: stroke;
}

/* ============================================================================
   NODE COMPONENTS
   ============================================================================ */

.node {
  position: absolute;
  width: 280px;
  min-width: 200px;
  min-height: min-content;
  background-color: #343a40;
  border: 2px solid #6c757d;
  border-radius: 0.5rem;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  cursor: move;
  user-select: none;
  z-index: 10;
  transition: box-shadow 0.2s ease, transform 0.1s ease;
  resize: none; /* Prevent default resize */
  color: #ffffff;
  overflow: visible; /* Позволяет точкам соединения выходить за границы ноды */
}

.node:hover {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  z-index: 11;
}

.node.selected {
  border-color: #0d6efd;
  box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.25);
  z-index: 12;
}

.node.dragging {
  opacity: 0.8;
  cursor: grabbing;
  z-index: 100;
}

.node.resizing {
  transition: none;
  z-index: 100;
}

/* Resize handles - invisible but active */
.node-resize-handle {
  position: absolute;
  z-index: 25;
}

/* Corner handles */
.node-resize-handle.nw {
  top: 0;
  left: 0;
  width: 15px;
  height: 15px;
  cursor: nw-resize;
}

.node-resize-handle.ne {
  top: 0;
  right: 0;
  width: 15px;
  height: 15px;
  cursor: ne-resize;
}

.node-resize-handle.sw {
  bottom: 0;
  left: 0;
  width: 15px;
  height: 15px;
  cursor: sw-resize;
}

.node-resize-handle.se {
  bottom: 0;
  right: 0;
  width: 15px;
  height: 15px;
  cursor: se-resize;
}

/* Edge handles */
.node-resize-handle.n {
  top: 0;
  left: 15px;
  right: 15px;
  height: 8px;
  cursor: n-resize;
}

.node-resize-handle.s {
  bottom: 0;
  left: 15px;
  right: 15px;
  height: 8px;
  cursor: s-resize;
}

.node-resize-handle.e {
  top: 15px;
  right: 0;
  bottom: 15px;
  width: 8px;
  cursor: e-resize;
}

.node-resize-handle.w {
  top: 15px;
  left: 0;
  bottom: 15px;
  width: 8px;
  cursor: w-resize;
}

.node.invalid {
  border-color: #dc3545;
}

.node.invalid .node-header {
  background-color: #dc3545 !important;
}

/* Node Header */
.node-header {
  display: flex;
  align-items: center;
  padding: 0.6rem 0.85rem;
  background-color: #6c757d;
  color: #ffffff;
  border-radius: 0.375rem 0.375rem 0 0;
  font-weight: 600;
  font-size: 0.95rem;
  gap: 0.5rem;
}

.node-icon {
  font-size: 1.2rem;
  flex-shrink: 0;
}

.node-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  letter-spacing: 0.02em;
}

.btn-node-delete {
  background: none;
  border: none;
  color: #ffffff;
  padding: 0.25rem;
  cursor: pointer;
  opacity: 0.7;
  transition: opacity 0.2s ease;
  flex-shrink: 0;
}

.btn-node-delete:hover {
  opacity: 1;
}

/* Node Body */
.node-body {
  padding: 0.85rem;
  font-size: 0.9rem;
  max-height: 350px;
  min-height: min-content;
  overflow-y: scroll;
  overflow-x: hidden;
  line-height: 1.5;
  color: #ffffff;
}

.node-body label,
.node-body .form-label {
  font-weight: 600;
  font-size: 0.85rem;
  color: #e9ecef;
  margin-bottom: 0.35rem;
}

.node-body input,
.node-body select,
.node-body textarea {
  font-size: 0.9rem;
  padding: 0.4rem 0.6rem;
  background-color: #495057;
  color: #ffffff;
  border-color: #6c757d;
}

.node-body .form-control,
.node-body .form-select {
  background-color: #495057;
  color: #ffffff;
  border-color: #6c757d;
}

.node-body .form-control:focus,
.node-body .form-select:focus {
  background-color: #495057;
  color: #ffffff;
  border-color: #86b7fe;
  box-shadow: 0 0 0 0.2rem rgba(13, 110, 253, 0.15);
}

/* White text for node body content - only text elements */
.node-body .text-muted {
  font-size: 0.8rem;
  color: #e9ecef !important;
}

.node-body .form-text {
  color: #e9ecef !important;
}

.node-body small {
  color: #e9ecef !important;
}

.node-body p,
.node-body span:not(.badge),
.node-body label,
.node-body .form-label {
  color: #ffffff;
}

.node-body .badge {
  font-size: 0.75rem;
  font-weight: 500;
  padding: 0.35em 0.6em;
}

.node-body::-webkit-scrollbar {
  width: 6px;
}

.node-body::-webkit-scrollbar-track {
  background: #495057;
}

.node-body::-webkit-scrollbar-thumb {
  background: #6c757d;
  border-radius: 3px;
}

.node-body::-webkit-scrollbar-thumb:hover {
  background: #adb5bd;
}

/* Connection Points */
.node-connection-point {
  position: absolute;
  width: 16px;
  height: 16px;
  background-color: #6c757d;
  border: 2px solid #ffffff;
  border-radius: 50%;
  cursor: pointer;
  z-index: 20;
  transition: all 0.2s ease;
}

.node-connection-point:hover {
  background-color: #0d6efd;
  transform: scale(1.3);
}

.node-connection-point.input {
  top: -8px;
  left: 50%;
  transform: translateX(-50%);
}

.node-connection-point.output {
  bottom: -8px;
  left: 50%;
  transform: translateX(-50%);
}

.node-connection-point.input:hover,
.node-connection-point.output:hover {
  transform: translateX(-50%) scale(1.3);
}

/* Conditional Logic Node - Multiple Outputs */
.conditional-outputs {
  padding: 0.5rem;
  background-color: #495057;
  border-top: 1px solid #6c757d;
}

.conditional-output-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.4rem 0.5rem;
  margin-bottom: 0.4rem;
  background-color: #343a40;
  border-radius: 0.375rem;
  border: 1px solid #6c757d;
  position: relative;
}

.conditional-output-row:last-child {
  margin-bottom: 0;
}

.conditional-label {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  padding: 0.25rem 0.5rem;
  border-radius: 0.25rem;
  user-select: none;
}

.then-label {
  background-color: #d1e7dd;
  color: #0a3622;
}

.else-label {
  background-color: #f8d7da;
  color: #58151c;
}

/* Conditional output connection points */
.node-connection-point.conditional-then {
  position: relative;
  background-color: #198754;
  border-color: #ffffff;
  margin: 0;
  top: auto;
  left: auto;
  transform: none;
}

.node-connection-point.conditional-then:hover {
  background-color: #146c43;
  transform: scale(1.3);
}

.node-connection-point.conditional-else {
  position: relative;
  background-color: #dc3545;
  border-color: #ffffff;
  margin: 0;
  top: auto;
  left: auto;
  transform: none;
}

.node-connection-point.conditional-else:hover {
  background-color: #b02a37;
  transform: scale(1.3);
}

/* ============================================================================
   FILTER NODE CLAUSES
   ============================================================================ */

.clause-item {
  background-color: #495057;
  border: 1px solid #6c757d !important;
  color: #ffffff;
}

.clause-item:hover {
  background-color: #5a6268;
}

.clauses-container {
  max-height: 300px;
  overflow-y: auto;
}

/* Conditional Logic Clause Cards (Properties Panel) */
.clause-card {
  transition: background-color 0.2s ease;
}

.clause-card:hover {
  background-color: #e9ecef !important;
}

.clauses-list {
  max-height: 400px;
  overflow-y: auto;
}

/* ============================================================================
   BLOCK PALETTE
   ============================================================================ */

.block-category {
  margin-bottom: 1rem;
}

.block-category-header {
  padding-bottom: 0.5rem;
  border-bottom: 2px solid #dee2e6;
}

.blocks-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.block-palette-item {
  display: flex;
  align-items: center;
  padding: 0.5rem 0.75rem;
  background-color: #f8f9fa;
  border: 1px solid #dee2e6;
  border-radius: 0.375rem;
  cursor: grab;
  transition: all 0.2s ease;
  user-select: none;
}

.block-palette-item:hover {
  background-color: #e9ecef;
  border-color: #adb5bd;
  transform: translateX(4px);
}

.block-palette-item:active {
  cursor: grabbing;
}

.block-palette-item.dragging {
  opacity: 0.5;
}

.block-palette-item.highlighted {
  background-color: #cfe2ff;
  border-color: #0d6efd;
}

.block-icon {
  font-size: 1.2rem;
  flex-shrink: 0;
}

.block-name {
  font-weight: 500;
  color: #212529;
}

/* ============================================================================
   PROPERTIES PANEL
   ============================================================================ */

.properties-content {
  font-size: 0.875rem;
}

.info-section .badge {
  font-size: 0.75rem;
  padding: 0.35rem 0.65rem;
}

.parameters-section .form-label {
  margin-bottom: 0.25rem;
  font-weight: 600;
  color: #495057;
}

.parameters-section .form-control,
.parameters-section .form-select {
  font-size: 0.875rem;
}

.validation-section .alert {
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
}

.validation-section ul {
  padding-left: 1.25rem;
  margin-bottom: 0;
}

.actions-section {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid #dee2e6;
}

/* ============================================================================
   SVG CONNECTIONS
   ============================================================================ */

.connections .connection {
  cursor: pointer;
}

.connections .connection-line {
  transition: stroke 0.2s ease, stroke-width 0.2s ease;
}

.connections .connection:hover .connection-line {
  stroke: #0d6efd !important;
  stroke-width: 3 !important;
}

.connections .connection.selected .connection-line {
  stroke: #0d6efd !important;
  stroke-width: 3 !important;
}

.temp-connection path {
  pointer-events: none;
}

/* ============================================================================
   TOOLBAR
   ============================================================================ */

.node-editor-toolbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  background-color: #ffffff;
  border-bottom: 1px solid #dee2e6;
  flex-wrap: wrap;
}

.node-editor-toolbar .btn {
  font-size: 0.875rem;
}

.node-editor-toolbar .btn-group {
  gap: 0;
}

.toolbar-divider {
  width: 1px;
  height: 24px;
  background-color: #dee2e6;
  margin: 0 0.5rem;
}

/* ============================================================================
   VALIDATION STATES
   ============================================================================ */

.node.has-errors {
  border-color: #dc3545;
}

.node.has-warnings {
  border-color: #ffc107;
}

.node.has-errors .node-header {
  background-color: #dc3545 !important;
}

.node.has-warnings .node-header {
  background-color: #ffc107 !important;
  color: #000000;
}

/* Validation badge in node */
.validation-badge {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background-color: #dc3545;
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: bold;
  z-index: 30;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.validation-badge.warning {
  background-color: #ffc107;
  color: #000000;
}

/* ============================================================================
   LOADING STATES
   ============================================================================ */

.node-editor-loading {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  z-index: 1000;
}

.node-editor-loading .spinner-border {
  width: 3rem;
  height: 3rem;
}

/* ============================================================================
   EMPTY STATE
   ============================================================================ */

.canvas-empty-state {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  color: #6c757d;
  pointer-events: none;
  user-select: none;
}

.canvas-empty-state i {
  font-size: 4rem;
  opacity: 0.3;
  margin-bottom: 1rem;
}

.canvas-empty-state h5 {
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.canvas-empty-state p {
  font-size: 0.875rem;
  opacity: 0.7;
}

/* ============================================================================
   MINIMAP (Optional)
   ============================================================================ */

.node-editor-minimap {
  position: absolute;
  bottom: 20px;
  right: 20px;
  width: 200px;
  height: 150px;
  background-color: rgba(255, 255, 255, 0.9);
  border: 1px solid #dee2e6;
  border-radius: 0.375rem;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  z-index: 50;
  overflow: hidden;
}

.minimap-viewport {
  position: absolute;
  border: 2px solid #0d6efd;
  background-color: rgba(13, 110, 253, 0.1);
  cursor: move;
}

/* ============================================================================
   CONTEXT MENU
   ============================================================================ */

.node-context-menu {
  position: absolute;
  background-color: #ffffff;
  border: 1px solid #dee2e6;
  border-radius: 0.375rem;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  padding: 0.5rem 0;
  min-width: 180px;
  z-index: 1000;
}

.context-menu-item {
  display: flex;
  align-items: center;
  padding: 0.5rem 1rem;
  cursor: pointer;
  transition: background-color 0.2s ease;
  gap: 0.75rem;
  font-size: 0.875rem;
}

.context-menu-item:hover {
  background-color: #f8f9fa;
}

.context-menu-item i {
  width: 16px;
  text-align: center;
  color: #6c757d;
}

.context-menu-divider {
  height: 1px;
  background-color: #dee2e6;
  margin: 0.5rem 0;
}

/* ============================================================================
   ZOOM CONTROLS
   ============================================================================ */

.zoom-controls {
  position: absolute;
  bottom: 20px;
  left: 20px;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 50;
}

.zoom-controls .btn {
  width: 40px;
  height: 40px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #ffffff;
  border: 1px solid #dee2e6;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.zoom-controls .btn:hover {
  background-color: #f8f9fa;
}

.zoom-level {
  background-color: #ffffff;
  border: 1px solid #dee2e6;
  border-radius: 0.375rem;
  padding: 0.5rem;
  text-align: center;
  font-size: 0.75rem;
  font-weight: 600;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* ============================================================================
   TOAST CONTAINER
   ============================================================================ */

#toast-container {
  z-index: 9999;
}

#toast-container .toast {
  min-width: 300px;
}

#toast-container .toast-header {
  font-weight: 600;
}

/* ============================================================================
   RESPONSIVE DESIGN
   ============================================================================ */

@media (max-width: 1200px) {
  .block-palette-sidebar {
    width: 200px;
  }
  
  .properties-panel-sidebar {
    width: 250px;
  }
  
  .node {
    width: 240px;
  }
}

@media (max-width: 992px) {
  .node-editor-container {
    flex-direction: column;
    height: auto;
  }
  
  .block-palette-sidebar,
  .properties-panel-sidebar {
    width: 100%;
    max-height: 200px;
    border: none;
    border-bottom: 1px solid #dee2e6;
  }
  
  .canvas-area {
    min-height: 500px;
  }
}

/* ============================================================================
   ANIMATIONS
   ============================================================================ */

@keyframes pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

.node.connecting {
  animation: pulse 1s infinite;
}

@keyframes slideIn {
  from {
    transform: translateX(-20px);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

.block-palette-item {
  animation: slideIn 0.3s ease;
}

/* ============================================================================
   PRINT STYLES
   ============================================================================ */

@media print {
  .block-palette-sidebar,
  .properties-panel-sidebar,
  .node-editor-toolbar,
  .zoom-controls {
    display: none !important;
  }
  
  .canvas-area {
    border: none;
    background: white;
  }
  
  .node {
    box-shadow: none;
    page-break-inside: avoid;
  }
}

/* ============================================================================
   ACCESSIBILITY
   ============================================================================ */

.node:focus,
.block-palette-item:focus,
.context-menu-item:focus {
  outline: 2px solid #0d6efd;
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ============================================================================
   DARK MODE SUPPORT (Optional)
   ============================================================================ */

@media (prefers-color-scheme: dark) {
  .node-editor-container {
    background-color: #212529;
    border-color: #495057;
  }
  
  .block-palette-sidebar,
  .properties-panel-sidebar {
    background-color: #343a40;
    border-color: #495057;
  }
  
  .canvas-area {
    background-color: #212529;
    background-image: 
      linear-gradient(rgba(255, 255, 255, 0.05) 1px, transparent 1px),
      linear-gradient(90deg, rgba(255, 255, 255, 0.05) 1px, transparent 1px);
  }
  
  .node {
    background-color: #343a40;
    border-color: #6c757d;
    color: #f8f9fa;
  }
  
  .block-palette-item {
    background-color: #495057;
    border-color: #6c757d;
    color: #f8f9fa;
  }
  
  .block-palette-item:hover {
    background-color: #6c757d;
  }
  
  .node-context-menu {
    background-color: #343a40;
    border-color: #495057;
  }
  
  .context-menu-item {
    color: #f8f9fa;
  }
  
  .context-menu-item:hover {
    background-color: #495057;
  }
}

/* ============================================================================
   FULLSCREEN MODE
   ============================================================================ */

.node-editor-fullscreen {
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  width: 100vw !important;
  height: 100vh !important;
  z-index: 99999 !important;
  background-color: #ffffff !important;
  border-radius: 0 !important;
  border: none !important;
  margin: 0 !important;
  box-shadow: none !important;
}

.node-editor-fullscreen #nodeEditorContainer {
  height: calc(100vh - 56px) !important;
}

.node-editor-fullscreen .card-header {
  border-radius: 0 !important;
  position: sticky;
  top: 0;
  z-index: 100;
}

.node-editor-fullscreen .card-body {
  height: calc(100vh - 56px) !important;
}

/* Hide sidebars by default in fullscreen mode */
.node-editor-fullscreen #blockPalette,
.node-editor-fullscreen #propertiesPanel {
  display: none !important;
  position: absolute;
  z-index: 1000;
  height: calc(100vh - 56px);
  box-shadow: 2px 0 10px rgba(0,0,0,0.2);
  transition: transform 0.3s ease;
}

/* Show sidebars when toggled */
.node-editor-fullscreen #blockPalette.panel-visible {
  display: block !important;
  left: 0;
  top: 0;
}

.node-editor-fullscreen #propertiesPanel.panel-visible {
  display: block !important;
  right: 0;
  top: 0;
  box-shadow: -2px 0 10px rgba(0,0,0,0.2);
}

/* Canvas area takes full width in fullscreen */
.node-editor-fullscreen #canvasArea {
  width: 100% !important;
  cursor: grab;
}

/* Grabbing cursor when panning */
.node-editor-fullscreen #canvasArea.panning {
  cursor: grabbing !important;
}

/* Panel toggle buttons - base styles */
.panel-toggle-btn {
  position: absolute;
  top: 0;
  width: 32px;
  height: 100%;
  border-radius: 0;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
  z-index: 1001;
  background-color: #198754;
  color: white;
  border: 1px solid #157347;
}

.panel-toggle-btn:hover {
  background-color: #157347;
  color: white;
}

.panel-toggle-btn.active {
  background-color: #146c43;
  color: white;
  border-color: #13653f;
}

/* Left toggle button (Palette) */
.panel-toggle-left {
  left: 0;
  border-radius: 0;
  border-left: none;
}

.panel-toggle-left.panel-shifted {
  left: 250px;
}

/* Right toggle button (Properties) */
.panel-toggle-right {
  right: 0;
  border-radius: 0;
  border-right: none;
}

.panel-toggle-right.panel-shifted {
  right: 300px;
}

/* Hide page elements when fullscreen */
body.node-editor-fullscreen-active {
  overflow: hidden !important;
}

/* ============================================================================
   UTILITY CLASSES
   ============================================================================ */

.cursor-grab {
  cursor: grab;
}

.cursor-grabbing {
  cursor: grabbing;
}

.cursor-pointer {
  cursor: pointer;
}

.cursor-not-allowed {
  cursor: not-allowed;
}

.no-select {
  user-select: none;
}

.overflow-hidden {
  overflow: hidden;
}

.overflow-auto {
  overflow: auto;
}
