/* ==========================================================================
   FLWFLW — Design System
   Brand: warm gold (#f59e0b family) on a clean slate canvas.
   Themes: light (default), dark, lava — driven by classes on <html>.
   ========================================================================== */

:root {
  --font-family: 'Inter', system-ui, -apple-system, sans-serif;

  /* Brand */
  --brand: #f59e0b;
  --brand-2: #fbbf24;
  --brand-strong: #d97706;
  --accent-violet: #8b5cf6;
  --accent-green: #10b981;

  /* Semantic palette */
  --primary: #d97706;
  --primary-hover: #b45309;
  --primary-rgb: 217, 119, 6;
  --danger: #ef4444;
  --danger-hover: #dc2626;

  /* Surfaces & text */
  --bg-color: #f5f6f8;
  --grid-color: #e4e8ef;
  --text-color: #0f172a;
  --text: var(--text-color);
  --text-muted: #64748b;
  --card-bg: #ffffff;
  --surface: #f8fafc;
  --surface-1: #ffffff;
  --surface-2: #eef1f6;
  --divider: #e2e8f0;
  --border: var(--divider);
  --input-bg: #ffffff;
  --edge-color: #64748b;

  /* Notes */
  --note-bg: #fef9c3;
  --note-border: #fde047;

  /* Chrome */
  --toolbar-bg: rgba(255, 255, 255, 0.82);
  --modal-overlay: rgba(15, 23, 42, 0.45);

  /* Shape & elevation */
  --border-radius: 9.6px;
  --shadow-sm: 0 1px 2px 0 rgb(15 23 42 / 0.06);
  --shadow-md: 0 3.2px 4.8px -1px rgb(15 23 42 / 0.08), 0 2px 3.2px -2px rgb(15 23 42 / 0.06);
  --shadow-lg: 0 8px 12px -3px rgb(15 23 42 / 0.10), 0 3.2px 4.8px -4px rgb(15 23 42 / 0.08);
  --shadow-xl: 0 19.2px 38.4px -12px rgb(15 23 42 / 0.25);

  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
}

/* ---------- Dark theme ---------- */
:root.dark-mode {
  --primary: #f59e0b;
  --primary-hover: #fbbf24;
  --primary-rgb: 245, 158, 11;

  --bg-color: #0b1120;
  --grid-color: rgba(148, 163, 184, 0.09);
  --text-color: #e6ecf5;
  --text-muted: #8fa0b8;
  --card-bg: #141d2e;
  --surface: #101828;
  --surface-1: #18223a;
  --surface-2: #1f2b45;
  --divider: #263451;
  --input-bg: rgba(255, 255, 255, 0.04);
  --edge-color: #7d8fb0;
  --toolbar-bg: rgba(11, 17, 32, 0.82);
  --edge-color: #7d8fb0;

  --note-bg: #3d3618;
  --note-border: #8a6d1d;

  --toolbar-bg: rgba(11, 17, 32, 0.82);
  --modal-overlay: rgba(2, 6, 16, 0.62);

  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.4);
  --shadow-md: 0 3.2px 6.4px -1px rgb(0 0 0 / 0.5);
  --shadow-lg: 0 9.6px 19.2px -6px rgb(0 0 0 / 0.55);
  --shadow-xl: 0 22.4px 44.8px -12px rgb(0 0 0 / 0.7);
}
:root.dark-mode .btn-primary,
:root.dark-mode .tb-btn-export {
  color: #201502;
}
:root.dark-mode .btn-primary:hover { color: #201502; }

/* ---------- Lava theme ---------- */
:root.lava-mode {
  --primary: #fb923c;
  --primary-hover: #f97316;
  --primary-rgb: 251, 146, 60;
  --brand: #fb923c;

  --bg-color: #160606;
  --grid-color: rgba(251, 146, 60, 0.07);
  --text-color: #ffe9dc;
  --text-muted: #d99a7e;
  --card-bg: #261009;
  --surface: #1d0b07;
  --surface-1: #2e130a;
  --surface-2: #3a1a0d;
  --divider: #4a2110;
  --input-bg: rgba(255, 255, 255, 0.04);
  --edge-color: #fb923c;

  --note-bg: #3a1a0d;
  --note-border: #7c2d12;

  --toolbar-bg: rgba(26, 9, 5, 0.85);
  --modal-overlay: rgba(8, 2, 2, 0.7);

  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.5);
  --shadow-md: 0 3.2px 6.4px -1px rgb(0 0 0 / 0.55);
  --shadow-lg: 0 9.6px 19.2px -6px rgb(0 0 0 / 0.6);
  --shadow-xl: 0 22.4px 44.8px -12px rgb(0 0 0 / 0.75);
}

/* ==========================================================================
   Base
   ========================================================================== */
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font-family);
  background-color: var(--bg-color);
  color: var(--text-color);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: background-color 0.3s, color 0.3s;
  -webkit-font-smoothing: antialiased;
}
::selection { background: rgba(var(--primary-rgb), 0.25); }
* { scrollbar-width: thin; scrollbar-color: var(--divider) transparent; }
*::-webkit-scrollbar { width: 6.4px; height: 6.4px; }
*::-webkit-scrollbar-thumb { background: var(--divider); border-radius: 6.4px; }
*::-webkit-scrollbar-track { background: transparent; }

button, select {
  font-family: var(--font-family);
  font-size: 0.68rem;
  font-weight: 500;
  padding: 4.8px 9.6px;
  border: 1px solid var(--divider);
  border-radius: 4.8px;
  background: var(--card-bg);
  color: var(--text-color);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 3.2px;
  transition: all 0.2s;
}
button:hover { background: var(--surface-2); }
button:focus-visible, select:focus-visible, a:focus-visible {
  outline: 2px solid rgba(var(--primary-rgb), 0.6);
  outline-offset: 1px;
}

select:hover { background: var(--input-bg); }

.btn-primary { background: var(--primary); color: #fff; border-color: transparent; font-weight: 600; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { background: var(--danger); color: #fff; border-color: transparent; }
.btn-danger:hover { background: var(--danger-hover); }
.btn-gradient {
  background: linear-gradient(45deg, #ec4899, #8b5cf6, #3b82f6);
  color: #fff;
  border: none;
  font-weight: 600;
}
.btn-gradient:hover { opacity: 0.92; background: linear-gradient(45deg, #ec4899, #8b5cf6, #3b82f6) !important; color: #fff !important; }
.btn-note { background: var(--note-bg) !important; color: #854d0e !important; border-color: var(--note-border) !important; }
.btn-ghost {
  background: transparent;
  border: 1px solid var(--divider);
  color: var(--text-color);
}
.btn-ghost:hover { background: var(--surface-2); }
.btn-text {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-weight: 600;
}
.btn-text:hover { background: transparent; color: var(--text-color); }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* ==========================================================================
   Lava mode ambience
   ========================================================================== */
@keyframes lavaFlow {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}
:root.lava-mode body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 50% at 20% -10%, rgba(249, 115, 22, 0.18), transparent 60%),
    radial-gradient(ellipse 60% 40% at 85% 110%, rgba(239, 68, 68, 0.15), transparent 60%),
    linear-gradient(-45deg, #160606, #2a0d08, #160606, #331008);
  background-size: 100% 100%, 100% 100%, 400% 400%;
  animation: lavaFlow 18s ease infinite;
  z-index: -1;
  pointer-events: none;
}
:root.lava-mode .edge-path-visible {
  stroke: url(#lavaGradient);
  filter: drop-shadow(0 0 4px #f97316);
  animation: lavaPulse 2s infinite alternate;
}
@keyframes lavaPulse {
  from { filter: drop-shadow(0 0 2px #f97316); }
  to { filter: drop-shadow(0 0 6.4px #fef08a); }
}
:root.lava-mode .brand { text-shadow: 0 0 14.4px rgba(251, 146, 60, 0.45); }
/* Keep text legible on the bright orange primary in lava mode */
:root.lava-mode .btn-primary,
:root.lava-mode .btn-primary:hover,
:root.lava-mode .pricing-btn,
:root.lava-mode .chat-msg.user,
:root.lava-mode .domain-badge,
:root.lava-mode .tb-btn-export,
:root.lava-mode .account-btn-guest,
:root.lava-mode .action-chip:hover,
:root.lava-mode .domain-actions button:hover { color: #2a1005; }

/* ==========================================================================
   Toolbar
   ========================================================================== */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 9.6px;
  padding: 6.4px 12.8px;
  background: var(--toolbar-bg);
  backdrop-filter: blur(11.2px);
  -webkit-backdrop-filter: blur(11.2px);
  border-bottom: 1px solid var(--divider);
  box-shadow: 0 1px 0 rgba(15, 23, 42, 0.02), 0 6.4px 19.2px -14.8px rgba(15, 23, 42, 0.25);
  position: relative;
  z-index: 10000;
  flex-shrink: 0;
}
.tb-group { display: flex; align-items: center; gap: 8px; min-width: 0; }
.tb-left { flex: 1 1 auto; flex-wrap: wrap; row-gap: 4.8px; }
.tb-right {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding-left: 8px;
  border-left: 1px solid var(--divider);
}
.tb-right .tb-primary {
  margin-right: 4px;
  padding-right: 8px;
  border-right: 1px solid var(--divider);
}

.brand {
  font-family: 'Yellowtail', cursive;
  font-weight: 400;
  font-size: 1.4rem;
  line-height: 1;
  color: var(--brand);
  cursor: pointer;
  padding: 2px 3.2px 4.8px;
  user-select: none;
  transition: transform 0.2s var(--ease-out);
}
.brand:hover { transform: scale(1.04) rotate(-1deg); }

.tb-name { position: relative; display: flex; align-items: center; }
.tb-name input {
  font-family: var(--font-family);
  font-weight: 500;
  font-size: 0.72rem;
  width: 128px;
  padding: 4.8px 22.4px 4.8px 8px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6.4px;
  color: var(--text-color);
  cursor: pointer;
  transition: all 0.2s;
}
.tb-name input:hover { border-color: var(--divider); background: var(--surface-1); }
.tb-name input:focus { border-color: var(--primary); background: var(--surface-1); outline: none; cursor: text; }
.tb-name-icon {
  position: absolute;
  right: 7.2px;
  pointer-events: none;
  color: var(--text-muted);
  opacity: 0.7;
}

/* Primary actions (right cluster) */
.tb-primary {
  display: flex;
  align-items: center;
  gap: 6.4px;
}
.tb-btn {
  display: inline-flex;
  align-items: center;
  gap: 5.6px;
  padding: 6.4px 11.2px;
  border: none;
  border-radius: 8px;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.008em;
  color: #fff;
  cursor: pointer;
  transition: transform 0.15s var(--ease-out), box-shadow 0.2s, filter 0.2s;
  white-space: nowrap;
}
.tb-btn:hover { transform: translateY(-1px); filter: brightness(1.06); }
.tb-btn:active { transform: translateY(0) scale(0.98); }
.tb-btn-add {
  background: transparent;
  border: 1.5px solid var(--primary);
  color: var(--primary);
  box-shadow: none;
}
.tb-btn-add:hover {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 3.2px 9.6px -4px rgba(217, 119, 6, 0.5);
}
:root.dark-mode .tb-btn-add:hover { color: #201502; }
.tb-btn-vibe {
  background: linear-gradient(135deg, #a855f7, #7c3aed);
  box-shadow: 0 3.2px 9.6px -4px rgba(139, 92, 246, 0.5);
}
.tb-btn-export {
  background: linear-gradient(135deg, var(--brand-2), var(--brand-strong));
  box-shadow: 0 3.2px 11.2px -4px rgba(217, 119, 6, 0.55);
  color: #fff;
}
:root.dark-mode .tb-btn-export { color: #241503; }

/* Secondary menus */
.tb-menus { display: flex; align-items: center; gap: 4.8px; flex-wrap: wrap; }

/* Ghost + icon buttons (left cluster) */
.tb-ghost-btn {
  display: inline-flex;
  align-items: center;
  gap: 4.8px;
  padding: 5.6px 9.6px;
  border: 1px solid var(--divider);
  border-radius: 8px;
  background: transparent;
  color: var(--text-color);
  font-weight: 600;
  font-size: 0.656rem;
  transition: all 0.2s;
}
.tb-ghost-btn:hover { background: var(--surface-2); border-color: var(--text-muted); }
.tb-icon-btn {
  width: 27.2px;
  height: 27.2px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--divider);
  border-radius: 8px;
  background: transparent;
  color: var(--text-color);
  transition: all 0.2s;
}
.tb-icon-btn:hover { background: var(--surface-2); border-color: var(--text-muted); }

.account-btn {
  border-radius: 799.2px;
  padding: 3.2px 9.6px 3.2px 4px;
  gap: 6.4px;
  background: var(--surface-1);
  border: 1px solid var(--divider);
  box-shadow: var(--shadow-sm);
}
.account-avatar {
  width: 20.8px;
  height: 20.8px;
  background: linear-gradient(135deg, var(--brand-2), var(--brand-strong));
  color: #fff;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.64rem;
  font-weight: 700;
}
.account-name { font-weight: 600; font-size: 0.704rem; }
.account-btn-guest {
  background: linear-gradient(135deg, var(--brand-2), var(--brand-strong));
  color: #fff;
  border: none;
  padding: 5.6px 12.8px;
  font-weight: 700;
  box-shadow: 0 3.2px 9.6px -4px rgba(217, 119, 6, 0.5);
}
.account-btn-guest:hover { filter: brightness(1.06); background: linear-gradient(135deg, var(--brand-2), var(--brand-strong)); }
:root.dark-mode .account-btn-guest { color: #241503; }

/* ==========================================================================
   Dropdowns (JS hover-intent driven — see app.js initDropdowns)
   ========================================================================== */
.dropdown { position: relative; display: inline-block; }
.dropbtn {
  display: inline-flex;
  align-items: center;
  gap: 4.8px;
  padding: 5.6px 8.8px;
  font-size: 0.664rem;
  font-weight: 600;
  color: var(--text-color);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.18s;
  white-space: nowrap;
}
.dropbtn .chevron { transition: transform 0.2s var(--ease-out); opacity: 0.6; }
.dropbtn:hover { background: var(--surface-2); }
.dropdown.open .dropbtn { background: var(--surface-2); border-color: var(--divider); }
.dropdown.open .dropbtn .chevron { transform: rotate(180deg); }

.dropdown-content {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  margin-top: 4.8px;
  min-width: 152px;
  max-height: min(384px, calc(100vh - 72px));
  overflow-y: auto;
  background: var(--card-bg);
  border: 1px solid var(--divider);
  border-radius: 9.6px;
  box-shadow: var(--shadow-xl);
  padding: 4.8px;
  z-index: 1000;
}
.dropdown.open .dropdown-content {
  display: block;
  animation: dropdownIn 0.18s var(--ease-out);
}
@keyframes dropdownIn {
  from { opacity: 0; transform: translateY(-6px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.dropdown-content a {
  display: flex;
  align-items: center;
  gap: 7.2px;
  color: var(--text-color);
  padding: 6.4px 8px;
  text-decoration: none;
  font-size: 0.68rem;
  font-weight: 500;
  border-radius: 6.4px;
  cursor: pointer;
  transition: background 0.12s;
}
.dropdown-content a svg { flex-shrink: 0; color: var(--text-muted); }
.dropdown-content a:hover { background: var(--surface-2); }
.dropdown-content a:hover svg { color: var(--text-color); }
.dropdown-content a .beta-badge { margin-left: auto; }
.dropdown-item-label { display: inline-flex; align-items: center; gap: 7.2px; }
.dropdown-item-disabled {
  color: var(--text-muted) !important;
  cursor: not-allowed !important;
}
.dropdown-hint {
  margin-left: auto;
  font-size: 0.56rem;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--surface-2);
  padding: 2px 5.6px;
  border-radius: 799.2px;
}
.dropdown-divider { height: 1px; background: var(--divider); margin: 4px 3.2px; }
.dropdown-load-row {
  position: relative;
  display: flex;
  gap: 4.8px;
  align-items: center;
  padding: 3.2px 3.2px 6.4px;
  border-bottom: 1px solid var(--divider);
  margin-bottom: 3.2px;
}
.dropdown-load-row select {
  width: 100%;
  padding: 5.6px 6.4px 5.6px 22.4px;
  border-radius: 6.4px;
  border: 1px solid var(--divider);
  background: var(--input-bg);
  color: var(--text-color);
  font-size: 0.656rem;
}
.dropdown-load-row select:disabled { color: var(--text-muted); cursor: not-allowed; }
.dropdown-load-icon {
  position: absolute;
  left: 11.2px;
  top: 50%;
  transform: translateY(calc(-50% - 2px));
  color: var(--text-muted);
  pointer-events: none;
  z-index: 1;
}
.dropdown-manage-btn {
  padding: 5.6px;
  border-radius: 6.4px;
  border: 1px solid var(--divider);
  background: transparent;
  color: var(--text-muted);
  flex-shrink: 0;
}
.dropdown-manage-btn:hover { color: var(--text-color); background: var(--surface-2); }

.beta-badge {
  background: #ef4444;
  color: #fff;
  font-size: 0.48rem;
  font-weight: 700;
  padding: 2px 4.8px;
  border-radius: 6.4px;
  letter-spacing: 0.04em;
}
.beta-badge-muted { background: var(--divider); color: var(--text-muted); }

.btn-delete-workflow { padding: 4.8px; }

/* ==========================================================================
   Workspace / Canvas
   ========================================================================== */
.workspace-container { flex: 1; position: relative; overflow: hidden; cursor: grab; }
.workspace-container.panning { cursor: grabbing; }
.grid-bg {
  position: absolute;
  top: -10000px; left: -10000px; right: -10000px; bottom: -10000px;
  background-image: linear-gradient(var(--grid-color) 1px, transparent 1px), linear-gradient(90deg, var(--grid-color) 1px, transparent 1px);
  background-size: 19.2px 19.2px;
  pointer-events: none;
  z-index: 0;
}
.workspace { position: absolute; top: 0; left: 0; transform-origin: 0 0; }
.empty-state {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  color: var(--text-muted);
  pointer-events: none;
  z-index: 5;
}

/* SVG Edges */
.edges-layer {
  position: absolute;
  top: -50000px;
  left: -50000px;
  width: 100000px;
  height: 100000px;
  pointer-events: none;
  overflow: visible;
  z-index: 10;
}
.edge-group { pointer-events: visibleStroke; cursor: pointer; }
.edge-path-hitbox { stroke: transparent; stroke-width: 20px; fill: none; }
.edge-path-visible {
  stroke: var(--edge-color);
  stroke-width: 2.4px;
  fill: none;
  transition: stroke 0.2s, stroke-width 0.2s;
}
.edge-group:hover .edge-path-visible { stroke: var(--danger); stroke-width: 3.2px; }
.temp-edge {
  stroke: var(--text-muted);
  stroke-width: 2px;
  stroke-dasharray: 5, 5;
  fill: none;
  pointer-events: none;
}

/* Node Cards */
.node {
  position: absolute;
  width: 320px;
  min-width: 200px;
  min-height: 120px;
  background: var(--card-bg);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow-md);
  transition: box-shadow 0.2s, background-color 0.3s, border 0.2s, transform 0.2s;
  display: flex;
  flex-direction: column;
  z-index: 20;
  overflow: visible;
  border: 2px solid transparent;
}
.node:hover { box-shadow: var(--shadow-lg); }
.node.note {
  width: 360px;
  background: var(--note-bg);
  border: 1px solid var(--note-border);
  border-radius: var(--border-radius) 0 var(--border-radius) var(--border-radius);
}
.node.note::after {
  content: '';
  position: absolute;
  bottom: 0;
  right: 0;
  border-width: 9.6px;
  border-style: solid;
  border-color: var(--note-border) transparent transparent var(--note-border);
  border-radius: 0 0 0 var(--border-radius);
}
.node-header {
  padding: 9.6px 12.8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px dashed var(--divider);
  cursor: grab;
  position: relative;
}
.domain-badge {
  position: absolute;
  top: -10px;
  left: 12.8px;
  background: var(--primary);
  color: #fff;
  font-size: 0.52rem;
  padding: 2px 4.8px;
  border-radius: 6.4px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  pointer-events: none;
}
:root.dark-mode .domain-badge { color: #201502; }
.node-header input {
  font-family: var(--font-family);
  font-weight: 600;
  font-size: 0.8rem;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-color);
  flex: 1;
  padding: 2px 3.2px;
  margin-right: 6.4px;
}
.node-header input:focus { border-bottom-color: var(--primary); outline: none; }
.node-actions { display: flex; gap: 3.2px; }
.node-actions button {
  padding: 2px 3.2px;
  font-size: 0.8rem;
  border: none;
  background: transparent;
  border-radius: 3.2px;
}
.node-actions button:hover { background: var(--bg-color); }
.node-body {
  padding: 12.8px;
  display: flex;
  flex-direction: column;
  gap: 9.6px;
  flex: 1;
}
.node-body label {
  font-size: 0.6rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.tools-input {
  width: 100%;
  padding: 6.4px;
  border: 1px solid var(--divider);
  border-radius: 4.8px;
  background: var(--input-bg);
  color: var(--text-color);
  font-family: var(--font-family);
}
.rules-header { display: flex; justify-content: space-between; align-items: center; }
.btn-add-rule {
  font-size: 0.6rem;
  padding: 2px 4.8px;
  border: none;
  background: var(--bg-color);
  color: var(--primary);
  border-radius: 3.2px;
  cursor: pointer;
}
.btn-add-rule:hover { background: var(--divider); }
.rules-list { display: flex; flex-direction: column; gap: 6.4px; }
.rule-row { display: flex; gap: 6.4px; align-items: flex-start; }
.rule-row textarea {
  flex: 1;
  resize: none;
  overflow: hidden;
  min-height: 28.8px;
  padding: 6.4px;
  border: 1px solid var(--divider);
  border-radius: 4.8px;
  font-family: var(--font-family);
  font-size: 0.68rem;
  background: var(--input-bg);
  color: var(--text-color);
}
.node.note .rule-row textarea { border: none; background: transparent; min-height: 96px; padding: 0; }
.node.note .rule-row textarea:focus { outline: none; }
.btn-delete-rule {
  background: transparent;
  border: none;
  color: var(--danger);
  font-size: 0.8rem;
  cursor: pointer;
  padding: 3.2px;
}

/* Ports */
.port {
  position: absolute;
  width: 22.4px;
  height: 22.4px;
  background: var(--card-bg);
  border: 2.4px solid var(--divider);
  border-radius: 50%;
  top: 50%;
  transform: translateY(-50%);
  cursor: crosshair;
  z-index: 30;
  transition: background 0.2s, border-color 0.2s, transform 0.2s;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}
.port:hover {
  transform: translateY(-50%) scale(1.2);
  background: var(--primary);
  border-color: var(--primary);
}
.port.in { left: -13.2px; }
.port.out { right: -13.2px; }

/* Zoom Controls */
.zoom-controls {
  position: absolute;
  bottom: 16px;
  left: 16px;
  display: flex;
  gap: 4.8px;
  z-index: 1000;
}
.zoom-controls button {
  background: var(--card-bg);
  border: 1px solid var(--divider);
  box-shadow: var(--shadow-sm);
  padding: 5.6px 8px;
  font-size: 0.8rem;
  border-radius: 8px;
  font-weight: 600;
}
.zoom-controls button:hover { background: var(--surface-2); }

/* Credit pill */
.credit-pill {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 5.6px;
  background: var(--card-bg);
  color: var(--text-color);
  padding: 5.6px 12.8px;
  border-radius: 799.2px;
  box-shadow: var(--shadow-md);
  z-index: 1000;
  font-weight: 600;
  font-size: 0.68rem;
  border: 1px solid var(--divider);
  white-space: nowrap;
}
.credit-pill svg { color: var(--brand); }

/* ==========================================================================
   Vibe Chat panel
   ========================================================================== */
.vibe-chat {
  position: absolute;
  right: 16px;
  top: 52.8px;
  width: 320px;
  min-width: 320px;
  max-width: calc(100vw - 32px);
  height: calc(100vh - 68.8px);
  background: var(--card-bg);
  border-radius: 12.8px;
  box-shadow: var(--shadow-xl);
  display: flex;
  flex-direction: column;
  z-index: 1500;
  border: 1px solid var(--divider);
  overflow: hidden;
  resize: horizontal;
  direction: rtl; /* Puts resize handle on the left edge */
  animation: panelSlideIn 0.3s var(--ease-out);
}
.vibe-chat > * {
  direction: ltr; /* Reset content direction */
}
.vibe-chat.hidden { display: none; }
@keyframes panelSlideIn {
  from { opacity: 0; transform: translateX(19.2px); }
  to { opacity: 1; transform: translateX(0); }
}
.chat-header {
  padding: 10.4px 12.8px;
  border-bottom: 1px solid var(--divider);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: linear-gradient(45deg, rgba(139, 92, 246, 0.10), rgba(245, 158, 11, 0.08));
}
.chat-header h3 {
  margin: 0;
  font-size: 0.76rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 240px;
}
.chat-header button {
  padding: 3.2px 6.4px;
  border: none;
  background: transparent;
  cursor: pointer;
  border-radius: 4.8px;
  color: var(--text-muted);
  font-size: 0.72rem;
}
.chat-header button:hover { background: rgba(0, 0, 0, 0.06); color: var(--text-color); }
.chat-settings {
  padding: 8px 12.8px;
  border-bottom: 1px solid var(--divider);
  display: flex;
  gap: 6.4px;
}
.chat-settings input, .chat-settings select {
  width: 100%;
  padding: 4.8px 6.4px;
  border: 1px solid var(--divider);
  border-radius: 4.8px;
  background: var(--input-bg);
  color: var(--text-color);
  font-size: 0.64rem;
}
.chat-settings-row { display: flex; gap: 6.4px; }
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12.8px;
  display: flex;
  flex-direction: column;
  gap: 9.6px;
}
.chat-msg {
  padding: 9.6px 12.8px;
  border-radius: 8px;
  font-size: 0.82rem;
  max-width: 90%;
  line-height: 1.55;
  word-break: break-word;
}
.chat-msg.user {
  background: var(--primary);
  color: #fff;
  align-self: flex-end;
  white-space: pre-wrap;
}
:root.dark-mode .chat-msg.user { color: #201502; }
.chat-msg.ai {
  background: var(--surface-2);
  border: 1px solid var(--divider);
  align-self: flex-start;
  white-space: normal;
  color: var(--text-color);
}
.chat-msg.ai p {
  margin: 0 0 8px;
}
.chat-msg.ai p:last-child {
  margin-bottom: 0;
}
.chat-msg.ai h1, .chat-msg.ai h2, .chat-msg.ai h3, .chat-msg.ai h4 {
  margin: 10px 0 6px;
  font-weight: 700;
  line-height: 1.3;
}
.chat-msg.ai h1 { font-size: 1.05rem; color: var(--primary); }
.chat-msg.ai h2 { font-size: 0.95rem; color: var(--primary); }
.chat-msg.ai h3 { font-size: 0.88rem; color: var(--text-color); }
.chat-msg.ai h4 { font-size: 0.82rem; color: var(--text-color); }
.chat-msg.ai ul, .chat-msg.ai ol {
  margin: 6px 0 8px;
  padding-left: 18px;
}
.chat-msg.ai li {
  margin-bottom: 4px;
}
.chat-msg.ai li:last-child {
  margin-bottom: 0;
}
.chat-msg.ai blockquote {
  margin: 8px 0;
  padding: 6px 12px;
  border-left: 3px solid var(--primary);
  background: rgba(99, 102, 241, 0.08);
  border-radius: 0 6px 6px 0;
  font-style: italic;
  font-size: 0.8rem;
}
.chat-msg.ai pre {
  background: #1e1e1e;
  color: #d4d4d4;
  padding: 8px 10px;
  border-radius: 6px;
  overflow-x: auto;
  font-family: monospace;
  font-size: 0.78rem;
  margin: 8px 0;
  border: 1px solid rgba(255, 255, 255, 0.1);
  white-space: pre;
}
.chat-msg.ai code {
  font-family: monospace;
  font-size: 0.85em;
  background: rgba(0, 0, 0, 0.08);
  padding: 1.6px 4px;
  border-radius: 3px;
}
:root.dark-mode .chat-msg.ai code {
  background: rgba(255, 255, 255, 0.1);
}
.chat-msg.ai pre code {
  background: transparent;
  padding: 0;
  color: inherit;
}
.chat-msg.ai hr {
  border: 0;
  border-top: 1px solid var(--divider);
  margin: 10px 0;
}
.chat-input-area {
  padding: 9.6px 12.8px 12.8px;
  border-top: 1px solid var(--divider);
  display: flex;
  flex-direction: column;
  gap: 6.4px;
}
.chat-input-area textarea {
  width: 100%;
  height: 96px;
  resize: none;
  padding: 8px;
  border: 1px solid var(--divider);
  border-radius: 6.4px;
  background: var(--input-bg);
  color: var(--text-color);
  font-family: var(--font-family);
  font-size: 0.85rem;
  line-height: 1.5;
}
.chat-input-area textarea:focus { outline: none; border-color: var(--primary); }
.btn-assess {
  margin: 0 12.8px 12.8px 12.8px;
  background: var(--note-bg);
  color: #854d0e;
  border-color: var(--note-border);
  justify-content: center;
  display: flex;
  align-items: center;
  padding: 6.4px 12.8px;
  border-radius: var(--border-radius);
  border: 1px solid var(--divider);
  font-weight: 500;
  cursor: pointer;
}

/* Vibe Chat Action Chips */
.action-chips-container {
  display: flex;
  gap: 6.4px;
  overflow-x: auto;
  padding-bottom: 4.8px;
  margin-bottom: 2px;
}
.action-chips-container::-webkit-scrollbar { height: 3.2px; }
.action-chips-container::-webkit-scrollbar-thumb { background: var(--divider); border-radius: 3.2px; }
.action-chip {
  white-space: nowrap;
  background: var(--surface-2);
  border: 1px solid var(--divider);
  color: var(--text-color);
  border-radius: 12.8px;
  padding: 4.8px 9.6px;
  font-size: 0.6rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 4.8px;
}
.action-chip:hover { background: var(--primary); border-color: var(--primary); color: #fff; }
:root.dark-mode .action-chip:hover { color: #201502; }

/* ==========================================================================
   Discuss Mode Enhancements (Questions, Tool Badges, Build Bridge)
   ========================================================================== */
.discuss-card {
  background: var(--surface-2);
  border: 1px solid var(--divider);
  border-radius: 8px;
  padding: 10px 12px;
  margin-top: 8px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.discuss-question-box {
  background: var(--surface-1);
  border: 1px solid rgba(var(--primary-rgb, 217, 119, 6), 0.25);
  border-radius: 6.4px;
  padding: 8px 10px;
}

.discuss-question-title {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--primary);
  display: flex;
  align-items: center;
  gap: 4.8px;
  margin-bottom: 6px;
}

.discuss-options-grid {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.discuss-chip-btn {
  background: var(--surface-2);
  border: 1px solid var(--divider);
  color: var(--text-color);
  border-radius: 6px;
  padding: 6.4px 9.6px;
  font-size: 0.68rem;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  text-align: left;
  transition: all 0.15s ease;
  line-height: 1.3;
}

.discuss-chip-btn:hover {
  border-color: var(--primary);
  background: var(--surface-1);
  transform: translateX(2px);
}

.discuss-chip-btn.recommended {
  border-color: rgba(16, 185, 129, 0.4);
  background: rgba(16, 185, 129, 0.05);
}

.discuss-chip-btn.recommended:hover {
  border-color: #10b981;
  background: rgba(16, 185, 129, 0.12);
}

.discuss-chip-badge {
  font-size: 0.58rem;
  font-weight: 700;
  background: #10b981;
  color: #ffffff;
  padding: 1.6px 4.8px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  white-space: nowrap;
}

.discuss-tools-section {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  align-items: center;
  margin-top: 4px;
}

.discuss-tool-btn {
  background: var(--surface-1);
  border: 1px solid var(--divider);
  color: var(--text-color);
  border-radius: 6px;
  padding: 4.8px 8px;
  font-size: 0.64rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: all 0.15s ease;
}

.discuss-tool-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--surface-2);
}

.discuss-build-bridge {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.08) 0%, rgba(168, 85, 247, 0.08) 100%);
  border: 1px dashed rgba(99, 102, 241, 0.4);
  border-radius: 6.4px;
  padding: 8px 10px;
  margin-top: 4px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.discuss-build-bridge-text {
  font-size: 0.68rem;
  color: var(--text-muted);
  flex: 1;
  min-width: 140px;
}

.discuss-build-bridge-text strong {
  color: var(--text-color);
  display: block;
  font-size: 0.72rem;
  margin-bottom: 2px;
}

.discuss-btn-build {
  background: #10b981;
  color: #ffffff;
  border: none;
  border-radius: 5px;
  padding: 5.6px 11.2px;
  font-size: 0.7rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  box-shadow: 0 1px 3px rgba(16, 185, 129, 0.3);
  transition: all 0.15s ease;
  white-space: nowrap;
}

.discuss-btn-build:hover {
  background: #059669;
  transform: translateY(-1px);
  box-shadow: 0 2px 5px rgba(16, 185, 129, 0.4);
}


/* ==========================================================================
   Flow Doctor panel (Flow reviewer)
   ========================================================================== */
.simulation-panel {
  position: fixed;
  right: 16px;
  top: 60.8px;
  width: 350px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 96px);
  background: var(--card-bg);
  border: 1px solid var(--divider);
  border-radius: 12.8px;
  box-shadow: var(--shadow-xl);
  z-index: 1500;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: panelSlideIn 0.3s var(--ease-out);
}
.simulation-panel.hidden { display: none; }
.sim-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10.4px 12.8px;
  background: linear-gradient(135deg, var(--brand-2), var(--brand-strong));
  color: #fff;
}
.sim-header-title { display: flex; align-items: center; gap: 8px; min-width: 0; }
.sim-header-icon {
  font-size: 1.04rem;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  width: 28.8px;
  height: 28.8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.sim-header h3 { margin: 0; font-size: 0.8rem; font-weight: 700; letter-spacing: 0.008em; }
.sim-header-sub { font-size: 0.576rem; font-weight: 500; opacity: 0.85; }
.sim-close {
  background: rgba(255, 255, 255, 0.15);
  border: none;
  color: #fff;
  cursor: pointer;
  font-size: 0.72rem;
  width: 22.4px;
  height: 22.4px;
  border-radius: 6.4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.sim-close:hover { background: rgba(255, 255, 255, 0.3); }
.sim-content {
  padding: 11.2px 12.8px;
  overflow-y: auto;
  font-size: 0.72rem;
  color: var(--text-color);
  display: flex;
  flex-direction: column;
  gap: 8.8px;
}

/* Flow Doctor 2.0 Card Elements */
.sim-score-card {
  background: var(--surface-1);
  border: 1px solid var(--divider);
  border-radius: 8px;
  padding: 10px 12px;
  box-shadow: var(--shadow-sm);
}
.sim-score-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}
.sim-score-badge {
  font-size: 1.1rem;
  font-weight: 800;
  display: flex;
  align-items: baseline;
  gap: 2px;
}
.sim-verdict-tag {
  font-size: 0.6rem;
  font-weight: 700;
  padding: 2.5px 6.4px;
  border-radius: 4.8px;
}
.sim-progress-bar {
  width: 100%;
  height: 5px;
  background: var(--surface-2);
  border-radius: 3px;
  overflow: hidden;
  margin: 4px 0 8px 0;
}
.sim-progress-fill {
  height: 100%;
  transition: width 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.sim-scope-box {
  background: var(--surface-2);
  border: 1px solid var(--divider);
  border-radius: 6.4px;
  padding: 8px 10px;
  font-size: 0.64rem;
  line-height: 1.45;
}
.sim-ai-impact-box {
  background: rgba(239, 68, 68, 0.08);
  border: 1px dashed rgba(239, 68, 68, 0.35);
  border-radius: 5px;
  padding: 6px 8px;
  font-size: 0.62rem;
  color: var(--text-color);
  line-height: 1.35;
  margin-top: 4px;
}
.sim-patch-btn {
  background: linear-gradient(135deg, #10b981, #059669);
  color: white;
  border: none;
  padding: 6px 10px;
  border-radius: 5.6px;
  font-weight: 700;
  font-size: 0.64rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4.8px;
  box-shadow: 0 2px 4px rgba(16, 185, 129, 0.25);
  transition: all 0.15s ease;
}
.sim-patch-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 3px 6px rgba(16, 185, 129, 0.4);
}
.sim-patched-badge {
  background: rgba(16, 185, 129, 0.15);
  color: #10b981;
  border: 1px solid #10b981;
  padding: 4px 8px;
  border-radius: 4.8px;
  font-weight: 700;
  font-size: 0.62rem;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
@keyframes flashGreen {
  0% { box-shadow: 0 0 0 4px #10b981, 0 0 24px rgba(16, 185, 129, 0.85); border-color: #10b981 !important; transform: scale(1.03); }
  50% { box-shadow: 0 0 0 6px #10b981, 0 0 32px rgba(16, 185, 129, 0.7); border-color: #10b981 !important; transform: scale(1.02); }
  100% { box-shadow: var(--shadow-md); border-color: var(--border-color); transform: scale(1); }
}

@keyframes flashRuleGreen {
  0% { background-color: rgba(16, 185, 129, 0.35) !important; border-color: #10b981 !important; }
  50% { background-color: rgba(16, 185, 129, 0.2) !important; border-color: #10b981 !important; }
  100% { background-color: var(--surface-2); border-color: var(--divider); }
}

/* ==========================================================================
   Modals — one design system for every dialog
   ========================================================================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--modal-overlay);
  backdrop-filter: blur(4.8px);
  -webkit-backdrop-filter: blur(4.8px);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12.8px;
}
.modal-overlay.hidden { display: none; }
.modal-card {
  background: var(--card-bg);
  border: 1px solid var(--divider);
  border-radius: 14.4px;
  box-shadow: var(--shadow-xl);
  width: 720px;
  max-width: 95vw;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: modalIn 0.25s var(--ease-out);
}
@keyframes modalIn {
  from { opacity: 0; transform: translateY(9.6px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.modal-sm { width: 336px; }
.modal-md { width: 448px; }
.modal-lg { width: 672px; max-width: 92vw; }

.modal-header {
  padding: 12.8px 16px;
  border-bottom: 1px solid var(--divider);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 9.6px;
}
.modal-header h2 { margin: 0; font-size: 0.92rem; font-weight: 700; letter-spacing: -0.0.8em; }
.modal-close {
  width: 24px;
  height: 24px;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.76rem;
  border-radius: 6.4px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.15s;
}
.modal-close:hover { background: var(--surface-2); color: var(--text-color); }

.modal-body {
  padding: 16px;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 11.2px;
}
.modal-body textarea {
  width: 100%;
  height: 400px;
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.68rem;
  padding: 12.8px;
  background: var(--surface);
  color: var(--text-color);
  border: 1px solid var(--divider);
  border-radius: 6.4px;
  resize: none;
}
.modal-footer {
  padding: 11.2px 16px;
  border-top: 1px solid var(--divider);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}
.modal-text { font-size: 0.72rem; color: var(--text-color); line-height: 1.5; margin: 0; }
.modal-input {
  width: 100%;
  padding: 7.2px 9.6px;
  border: 1px solid var(--divider);
  border-radius: 6.4px;
  background: var(--input-bg);
  color: var(--text-color);
  font-family: var(--font-family);
  font-size: 0.72rem;
}
.modal-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 2.4px rgba(var(--primary-rgb), 0.15); }

/* Centered "announcement" style modals (quota, limits, mobile) */
.modal-centered-card {
  padding: 28.8px 25.6px 22.4px;
  text-align: center;
  align-items: center;
  gap: 0;
}
.modal-icon {
  width: 48px;
  height: 48px;
  border-radius: 14.4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.44rem;
  margin-bottom: 14.4px;
}
.modal-icon-danger { background: rgba(239, 68, 68, 0.12); color: var(--danger); }
.modal-icon-brand { background: rgba(var(--primary-rgb), 0.12); }
.modal-title-center {
  margin: 0 0 8px;
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -0.1.6em;
  color: var(--text-color);
}
.modal-text-center {
  color: var(--text-muted);
  line-height: 1.6;
  font-size: 0.76rem;
  margin: 0 0 19.2px;
}
.modal-actions-col { display: flex; flex-direction: column; gap: 8px; width: 100%; }
.modal-cta {
  width: 100%;
  padding: 10.4px;
  font-weight: 700;
  font-size: 0.8rem;
  border-radius: 9.6px;
  justify-content: center;
  border: none;
  cursor: pointer;
  transition: transform 0.15s var(--ease-out), filter 0.2s;
}
.modal-cta:hover { transform: translateY(-1px); filter: brightness(1.05); }
.modal-cta:active { transform: scale(0.98); }
.modal-actions-col .btn-text { width: 100%; padding: 8px; justify-content: center; border-radius: 9.6px; }
.modal-actions-col .btn-text:hover { background: var(--surface-2); }

/* Settings */
.settings-section { display: flex; flex-direction: column; gap: 6.4px; }
.settings-label {
  font-size: 0.624rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.048em;
}
.settings-input {
  width: 100%;
  padding: 7.2px 9.6px;
  background: var(--surface-2);
  border: 1px solid var(--divider);
  color: var(--text-muted);
  border-radius: 6.4px;
  font-size: 0.68rem;
  font-family: 'Courier New', monospace;
}
.settings-version { font-size: 0.624rem; color: var(--text-muted); text-align: center; margin: 6.4px 0 0; }

.theme-switch {
  display: flex;
  gap: 3.2px;
  background: var(--surface-2);
  border: 1px solid var(--divider);
  border-radius: 9.6px;
  padding: 3.2px;
}
.theme-switch button {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6.4px;
  padding: 7.2px 6.4px;
  border: 1px solid transparent;
  border-radius: 7.2px;
  background: transparent;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.68rem;
  transition: all 0.18s;
}
.theme-switch button:hover { color: var(--text-color); background: transparent; }
.theme-switch button.active {
  background: var(--card-bg);
  color: var(--text-color);
  border-color: var(--divider);
  box-shadow: var(--shadow-sm);
}
.theme-swatch {
  width: 11.2px;
  height: 11.2px;
  border-radius: 4px;
  border: 1px solid rgba(0, 0, 0, 0.15);
  flex-shrink: 0;
}
.theme-swatch-light { background: linear-gradient(135deg, #ffffff 55%, #f59e0b 55%); }
.theme-swatch-dark { background: linear-gradient(135deg, #0b1120 55%, #f59e0b 55%); }
.theme-swatch-lava { background: linear-gradient(135deg, #261009 45%, #fb923c 45%); }

/* Segmented tabs (Compile modal) */
.seg-tabs {
  display: flex;
  gap: 3.2px;
  background: var(--surface-2);
  border: 1px solid var(--divider);
  border-radius: 9.6px;
  padding: 3.2px;
  flex-wrap: wrap;
}
.seg-tab {
  flex: 1;
  min-width: 80px;
  justify-content: center;
  padding: 6.4px 8px;
  border: 1px solid transparent;
  border-radius: 7.2px;
  background: transparent;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.664rem;
  transition: all 0.18s;
  white-space: nowrap;
}
.seg-tab:hover { color: var(--text-color); background: transparent; }
.seg-tab.active {
  background: var(--card-bg);
  color: var(--text-color);
  border-color: var(--divider);
  box-shadow: var(--shadow-sm);
}

/* Heatmap options */
.heatmap-option {
  display: flex;
  align-items: center;
  gap: 9.6px;
  width: 100%;
  padding: 8.8px 9.6px;
  border: 1px solid var(--divider);
  border-radius: 9.6px;
  background: var(--surface-1);
  text-align: left;
  transition: all 0.15s;
}
.heatmap-option:hover { border-color: var(--primary); background: var(--surface-2); transform: translateY(-1px); }
.heatmap-option-icon { font-size: 1rem; flex-shrink: 0; }
.heatmap-option-text { display: flex; flex-direction: column; gap: 1px; }
.heatmap-option-text strong { font-size: 0.704rem; color: var(--text-color); }
.heatmap-option-text small { font-size: 0.6rem; color: var(--text-muted); }

/* ==========================================================================
   Floating cards (upsell, welcome, promo, mobile splash)
   ========================================================================== */
.upsell-card {
  position: fixed;
  left: 19.2px;
  top: 50%;
  transform: translateY(-50%);
  width: 256px;
  max-width: calc(100vw - 38.4px);
  background: var(--card-bg);
  border: 1px solid rgba(var(--primary-rgb), 0.5);
  border-radius: 12.8px;
  box-shadow: var(--shadow-xl);
  z-index: 10000;
  padding: 17.6px;
  animation: panelSlideInLeft 0.35s var(--ease-out);
}
@keyframes panelSlideInLeft {
  from { opacity: 0; transform: translateY(-50%) translateX(-20px); }
  to { opacity: 1; transform: translateY(-50%) translateX(0); }
}
.upsell-close { position: absolute; top: 9.6px; right: 9.6px; }
.upsell-title {
  margin: 0 0 8px;
  color: var(--primary);
  font-size: 0.92rem;
  display: flex;
  align-items: center;
  gap: 6.4px;
}
.upsell-msg { font-size: 0.736rem; color: var(--text-color); margin: 0 0 14.4px; line-height: 1.55; }
.upsell-cta { width: 100%; padding: 8.8px; border-radius: 8px; font-weight: 700; border: none; cursor: pointer; justify-content: center; }

.welcome-card {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(600px, calc(100vw - 32px));
  max-height: 85vh;
  background: var(--card-bg);
  border: 1px solid var(--divider);
  border-radius: 16px;
  box-shadow: var(--shadow-xl);
  z-index: 10001;
  padding: 32px;
  overflow-y: auto;
  animation: welcomeIn 0.35s var(--ease-out);
}
@keyframes welcomeIn {
  from { opacity: 0; transform: translate(-50%, calc(-50% + 11.2px)) scale(0.98); }
  to { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}
.welcome-close { position: absolute; top: 14.4px; right: 14.4px; }

.mobile-splash-brand {
  font-family: 'Yellowtail', cursive;
  font-size: 2.4rem;
  line-height: 1.1;
  color: var(--brand);
  margin-bottom: 4.8px;
}
.mobile-splash-points {
  list-style: none;
  padding: 0;
  margin: 0 0 19.2px;
  display: flex;
  flex-direction: column;
  gap: 7.2px;
  text-align: left;
  width: 100%;
}
.mobile-splash-points li {
  background: var(--surface-2);
  border: 1px solid var(--divider);
  border-radius: 8px;
  padding: 7.2px 9.6px;
  font-size: 0.68rem;
  color: var(--text-color);
  line-height: 1.4;
}

/* Promo banner */
.promo-minimized {
  position: fixed;
  bottom: 19.2px;
  left: 19.2px;
  width: 44.8px;
  height: 44.8px;
  background: linear-gradient(45deg, #ec4899, #8b5cf6);
  border-radius: 50%;
  box-shadow: 0 8px 20px rgba(236, 72, 153, 0.5);
  z-index: 9999;
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 1.36rem;
  animation: promoPulse 2s infinite;
}
.promo-banner {
  position: fixed;
  bottom: 19.2px;
  left: 19.2px;
  display: flex;
  align-items: flex-start;
  gap: 9.6px;
  background: var(--card-bg);
  border: 1px solid rgba(var(--primary-rgb), 0.5);
  box-shadow: var(--shadow-xl);
  padding: 14.4px;
  border-radius: 12.8px;
  z-index: 9999;
  max-width: 272px;
  animation: slideInUp 0.4s var(--ease-out);
}
.promo-banner-icon { font-size: 1.44rem; }
.promo-banner-body h3 { margin: 0 0 4.8px; font-size: 0.84rem; color: var(--text-color); }
.promo-banner-body p { margin: 0 0 11.2px; font-size: 0.704rem; color: var(--text-muted); line-height: 1.5; }
.promo-banner-body p strong { color: var(--primary); }
.promo-cta { width: 100%; padding: 8px; border-radius: 6.4px; font-weight: 700; border: none; cursor: pointer; color: #fff; justify-content: center; transition: all 0.2s; }
.promo-close { flex-shrink: 0; }
@keyframes slideInUp {
  from { transform: translateY(32px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.55; transform: scale(0.85); }
}
@keyframes promoPulse {
  0% { transform: scale(1); box-shadow: 0 8px 20px rgba(236, 72, 153, 0.5); }
  50% { transform: scale(1.08); box-shadow: 0 8px 28px rgba(236, 72, 153, 0.8); }
  100% { transform: scale(1); box-shadow: 0 8px 20px rgba(236, 72, 153, 0.5); }
}
.btn-glow:hover {
  box-shadow: 0 0 12px 4px rgba(236, 72, 153, 0.6) !important;
  transform: scale(1.02) !important;
  opacity: 1 !important;
}

/* ==========================================================================
   Toast
   ========================================================================== */
.toast {
  position: fixed;
  bottom: -100px;
  right: 19.2px;
  background: #1e293b;
  color: #fff;
  padding: 9.6px 17.6px;
  border-radius: 8px;
  box-shadow: var(--shadow-lg);
  z-index: 3000;
  font-size: 0.704rem;
  font-weight: 500;
  transition: bottom 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.3s;
  opacity: 0;
  max-width: min(336px, calc(100vw - 38.4px));
}
.toast.show { bottom: 19.2px; opacity: 1; }

/* AI Thinking Indicator */
.ai-thinking-loop { display: inline-flex; align-items: center; gap: 4.8px; padding: 3.2px 6.4px; background: var(--surface-2); border-radius: 9.6px; border: 1px solid var(--border); }
.ai-thinking-dot { width: 6.4px; height: 6.4px; border-radius: 50%; background: var(--primary); animation: ai-complex-think 2.5s infinite ease-in-out; }
.ai-thinking-dot:nth-child(2) { animation-delay: 0.2s; }
.ai-thinking-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes ai-complex-think {
  0% { transform: scale(0.8); opacity: 0.4; background: var(--primary); }
  25% { transform: scale(1.2) translateY(-3px); opacity: 1; background: #00d2ff; }
  50% { transform: scale(0.9) translateY(0); opacity: 0.6; background: #3a7bd5; }
  75% { transform: scale(1.1) translateY(2px); opacity: 0.9; background: #8a2387; }
  100% { transform: scale(0.8); opacity: 0.4; background: var(--primary); }
}

/* ==========================================================================
   Pricing dropdown
   ========================================================================== */
.pricing-dropdown {
  width: 544px;
  max-width: calc(100vw - 19.2px);
  padding: 19.2px;
  right: 0;
  left: auto;
  cursor: default;
}
.pricing-dropdown a:hover { background-color: transparent !important; }
.pricing-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 11.2px; }
.pricing-tier {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 11.2px;
  padding: 12.8px;
  display: flex;
  flex-direction: column;
  transition: transform 0.2s, box-shadow 0.2s;
  position: relative;
  overflow: hidden;
}
.pricing-tier:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); border-color: var(--primary); }
.pricing-tier h4 { margin: 0 0 6.4px 0; font-size: 0.84rem; color: var(--text-color); letter-spacing: 0.032em; }
.pricing-tier .price { font-size: 1.08rem; font-weight: 800; color: var(--primary); margin-bottom: 2px; }
.pricing-tier .subprice { font-size: 0.6rem; color: var(--text-muted); margin-bottom: 11.2px; }
.pricing-tier ul { margin: 0; padding-left: 14.4px; font-size: 0.664rem; color: var(--text-muted); flex-grow: 1; }
.pricing-tier ul li { margin-bottom: 5.6px; line-height: 1.35; }
.pricing-btn {
  margin-top: 11.2px;
  padding: 8px;
  border-radius: 7.2px;
  border: none;
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
  text-align: center;
  justify-content: center;
  transition: filter 0.2s;
}
.pricing-btn:hover { filter: brightness(1.1); }
:root.dark-mode .pricing-btn { color: #201502; }
.pricing-btn:disabled { opacity: 0.55; cursor: default; }

/* ==========================================================================
   Tour overlay
   ========================================================================== */
.tour-highlight {
  position: relative !important;
  z-index: 20001 !important;
  pointer-events: none !important;
  box-shadow: 0 0 0 3.2px rgba(217, 119, 6, 0.35), 0 0 16px rgba(217, 119, 6, 0.7) !important;
  border-radius: 8px;
}
#tour-logo.tour-highlight { border-radius: 4.8px; box-shadow: 0 0 0 3.2px rgba(245, 158, 11, 0.4), 0 0 16px rgba(245, 158, 11, 0.8) !important; }
#tour-add-node.tour-highlight { box-shadow: 0 0 0 3.2px rgba(16, 185, 129, 0.4), 0 0 16px rgba(16, 185, 129, 0.8) !important; }
#tour-login.tour-highlight { border-radius: 799.2px; }

.tour-tooltip-box {
  position: absolute;
  background: var(--card-bg);
  border: 2px solid var(--primary);
  box-shadow: var(--shadow-xl);
  padding: 8px 11.2px;
  border-radius: 9.6px;
  color: var(--text-color);
  font-weight: 600;
  font-size: 0.68rem;
  z-index: 20002;
  white-space: normal;
  max-width: 144px;
  text-align: center;
  line-height: 1.4;
  animation: floatTooltip 2s ease-in-out infinite;
  --arrow-pos: 50%;
  --arrow-height: 8px;
}
.tour-tooltip-box::after {
  content: '';
  position: absolute;
  top: calc(-1 * var(--arrow-height));
  left: var(--arrow-pos);
  transform: translateX(-50%);
  border-width: 0 8px var(--arrow-height) 8px;
  border-style: solid;
  border-color: transparent transparent var(--primary) transparent;
}
@keyframes floatTooltip {
  0% { transform: translateY(0); }
  50% { transform: translateY(4px); }
  100% { transform: translateY(0); }
}

/* ==========================================================================
   Domain panel
   ========================================================================== */
.domain-panel {
  position: absolute;
  left: 16px;
  top: 52.8px;
  width: 200px;
  background: var(--card-bg);
  border: 1px solid var(--divider);
  border-radius: 12.8px;
  box-shadow: var(--shadow-xl);
  display: flex;
  flex-direction: column;
  z-index: 1000;
  max-height: calc(100vh - 68.8px);
  overflow-y: auto;
}
.domain-panel.hidden { display: none; }
.domain-header {
  padding: 9.6px 12.8px;
  border-bottom: 1px solid var(--divider);
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  background: var(--card-bg);
  border-radius: 12.8px 12.8px 0 0;
}
.domain-list { padding: 6.4px; display: flex; flex-direction: column; gap: 3.2px; }
.domain-item {
  padding: 6.4px 9.6px;
  border-radius: 6.4px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 6.4px;
  border: 1px solid transparent;
  transition: all 0.2s;
}
.domain-item:hover { background: var(--surface-2); }
.domain-item.active { background: var(--surface-2); border-color: var(--primary); }
.domain-item-header { display: flex; align-items: center; gap: 6.4px; font-weight: 600; font-size: 0.72rem; }
.domain-badge-color { width: 9.6px; height: 9.6px; border-radius: 50%; }
.domain-actions { display: none; gap: 6.4px; }
.domain-item.active .domain-actions { display: flex; }
.domain-actions button {
  flex: 1;
  padding: 3.2px;
  border-radius: 3.2px;
  border: 1px solid var(--divider);
  background: var(--card-bg);
  color: var(--text-color);
  font-size: 0.6rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}
.domain-actions button:hover { background: var(--primary); color: #fff; }
:root.dark-mode .domain-actions button:hover { color: #201502; }
.domain-actions button.btn-vibe { background: #a855f7; color: #fff; border-color: #9333ea; }
.domain-actions button.btn-vibe:hover { background: #9333ea; }
.node.node-dimmed { opacity: 0.3; filter: grayscale(1); }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ==========================================================================
   DAG Version History & Forks modal
   ========================================================================== */
.history-commit-card {
  background: var(--card-bg);
  border: 2px solid var(--divider);
  border-radius: 6.4px;
  padding: 6.4px 8px;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  transition: all 0.2s var(--ease-out);
  user-select: none;
  z-index: 10;
  box-sizing: border-box;
}
.history-commit-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); border-color: var(--primary) !important; }
.history-commit-card.selected { outline: 2px solid var(--primary); box-shadow: 0 0 0 3.2px rgba(var(--primary-rgb), 0.25); }
.history-commit-card.current {
  background: linear-gradient(135deg, var(--card-bg), var(--surface-1));
  box-shadow: 0 0 9.6px rgba(16, 185, 129, 0.2);
}
.history-commit-card.dimmed { opacity: 0.25; filter: grayscale(0.8); }
.badge-ghost { background: var(--surface-2); color: var(--text-muted); }
.badge-success { background: rgba(16, 185, 129, 0.15); color: #10b981; border: 1px solid rgba(16, 185, 129, 0.3); }
.badge-primary { background: rgba(var(--primary-rgb), 0.15); color: var(--primary); border: 1px solid rgba(var(--primary-rgb), 0.3); }
#history-graph-viewport.panning { cursor: grabbing !important; }

/* Swarm Wave Compiler */
.swarm-wave-card { transition: transform 0.15s ease, box-shadow 0.15s ease; }
.swarm-wave-card:hover { box-shadow: var(--shadow-sm); }
.swarm-wave-card button:hover { filter: brightness(1.08); }

/* ==========================================================================
   Responsive — the tool stays presentable on small screens
   ========================================================================== */
@media (max-width: 960px) {
  .tb-ghost-btn span { display: none; }
  .tb-ghost-btn { padding: 5.6px 7.2px; }
  .tb-btn { padding: 6.4px 8.8px; }
}

@media (max-width: 720px) {
  .toolbar { flex-wrap: wrap; padding: 6.4px 9.6px; row-gap: 6.4px; }
  .tb-left { flex-wrap: wrap; }
  .tb-right { margin-left: auto; border-left: none; padding-left: 0; flex-wrap: wrap; }
  .tb-right .tb-primary { border-right: none; margin-right: 0; padding-right: 0; }
  .vibe-chat {
    left: 9.6px;
    right: 9.6px;
    top: auto;
    bottom: 9.6px;
    width: auto;
    max-width: none;
    height: 62vh;
  }
  .simulation-panel {
    left: 9.6px;
    right: 9.6px;
    top: auto;
    bottom: 9.6px;
    width: auto;
    max-width: none;
    max-height: 62vh;
  }
  .modal-card { max-width: calc(100vw - 12.8px); max-height: calc(100vh - 25.6px); }
  .modal-sm, .modal-md, .modal-lg { width: 100%; }
  .modal-centered-card { padding: 22.4px 16px 17.6px; }
  .pricing-dropdown { width: calc(100vw - 12.8px); padding: 12.8px; }
  .pricing-grid { grid-template-columns: 1fr; max-height: 46vh; overflow-y: auto; }
  .domain-panel { left: 9.6px; top: auto; bottom: 9.6px; max-height: 45vh; }
  .welcome-card { padding: 20.8px 17.6px; }
  .credit-pill { bottom: 11.2px; font-size: 0.624rem; padding: 4.8px 9.6px; }
  .zoom-controls { bottom: 11.2px; left: 11.2px; }
  .upsell-card { left: 9.6px; width: 240px; }
  .promo-banner { left: 9.6px; right: 9.6px; max-width: none; }
  .promo-minimized { left: 9.6px; bottom: 11.2px; }
  .empty-state { width: calc(100vw - 38.4px); }
  .empty-state h2 { font-size: 0.96rem !important; }
}

@media (max-width: 448px) {
  .brand { font-size: 1.2rem; }
  .tb-name input { width: 88px; font-size: 0.656rem; }
  .tb-btn { padding: 6.4px 8px; font-size: 0.624rem; gap: 4px; }
  .dropbtn { padding: 5.6px 7.2px; font-size: 0.64rem; }
  .account-name { display: none; }
  .account-btn { padding: 3.2px 6.4px 3.2px 3.2px; }
  .account-btn-guest { padding: 5.6px 9.6px; font-size: 0.64rem; }
  .modal-title-center { font-size: 1rem; }
  .mobile-splash-brand { font-size: 1.92rem; }
  .chat-header h3 { max-width: 160px; }
}

/* ==========================================================================
   RESUME PREVIOUS PROJECT FLOATING PILL
   ========================================================================== */
.flw-resume-pill {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  animation: flwPillSlideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  pointer-events: auto;
}

@keyframes flwPillSlideUp {
  0% {
    opacity: 0;
    transform: translate(-50%, 20px) scale(0.95);
  }
  100% {
    opacity: 1;
    transform: translate(-50%, 0) scale(1);
  }
}

.flw-resume-pill-content {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: rgba(18, 24, 38, 0.92);
  backdrop-filter: blur(14px) saturate(180%);
  -webkit-backdrop-filter: blur(14px) saturate(180%);
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: 0 12px 32px -4px rgba(0, 0, 0, 0.45), 0 0 0 1px rgba(255, 255, 255, 0.05);
  padding: 6px 14px 6px 16px;
  border-radius: 9999px;
  color: #e2e8f0;
  font-size: 0.8125rem;
  font-family: inherit;
  white-space: nowrap;
  transition: all 0.2s ease;
}

[data-theme="light"] .flw-resume-pill-content {
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid rgba(0, 0, 0, 0.12);
  box-shadow: 0 12px 32px -4px rgba(0, 0, 0, 0.15), 0 0 0 1px rgba(0, 0, 0, 0.04);
  color: #1e293b;
}

.flw-resume-pill-icon {
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  color: #f59e0b;
}

.flw-resume-pill-text {
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.flw-resume-pill-text strong {
  color: #f59e0b;
  font-weight: 600;
}

.flw-resume-pill-btn {
  background: linear-gradient(135deg, #f59e0b, #d97706);
  color: #ffffff;
  border: none;
  border-radius: 9999px;
  padding: 4px 12px;
  font-size: 0.75rem;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 0.02em;
  box-shadow: 0 2px 6px rgba(245, 158, 11, 0.35);
  transition: transform 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease;
}

.flw-resume-pill-btn:hover {
  transform: translateY(-1px);
  filter: brightness(1.08);
  box-shadow: 0 4px 12px rgba(245, 158, 11, 0.45);
}

.flw-resume-pill-btn:active {
  transform: translateY(0);
}

.flw-resume-pill-close {
  background: transparent;
  border: none;
  color: rgba(148, 163, 184, 0.8);
  font-size: 1.1rem;
  line-height: 1;
  padding: 2px 4px;
  margin-left: -2px;
  cursor: pointer;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s ease, background-color 0.15s ease;
}

.flw-resume-pill-close:hover {
  color: #ffffff;
  background-color: rgba(255, 255, 255, 0.1);
}

[data-theme="light"] .flw-resume-pill-close:hover {
  color: #0f172a;
  background-color: rgba(0, 0, 0, 0.06);
}

@media (max-width: 600px) {
  .flw-resume-pill {
    bottom: 72px;
    width: calc(100% - 24px);
  }
  .flw-resume-pill-content {
    width: 100%;
    justify-content: space-between;
    box-sizing: border-box;
  }
  .flw-resume-pill-text {
    max-width: 160px;
  }
}

