/* ═══════════════════════════════════════════════════════════════════════════
   AI Agent Flow Visualizer — Styles
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── CSS Variables ─────────────────────────────────────────────────────────── */
:root {
  --bg: #0d1117;
  --surface: #161b22;
  --surface2: #1e2530;
  --border: #30363d;
  --text: #e6edf3;
  --text-muted: #7d8590;
  --text-dim: #484f58;

  --accent: #58a6ff;
  --accent-glow: rgba(88, 166, 255, 0.25);

  --node-input:     #1e3a5f;
  --node-input-b:   #58a6ff;
  --node-llm:       #3a1e5f;
  --node-llm-b:     #c084fc;
  --node-tool:      #1e4a2e;
  --node-tool-b:    #4ade80;
  --node-condition: #4a3e1a;
  --node-condition-b: #fbbf24;
  --node-output:    #4a1e1e;
  --node-output-b:  #f87171;

  --edge-color: #58a6ff;
  --edge-active-color: #4ade80;

  --palette-w: 200px;
  --inspector-w: 240px;
  --topbar-h: 52px;
  --log-h: 140px;

  --radius: 10px;
  --radius-sm: 6px;
  --transition: 0.18s ease;

  --shadow-node: 0 4px 24px rgba(0,0,0,0.5);
  --shadow-glow: 0 0 16px rgba(88,166,255,0.3);
}

/* ── Reset ─────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body { font-family: 'Segoe UI', system-ui, -apple-system, sans-serif; background: var(--bg); color: var(--text); font-size: 13px; }

/* ── Top Bar ────────────────────────────────────────────────────────────────── */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px;
  z-index: 100;
  gap: 12px;
}
.topbar-left { display: flex; align-items: baseline; gap: 8px; }
.logo { font-size: 16px; font-weight: 700; color: var(--accent); letter-spacing: -0.3px; }
.logo-sub { font-size: 11px; color: var(--text-muted); }
.topbar-center { display: flex; align-items: center; gap: 8px; flex: 1; justify-content: center; }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.portfolio-link {
  font-size: 12px; color: var(--text-muted); text-decoration: none;
  padding: 4px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  transition: var(--transition);
}
.portfolio-link:hover { color: var(--accent); border-color: var(--accent); }

/* ── Buttons ────────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 5px 13px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface2);
  color: var(--text); font-size: 12px; font-weight: 500;
  cursor: pointer; transition: var(--transition);
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn-run { border-color: #238636; background: #1a3a20; color: #4ade80; }
.btn-run:hover { background: #1e4a26; border-color: #4ade80; color: #4ade80; box-shadow: 0 0 10px rgba(74,222,128,0.2); }
.btn-pause { border-color: #fbbf24; background: #3a2e10; color: #fbbf24; }
.btn-pause:hover { background: #4a3a14; }
.btn-reset { }
.btn-clear { }
.btn-apply { border-color: var(--accent); color: var(--accent); }
.btn-apply:hover { background: var(--accent-glow); }
.btn-delete { border-color: #f87171; color: #f87171; }
.btn-delete:hover { background: rgba(248,113,113,0.1); }
.hidden { display: none !important; }

.speed-control {
  display: flex; align-items: center; gap: 6px;
  color: var(--text-muted); font-size: 11px;
}
input[type=range] {
  width: 80px; accent-color: var(--accent);
  cursor: pointer;
}

/* ── App Layout ─────────────────────────────────────────────────────────────── */
.app {
  display: grid;
  grid-template-columns: var(--palette-w) 1fr var(--inspector-w);
  position: fixed;
  top: var(--topbar-h); left: 0; right: 0;
  bottom: var(--log-h);
}

/* ── Palette ────────────────────────────────────────────────────────────────── */
.palette {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 16px 12px;
  overflow-y: auto;
  display: flex; flex-direction: column; gap: 6px;
}
.palette-title {
  font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 1.2px; color: var(--text-muted);
  padding: 0 4px 8px;
}
.palette-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 10px; border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface2);
  cursor: grab; user-select: none;
  transition: var(--transition);
}
.palette-item:hover { border-color: var(--accent); transform: translateX(2px); }
.palette-item:active { cursor: grabbing; }

.palette-icon {
  width: 32px; height: 32px; border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.input-icon     { background: var(--node-input);     color: var(--node-input-b); }
.llm-icon       { background: var(--node-llm);       color: var(--node-llm-b); }
.tool-icon      { background: var(--node-tool);      color: var(--node-tool-b); }
.condition-icon { background: var(--node-condition); color: var(--node-condition-b); }
.output-icon    { background: var(--node-output);    color: var(--node-output-b); }

.palette-label { display: flex; flex-direction: column; gap: 1px; }
.palette-name { font-size: 12px; font-weight: 600; color: var(--text); }
.palette-desc { font-size: 10px; color: var(--text-muted); }

.palette-hint {
  display: flex; align-items: flex-start; gap: 6px;
  font-size: 10px; color: var(--text-dim); line-height: 1.5;
  padding: 12px 4px 0;
  margin-top: 4px; border-top: 1px solid var(--border);
}
.palette-hint svg { flex-shrink: 0; margin-top: 1px; }

/* ── Canvas ─────────────────────────────────────────────────────────────────── */
.canvas-wrap {
  position: relative; overflow: hidden;
  background: var(--bg);
  background-image:
    radial-gradient(circle at 1px 1px, var(--border) 1px, transparent 0);
  background-size: 28px 28px;
}
.canvas { width: 100%; height: 100%; }
.canvas-hint {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  color: var(--text-dim); font-size: 14px; pointer-events: none;
  text-align: center; line-height: 2;
  transition: opacity 0.5s;
}
.particle-canvas {
  position: absolute; inset: 0; pointer-events: none;
  width: 100%; height: 100%;
}

/* ── SVG Nodes ──────────────────────────────────────────────────────────────── */
.node-group { cursor: move; }
.node-group:focus { outline: none; }

.node-body {
  rx: 10; ry: 10;
  stroke-width: 1.5;
  filter: drop-shadow(0 4px 12px rgba(0,0,0,0.5));
  transition: filter 0.2s;
}
.node-group:hover .node-body { filter: drop-shadow(0 4px 16px rgba(88,166,255,0.25)); }
.node-group.selected .node-body { stroke-width: 2.5; filter: drop-shadow(0 0 12px rgba(88,166,255,0.5)); }
.node-group.executing .node-body { filter: drop-shadow(0 0 20px var(--node-exec-glow, rgba(74,222,128,0.7))); }
.node-group.completed .node-body { opacity: 0.85; }
.node-group.error .node-body { filter: drop-shadow(0 0 16px rgba(248,113,113,0.7)); }

.node-title { font-size: 12px; font-weight: 700; fill: #e6edf3; }
.node-subtitle { font-size: 10px; fill: rgba(255,255,255,0.55); }
.node-badge {
  rx: 4; ry: 4;
}

/* Ports */
.port {
  cursor: crosshair; transition: r 0.15s;
}
.port:hover { r: 7; }
.port-in  { fill: #2d333b; stroke: var(--text-muted); stroke-width: 1.5; }
.port-out { fill: #2d333b; stroke: var(--accent); stroke-width: 1.5; }
.port-out:hover { fill: var(--accent); }

/* ── Edges ──────────────────────────────────────────────────────────────────── */
.edge {
  fill: none;
  stroke: var(--edge-color);
  stroke-width: 1.8;
  marker-end: url(#arrowhead);
  opacity: 0.6;
  cursor: pointer;
  transition: stroke 0.2s, opacity 0.2s, stroke-width 0.2s;
}
.edge:hover { opacity: 1; stroke-width: 2.5; }
.edge.selected { stroke: white; opacity: 1; stroke-width: 2.5; }
.edge.active {
  stroke: var(--edge-active-color);
  opacity: 1;
  stroke-width: 2.5;
  marker-end: url(#arrowhead-active);
}
.edge.edge-cond-true  { stroke: #4ade80; }
.edge.edge-cond-false { stroke: #f87171; }

.temp-edge {
  fill: none; stroke: var(--accent); stroke-width: 1.8;
  stroke-dasharray: 6 4; opacity: 0.7;
  marker-end: url(#arrowhead);
  pointer-events: none;
}

/* ── Inspector ──────────────────────────────────────────────────────────────── */
.inspector {
  background: var(--surface);
  border-left: 1px solid var(--border);
  padding: 16px 14px;
  overflow-y: auto;
  display: flex; flex-direction: column; gap: 12px;
}
.inspector-title {
  font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 1.2px; color: var(--text-muted);
  padding-bottom: 8px; border-bottom: 1px solid var(--border);
}
.inspector-empty { color: var(--text-dim); font-size: 12px; line-height: 1.6; }
.inspector-form { display: flex; flex-direction: column; gap: 12px; }
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group label { font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.8px; color: var(--text-muted); }
.form-group input, .form-group select, .form-group textarea {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text);
  font-size: 12px; padding: 7px 9px;
  transition: var(--transition);
  font-family: inherit; resize: none;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
}
.form-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ── Log Panel ──────────────────────────────────────────────────────────────── */
.log-panel {
  position: fixed; bottom: 0; left: 0; right: 0;
  height: var(--log-h);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex; flex-direction: column;
  z-index: 90;
}
.log-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 16px;
  font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 1px; color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.log-toggle {
  background: none; border: none; color: var(--text-muted);
  cursor: pointer; font-size: 12px; padding: 2px 6px;
  border-radius: 3px; transition: var(--transition);
}
.log-toggle:hover { color: var(--accent); }
.log-body {
  flex: 1; overflow-y: auto;
  padding: 8px 16px;
  font-family: 'Consolas', 'Menlo', monospace;
  font-size: 11px; line-height: 1.8;
}
.log-entry { display: flex; gap: 10px; align-items: flex-start; }
.log-time { color: var(--text-dim); flex-shrink: 0; }
.log-level-info  { color: var(--accent); }
.log-level-exec  { color: #4ade80; }
.log-level-done  { color: #c084fc; }
.log-level-warn  { color: #fbbf24; }
.log-level-error { color: #f87171; }

/* ── Node type specific colours (used in JS) ── */
.type-input     { --node-bg: #1a2e4a; --node-border: var(--node-input-b);     --node-exec-glow: rgba(88,166,255,0.7); }
.type-llm       { --node-bg: #2a1a4a; --node-border: var(--node-llm-b);       --node-exec-glow: rgba(192,132,252,0.7); }
.type-tool      { --node-bg: #1a3a22; --node-border: var(--node-tool-b);      --node-exec-glow: rgba(74,222,128,0.7); }
.type-condition { --node-bg: #3a2e10; --node-border: var(--node-condition-b); --node-exec-glow: rgba(251,191,36,0.7); }
.type-output    { --node-bg: #3a1a1a; --node-border: var(--node-output-b);    --node-exec-glow: rgba(248,113,113,0.7); }

/* ── Execution status overlay ───────────────────────────────────────────────── */
.status-badge {
  font-size: 9px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.6px; pointer-events: none;
}

/* ── Scrollbar ──────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

/* ── Animations ─────────────────────────────────────────────────────────────── */
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.6; }
}
@keyframes spin {
  to { transform: rotate(360deg); }
}
.executing-spin {
  transform-origin: center;
  animation: spin 1.2s linear infinite;
}

/* ── Mobile / Touch ─────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  :root {
    --topbar-h: 48px;
    --log-h: 68px;
    --palette-w: 0px;
    --inspector-w: 0px;
    --mobile-palette-h: 72px;
  }

  /* Topbar: stripped for mobile */
  .logo-sub { display: none; }
  .topbar-left { flex: 1; }
  .topbar-center { gap: 6px; flex: 0; }
  .topbar-center .speed-control { display: none; }
  .portfolio-link { display: none; }
  .btn { padding: 5px 11px; font-size: 12px; gap: 4px; }

  /* Layout: full-width canvas, palette at bottom */
  .app {
    grid-template-columns: 1fr;
    bottom: calc(var(--log-h) + var(--mobile-palette-h));
  }

  /* Inspector: disabled (mobile uses overlay) */
  .inspector { display: none; }

  /* Palette: horizontal scroll strip at bottom */
  .palette {
    position: fixed;
    left: 0; right: 0;
    bottom: var(--log-h);
    height: var(--mobile-palette-h);
    width: 100%;
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 8px 10px;
    border-right: none;
    border-top: 1px solid var(--border);
    gap: 8px;
    align-items: center;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x mandatory;
  }
  .palette-title { display: none; }
  .palette-hint  { display: none; }
  .palette-item {
    flex-direction: column;
    align-items: center;
    padding: 8px 12px;
    gap: 4px;
    min-width: 62px;
    flex-shrink: 0;
    scroll-snap-align: start;
    cursor: pointer;
    border-radius: 10px;
    touch-action: manipulation;
  }
  .palette-item:hover { transform: none; }
  .palette-item:active { background: var(--accent-glow); border-color: var(--accent); }
  .palette-icon { width: 28px; height: 28px; }
  .palette-label { align-items: center; }
  .palette-name { font-size: 10px; font-weight: 600; }
  .palette-desc { display: none; }

  /* Log: compact */
  .log-body { font-size: 10px; padding: 5px 12px; line-height: 1.6; }

  /* Canvas hint: mobile text */
  .canvas-hint { font-size: 12px; padding: 0 24px; text-align: center; line-height: 1.8; }
}

/* ── Mobile Inspector Overlay ────────────────────────────────────────────────── */
#mobileInspector {
  display: none;
}

@media (max-width: 768px) {
  #mobileInspector {
    display: flex;
    position: fixed;
    left: 0; right: 0;
    bottom: calc(68px + 72px);
    background: var(--surface);
    border-top: 2px solid var(--accent);
    border-radius: 14px 14px 0 0;
    padding: 12px 16px 16px;
    z-index: 85;
    flex-direction: column;
    gap: 10px;
    max-height: 48vh;
    overflow-y: auto;
    transform: translateY(110%);
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 -8px 32px rgba(0,0,0,0.5);
  }
  #mobileInspector.open { transform: translateY(0); }

  .mob-insp-handle {
    width: 36px; height: 4px;
    background: var(--border); border-radius: 2px;
    margin: 0 auto -2px;
  }
  .mob-insp-header {
    display: flex; align-items: center; justify-content: space-between;
  }
  .mob-insp-badge {
    font-size: 10px; font-weight: 700; text-transform: uppercase;
    letter-spacing: 0.8px; padding: 3px 10px;
    border-radius: 20px; border: 1px solid currentColor;
  }
  .mob-insp-close {
    background: none; border: none;
    color: var(--text-muted); cursor: pointer;
    font-size: 20px; line-height: 1; padding: 0 4px;
  }
  .mob-insp-name {
    font-size: 14px; font-weight: 600; color: var(--text);
  }
  .mob-insp-grid {
    display: grid; grid-template-columns: auto 1fr;
    gap: 7px 12px; align-items: center;
  }
  .mob-insp-label {
    font-size: 10px; font-weight: 600; text-transform: uppercase;
    color: var(--text-muted); white-space: nowrap;
  }
  .mob-insp-value {
    font-size: 12px; color: var(--text);
    background: var(--surface2); border: 1px solid var(--border);
    border-radius: var(--radius-sm); padding: 5px 9px;
  }
}
