/* =========================================================
   Truth Portal Visual Stabilizer
   Purpose: fix existing fractal + semi-lattice boxes without
   injecting a new visual system or touching Notion sync.
   ========================================================= */

/* Main visual modal container */
.visual-modal .modal-card.visual-wide,
.visual-wide {
  width: min(1500px, calc(100vw - 24px)) !important;
  max-width: 1500px !important;
  min-height: min(92vh, 980px) !important;
  max-height: calc(100vh - 24px) !important;
  overflow: auto !important;
}

/* Modal header should not crush controls */
.visual-top {
  display: flex !important;
  align-items: flex-start !important;
  justify-content: space-between !important;
  gap: 16px !important;
  flex-wrap: wrap !important;
}

.visual-tools {
  display: flex !important;
  gap: 8px !important;
  align-items: center !important;
  justify-content: flex-end !important;
  flex-wrap: wrap !important;
}

/* Stable three-panel layout on desktop */
.visual-layout {
  display: grid !important;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(300px, 340px) !important;
  gap: 16px !important;
  align-items: stretch !important;
}

/* Single-view modes */
.visual-layout.fractal-only,
.visual-layout.semi-only {
  grid-template-columns: minmax(0, 1fr) minmax(300px, 340px) !important;
}

.visual-layout.fractal-only #semiPanel,
.visual-layout.semi-only #fractalPanel {
  display: none !important;
}

/* Diagram cards */
.diagram-panel {
  min-width: 0 !important;
  min-height: 620px !important;
  padding: 14px !important;
  overflow: hidden !important;
  background:
    radial-gradient(circle at 20% 10%, rgba(255, 110, 20, .08), transparent 30%),
    linear-gradient(180deg, var(--surface-2), var(--surface)) !important;
  border: 1px solid rgba(14, 34, 64, .12) !important;
  border-radius: 22px !important;
}

.panel-title {
  min-height: 52px !important;
  margin-bottom: 10px !important;
}

.panel-title h3 {
  font-size: 18px !important;
  line-height: 1.15 !important;
  margin: 0 !important;
}

.panel-title span {
  display: block !important;
  max-width: 220px !important;
  font-size: 11px !important;
  line-height: 1.25 !important;
  color: var(--muted) !important;
}

/* SVG canvas */
.svg-mount {
  min-height: 520px !important;
  height: 520px !important;
  width: 100% !important;
  overflow: hidden !important;
  border-radius: 18px !important;
  background:
    radial-gradient(circle at 50% 50%, rgba(255, 110, 20, .08), transparent 35%),
    linear-gradient(135deg, rgba(14,34,64,.04), rgba(255,255,255,.03)) !important;
}

.svg-mount svg {
  width: 100% !important;
  height: 100% !important;
  display: block !important;
  overflow: visible !important;
}

/* Mini cards should show simplified previews */
.systems-inline {
  align-items: stretch !important;
}

.visual-card.mini {
  overflow: hidden !important;
  min-height: 330px !important;
}

.visual-card.mini .visual-head {
  min-height: 44px !important;
}

.mini-mount {
  height: 260px !important;
  min-height: 260px !important;
  overflow: hidden !important;
  border-radius: 16px !important;
  background:
    radial-gradient(circle at 50% 40%, rgba(255,110,20,.08), transparent 35%),
    linear-gradient(135deg, rgba(14,34,64,.04), rgba(255,255,255,.03)) !important;
}

.mini-mount svg {
  width: 100% !important;
  height: 100% !important;
  overflow: visible !important;
}

/* Grid background */
.visual-grid-bg {
  fill: rgba(14, 34, 64, .035) !important;
  stroke: rgba(14, 34, 64, .10) !important;
  stroke-width: 1 !important;
}

/* Relationship lines */
.edge {
  stroke: rgba(14,34,64,.25) !important;
  stroke-width: 2 !important;
  fill: none !important;
  stroke-linecap: round !important;
}

.edge.animated {
  stroke-dasharray: 7 8 !important;
  animation: dash 1.8s linear infinite !important;
}

.edge.highlight {
  stroke: var(--color-orange) !important;
  stroke-width: 3 !important;
}

/* Node shapes */
.node circle,
.node rect {
  filter: drop-shadow(0 8px 14px rgba(14,34,64,.18)) !important;
  stroke: rgba(255,255,255,.42) !important;
  stroke-width: 1.4 !important;
}

/* Actual node text inside circles/rects */
.node text {
  font-family: var(--font-display) !important;
  font-size: 8px !important;
  font-weight: 800 !important;
  letter-spacing: .01em !important;
  fill: #fff !important;
  pointer-events: none !important;
}

.node .subtext {
  font-family: var(--font-body) !important;
  font-size: 6px !important;
  font-weight: 600 !important;
  fill: rgba(255,255,255,.80) !important;
}

/* Label cards if generated */
.node-label rect {
  fill: rgba(255,255,255,.94) !important;
  stroke: rgba(14,34,64,.15) !important;
  stroke-width: 1 !important;
  filter: drop-shadow(0 8px 18px rgba(14,34,64,.12)) !important;
}

.node-label text {
  font-family: var(--font-body) !important;
  font-size: 8px !important;
  line-height: 1.1 !important;
  fill: var(--text) !important;
  font-weight: 800 !important;
}

.node-label.center-label rect {
  fill: var(--color-navy) !important;
  stroke: rgba(255,110,20,.55) !important;
}

.node-label.center-label text {
  fill: #fff !important;
  font-size: 9px !important;
}

/* Selected node behavior */
.node:hover circle,
.node:hover rect,
.node.selected circle,
.node.selected rect {
  filter: drop-shadow(0 0 18px rgba(255,110,20,.55)) !important;
  stroke: var(--color-orange) !important;
  stroke-width: 2.8 !important;
}

/* Node panel beside visuals */
.visual-note-panel {
  min-height: 620px !important;
  max-height: none !important;
  overflow: visible !important;
  background: linear-gradient(180deg, var(--surface), var(--surface-2)) !important;
  border: 1px solid rgba(14,34,64,.12) !important;
  border-radius: 22px !important;
  padding: 18px !important;
}

.visual-note-panel h3 {
  font-size: clamp(21px, 2vw, 28px) !important;
  line-height: 1.08 !important;
  margin-bottom: 8px !important;
  color: var(--color-navy) !important;
}

[data-theme="dark"] .visual-note-panel h3 {
  color: #fff !important;
}

.node-meta {
  font-size: 12px !important;
  line-height: 1.35 !important;
  color: var(--muted) !important;
}

#selectedNodeText {
  font-size: 14px !important;
  line-height: 1.5 !important;
}

.visual-note-panel textarea {
  min-height: 220px !important;
  font-size: 14px !important;
  line-height: 1.5 !important;
  resize: vertical !important;
}

/* Mobile and tablet */
@media (max-width: 1280px) {
  .visual-layout {
    grid-template-columns: 1fr !important;
  }

  .visual-note-panel {
    min-height: auto !important;
  }

  .diagram-panel {
    min-height: 560px !important;
  }

  .svg-mount {
    min-height: 470px !important;
    height: 470px !important;
  }
}

@media (max-width: 860px) {
  .visual-modal .modal-card.visual-wide,
  .visual-wide {
    width: 100% !important;
    max-width: 100% !important;
    min-height: auto !important;
    max-height: calc(100vh - 16px) !important;
    border-radius: 20px !important;
    padding: 14px !important;
  }

  .visual-top {
    flex-direction: column !important;
    align-items: stretch !important;
  }

  .visual-tools {
    justify-content: flex-start !important;
    overflow-x: auto !important;
    flex-wrap: nowrap !important;
    padding-bottom: 4px !important;
  }

  .visual-tools .pill {
    white-space: nowrap !important;
    flex: 0 0 auto !important;
  }

  .diagram-panel {
    min-height: 500px !important;
    padding: 12px !important;
  }

  .svg-mount {
    min-height: 410px !important;
    height: 410px !important;
  }

  .mini-mount {
    height: 230px !important;
    min-height: 230px !important;
  }

  .node text {
    font-size: 7px !important;
  }

  .node .subtext {
    font-size: 5px !important;
  }

  .node-label text {
    font-size: 7px !important;
  }
}

@media (max-width: 520px) {
  .diagram-panel {
    min-height: 440px !important;
  }

  .svg-mount {
    min-height: 360px !important;
    height: 360px !important;
  }

  .visual-card.mini {
    min-height: 290px !important;
  }

  .mini-mount {
    height: 205px !important;
    min-height: 205px !important;
  }

  .panel-title {
    display: block !important;
  }

  .panel-title span {
    max-width: none !important;
    margin-top: 4px !important;
  }
}

/* ===== Hotfix visible SVG renderer ===== */
.truth-hot-svg {
  width: 100% !important;
  height: 100% !important;
  display: block !important;
}

.truth-hot-svg .visual-grid-bg {
  fill: rgba(14, 34, 64, .035) !important;
  stroke: rgba(14, 34, 64, .10) !important;
  stroke-width: 1 !important;
}

[data-theme="dark"] .truth-hot-svg .visual-grid-bg {
  fill: rgba(255,255,255,.035) !important;
  stroke: rgba(255,255,255,.08) !important;
}

.truth-hot-svg .edge {
  stroke: rgba(255, 110, 20, .38) !important;
  stroke-width: 2.2 !important;
  fill: none !important;
  stroke-linecap: round !important;
}

.truth-hot-svg .edge.animated {
  stroke-dasharray: 8 8 !important;
  animation: dash 1.8s linear infinite !important;
}

.truth-hot-node circle {
  stroke: rgba(255,255,255,.70) !important;
  stroke-width: 2 !important;
  filter: drop-shadow(0 8px 16px rgba(14,34,64,.22)) !important;
  cursor: pointer !important;
}

.truth-hot-node:hover circle,
.truth-hot-node.selected circle {
  stroke: #FF6E14 !important;
  stroke-width: 4 !important;
  filter: drop-shadow(0 0 18px rgba(255,110,20,.75)) !important;
}

.truth-hot-label rect {
  fill: rgba(255,255,255,.94) !important;
  stroke: rgba(14,34,64,.16) !important;
  stroke-width: 1 !important;
  filter: drop-shadow(0 8px 18px rgba(14,34,64,.12)) !important;
}

[data-theme="dark"] .truth-hot-label rect {
  fill: rgba(11, 25, 49, .92) !important;
  stroke: rgba(255,255,255,.12) !important;
}

.truth-hot-label .label-text {
  font-family: var(--font-display) !important;
  font-size: 13px !important;
  font-weight: 900 !important;
  fill: var(--color-navy) !important;
  pointer-events: none !important;
}

[data-theme="dark"] .truth-hot-label .label-text {
  fill: #fff !important;
}

.truth-hot-label .detail-text {
  font-family: var(--font-body) !important;
  font-size: 8.5px !important;
  font-weight: 650 !important;
  fill: var(--muted) !important;
  pointer-events: none !important;
}

[data-theme="dark"] .truth-hot-label .detail-text {
  fill: rgba(255,255,255,.68) !important;
}
