/**
 * DAG Builder - Apple Vision Pro Design
 * Premium glassmorphic design with depth and materials
 */

/* ========================================================================
   VISION PRO MATERIALS & DEPTH
   ======================================================================== */

.dag-builder-container {
  background: linear-gradient(135deg,
    rgba(255, 255, 255, 0.95) 0%,
    rgba(245, 245, 247, 0.98) 100%
  );
  backdrop-filter: blur(40px) saturate(180%);
  -webkit-backdrop-filter: blur(40px) saturate(180%);
  border-radius: 24px;
  box-shadow:
    0 2px 4px rgba(0, 0, 0, 0.02),
    0 8px 16px rgba(0, 0, 0, 0.04),
    0 24px 48px rgba(0, 0, 0, 0.06),
    inset 0 1px 0 rgba(255, 255, 255, 0.8);
  position: relative;
  overflow: hidden;
}

/* Subtle noise texture for realism */
.dag-builder-container::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 400 400' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)'/%3E%3C/svg%3E");
  opacity: 0.015;
  pointer-events: none;
  mix-blend-mode: overlay;
}

/* ========================================================================
   TOOLBAR - VISION PRO STYLE
   ======================================================================== */

.dag-toolbar {
  display: flex;
  gap: 12px;
  padding: 16px;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(30px) saturate(180%);
  -webkit-backdrop-filter: blur(30px) saturate(180%);
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 24px 24px 0 0;
  position: sticky;
  top: 0;
  z-index: 100;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.dag-toolbar.scrolled {
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.tool-group {
  display: flex;
  gap: 6px;
  padding: 4px;
  background: rgba(0, 0, 0, 0.04);
  border-radius: 12px;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.1);
}

.tool-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 16px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--color-grey-700);
  font: 500 14px -apple-system, BlinkMacSystemFont, "SF Pro Display", Inter, sans-serif;
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  position: relative;
  overflow: hidden;
}

.tool-btn svg {
  width: 16px;
  height: 16px;
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Hover state - Vision Pro material */
.tool-btn:hover {
  background: rgba(255, 255, 255, 0.9);
  color: var(--color-grey-900);
  box-shadow:
    0 2px 8px rgba(0, 0, 0, 0.08),
    inset 0 1px 0 rgba(255, 255, 255, 1);
  transform: translateY(-1px);
}

.tool-btn:hover svg {
  transform: scale(1.1);
}

/* Active state */
.tool-btn.active {
  background: linear-gradient(135deg, #0071E3 0%, #0051D5 100%);
  color: white;
  box-shadow:
    0 4px 12px rgba(0, 113, 227, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

.tool-btn.active:hover {
  background: linear-gradient(135deg, #007AFF 0%, #0062CC 100%);
  box-shadow:
    0 6px 16px rgba(0, 113, 227, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.4);
}

/* Secondary button style */
.tool-btn.btn-secondary {
  color: var(--color-grey-600);
}

.tool-btn.btn-secondary:hover {
  background: rgba(0, 0, 0, 0.06);
  color: var(--color-grey-900);
}

/* Delete edge button - destructive */
#delete-edge-btn.active {
  background: linear-gradient(135deg, #ff3b30 0%, #ff2d1f 100%);
  box-shadow:
    0 4px 12px rgba(255, 59, 48, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

/* Delete node button - destructive */
#delete-node-btn.active {
  background: linear-gradient(135deg, #ff3b30 0%, #ff2d1f 100%);
  box-shadow:
    0 4px 12px rgba(255, 59, 48, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

/* ========================================================================
   NODE CUSTOMIZATION PANEL
   ======================================================================== */

.dag-customization-section {
  padding: 20px;
  background: rgba(255, 255, 255, 0.8);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
  position: sticky;
  top: 74px; /* Height of toolbar + some spacing */
  z-index: 90;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.dag-customization-section.scrolled {
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.dag-customization-section h3 {
  font-size: 16px;
  font-weight: 600;
  color: var(--color-grey-900);
  margin: 0 0 16px 0;
  letter-spacing: -0.01em;
}

.node-type-selector label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--color-grey-600);
  margin-bottom: 10px;
}

.node-type-buttons {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.node-type-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border: 1.5px solid rgba(0, 0, 0, 0.08);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.8);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  font: 500 13px -apple-system, BlinkMacSystemFont, "SF Pro Display", Inter, sans-serif;
  color: var(--color-grey-700);
}

.node-type-preview {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 6px;
  color: white;
  font-size: 14px;
  box-shadow:
    0 2px 4px rgba(0, 0, 0, 0.1),
    inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

.node-type-btn:hover {
  border-color: rgba(0, 113, 227, 0.3);
  background: white;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  transform: translateY(-1px);
}

.node-type-btn.active {
  border-color: #0071E3;
  background: rgba(0, 113, 227, 0.08);
  color: #0071E3;
  box-shadow:
    0 0 0 3px rgba(0, 113, 227, 0.1),
    0 2px 8px rgba(0, 113, 227, 0.15);
}

.node-type-hint {
  font-size: 12px;
  color: var(--color-grey-500);
  margin: 0;
  font-style: italic;
}

/* Edge Style Selector */
.edge-style-selector {
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid rgba(0, 0, 0, 0.06);
}

.edge-style-selector label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--color-grey-600);
  margin-bottom: 10px;
}

.edge-style-buttons {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}

.edge-style-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 12px;
  border: 1.5px solid rgba(0, 0, 0, 0.08);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.8);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  font: 500 13px -apple-system, BlinkMacSystemFont, "SF Pro Display", Inter, sans-serif;
  color: var(--color-grey-700);
}

.edge-style-btn:hover {
  background: rgba(255, 255, 255, 1);
  border-color: rgba(0, 0, 0, 0.15);
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.edge-style-btn.active {
  background: linear-gradient(135deg, #0071E3 0%, #0051D5 100%);
  border-color: transparent;
  color: white;
  box-shadow:
    0 4px 12px rgba(0, 113, 227, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

.edge-style-btn.active:hover {
  background: linear-gradient(135deg, #007AFF 0%, #0062CC 100%);
  transform: translateY(-1px);
  box-shadow:
    0 6px 16px rgba(0, 113, 227, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.4);
}

.edge-style-btn svg {
  transition: transform 0.25s ease;
}

.edge-style-btn:hover svg {
  transform: scale(1.1);
}

/* ========================================================================
   CONTEXT MENU - RIGHT-CLICK MENU
   ======================================================================== */

.dag-context-menu {
  position: fixed;
  min-width: 160px;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(40px) saturate(180%);
  -webkit-backdrop-filter: blur(40px) saturate(180%);
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 12px;
  box-shadow:
    0 4px 12px rgba(0, 0, 0, 0.12),
    0 16px 48px rgba(0, 0, 0, 0.16),
    inset 0 1px 0 rgba(255, 255, 255, 0.9);
  padding: 6px;
  z-index: 10000;
  animation: contextMenuFadeIn 0.15s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes contextMenuFadeIn {
  from {
    opacity: 0;
    transform: scale(0.95) translateY(-5px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.context-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s ease;
  font: 500 13px -apple-system, BlinkMacSystemFont, "SF Pro Display", Inter, sans-serif;
  color: var(--color-grey-800);
  user-select: none;
}

.context-menu-item:hover {
  background: rgba(0, 113, 227, 0.1);
  color: #0071E3;
}

.context-menu-item[data-action="delete"]:hover {
  background: rgba(255, 59, 48, 0.1);
  color: #ff3b30;
}

.context-menu-item svg {
  flex-shrink: 0;
  opacity: 0.7;
}

.context-menu-item:hover svg {
  opacity: 1;
}

.context-menu-item span {
  flex: 1;
}

/* Context menu with submenu */
.context-menu-item.has-submenu {
  position: relative;
}

.context-menu-item.has-submenu::after {
  content: '›';
  font-size: 16px;
  font-weight: 600;
  margin-left: auto;
  opacity: 0.5;
  transition: opacity 0.15s ease;
}

.context-menu-item.has-submenu:hover::after {
  opacity: 1;
}

.context-menu-submenu {
  position: fixed;
  min-width: 180px;
  max-height: 300px;
  overflow-y: auto;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(40px) saturate(180%);
  -webkit-backdrop-filter: blur(40px) saturate(180%);
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 12px;
  box-shadow:
    0 4px 12px rgba(0, 0, 0, 0.12),
    0 16px 48px rgba(0, 0, 0, 0.16),
    inset 0 1px 0 rgba(255, 255, 255, 0.9);
  padding: 6px;
  z-index: 10001;
  display: none;
  animation: contextMenuFadeIn 0.15s cubic-bezier(0.16, 1, 0.3, 1);
}

.context-menu-submenu.active {
  display: block;
}

.context-menu-submenu-header {
  padding: 8px 12px;
  font: 600 11px -apple-system, BlinkMacSystemFont, "SF Pro Display", Inter, sans-serif;
  color: var(--color-grey-500);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.context-menu-submenu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s ease;
  font: 500 13px -apple-system, BlinkMacSystemFont, "SF Pro Display", Inter, sans-serif;
  color: var(--color-grey-800);
  user-select: none;
}

.context-menu-submenu-item:hover {
  background: rgba(0, 113, 227, 0.1);
  color: #0071E3;
}

.context-menu-submenu-item .node-symbol {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 600;
  flex-shrink: 0;
}

/* Scrollbar styling for submenu */
.context-menu-submenu::-webkit-scrollbar {
  width: 6px;
}

.context-menu-submenu::-webkit-scrollbar-track {
  background: transparent;
}

.context-menu-submenu::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.2);
  border-radius: 3px;
}

.context-menu-submenu::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.3);
}

/* ========================================================================
   COLOR LEGEND - FLOATING VISION PRO PANEL
   ======================================================================== */

.dag-legend {
  position: absolute;
  top: 20px;
  right: 20px;
  min-width: 200px;
  max-width: 280px;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(40px) saturate(180%);
  -webkit-backdrop-filter: blur(40px) saturate(180%);
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 16px;
  box-shadow:
    0 4px 12px rgba(0, 0, 0, 0.08),
    0 16px 48px rgba(0, 0, 0, 0.12),
    inset 0 1px 0 rgba(255, 255, 255, 0.9);
  z-index: 100;
  animation: legendFadeIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes legendFadeIn {
  from {
    opacity: 0;
    transform: translateY(-10px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.legend-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
}

.legend-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--color-grey-900);
  letter-spacing: -0.01em;
}

.legend-close {
  width: 24px;
  height: 24px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--color-grey-500);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  transition: all 0.2s ease;
}

.legend-close:hover {
  background: rgba(0, 0, 0, 0.06);
  color: var(--color-grey-900);
}

.legend-items {
  padding: 12px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  transition: background 0.2s ease;
}

.legend-item:hover {
  background: rgba(0, 0, 0, 0.03);
}

.legend-symbol {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 7px;
  color: white;
  font-size: 16px;
  font-weight: bold;
  box-shadow:
    0 2px 6px rgba(0, 0, 0, 0.12),
    inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

.legend-label {
  flex: 1;
  font-size: 13px;
  font-weight: 500;
  color: var(--color-grey-800);
}

.legend-count {
  font-size: 12px;
  font-weight: 600;
  color: var(--color-grey-500);
  padding: 2px 6px;
  background: rgba(0, 0, 0, 0.05);
  border-radius: 4px;
}

/* Classification headers in legend */
.legend-classification-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 10px 6px 10px;
  margin-top: 8px;
  border-top: 1px solid rgba(0, 0, 0, 0.06);
}

.legend-classification-header:first-child {
  margin-top: 0;
  border-top: none;
  padding-top: 4px;
}

.legend-classification-icon {
  font-size: 14px;
  line-height: 1;
}

.legend-classification-label {
  flex: 1;
  font-size: 11px;
  font-weight: 700;
  color: var(--color-grey-700);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.legend-classification-count {
  font-size: 11px;
  font-weight: 700;
  color: var(--color-grey-500);
  padding: 2px 6px;
  background: rgba(0, 0, 0, 0.05);
  border-radius: 4px;
}

/* Node items within classifications */
.legend-item-node {
  padding: 6px 10px;
  margin-left: 8px;
}

.legend-item-node .legend-symbol {
  width: 24px;
  height: 24px;
  font-size: 14px;
  font-weight: 600;
  box-shadow: none;
}

.legend-item-node .legend-label {
  font-size: 12px;
  font-weight: 500;
}

/* ========================================================================
   NODE DETAIL DIALOG
   ======================================================================== */

.node-detail-dialog {
  position: fixed;
  inset: 0;
  display: none;
  pointer-events: none;
  z-index: 70;
}

.node-detail-dialog.visible {
  display: block;
  pointer-events: auto;
}

.node-detail-content {
  position: absolute;
  background: linear-gradient(135deg, #ffffff 0%, #f5f5f7 100%);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-radius: 14px;
  border: 1px solid rgba(0, 0, 0, 0.08);
  box-shadow:
    0 12px 40px rgba(0, 0, 0, 0.1),
    inset 0 1px 0 rgba(255, 255, 255, 0.8);
  width: min(380px, 85vw);
  max-height: min(85vh, 600px);
  display: flex;
  flex-direction: column;
  pointer-events: auto;
  animation: dialogSlideIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  overflow: hidden;
}

@keyframes dialogSlideIn {
  from {
    transform: translateY(-20px) scale(0.95);
    opacity: 0;
  }
  to {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
}

.node-detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
  flex-shrink: 0;
}

.node-detail-header h3 {
  font-size: 16px;
  font-weight: 600;
  color: #1d1d1f;
  margin: 0;
  letter-spacing: -0.02em;
}

.node-detail-close {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: rgba(255, 255, 255, 0.6);
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  transition: all 0.2s ease;
}

.node-detail-close:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #ffffff;
}

.node-detail-body {
  padding: 16px 18px;
  overflow-y: auto;
  overflow-x: hidden;
  flex: 1;
  min-height: 0;
  max-height: calc(85vh - 140px);
}

/* Custom scrollbar for dialog body */
.node-detail-body::-webkit-scrollbar {
  width: 8px;
}

.node-detail-body::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.05);
  border-radius: 4px;
}

.node-detail-body::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.2);
  border-radius: 4px;
}

.node-detail-body::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.3);
}

.node-detail-body .input-group {
  margin-bottom: 14px;
}

.node-detail-body .input-group:last-child {
  margin-bottom: 0;
}

.node-detail-body .input-group-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 14px;
}

.node-detail-body .input-group-row .input-group {
  margin-bottom: 0;
}

.node-distribution-group-hidden {
  display: none !important;
}

.node-dist-params-group-hidden {
  display: none !important;
}

.node-detail-body label {
  display: block;
  font-size: 13px;
  font-weight: 700;
  color: #000000;
  margin-bottom: 6px;
}

.node-detail-body label .required {
  color: #ff3b30;
}

.node-detail-body input,
.node-detail-body textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1.5px solid #cccccc;
  border-radius: 8px;
  background: #ffffff;
  font: 500 13px -apple-system, BlinkMacSystemFont, "SF Pro Display", Inter, sans-serif;
  color: #000000;
  transition: all 0.2s ease;
  box-sizing: border-box;
}

.node-detail-body input::placeholder,
.node-detail-body textarea::placeholder {
  color: #999999;
  font-weight: 400;
}

.node-detail-body textarea {
  resize: vertical;
  min-height: 60px;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", Inter, sans-serif;
}

.node-detail-body input:focus,
.node-detail-body textarea:focus {
  outline: none;
  border-color: #0071e3;
  box-shadow:
    0 0 0 3px rgba(0, 113, 227, 0.1),
    0 2px 12px rgba(0, 113, 227, 0.15);
  background: #ffffff;
}

.input-hint {
  display: block;
  font-size: 11px;
  color: #333333;
  margin-top: 4px;
  font-style: italic;
  font-weight: 500;
}

.node-detail-footer {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  padding: 14px 18px;
  border-top: 1px solid rgba(0, 0, 0, 0.08);
  flex-shrink: 0;
}

.node-detail-footer .tool-btn {
  min-width: 85px;
  padding: 8px 14px;
  font-size: 13px;
}

.node-detail-footer .btn-delete {
  background: transparent;
  color: #ff3b30;
  border: 1.5px solid rgba(255, 59, 48, 0.3);
  min-width: auto;
  padding: 10px 16px;
}

.node-detail-delete-btn {
  margin-right: auto;
}

.delete-icon-svg {
  margin-right: 4px;
}

.node-detail-dialog-hidden {
  display: none !important;
}

.node-detail-dialog.visible {
  display: block !important;
  pointer-events: auto;
}

/* Causal Identification Section */
.causal-identification-section {
  margin-bottom: 16px;
}

.identify-causal-btn {
  width: 100%;
  margin-bottom: 12px;
}

.identify-icon {
  margin-right: 6px;
}

.identify-hint {
  display: block;
  color: #666;
  font-size: 11px;
  margin-top: 4px;
}

.node-detail-footer .btn-delete:hover {
  background: rgba(255, 59, 48, 0.1);
  border-color: #ff3b30;
  transform: translateY(-1px);
}

.node-detail-body select.form-control {
  appearance: none;
  background-color: #ffffff;
  background-image: url("data:image/svg+xml,%3Csvg width='12' height='8' viewBox='0 0 12 8' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1L6 6L11 1' stroke='%23000000' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  border: 1.5px solid #cccccc;
  padding-right: 36px;
  color: #000000;
  font-weight: 600;
}

/* ========================================================================
   CANVAS CONTAINER
   ======================================================================== */

.dag-canvas-container {
  position: relative;
  padding: 20px;
  background: rgba(250, 250, 250, 0.4);
}

#dag-canvas {
  border-radius: 16px;
  box-shadow:
    0 2px 8px rgba(0, 0, 0, 0.06),
    inset 0 0 0 1px rgba(0, 0, 0, 0.04);
  background: white;
}

/* ========================================================================
   ANALYSIS PANEL
   ======================================================================== */

.dag-analysis-section {
  padding: 20px;
  background: rgba(255, 255, 255, 0.6);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

.dag-analysis-section h3 {
  font-size: 16px;
  font-weight: 700;
  color: #000000;
  margin: 0 0 16px 0;
  letter-spacing: -0.01em;
}

.analysis-controls {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.input-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.input-group label {
  font-size: 13px;
  font-weight: 700;
  color: #000000;
}

.form-control {
  padding: 10px 14px;
  border: 1.5px solid #cccccc;
  border-radius: 10px;
  background: #ffffff;
  font: 600 14px -apple-system, BlinkMacSystemFont, "SF Pro Display", Inter, sans-serif;
  color: #000000;
  transition: all 0.2s ease;
}

.form-control::placeholder {
  color: #999999;
}

.form-control:focus {
  outline: none;
  border-color: #0071E3;
  box-shadow:
    0 0 0 3px rgba(0, 113, 227, 0.1),
    0 2px 8px rgba(0, 113, 227, 0.1);
}

/* ========================================================================
   STRATIFICATION RESULTS
   ======================================================================== */

.stratification-display {
  margin-top: 24px;
  padding: 20px;
  background: rgba(255, 255, 255, 0.6);
  backdrop-filter: blur(20px) saturate(180%);
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 16px;
}

.stratification-header {
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
}

.stratification-header h3 {
  margin: 0 0 8px 0;
  font-size: 20px;
  font-weight: 700;
  color: #000000;
}

.stratification-header p {
  margin: 4px 0;
  color: #333333;
  font-size: 14px;
  font-weight: 500;
}

.strata-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
  margin-top: 16px;
}

.stratum-card {
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.95), rgba(250, 250, 252, 0.95));
  border: 1px solid rgba(0, 0, 0, 0.06);
  border-radius: 12px;
  padding: 16px;
  box-shadow:
    0 2px 8px rgba(0, 0, 0, 0.04),
    0 1px 2px rgba(0, 0, 0, 0.06);
  transition: all 0.2s ease;
}

.stratum-card:hover {
  box-shadow:
    0 4px 12px rgba(0, 0, 0, 0.08),
    0 2px 4px rgba(0, 0, 0, 0.08);
  transform: translateY(-2px);
}

.stratum-card h4 {
  margin: 0 0 8px 0;
  font-size: 16px;
  font-weight: 600;
  color: #0071E3;
}

.stratum-size {
  margin: 0 0 12px 0;
  font-size: 13px;
  color: #333333;
  font-style: italic;
  font-weight: 500;
}

.stratum-stats {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid rgba(0, 0, 0, 0.05);
}

.stratum-stats p {
  margin: 6px 0;
  font-size: 13px;
  color: #000000;
  line-height: 1.5;
  font-weight: 500;
}

.stratum-stats strong {
  font-weight: 600;
  color: #000;
}

.result-success,
.result-error {
  padding: 20px;
  border-radius: 12px;
  margin-top: 16px;
}

.result-success {
  background: linear-gradient(135deg, rgba(52, 199, 89, 0.1), rgba(48, 209, 88, 0.05));
  border: 1px solid rgba(52, 199, 89, 0.2);
}

.result-error {
  background: linear-gradient(135deg, rgba(255, 59, 48, 0.1), rgba(255, 69, 58, 0.05));
  border: 1px solid rgba(255, 59, 48, 0.2);
}

.result-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.result-header svg {
  flex-shrink: 0;
}

.result-header h4 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: #1d1d1f;
}

.result-success p,
.result-error p {
  margin: 8px 0;
  color: #1d1d1f;
  font-size: 14px;
}

.result-stats {
  margin-top: 16px;
  padding: 16px;
  background: rgba(255, 255, 255, 0.6);
  border-radius: 8px;
}

.result-stats h5 {
  margin: 0 0 12px 0;
  font-size: 14px;
  font-weight: 600;
  color: #1d1d1f;
}

.stats-grid {
  display: grid;
  gap: 8px;
}

.stats-grid p {
  margin: 0;
  font-size: 13px;
  color: #1d1d1f;
  padding: 4px 0;
}

.stats-grid strong {
  font-weight: 600;
  color: #000;
}

/* ========================================================================
   RESPONSIVE DESIGN
   ======================================================================== */

@media (max-width: 768px) {
  .dag-toolbar {
    flex-wrap: wrap;
  }

  .node-type-buttons {
    grid-template-columns: repeat(2, 1fr);
  }

  .dag-legend {
    top: 10px;
    right: 10px;
    max-width: 220px;
  }
}

/* ========================================================================
   REDUCED MOTION
   ======================================================================== */

@media (prefers-reduced-motion: reduce) {
  .tool-btn,
  .node-type-btn,
  .legend-item {
    transition: none;
  }

  .dag-legend {
    animation: none;
  }

  .tool-btn:hover,
  .node-type-btn:hover {
    transform: none;
  }
}

/* ========================================================================
   Edge Detail Dialog
   ======================================================================== */

.detail-dialog {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 80;
  animation: fadeIn 0.3s ease;
}

.detail-dialog.active {
  display: flex;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.dialog-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.dialog-content {
  position: relative;
  background: linear-gradient(135deg, #ffffff 0%, #f5f5f7 100%);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-radius: 16px;
  border: 1px solid rgba(0, 0, 0, 0.08);
  box-shadow:
    0 20px 60px rgba(0, 0, 0, 0.15),
    inset 0 1px 0 rgba(255, 255, 255, 0.8);
  width: min(520px, 90vw);
  max-height: min(85vh, 700px);
  display: flex;
  flex-direction: column;
  animation: dialogSlideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  overflow: hidden;
}

@keyframes dialogSlideUp {
  from {
    transform: translateY(30px) scale(0.95);
    opacity: 0;
  }
  to {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
  flex-shrink: 0;
}

.dialog-header h2 {
  font-size: 18px;
  font-weight: 600;
  color: #1d1d1f;
  margin: 0;
  letter-spacing: -0.02em;
}

.dialog-close {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.04);
  color: #1d1d1f;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.dialog-close:hover {
  background: rgba(0, 0, 0, 0.08);
  transform: scale(1.05);
}

.dialog-body {
  padding: 20px 22px;
  overflow-y: auto;
  overflow-x: hidden;
  flex: 1;
  min-height: 0;
}

.dialog-body::-webkit-scrollbar {
  width: 8px;
}

.dialog-body::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.05);
  border-radius: 4px;
}

.dialog-body::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.2);
  border-radius: 4px;
}

.dialog-body::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.3);
}

.dialog-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 22px;
  border-top: 1px solid rgba(0, 0, 0, 0.08);
  flex-shrink: 0;
}

/* Form Sections */
.form-section {
  margin-bottom: 20px;
}

.form-section h3 {
  font-size: 14px;
  font-weight: 600;
  color: #1d1d1f;
  margin: 0 0 12px 0;
  letter-spacing: -0.01em;
}

.form-section label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: #1d1d1f;
  margin-bottom: 6px;
}

.form-control {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid rgba(0, 0, 0, 0.15);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.8);
  color: #1d1d1f;
  font-size: 14px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  transition: all 0.2s ease;
}

.form-control:focus {
  outline: none;
  border-color: #0071e3;
  box-shadow: 0 0 0 3px rgba(0, 113, 227, 0.1);
}

.form-hint {
  display: block;
  margin-top: 4px;
  font-size: 12px;
  color: rgba(0, 0, 0, 0.5);
}

.form-row {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
}

.form-group {
  flex: 1;
}

/* Edge Info Badge */
.edge-info {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: rgba(0, 113, 227, 0.08);
  border-radius: 10px;
  border: 1px solid rgba(0, 113, 227, 0.15);
}

.node-badge {
  padding: 6px 12px;
  background: rgba(255, 255, 255, 0.9);
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  color: #1d1d1f;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
}

.arrow {
  font-size: 18px;
  font-weight: 600;
  color: #0071e3;
}

/* Formula Preview */
.formula-preview {
  padding: 14px 16px;
  background: #f5f5f7;
  border-radius: 10px;
  border: 1px solid rgba(0, 0, 0, 0.08);
  font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Courier New', monospace;
}

.formula-preview code {
  display: block;
  font-size: 14px;
  color: #1d1d1f;
  font-weight: 500;
  line-height: 1.5;
}

/* Buttons */
.btn {
  padding: 10px 20px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.btn-primary {
  background: #0071e3;
  color: white;
  box-shadow: 0 2px 8px rgba(0, 113, 227, 0.25);
}

.btn-primary:hover {
  background: #0077ed;
  box-shadow: 0 4px 12px rgba(0, 113, 227, 0.35);
  transform: translateY(-1px);
}

.btn-secondary {
  background: rgba(0, 0, 0, 0.06);
  color: #1d1d1f;
}

.btn-secondary:hover {
  background: rgba(0, 0, 0, 0.1);
}

/* Responsive */
@media (max-width: 768px) {
  .dialog-content {
    width: 95vw;
    max-height: 90vh;
  }

  .dialog-header {
    padding: 14px 16px;
  }

  .dialog-body {
    padding: 16px;
  }

  .dialog-footer {
    padding: 12px 16px;
  }

  .form-row {
    flex-direction: column;
  }
}

/* ========================================================================
   Data Preview Dialog
   ======================================================================== */

.data-dialog-large {
  width: min(900px, 95vw);
  max-height: min(85vh, 800px);
}

.table-info {
  font-size: 12px;
  color: rgba(0, 0, 0, 0.5);
  font-weight: 400;
  margin-left: 8px;
}

/* Data Summary Table */
.data-summary {
  overflow-x: auto;
  border-radius: 10px;
  border: 1px solid rgba(0, 0, 0, 0.08);
}

.summary-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  background: white;
}

.summary-table thead {
  background: linear-gradient(135deg, #f5f5f7 0%, #e8e8ea 100%);
}

.summary-table th {
  padding: 10px 12px;
  text-align: left;
  font-weight: 600;
  color: #1d1d1f;
  border-bottom: 2px solid rgba(0, 0, 0, 0.1);
  white-space: nowrap;
}

.summary-table td {
  padding: 8px 12px;
  text-align: left;
  border-bottom: 1px solid rgba(0, 0, 0, 0.05);
  font-family: 'SF Mono', Monaco, monospace;
  font-size: 12px;
}

.summary-table .var-name {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-weight: 600;
  color: #0071e3;
}

.summary-table tbody tr:hover {
  background: rgba(0, 113, 227, 0.05);
}

/* Data Preview Table */
.data-table-container {
  overflow: auto;
  max-height: 400px;
  border-radius: 10px;
  border: 1px solid rgba(0, 0, 0, 0.08);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  background: white;
}

.data-table thead {
  position: sticky;
  top: 0;
  background: linear-gradient(135deg, #f5f5f7 0%, #e8e8ea 100%);
  z-index: 1;
}

.data-table th {
  padding: 8px 10px;
  text-align: left;
  font-weight: 600;
  color: #1d1d1f;
  border-bottom: 2px solid rgba(0, 0, 0, 0.1);
  white-space: nowrap;
}

.data-table td {
  padding: 6px 10px;
  text-align: left;
  border-bottom: 1px solid rgba(0, 0, 0, 0.05);
  font-family: 'SF Mono', Monaco, monospace;
}

.data-table .row-num {
  background: #f5f5f7;
  font-weight: 600;
  color: rgba(0, 0, 0, 0.5);
  text-align: center;
  position: sticky;
  left: 0;
}

.data-table tbody tr:hover {
  background: rgba(0, 113, 227, 0.05);
}

/* Correlation Matrix */
.correlation-matrix {
  overflow: auto;
  border-radius: 10px;
  border: 1px solid rgba(0, 0, 0, 0.08);
}

.corr-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  background: white;
}

.corr-table th {
  padding: 8px;
  text-align: center;
  font-weight: 600;
  color: #1d1d1f;
  background: linear-gradient(135deg, #f5f5f7 0%, #e8e8ea 100%);
  border: 1px solid rgba(0, 0, 0, 0.08);
  max-width: 80px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.corr-table td {
  padding: 8px;
  text-align: center;
  border: 1px solid rgba(0, 0, 0, 0.08);
  font-family: 'SF Mono', Monaco, monospace;
  font-weight: 600;
}

.corr-diagonal {
  background: rgba(0, 113, 227, 0.1);
  color: #0071e3;
}

.corr-high {
  background: rgba(255, 59, 48, 0.15);
  color: #ff3b30;
}

.corr-medium {
  background: rgba(255, 149, 0, 0.15);
  color: #ff9500;
}

.corr-low {
  background: rgba(0, 0, 0, 0.03);
  color: rgba(0, 0, 0, 0.5);
}

.corr-negative {
  background: rgba(0, 113, 227, 0.15);
  color: #0071e3;
}

/* Button Icons */
.btn-icon {
  display: inline-block;
  margin-right: 6px;
}

.dialog-footer .btn {
  font-size: 13px;
  padding: 8px 16px;
}

@media (max-width: 768px) {
  .data-dialog-large {
    width: 95vw;
  }

  .dialog-footer {
    flex-wrap: wrap;
  }

  .dialog-footer .btn {
    flex: 1 1 auto;
    min-width: 120px;
  }
}

/* ========================================================================
   Estimation Results Dialog
   ======================================================================== */

/* Ground Truth Banner */
.ground-truth-banner {
  padding: 16px 20px;
  background: linear-gradient(135deg, rgba(52, 199, 89, 0.15) 0%, rgba(52, 199, 89, 0.05) 100%);
  border-radius: 12px;
  border: 2px solid rgba(52, 199, 89, 0.3);
  text-align: center;
}

.ground-truth-banner h3 {
  margin: 0 0 10px 0;
  color: #22c55e;
  font-size: 16px;
}

.true-ate {
  font-size: 24px;
  font-weight: 700;
  color: #22c55e;
  margin: 10px 0;
  font-family: 'SF Mono', Monaco, monospace;
}

.ground-truth-banner small {
  color: rgba(0, 0, 0, 0.6);
  display: block;
  margin-top: 8px;
}

/* Results Comparison Table */
.results-table-container {
  overflow-x: auto;
  border-radius: 10px;
  border: 1px solid rgba(0, 0, 0, 0.08);
}

.results-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  background: white;
}

.results-table thead {
  background: linear-gradient(135deg, #f5f5f7 0%, #e8e8ea 100%);
}

.results-table th {
  padding: 12px 10px;
  text-align: left;
  font-weight: 600;
  color: #1d1d1f;
  border-bottom: 2px solid rgba(0, 0, 0, 0.1);
  white-space: nowrap;
}

.results-table td {
  padding: 10px;
  text-align: left;
  border-bottom: 1px solid rgba(0, 0, 0, 0.05);
  font-family: 'SF Mono', Monaco, monospace;
  font-size: 13px;
}

.results-table .method-name {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-weight: 600;
  color: #1d1d1f;
}

.results-table .ate-value {
  font-weight: 700;
  color: #0071e3;
  font-size: 14px;
}

.results-table .significant {
  color: #22c55e;
  font-weight: 600;
}

.results-table .bias-low {
  color: #22c55e;
}

.results-table .bias-high {
  color: #ff3b30;
  font-weight: 600;
}

.results-table tbody tr:hover {
  background: rgba(0, 113, 227, 0.05);
}

/* Recommendation Banner */
.recommendation-banner {
  padding: 20px;
  background: linear-gradient(135deg, rgba(0, 113, 227, 0.15) 0%, rgba(0, 113, 227, 0.05) 100%);
  border-radius: 12px;
  border: 2px solid rgba(0, 113, 227, 0.3);
  text-align: center;
}

.recommendation-banner h3 {
  margin: 0 0 12px 0;
  color: #0071e3;
  font-size: 16px;
}

.best-method-name {
  font-size: 20px;
  font-weight: 700;
  color: #0071e3;
  margin: 10px 0 16px 0;
}

.best-method-stats {
  display: flex;
  justify-content: center;
  gap: 30px;
  margin: 16px 0;
}

.stat {
  text-align: center;
}

.stat-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: rgba(0, 0, 0, 0.5);
  margin-bottom: 4px;
}

.stat-value {
  font-size: 18px;
  font-weight: 700;
  color: #1d1d1f;
  font-family: 'SF Mono', Monaco, monospace;
}

.recommendation-banner.guidance {
  background: linear-gradient(135deg, rgba(139, 92, 246, 0.15) 0%, rgba(139, 92, 246, 0.05) 100%);
  border-color: rgba(139, 92, 246, 0.3);
  text-align: left;
}

.recommendation-banner.guidance h3 {
  color: #8b5cf6;
}

.recommendation-banner.guidance ul {
  margin: 12px 0;
  padding-left: 20px;
}

.recommendation-banner.guidance li {
  margin: 8px 0;
  line-height: 1.5;
}

/* Detailed Results Cards */
.result-detail-card {
  margin-bottom: 16px;
  padding: 16px;
  background: white;
  border-radius: 10px;
  border: 1px solid rgba(0, 0, 0, 0.08);
}

.result-detail-card h4 {
  margin: 0 0 12px 0;
  color: #1d1d1f;
  font-size: 15px;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
}

.detail-stats {
  margin-bottom: 12px;
}

.detail-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

.detail-label {
  color: rgba(0, 0, 0, 0.6);
  font-size: 13px;
}

.detail-value {
  font-weight: 600;
  color: #1d1d1f;
  font-family: 'SF Mono', Monaco, monospace;
  font-size: 13px;
}

.detail-value.significant {
  color: #22c55e;
}

.method-details {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid rgba(0, 0, 0, 0.08);
  font-size: 12px;
}

.method-details ul {
  margin: 8px 0;
  padding-left: 20px;
}

.method-details li {
  margin: 4px 0;
  color: rgba(0, 0, 0, 0.7);
}

.method-details .detail-key {
  font-weight: 600;
  color: #1d1d1f;
}

@media (max-width: 768px) {
  .best-method-stats {
    flex-direction: column;
    gap: 16px;
  }

  .results-table {
    font-size: 11px;
  }

  .results-table th,
  .results-table td {
    padding: 8px 6px;
  }
}
