/* ============================================================
   FlowForge — Styles (Responsive: mobile / tablet / desktop)
   ============================================================ */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; width: 100%;
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
}
:root {
  --bg: #0f172a;
  --panel: #1e293b;
  --panel-2: #172033;
  --border: #334155;
  --accent: #f97316;
  --accent-2: #fb923c;
  --text: #e2e8f0;
  --muted: #94a3b8;
}

/* ===== Canvas grid background ===== */
#canvas {
  background-color: var(--bg);
  background-image: radial-gradient(circle, rgba(148,163,184,0.13) 1px, transparent 1px);
  background-size: 22px 22px;
  touch-action: none;            /* important for touch pan/drag */
}

/* ===== Node styling ===== */
.wf-node {
  position: absolute;
  width: 220px;
  background: linear-gradient(180deg, #233044 0%, #1e293b 100%);
  border: 2px solid var(--border);
  border-radius: 14px;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  transition: border-color .15s, box-shadow .15s, transform .08s;
  z-index: 5;
  touch-action: none;
}
.wf-node:hover { border-color: #64748b; box-shadow: 0 6px 24px rgba(0,0,0,.45); }
.wf-node.selected { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(249,115,22,.25); }
.wf-node.dragging { cursor: grabbing; opacity: .92; z-index: 50; box-shadow: 0 12px 40px rgba(0,0,0,.6); }
.wf-node.exec-success { border-color: #22c55e; box-shadow: 0 0 0 2px rgba(34,197,94,.2); }
.wf-node.exec-error { border-color: #ef4444; box-shadow: 0 0 0 2px rgba(239,68,68,.2); }
.wf-node.exec-running { border-color: #eab308; animation: pulse 1s infinite; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(234,179,8,.4);} 50% { box-shadow: 0 0 0 8px rgba(234,179,8,0);} }

.node-header {
  display: flex; align-items: center; gap: 8px;
  padding: 11px 12px;
  border-radius: 12px 12px 0 0;
  font-weight: 600; font-size: 13px;
}
.node-header span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.node-body { padding: 8px 12px 12px; font-size: 11px; color: var(--muted); word-break: break-word; }
.node-badge {
  position: absolute; top: -9px; right: 10px;
  font-size: 9px; padding: 2px 7px; border-radius: 8px; font-weight: 700;
}

/* ===== Ports (connection dots) ===== */
.port {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 16px; height: 16px; border-radius: 50%;
  background: #475569; border: 2px solid #0f172a;
  cursor: crosshair; z-index: 10;
  transition: transform .12s, background .12s;
  touch-action: none;
}
.port:hover, .port.port-hot { background: var(--accent); transform: translateY(-50%) scale(1.4); }
.port-in { left: -9px; }
.port-out { right: -9px; }
.port-label {
  position: absolute; right: 20px; top: 50%; transform: translateY(-50%);
  font-size: 8px; font-weight: 700; color: #94a3b8; white-space: nowrap;
  pointer-events: none; background: var(--panel); padding: 0 3px; border-radius: 3px;
}

/* ===== Connection SVG ===== */
#connections { position: absolute; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none; z-index: 1; overflow: visible; }
.conn-path { fill: none; stroke: #64748b; stroke-width: 2.5; transition: stroke .12s; }
.conn-path:hover { stroke: var(--accent); }
.conn-hit { fill: none; stroke: transparent; stroke-width: 20; pointer-events: stroke; cursor: pointer; }
.conn-active { stroke: var(--accent); stroke-dasharray: 6 4; animation: dash 0.5s linear infinite; }
@keyframes dash { to { stroke-dashoffset: -10; } }

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--panel); }
::-webkit-scrollbar-thumb { background: #475569; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #64748b; }

/* ===== Palette item ===== */
.palette-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px; border-radius: 10px; cursor: grab;
  background: var(--panel); border: 1px solid var(--border);
  transition: all .12s; touch-action: manipulation;
}
.palette-item:hover { background: #334155; border-color: var(--accent); transform: translateX(2px); }
.palette-item:active { transform: scale(.97); }

/* ===== Toast ===== */
.toast {
  position: fixed; bottom: 20px; right: 20px; z-index: 2000;
  padding: 12px 18px; border-radius: 10px; font-size: 14px; font-weight: 500;
  box-shadow: 0 8px 30px rgba(0,0,0,.5);
  animation: slideIn .25s ease; max-width: calc(100vw - 40px);
}
@keyframes slideIn { from { transform: translateY(20px); opacity: 0;} to { transform: translateY(0); opacity: 1;} }

/* ===== Modal ===== */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.65); z-index: 1500; display: flex; align-items: center; justify-content: center; padding: 16px; backdrop-filter: blur(2px); }
.spin { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Inputs ===== */
input, select, textarea, button { font-family: inherit; }
.cfg-input {
  width: 100%; padding: 9px 11px; border-radius: 8px;
  background: #0f172a; border: 1px solid var(--border); color: var(--text); font-size: 14px;
}
.cfg-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px rgba(249,115,22,.15); }

/* ===== Buttons (touch-friendly min 40px) ===== */
.btn { min-height: 40px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.icon-btn { width: 40px; height: 40px; display: inline-flex; align-items: center; justify-content: center; border-radius: 10px; }

/* ===== Drawer overlay (mobile) ===== */
.drawer-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 39; opacity: 0; pointer-events: none; transition: opacity .2s; }
.drawer-overlay.show { opacity: 1; pointer-events: auto; }

/* line clamp */
.line-clamp-2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* ============================================================
   RESPONSIVE — Mobile / Tablet
   ============================================================ */

/* Palette as slide-in drawer on small screens */
@media (max-width: 1024px) {
  #palette-aside {
    position: fixed; top: 0; left: 0; bottom: 0;
    width: 270px; max-width: 82vw;
    transform: translateX(-105%);
    transition: transform .22s ease;
    z-index: 40;
    box-shadow: 8px 0 30px rgba(0,0,0,.5);
  }
  #palette-aside.open { transform: translateX(0); }

  /* Config panel becomes bottom sheet on mobile */
  #config-panel {
    position: fixed !important;
    left: 0; right: 0; bottom: 0;
    width: 100% !important;
    max-height: 70vh;
    border-left: none !important;
    border-top: 1px solid var(--border);
    border-radius: 18px 18px 0 0;
    transform: translateY(100%);
    transition: transform .25s ease;
    z-index: 45;
    box-shadow: 0 -8px 30px rgba(0,0,0,.5);
  }
  #config-panel.open { transform: translateY(0); }
}

/* Desktop config panel slides from right */
@media (min-width: 1025px) {
  #config-panel { transition: width .2s ease; }
}

/* Extra small phones */
@media (max-width: 480px) {
  .wf-node { width: 180px; }
  .toast { left: 16px; right: 16px; bottom: 16px; }
  .dash-title { font-size: 1.05rem; }
}

/* Make sure interactive controls are reachable above iOS safe areas */
.safe-bottom { padding-bottom: env(safe-area-inset-bottom, 0); }
.safe-top { padding-top: env(safe-area-inset-top, 0); }

/* Mobile FAB for palette */
#mobile-palette-fab {
  position: fixed; bottom: 18px; left: 18px; z-index: 30;
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--accent); color: white; font-size: 20px;
  box-shadow: 0 6px 20px rgba(249,115,22,.5);
  display: none; align-items: center; justify-content: center;
}
@media (max-width: 1024px) { #mobile-palette-fab { display: flex; } }

/* hide scrollbars on horizontal toolbars but keep scroll */
.no-scrollbar::-webkit-scrollbar { display: none; }
.no-scrollbar { -ms-overflow-style: none; scrollbar-width: none; }

/* ============================================================
   AI BUILDING ANIMATION — "AI khud bana raha hai" effect
   Full-screen blue pulse/scan + node reveal
   ============================================================ */

/* Overlay that covers the canvas while AI is building */
#ai-building-overlay {
  position: absolute; inset: 0; z-index: 25;
  pointer-events: none; opacity: 0;
  transition: opacity .35s ease;
  background:
    radial-gradient(circle at 50% 50%, rgba(59,130,246,.10), transparent 70%);
}
#ai-building-overlay.on { opacity: 1; }

/* Animated blue border glow around the whole canvas */
#ai-building-overlay::before {
  content: ''; position: absolute; inset: 0;
  border: 2px solid rgba(59,130,246,.0);
  border-radius: 12px;
  box-shadow: inset 0 0 0 0 rgba(59,130,246,0);
  animation: aiGlowPulse 1.6s ease-in-out infinite;
}
@keyframes aiGlowPulse {
  0%, 100% {
    border-color: rgba(59,130,246,.25);
    box-shadow: inset 0 0 40px 4px rgba(59,130,246,.10),
                inset 0 0 0 1px rgba(96,165,250,.30);
  }
  50% {
    border-color: rgba(96,165,250,.70);
    box-shadow: inset 0 0 90px 10px rgba(59,130,246,.28),
                inset 0 0 0 2px rgba(96,165,250,.70);
  }
}

/* Horizontal scan line sweeping top->bottom (the "lup lup" beam) */
#ai-building-overlay::after {
  content: ''; position: absolute; left: 0; right: 0; height: 140px;
  top: -140px;
  background: linear-gradient(180deg,
    transparent,
    rgba(59,130,246,.06) 30%,
    rgba(96,165,250,.22) 50%,
    rgba(59,130,246,.06) 70%,
    transparent);
  filter: blur(2px);
  animation: aiScan 2.2s linear infinite;
}
@keyframes aiScan {
  0%   { top: -140px; opacity: 0; }
  10%  { opacity: 1; }
  90%  { opacity: 1; }
  100% { top: 100%; opacity: 0; }
}

/* Floating "AI building" badge */
.ai-building-badge {
  position: absolute; top: 14px; left: 50%; transform: translateX(-50%);
  z-index: 26; pointer-events: none;
  display: flex; align-items: center; gap: 8px;
  padding: 8px 16px; border-radius: 999px;
  background: rgba(15,23,42,.85); backdrop-filter: blur(8px);
  border: 1px solid rgba(96,165,250,.5);
  color: #bfdbfe; font-size: 12px; font-weight: 600;
  box-shadow: 0 4px 24px rgba(59,130,246,.35);
  animation: aiBadgePulse 1.4s ease-in-out infinite;
}
@keyframes aiBadgePulse {
  0%,100% { box-shadow: 0 4px 24px rgba(59,130,246,.30); }
  50%     { box-shadow: 0 4px 38px rgba(59,130,246,.65); }
}
.ai-building-badge .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: #60a5fa; box-shadow: 0 0 10px #60a5fa;
  animation: aiDotBlink .9s ease-in-out infinite;
}
@keyframes aiDotBlink { 0%,100% { opacity: .35; } 50% { opacity: 1; } }

/* While building, give the whole canvas wrap a subtle blue tint */
#canvas-wrap.ai-building { background:
  radial-gradient(circle at 50% 40%, rgba(30,58,138,.18), transparent 60%); }

/* Each freshly-added node pops in with a blue flash */
.wf-node.ai-spawn {
  animation: aiNodeSpawn .55s cubic-bezier(.18,.89,.32,1.28) both;
}
@keyframes aiNodeSpawn {
  0%   { transform: scale(.6); opacity: 0; filter: drop-shadow(0 0 0 rgba(96,165,250,0)); }
  60%  { transform: scale(1.06); opacity: 1; filter: drop-shadow(0 0 14px rgba(96,165,250,.9)); }
  100% { transform: scale(1); opacity: 1; filter: drop-shadow(0 0 0 rgba(96,165,250,0)); }
}

/* Connections draw-in animation */
.conn-path.ai-draw {
  stroke-dasharray: 600; stroke-dashoffset: 600;
  animation: aiConnDraw .7s ease-out forwards;
}
@keyframes aiConnDraw { to { stroke-dashoffset: 0; } }

/* Typing dots inside chat while AI works */
.ai-typing span {
  display: inline-block; width: 6px; height: 6px; margin: 0 1px;
  border-radius: 50%; background: #94a3b8;
  animation: aiTyping 1.2s infinite;
}
.ai-typing span:nth-child(2) { animation-delay: .2s; }
.ai-typing span:nth-child(3) { animation-delay: .4s; }
@keyframes aiTyping { 0%,60%,100% { transform: translateY(0); opacity:.4;} 30% { transform: translateY(-4px); opacity:1;} }
