/* Flow Editor — Akompani */

/* ===== Easing ===== */
:root {
  --ease-out-expo: cubic-bezier(0.16, 1, 0.3, 1);
  --editor-surface: rgba(245, 247, 251, 0.94);
  --editor-surface-strong: rgba(255, 255, 255, 0.96);
  --editor-border: rgba(148, 162, 184, 0.34);
  /* Static shadow — matches hero-title style */
  --static-shadow: 0 6px 0 rgba(183, 169, 187, 0.28);
  --static-shadow-sm: 0 3px 0 rgba(183, 169, 187, 0.22);
  --static-shadow-lg: 0 8px 0 rgba(183, 169, 187, 0.24);
  /* Scratch block card surface */
  --scratch-card-bg: #ffffff;
  --scratch-card-border: rgba(0, 0, 0, 0.08);
  --scratch-arm-cavity: rgba(0, 0, 0, 0.04);
}

[data-theme="dark"] {
  --editor-surface: rgba(48, 53, 66, 0.95);
  --editor-surface-strong: rgba(58, 63, 78, 0.98);
  --editor-border: rgba(113, 128, 151, 0.42);
  --static-shadow: 0 6px 0 rgba(170, 157, 182, 0.24);
  --static-shadow-sm: 0 3px 0 rgba(170, 157, 182, 0.18);
  --static-shadow-lg: 0 8px 0 rgba(170, 157, 182, 0.20);
  --scratch-card-bg: #2a2d3a;
  --scratch-card-border: rgba(255, 255, 255, 0.08);
  --scratch-arm-cavity: rgba(0, 0, 0, 0.18);
}

/* ===== Nav Overrides ===== */
.editor-nav {
  background: var(--bg-secondary);
  border-bottom: none;
  box-shadow: none;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  height: 40px;
}

[data-theme="dark"] .editor-nav {
  background: var(--bg-secondary);
  border-bottom: none;
  box-shadow: none;
}

.editor-nav .top-nav-inner {
  max-width: none;
  gap: 0;
  padding: 0 12px;
  justify-content: flex-start;
}

/* ===== Pill / Segment Mode Switcher ===== */
.mode-switcher {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-full);
  margin-right: 12px;
  flex-shrink: 0;
}

[data-theme="dark"] .mode-switcher {
  background: color-mix(in srgb, var(--bg-tertiary) 70%, var(--bg));
}

.mode-tab {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 12px;
  height: auto;
  min-height: 0;
  font-family: inherit;
  font-size: 12px;
  font-weight: var(--font-medium);
  color: var(--text-muted);
  text-decoration: none;
  background: transparent;
  border: none;
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: all 200ms ease;
  white-space: nowrap;
  position: relative;
  z-index: 1;
  line-height: 1;
}

.mode-tab:hover {
  color: var(--text-secondary);
}

.mode-tab.active,
.mode-tab[aria-selected="true"] {
  color: var(--text);
  background: var(--bg);
  box-shadow: none;
}

[data-theme="dark"] .mode-tab.active,
[data-theme="dark"] .mode-tab[aria-selected="true"] {
  background: var(--bg-secondary);
  box-shadow: none;
}

.mode-tab:focus-visible {
  background: var(--bg-secondary);
  color: var(--text);
}

.mode-tab svg {
  width: 13px;
  height: 13px;
  opacity: 0.6;
  flex-shrink: 0;
}

.mode-tab.active svg,
.mode-tab[aria-selected="true"] svg {
  opacity: 1;
}

/* ===== Canvas Controls in Nav ===== */
.nav-canvas-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 8px;
}

/* Flow Name Wrapper (anchors dropdown) */
.flow-name-wrap {
  position: relative;
}

/* Flow Name Display */
.flow-name-display {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  height: 26px;
  background: var(--bg-tertiary);
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 150ms ease;
  max-width: 220px;
}

.flow-name-display:hover {
  background: var(--bg-hover);
}

.flow-name-text {
  font-size: 12px;
  font-weight: var(--font-medium);
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.flow-name-caret {
  width: 10px;
  height: 10px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.flow-name-edit {
  font-size: 12px;
  font-weight: var(--font-medium);
  color: var(--text);
  background: var(--bg);
  border: 2px solid var(--brand);
  border-radius: var(--radius-sm);
  padding: 2px 6px;
  height: 22px;
  outline: none;
  min-width: 120px;
  max-width: 200px;
}

/* Flow Dropdown */
.flow-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 240px;
  max-width: 320px;
  max-height: 320px;
  overflow-y: auto;
  background: var(--bg-secondary);
  border: none;
  border-radius: var(--radius-md);
  box-shadow: var(--static-shadow);
  padding: 4px;
  z-index: 100;
  animation: menuFadeIn 150ms var(--ease-out-expo);
}

.flow-dropdown-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 8px 10px;
  font-family: inherit;
  font-size: 12px;
  font-weight: var(--font-medium);
  color: var(--text-secondary);
  background: none;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 120ms ease;
  text-align: left;
}

.flow-dropdown-item:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.flow-dropdown-item.active {
  background: var(--brand-soft, rgba(99, 102, 241, 0.12));
  color: var(--brand);
}

.flow-dropdown-item-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.flow-dropdown-item-time {
  font-size: 10px;
  color: var(--text-muted);
  flex-shrink: 0;
  margin-left: 12px;
}

.flow-dropdown-empty {
  padding: 16px;
  text-align: center;
  font-size: 11px;
  color: var(--text-muted);
}

.nav-canvas-controls .btn-sm {
  padding: 3px 10px;
  font-size: 12px;
  height: 26px;
}

.nav-canvas-controls .btn-icon.btn-sm {
  padding: 3px;
  width: 26px;
  height: 26px;
}

/* ===== Flow Actions Dropdown ===== */
.flow-menu-wrap {
  position: relative;
}

.flow-menu {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 180px;
  background: var(--bg-secondary);
  border: none;
  border-radius: var(--radius-md);
  box-shadow: var(--static-shadow);
  padding: 4px;
  z-index: 100;
  animation: menuFadeIn 150ms var(--ease-out-expo);
}

.flow-menu.is-open {
  display: block;
}

@keyframes menuFadeIn {
  from { opacity: 0; transform: translateY(-4px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.flow-menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 7px 10px;
  font-family: inherit;
  font-size: 12px;
  font-weight: var(--font-medium);
  color: var(--text-secondary);
  background: none;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 120ms ease;
  text-align: left;
}

.flow-menu-item:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.flow-menu-item svg {
  flex-shrink: 0;
  opacity: 0.6;
}

.flow-menu-item:hover svg {
  opacity: 1;
}

.flow-menu-item--danger {
  color: var(--red, #ef4444);
}

.flow-menu-item--danger:hover {
  background: color-mix(in srgb, var(--red, #ef4444) 10%, var(--bg));
  color: var(--red, #ef4444);
}

.flow-menu-divider {
  height: 1px;
  background: var(--bg-tertiary);
  margin: 4px 0;
}

/* ===== Nav Actions (right) ===== */
.editor-nav .nav-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-left: auto;
}

.editor-nav .nav-actions .btn-ghost {
  color: var(--text-muted);
}

.editor-nav .nav-actions .btn-ghost:hover {
  color: var(--text);
  background: var(--bg-tertiary);
}

.editor-nav .nav-actions .btn-icon.btn-sm {
  width: 28px;
  height: 28px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ===== Flow Tabs (VSCode-style) ===== */
.flow-tabs {
  display: flex;
  align-items: center;
  height: 32px;
  background: var(--bg-tertiary);
  border-bottom: none;
  padding: 0;
  overflow: hidden;
  flex-shrink: 0;
}

[data-theme="dark"] .flow-tabs {
  background: var(--bg-tertiary);
}

.flow-tabs-scroll {
  display: flex;
  align-items: stretch;
  height: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  flex: 1;
  min-width: 0;
  scrollbar-width: none;
}

.flow-tabs-scroll::-webkit-scrollbar {
  display: none;
}

.flow-tab {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 12px;
  height: 100%;
  font-family: inherit;
  font-size: 11px;
  font-weight: var(--font-medium);
  color: var(--text-muted);
  background: transparent;
  border: none;
  cursor: pointer;
  white-space: nowrap;
  transition: all 150ms ease;
  position: relative;
  min-width: 0;
  max-width: 160px;
  flex-shrink: 0;
}

.flow-tab:hover {
  color: var(--text-secondary);
  background: var(--bg-hover);
}

.flow-tab.is-active {
  color: var(--text);
  background: var(--bg);
}

.flow-tab.is-active::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: var(--bg);
}

.flow-tab-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.flow-tab-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 3px;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  opacity: 0;
  transition: all 120ms ease;
  flex-shrink: 0;
  font-size: 12px;
  line-height: 1;
  padding: 0;
}

.flow-tab:hover .flow-tab-close,
.flow-tab.is-active .flow-tab-close {
  opacity: 0.6;
}

.flow-tab-close:hover {
  opacity: 1 !important;
  background: var(--bg-tertiary);
  color: var(--text);
}

.flow-tab-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
  opacity: 0;
}

.flow-tab.is-modified .flow-tab-dot {
  opacity: 1;
}

.flow-tab-new {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 100%;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 150ms ease;
  flex-shrink: 0;
}

.flow-tab-new:hover {
  color: var(--text);
  background: var(--bg-hover);
}

.flow-tab-new svg {
  width: 13px;
  height: 13px;
}

/* ===== Editor Main ===== */
.editor-main {
  flex: 1;
  position: relative;
  overflow: hidden;
  isolation: isolate;
  background: var(--bg);
}

.editor-main::before,
.editor-main::after {
  content: "";
  position: absolute;
  pointer-events: none;
  z-index: 0;
}

.editor-main::before {
  display: none;
}

.editor-main::after {
  display: none;
}

.editor-view {
  position: absolute;
  inset: 0;
  z-index: 1;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(14px) scale(0.992);
  transition: opacity 300ms var(--ease-out-expo),
    transform 360ms var(--ease-out-expo),
    visibility 0s linear 360ms;
}

.editor-view.is-active {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateY(0) scale(1);
  transition: opacity 320ms var(--ease-out-expo), transform 420ms var(--ease-out-expo);
}

.settings-view {
  overflow-y: auto;
  background: var(--bg);
}

.settings-view .settings-main {
  padding-top: var(--space-8);
  padding-bottom: var(--space-8);
}

/* ===================================================
   FULL-SCREEN CHAT (ChatGPT-like)
   =================================================== */

.chat-full {
  display: grid;
  grid-template-columns: 1fr 300px;
  min-height: 0;
  height: 100%;
}

body.chat-log-collapsed .chat-full {
  grid-template-columns: 1fr;
}

body.chat-log-collapsed .chat-full-log {
  display: none;
}

.chat-full-center {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--bg);
}

.chat-full-scroll {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.chat-full-messages {
  flex: 1;
  display: flex;
  flex-direction: column;
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
  padding: 24px 24px 0;
  gap: 20px;
}

/* Welcome State */
.chat-full-welcome {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px 20px;
  gap: 8px;
}

.chat-full-welcome h1 {
  font-size: var(--text-2xl);
  font-weight: var(--font-semibold);
  color: var(--text);
  letter-spacing: -0.02em;
}

.chat-full-welcome p {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  max-width: 400px;
}

.chat-welcome-chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 20px;
}

.welcome-chip {
  padding: 8px 16px;
  font-family: inherit;
  font-size: var(--text-xs);
  font-weight: var(--font-medium);
  color: var(--text-secondary);
  background: var(--bg-secondary);
  border: none;
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: all 200ms var(--ease-out-expo);
}

.welcome-chip:hover {
  background: var(--bg-tertiary);
  color: var(--text);
  transform: translateY(-1px);
}

/* Chat Messages */
.chat-msg {
  display: flex;
  gap: 12px;
  max-width: 100%;
  animation: msgSlideIn 0.35s var(--ease-out-expo) both;
}

.chat-msg.user {
  flex-direction: row-reverse;
}

.chat-msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 11px;
  font-weight: var(--font-semibold);
}

.chat-msg.user .chat-msg-avatar {
  background: var(--brand);
  color: white;
}

.chat-msg.assistant .chat-msg-avatar {
  background: var(--bg-tertiary);
  color: var(--text-secondary);
}

.chat-msg-body {
  flex: 1;
  min-width: 0;
}

.chat-msg-role {
  display: block;
  font-size: 11px;
  font-weight: var(--font-semibold);
  color: var(--text-secondary);
  margin-bottom: 2px;
}

.chat-msg.user .chat-msg-role {
  text-align: right;
}

.chat-msg-content {
  font-size: var(--text-sm);
  line-height: 1.6;
  color: var(--text);
  word-break: break-word;
  white-space: pre-wrap;
}

.chat-msg.user .chat-msg-content {
  background: var(--brand);
  color: white;
  padding: 10px 14px;
  border-radius: var(--radius-lg);
  border-bottom-right-radius: 4px;
  display: inline-block;
}

.chat-msg.assistant .chat-msg-content {
  padding: 10px 0;
}

/* Composer */
.chat-full-composer {
  padding: 0 24px 24px;
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
}

.chat-composer-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-secondary);
  border-radius: var(--radius-lg);
  padding: 12px 14px;
  transition: all 200ms var(--ease-out-expo);
}

.chat-composer-wrap:focus-within {
  background: var(--bg-hover);
}

.chat-composer-input {
  flex: 1;
  background: transparent;
  border: none;
  font-family: inherit;
  font-size: var(--text-sm);
  line-height: 1.5;
  color: var(--text);
  resize: none;
  outline: none;
  min-height: 22px;
  max-height: 160px;
}

.chat-composer-input::placeholder {
  color: var(--text-placeholder);
}

.chat-composer-send {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--text);
  color: var(--bg);
  border: none;
  border-radius: var(--radius-full);
  cursor: pointer;
  flex-shrink: 0;
  transition: all 200ms var(--ease-out-expo);
}

.chat-composer-send:hover {
  transform: translateY(-1px);
  box-shadow: var(--static-shadow-sm);
}

[data-theme="dark"] .chat-composer-send {
  background: rgba(99, 102, 241, 0.45);
  color: rgba(255, 255, 255, 0.9);
}

.chat-composer-hint {
  display: none;
}

/* Conversation Log Sidebar */
.chat-full-log {
  background: var(--bg-secondary);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-log-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  min-height: 48px;
  background: var(--bg-tertiary);
}

.chat-log-title {
  font-size: var(--text-xs);
  font-weight: var(--font-semibold);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.chat-log-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.chat-log-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background 150ms ease;
  text-decoration: none;
  color: inherit;
  background: var(--bg-tertiary);
}

.chat-log-item:hover {
  background: var(--bg-hover);
}

.chat-log-item.active {
  background: color-mix(in srgb, var(--brand-soft) 40%, var(--bg-tertiary));
}

.chat-log-item-icon {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
}

.chat-log-item-text {
  flex: 1;
  min-width: 0;
  font-size: var(--text-sm);
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.4;
}

.chat-log-item-time {
  font-size: 11px;
  color: var(--text-muted);
  flex-shrink: 0;
  white-space: nowrap;
}

.chat-log-empty {
  font-size: var(--text-xs);
  color: var(--text-muted);
  text-align: center;
  padding: 40px 16px;
  line-height: 1.6;
}

.chat-log-new-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin: 8px 10px;
  padding: 8px 12px;
  font-family: inherit;
  font-size: var(--text-xs);
  font-weight: var(--font-medium);
  color: var(--text-muted);
  background: var(--bg-tertiary);
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 150ms ease;
  flex-shrink: 0;
}

.chat-log-new-btn:hover {
  color: var(--text);
  background: var(--bg-hover);
}

.chat-log-new-btn svg {
  width: 12px;
  height: 12px;
  flex-shrink: 0;
}

/* ===================================================
   DEPLOY VIEW
   =================================================== */

.deploy-view {
  display: grid;
  grid-template-columns: 1fr 300px;
  min-height: 0;
  height: 100%;
}

.deploy-main {
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 40px;
  background: var(--bg);
}

.deploy-inner {
  max-width: 640px;
  width: 100%;
  margin: 0 auto;
}

.deploy-header {
  margin-bottom: var(--space-10);
}

.deploy-title {
  font-size: var(--text-3xl);
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text);
  margin: 0 0 var(--space-2);
}

.deploy-subtitle {
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

.deploy-section {
  margin-bottom: var(--space-10);
}

.deploy-section-title {
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--text);
  margin: 0 0 var(--space-4);
}

.deploy-card {
  background: var(--bg-secondary);
  border: none;
  border-radius: var(--radius-lg);
  padding: 20px;
}

.deploy-field {
  margin-bottom: 16px;
}

.deploy-field:last-child {
  margin-bottom: 0;
}

.deploy-label {
  display: block;
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  color: var(--text-secondary);
  margin-bottom: var(--space-2);
}

.deploy-field .form-input,
.deploy-field .form-select,
.deploy-field .form-textarea {
  width: 100%;
}

.deploy-actions {
  display: flex;
  gap: 10px;
  margin-top: 24px;
}

.deploy-note {
  margin: 10px 0 0;
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.deploy-inline-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}

.deploy-status {
  font-size: var(--text-sm);
  color: var(--text-muted);
  margin-top: 12px;
}

.deploy-status.success {
  color: var(--success);
}

.deploy-status.error {
  color: var(--error);
}

/* Deploy sidebar */
.deploy-sidebar {
  background: var(--bg-secondary);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.deploy-sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  min-height: 48px;
  background: var(--bg-tertiary);
}

.deploy-sidebar-title {
  font-size: var(--text-sm);
  font-weight: var(--font-semibold);
  color: var(--text);
}

.deploy-sidebar-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.deploy-log-item {
  background: var(--bg-tertiary);
  border: none;
  border-radius: var(--radius-md);
  padding: 10px 12px;
  font-size: var(--text-xs);
  transition: background 150ms ease;
}

.deploy-log-item:hover {
  background: var(--bg-hover);
}

.deploy-log-item-name {
  font-weight: var(--font-medium);
  color: var(--text);
  margin-bottom: 2px;
}

.deploy-log-item-meta {
  color: var(--text-muted);
}

.deploy-log-empty {
  font-size: var(--text-xs);
  color: var(--text-muted);
  text-align: center;
  padding: 24px 12px;
}

/* ===================================================
   CANVAS LAYOUT
   =================================================== */

.canvas-layout {
  display: grid;
  --col-blocks: 280px;
  --col-resL: 4px;
  --col-canvas: 1fr;
  --col-resC: 0px;
  --col-chat: 0px;
  grid-template-areas: "blocks resL canvas resC chat";
  grid-template-columns: var(--col-blocks) var(--col-resL) var(--col-canvas) var(--col-resC) var(--col-chat);
  grid-template-rows: minmax(0, 1fr);
  min-height: 0;
  height: 100%;
  overflow: hidden;
}

.blocks-panel { grid-area: blocks; }
.panel-resize-handle[data-panel="left"] { grid-area: resL; }
.editor-canvas { grid-area: canvas; }
.chat-resize-handle { grid-area: resC; }
.chat-drawer-inline { grid-area: chat; }

body.chat-drawer-open .canvas-layout {
  --col-resC: 4px;
  --col-chat: 360px;
}

/* Flipped: blocks on right side */
body.left-panel-flipped .canvas-layout {
  grid-template-areas: "canvas resL blocks resC chat";
}

/* ===== Panel Resize Handles ===== */
.panel-resize-handle {
  width: 4px;
  cursor: col-resize;
  background: transparent;
  position: relative;
  z-index: 10;
  transition: background 150ms ease;
}

.panel-resize-handle::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: -3px;
  right: -3px;
}

.panel-resize-handle:hover,
.panel-resize-handle.is-dragging {
  background: var(--brand);
}

/* ===== Blocks Panel ===== */
.blocks-panel {
  background: var(--bg-secondary);
  border-right: none;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Panel Tabs */
.panel-tabs {
  display: flex;
  border-bottom: none;
  padding: 0 8px;
  flex-shrink: 0;
  background: var(--bg-tertiary);
}

.panel-tab {
  flex: 1;
  padding: 8px 4px;
  font-size: 11px;
  font-weight: var(--font-semibold);
  color: var(--text-muted);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  text-align: center;
  transition: all 150ms ease;
}

.panel-tab:hover { color: var(--text-secondary); }

.panel-tab.active {
  color: var(--brand);
  border-bottom-color: var(--brand);
}

.panel-tab-content {
  display: none;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.panel-tab-content.active {
  display: flex;
}

.panel-empty-state {
  padding: 24px 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: var(--text-sm);
  line-height: 1.5;
}

.panel-search-results {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

/* Flow Outline */
.flow-outline {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.outline-node {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background 120ms ease;
  font-size: var(--text-sm);
}

.outline-node:hover { background: var(--bg-hover); }
.outline-node.active { background: var(--brand-soft); color: var(--brand); }

.outline-node-icon {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: block;
  overflow: hidden;
  font-size: 0;
  flex-shrink: 0;
}

.outline-node-icon svg,
.outline-node-icon * {
  display: none;
}

.outline-node-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
}

.outline-node-type {
  font-size: 10px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.search-result-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background 120ms ease;
  font-size: var(--text-sm);
}

.search-result-item:hover { background: var(--bg-hover); }

.search-result-flow {
  font-size: 10px;
  color: var(--text-muted);
  margin-left: auto;
  flex-shrink: 0;
}

/* Panel Search */
.panel-search {
  position: relative;
  padding: 12px 16px;
  border-bottom: none;
}

.panel-search input {
  padding-left: 32px;
  background: var(--bg-tertiary);
}

.search-icon {
  position: absolute;
  left: 24px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
  width: 16px;
  height: 16px;
}

/* Palette Content */
.palette-content {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.palette-content > * {
  flex-shrink: 0;
}

/* Palette Groups */
.palette-group {
  background: transparent;
  border-radius: var(--radius-md);
}

.palette-group-head-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 6px 12px;
  background: transparent;
  border: none;
  cursor: pointer;
  font-family: inherit;
  text-align: left;
  color: inherit;
  transition: background 150ms ease;
}

.palette-group-head-btn:hover {
  background: var(--bg-hover);
}

.palette-group-caret {
  width: 12px;
  height: 12px;
  color: var(--text-muted);
  flex-shrink: 0;
  transition: transform 200ms var(--ease-out-expo);
}

.palette-group.collapsed .palette-group-caret {
  transform: rotate(-90deg);
}

.palette-group.collapsed .palette-group-items {
  display: none;
}

.palette-group-label {
  flex: 1;
  font-size: 10px;
  font-weight: var(--font-semibold);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.palette-group-count {
  font-size: 10px;
  color: var(--text-muted);
  opacity: 0.6;
}

.palette-group-items {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 4px 10px 8px;
}


.palette-group-empty {
  padding: 6px 14px;
  font-size: 11px;
  color: var(--text-muted);
  font-style: italic;
}

/* ===== Compact Block Cards (palette) ===== */
.block-item.compact {
  display: flex;
  flex-direction: column;
  border-radius: var(--radius-sm, 6px);
  cursor: grab;
  transition: filter 140ms ease, transform 140ms ease;
  background: var(--scratch-card-bg, #f5f7fb);
  border: none;
  position: relative;
  overflow: hidden;
}

/* Left accent bar */
.block-item.compact::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  background: var(--block-color, #888);
  border-radius: 4px 0 0 4px;
  z-index: 1;
}

.block-item.compact:hover {
  filter: brightness(0.97);
}

[data-theme="dark"] .block-item.compact:hover {
  filter: brightness(1.1);
}

.block-item.compact:active {
  cursor: grabbing;
  transform: scale(0.97);
}

.block-item.compact:focus-visible {
  background: color-mix(in srgb, var(--brand-soft) 40%, var(--scratch-card-bg));
}

/* Palette block: show scratch-block as full replica */
.block-item.compact .scratch-block {
  width: 100%;
  min-width: 0;
  max-width: none;
  background: transparent;
  pointer-events: none;
}

/* Palette: compact preview mode (summary-first, non-editable) */
.block-item.compact .scratch-block-actions,
.block-item.compact .scratch-block-status,
.block-item.compact .scratch-block .scratch-block-vars,
.block-item.compact .scratch-block .scratch-block-fields {
  display: none !important;
}

.block-item.compact .scratch-block-summary {
  display: flex !important;
  padding: 4px 10px 7px;
  gap: 2px 6px;
  font-size: 10.5px;
}

.block-item.compact .scratch-summary-item:nth-child(n + 3) {
  display: none;
}

.block-item.compact .scratch-block {
  border: 1px solid color-mix(in srgb, var(--block-color, var(--border)) 24%, transparent);
  border-radius: var(--radius-sm, 6px);
}

.block-item.compact .scratch-block-header {
  padding: 6px 10px 5px 12px;
  border-bottom: 1px solid color-mix(in srgb, var(--block-color, var(--border)) 18%, transparent);
}

.block-item.compact .scratch-block-ports {
  padding: 2px 10px 6px;
  font-size: 9px;
  opacity: 0.72;
}

/* Palette: fields are hidden in compact mode, keep reduced typography for future toggles */
.block-item.compact .scratch-input,
.block-item.compact .scratch-select,
.block-item.compact .scratch-textarea,
.block-item.compact .scratch-textarea-preview {
  font-size: 10.5px;
  padding: 3px 6px;
  min-height: 22px;
  cursor: grab;
}

.block-item.compact .scratch-pill {
  font-size: 9.5px;
  padding: 2px 7px;
  cursor: grab;
}

.block-item.compact .scratch-field-label {
  font-size: 10.5px;
}

.block-item.compact .scratch-field {
  min-height: 24px;
  gap: 6px;
}

/* ===== Layout Toggle Buttons (VSCode-style) ===== */
.layout-toggles {
  display: none;
  align-items: center;
  gap: 0;
  margin-right: 2px;
}

body[data-editor-mode="canvas"] .layout-toggles {
  display: flex;
}

.layout-toggle-btn {
  width: 26px !important;
  height: 26px !important;
  padding: 0 !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  color: var(--text-muted);
  transition: color 150ms ease, background 150ms ease;
}

.layout-toggle-btn:hover {
  color: var(--text);
  background: var(--bg-tertiary);
}

.layout-toggle-btn.is-collapsed {
  color: var(--text-muted);
  opacity: 0.55;
}

.layout-toggle-btn.is-collapsed:hover {
  opacity: 1;
}

/* ===== Left Collapsed State ===== */
body.left-collapsed .canvas-layout {
  --col-blocks: 44px;
  --col-resL: 0px;
}

body.left-collapsed .blocks-panel {
  min-width: 0;
  overflow: hidden;
  cursor: pointer;
  position: relative;
}

body.left-collapsed .blocks-panel .panel-tabs,
body.left-collapsed .blocks-panel .panel-tab-content,
body.left-collapsed .blocks-panel .panel-search {
  display: none;
}

body.left-collapsed .blocks-panel::after {
  content: "BLOCKS";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) rotate(-90deg);
  font-size: var(--text-xs);
  font-weight: var(--font-semibold);
  letter-spacing: 0.05em;
  color: var(--text-muted);
  white-space: nowrap;
  pointer-events: none;
}

body.left-collapsed .panel-resize-handle[data-panel="left"] {
  display: none;
}

/* ===== Canvas Area ===== */
.editor-canvas {
  position: relative;
  background:
    radial-gradient(circle, rgba(164, 184, 205, 0.2) 0.7px, transparent 0.7px),
    var(--bg);
  background-size: 22px 22px, 100% 100%;
  overflow: hidden;
}

[data-theme="dark"] .editor-canvas {
  background:
    radial-gradient(circle, rgba(113, 128, 151, 0.12) 0.7px, transparent 0.7px),
    var(--bg);
  background-size: 22px 22px, 100% 100%;
}

.canvas-toolbar {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  z-index: 12;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  pointer-events: none;
}

.canvas-toolbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  pointer-events: auto;
}

.canvas-toolbar-btn {
  border: none;
  background: var(--bg-secondary);
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: var(--font-medium);
  font-family: var(--font-mono);
  padding: 6px 10px;
  border-radius: var(--radius-md);
  cursor: pointer;
  white-space: nowrap;
  transition: background 150ms ease, color 150ms ease, transform 150ms ease;
  box-shadow: var(--static-shadow-sm);
}

.canvas-toolbar-btn:hover {
  background: var(--bg-hover);
  color: var(--text);
  transform: translateY(-1px);
}

.canvas-shortcuts {
  font-size: 10px;
  font-family: var(--font-mono);
  color: var(--text-muted);
  background: var(--bg-secondary);
  padding: 4px 10px;
  border-radius: var(--radius-md);
  white-space: nowrap;
  box-shadow: var(--static-shadow-sm);
}

.canvas-shortcuts kbd {
  font-family: inherit;
  font-size: 10px;
  padding: 1px 4px;
  background: var(--bg-secondary);
  border-radius: 3px;
  color: var(--text-secondary);
}

.scratch-canvas {
  width: 100%;
  height: 100%;
  position: relative;
}

/* ===== Zoom Controls ===== */
.canvas-zoom {
  position: absolute;
  bottom: 12px;
  left: 12px;
  z-index: 11;
  display: flex;
  align-items: center;
  gap: 2px;
  background: var(--bg-secondary);
  border: none;
  border-radius: var(--radius-md);
  padding: 3px;
  box-shadow: var(--static-shadow-sm);
}

.canvas-zoom-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  background: none;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 120ms ease;
}

.canvas-zoom-btn:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.canvas-zoom-btn.is-active {
  background: var(--brand-soft, rgba(99, 102, 241, 0.12));
  color: var(--brand);
}

.canvas-zoom-level {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: var(--font-medium);
  color: var(--text-muted);
  min-width: 40px;
  text-align: center;
  user-select: none;
}

.canvas-zoom-sep {
  width: 1px;
  height: 16px;
  background: var(--bg-tertiary);
  margin: 0 2px;
}

/* Minimap removed */

/* ===== ScratchCanvas Overrides ===== */
.scratch-canvas {
  width: 100%;
  height: 100%;
  position: relative;
  overflow: hidden;
}

.scratch-svg {
  cursor: grab;
}
.scratch-svg:active {
  cursor: grabbing;
}

.scratch-node {
  cursor: grab;
  transition: opacity 120ms ease;
}
.scratch-node:active {
  cursor: grabbing;
}
.scratch-node.selected .scratch-shape {
  stroke: var(--brand, #6366f1);
  stroke-width: 2;
}
.scratch-node.selected .scratch-accent {
  opacity: 1;
}

.scratch-fo-body {
  pointer-events: auto;
}

/* Snap preview line */
.scratch-snap-preview {
  pointer-events: none;
  transition: opacity 150ms ease;
}

/* Dragging state */
.scratch-node.dragging {
  opacity: 0.85;
}

/* ===== Static Asset Manager ===== */
.asset-manager {
  border-top: 1px solid var(--scratch-card-border, rgba(0,0,0,0.08));
  padding-top: 6px;
  margin-top: 4px;
}
.asset-manager-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  font-weight: 600;
  margin-bottom: 4px;
  color: var(--text-secondary, #888);
}
.asset-size { font-weight: 400; }
.asset-file-list {
  max-height: 120px;
  overflow-y: auto;
  margin-bottom: 4px;
}
.asset-file-row {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 2px 4px;
  font-size: 11px;
  border-radius: 3px;
}
.asset-file-row:hover { background: var(--bg-hover, rgba(0,0,0,0.04)); }
.asset-file-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--mono, monospace);
}
.asset-file-type {
  color: var(--text-secondary, #888);
  font-size: 10px;
}
.asset-file-delete {
  width: 18px;
  height: 18px;
  padding: 0;
  font-size: 13px;
  line-height: 1;
  opacity: 0;
  transition: opacity 120ms;
}
.asset-file-row:hover .asset-file-delete { opacity: 0.7; }
.asset-file-delete:hover { opacity: 1 !important; color: #ef476f; }
.asset-empty {
  font-size: 11px;
  color: var(--text-secondary, #888);
  text-align: center;
  padding: 8px 0;
}
.asset-upload-btn {
  display: block;
  text-align: center;
  font-size: 11px;
  padding: 4px 8px;
  border-radius: 4px;
  cursor: pointer;
  color: var(--brand, #6366f1);
  border: 1px dashed var(--brand, #6366f1);
  opacity: 0.7;
  transition: opacity 120ms;
}
.asset-upload-btn:hover { opacity: 1; }

/* ===== Code Preview Panel (Bottom) ===== */
.code-preview-panel {
  grid-area: canvas;
  align-self: end;
  position: relative;
  z-index: 12;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: height var(--dur-base) var(--ease-smooth);
}
.code-preview-panel.collapsed { height: 0 !important; border-top: none; }
.code-preview-resize {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  cursor: ns-resize;
  z-index: 10;
  background: transparent;
}
.code-preview-resize:hover { background: var(--brand); opacity: 0.38; }
.code-preview-toolbar {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 0 8px;
  flex-shrink: 0;
  background: var(--bg-tertiary);
}
.code-preview-tab {
  padding: 8px 10px;
  cursor: pointer;
  font-size: 11px;
  font-weight: var(--font-semibold);
  font-family: var(--font-mono);
  color: var(--text-muted);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  transition: color var(--dur-fast) ease;
}
.code-preview-tab:hover { color: var(--text-secondary); }
.code-preview-tab.active {
  color: var(--brand);
  border-bottom-color: var(--brand);
}
.code-preview-actions {
  margin-left: auto;
  display: flex;
  gap: 4px;
}
.code-preview-actions button {
  font-size: 11px;
  font-weight: var(--font-medium);
  padding: 3px 10px;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: background var(--dur-fast) ease, color var(--dur-fast) ease;
}
.code-preview-actions button:hover { color: var(--text); background: var(--bg-hover); }
.code-preview-body {
  flex: 1;
  overflow: auto;
  padding: 12px 16px;
  background: var(--bg);
}
.code-preview-body pre {
  margin: 0;
  font-size: 12px;
  line-height: 1.6;
  font-family: var(--font-mono);
  white-space: pre;
  tab-size: 2;
  color: var(--text);
}
/* Syntax highlight — light-friendly palette */
.code-preview-body .kw { color: #7c3aed; }
.code-preview-body .str { color: #0f8f67; }
.code-preview-body .cmt { color: var(--text-muted); font-style: italic; }
.code-preview-body .num { color: #bc7708; }
.code-preview-body .fn { color: #2563eb; }
/* Dark theme overrides */
[data-theme="dark"] .code-preview-body .kw { color: #cba6f7; }
[data-theme="dark"] .code-preview-body .str { color: #a6e3a1; }
[data-theme="dark"] .code-preview-body .num { color: #fab387; }
[data-theme="dark"] .code-preview-body .fn { color: #89b4fa; }

/* ===== Editor Panel (Right) ===== */
.editor-panel {
  background: var(--bg-secondary);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Inspector removed — inline Scratch blocks instead */

/* Form Sections */
.form-sections { display: flex; flex-direction: column; gap: 16px; }
.form-fields { display: flex; flex-direction: column; gap: 16px; }

.form-section {
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
  padding: 12px;
}

.form-section-title {
  font-size: var(--text-xs);
  font-weight: var(--font-semibold);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  margin: 0 0 12px;
}

.form-field { margin-bottom: 12px; }
.form-field:last-child { margin-bottom: 0; }

.form-field label {
  display: block;
  font-size: var(--text-xs);
  font-weight: var(--font-medium);
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.form-field input,
.form-field select,
.form-field textarea { width: 100%; }

.field-help { font-size: var(--text-xs); color: var(--text-muted); margin-top: 4px; line-height: 1.4; }
.field-example { font-size: var(--text-xs); color: var(--brand); margin-top: 2px; }

.field-input-wrap { display: flex; flex-direction: column; gap: 4px; }

.field-preset-list { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }

.field-preset {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-secondary);
  background: var(--bg-tertiary);
  padding: 2px 7px;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  transition: all 150ms ease;
}

.field-preset:hover { background: var(--brand); color: white; border-color: var(--brand); }

/* Field pill group (inline select alternative) */
.field-pill-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0;
  background: var(--bg-tertiary);
  border-radius: var(--radius-md);
  padding: 2px;
  border: none;
}

.field-pill {
  flex: 1;
  min-width: 0;
  padding: 4px 8px;
  font-size: 11px;
  font-weight: var(--font-medium);
  color: var(--text-secondary);
  background: none;
  border: none;
  border-radius: calc(var(--radius-md) - 2px);
  cursor: pointer;
  text-align: center;
  transition: all 120ms ease;
  white-space: nowrap;
}

.field-pill:hover { color: var(--text); background: var(--bg-hover); }

.field-pill.active {
  color: var(--text);
  background: var(--bg);
  box-shadow: var(--static-shadow-sm);
  font-weight: var(--font-semibold);
}

/* Field mode badge */
.field-mode-badge {
  display: inline-block;
  margin-left: 6px;
  font-size: 9px;
  font-weight: var(--font-medium);
  color: var(--brand);
  background: var(--brand-soft);
  padding: 1px 5px;
  border-radius: var(--radius-sm);
  text-transform: lowercase;
  vertical-align: middle;
}

/* Code textarea */
.code-textarea {
  font-family: var(--font-mono) !important;
  font-size: 12px !important;
  line-height: 1.5 !important;
  tab-size: 2;
  white-space: pre;
  resize: vertical;
  min-height: 120px;
}

/* Variable Hints */
.shortcuts-list { display: flex; flex-wrap: wrap; gap: 6px; }

.hint-head { font-size: var(--text-xs); font-weight: var(--font-semibold); color: var(--text-secondary); margin-bottom: 6px; }
.hint-empty { font-size: var(--text-xs); color: var(--text-muted); font-style: italic; }
.hint-list { display: flex; flex-wrap: wrap; gap: 5px; }

.hint-chip {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-secondary);
  background: var(--bg-tertiary);
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  transition: all 150ms ease;
}

.hint-chip:hover { background: var(--brand); color: white; }

.var-chip {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-secondary);
  background: var(--bg-tertiary);
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  transition: all 150ms ease;
}

.var-chip:hover { background: var(--brand); color: white; }

/* JSON KV Editor */
.json-kv-editor { display: flex; flex-direction: column; gap: 6px; }
.json-kv-list { display: flex; flex-direction: column; gap: 4px; }

.json-kv-row {
  display: grid;
  grid-template-columns: 1fr auto 1.2fr auto;
  align-items: center;
  gap: 4px;
}

.json-kv-key, .json-kv-value {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  padding: 5px 8px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--bg-tertiary);
  color: var(--text);
  outline: none;
  transition: background 150ms ease;
}

.json-kv-key:focus, .json-kv-value:focus { background: var(--bg-hover); }
.json-kv-sep { font-size: var(--text-xs); color: var(--text-muted); text-align: center; }

.json-kv-remove {
  font-size: 10px;
  color: var(--error);
  background: none;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  padding: 3px 6px;
  transition: all 150ms ease;
}

.json-kv-remove:hover { background: var(--red-soft); }
.json-kv-actions { display: flex; gap: 4px; }

.json-kv-add {
  font-size: var(--text-xs);
  font-weight: var(--font-medium);
  color: var(--brand);
  background: var(--bg-tertiary);
  border: none;
  border-radius: var(--radius-sm);
  padding: 4px 10px;
  cursor: pointer;
  transition: all 150ms ease;
}

.json-kv-add:hover { background: var(--brand-light); }

/* Run Status / Events */
.run-status { padding: 0 16px 12px; font-size: var(--text-xs); font-family: var(--font-mono); }
.run-status.success { color: var(--success); }
.run-status.error { color: var(--error); }

.events-output {
  margin: 0 16px 16px;
  padding: 10px;
  background: var(--bg-tertiary);
  border: none;
  border-radius: var(--radius-md);
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1.5;
  max-height: 160px;
  overflow-y: auto;
  color: var(--text-secondary);
}


/* Runtime State */
.runtime-state-display {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-secondary);
  line-height: 1.5;
}

.runtime-state-display pre { margin: 0; white-space: pre-wrap; word-break: break-all; }

/* ===== Old Node Card Components — replaced by Scratch blocks ===== */

.info-chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-secondary);
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  font-size: 10px;
}

.info-chip-label { color: var(--text-muted); }
.info-chip-value { color: var(--text); font-weight: var(--font-medium); }

/* Canvas State */
.drag-over { background: color-mix(in srgb, var(--brand-soft) 20%, var(--bg)) !important; }

/* ===== Generate Overlay ===== */
.generate-overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,0.5);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  animation: overlayFadeIn 0.3s var(--ease-out-expo) both;
}

[data-theme="dark"] .generate-overlay { background: rgba(0,0,0,0.4); }

.generate-card {
  background: var(--bg-secondary);
  border-radius: 20px;
  box-shadow: var(--static-shadow-lg);
  padding: 40px;
  max-width: 520px;
  width: 100%;
  text-align: center;
  animation: cardScaleIn 0.35s var(--ease-out-expo) both;
}

.generate-title { font-size: 1.5rem; font-weight: var(--font-semibold); color: var(--text); margin: 0 0 6px; }
.generate-subtitle { font-size: var(--text-sm); color: var(--text-muted); margin: 0 0 20px; }

.generate-textarea {
  width: 100%;
  min-height: 100px;
  padding: 12px 14px;
  font-family: inherit;
  font-size: var(--text-sm);
  border: none;
  border-radius: var(--radius-md);
  background: var(--bg-secondary);
  color: var(--text);
  resize: vertical;
  outline: none;
  transition: background 150ms ease;
  box-sizing: border-box;
}

.generate-textarea:focus { background: var(--bg-tertiary); }

.generate-submit { margin-top: 16px; width: 100%; padding: 12px; font-size: var(--text-sm); font-weight: var(--font-semibold); }
.generate-btn-loading { display: inline-flex; align-items: center; gap: 6px; }
.generate-spinner { animation: spin 1s linear infinite; }

@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }

.generate-examples { margin-top: 16px; display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 6px; }
.generate-examples-label { font-size: var(--text-xs); color: var(--text-muted); }

.generate-example-chip {
  font-size: var(--text-xs);
  color: var(--text-secondary);
  background: var(--bg-secondary);
  border: none;
  border-radius: var(--radius-full);
  padding: 5px 12px;
  cursor: pointer;
  transition: all 200ms var(--ease-out-expo);
}

.generate-example-chip:hover { color: var(--brand); background: var(--brand-light); }
.generate-error { margin-top: 12px; font-size: var(--text-xs); color: var(--error); text-align: center; }
.generate-templates-link { margin-top: 8px; text-align: center; display: flex; align-items: center; justify-content: center; gap: 8px; }

/* ===== Template Gallery Overlay ===== */
.template-gallery-overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,0.5);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  animation: overlayFadeIn 0.3s var(--ease-out-expo) both;
}
[data-theme="dark"] .template-gallery-overlay { background: rgba(0,0,0,0.4); }

.template-gallery-card {
  background: var(--bg);
  border-radius: 20px;
  box-shadow: var(--static-shadow-lg);
  padding: 32px;
  max-width: 680px;
  width: 100%;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  animation: cardScaleIn 0.35s var(--ease-out-expo) both;
}
.template-gallery-header {
  text-align: center;
  margin-bottom: 20px;
  position: relative;
}
.template-gallery-title {
  font-size: 1.5rem;
  font-weight: var(--font-semibold);
  color: var(--text);
  margin: 0 0 6px;
}
.template-gallery-subtitle {
  font-size: var(--text-sm);
  color: var(--text-muted);
  margin: 0;
}
.template-gallery-close {
  position: absolute;
  top: 0;
  right: 0;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: var(--radius-sm);
  transition: all 150ms ease;
}
.template-gallery-close:hover {
  color: var(--text);
  background: var(--bg-hover);
}
.template-gallery-filters {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  margin-bottom: 20px;
}
.template-filter-pill {
  padding: 5px 14px;
  font-family: inherit;
  font-size: var(--text-xs);
  font-weight: var(--font-medium);
  color: var(--text-secondary);
  background: var(--bg-secondary);
  border: none;
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: all 200ms var(--ease-out-expo);
}
.template-filter-pill:hover {
  background: var(--bg-tertiary);
  color: var(--text);
}
.template-filter-pill.active {
  background: var(--text);
  color: var(--bg);
}
[data-theme="dark"] .template-filter-pill.active {
  background: var(--brand);
  color: #fff;
}
.template-gallery-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  overflow-y: auto;
  padding-right: 4px;
}
.template-card {
  background: var(--bg-secondary);
  border-radius: var(--radius-lg);
  padding: 16px;
  cursor: pointer;
  transition: all 200ms var(--ease-out-expo);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.template-card:hover {
  background: var(--bg-tertiary);
  transform: translateY(-2px);
  box-shadow: var(--static-shadow-sm);
}
.template-card--blank {
  border: 2px dashed var(--border, var(--bg-tertiary));
  background: transparent;
  align-items: center;
  justify-content: center;
  min-height: 120px;
}
.template-card--blank:hover {
  border-color: var(--text-muted);
  background: var(--bg-secondary);
}
.template-card-head {
  display: flex;
  align-items: center;
  gap: 10px;
}
.template-card-icon {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: #fff;
}
.template-card-icon svg { width: 16px; height: 16px; }
.template-card-meta { flex: 1; min-width: 0; }
.template-card-name {
  font-size: var(--text-sm);
  font-weight: var(--font-semibold);
  color: var(--text);
  margin: 0;
  line-height: 1.3;
}
.template-card-desc {
  font-size: var(--text-xs);
  color: var(--text-muted);
  line-height: 1.4;
  margin: 0;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.template-card-footer {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: auto;
}
.template-card-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  font-size: 10px;
  font-weight: var(--font-medium);
  border-radius: var(--radius-full);
  text-transform: capitalize;
}
.template-card-badge--beginner    { background: var(--blue-soft);   color: var(--blue); }
.template-card-badge--intermediate { background: var(--purple-soft); color: var(--purple); }
.template-card-badge--advanced    { background: var(--orange-soft); color: var(--orange); }
.template-card-nodes {
  font-size: 10px;
  color: var(--text-muted);
  margin-left: auto;
}
.template-blank-icon { color: var(--text-muted); margin-bottom: 6px; }
.template-blank-label {
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  color: var(--text-muted);
}

@media (max-width: 600px) {
  .template-gallery-grid { grid-template-columns: 1fr; }
  .template-gallery-card { max-width: 95%; padding: 20px; }
}

/* ===== Welcome Guide Overlay ===== */
.welcome-guide-overlay {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal, 300);
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,0.5);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  animation: overlayFadeIn 0.3s var(--ease-out-expo) both;
}
[data-theme="dark"] .welcome-guide-overlay { background: rgba(0,0,0,0.4); }

.welcome-guide-card {
  background: var(--bg-secondary);
  border-radius: 20px;
  box-shadow: var(--static-shadow-lg);
  padding: 36px 32px 28px;
  max-width: 460px;
  width: 100%;
  text-align: center;
  animation: cardScaleIn 0.35s var(--ease-out-expo) both;
}
.welcome-guide-title {
  font-size: 1.5rem;
  font-weight: var(--font-semibold);
  color: var(--text);
  margin: 0 0 6px;
}
.welcome-guide-subtitle {
  font-size: var(--text-sm);
  color: var(--text-muted);
  margin: 0 0 24px;
}
.welcome-guide-steps {
  display: flex;
  flex-direction: column;
  gap: 14px;
  text-align: left;
  margin-bottom: 24px;
}
.welcome-guide-step {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}
.welcome-guide-step-num {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--brand, var(--blue));
  color: #fff;
  font-size: var(--text-xs);
  font-weight: var(--font-semibold);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 1px;
}
.welcome-guide-step-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.welcome-guide-step-body strong {
  font-size: var(--text-sm);
  font-weight: var(--font-semibold);
  color: var(--text);
}
.welcome-guide-step-body span {
  font-size: var(--text-xs);
  color: var(--text-muted);
  line-height: 1.45;
}
.welcome-guide-btn {
  width: 100%;
  padding: 10px 0;
}

@media (max-width: 500px) {
  .welcome-guide-card { max-width: 95%; padding: 24px 20px 20px; }
}

/* ===== Hover Card ===== */
.palette-hover-card {
  position: fixed;
  z-index: 1000;
  max-width: 280px;
  background: var(--bg-secondary);
  border: none;
  border-radius: 14px;
  padding: 12px;
  box-shadow: var(--static-shadow);
  opacity: 0;
  transform: translateX(-8px);
  transition: all 200ms var(--ease-out-expo);
  pointer-events: none;
}

.palette-hover-card.visible { opacity: 1; transform: translateX(0); }

.palette-hover-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; position: relative; }
.palette-hover-title-wrap { flex: 1; min-width: 0; }
.palette-hover-title { font-size: var(--text-sm); font-weight: var(--font-semibold); color: var(--text); }
.palette-hover-sub { font-size: var(--text-xs); color: var(--text-muted); }
.palette-hover-orbit { position: absolute; top: -4px; right: -4px; width: 8px; height: 8px; border-radius: var(--radius-full); background: var(--brand); opacity: 0.5; }
.palette-hover-desc { font-size: var(--text-sm); color: var(--text-secondary); line-height: 1.5; margin-bottom: 10px; }

.palette-hover-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 10px; }
.palette-hover-stat { background: var(--bg-secondary); border-radius: var(--radius-sm); padding: 6px; text-align: center; font-size: var(--text-xs); color: var(--text-muted); }
.palette-hover-stat strong { display: block; font-size: var(--text-sm); font-weight: var(--font-semibold); color: var(--text); margin-bottom: 2px; }
.palette-hover-section { font-size: var(--text-xs); font-weight: var(--font-semibold); text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-secondary); margin-bottom: 6px; }
.palette-hover-defaults { display: flex; flex-direction: column; gap: 4px; }
.palette-hover-default-row { display: flex; justify-content: space-between; gap: 8px; font-size: var(--text-xs); padding: 3px 0; }
.palette-hover-default-row .k { color: var(--text-muted); }
.palette-hover-default-row .v { color: var(--text); font-family: var(--font-mono); text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 160px; }
.palette-hover-empty { font-size: var(--text-xs); color: var(--text-muted); font-style: italic; }

/* ===================================================
   FLOATING CHAT PILL
   =================================================== */

/* ===== Chat Drawer (in-grid) ===== */
.chat-drawer-inline {
  display: none;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-secondary);
}

body.chat-drawer-open .chat-drawer-inline {
  display: flex;
}

.chat-resize-handle {
  display: none;
}

body.chat-drawer-open .chat-resize-handle {
  display: block;
}

.chat-drawer-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.chat-drawer-empty {
  font-size: 11px;
  color: var(--text-muted);
  text-align: center;
  padding: 44px 16px;
  line-height: 1.6;
}

.chat-drawer-messages .chat-msg {
  gap: 10px;
  animation-duration: 0.22s;
}

.chat-drawer-messages .chat-msg-avatar {
  width: 22px;
  height: 22px;
  font-size: 10px;
}

.chat-drawer-messages .chat-msg-content {
  font-size: var(--text-xs);
  line-height: 1.55;
}

.chat-drawer-messages .chat-msg-role {
  font-size: 10px;
  margin-bottom: 3px;
}

.chat-drawer-messages .chat-msg.user .chat-msg-content {
  padding: 8px 11px;
  border-radius: var(--radius-md);
  border-bottom-right-radius: 4px;
}

.chat-drawer-messages .chat-msg.assistant .chat-msg-content {
  padding: 8px 10px;
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
  border-bottom-left-radius: 4px;
  display: inline-block;
}

/* Agentic indicators */
.chat-msg-thinking {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  color: var(--text-muted);
  font-size: var(--text-xs);
}

.chat-drawer-messages .chat-msg-thinking {
  font-size: 11px;
  padding: 6px 6px;
}

.thinking-dots {
  display: flex;
  gap: 3px;
}

.thinking-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: thinkingBounce 1.4s infinite both;
}

.thinking-dot:nth-child(2) { animation-delay: 0.16s; }
.thinking-dot:nth-child(3) { animation-delay: 0.32s; }

@keyframes thinkingBounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

.chat-msg-step {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  font-size: var(--text-xs);
  color: var(--brand);
  background: var(--brand-soft, rgba(99, 102, 241, 0.08));
  border-radius: var(--radius-md);
}

.chat-drawer-composer {
  padding: 10px 12px 12px;
  background: var(--bg-tertiary);
  flex-shrink: 0;
}

.chat-drawer-composer-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-lg);
  min-height: 40px;
  padding: 8px 10px;
  transition: background 200ms var(--ease-out-expo);
}

.chat-drawer-composer-wrap:focus-within {
  background: var(--bg-hover);
}

.chat-drawer-input {
  flex: 1;
  min-height: 20px;
  max-height: 120px;
  margin: 0;
  padding: 1px 0;
  font-family: inherit;
  font-size: var(--text-sm);
  line-height: 1.5;
  border: none;
  background: transparent;
  color: var(--text);
  resize: none;
  outline: none;
}

.chat-drawer-input::placeholder {
  color: var(--text-placeholder);
}

.chat-drawer-send {
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  align-self: center;
  background: var(--text);
  color: var(--bg);
  border: none;
  border-radius: var(--radius-full);
  cursor: pointer;
  flex-shrink: 0;
  transition: all 200ms var(--ease-out-expo);
}

.chat-drawer-send:hover {
  transform: translateY(-1px);
  box-shadow: var(--static-shadow-sm);
}

[data-theme="dark"] .chat-drawer-send {
  background: rgba(99, 102, 241, 0.45);
  color: rgba(255, 255, 255, 0.9);
}

[data-theme="dark"] .chat-drawer-composer {
  background: var(--bg-secondary);
}

/* ===================================================
   ANIMATIONS
   =================================================== */

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

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

@keyframes contentFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes overlayFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes cardScaleIn {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

/* Entrance animations */
.anim-in {
  opacity: 0;
  transform: translateY(20px);
  animation: editorFadeIn 0.6s var(--ease-out-expo) forwards;
}

.anim-d1 { animation-delay: 0.08s; }
.anim-d2 { animation-delay: 0.14s; }
.anim-d3 { animation-delay: 0.20s; }
.anim-d4 { animation-delay: 0.26s; }
.anim-d5 { animation-delay: 0.32s; }

@media (prefers-reduced-motion: reduce) {
  .editor-view,
  .nav-canvas-controls,
  .chat-drawer,
  .chat-drawer-panel {
    transition: none !important;
    transform: none !important;
    animation: none !important;
  }
}

/* ===== Responsive ===== */
@media (max-width: 1320px) {
  .nav-canvas-controls.is-visible { max-width: 520px; }
  #flowName { min-width: 110px; }
}

@media (max-width: 1200px) {
  .canvas-layout { --col-blocks: 220px; }
  body.chat-drawer-open .canvas-layout { --col-chat: 300px; }
  .chat-full { grid-template-columns: 1fr 260px; }
  .deploy-view { grid-template-columns: 1fr 260px; }
  .canvas-shortcuts { display: none; }
}

@media (max-width: 1024px) {
  .editor-nav .top-nav-inner {
    padding: 0 8px;
  }

  .canvas-layout {
    --col-blocks: 0px; --col-resL: 0px;
    --col-resC: 0px; --col-chat: 0px;
    grid-template-columns: var(--col-blocks) var(--col-resL) var(--col-canvas) var(--col-resC) var(--col-chat);
  }
  .blocks-panel, .panel-resize-handle, .chat-drawer-inline, .chat-resize-handle { display: none !important; }
  .chat-full { grid-template-columns: 1fr; }
  .chat-full-log { display: none; }
  .deploy-view { grid-template-columns: 1fr; }
  .deploy-sidebar { display: none; }
  .nav-canvas-controls {
    display: none !important;
  }
  .layout-toggles {
    display: none;
  }
}

@media (max-width: 760px) {
  .mode-tab span {
    display: none;
  }

  .mode-tab {
    padding: 4px 8px;
  }

  .mode-switcher {
    margin-right: 8px;
  }
}

/* ── Deploy Method Tabs ── */
.deploy-method-tabs {
  display: flex;
  gap: var(--space-1);
  background: var(--bg-tertiary);
  padding: 3px;
  border-radius: var(--radius-md);
  margin-bottom: var(--space-4);
}

.deploy-method-tab {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  border-radius: calc(var(--radius-md) - 2px);
  cursor: pointer;
  transition: all 200ms ease;
}

.deploy-method-tab:hover {
  color: var(--text);
}

.deploy-method-tab.active {
  background: var(--bg-secondary);
  color: var(--text);
  box-shadow: var(--static-shadow-sm);
}

.deploy-method-panel {
  animation: contentFadeIn 0.3s var(--ease-smooth);
}

.deploy-missing {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3);
  background: color-mix(in srgb, var(--warning) 8%, var(--bg-tertiary));
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  color: var(--warning);
  margin-bottom: var(--space-3);
}

.deploy-missing a {
  color: var(--brand);
  text-decoration: underline;
}

/* ===== Dark mode overrides ===== */
[data-theme="dark"] .editor-main {
  background: var(--bg);
}

[data-theme="dark"] .blocks-panel,
[data-theme="dark"] .editor-panel {
  background: var(--bg-secondary);
}

[data-theme="dark"] .deploy-main {
  background: var(--bg);
}

[data-theme="dark"] .deploy-sidebar {
  background: var(--bg-secondary);
}

[data-theme="dark"] .editor-canvas {
  background: color-mix(in srgb, var(--bg) 85%, var(--bg-secondary));
}

[data-theme="dark"] .scratch-node.selected .scratch-shape {
  stroke: var(--brand);
  stroke-width: 2;
}

[data-theme="dark"] .settings-view {
  background: var(--bg);
}

[data-theme="dark"] .settings-view .settings-main {
  background: transparent;
}

[data-theme="dark"] .settings-view .settings-card {
  background: var(--bg-secondary);
  border: none;
}

[data-theme="dark"] .settings-view .settings-card-header {
  border-bottom: none;
}

[data-theme="dark"] .settings-view .settings-card-icon {
  background: var(--bg-tertiary);
}

[data-theme="dark"] .settings-view .form-input,
[data-theme="dark"] .settings-view .form-select,
[data-theme="dark"] .settings-view .form-textarea {
  background: var(--bg-tertiary);
  border-color: var(--border-strong);
  color: var(--text);
}

[data-theme="dark"] .settings-view .form-input::placeholder,
[data-theme="dark"] .settings-view .form-textarea::placeholder {
  color: var(--text-placeholder);
}

/* Deploy dark mode */
[data-theme="dark"] .deploy-card {
  background: var(--bg-secondary);
  border: none;
}

[data-theme="dark"] .deploy-view .form-input,
[data-theme="dark"] .deploy-view .form-select,
[data-theme="dark"] .deploy-view .form-textarea {
  background: var(--bg-tertiary);
  border-color: var(--border-strong);
  color: var(--text);
}

[data-theme="dark"] .deploy-view .form-input::placeholder,
[data-theme="dark"] .deploy-view .form-textarea::placeholder {
  color: var(--text-placeholder);
}

.deploy-progress {
  margin-top: var(--space-3);
}

.deploy-result {
  margin-top: var(--space-3);
  padding: var(--space-3);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
}

.deploy-result.success {
  background: color-mix(in srgb, var(--success) 10%, transparent);
  color: var(--success);
}

.deploy-result.error {
  background: color-mix(in srgb, var(--error) 10%, transparent);
  color: var(--error);
}

.deploy-result a {
  color: inherit;
  text-decoration: underline;
}

.deploy-result .result-url {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-top: var(--space-2);
}

.deploy-result .copy-url {
  background: none;
  border: none;
  color: inherit;
  cursor: pointer;
  padding: 2px;
  opacity: 0.7;
}

.deploy-result .copy-url:hover {
  opacity: 1;
}

/* --- Deploy Guide (step-by-step accordion) --- */
.deploy-guide {
  margin-top: var(--space-4);
  width: 100%;
}

.deploy-guide > summary {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  cursor: pointer;
  user-select: none;
  font-weight: 600;
  font-size: var(--text-sm);
  color: var(--text);
  list-style: none;
  transition: color 200ms ease;
}

.deploy-guide > summary::-webkit-details-marker { display: none; }

.deploy-guide > summary::before {
  content: "";
  display: inline-block;
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  background: currentColor;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 4l4 4-4 4'/%3E%3C/svg%3E") center/contain no-repeat;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 4l4 4-4 4'/%3E%3C/svg%3E") center/contain no-repeat;
  transition: transform 200ms ease;
}

.deploy-guide[open] > summary::before {
  transform: rotate(90deg);
}

.deploy-guide > summary:hover {
  color: var(--brand);
}

.deploy-guide-steps {
  list-style: none;
  padding: 0;
  margin: var(--space-3) 0 0 0;
  counter-reset: guide-step;
}

.deploy-guide-steps li {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-1);
  font-size: var(--text-sm);
  color: var(--text-secondary);
  line-height: 1.5;
  transition: background 150ms ease;
  animation: contentFadeIn 0.3s ease both;
}

.deploy-guide-steps li:nth-child(1) { animation-delay: 0.05s; }
.deploy-guide-steps li:nth-child(2) { animation-delay: 0.1s; }
.deploy-guide-steps li:nth-child(3) { animation-delay: 0.15s; }
.deploy-guide-steps li:nth-child(4) { animation-delay: 0.2s; }
.deploy-guide-steps li:nth-child(5) { animation-delay: 0.25s; }
.deploy-guide-steps li:nth-child(6) { animation-delay: 0.3s; }
.deploy-guide-steps li:nth-child(7) { animation-delay: 0.35s; }
.deploy-guide-steps li:nth-child(8) { animation-delay: 0.4s; }

.deploy-guide-steps li:hover {
  background: var(--bg-tertiary);
}

.deploy-guide-steps li::before {
  counter-increment: guide-step;
  content: counter(guide-step);
  min-width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--brand-soft);
  color: var(--brand);
  font-weight: 600;
  font-size: var(--text-xs);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 1px;
}

.deploy-guide-steps .guide-step-content {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.deploy-guide-steps .guide-step-hint {
  font-size: var(--text-xs);
  color: var(--text-muted);
  font-style: italic;
}

.deploy-guide-steps code {
  background: var(--bg-hover);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text);
  white-space: nowrap;
}

.deploy-guide-note {
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-top: var(--space-3);
  padding-top: var(--space-3);
  border-top: 1px solid var(--border);
}

.deploy-guide-actions {
  display: flex;
  gap: var(--space-2);
  margin-top: var(--space-3);
  flex-wrap: wrap;
}

.deploy-guide-download {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  background: var(--brand);
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
  transition: all 200ms ease;
}

.deploy-guide-download:hover {
  background: var(--brand-hover);
  transform: translateY(-1px);
  box-shadow: var(--static-shadow-sm);
}

.deploy-guide-copy-cmds {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: 500;
  cursor: pointer;
  transition: all 200ms ease;
}

.deploy-guide-copy-cmds:hover {
  background: var(--bg-hover);
  color: var(--text);
  border-color: var(--border-strong);
}

.deploy-guide-files {
  margin-top: var(--space-3);
  padding: var(--space-2) var(--space-3);
  background: var(--bg-tertiary);
  border-radius: var(--radius-md);
  font-size: var(--text-xs);
  color: var(--text-muted);
  font-family: var(--font-mono);
  line-height: 1.6;
}

.deploy-guide-files summary {
  font-family: var(--font-sans);
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  user-select: none;
  list-style: none;
  font-size: var(--text-xs);
}

.deploy-guide-files summary::-webkit-details-marker { display: none; }

.deploy-guide-files summary::before {
  content: "▸ ";
}

.deploy-guide-files[open] summary::before {
  content: "▾ ";
}

.deploy-guide-files ul {
  list-style: none;
  padding: var(--space-1) 0 0 var(--space-3);
  margin: 0;
}

.deploy-guide-files li {
  padding: 1px 0;
}

/* Dark mode: deploy guide */
[data-theme="dark"] .deploy-guide-steps li:hover {
  background: color-mix(in srgb, var(--bg-tertiary) 80%, transparent);
}

[data-theme="dark"] .deploy-guide-steps code {
  background: var(--bg-tertiary);
}

[data-theme="dark"] .deploy-guide-copy-cmds {
  background: var(--bg-secondary);
  border-color: var(--border);
}

/* ===================================================================
   Scratch-Style Inline Blocks — Card Design
   =================================================================== */

/* --- Block structure --- */
.scratch-block {
  display: flex;
  flex-direction: column;
  width: 260px;
  border-radius: 0;
  overflow: hidden;
  background: transparent;
}

.scratch-fo-body .scratch-block {
  width: 260px;
  background: transparent;
  border-radius: 0;
}

.block-item .scratch-block,
.drawflow_content_node .scratch-block {
  min-width: 260px;
  max-width: 400px;
  width: auto;
  border-radius: 10px;
  background: var(--bg-secondary);
}

/* --- Header --- */
.scratch-block-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px 6px 14px;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.01em;
  user-select: none;
  border-bottom: 1px solid color-mix(in srgb, var(--node-color, var(--border)) 12%, transparent);
}

/* Icon removed — accent bar on SVG handles category color */
.scratch-block-icon { display: none; }

.scratch-block-label {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--node-color, var(--text));
}

.scratch-block-meta {
  font-size: 10px;
  color: var(--text-muted);
  white-space: nowrap;
  font-weight: 500;
}

/* --- Actions (hover / selected) --- */
.scratch-block-actions {
  display: flex;
  gap: 2px;
  opacity: 0;
  transition: opacity 150ms;
  margin-left: auto;
}
.scratch-block:hover .scratch-block-actions,
.scratch-node.selected .scratch-block-actions {
  opacity: 1;
}

.scratch-btn {
  width: 20px;
  height: 20px;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: all 100ms ease;
}
.scratch-btn svg { width: 12px; height: 12px; fill: currentColor; }
.scratch-btn:hover { background: var(--bg-hover); color: var(--text); }
.scratch-btn[data-action="delete"]:hover {
  background: rgba(239, 68, 68, 0.12);
  color: #ef4444;
}

/* --- Status badge --- */
.scratch-block-status {
  font-size: 9px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 9999px;
  background: var(--bg-tertiary);
  color: var(--text-muted);
  white-space: nowrap;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}
.scratch-block-status.status-running {
  background: rgba(59, 130, 246, 0.10);
  color: #3b82f6;
}
.scratch-block-status.status-done {
  background: rgba(34, 197, 94, 0.10);
  color: #22c55e;
}
.scratch-block-status.status-error {
  background: rgba(239, 68, 68, 0.10);
  color: #ef4444;
}

/* --- Summary (collapsed state) --- */
.scratch-block-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 3px 8px;
  padding: 5px 14px 8px;
  font-size: 11.5px;
  color: var(--text-secondary);
  line-height: 1.45;
}
.scratch-summary-item { display: inline; }
.scratch-summary-item .k {
  color: var(--text-muted);
  font-weight: 600;
  margin-right: 3px;
  text-transform: uppercase;
  font-size: 9.5px;
  letter-spacing: 0.04em;
}
.scratch-summary-item .k::after { content: ":"; }

/* --- SVG block body: transparent (card bg from SVG path fill) --- */
.scratch-fo-body .scratch-block-summary,
.scratch-fo-body .scratch-block-fields {
  background: transparent;
}
.scratch-fo-body .scratch-block-ports {
  color: var(--text-muted);
  font-size: 10px;
  padding: 4px 14px 6px;
  opacity: 0.75;
}

/* --- Inline fields (expanded state) --- */
.scratch-block-fields {
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 10px 14px;
}

.scratch-field {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 30px;
}

.scratch-field-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  white-space: nowrap;
  min-width: 58px;
  flex-shrink: 0;
}

/* Scratch input bubble */
.scratch-input {
  flex: 1;
  min-width: 0;
  padding: 5px 10px;
  font-size: 12px;
  font-family: var(--font-mono);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  outline: none;
  transition: border-color 150ms ease;
}
.scratch-input:focus {
  border-color: var(--brand);
  background: var(--bg-hover);
}

.scratch-input-number {
  max-width: 80px;
  text-align: center;
}

/* Scratch select dropdown */
.scratch-select {
  flex: 1;
  min-width: 0;
  padding: 5px 10px;
  font-size: 12px;
  font-family: var(--font-mono);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  outline: none;
  cursor: pointer;
  transition: border-color 150ms ease;
}
.scratch-select:focus {
  border-color: var(--brand);
  background: var(--bg-hover);
}

/* Pill toggles for small select groups */
.scratch-pill-group {
  display: flex;
  gap: 2px;
  background: var(--bg-tertiary);
  border-radius: 9999px;
  padding: 2px;
}
.scratch-pill {
  padding: 3px 10px;
  font-size: 11px;
  font-weight: 600;
  border: none;
  border-radius: 9999px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 100ms, color 100ms;
}
.scratch-pill.active {
  background: var(--bg);
  color: var(--text);
}
[data-theme="dark"] .scratch-pill.active {
  background: var(--bg-secondary);
  color: var(--text);
}

/* Textarea: preview and expanded */
.scratch-textarea-preview {
  flex: 1;
  padding: 5px 10px;
  font-size: 12px;
  font-family: var(--font-mono);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: text;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
  min-height: 26px;
  line-height: 1.5;
  transition: border-color 150ms ease;
}
[data-theme="dark"] .scratch-textarea-preview {
  background: var(--bg-tertiary);
  color: var(--text);
}

.scratch-textarea {
  width: 100%;
  min-height: 60px;
  max-height: 200px;
  padding: 6px 10px;
  font-size: 12px;
  font-family: var(--font-mono);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  resize: vertical;
  outline: none;
  transition: border-color 150ms ease;
}
[data-theme="dark"] .scratch-textarea {
  background: var(--bg-tertiary);
  color: var(--text);
}
.scratch-textarea:focus {
  border-color: var(--brand);
  background: var(--bg-hover);
}

/* --- Variable chips (Scratch ovals) --- */
.scratch-block-vars {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 4px 14px 8px;
  border-top: 1px dashed var(--border);
}
.scratch-var-chip {
  padding: 2px 10px;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  color: var(--node-color, var(--brand));
  border: 1px solid color-mix(in srgb, var(--node-color, var(--brand)) 30%, transparent);
  background: color-mix(in srgb, var(--node-color, var(--brand)) 8%, transparent);
  border-radius: 9999px;
  cursor: pointer;
  transition: all 100ms;
}
.scratch-var-chip:hover {
  background: color-mix(in srgb, var(--node-color, var(--brand)) 15%, transparent);
  transform: scale(1.03);
}

/* --- Ports row (bottom of block) --- */
.scratch-block-ports {
  display: flex;
  justify-content: space-between;
  padding: 5px 14px 7px;
  font-size: 10px;
  color: var(--text-muted);
  letter-spacing: 0.03em;
  font-weight: 500;
}

/* --- Expand / collapse transition --- */
.scratch-block-fields,
.scratch-block-vars {
  display: none;
}
.scratch-block.is-expanded .scratch-block-fields,
.scratch-block.is-expanded .scratch-block-vars {
  display: flex;
}
.scratch-block.is-expanded .scratch-block-summary {
  display: none;
}
