/* ═══════════════════════════════════════════════════════════════════════
   MCRouter admin — shadcn-inspired dark theme + Blueprint node editor
   ═══════════════════════════════════════════════════════════════════════ */
:root {
  --bg: #09090b;
  --surface: #0c0c0e;
  --surface-2: #18181b;
  --border: #27272a;
  --border-hover: #3f3f46;
  --text: #fafafa;
  --text-muted: #a1a1aa;
  --text-soft: #71717a;
  --primary: #10b981;
  --primary-hover: #059669;
  --primary-soft: rgba(16, 185, 129, 0.12);
  --danger: #ef4444;
  --danger-soft: rgba(239, 68, 68, 0.12);
  --warn: #f59e0b;
  --warn-soft: rgba(245, 158, 11, 0.12);
  --radius: 8px;
}
*{box-sizing:border-box}
html,body{margin:0;padding:0;background:var(--bg);color:var(--text);font-family:ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,Helvetica,Arial,sans-serif;font-size:14px;line-height:1.5;-webkit-font-smoothing:antialiased}
a{color:inherit;text-decoration:none}
button{font-family:inherit;cursor:pointer}
input,select,textarea{font-family:inherit}

.card{background:var(--surface);border:1px solid var(--border);border-radius:var(--radius);padding:1.25rem}
.btn{display:inline-flex;align-items:center;gap:0.4rem;padding:0.5rem 0.85rem;border-radius:6px;border:1px solid var(--border);background:var(--surface-2);color:var(--text);font-size:13px;transition:all 0.12s}
.btn:hover{border-color:var(--border-hover);background:#27272a}
.btn-primary{background:var(--primary);color:#051a14;border-color:transparent;font-weight:600}
.btn-primary:hover{background:var(--primary-hover)}
.btn-danger{color:var(--danger)}
.btn-danger:hover{background:var(--danger-soft);border-color:var(--danger)}
.btn-ghost{background:transparent;border-color:transparent}
.btn-ghost:hover{background:var(--surface-2)}
.btn-sm{padding:0.3rem 0.6rem;font-size:12px}
.input,.select,.textarea{width:100%;background:#0a0a0b;border:1px solid var(--border);border-radius:6px;padding:0.5rem 0.7rem;color:var(--text);font-size:13px;outline:none;transition:border-color 0.12s,box-shadow 0.12s}
.input:focus,.select:focus,.textarea:focus{border-color:var(--primary);box-shadow:0 0 0 3px rgba(16,185,129,0.18)}
.mono{font-family:ui-monospace,"JetBrains Mono",Menlo,monospace;font-size:12px}
label.lbl{display:block;font-size:12px;color:var(--text-muted);margin-bottom:0.3rem;font-weight:500}
.badge{display:inline-block;font-size:11px;padding:0.1rem 0.5rem;border-radius:999px;border:1px solid var(--border);background:var(--surface-2);letter-spacing:0.02em}
.grid-2{display:grid;grid-template-columns:1fr 1fr;gap:1rem}
.grid-3{display:grid;grid-template-columns:1fr 1fr 1fr;gap:1rem}
.row{display:flex;gap:0.75rem;align-items:center}
.fieldset{border:1px solid var(--border);border-radius:var(--radius);padding:1rem 1.25rem 1.25rem;margin:0}
.fieldset>legend{padding:0 0.5rem;color:var(--text-muted);font-size:12px}
table.tbl{width:100%;border-collapse:collapse;font-size:13px}
table.tbl th{text-align:left;padding:0.6rem 0.85rem;color:var(--text-soft);font-weight:500;font-size:11px;text-transform:uppercase;letter-spacing:0.04em;border-bottom:1px solid var(--border)}
table.tbl td{padding:0.7rem 0.85rem;border-bottom:1px solid var(--border)}
table.tbl tr:last-child td{border-bottom:none}
table.tbl tr:hover td{background:rgba(255,255,255,0.02)}
.muted{color:var(--text-muted)}
.soft{color:var(--text-soft)}
.h1{font-size:1.4rem;font-weight:700;letter-spacing:-0.02em;margin:0}
.nav-link{padding:0.35rem 0.7rem;border-radius:6px;color:var(--text-muted);transition:all 0.1s}
.nav-link:hover{color:var(--text);background:var(--surface-2)}
.nav-active{color:var(--text);background:var(--surface-2)}

/* ── Sidebar ─────────────────────────────────────────────────────────── */
.sidebar {
  width: 56px;
  min-width: 56px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: sticky;
  top: 0;
  z-index: 30;
  overflow: hidden;
  transition: width 0.2s ease, min-width 0.2s ease;
}
.sidebar:hover,
.sidebar.sidebar-pinned {
  width: 220px;
  min-width: 220px;
}
.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 0;
  padding: 0.85rem 0.85rem;
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: -0.02em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  overflow: hidden;
  padding-left: 18px;
  transition: padding-left 0.2s ease;
}
.sidebar:hover .sidebar-logo,
.sidebar.sidebar-pinned .sidebar-logo {
  padding-left: 0.85rem;
}
.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0.75rem 0.4rem;
  flex: 1;
}
.sidebar-link {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  font-size: 13px;
  color: var(--text-muted);
  transition: all 0.1s;
  white-space: nowrap;
  overflow: hidden;
}
.sidebar-link:hover { color: var(--text); background: var(--surface-2); }
.sidebar-active { color: var(--text); background: var(--surface-2); font-weight: 500; }
.sidebar-link-sm { font-size: 12px; padding: 0.35rem 0.75rem; }
.sidebar-icon { width: 18px; height: 18px; flex-shrink: 0; }
.sidebar-label {
  opacity: 0;
  transition: opacity 0.15s ease;
  pointer-events: none;
}
/* When collapsed (not hovered, not pinned): collapse the user email label
   smoothly so there's no huge gap above the logout button.
   Uses max-height transition instead of display:none so the space animates.
   The opacity transition is already handled by .sidebar-label. */
.sidebar-user {
  max-height: 40px;
  overflow: hidden;
  transition: max-height 0.2s ease;
}
.sidebar:not(:hover):not(.sidebar-pinned) .sidebar-user {
  max-height: 0;
}
/* Logo: when collapsed, the "router" text collapses so only "mc" shows
   centered. When expanded, "router" slides in and the logo left-aligns. */
.sidebar-logo .sidebar-label {
  max-width: 60px;
  overflow: hidden;
  transition: opacity 0.15s ease, max-width 0.2s ease;
}
.sidebar:not(:hover):not(.sidebar-pinned) .sidebar-logo .sidebar-label {
  max-width: 0;
}
.sidebar:hover .sidebar-label,
.sidebar.sidebar-pinned .sidebar-label {
  opacity: 1;
  pointer-events: auto;
}
.sidebar-footer {
  padding: 0.6rem 0.5rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  overflow: hidden;
}
.sidebar-user { font-size: 11px; color: var(--text-soft); word-break: break-all; }
.sidebar-badge { font-size: 11px; color: var(--warn); }
.sidebar-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 0.6rem 0;
  border: none;
  border-top: 1px solid var(--border);
  background: transparent;
  color: var(--text-soft);
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
}
.sidebar-toggle:hover { color: var(--text); background: var(--surface-2); }
.sidebar-toggle-icon { width: 16px; height: 16px; transition: transform 0.2s ease; }

.app-shell { display: flex; height: 100vh; overflow: hidden; }
.app-main { flex: 1; overflow: auto; min-width: 0; }

/* ═══════════════════════════════════════════════════════════════════════
   Flow Editor — Blueprint-style visual node canvas
   ═══════════════════════════════════════════════════════════════════════ */

/* Toolbar — left panel for flow editor */
#fe-toolbar {
  display: flex;
  flex-direction: column;
  width: 180px;
  min-width: 180px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 12px 10px;
  gap: 4px;
  flex-shrink: 0;
  z-index: 20;
  overflow-y: auto;
}
.fe-toolbar-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-soft);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 4px 6px 6px;
}
.fe-toolbar-section { display:flex; flex-direction:column; gap:3px; }
#fe-toolbar .fe-btn { width: 100%; text-align: left; justify-content: flex-start; }
.fe-toolbar-right { margin-top: auto; padding-top: 8px; border-top: 1px solid var(--border); display:flex; flex-direction:column; gap:3px; }
.fe-toolbar-right .fe-btn { display: inline-flex; align-items: center; gap: 6px; }

/* Buttons */
.fe-btn {
  padding: 4px 10px;
  border-radius: 5px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.1s;
  white-space: nowrap;
}
.fe-btn:hover { background: #27272a; border-color: var(--border-hover); }
.fe-btn-primary { background: var(--primary); color: #051a14; border-color: transparent; font-weight: 600; }
.fe-toolbar-right .fe-btn-primary { margin-top: 4px; }
.fe-btn-primary:hover { background: var(--primary-hover); }
.fe-btn-ghost { background: transparent; border-color: transparent; color: var(--text-soft); }
.fe-btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.fe-btn-green  { border-color: #10b98140; color: #6ee7b7; }
.fe-btn-green:hover  { background: #10b98118; }
.fe-btn-purple { border-color: #8b5cf640; color: #c4b5fd; }
.fe-btn-purple:hover { background: #8b5cf618; }
.fe-btn-blue   { border-color: #3b82f640; color: #93c5fd; }
.fe-btn-blue:hover   { background: #3b82f618; }
.fe-btn-violet { border-color: #a855f740; color: #d8b4fe; }
.fe-btn-violet:hover { background: #a855f718; }
.fe-btn-red    { border-color: #ef444440; color: #fca5a5; }
.fe-btn-red:hover    { background: #ef444418; }
.fe-btn-amber  { border-color: #f59e0b40; color: #fcd34d; }
.fe-btn-amber:hover  { background: #f59e0b18; }
.fe-btn-cyan   { border-color: #06b6d440; color: #67e8f9; }
.fe-btn-cyan:hover   { background: #06b6d418; }

/* Canvas */
#fe-canvas {
  background-color: #08080a;
  background-image:
    radial-gradient(circle, #1a1a1f 1px, transparent 1px);
  background-size: 24px 24px;
  cursor: grab;
}
#fe-workspace { pointer-events: none; }
#fe-workspace .fe-node { pointer-events: all; }
#fe-edges path { cursor: pointer; }

/* ── Node ─────────────────────────────────────────────────────────────── */
.fe-node {
  position: absolute;
  background: #111114;
  border: 1px solid #2a2a30;
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.5);
  cursor: default;
  user-select: none;
  transition: box-shadow 0.1s;
  z-index: 1;
}
.fe-node:hover { box-shadow: 0 4px 20px rgba(0,0,0,0.65); z-index: 10; }
.fe-node-sel {
  box-shadow: 0 0 0 2px #10b981, 0 4px 24px rgba(16,185,129,0.15) !important;
  z-index: 20 !important;
}

/* Title bar */
.fe-node-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  border-radius: 7px 7px 0 0;
  cursor: grab;
}
.fe-node-title:active { cursor: grabbing; }
.fe-node-title-text {
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  letter-spacing: 0.01em;
}
.fe-node-x {
  background: none;
  border: none;
  color: rgba(255,255,255,0.4);
  font-size: 16px;
  line-height: 1;
  padding: 0 2px;
  cursor: pointer;
  border-radius: 3px;
}
.fe-node-x:hover { color: #fff; background: rgba(255,255,255,0.15); }

/* Body */
.fe-node-body {
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Form elements inside nodes */
.fe-row { display: flex; flex-direction: column; gap: 3px; }
.fe-lbl { font-size: 10px; color: var(--text-soft); font-weight: 500; text-transform: uppercase; letter-spacing: 0.04em; }
.fe-inp {
  width: 100%;
  background: #08080a;
  border: 1px solid #2a2a30;
  border-radius: 4px;
  padding: 5px 8px;
  color: var(--text);
  font-size: 12px;
  outline: none;
}
.fe-inp:focus { border-color: var(--primary); }
.fe-sel {
  width: 100%;
  background: #08080a;
  border: 1px solid #2a2a30;
  border-radius: 4px;
  padding: 5px 8px;
  color: var(--text);
  font-size: 12px;
  outline: none;
  cursor: pointer;
}
.fe-sel:focus { border-color: var(--primary); }
.fe-ta {
  width: 100%;
  background: #08080a;
  border: 1px solid #2a2a30;
  border-radius: 4px;
  padding: 5px 8px;
  color: var(--text);
  font-size: 12px;
  outline: none;
  resize: vertical;
  min-height: 50px;
}
.fe-ta:focus { border-color: var(--primary); }
.fe-hint { font-size: 11px; color: var(--text-soft); padding: 2px 0; }

/* Pool checkboxes */
.fe-pool { display:flex; flex-direction:column; gap:3px; max-height:80px; overflow:auto; }
.fe-pool-item {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--text-soft);
  cursor: pointer;
}
.fe-pool-item input { width:12px; height:12px; accent-color: var(--primary); }

/* List editor (for in/not_in matchers) */
.fe-list { display:flex; flex-direction:column; gap:3px; }
.fe-list-item { display:flex; align-items:center; gap:4px; }
.fe-list-item .fe-inp { flex:1; min-width:0; }
.fe-list-rm {
  background: none; border: none; color: var(--text-soft); cursor: pointer;
  font-size: 14px; line-height: 1; padding: 2px 4px; border-radius: 3px;
}
.fe-list-rm:hover { color: #f87171; background: rgba(248,113,113,0.1); }
.fe-list-add {
  background: none; border: 1px dashed var(--border); color: var(--primary);
  cursor: pointer; font-size: 11px; padding: 3px 8px; border-radius: 4px;
  margin-top: 2px;
}
.fe-list-add:hover { background: rgba(99,102,241,0.1); border-color: var(--primary); }

/* Output labels */
.fe-out-labels {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  font-weight: 600;
  padding: 2px 0;
}
.fe-out-true  { color: #6ee7b7; }
.fe-out-false { color: #fca5a5; }

/* ── Ports ─────────────────────────────────────────────────────────────── */
.fe-port {
  position: absolute;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid #555;
  background: #222;
  cursor: crosshair;
  z-index: 10;
  transition: border-color 0.12s, background 0.12s, box-shadow 0.12s;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  font-weight: 700;
  color: rgba(255,255,255,0.6);
}
.fe-port:hover {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
  box-shadow: 0 0 10px rgba(99,102,241,0.5);
}
.fe-port-active {
  border-color: #22c55e !important;
  background: #22c55e !important;
  color: #fff !important;
  box-shadow: 0 0 10px #22c55e80;
}
/* Port hover tooltip */
.fe-port::after {
  content: attr(title);
  position: absolute;
  font-size: 9px;
  color: var(--text-soft);
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.12s;
  top: 50%;
  transform: translateY(-50%);
}
.fe-port-in::after  { left: 20px; }
.fe-port-out::after { right: 20px; }
.fe-port:hover::after { opacity: 1; }

/* ═══════════════════════════════════════════════════════════════════════
   Design system layer (shared)
   ═══════════════════════════════════════════════════════════════════════ */

/* Toast — replaces janky button-text swaps for save feedback */
#toast-host { position: fixed; bottom: 1rem; right: 1rem; display: flex; flex-direction: column; gap: 0.5rem; z-index: 200; pointer-events: none; }
.toast {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px;
  padding: 0.55rem 0.9rem; color: var(--text); font-size: 13px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.45); pointer-events: auto; max-width: 360px;
  display: flex; align-items: center; gap: 0.5rem;
  animation: toast-in 0.16s ease-out;
}
.toast.leaving { animation: toast-out 0.18s forwards; }
.toast-success { border-color: rgba(16,185,129,0.4); }
.toast-success::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--primary); flex-shrink: 0; }
.toast-error   { border-color: rgba(239,68,68,0.4); }
.toast-error::before   { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--danger); flex-shrink: 0; }
.toast-info::before    { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--text-soft); flex-shrink: 0; }
@keyframes toast-in  { from { transform: translateY(6px); opacity: 0 } to { transform: translateY(0); opacity: 1 } }
@keyframes toast-out { to { transform: translateY(6px); opacity: 0 } }

/* Keyboard shortcut badge */
.kbd {
  display: inline-block; font-family: ui-monospace, Menlo, monospace; font-size: 11px;
  padding: 1px 6px; border: 1px solid var(--border); border-bottom-width: 2px;
  border-radius: 4px; background: var(--surface-2); color: var(--text-muted);
  min-width: 18px; text-align: center; line-height: 1.4;
}

/* Focus rings — visible only for keyboard navigation, off for mouse click */
.btn:focus-visible, .fe-btn:focus-visible {
  outline: none; box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--primary);
}
.input:focus-visible, .select:focus-visible, .textarea:focus-visible { outline: none; }

/* Empty state */
.empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 3rem 1.5rem; text-align: center; color: var(--text-muted);
  border: 1px dashed var(--border); border-radius: var(--radius);
  background: rgba(255,255,255,0.01);
}
.empty-state svg { width: 40px; height: 40px; color: var(--text-soft); margin-bottom: 0.75rem; }
.empty-state h3 { margin: 0 0 0.25rem; font-size: 1rem; color: var(--text); font-weight: 600; }
.empty-state p  { margin: 0 0 1rem; font-size: 13px; color: var(--text-soft); max-width: 360px; }

/* Extra flow palette colors */
.fe-btn-teal   { border-color: #14b8a640; color: #5eead4; }
.fe-btn-teal:hover   { background: #14b8a618; }
.fe-btn-orange { border-color: #f9731640; color: #fdba74; }
.fe-btn-orange:hover { background: #f9731618; }

/* ═══════════════════════════════════════════════════════════════════════
   Flow editor: zoom widget + shortcuts modal + snap indicator
   ═══════════════════════════════════════════════════════════════════════ */

.fe-zoom {
  position: absolute; bottom: 12px; right: 12px; display: flex; flex-direction: column;
  gap: 1px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 4px; z-index: 15; box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}
.fe-zoom button {
  background: transparent; border: none; color: var(--text-muted);
  font-size: 15px; font-weight: 600; width: 28px; height: 28px; border-radius: 5px;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: background 0.1s, color 0.1s;
}
.fe-zoom button:hover  { background: var(--surface-2); color: var(--text); }
.fe-zoom button.active { background: var(--primary-soft); color: var(--primary); }
.fe-zoom-sep   { height: 1px; background: var(--border); margin: 3px 3px; }
.fe-zoom-level { font-size: 10px; color: var(--text-soft); text-align: center; padding: 3px 0; line-height: 1; user-select: none; font-family: ui-monospace, Menlo, monospace; }

/* Shared modal (used for shortcuts, could be reused) */
.fe-modal-bg {
  position: fixed; inset: 0; background: rgba(0,0,0,0.55); z-index: 150;
  display: flex; align-items: center; justify-content: center; padding: 1.5rem;
  opacity: 0; pointer-events: none; transition: opacity 0.16s;
}
.fe-modal-bg.open { opacity: 1; pointer-events: auto; }
.fe-modal {
  background: #18181b; border: 1px solid var(--border); border-radius: 12px;
  max-width: 520px; width: 100%; transform: scale(0.97);
  transition: transform 0.16s; overflow: hidden; box-shadow: 0 20px 40px rgba(0,0,0,0.5);
}
.fe-modal-bg.open .fe-modal { transform: scale(1); }
.fe-modal-head { padding: 12px 16px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.fe-modal-head span { font-weight: 600; font-size: 14px; }
.fe-modal-head button { background: none; border: none; color: var(--text-soft); cursor: pointer; font-size: 20px; line-height: 1; }
.fe-modal-body { padding: 16px 20px 20px; }
.fe-shortcuts  { display: grid; grid-template-columns: auto 1fr; gap: 10px 20px; font-size: 13px; align-items: center; }
.fe-shortcuts .fe-sc-keys { display: flex; gap: 3px; align-items: center; justify-self: end; }
.fe-shortcuts .fe-sc-desc { color: var(--text-muted); }
.fe-shortcuts-section { grid-column: 1 / -1; margin-top: 6px; font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-soft); padding-top: 8px; border-top: 1px solid var(--border); }
.fe-shortcuts-section:first-child { border-top: none; padding-top: 0; margin-top: 0; }

/* Hint bar — link-styled ? cue */
#fe-hint .fe-hint-kbd { border-color: var(--border-hover); color: var(--text-muted); cursor: pointer; pointer-events: auto; }
#fe-hint .fe-hint-kbd:hover { color: var(--text); }

/* ═══════════════════════════════════════════════════════════════════════
   Flow editor: tab bar
   ═══════════════════════════════════════════════════════════════════════ */
.fe-tabs {
  display: flex; align-items: stretch; gap: 0;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: 0 8px;
  min-height: 46px;
  flex-shrink: 0;
  position: relative;
}
.fe-tab-list {
  display: flex; gap: 2px; align-items: stretch;
  overflow-x: auto; flex: 1;
  scrollbar-width: none;
  padding: 4px 0 0;
}
.fe-tab-list::-webkit-scrollbar { display: none; }
/* Fade overflow edges when there's more to scroll */
.fe-tabs::before, .fe-tabs::after {
  content: ""; position: absolute; top: 0; bottom: 1px; width: 20px; pointer-events: none; z-index: 2;
  opacity: 0; transition: opacity 0.15s;
}
.fe-tabs::before { left: 8px;  background: linear-gradient(to right, var(--bg), transparent); }
.fe-tabs::after  { right: 60px; background: linear-gradient(to left,  var(--bg), transparent); }
.fe-tabs.scroll-left::before  { opacity: 1; }
.fe-tabs.scroll-right::after  { opacity: 1; }

.fe-tab {
  display: inline-flex; align-items: center; gap: 7px;
  background: transparent; border: none; color: var(--text-soft);
  padding: 6px 12px 7px; border-radius: 6px 6px 0 0;
  font-size: 13px; font-weight: 500;
  cursor: pointer; white-space: nowrap; user-select: none;
  transition: color 0.1s, background 0.1s;
  position: relative;
}
.fe-tab:hover  { color: var(--text); background: var(--surface); }
.fe-tab.active {
  color: var(--text); background: var(--surface);
  box-shadow: inset 0 2px 0 var(--primary);
}
.fe-tab-icon { width: 14px; height: 14px; flex-shrink: 0; color: var(--text-soft); }
.fe-tab.active .fe-tab-icon,
.fe-tab:hover .fe-tab-icon { color: var(--text-muted); }
.fe-tab-name { max-width: 180px; overflow: hidden; text-overflow: ellipsis; }
.fe-tab-name:focus { outline: none; }
.fe-tab-name[contenteditable="true"] {
  background: var(--surface-2); border-radius: 4px; padding: 1px 5px;
  outline: 1px solid var(--primary);
}
.fe-tab-x {
  width: 16px; height: 16px; border-radius: 3px;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--text-soft); font-size: 13px; line-height: 1;
  cursor: pointer; opacity: 0;
  transition: opacity 0.1s, background 0.1s, color 0.1s;
  margin-left: 2px;
}
.fe-tab:hover .fe-tab-x, .fe-tab.active .fe-tab-x { opacity: 1; }
.fe-tab-x:hover { background: rgba(239,68,68,0.15); color: #f87171; }

/* New-function button styled as a ghost tab so it reads as part of the row */
.fe-tab-new {
  display: inline-flex; align-items: center; gap: 5px;
  background: transparent; border: 1px dashed var(--border); color: var(--text-soft);
  border-radius: 6px; padding: 4px 10px; margin: 4px 0px 4px 0px;
  font-size: 12px; font-weight: 500; cursor: pointer; white-space: nowrap;
  flex-shrink: 0; transition: color 0.1s, border-color 0.1s, background 0.1s;
}
.fe-tab-new:hover { color: var(--text); border-color: var(--border-hover); background: var(--surface); }
.fe-tab-new svg { width: 12px; height: 12px; }

/* ═══════════════════════════════════════════════════════════════════════
   Mobile responsive layer (breakpoint: 720px)
   ═══════════════════════════════════════════════════════════════════════ */

/* Global hamburger button — rendered by nav.html, shown only on mobile */
.mobile-hamburger {
  display: none;
  position: fixed; top: 10px; left: 10px; z-index: 90;
  width: 40px; height: 40px;
  align-items: center; justify-content: center;
  background: var(--surface-2); border: 1px solid var(--border);
  color: var(--text); border-radius: 8px; cursor: pointer;
  box-shadow: 0 2px 10px rgba(0,0,0,0.4);
}
.mobile-hamburger:hover { border-color: var(--border-hover); }
.mobile-hamburger svg { width: 20px; height: 20px; }

/* Backdrop shared by mobile sidebar drawer AND flow-editor toolbar drawer */
.mobile-backdrop {
  display: none;
  position: fixed; inset: 0; background: rgba(0,0,0,0.55); z-index: 80;
}
.mobile-backdrop.open { display: block; }

/* Flow-editor toolbar drawer toggle */
.fe-mobile-tools { display: none; }

@media (max-width: 720px) {
  /* ── Sidebar becomes an off-canvas drawer ─────────────────────────── */
  .sidebar {
    position: fixed; top: 0; left: 0; height: 100vh;
    width: 240px; min-width: 240px;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    z-index: 95;
  }
  .sidebar.mobile-open { transform: translateX(0); box-shadow: 4px 0 24px rgba(0,0,0,0.55); }
  .sidebar:hover { width: 240px; min-width: 240px; } /* neutralise desktop hover-expand */
  .sidebar-label { opacity: 1 !important; pointer-events: auto !important; }
  .sidebar-toggle { display: none; }
  .app-main { width: 100%; }
  .mobile-hamburger { display: flex; }

  /* ── Layout compaction ────────────────────────────────────────────── */
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  main.max-w-6xl, main.max-w-2xl { padding: 3.5rem 0.9rem 1.5rem !important; }
  h1.h1 { font-size: 1.2rem; }
  .card { padding: 1rem; }

  /* ── Tables scroll horizontally inside their card ─────────────────── */
  .card { overflow-x: auto; }
  table.tbl { min-width: 460px; }

  /* ── Dashboard chart grids stack ─────────────────────────────────── */
  main div[style*="grid-template-columns:1fr 1fr"] { grid-template-columns: 1fr !important; }

  /* ── Modals & overlays fit the viewport ─────────────────────────── */
  .fe-modal { max-width: calc(100vw - 1.5rem) !important; width: calc(100vw - 1.5rem); }
  .ai-panel { width: calc(100vw - 1.5rem) !important; max-height: 82vh; }
  .ai-overlay { padding: 0.75rem; align-items: flex-end; }

  /* ── Toast host stretches full-width on mobile ───────────────────── */
  #toast-host { left: 1rem; right: 1rem; }
  #toast-host .toast { max-width: 100%; }

  /* ── Flow editor palette becomes an off-canvas drawer ─────────────── */
  #fe-toolbar {
    position: absolute; top: 0; bottom: 0; left: 0;
    width: 200px; min-width: 200px;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    z-index: 30;
    box-shadow: none;
  }
  #fe-toolbar.mobile-open { transform: translateX(0); box-shadow: 4px 0 12px rgba(0,0,0,0.55); }
  .fe-mobile-tools {
    display: flex; align-items: center; justify-content: center;
    position: absolute; top: 10px; left: 10px; z-index: 22;
    background: var(--surface-2); border: 1px solid var(--border);
    color: var(--text); border-radius: 6px;
    width: 34px; height: 34px; cursor: pointer;
    box-shadow: 0 2px 8px rgba(0,0,0,0.45);
  }
  .fe-mobile-tools svg { width: 18px; height: 18px; }
  /* Hint bar shrinks on tiny screens */
  #fe-hint { font-size: 10px; text-align: center; max-width: 90vw; }
  /* Zoom widget: shrink and hide the snap toggle (drag-heavy on touch) */
  .fe-zoom { padding: 2px; }
  .fe-zoom button { width: 32px; height: 32px; font-size: 14px; }

  /* Backend/settings forms: less padding, no fixed max-width overrides */
  main.max-w-2xl form.card { padding: 1rem; }
}

/* ═══════════════════════════════════════════════════════════════════════
   Flow editor: touch input
   ═══════════════════════════════════════════════════════════════════════ */
/* Disable browser gesture handling on the canvas so single-finger drag pans
   and two-finger pinch zooms via our JS instead of scrolling the page. */
#fe-canvas { touch-action: none; }
/* Node interactive surfaces: no browser handling so pointerdown drags them. */
.fe-node-title, .fe-port { touch-action: none; }
/* Scrollable inner areas keep browser scroll: */
.fe-pool { touch-action: pan-y; }

/* ═══════════════════════════════════════════════════════════════════════
   Sidebar / toolbar: keep bottom actions visible when viewport is short
   ═══════════════════════════════════════════════════════════════════════ */
/* Main sidebar: nav links scroll internally so logo + footer + toggle
   never get pushed off-screen. min-height:0 is required for flex children
   to actually shrink and let overflow kick in. */
.sidebar-nav { min-height: 0; overflow-y: auto; }
.sidebar-footer { flex-shrink: 0; }

/* Flow-editor toolbar: palette buttons scroll internally so AI / Delete /
   Save stay pinned at the bottom on short viewports. */
#fe-toolbar { min-height: 0; }
.fe-toolbar-section { min-height: 0; overflow-y: auto; }
.fe-toolbar-right { flex-shrink: 0; }

/* Dynamic viewport height for mobile: accounts for the browser chrome
   (URL bar) so the drawer really fills the visible height instead of
   overshooting and hiding its own footer. */
@supports (height: 100dvh) {
  @media (max-width: 720px) {
    .sidebar { height: 100dvh; }
  }
}
