/* EXPERIMENTAL / DELETABLE — AI Workflow Visualizer */
/*
 * Node-based visualizer for the AI workflow pipeline.
 * Light, spacious, Figma-Weave-inspired editorial canvas.
 * Fully self-contained; deletion = remove this file
 * + the fenced <link> in editor.html.erb.
 */

/* ==========================================================================
   Visualise trigger button (inside _ai_inputs_panel_v2.html.erb)
   ========================================================================== */

.ai-viz-open-btn {
  appearance: none;
  background: rgba(168, 85, 247, 0.08);
  border: 1px solid rgba(168, 85, 247, 0.2);
  color: #7c3aed;
  border-radius: 8px;
  padding: 5px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  margin-left: auto;
  margin-right: 24px;
  letter-spacing: 0.3px;
  transition: all 0.2s ease;
}
.ai-viz-open-btn:hover {
  background: rgba(168, 85, 247, 0.14);
  border-color: rgba(168, 85, 247, 0.35);
}

/* ==========================================================================
   Dimmed backdrop + floating widget frame
   ========================================================================== */

.ai-viz-overlay {
  position: fixed;
  top: 64px;    /* Inset below the editor's top nav bar */
  left: 60px;   /* Inset past the editor's left nav rail */
  right: 0;
  bottom: 0;
  z-index: 9999;
  background: rgba(0, 0, 0, 0.25); /* Dimmed editor behind */
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 28px;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  color: #1a1a2e;
  opacity: 1;
  transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.ai-viz-overlay[hidden] {
  display: none;
  opacity: 0;
}

/* The floating panel widget */
.ai-viz-widget {
  position: relative;
  width: 100%;
  height: 100%;
  max-width: 1600px;
  max-height: 100%;
  background: #f8f9fc;
  border-radius: 20px;
  border: 1px solid rgba(0, 0, 0, 0.08);
  box-shadow:
    0 8px 40px rgba(0, 0, 0, 0.12),
    0 2px 12px rgba(0, 0, 0, 0.06);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ==========================================================================
   Toolbar
   ========================================================================== */

.ai-viz-toolbar {
  position: relative;
  flex-shrink: 0;
  height: 52px;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
  background: #fff;
  border-radius: 20px 20px 0 0;
  z-index: 10;
}

.ai-viz-toolbar__left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.ai-viz-toolbar__title {
  font-size: 13px;
  font-weight: 600;
  color: #475569;
  letter-spacing: 0.8px;
  text-transform: uppercase;
}

.ai-viz-toolbar__badge {
  font-size: 11px;
  font-weight: 500;
  color: #94a3b8;
  background: #f1f5f9;
  padding: 3px 10px;
  border-radius: 6px;
  letter-spacing: 0.3px;
}

.ai-viz-toolbar__controls {
  display: flex;
  gap: 6px;
}

.ai-viz-toolbar button {
  appearance: none;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  color: #475569;
  height: 32px;
  padding: 0 12px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ai-viz-toolbar button.ai-viz-toolbar__zoom {
  padding: 0;
  width: 32px;
  font-size: 15px;
  font-weight: 600;
}

.ai-viz-toolbar button:hover {
  background: #f1f5f9;
  border-color: #cbd5e1;
}

.ai-viz-toolbar__close-group {
  display: flex;
  gap: 6px;
  margin-left: 12px;
  padding-left: 12px;
  border-left: 1px solid #e2e8f0;
}

.ai-viz-toolbar button.ai-viz-toolbar__close {
  background: #fff;
  color: #64748b;
  gap: 4px;
  padding: 0 14px;
  font-weight: 500;
}

.ai-viz-toolbar button.ai-viz-toolbar__close:hover {
  background: #f1f5f9;
  color: #1e293b;
}

/* --------------------------------------------------------------------------
   Mobile / narrow viewports — keep the toolbar (esp. Close) reachable.
   On desktop the toolbar's title + status badge + 3 zoom buttons + the
   redundant Close/"Back to Workflow Editor" pair fit fine; on a ~390px phone
   they overflow and push Close off-screen. Here we go full-bleed, drop the
   non-essential badge, collapse the redundant second close button, and pin
   the controls so Close never scrolls out of view (title truncates instead).
   -------------------------------------------------------------------------- */
@media (max-width: 640px) {
  .ai-viz-overlay {
    top: 56px;
    left: 0;
    padding: 8px;
  }

  .ai-viz-widget {
    border-radius: 14px;
  }

  .ai-viz-toolbar {
    padding: 0 12px;
    gap: 8px;
  }

  .ai-viz-toolbar__left {
    min-width: 0;      /* allow the title to shrink/truncate */
    flex: 1 1 auto;
    overflow: hidden;
  }

  .ai-viz-toolbar__title {
    font-size: 12px;
    letter-spacing: 0.4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* Non-essential "Visualization only…" status text — hide on small screens. */
  .ai-viz-toolbar__badge {
    display: none;
  }

  .ai-viz-toolbar__controls {
    flex-shrink: 0;    /* controls (incl. Close) always stay visible */
    gap: 4px;
  }

  .ai-viz-toolbar button {
    height: 30px;
    padding: 0 10px;
    font-size: 12px;
  }

  .ai-viz-toolbar button.ai-viz-toolbar__zoom {
    width: 30px;
    padding: 0;
  }

  .ai-viz-toolbar__close-group {
    margin-left: 6px;
    padding-left: 6px;
  }

  /* Both close buttons do the same thing; keep just "Close" on mobile. */
  .ai-viz-toolbar__close-group .ai-viz-toolbar__close:last-child {
    display: none;
  }
}

/* ==========================================================================
   Canvas wrapper — premium textured background
   ========================================================================== */

.ai-viz-canvas-wrapper {
  flex: 1;
  position: relative;
  overflow: hidden;
  cursor: grab;
  border-radius: 0 0 20px 20px;

  /* Premium mesh gradient wash */
  background:
    radial-gradient(ellipse 80% 60% at 15% 25%, rgba(168, 85, 247, 0.04) 0%, transparent 70%),
    radial-gradient(ellipse 70% 50% at 85% 75%, rgba(6, 182, 212, 0.04) 0%, transparent 70%),
    radial-gradient(ellipse 60% 40% at 50% 10%, rgba(244, 114, 182, 0.02) 0%, transparent 60%),
    #f8f9fc;

  /* Subtle dot grid */
  background-image:
    radial-gradient(circle, rgba(148, 163, 184, 0.3) 0.6px, transparent 0.6px),
    radial-gradient(ellipse 80% 60% at 15% 25%, rgba(168, 85, 247, 0.04) 0%, transparent 70%),
    radial-gradient(ellipse 70% 50% at 85% 75%, rgba(6, 182, 212, 0.04) 0%, transparent 70%),
    radial-gradient(ellipse 60% 40% at 50% 10%, rgba(244, 114, 182, 0.02) 0%, transparent 60%);
  background-size: 20px 20px, 100% 100%, 100% 100%, 100% 100%;
  background-color: #f8f9fc;
}

.ai-viz-canvas-wrapper:active {
  cursor: grabbing;
}

/* Inner surface that pans/zooms */
.ai-viz-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  transform-origin: 0 0;
  will-change: transform;
}

/* SVG Threads */
.ai-viz-svg-layer {
  position: absolute;
  top: 0;
  left: 0;
  overflow: visible;
  pointer-events: none;
  z-index: 1;
}

.ai-viz-svg-layer path {
  fill: none;
  vector-effect: non-scaling-stroke;
}

/* ==========================================================================
   Nodes (Cards)
   ========================================================================== */

.ai-viz-node {
  position: absolute;
  z-index: 2;
  box-sizing: border-box;
  cursor: grab;
  opacity: 0;
  animation: viz-node-enter 0.45s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

.ai-viz-node:active {
  cursor: grabbing;
  z-index: 3;
}

@keyframes viz-node-enter {
  0% { opacity: 0; transform: translateY(12px) scale(0.97); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

/* Base Card — light glassmorphism */
.ai-viz-card {
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(0, 0, 0, 0.06);
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  transition: border-color 0.2s, box-shadow 0.2s, transform 0.2s;
  box-shadow:
    0 1px 3px rgba(0, 0, 0, 0.04),
    0 4px 16px rgba(0, 0, 0, 0.03);
}

.ai-viz-node:hover .ai-viz-card {
  border-color: rgba(0, 0, 0, 0.1);
  box-shadow:
    0 2px 8px rgba(0, 0, 0, 0.06),
    0 8px 32px rgba(0, 0, 0, 0.04);
  transform: translateY(-1px);
}

/* --------------------------------------------------------------------------
   1. Global Input Node (Left rail) — "upload" placeholder style (Cyan themed)
   -------------------------------------------------------------------------- */

.ai-viz-node--input {
  width: 200px;
}
.ai-viz-node--input .ai-viz-card {
  padding: 0;
  border-radius: 14px;
  overflow: hidden;
  border: 2px dashed rgba(6, 182, 212, 0.25);
  background: rgba(236, 254, 255, 0.85);
  box-shadow:
    0 1px 3px rgba(6, 182, 212, 0.05),
    0 4px 12px rgba(6, 182, 212, 0.03);
}
.ai-viz-node--input:hover .ai-viz-card {
  border-color: rgba(6, 182, 212, 0.45);
  background: rgba(236, 254, 255, 0.95);
}
.ai-viz-node__input-slot {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 24px 16px;
  text-align: center;
}
.ai-viz-node__input-glyph {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: linear-gradient(135deg, rgba(6, 182, 212, 0.1) 0%, rgba(34, 211, 238, 0.15) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  color: #0891b2;
}
.ai-viz-node__input-label {
  font-size: 13px;
  color: #0f766e;
  font-weight: 600;
  line-height: 1.3;
}
.ai-viz-node__input-hint {
  font-size: 11px;
  color: #0891b2;
  opacity: 0.8;
  font-weight: 500;
}

/* --------------------------------------------------------------------------
   2. Canvas Node — IMAGE-FORWARD (Figma Weave style)
   -------------------------------------------------------------------------- */

.ai-viz-node--canvas {
  width: 300px;
}
.ai-viz-node--canvas .ai-viz-card {
  padding: 0;
  overflow: hidden;
}
.ai-viz-node__canvas-img-wrap {
  width: 100%;
  aspect-ratio: 16 / 10;
  background: #f1f5f9;
  overflow: hidden;
  position: relative;
}
.ai-viz-node__canvas-thumb {
  width: 100%;
  height: 100%;
  object-fit: contain; /* preview the entire image without crop */
  display: block;
}
/* Placeholder when no image */
.ai-viz-node__canvas-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 36px;
  color: #cbd5e1;
}
.ai-viz-node__canvas-caption {
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 6px;
  border-top: 1px solid rgba(0, 0, 0, 0.04);
}
.ai-viz-node__canvas-title {
  font-size: 13px;
  font-weight: 600;
  color: #1e293b;
}
.ai-viz-node__canvas-dot {
  font-size: 8px;
  color: #cbd5e1;
}
.ai-viz-node__canvas-slide {
  font-size: 12px;
  color: #94a3b8;
  font-weight: 500;
}

/* --------------------------------------------------------------------------
   3. Hero Step Node — the star of the show
   -------------------------------------------------------------------------- */

.ai-viz-node--step {
  width: 300px;
}
.ai-viz-node--step .ai-viz-card {
  padding: 24px;
  border: 1px solid rgba(168, 85, 247, 0.12);
  box-shadow:
    0 0 0 1px rgba(168, 85, 247, 0.04),
    0 2px 8px rgba(168, 85, 247, 0.06),
    0 8px 32px rgba(0, 0, 0, 0.04);
}
.ai-viz-node--step:hover .ai-viz-card {
  border-color: rgba(168, 85, 247, 0.25);
  box-shadow:
    0 0 0 1px rgba(168, 85, 247, 0.08),
    0 4px 16px rgba(168, 85, 247, 0.1),
    0 12px 40px rgba(0, 0, 0, 0.06);
}
.ai-viz-node__step-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}
.ai-viz-node__step-preset {
  font-size: 11px;
  font-weight: 700;
  color: #7c3aed;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  background: rgba(168, 85, 247, 0.08);
  padding: 5px 10px;
  border-radius: 6px;
}
.ai-viz-node__step-icon {
  font-size: 20px;
}
.ai-viz-node__step-action {
  font-size: 18px;
  font-weight: 700;
  color: #1e293b;
  margin-bottom: 10px;
  letter-spacing: -0.2px;
}
.ai-viz-node__step-prompt {
  font-size: 13px;
  color: #94a3b8;
  line-height: 1.6;
  max-height: 72px;
  overflow-y: auto;
  padding-right: 4px;
}
/* Style the scrollbar to keep it premium */
.ai-viz-node__step-prompt::-webkit-scrollbar {
  width: 4px;
}
.ai-viz-node__step-prompt::-webkit-scrollbar-track {
  background: transparent;
}
.ai-viz-node__step-prompt::-webkit-scrollbar-thumb {
  background: rgba(168, 85, 247, 0.15);
  border-radius: 2px;
}
.ai-viz-node__step-prompt::-webkit-scrollbar-thumb:hover {
  background: rgba(168, 85, 247, 0.3);
}

/* --------------------------------------------------------------------------
   4. Output Node — premium shimmer placeholder
   -------------------------------------------------------------------------- */

.ai-viz-node--output {
  width: 300px;
}
.ai-viz-node--output .ai-viz-card {
  align-items: center;
  justify-content: center;
  padding: 0;
  overflow: hidden;
  border: 2px dashed rgba(0, 0, 0, 0.06);
  background: rgba(255, 255, 255, 0.7);
}
.ai-viz-node__output-frame {
  width: 100%;
  aspect-ratio: 16 / 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  position: relative;
  overflow: hidden;
  background: linear-gradient(135deg, #f8f9fc 0%, #f1f0ff 40%, #ecfeff 100%);
}
/* Shimmer sweep animation */
.ai-viz-node__output-frame::after {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 60%;
  height: 100%;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(255, 255, 255, 0.6) 50%,
    transparent 100%
  );
  animation: viz-shimmer 3s ease-in-out infinite;
  pointer-events: none;
}
@keyframes viz-shimmer {
  0% { left: -100%; }
  100% { left: 200%; }
}
.ai-viz-node__output-icon {
  font-size: 32px;
  z-index: 1;
}
.ai-viz-node__output-label {
  font-size: 14px;
  font-weight: 600;
  z-index: 1;
  background: linear-gradient(135deg, #7c3aed, #06b6d4);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
.ai-viz-node__output-caption {
  padding: 10px 16px;
  width: 100%;
  box-sizing: border-box;
  border-top: 1px solid rgba(0, 0, 0, 0.04);
  text-align: center;
}
.ai-viz-node__output-hint {
  font-size: 11px;
  color: #94a3b8;
  font-weight: 400;
}

/* Video variant — film-strip accent */
.ai-viz-node--output[data-output-type="video"] .ai-viz-card {
  border-color: rgba(6, 182, 212, 0.2);
}
.ai-viz-node--output[data-output-type="video"] .ai-viz-node__output-frame {
  background: linear-gradient(135deg, #f8f9fc 0%, #ecfeff 40%, #f0fdfa 100%);
}

/* ==========================================================================
   Empty State
   ========================================================================== */

.ai-viz-empty {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  text-align: center;
}
.ai-viz-empty__icon {
  font-size: 40px;
  opacity: 0.4;
}
.ai-viz-empty h3 {
  font-size: 18px;
  color: #1e293b;
  font-weight: 600;
}
.ai-viz-empty p {
  font-size: 14px;
  color: #94a3b8;
  max-width: 280px;
  line-height: 1.6;
}
