/* SystemFlow - design tokens & base styles (Stitch design system) */

/* ── Dark theme (default) - SysFlow cold dark palette ────────── */
:root,
[data-theme="dark"],
html.dark {
  --bg:           #131316;
  --surface:      #1c1d20;
  --surface1:     #1c1d20;
  --surface2:     #232427;
  --surface3:     #2b2c30;
  --bg-2:         #171719;
  --surface-bright: #353639;
  --border:       rgba(255,255,255,0.07);
  --border2:      rgba(255,255,255,0.12);
  --border3:      rgba(255,255,255,0.20);
  --border-md:    rgba(255,255,255,0.10);
  --text:         #f2f1ef;
  --text-sec:     #b2b0b5;
  --text-dim:     rgba(178,176,181,0.5);
  --text-muted:   rgba(178,176,181,0.28);
  --outline:      #8a8890;
  --outline-var:  #45444a;
  --canvas-bg:    #0d0d10;
  --canvas-grid:  rgba(255,255,255,0.045);

  /* Accent - refined terracotta */
  --accent:       #d4634a;
  --accent-dim:   rgba(212,99,74,0.16);
  --accent-glow:  0 0 20px rgba(212,99,74,0.38);
  --accent2:      #e8a87c;
  --accent2-dim:  rgba(232,168,124,0.14);
  --clay:         #e8a87c;
  --clay-dim:     rgba(232,168,124,0.14);

  /* Semantic colors */
  --green:        #34D399;
  --green-dim:    rgba(52,211,153,0.14);
  --amber:        #F59E0B;
  --amber-dim:    rgba(245,158,11,0.14);
  --red:          #EF4444;
  --red-dim:      rgba(239,68,68,0.14);
  --purple:       #A78BFA;
  --purple-dim:   rgba(167,139,250,0.14);
  --cyan:         #38BDF8;
  --cyan-dim:     rgba(56,189,248,0.12);
  --cyan-glow:    rgba(56,189,248,0.25);
  --indigo:       #6366f1;
  --indigo-dim:   rgba(99,102,241,0.14);
  --gold:         #EAB308;
  --gold-dim:     rgba(234,179,8,0.14);
  --blue:         #3B82F6;

  /* Glassmorphism */
  --glass:        rgba(26,27,29,0.88);
  --glass-border: rgba(255,255,255,0.08);

  /* Font vars */
  --sans: 'Inter', 'Geist', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'JetBrains Mono', 'Geist Mono', 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;

  /* Radius / transition tokens */
  --r-sm: 4px; --r-md: 8px; --r-lg: 12px;
  --t: 0.18s cubic-bezier(0.4, 0, 0.2, 1);
  --spring: 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease-out: cubic-bezier(0,0,0.2,1);
}

/* ── Light theme - warm gray, easy on eyes ────────────────────── */
[data-theme="light"],
html.light {
  --bg:           #f0ece6;
  --surface:      #f7f4ef;
  --surface1:     #f7f4ef;
  --surface2:     #ece7e0;
  --surface3:     #e0dbd2;
  --bg-2:         #ece7e0;
  --surface-bright:#fcfaf6;
  --border:       rgba(0,0,0,0.09);
  --border2:      rgba(0,0,0,0.14);
  --border3:      rgba(0,0,0,0.20);
  --border-md:    rgba(0,0,0,0.12);
  --text:         #1a1813;
  --text-sec:     #4a4339;
  --text-dim:     #7e7668;
  --text-muted:   #a39a8f;
  --outline:      #7e7668;
  --outline-var:  #c6bfb5;
  --canvas-bg:    #e6e1d9;
  --canvas-grid:  rgba(0,0,0,0.055);

  --accent:       #c2553a;
  --accent-dim:   rgba(194,85,58,0.12);
  --accent-glow:  0 0 12px rgba(194,85,58,0.25);
  --accent2:      #b9774a;
  --accent2-dim:  rgba(185,119,74,0.12);
  --clay:         #b9774a;
  --clay-dim:     rgba(185,119,74,0.12);

  --green:        #15803D;
  --green-dim:    rgba(21,128,61,0.13);
  --amber:        #B45309;
  --amber-dim:    rgba(180,83,9,0.13);
  --red:          #B91C1C;
  --red-dim:      rgba(185,28,28,0.12);
  --purple:       #6D28D9;
  --purple-dim:   rgba(109,40,217,0.12);
  --cyan:         #0369A1;
  --cyan-dim:     rgba(3,105,161,0.12);
  --cyan-glow:    rgba(3,105,161,0.20);
  --indigo:       #4338CA;
  --indigo-dim:   rgba(67,56,202,0.12);
  --gold:         #92400E;
  --gold-dim:     rgba(146,64,14,0.13);
  --blue:         #1D4ED8;

  --glass:        rgba(244,241,236,0.92);
  --glass-border: rgba(0,0,0,0.09);

  --sans: 'Inter', 'Geist', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'JetBrains Mono', 'Geist Mono', 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;

  --r-sm: 4px; --r-md: 8px; --r-lg: 12px;
  --t: 0.18s cubic-bezier(0.4, 0, 0.2, 1);
  --spring: 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease-out: cubic-bezier(0,0,0.2,1);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
  touch-action: none;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 13px;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

#root { width: 100%; height: 100%; }

button {
  font-family: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
}

input, textarea, select {
  font-family: inherit;
  color: inherit;
}

/* ---------- scrollbars ---------- */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-md); border-radius: 2px; }
::-webkit-scrollbar-thumb:hover { background: var(--outline); }

/* ---------- layout ---------- */
.app {
  width: 100vw;
  height: 100vh;
  display: grid;
  grid-template-rows: 40px 1fr auto;
  grid-template-columns: auto 1fr auto;
  grid-template-areas:
    "header header header"
    "left   canvas right"
    "bottom bottom bottom";
  background: var(--bg);
}

.header { grid-area: header; }
.left-panel { grid-area: left; position: relative; }
.canvas-area { grid-area: canvas; position: relative; overflow: hidden; }
.right-panel { grid-area: right; position: relative; }
.bottom-panel { grid-area: bottom; position: relative; }

/* ---------- header ---------- */
.header {
  height: 40px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 10px;
  gap: 10px;
  z-index: 30;
  position: relative;
}
/* ---------- header view tabs (demo style) ---------- */
.header-view-tabs {
  display: flex;
  align-items: center;
  height: 100%;
  gap: 0;
  margin: 0 4px;
}
.header-view-tab {
  height: 100%;
  padding: 0 10px;
  display: flex;
  align-items: center;
  font: 500 12px/1 var(--sans);
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  transition: var(--t);
  cursor: pointer;
}
.header-view-tab:hover { color: var(--text-sec); background: var(--surface2); }
.header-view-tab.active {
  color: var(--text);
  border-bottom-color: var(--accent);
  font-weight: 700;
}

/* ---------- header PRO chip ---------- */
.header-pro-chip {
  font: 700 9px/1 var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 2px 5px;
  border-radius: 3px;
  background: var(--surface2);
  border: 1px solid var(--border2);
  color: var(--text-muted);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
}
.brand-logo {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.brand-logo svg { width: 22px; height: 22px; }
.logo-spinning { animation: spin 3s linear infinite; transform-origin: center; }
@keyframes spin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}
.brand-name {
  font-size: 15px;
  font-weight: 800;
  letter-spacing: -0.01em;
  font-family: var(--sans);
}
.brand-name .accent { color: var(--accent); }

.header-divider {
  width: 1px;
  height: 22px;
  background: var(--border2);
}

.header-chip {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 4px 10px;
  border: 1px solid var(--border2);
  border-radius: var(--r-sm);
  background: var(--surface2);
  min-width: 64px;
}
.header-chip-label {
  font: 700 9px/1 var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}
.header-chip-value {
  font: 700 13px/1.1 var(--mono);
}
.header-chip.cyan .header-chip-value { color: var(--accent); }
.header-chip.accent .header-chip-value { color: var(--accent); }
.header-chip.indigo .header-chip-value { color: var(--accent); }

.header-metrics {
  display: flex;
  gap: 18px;
  margin-left: 6px;
  align-items: center;
  flex: 1;
  justify-content: center;
}
.metric-cell {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 52px;
}
.metric-label {
  font: 700 9px/1 var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}
.metric-value {
  font: 700 13px/1 var(--mono);
}
.metric-value.cyan   { color: var(--accent); }
.metric-value.accent { color: var(--accent); }
.metric-value.green  { color: var(--green); }
.metric-value.amber  { color: var(--amber); }
.metric-value.red    { color: var(--red); }
.metric-value.indigo { color: var(--indigo); }

.pulse-rate { animation: pulseOpacity 1.2s infinite; }
@keyframes pulseOpacity {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}

.pattern-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 9px;
  border-radius: var(--r-sm);
  background: var(--accent-dim);
  border: 1px solid rgba(220,90,45,0.35);
  color: var(--accent);
  font: 700 10px/1 var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.icon-btn {
  width: 32px;
  height: 32px;
  border-radius: var(--r-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-sec);
  transition: var(--t);
  position: relative;
}
.icon-btn:hover {
  background: var(--surface2);
  color: var(--text);
}
.icon-btn svg { width: 16px; height: 16px; }

.avatar-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--surface2);
  border: 1px solid var(--border2);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  font: 700 11px/1 var(--mono);
  overflow: hidden;
  transition: var(--t);
  cursor: pointer;
}
.avatar-btn:hover { border-color: var(--accent); }
.avatar-btn img { width: 100%; height: 100%; object-fit: cover; }

/* ---------- dropdown ---------- */
.dropdown {
  position: absolute;
  top: 46px;
  right: 14px;
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: var(--r-md);
  box-shadow: 0 12px 32px rgba(0,0,0,0.18);
  z-index: 100;
  animation: fadeSlideDown 0.15s ease;
  padding: 14px;
}
@keyframes fadeSlideDown {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.dropdown-section + .dropdown-section {
  border-top: 1px solid var(--border);
  padding-top: 12px;
  margin-top: 12px;
}

/* ---------- left panel ---------- */
.left-panel {
  width: 220px;
  background: var(--surface);
  border-right: 1px solid var(--border2);
  display: flex;
  flex-direction: column;
  transition: width 0.22s ease;
  overflow: hidden;
  position: relative;
  z-index: 10;
}
.left-panel.collapsed { width: 0; overflow: visible; }

/* ---------- left panel palette tabs (demo style) ---------- */
.palette-tabs {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
}
.palette-tab {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  border-radius: var(--r-sm);
  font: 600 11px/1 var(--sans);
  color: var(--text-muted);
  cursor: pointer;
  transition: var(--t);
  border: none;
  background: none;
  text-align: left;
  width: 100%;
}
.palette-tab svg { width: 16px; height: 16px; flex-shrink: 0; }
.palette-tab:hover { color: var(--text); background: var(--surface2); }
.palette-tab.active {
  background: var(--accent-dim);
  color: var(--accent);
  border-left: 2px solid var(--accent);
  padding-left: 8px;
}

.categories-section {
  padding: 6px 10px 8px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  flex-shrink: 0;
}
.category-chip {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 3px 7px;
  border-radius: 10px;
  font: 600 10px/1 var(--sans);
  color: var(--text-muted);
  background: var(--surface2);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: var(--t);
  white-space: nowrap;
  user-select: none;
}
.category-chip:hover { color: var(--text); border-color: var(--border2); }
.category-chip.active { background: var(--accent-dim); color: var(--accent); border-color: rgba(220,90,45,0.35); }
.category-chip .chip-count { font: 700 9px/1 var(--mono); opacity: 0.65; }

/* ---------- add component CTA ---------- */
.add-component-btn {
  margin: 8px 12px;
  padding: 8px 0;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--r-sm);
  font: 700 11px/1 var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  cursor: pointer;
  transition: var(--t);
  width: calc(100% - 24px);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.add-component-btn:hover { background: var(--accent); opacity: 0.85; }
.add-component-btn svg { width: 14px; height: 14px; }

.panel-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}
.panel-title {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: -0.01em;
  font-family: var(--sans);
}
.count-badge {
  font: 700 10px/1 var(--mono);
  padding: 3px 7px;
  border-radius: 99px;
  background: var(--surface3);
  color: var(--text-sec);
}
.pro-chip {
  margin-left: auto;
  font: 700 9px/1 var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 3px 6px;
  border-radius: 4px;
  background: var(--amber-dim);
  color: var(--amber);
  border: 1px solid rgba(245, 158, 11, 0.4);
}

.search {
  position: relative;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
.search input {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: var(--r-sm);
  padding: 8px 28px 8px 30px;
  font-size: 12px;
  outline: none;
  transition: var(--t);
  color: var(--text);
}
.search input:focus { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-dim); }
.search .search-icon { position: absolute; left: 22px; top: 50%; transform: translateY(-50%); color: var(--text-muted); pointer-events: none; }
.search .clear-icon { position: absolute; right: 22px; top: 50%; transform: translateY(-50%); color: var(--text-muted); cursor: pointer; width: 14px; height: 14px; }

.cat-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
.cat-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 8px;
  border-radius: 99px;
  border: 1px solid var(--border2);
  background: transparent;
  font: 600 10.5px/1 var(--sans);
  color: var(--text-sec);
  transition: var(--t);
  cursor: pointer;
}
.cat-pill svg { width: 11px; height: 11px; }
.cat-pill:hover { color: var(--text); border-color: var(--border3); }
.cat-pill.active {
  background: var(--cat-dim, var(--surface2));
  border-color: var(--cat-color, var(--border3));
  color: var(--cat-color, var(--text));
}
.cat-pill.icon-only { padding: 4px 6px; }
.cat-pill.icon-only span { display: none; }
.cat-pill.active span { display: inline; }

.node-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0 8px 0;
}

.node-group-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px 6px 14px;
  border-left: 3px solid var(--cat-color, var(--border2));
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 1;
}
.node-group-header svg { width: 12px; height: 12px; color: var(--cat-color, var(--text-sec)); }
.node-group-label {
  font: 700 10px/1 var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--cat-color, var(--text-sec));
}
.node-group-count {
  margin-left: auto;
  font: 700 10px/1 var(--mono);
  padding: 2px 6px;
  border-radius: 99px;
  background: var(--surface2);
  color: var(--text-muted);
}

.node-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px 8px 11px;
  border-left: 3px solid transparent;
  cursor: grab;
  transition: var(--t);
  position: relative;
  user-select: none;
}
.node-item:active { cursor: grabbing; }
.node-item:hover {
  background: var(--surface2);
  border-left-color: var(--cat-color, var(--accent));
}
.node-item:hover .node-item-label { color: var(--cat-color, var(--text)); }

.node-icon-wrap {
  width: 26px;
  height: 26px;
  border-radius: var(--r-sm);
  background: var(--surface2);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--cat-color, var(--text-sec));
  flex-shrink: 0;
  transition: var(--t);
}
.node-icon-wrap svg { width: 14px; height: 14px; }
.node-item:hover .node-icon-wrap {
  box-shadow: 0 0 12px var(--cat-glow, var(--accent-dim));
  background: var(--cat-dim, var(--surface2));
}

.node-item-text { min-width: 0; flex: 1; }
.node-item-label {
  font: 600 12.5px/1.3 var(--sans);
  color: var(--text);
  transition: var(--t);
}
.node-item-tag {
  font: 400 11px/1.2 var(--sans);
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mini-badge {
  font: 700 9px/1 var(--mono);
  padding: 2px 5px;
  border-radius: 3px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.mini-badge.amber  { background: var(--amber-dim); color: var(--amber); }
.mini-badge.green  { background: var(--green-dim); color: var(--green); }
.mini-badge.cyan   { background: var(--accent-dim); color: var(--accent); }
.mini-badge.red    { background: var(--red-dim); color: var(--red); }
.mini-badge.purple { background: var(--purple-dim); color: var(--purple); }
.mini-badge.indigo { background: var(--indigo-dim); color: var(--indigo); }
.mini-badge.gray   { background: var(--surface3); color: var(--text-muted); }

.left-footer {
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  font: 600 10.5px/1.2 var(--mono);
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
  gap: 6px;
}
.left-footer.amber { color: var(--amber); }

/* ---------- collapse tabs ---------- */
.collapse-tab {
  position: absolute;
  width: 20px;
  height: 72px;
  background: var(--surface2);
  border: 1px solid var(--border2);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-sec);
  z-index: 25;
  cursor: pointer;
  transition: var(--t);
  box-shadow: 0 2px 8px rgba(0,0,0,0.12);
}
.collapse-tab:hover { color: var(--accent); background: var(--surface3); border-color: var(--accent); box-shadow: 0 0 8px var(--accent-dim); }
.collapse-tab svg { width: 11px; height: 11px; }

.collapse-tab.left {
  top: 50%;
  right: -20px;
  transform: translateY(-50%);
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
  border-left: none;
}
.collapse-tab.right {
  top: 50%;
  left: -20px;
  transform: translateY(-50%);
  border-radius: var(--r-sm) 0 0 var(--r-sm);
  border-right: none;
}
.collapse-tab.bottom {
  left: 50%;
  top: -18px;
  transform: translateX(-50%);
  border-radius: var(--r-sm) var(--r-sm) 0 0;
  border-bottom: none;
  width: 96px;
  height: 18px;
}

/* ---------- canvas ---------- */
.canvas-area {
  background: var(--canvas-bg);
  background-image: radial-gradient(circle, var(--canvas-grid) 1px, transparent 1px);
  background-size: 22px 22px;
  position: relative;
}
.canvas-stage {
  position: absolute;
  inset: 0;
}
.canvas-svg {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.canvas-nodes {
  position: absolute;
  inset: 0;
}

/* 2D node circles.
   Position comes from --tx/--ty (set inline by React) through translate3d, so
   node moves composite on the GPU. Scale effects compose after the translate.
   `transform` is deliberately NOT in the transition list: the node must track
   the cursor 1:1 during a drag, with zero rubber-banding. */
.sys-node {
  position: absolute;
  transform: translate3d(var(--tx, 0px), var(--ty, 0px), 0);
  width: 80px;
  height: 80px;
  background: var(--node-color, #6366f1);
  border: 2.5px solid rgba(255,255,255,0.22);
  border-radius: 50%;
  overflow: visible;
  cursor: grab;
  transition: box-shadow 0.2s, border-color 0.2s;
  user-select: none;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  box-shadow: 0 4px 14px rgba(0,0,0,0.35), 0 0 0 0px transparent;
}
.sys-node.selected {
  border-color: rgba(255,255,255,0.8);
  box-shadow: 0 4px 14px rgba(0,0,0,0.35), 0 0 0 3px rgba(255,255,255,0.22), 0 0 28px var(--node-color, var(--accent));
  transform: translate3d(var(--tx, 0px), var(--ty, 0px), 0) scale(1.08);
}
.sys-node.bottleneck { border-color: var(--amber); box-shadow: 0 4px 14px rgba(0,0,0,0.35), 0 0 0 2px rgba(245,158,11,0.4), 0 0 22px rgba(245,158,11,0.3); }
.sys-node.crashed { border-color: var(--red); box-shadow: 0 4px 14px rgba(0,0,0,0.35), 0 0 0 2px rgba(239,68,68,0.4), 0 0 22px rgba(239,68,68,0.3); }
.sys-node:active { cursor: grabbing; transform: translate3d(var(--tx, 0px), var(--ty, 0px), 0) scale(0.98); }
.sys-node.dragging, .card-node.dragging { transition: none; cursor: grabbing; }

/* 2px color accent band at top */
.node-top-band { height: 3px; width: 100%; flex-shrink: 0; }

.node-main-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 9px 6px;
}
.node-icon-box {
  width: 30px; height: 30px;
  border-radius: 6px;
  border: 1.5px solid transparent;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.node-icon-box svg { width: 15px; height: 15px; }
.node-text-col { flex: 1; min-width: 0; }
.node-name-line { font: 600 12px/1.2 var(--sans); color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.node-tag-line  { font: 400 10px/1.2 var(--sans); color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 1px; }
.node-pulse { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }

.node-load-strip { height: 2px; background: var(--surface3); }
.node-load-fill  { height: 100%; transition: width 0.35s ease; }

.node-metric-row {
  display: flex; align-items: center; justify-content: center;
  gap: 4px; padding: 4px 9px 5px;
  font: 600 10px/1 var(--mono); color: var(--text-muted);
}
.node-cfg-row {
  display: flex; align-items: center; justify-content: center;
  gap: 4px; padding: 3px 9px 4px;
  font: 500 9px/1 var(--mono); color: var(--text-muted);
  opacity: 0.7;
}
.nm-val { color: var(--text-sec); }
.nm-sep { color: var(--border2); }
.node-crash-tag {
  padding: 4px 9px 5px;
  font: 600 10px/1 var(--mono); color: var(--red);
  text-transform: uppercase; letter-spacing: 0.04em;
}

@keyframes pulseGlow {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.6; transform: scale(1.28); }
}

/* Crash throb for canvas nodes. Nodes are positioned by
   translate3d(var(--tx),var(--ty)) - a keyframe with a bare scale() replaces
   that transform and teleports the node to the canvas origin (it reads as
   "crashed nodes disappear"). Every node keyframe must compose with the
   position, same as v3-node-spawn. */
@keyframes nodeCrashPulse {
  0%, 100% { opacity: 1;    transform: translate3d(var(--tx, 0px), var(--ty, 0px), 0) scale(1); }
  50%      { opacity: 0.72; transform: translate3d(var(--tx, 0px), var(--ty, 0px), 0) scale(1.04); }
}

/* circle node label */
.sys-node-label {
  font: 600 10.5px/1.25 var(--sans);
  color: rgba(255,255,255,0.95);
  text-shadow: 0 1px 4px rgba(0,0,0,0.6);
  word-break: break-word;
  padding: 0 8px;
  pointer-events: none;
  position: relative;
  z-index: 1;
}

/* connection handles - must be visible outside circle.
   The visible dot is 14px; the ::after pseudo pads the hit target out to
   ~26px so grabbing one no longer needs pixel-perfect aim. */
.handle {
  position: absolute;
  width: 14px;
  height: 14px;
  background: var(--bg);
  border: 2px solid rgba(255,255,255,0.6);
  border-radius: 50%;
  cursor: crosshair;
  transition: background 0.15s, box-shadow 0.15s;
  z-index: 10;
  opacity: 0;
}
.handle::after {
  content: '';
  position: absolute;
  inset: -6px;
  border-radius: 50%;
}
.sys-node:hover .handle { opacity: 1; }
.card-node:hover .handle { opacity: 1; }
.card-node.selected .handle { opacity: 1; }
.handle:hover { background: white; box-shadow: 0 0 8px rgba(255,255,255,0.8); opacity: 1; }
.handle.left  { left: -7px;  top: 50%; transform: translateY(-50%); }
.handle.right { right: -7px; top: 50%; transform: translateY(-50%); }
.handle.top   { top: -7px;   left: 50%; transform: translateX(-50%); }
.handle.bottom { bottom: -7px; left: 50%; transform: translateX(-50%); }

/* connect mode: while a connection is being made (drag or click-to-connect),
   every handle is visible and any hovered target node lights up as valid. */
.canvas-area.connecting .handle { opacity: 1; }
.canvas-area.connecting [data-node-id]:hover .card-node,
.canvas-area.connecting .card-node:hover,
.canvas-area.connecting .sys-node:hover {
  outline: 2px solid var(--accent, #10b981);
  outline-offset: 3px;
  border-radius: 14px;
}
.canvas-area.connecting { cursor: crosshair !important; }

/* canvas controls */
.canvas-controls {
  position: absolute;
  bottom: 16px;
  left: 16px;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: var(--r-sm);
  overflow: hidden;
  z-index: 5;
}
.canvas-controls button {
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-sec);
  transition: var(--t);
  border-bottom: 1px solid var(--border);
}
.canvas-controls button:last-child { border-bottom: none; }
.canvas-controls button:hover { color: var(--accent); background: var(--surface2); }
.canvas-controls svg { width: 14px; height: 14px; }
.ctrl-divider { height: 1px; background: var(--border2); margin: 0; }
.ctrl-btn-text { font: 700 10px/1 var(--mono); letter-spacing: -0.02em; }
.ctrl-btn-danger:hover { color: var(--red) !important; }
.ctrl-btn-cloud:hover { color: var(--green) !important; }

.minimap {
  position: absolute;
  bottom: 16px;
  right: 16px;
  width: 260px;
  height: 160px;
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: var(--r-sm);
  overflow: hidden;
  z-index: 5;
}

/* canvas empty state */
.canvas-empty {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  color: var(--text-muted);
  pointer-events: none;
}
.canvas-empty h2 { font-size: 18px; font-weight: 700; color: var(--text-sec); margin: 0 0 6px 0; font-family: var(--sans); }
.canvas-empty p { margin: 0; font-size: 13px; }

/* edge particle */
.particle {
  fill: var(--accent);
  filter: drop-shadow(0 0 4px var(--accent));
}

/* ---------- right panel ---------- */
.right-panel {
  width: 280px;
  background: var(--surface);
  border-left: 1px solid var(--border2);
  display: flex;
  flex-direction: column;
  transition: width 0.22s ease;
  overflow: hidden;
  position: relative;
  z-index: 10;
}
.right-panel.collapsed { width: 0; overflow: visible; }

.tab-bar {
  height: 44px;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  border-bottom: 1px solid var(--border2);
  background: var(--surface);
}
.tab-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--text-muted);
  font: 600 9px/1 var(--sans);
  border-bottom: 2px solid transparent;
  transition: var(--t);
  position: relative;
}
.tab-btn > span:not(.tab-badge) { display: block; }
.tab-btn svg { width: 13px; height: 13px; }
.tab-btn:hover { color: var(--text-sec); background: var(--surface2); }
.tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  background: var(--accent-dim);
}
.tab-badge {
  position: absolute;
  top: 6px;
  right: 14px;
  font: 700 9px/1 var(--mono);
  padding: 2px 4px;
  min-width: 14px;
  text-align: center;
  border-radius: 99px;
  background: var(--accent);
  color: #fff;
}

.tab-content {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  animation: fadeIn 0.1s ease;
}
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.section-title {
  font: 700 10px/1 var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin: 4px 0 10px 0;
}

.config-row {
  margin-bottom: 14px;
}
.config-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}
.config-label-text {
  font: 600 11.5px/1.2 var(--sans);
  color: var(--text-sec);
}
.config-value-chip {
  font: 700 11px/1 var(--mono);
  color: var(--accent);
  padding: 2px 7px;
  border-radius: 4px;
  background: var(--accent-dim);
}

.config-select {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text);
  font: 500 11.5px/1 var(--sans);
  padding: 6px 8px;
  cursor: pointer;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  padding-right: 24px;
}
.config-select:focus { border-color: var(--accent); }
.config-select option { background: var(--surface2); color: var(--text); }

.slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  background: var(--surface3);
  border-radius: 99px;
  outline: none;
}
.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 0 0 2px var(--bg), 0 0 8px var(--accent-dim);
  transition: transform 0.15s;
}
.slider::-webkit-slider-thumb:hover {
  transform: scale(1.3);
  box-shadow: 0 0 0 2px var(--bg), 0 0 14px var(--accent);
}
.slider::-moz-range-thumb {
  width: 14px; height: 14px;
  background: var(--accent);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 0 8px var(--accent-dim);
}

.text-input {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: var(--r-sm);
  padding: 8px 10px;
  font-size: 12.5px;
  outline: none;
  transition: var(--t);
  color: var(--text);
}
.text-input:focus { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-dim); }
.text-input.mono { font-family: var(--mono); }

.empty-state {
  padding: 32px 16px;
  text-align: center;
  color: var(--text-muted);
}
.empty-state-icon {
  width: 40px;
  height: 40px;
  margin: 0 auto 10px auto;
  color: var(--text-muted);
  opacity: 0.5;
}
.empty-state h3 { font-size: 13px; color: var(--text-sec); margin: 0 0 4px 0; font-weight: 600; font-family: var(--sans); }
.empty-state p { font-size: 11.5px; margin: 0; }

/* ---------- charts ---------- */
.chart-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 10px 12px;
  margin-bottom: 10px;
}
.chart-head {
  display: flex;
  justify-content: space-between;
  margin-bottom: 6px;
}
.chart-title { font: 600 11px/1 var(--sans); color: var(--text-sec); }
.chart-value { font: 700 12px/1 var(--mono); }

.percentile-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
}
.percentile-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 8px;
  text-align: center;
}
.percentile-card .l { font: 700 9px/1 var(--mono); color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.08em; }
.percentile-card .v { font: 700 16px/1.2 var(--mono); color: var(--accent); margin-top: 4px; }

.heatmap {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 3px;
}
.heat-cell {
  height: 18px;
  border-radius: 3px;
}

/* ---------- log ---------- */
.log-toolbar {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
  align-items: center;
}
.toggle-chip {
  font: 600 10px/1 var(--sans);
  padding: 5px 8px;
  border-radius: 99px;
  border: 1px solid var(--border2);
  background: transparent;
  color: var(--text-sec);
  cursor: pointer;
  transition: var(--t);
}
.toggle-chip.active {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
}

.log-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.log-entry {
  display: grid;
  grid-template-columns: 64px 38px 1fr 44px 44px;
  gap: 6px;
  align-items: center;
  padding: 5px 8px;
  border-radius: 4px;
  background: var(--surface2);
  font: 500 10.5px/1.2 var(--mono);
}
.log-entry .ts { color: var(--text-muted); }
.log-entry .method { font-weight: 700; color: var(--accent); }
.log-entry .path { color: var(--text-sec); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.log-entry .status { text-align: right; font-weight: 700; }
.log-entry .lat { color: var(--text-muted); text-align: right; }
.log-entry.s2xx .status { color: var(--green); }
.log-entry.s4xx .status { color: var(--amber); }
.log-entry.s5xx .status { color: var(--red); }

/* ---------- topology / advisor findings ---------- */
.finding {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 10px 12px;
  margin-bottom: 8px;
  border-left: 3px solid var(--severity-color, var(--accent));
}
.finding-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}
.finding-title {
  font: 600 12.5px/1.2 var(--sans);
  flex: 1;
}
.severity-chip {
  font: 700 9px/1 var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 3px 6px;
  border-radius: 4px;
  background: var(--severity-dim);
  color: var(--severity-color);
}
.finding-desc { color: var(--text-sec); font-size: 11.5px; line-height: 1.4; }
.finding-fix { color: var(--text-muted); font-size: 11px; line-height: 1.4; margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--border); }
.finding-fix strong { color: var(--accent); font-weight: 600; }

/* ---------- templates ---------- */
.template-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.template-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 10px;
  cursor: pointer;
  transition: var(--t);
  border-top: 3px solid var(--cat-color, var(--accent));
}
.template-card:hover { border-color: var(--border3); transform: translateY(-1px); background: var(--surface3); }
.template-card h4 { margin: 0 0 4px 0; font-size: 12px; font-weight: 700; font-family: var(--sans); }
.template-card p { margin: 0; color: var(--text-muted); font-size: 10.5px; line-height: 1.35; }
.template-card .meta { display: flex; justify-content: space-between; margin-top: 8px; font: 600 9.5px/1 var(--mono); color: var(--text-muted); }

/* ---------- bottom panel ---------- */
.bottom-panel {
  background: var(--surface);
  border-top: 1px solid var(--border2);
  position: relative;
}
.bottom-panel.collapsed .ribbon-body { display: none; }

/* ---------- sim controls bar - floating centered (demo style) ---------- */
.sim-controls-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px 0;
  background: transparent;
  border-bottom: 1px solid var(--border);
  position: relative;
}
.sim-controls-pill {
  display: inline-flex;
  align-items: center;
  gap: 0;
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: var(--r-md);
  overflow: hidden;
  box-shadow: 0 2px 12px rgba(0,0,0,0.18);
}
.sim-ctrl-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 6px 14px;
  font: 700 9px/1 var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  transition: var(--t);
  cursor: pointer;
  background: none;
  border: none;
  border-right: 1px solid var(--border);
  min-width: 52px;
}
.sim-ctrl-btn:last-child { border-right: none; }
.sim-ctrl-btn svg { width: 16px; height: 16px; margin-bottom: 1px; }
.sim-ctrl-btn:hover { color: var(--text); background: var(--surface3); }
.sim-ctrl-btn.play:hover { color: var(--green); }
.sim-ctrl-btn.play.active { color: var(--green); background: var(--green-dim); }
.sim-ctrl-btn.pause:hover { color: var(--amber); }
.sim-ctrl-btn.pause.active { color: var(--amber); background: rgba(245,158,11,0.08); }
.sim-ctrl-btn.reset:hover { color: var(--red); }
.sim-ctrl-btn.timeline:hover { color: var(--accent); }
.sim-controls-divider {
  width: 1px;
  height: 28px;
  background: var(--border2);
}

.ribbon {
  height: 34px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--border);
}
.ribbon-tab {
  padding: 0 14px;
  height: 34px;
  display: flex;
  align-items: center;
  font: 700 9px/1 var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: var(--t);
}
.ribbon-tab:hover { color: var(--text-sec); }
.ribbon-tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.ribbon-status {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 6px;
  padding-right: 14px;
  font: 700 10px/1 var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.ribbon-status .pulse-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--status-color, var(--text-muted));
  box-shadow: 0 0 8px var(--status-color, transparent);
}
.ribbon-status.idle .pulse-dot { background: var(--text-muted); box-shadow: none; }
.ribbon-status.running .pulse-dot { background: var(--green); animation: pulseGlow 1s infinite; }
.ribbon-status.paused .pulse-dot { background: var(--amber); }
.ribbon-status.idle { color: var(--text-muted); }
.ribbon-status.running { color: var(--green); }
.ribbon-status.paused { color: var(--amber); }
.ribbon-collapse {
  width: 30px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
}
.ribbon-collapse:hover { color: var(--accent); }
.ribbon-collapse svg { width: 12px; height: 12px; }

.ribbon-body {
  padding: 12px 14px;
  min-height: 76px;
}

.simulate-row {
  display: flex;
  align-items: center;
  gap: 14px;
}
.sim-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 16px;
  border-radius: var(--r-sm);
  font: 700 11px/1 var(--sans);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border: 1px solid var(--btn-color, var(--accent));
  background: var(--btn-dim, var(--accent-dim));
  color: var(--btn-color, var(--accent));
  transition: var(--t);
}
.sim-btn:hover { box-shadow: 0 0 14px var(--btn-glow, rgba(220,90,45,0.25)); }
.sim-btn:disabled { opacity: 0.4; cursor: not-allowed; box-shadow: none; }
.sim-btn svg { width: 12px; height: 12px; }

.sim-counters {
  display: flex;
  gap: 18px;
  align-items: center;
}

.traffic-row {
  display: flex;
  align-items: center;
  gap: 16px;
}
.rate-input {
  width: 88px;
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: var(--r-sm);
  padding: 8px 10px;
  font: 700 16px/1 var(--mono);
  color: var(--accent);
  outline: none;
  text-align: right;
}
.rate-input:focus { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-dim); }
.unit-label { font: 600 11px/1 var(--mono); color: var(--text-muted); }

.pattern-btns {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.pattern-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 11px;
  border: 1px solid var(--border2);
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text-sec);
  font: 600 11px/1 var(--sans);
  transition: var(--t);
}
.pattern-btn:hover { color: var(--text); border-color: var(--border3); }
.pattern-btn.active {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
}
.pattern-glyph {
  font-family: var(--mono);
  width: 14px;
  display: inline-flex;
  justify-content: center;
}

.log-slider-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: 340px;
}
.log-slider-labels {
  display: flex;
  justify-content: space-between;
  font: 600 9.5px/1 var(--mono);
  color: var(--text-muted);
}

/* profile cards */
.profile-row {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 4px;
}
.profile-card {
  min-width: 132px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-top: 3px solid var(--prof-color, var(--accent));
  border-radius: var(--r-md);
  padding: 10px;
  cursor: pointer;
  transition: var(--t);
  flex-shrink: 0;
}
.profile-card:hover { border-color: var(--prof-color, var(--accent)); }
.profile-card.active { background: var(--prof-dim, var(--accent-dim)); border-color: var(--prof-color, var(--accent)); }
.profile-card h5 { margin: 0; font-size: 12px; font-weight: 700; font-family: var(--sans); }
.profile-card .rate { font: 700 11px/1 var(--mono); color: var(--prof-color, var(--accent)); margin-top: 6px; }
.profile-card .pattern { font: 600 9.5px/1 var(--mono); color: var(--text-muted); margin-top: 4px; text-transform: uppercase; letter-spacing: 0.06em; }
.profile-card .chaos-label {
  margin-top: 6px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font: 700 9px/1 var(--mono);
  color: var(--red);
}
.profile-card .chaos-label svg { width: 9px; height: 9px; }

/* chaos toggle */
.chaos-row {
  display: flex;
  align-items: center;
  gap: 12px;
}
.toggle-switch {
  width: 38px;
  height: 20px;
  background: var(--surface3);
  border-radius: 99px;
  position: relative;
  cursor: pointer;
  transition: var(--t);
  flex-shrink: 0;
}
.toggle-switch.on { background: var(--red); }
.toggle-thumb {
  width: 14px;
  height: 14px;
  background: #fff;
  border-radius: 50%;
  position: absolute;
  top: 3px;
  left: 3px;
  transition: var(--t);
}
.toggle-switch.on .toggle-thumb { transform: translateX(18px); }

.chaos-info { display: flex; flex-direction: column; gap: 2px; }
.chaos-info-title { font: 700 12.5px/1.1 var(--sans); }
.chaos-info-desc { font: 500 11px/1.2 var(--sans); color: var(--text-muted); }

.warning-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 9px;
  border-radius: var(--r-sm);
  background: var(--red-dim);
  border: 1px solid var(--red);
  color: var(--red);
  font: 700 10px/1 var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-left: auto;
}

/* test lab cards */
.testlab-row {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 4px;
}
.testcard {
  min-width: 172px;
  width: 172px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-top: 3px solid var(--test-color, var(--accent));
  border-radius: var(--r-md);
  padding: 10px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  cursor: pointer;
  transition: var(--t);
  min-height: 158px;
}
.testcard:hover { border-color: var(--test-color, var(--border3)); }
.testcard .badge {
  align-self: flex-start;
  font: 700 9px/1 var(--mono);
  padding: 3px 6px;
  border-radius: 3px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  background: var(--test-dim);
  color: var(--test-color);
}
.testcard h5 { margin: 0; font-size: 12.5px; font-weight: 700; font-family: var(--sans); }
.testcard p { margin: 0; font-size: 10.5px; color: var(--text-muted); line-height: 1.35; }
.testcard .progress-bar {
  height: 4px;
  background: var(--surface3);
  border-radius: 99px;
  overflow: hidden;
  margin-top: 4px;
}
.testcard .progress-fill {
  height: 100%;
  background: var(--test-color);
  border-radius: 99px;
  transition: width 0.3s;
}
.testcard .progress-pct {
  font: 700 9.5px/1 var(--mono);
  color: var(--test-color);
  text-align: right;
}
.testcard .results {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: auto;
  padding-top: 6px;
  border-top: 1px solid var(--border);
}
.testcard .results .nums { font: 700 10px/1 var(--mono); color: var(--text-sec); }
.testcard .verdict {
  font: 700 9px/1 var(--mono);
  padding: 3px 7px;
  border-radius: 3px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.testcard .verdict.pass { background: var(--green-dim); color: var(--green); }
.testcard .verdict.fail { background: var(--red-dim); color: var(--red); }
.testcard .fail-reason {
  font: 600 8.5px/1.3 var(--mono);
  color: var(--red);
  padding: 4px 6px;
  border-radius: 3px;
  background: var(--red-dim);
  margin-top: 4px;
}

/* ---------- high traffic modal ---------- */
/* .crash-modal-backdrop shares this centering (flex, not transform) so the
   crash card's own pop-in animation can own `transform` for its bounce
   without ever fighting a translate(-50%,-50%) position hack - see
   .sf-crash-modal in styles-v3.css. */
.modal-overlay, .crash-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.2s;
}
.high-traffic-card {
  width: 480px;
  background: var(--surface);
  border: 1px solid var(--red);
  border-radius: var(--r-lg);
  padding: 28px;
  box-shadow: 0 0 40px rgba(239, 68, 68, 0.3);
  text-align: center;
}
.high-traffic-card .warn-icon { width: 48px; height: 48px; color: var(--red); margin: 0 auto 14px auto; display: block; }
.high-traffic-card h2 { font: 800 16px/1 var(--mono); color: var(--red); text-transform: uppercase; letter-spacing: 0.1em; margin: 0 0 6px 0; }
.high-traffic-card .sub { font-size: 12px; color: var(--text-sec); margin-bottom: 18px; }
.high-traffic-info {
  background: var(--red-dim);
  border: 1px solid rgba(239, 68, 68, 0.4);
  border-radius: var(--r-md);
  padding: 12px;
  font-size: 11.5px;
  color: var(--text-sec);
  text-align: left;
  margin-bottom: 18px;
}
.high-traffic-info ul { margin: 6px 0 0 18px; padding: 0; color: var(--text-muted); }
.confirm-input {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: var(--r-sm);
  padding: 10px 12px;
  font: 700 13px/1 var(--mono);
  outline: none;
  letter-spacing: 0.1em;
  margin-bottom: 14px;
  text-align: center;
  color: var(--text);
}
.confirm-input.valid { border-color: var(--green); color: var(--green); box-shadow: 0 0 0 2px var(--green-dim); }
.modal-buttons { display: flex; gap: 10px; justify-content: flex-end; }

/* ---------- Shared button classes ---------- */
.btn {
  padding: 9px 16px;
  border-radius: var(--r-sm);
  font: 700 11px/1 var(--sans);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  transition: var(--t);
  border: 1px solid var(--border2);
  background: var(--surface2);
  color: var(--text-sec);
  cursor: pointer;
}
.btn:hover { border-color: var(--border3); color: var(--text); }
.btn-danger { border-color: var(--red); background: var(--red-dim); color: var(--red); }
.btn-danger:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-danger:not(:disabled):hover { box-shadow: 0 0 14px rgba(239,68,68,0.3); }
.btn-primary { border-color: var(--accent); background: var(--accent); color: #fff; font-weight: 700; }
.btn-primary:hover { background: #C44E22; box-shadow: 0 4px 14px rgba(220,90,45,0.35); }
.btn-primary:disabled { opacity: 0.4; cursor: default; }
.btn-ghost { background: transparent; }

/* New Stitch-aligned button classes */
.btn-secondary {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 500;
  padding: 0 12px;
  height: 28px;
  cursor: pointer;
  transition: background 150ms ease;
}
.btn-secondary:hover { background: var(--surface3); }

/* ---------- Input component ---------- */
.sf-input {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-family: var(--mono);
  font-size: 12px;
  padding: 4px 8px;
  height: 28px;
  outline: none;
  width: 100%;
}
.sf-input:focus { border-color: var(--border-md); }

/* ---------- Toggle switch (Stitch style) ---------- */
.sf-toggle {
  position: relative;
  display: inline-block;
  width: 32px;
  height: 16px;
}
.sf-toggle input { opacity: 0; width: 0; height: 0; }
.sf-toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--surface3);
  border-radius: 8px;
  transition: background 200ms ease;
  cursor: pointer;
}
.sf-toggle-slider::before {
  content: '';
  position: absolute;
  width: 12px;
  height: 12px;
  background: #fff;
  border-radius: 50%;
  top: 2px;
  left: 2px;
  transition: transform 200ms ease;
}
.sf-toggle input:checked + .sf-toggle-slider { background: var(--accent); }
.sf-toggle input:checked + .sf-toggle-slider::before { transform: translateX(16px); }

/* ---------- Range slider (Stitch style) ---------- */
input[type=range].sf-range {
  -webkit-appearance: none;
  width: 100%;
  height: 3px;
  background: var(--surface3);
  border-radius: 2px;
  outline: none;
}
input[type=range].sf-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px;
  height: 12px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 0 0 2px var(--accent-dim);
}

/* ---------- Tab badge ---------- */
.tab-badge-standalone {
  background: var(--accent);
  color: #fff;
  font-family: var(--mono);
  font-size: 9px;
  font-weight: 700;
  padding: 1px 4px;
  border-radius: 8px;
  min-width: 14px;
  text-align: center;
}

/* ---------- onboarding ---------- */
.tour-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 950;
}
.tour-card {
  position: fixed;
  background: var(--surface);
  border: 1px solid var(--accent);
  border-radius: var(--r-md);
  padding: 14px;
  width: 280px;
  box-shadow: 0 0 0 4px var(--accent-dim), 0 12px 32px rgba(0,0,0,0.5);
  z-index: 960;
  animation: fadeSlideDown 0.2s ease;
}
.tour-step { font: 700 9.5px/1 var(--mono); color: var(--accent); text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 6px; }
.tour-title { font: 700 14px/1.2 var(--sans); margin: 0 0 6px 0; }
.tour-desc { font-size: 12px; color: var(--text-sec); line-height: 1.45; margin-bottom: 12px; }
.tour-actions { display: flex; justify-content: space-between; align-items: center; }

/* ---------- profile dropdown ---------- */
.profile-dropdown {
  width: 268px;
}
.profile-row-top { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.profile-avatar {
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--surface2); border: 1px solid var(--border2);
  display: flex; align-items: center; justify-content: center;
  font: 700 13px/1 var(--mono); color: var(--accent);
  cursor: pointer; overflow: hidden;
  flex-shrink: 0;
}
.profile-avatar img { width: 100%; height: 100%; object-fit: cover; }
.profile-info { flex: 1; min-width: 0; }
.profile-name-row { display: flex; align-items: center; gap: 6px; }
.profile-name-input {
  background: transparent;
  border: none;
  outline: none;
  font: 700 13px/1.2 var(--sans);
  color: var(--text);
  padding: 0;
  width: 100%;
}
.profile-name-input:focus { background: var(--surface2); padding: 2px 4px; border-radius: 3px; }
.profile-email { font: 500 11px/1.2 var(--mono); color: var(--text-muted); margin-top: 2px; }
.pencil-btn { color: var(--text-muted); width: 14px; height: 14px; cursor: pointer; flex-shrink: 0; }
.pencil-btn:hover { color: var(--accent); }

.premium-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: var(--r-sm);
  background: var(--amber-dim);
  border: 1px solid rgba(245, 158, 11, 0.4);
  color: var(--amber);
  font: 700 11px/1 var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  width: 100%;
  justify-content: center;
}
.premium-badge svg { width: 14px; height: 14px; flex-shrink: 0; }

.activate-row { display: flex; gap: 6px; }
.activate-row input { flex: 1; }

.dropdown-btn-row { display: flex; gap: 6px; }
.dropdown-btn-row .btn { flex: 1; padding: 7px 10px; font-size: 10.5px; }

/* shortcut table */
.shortcut-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  border-bottom: 1px dashed var(--border);
}
.shortcut-row:last-child { border-bottom: none; }
.shortcut-row .desc { font-size: 11.5px; color: var(--text-sec); }
.kbd {
  display: inline-flex;
  align-items: center;
  font: 700 10px/1 var(--mono);
  padding: 3px 6px;
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: 4px;
  color: var(--text);
}

/* misc utilities */
.row { display: flex; align-items: center; gap: 8px; }
.spacer { flex: 1; }
.mono { font-family: var(--mono); }
.muted { color: var(--text-muted); }
.hidden { display: none !important; }

/* ---------- AI / RAG chat tab ---------- */
.rag-messages {
  max-height: 260px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 4px 0 8px 0;
  margin-bottom: 8px;
}
.rag-msg { display: flex; }
.rag-msg.user { justify-content: flex-end; }
.rag-msg.ai   { justify-content: flex-start; }
.rag-bubble {
  max-width: 88%;
  padding: 8px 11px;
  border-radius: 10px;
  font-size: 12px;
  line-height: 1.5;
  word-break: break-word;
}
.rag-msg.user .rag-bubble {
  background: var(--accent-dim);
  border: 1px solid rgba(220,90,45,0.28);
  color: var(--text);
  border-radius: 10px 10px 3px 10px;
}
.rag-msg.ai .rag-bubble {
  background: var(--surface2);
  border: 1px solid var(--border2);
  color: var(--text);
  border-radius: 10px 10px 10px 3px;
}
.rag-bubble.thinking {
  display: flex;
  gap: 5px;
  align-items: center;
  padding: 10px 14px;
  min-width: 52px;
}
.rag-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: ragBlink 1.4s infinite ease-in-out;
}
.rag-dot:nth-child(2) { animation-delay: 0.18s; }
.rag-dot:nth-child(3) { animation-delay: 0.36s; }
@keyframes ragBlink {
  0%, 80%, 100% { opacity: 0.25; transform: scale(0.75); }
  40%           { opacity: 1;    transform: scale(1.1); }
}
.rag-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 6px 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
}
.rag-input-row {
  display: flex;
  gap: 7px;
  align-items: center;
}
