/* ========================================
   FLOWBOARD — Visual Agent Board Editor
   ======================================== */

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #080810;
  --surface: #0f0f1a;
  --surface-hover: #151525;
  --border: #1a1a2e;
  --border-light: #252540;
  --green: #00e87b;
  --green-dim: rgba(0, 232, 123, 0.15);
  --purple: #8b5cf6;
  --purple-dim: rgba(139, 92, 246, 0.15);
  --amber: #f59e0b;
  --amber-dim: rgba(245, 158, 11, 0.15);
  --pink: #ec4899;
  --pink-dim: rgba(236, 72, 153, 0.15);
  --text: #e2e8f0;
  --text-secondary: #94a3b8;
  --muted: #64748b;
  --danger: #ef4444;
  --tile-w: 180px;
  --tile-h: 72px;
  --port-r: 7px;
  --topbar-h: 52px;
  --sidebar-w: 200px;
}

body {
  font-family: 'DM Sans', sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 {
  font-family: 'Space Grotesk', sans-serif;
  line-height: 1.1;
}

/* ========== LANDING HERO ========== */

.landing-hero {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.hero-content {
  max-width: 600px;
  padding: 24px;
}

.logo-large {
  font-size: 1.8rem;
  justify-content: center;
  margin-bottom: 32px;
}

.logo-icon-lg {
  width: 40px;
  height: 40px;
}

.hero-title {
  font-size: clamp(2rem, 5vw, 3.2rem);
  font-weight: 700;
  margin-bottom: 16px;
  letter-spacing: -0.02em;
}

.gradient-text {
  background: linear-gradient(135deg, var(--green), var(--purple));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.hero-sub {
  color: var(--muted);
  font-size: 1.1rem;
  margin-bottom: 32px;
  line-height: 1.7;
}

.btn-hero {
  background: linear-gradient(135deg, var(--green), #00c868);
  color: #080810;
  font-weight: 700;
  font-size: 1.05rem;
  padding: 14px 36px;
  border-radius: 12px;
  border: none;
  cursor: pointer;
  transition: all 0.2s;
  font-family: 'Space Grotesk', sans-serif;
}

.btn-hero:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 30px rgba(0, 232, 123, 0.25);
}

.btn-hero .arrow {
  display: inline-block;
  transition: transform 0.2s;
}

.btn-hero:hover .arrow {
  transform: translateX(4px);
}

.hero-tiles {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 40px;
  flex-wrap: wrap;
}

.hero-chip {
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.chip-green { background: var(--green-dim); color: var(--green); border: 1px solid rgba(0,232,123,0.2); }
.chip-amber { background: var(--amber-dim); color: var(--amber); border: 1px solid rgba(245,158,11,0.2); }
.chip-purple { background: var(--purple-dim); color: var(--purple); border: 1px solid rgba(139,92,246,0.2); }
.chip-pink { background: var(--pink-dim); color: var(--pink); border: 1px solid rgba(236,72,153,0.2); }

/* ========== LOGO ========== */

.logo {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.15rem;
  font-weight: 700;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 10px;
  user-select: none;
}

.logo-icon {
  width: 28px;
  height: 28px;
  background: linear-gradient(135deg, var(--green), var(--purple));
  border-radius: 6px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 2px;
  padding: 4px;
  flex-shrink: 0;
}

.logo-icon span { border-radius: 2px; }
.logo-icon span:nth-child(1) { background: rgba(255,255,255,0.9); }
.logo-icon span:nth-child(2) { background: rgba(255,255,255,0.4); }
.logo-icon span:nth-child(3) { background: rgba(255,255,255,0.4); }
.logo-icon span:nth-child(4) { background: rgba(255,255,255,0.9); }

/* ========== TOPBAR ========== */

.topbar {
  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: 50;
  flex-shrink: 0;
}

.topbar-left, .topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 160px;
}

.topbar-right { justify-content: flex-end; }

.topbar-center {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ========== BUTTONS ========== */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-family: 'DM Sans', sans-serif;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.btn:hover { background: var(--surface-hover); border-color: var(--border-light); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn:disabled:hover { background: var(--surface); border-color: var(--border); }

.btn-simulate {
  background: var(--green-dim);
  border-color: rgba(0,232,123,0.25);
  color: var(--green);
}
.btn-simulate:hover:not(:disabled) {
  background: rgba(0,232,123,0.2);
  border-color: rgba(0,232,123,0.4);
}

.btn-step {
  background: var(--purple-dim);
  border-color: rgba(139,92,246,0.25);
  color: var(--purple);
}
.btn-step:hover { background: rgba(139,92,246,0.2); }

.btn-stop {
  background: rgba(239,68,68,0.1);
  border-color: rgba(239,68,68,0.25);
  color: var(--danger);
}
.btn-stop:hover { background: rgba(239,68,68,0.2); }

.btn-ghost {
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}
.btn-ghost:hover { color: var(--text); background: var(--surface-hover); }

.btn-primary {
  background: var(--green);
  border-color: var(--green);
  color: #080810;
  font-weight: 600;
}
.btn-primary:hover { background: #00d06e; }

.btn-icon {
  padding: 6px 8px;
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}
.btn-icon:hover { color: var(--text); background: var(--surface-hover); }

.sim-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  border-radius: 8px;
  background: var(--green-dim);
  color: var(--green);
  font-size: 0.82rem;
  font-weight: 600;
}

.sim-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  animation: pulse-dot 1s ease-in-out infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.8); }
}

/* ========== APP LAYOUT ========== */

.app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.app-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ========== SIDEBAR ========== */

.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex-shrink: 0;
  overflow-y: auto;
}

.sidebar-section { display: flex; flex-direction: column; gap: 8px; }

.sidebar-title {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  padding: 0 4px;
}

.sidebar-divider {
  height: 1px;
  background: var(--border);
  margin: 12px 0;
}

.palette { display: flex; flex-direction: column; gap: 4px; }

.palette-tile {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 10px;
  border-radius: 8px;
  cursor: grab;
  transition: all 0.15s;
  font-size: 0.88rem;
  font-weight: 500;
  user-select: none;
  border: 1px solid transparent;
}

.palette-tile:hover {
  background: var(--surface-hover);
  border-color: var(--border);
}

.palette-tile:active { cursor: grabbing; }

.palette-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: color-mix(in srgb, var(--tile-color) 12%, transparent);
  color: var(--tile-color);
  flex-shrink: 0;
  border: 1px solid color-mix(in srgb, var(--tile-color) 20%, transparent);
}

.sidebar-help {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.4;
}

.sidebar-help kbd {
  display: inline;
  font-family: 'DM Sans', sans-serif;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
}

/* ========== BOARD ========== */

.board-container {
  flex: 1;
  overflow: auto;
  position: relative;
  background: var(--bg);
}

.board {
  width: 4000px;
  height: 3000px;
  position: relative;
  background-image: radial-gradient(circle, var(--border) 1px, transparent 1px);
  background-size: 24px 24px;
}

.connections-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
}

.connection-path {
  fill: none;
  stroke: var(--muted);
  stroke-width: 2;
  marker-end: url(#arrowhead);
  transition: stroke 0.3s, stroke-width 0.3s;
  pointer-events: stroke;
  cursor: pointer;
}

.connection-path:hover {
  stroke: var(--text-secondary);
  stroke-width: 2.5;
}

.connection-path.selected {
  stroke: var(--danger);
  stroke-width: 2.5;
  stroke-dasharray: 6 3;
}

.connection-path.sim-active {
  stroke: var(--green);
  stroke-width: 3;
  marker-end: url(#arrowhead-active);
  filter: drop-shadow(0 0 6px rgba(0, 232, 123, 0.5));
  stroke-dasharray: 8 4;
  animation: flow-dash 0.6s linear infinite;
}

@keyframes flow-dash {
  to { stroke-dashoffset: -12; }
}

/* ========== BOARD TILES ========== */

.tile {
  position: absolute;
  width: var(--tile-w);
  height: var(--tile-h);
  border-radius: 12px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  cursor: grab;
  z-index: 2;
  transition: box-shadow 0.2s, border-color 0.2s, transform 0.1s;
  user-select: none;
}

.tile:hover {
  border-color: var(--border-light);
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}

.tile:active { cursor: grabbing; }

.tile.selected {
  border-color: var(--green);
  box-shadow: 0 0 0 2px var(--green-dim), 0 4px 20px rgba(0,0,0,0.3);
}

.tile.sim-active {
  border-color: var(--green);
  box-shadow: 0 0 0 3px var(--green-dim), 0 0 30px rgba(0, 232, 123, 0.3);
  animation: tile-pulse 0.8s ease-in-out infinite;
  z-index: 10;
}

@keyframes tile-pulse {
  0%, 100% { box-shadow: 0 0 0 3px var(--green-dim), 0 0 30px rgba(0, 232, 123, 0.3); }
  50% { box-shadow: 0 0 0 5px var(--green-dim), 0 0 50px rgba(0, 232, 123, 0.5); }
}

.tile-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 0.9rem;
}

.tile-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.tile-label {
  font-weight: 600;
  font-size: 0.85rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tile-type {
  font-size: 0.7rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 500;
}

/* Tile type colors */
.tile.type-agent .tile-icon { background: var(--green-dim); color: var(--green); border: 1px solid rgba(0,232,123,0.2); }
.tile.type-decision .tile-icon { background: var(--amber-dim); color: var(--amber); border: 1px solid rgba(245,158,11,0.2); }
.tile.type-handoff .tile-icon { background: var(--purple-dim); color: var(--purple); border: 1px solid rgba(139,92,246,0.2); }
.tile.type-checkpoint .tile-icon { background: var(--pink-dim); color: var(--pink); border: 1px solid rgba(236,72,153,0.2); }

.tile.type-agent.selected { border-color: var(--green); box-shadow: 0 0 0 2px var(--green-dim); }
.tile.type-decision.selected { border-color: var(--amber); box-shadow: 0 0 0 2px var(--amber-dim); }
.tile.type-handoff.selected { border-color: var(--purple); box-shadow: 0 0 0 2px var(--purple-dim); }
.tile.type-checkpoint.selected { border-color: var(--pink); box-shadow: 0 0 0 2px var(--pink-dim); }

/* ========== PORTS ========== */

.port {
  position: absolute;
  width: calc(var(--port-r) * 2);
  height: calc(var(--port-r) * 2);
  border-radius: 50%;
  background: var(--surface);
  border: 2px solid var(--muted);
  cursor: crosshair;
  z-index: 5;
  transition: all 0.15s;
  transform: translate(-50%, -50%);
}

.port:hover {
  border-color: var(--green);
  background: var(--green-dim);
  transform: translate(-50%, -50%) scale(1.3);
}

.port-in { left: 0; top: 50%; }
.port-out { left: 100%; top: 50%; }

/* Decision tiles get extra output ports */
.tile.type-decision .port-out-yes { left: 100%; top: 33%; }
.tile.type-decision .port-out-no { left: 100%; top: 67%; }
.tile.type-decision .port-out-yes::after,
.tile.type-decision .port-out-no::after {
  content: attr(data-label);
  position: absolute;
  left: calc(100% + 4px);
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.6rem;
  color: var(--muted);
  white-space: nowrap;
  pointer-events: none;
}

.port.connecting {
  border-color: var(--green);
  background: var(--green);
  transform: translate(-50%, -50%) scale(1.4);
}

/* ========== EMPTY STATE ========== */

.empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  pointer-events: none;
  z-index: 0;
}

.empty-state h3 {
  font-size: 1.1rem;
  color: var(--text-secondary);
}

.empty-state p {
  font-size: 0.9rem;
  color: var(--muted);
}

.empty-state.hidden { display: none; }

/* ========== MODAL ========== */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 8, 16, 0.8);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  width: 340px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.modal h3 {
  font-size: 1rem;
}

.modal-input {
  width: 100%;
  padding: 10px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-family: 'DM Sans', sans-serif;
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.15s;
}

.modal-input:focus {
  border-color: var(--green);
}

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

/* ========== DRAG GHOST ========== */

.drag-ghost {
  position: fixed;
  width: var(--tile-w);
  height: var(--tile-h);
  border-radius: 12px;
  background: var(--surface);
  border: 1.5px dashed var(--green);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  pointer-events: none;
  z-index: 500;
  opacity: 0.85;
  box-shadow: 0 8px 30px rgba(0,0,0,0.5);
}

/* ========== TEMP CONNECTION ========== */

.temp-connection {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 400;
}

/* ========== SCROLLBAR ========== */

.board-container::-webkit-scrollbar { width: 8px; height: 8px; }
.board-container::-webkit-scrollbar-track { background: var(--bg); }
.board-container::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
.board-container::-webkit-scrollbar-thumb:hover { background: var(--border-light); }
.board-container::-webkit-scrollbar-corner { background: var(--bg); }

/* ========== RESPONSIVE ========== */

@media (max-width: 768px) {
  .sidebar { width: 60px; padding: 8px; }
  .palette-tile span { display: none; }
  .palette-tile { justify-content: center; padding: 8px; }
  .sidebar-title, .sidebar-help, .sidebar-divider { display: none; }
  .topbar-left .logo span:not(.logo-icon) { display: none; }
}

/* ========== CONTEXT MENU ========== */

.context-menu {
  position: fixed;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px;
  z-index: 300;
  min-width: 160px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.5);
}

.context-menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 0.85rem;
  cursor: pointer;
  color: var(--text);
  transition: background 0.1s;
}

.context-menu-item:hover { background: var(--surface-hover); }
.context-menu-item.danger { color: var(--danger); }
.context-menu-item.danger:hover { background: rgba(239,68,68,0.1); }
