/* =========================================================================
   GRAIPH DOCS — INTERACTIVE DIAGRAMS & VISUALIZATIONS
   Enhanced visual components for documentation
   ========================================================================= */

/* ── SVG Centering for all diagram containers ── */
#arch-diagram-interactive,
#pipeline-diagram-interactive,
#panoptic-substeps-diagram,
#coord-diagram-interactive,
#save-layers-diagram,
#auth-sequence-diagram {
  text-align: center;
  margin-bottom: 24px;
  overflow-x: auto;
}

#arch-diagram-interactive svg,
#pipeline-diagram-interactive svg,
#panoptic-substeps-diagram svg,
#coord-diagram-interactive svg,
#save-layers-diagram svg,
#auth-sequence-diagram svg {
  max-width: 100%;
  height: auto;
  display: inline-block;
}

/* ── Architecture Diagram ── */
.arch-diagram-svg {
  width: 100%;
  max-width: 900px;
  margin: 0 auto 24px;
  display: block;
}

.arch-diagram-svg .node-box {
  cursor: pointer;
  transition: filter 0.2s;
}

.arch-diagram-svg .node-box:hover rect {
  stroke: var(--accent);
  stroke-width: 2;
}

.arch-diagram-svg text {
  font-family: var(--font);
  fill: var(--text-primary);
  pointer-events: none;
}

.arch-diagram-svg .label-small {
  font-family: var(--font-mono);
  font-size: 10px;
  fill: var(--text-muted);
}

.arch-diagram-svg .label-title {
  font-size: 13px;
  font-weight: 600;
}

.arch-diagram-svg .label-port {
  font-family: var(--font-mono);
  font-size: 10px;
  fill: var(--accent);
}

.arch-diagram-svg .flow-line {
  stroke-dasharray: 6 4;
}

.arch-diagram-svg .arch-link {
  opacity: 0.5;
}

/* ── Interactive Pipeline Diagram ── */
.pipeline-diagram-svg {
  width: 100%;
  max-width: 960px;
  margin: 0 auto 24px;
  display: block;
}

.pipeline-diagram-svg .step-group {
  cursor: pointer;
  transition: transform 0.15s;
}

.pipeline-diagram-svg .step-group:hover .step-bg {
  stroke: var(--accent);
}

.pipeline-diagram-svg .connector-animated {
  stroke-dasharray: 5 5;
}

.pipeline-diagram-svg .flag-pill {
  rx: 8;
  ry: 8;
}

/* ── Data Flow Journey ── */
.journey-diagram {
  display: flex;
  align-items: stretch;
  gap: 0;
  margin: 24px 0;
  overflow-x: auto;
  padding: 16px 0;
}

.journey-stage {
  flex: 1;
  min-width: 150px;
  position: relative;
  text-align: center;
  padding: 0 8px;
}

.journey-icon {
  width: 64px;
  height: 64px;
  margin: 0 auto 12px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  z-index: 2;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  box-shadow: 0 0 0 4px var(--bg-primary);
}

.journey-icon svg { color: white; }

/* Each pipeline stage is colour-coded */
.journey-icon.capture  { background: #2196F3; border-color: transparent; }
.journey-icon.segment  { background: #9C27B0; border-color: transparent; }
.journey-icon.classify { background: #FF9800; border-color: transparent; }
.journey-icon.describe { background: #00BCD4; border-color: transparent; }
.journey-icon.review   { background: #33CC66; border-color: transparent; }
.journey-icon.export   { background: #607D8B; border-color: transparent; }

.journey-connector {
  position: absolute;
  top: 36px;
  right: -50%;
  width: 100%;
  height: 2px;
  z-index: 1;
}

.journey-connector::after {
  content: '';
  display: block;
  width: 100%;
  height: 2px;
  background: linear-gradient(90deg, var(--accent) 0%, var(--border) 100%);
  opacity: 0.5;
}

.journey-stage:last-child .journey-connector { display: none; }

.journey-stage h3 {
  font-size: 13px;
  margin-bottom: 4px;
}

.journey-stage p {
  font-size: 11px;
  color: var(--text-muted);
  margin: 0;
  line-height: 1.4;
}

.journey-service-tag {
  display: inline-block;
  margin-top: 6px;
  padding: 2px 8px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-family: var(--font-mono);
  font-size: 9px;
  color: var(--text-muted);
}

/* ── Embedding Scatter Plot ── */
.scatter-container {
  position: relative;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  margin-bottom: 24px;
  overflow: hidden;
}

.scatter-svg {
  width: 100%;
  height: 360px;
  display: block;
}

.scatter-svg .axis-line {
  stroke: var(--border);
  stroke-width: 1;
}

.scatter-svg .axis-label {
  font-family: var(--font-mono);
  font-size: 10px;
  fill: var(--text-muted);
}

.scatter-svg .grid-line {
  stroke: var(--border);
  stroke-width: 0.5;
  stroke-dasharray: 2 4;
  opacity: 0.4;
}

.scatter-svg .point {
  cursor: pointer;
  transition: r 0.2s, opacity 0.2s;
}

.scatter-svg .point:hover {
  r: 8;
  opacity: 1 !important;
}

.scatter-svg .cluster-label {
  font-family: var(--font);
  font-size: 11px;
  font-weight: 600;
  fill: var(--text-secondary);
  pointer-events: none;
}

.scatter-svg .cluster-ring {
  fill: none;
  stroke-dasharray: 4 3;
  opacity: 0.3;
}

.scatter-svg .outlier-ring {
  fill: none;
  stroke: var(--alert-warning);
  stroke-width: 2;
  stroke-dasharray: 3 3;
  opacity: 0.7;
}

.scatter-legend {
  display: flex;
  gap: 16px;
  justify-content: center;
  margin-top: 8px;
  flex-wrap: wrap;
}

.scatter-legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-secondary);
}

.scatter-legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ── Auth Flow Sequence Diagram ── */
.sequence-diagram {
  width: 100%;
  max-width: 800px;
  margin: 0 auto 24px;
}

.sequence-diagram svg {
  width: 100%;
  display: block;
}

.sequence-diagram .actor-line {
  stroke: var(--border);
  stroke-width: 1;
  stroke-dasharray: 4 4;
}

.sequence-diagram .actor-box {
  fill: var(--bg-elevated);
  stroke: var(--border);
  stroke-width: 1;
  rx: 4;
  ry: 4;
}

.sequence-diagram .actor-label {
  font-family: var(--font);
  font-size: 12px;
  font-weight: 600;
  fill: var(--text-primary);
  text-anchor: middle;
}

.sequence-diagram .msg-arrow {
  stroke: var(--accent);
  stroke-width: 1.5;
  marker-end: url(#arrowhead);
}

.sequence-diagram .msg-arrow-return {
  stroke: var(--text-muted);
  stroke-width: 1;
  stroke-dasharray: 4 3;
  marker-end: url(#arrowhead-muted);
}

.sequence-diagram .msg-label {
  font-family: var(--font-mono);
  font-size: 10px;
  fill: var(--text-secondary);
}

.sequence-diagram .msg-number {
  font-family: var(--font);
  font-size: 10px;
  font-weight: 700;
  fill: white;
}

/* ── Flags Cascade Interactive ── */
.flags-interactive {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-bottom: 24px;
}

.flags-row {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.flag-chip {
  padding: 8px 14px;
  border-radius: 20px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.25s;
  border: 2px solid transparent;
  user-select: none;
}

.flag-chip.active {
  background: var(--accent-muted);
  border-color: var(--accent);
  color: var(--accent);
}

.flag-chip.inactive {
  background: var(--bg-tertiary);
  border-color: var(--border);
  color: var(--text-muted);
}

.flag-chip.clearing {
  animation: flagClear 0.4s ease-out;
  background: rgba(229, 57, 53, 0.15);
  border-color: var(--alert-error);
  color: var(--alert-error);
}

@keyframes flagClear {
  0% { transform: scale(1); }
  50% { transform: scale(0.92); }
  100% { transform: scale(1); }
}

.flag-arrow {
  color: var(--text-muted);
  font-size: 18px;
  flex-shrink: 0;
}

.flags-controls {
  text-align: center;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.flags-controls p {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.flag-sim-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  margin: 0 4px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-family: var(--font);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
}

.flag-sim-btn:hover {
  background: var(--accent-muted);
  border-color: var(--accent);
  color: var(--accent);
}

.flag-sim-btn.active-btn {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

/* ── Tagger Transformation Visual ── */
.transform-visual {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 16px;
  align-items: center;
  margin: 24px 0;
}

.transform-side {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
}

.transform-side h3 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  margin-bottom: 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

.transform-arrow {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  color: var(--accent);
}

.transform-arrow svg {
  opacity: 0.8;
}

.transform-arrow span {
  font-size: 10px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.transform-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  margin-bottom: 4px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  color: var(--text-secondary);
}

.transform-item:last-child { margin-bottom: 0; }

.transform-color {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  flex-shrink: 0;
}

.transform-item code {
  font-size: 10px;
  margin-left: auto;
}

/* ── Object Type Visual Cards ── */
.obj-type-visual {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin: 20px 0;
}

.obj-type-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  text-align: center;
  transition: border-color 0.15s;
  cursor: default;
  position: relative;
}

.obj-type-card:hover {
  border-color: var(--border-hover);
}

.obj-type-card .obj-icon {
  width: 40px;
  height: 40px;
  margin: 0 auto 8px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-tertiary);
  color: var(--text-secondary);
}

.obj-type-card h4 {
  font-size: 13px;
  text-transform: none;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.obj-type-card .obj-kind {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  font-weight: 600;
}

.obj-type-card p {
  font-size: 11px;
  color: var(--text-muted);
  margin: 6px 0 0;
  line-height: 1.4;
}

/* ── Responsive ── */
@media (max-width: 900px) {
  .obj-type-visual { grid-template-columns: repeat(2, 1fr); }
  .transform-visual { grid-template-columns: 1fr; }
  .transform-arrow { transform: rotate(90deg); }
  .journey-diagram { flex-wrap: wrap; }
}

@media (max-width: 600px) {
  .obj-type-visual { grid-template-columns: 1fr; }
}
