/* ============================================
   AI FLOWCHART STUDIO — PREMIUM DESIGN SYSTEM
   ============================================ */

:root {
  --bg-primary: #07090f;
  --bg-secondary: #0d1117;
  --bg-elevated: rgba(15, 20, 35, 0.82);
  --bg-surface: rgba(255, 255, 255, 0.04);
  --text-primary: #f0f4f8;
  --text-secondary: #8b95a5;
  --text-muted: #5a6577;
  --accent-primary: #6366f1;
  --accent-secondary: #8b5cf6;
  --accent-cyan: #06b6d4;
  --accent-gradient: linear-gradient(135deg, #6366f1, #8b5cf6, #06b6d4);
  --border-subtle: rgba(255, 255, 255, 0.06);
  --border-medium: rgba(255, 255, 255, 0.1);
  --glass-bg: rgba(12, 16, 28, 0.85);
  --glass-blur: 20px;
  --canvas-bg: #f8fafc;
  --canvas-dot: #d1d5db;
  --shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 30px rgba(99, 102, 241, 0.15);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --transition-fast: 0.15s ease;
  --transition-normal: 0.25s ease;
  --transition-smooth: 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ========== ANIMATED BACKGROUND ========== */
.bg-mesh {
  position: fixed;
  inset: 0;
  z-index: -2;
  background:
    radial-gradient(ellipse 80% 60% at 20% 30%, rgba(99, 102, 241, 0.08) 0%, transparent 60%),
    radial-gradient(ellipse 60% 50% at 80% 70%, rgba(6, 182, 212, 0.06) 0%, transparent 60%),
    radial-gradient(ellipse 70% 70% at 50% 50%, rgba(139, 92, 246, 0.04) 0%, transparent 60%);
}

.bg-blob {
  position: fixed;
  border-radius: 50%;
  z-index: -1;
  pointer-events: none;
  filter: blur(80px);
}

.blob-1 {
  top: -15%;
  left: -10%;
  width: 500px;
  height: 500px;
  background: rgba(99, 102, 241, 0.12);
  animation: blobFloat 30s infinite alternate ease-in-out;
}

.blob-2 {
  bottom: -20%;
  right: -10%;
  width: 400px;
  height: 400px;
  background: rgba(6, 182, 212, 0.1);
  animation: blobFloat 25s infinite alternate-reverse ease-in-out;
}

.blob-3 {
  top: 50%;
  left: 40%;
  width: 300px;
  height: 300px;
  background: rgba(139, 92, 246, 0.07);
  animation: blobFloat 35s infinite alternate ease-in-out;
  animation-delay: -10s;
}

@keyframes blobFloat {
  0% {
    transform: translate(0, 0) scale(1);
  }

  50% {
    transform: translate(40px, -30px) scale(1.08);
  }

  100% {
    transform: translate(-20px, 40px) scale(0.95);
  }
}

/* ========== APP LAYOUT ========== */
.app-layout {
  display: grid;
  grid-template-columns: 380px 1fr;
  height: 100vh;
  padding: 12px;
  gap: 12px;
}

/* ========== LEFT PANEL ========== */
.left-panel {
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 24px;
  gap: 20px;
}

.left-panel::-webkit-scrollbar {
  width: 5px;
}

.left-panel::-webkit-scrollbar-track {
  background: transparent;
}

.left-panel::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 10px;
}

.left-panel::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* ========== BRAND HEADER ========== */
.brand-header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border-subtle);
}

.brand-icon {
  width: 44px;
  height: 44px;
  background: var(--bg-surface);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.brand-text h1 {
  font-size: 1.35rem;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.02em;
}

.gradient-text {
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.brand-tagline {
  color: var(--text-secondary);
  font-size: 0.82rem;
  margin-top: 2px;
}

/* ========== TABS ========== */
.tabs {
  display: flex;
  background: rgba(0, 0, 0, 0.3);
  border-radius: var(--radius-md);
  padding: 4px;
  border: 1px solid var(--border-subtle);
  position: relative;
  z-index: 1;
}

.tabs::before {
  content: '';
  position: absolute;
  top: 4px;
  bottom: 4px;
  left: 4px;
  width: calc(50% - 4px);
  background: rgba(99, 102, 241, 0.15);
  box-shadow: 0 2px 12px rgba(99, 102, 241, 0.15);
  border: 1px solid rgba(99, 102, 241, 0.2);
  border-radius: var(--radius-sm);
  transition: transform var(--transition-smooth);
  z-index: -1;
  pointer-events: none;
}

.tabs:has(.tab-btn[data-target="tab-manual"].active)::before {
  transform: translateX(100%);
}

.tab-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: transparent;
  color: var(--text-secondary);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-weight: 500;
  font-size: 0.85rem;
  border: none;
  cursor: pointer;
  transition: color var(--transition-smooth), background var(--transition-smooth);
}

.tab-btn:hover:not(.active) {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.04);
}

.tab-btn.active {
  color: #a5b4fc;
  /* Background/border removed in favor of sliding pill */
}

.tab-btn svg {
  width: 15px;
  height: 15px;
}

@keyframes tabFadeIn {
  from {
    opacity: 0;
    transform: translateY(4px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.tab-content {
  display: flex;
  flex-direction: column;
  gap: 16px;
  animation: tabFadeIn 0.25s ease-out;
}

.hidden {
  display: none !important;
}

/* ========== INPUTS ========== */
.input-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 6px;
  display: block;
}

textarea,
input,
.left-panel select {
  width: 100%;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.9rem;
  outline: none;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast), background var(--transition-fast);
}

/* Base select reset for non-panel selects */
select {
  font-family: inherit;
  font-size: 0.9rem;
  outline: none;
  border-radius: var(--radius-sm);
}

textarea {
  min-height: 110px;
  resize: vertical;
  line-height: 1.5;
  margin-bottom: 12px;
}

textarea::placeholder,
input::placeholder {
  color: var(--text-muted);
  font-style: italic;
}

textarea:focus,
input:focus,
.left-panel select:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
  background: rgba(0, 0, 0, 0.35);
}

/* ========== BUTTONS ========== */
.primary-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--accent-gradient);
  color: white;
  border: none;
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
  box-shadow: 0 4px 20px rgba(99, 102, 241, 0.35);
  transition: all var(--transition-normal);
  position: relative;
  overflow: hidden;
}

.primary-btn::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.15), transparent);
  opacity: 0;
  transition: opacity var(--transition-fast);
}

.primary-btn:hover:not(:disabled)::before {
  opacity: 1;
}

.primary-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 6px 28px rgba(99, 102, 241, 0.45);
}

.primary-btn:active:not(:disabled) {
  transform: translateY(0);
}

.primary-btn:disabled {
  background: #334155;
  box-shadow: none;
  cursor: not-allowed;
  opacity: 0.6;
}

.primary-btn.compact {
  padding: 9px 14px;
  font-size: 0.85rem;
}

.secondary-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
  padding: 9px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  width: 100%;
  font-size: 0.85rem;
  font-weight: 500;
  transition: all var(--transition-normal);
}

.secondary-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: var(--border-medium);
}

.secondary-btn.accent {
  border-color: rgba(99, 102, 241, 0.25);
  color: #a5b4fc;
}

.secondary-btn.accent:hover:not(:disabled) {
  background: rgba(99, 102, 241, 0.1);
  border-color: rgba(99, 102, 241, 0.4);
}

.secondary-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: auto;
}

.destructive-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: rgba(239, 68, 68, 0.08);
  color: #fca5a5;
  border: 1px solid rgba(239, 68, 68, 0.15);
  padding: 9px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  width: 100%;
  font-size: 0.85rem;
  font-weight: 500;
  transition: all var(--transition-normal);
}

.destructive-btn:hover {
  background: rgba(239, 68, 68, 0.15);
  color: #f87171;
  border-color: rgba(239, 68, 68, 0.3);
}

.destructive-btn.compact {
  padding: 9px 14px;
  font-size: 0.85rem;
}

/* ========== SETTINGS SECTION ========== */
.settings-section {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.collapsible-header {
  padding: 10px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  transition: background var(--transition-fast);
}

.collapsible-header:hover {
  background: rgba(255, 255, 255, 0.04);
}

.collapsible-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.chevron-icon {
  transition: transform var(--transition-normal);
  color: var(--text-muted);
}

.collapsible-content {
  padding: 14px;
  border-top: 1px solid var(--border-subtle);
  background: rgba(0, 0, 0, 0.15);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.settings-hint {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-style: italic;
}

/* ========== MANUAL BUILDER ========== */
.manual-section {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.manual-section h3 {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
}

.input-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.elements-list {
  border-top: 1px solid var(--border-subtle);
  padding-top: 12px;
}

.elements-list h4 {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 8px 0 6px 0;
}

.elements-list ul {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.elements-list li {
  background: rgba(0, 0, 0, 0.2);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border: 1px solid transparent;
  transition: all var(--transition-fast);
}

.elements-list li:hover {
  border-color: var(--border-medium);
  background: rgba(0, 0, 0, 0.3);
}

.delete-btn {
  background: none;
  border: none;
  color: #ef4444;
  cursor: pointer;
  font-size: 1.1rem;
  padding: 0 4px;
  opacity: 0.5;
  transition: opacity var(--transition-fast);
}

.delete-btn:hover {
  opacity: 1;
}

/* ========== STATUS SECTION ========== */
.status-header {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--accent-primary);
  font-weight: 600;
  font-size: 0.85rem;
  margin-bottom: 8px;
}

#statusList {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

#statusList li {
  padding: 6px 0;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  font-size: 0.82rem;
  transition: color var(--transition-fast);
}

#statusList li.active {
  color: #a5b4fc;
  font-weight: 500;
}

#statusList li.error {
  color: #f87171;
}

.loader {
  border: 2px solid rgba(255, 255, 255, 0.08);
  border-top: 2px solid var(--accent-primary);
  border-radius: 50%;
  width: 22px;
  height: 22px;
  animation: spin 0.8s linear infinite;
  margin: 10px auto;
}

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

/* ========== RIGHT PANEL (CANVAS) ========== */
.right-panel {
  background: var(--canvas-bg);
  border-radius: var(--radius-xl);
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
}

/* ========== CANVAS TOOLBAR ========== */
.canvas-toolbar {
  z-index: 20;
  margin: 14px 14px 0 14px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  padding: 8px 12px;
  border-radius: var(--radius-md);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  border: 1px solid rgba(0, 0, 0, 0.06);
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.toolbar-divider {
  width: 1px;
  height: 24px;
  background: rgba(0, 0, 0, 0.1);
  margin: 0 4px;
}

.toolbar-select {
  width: auto;
  background: #ffffff !important;
  color: #1e293b !important;
  border: 1px solid #e2e8f0;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
  -webkit-appearance: none;
  -moz-appearance: none;
  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='%23475569' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E") !important;
  background-repeat: no-repeat !important;
  background-position: right 8px center !important;
  padding-right: 28px;
}

.toolbar-select option {
  background: #ffffff !important;
  color: #1e293b !important;
  font-weight: 500;
  padding: 6px;
}

.toolbar-select:hover {
  border-color: #cbd5e1;
}

.toolbar-select:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.15);
  background: #ffffff !important;
  color: #1e293b !important;
}

/* Left-panel select options */
.left-panel select option {
  background: #1a1f2e;
  color: #f0f4f8;
}

.toolbar-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  background: #ffffff;
  color: #475569;
  border: 1px solid #e2e8f0;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-normal);
}

.toolbar-btn:hover {
  background: #f1f5f9;
  color: #1e293b;
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.toolbar-btn span {
  font-size: 0.78rem;
}

/* Export Dropdown */
.dropdown-container {
  position: relative;
  display: inline-block;
}

.dropdown-menu {
  position: fixed;
  background: var(--glass-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
  min-width: 170px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  padding: 6px;
  gap: 2px;
  opacity: 1;
  transform-origin: top right;
  transform: scale(1) translateY(0);
  transition: opacity 0.2s cubic-bezier(0.16, 1, 0.3, 1), transform 0.2s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.2s;
  visibility: visible;
}

.mobile-only-header {
  display: none !important;
}

.dropdown-menu.hidden {
  opacity: 0;
  transform: scale(0.95) translateY(-4px);
  visibility: hidden;
  pointer-events: none;
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: transparent;
  border: none;
  border-radius: calc(var(--radius-sm) - 2px);
  color: var(--text-primary);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: all 0.15s ease;
  width: 100%;
}

.dropdown-item:hover {
  background: var(--accent-light);
  color: var(--accent-primary);
}

.dropdown-item svg {
  flex-shrink: 0;
  opacity: 0.8;
}

/* ========== CANVAS CONTAINER ========== */
.canvas-container {
  width: 100%;
  flex: 1;
  overflow: auto;
  display: block;
  text-align: center;
  padding: 20px 40px 40px 40px;
  background-color: #f8fafc;
  background-image: radial-gradient(var(--canvas-dot) 1px, transparent 1px);
  background-size: 24px 24px;
  cursor: grab;
  position: relative;
}

.canvas-container:active {
  cursor: grabbing;
}

/* ========== WELCOME STATE ========== */
.welcome-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 16px;
  animation: welcomeFade 0.8s ease-out;
  margin-top: 18vh;
}

.welcome-icon {
  width: 100px;
  height: 100px;
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.08), rgba(6, 182, 212, 0.06));
  border-radius: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(99, 102, 241, 0.12);
  animation: welcomePulse 3s ease-in-out infinite;
}

.welcome-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: #1e293b;
  letter-spacing: -0.02em;
}

.welcome-desc {
  color: #64748b;
  font-size: 0.9rem;
  max-width: 360px;
  line-height: 1.5;
}

.welcome-shortcuts {
  display: flex;
  gap: 10px;
  margin-top: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

.shortcut-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 20px;
  background: rgba(99, 102, 241, 0.06);
  border: 1px solid rgba(99, 102, 241, 0.1);
  font-size: 0.75rem;
  color: #475569;
}

.shortcut-chip kbd {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'Inter', sans-serif;
  font-size: 0.7rem;
  font-weight: 600;
  color: #6366f1;
}

@keyframes welcomeFade {
  from {
    opacity: 0;
    transform: translateY(20px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes welcomePulse {

  0%,
  100% {
    box-shadow: 0 0 0 0 rgba(99, 102, 241, 0.1);
  }

  50% {
    box-shadow: 0 0 0 12px rgba(99, 102, 241, 0);
  }
}

/* ========== ZOOM CONTROLS ========== */
.zoom-controls {
  position: absolute;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(12px);
  padding: 6px;
  border-radius: var(--radius-md);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
  border: 1px solid rgba(0, 0, 0, 0.06);
  z-index: 50;
}

.zoom-controls button {
  width: 38px;
  height: 38px;
  border: 1px solid #e2e8f0;
  background: #ffffff;
  color: #475569;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
}

.zoom-controls button:hover {
  background: #f1f5f9;
  color: var(--accent-primary);
  transform: scale(1.05);
}

/* ========== MERMAID CHART ========== */
.mermaid {
  transition: opacity 0.3s ease;
  display: inline-block;
  width: max-content;
  background: transparent !important;
  transform-origin: top center;
  margin: 0 auto;
}

.mermaid svg {
  display: block;
  max-width: none;
  height: auto !important;
  background: transparent !important;
}

.mermaid-fade-in {
  animation: mermaidFadeIn 0.5s ease-out;
}

@keyframes mermaidFadeIn {
  from {
    opacity: 0;
    transform: scale(0.97) translateY(8px);
  }

  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

/* Node interaction styles */
.node label,
.nodeLabel,
.node text,
.node tspan {
  white-space: normal !important;
  word-wrap: break-word !important;
  max-width: 220px;
  display: block;
  text-align: center;
  line-height: 1.3;
  pointer-events: none !important;
}

.node {
  cursor: pointer !important;
  transition: filter 0.2s ease, opacity 0.2s ease !important;
}

.node:hover {
  filter: drop-shadow(0 0 10px rgba(99, 102, 241, 0.4)) !important;
}

.edgePath .path {
  transition: stroke 0.25s ease, stroke-width 0.25s ease, opacity 0.25s ease !important;
}

.node.active-node rect,
.node.active-node polygon,
.node.active-node circle,
.node.active-node ellipse,
.node.active-node path {
  stroke: var(--accent-primary) !important;
  stroke-width: 3px !important;
}

/* ========== FLOATING NODE EDITOR ========== */
.node-editor {
  position: fixed;
  z-index: 1000;
  width: 280px;
  background: var(--glass-bg);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-lg);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
  overflow: hidden;
  animation: editorPopIn 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes editorPopIn {
  from {
    opacity: 0;
    transform: scale(0.92) translateY(8px);
  }

  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.editor-header {
  background: rgba(255, 255, 255, 0.04);
  padding: 10px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border-subtle);
}

.editor-header span {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 0.85rem;
  color: #a5b4fc;
}

#closeEditor,
#closeExportMenuBtn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
  transition: color var(--transition-fast);
}

#closeEditor:hover,
#closeExportMenuBtn:hover {
  color: var(--text-primary);
}

.editor-body {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

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

.input-group label {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.node-editor select {
  width: 100%;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  -webkit-appearance: none;
  -moz-appearance: none;
  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='%238b95a5' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 30px;
}

.node-editor select:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
}

.node-editor select option {
  background: #1a1f2e;
  color: #f0f4f8;
}

/* ========== TOAST NOTIFICATIONS ========== */
.toast-container {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}

.toast {
  background: rgba(15, 23, 42, 0.95);
  backdrop-filter: blur(12px);
  color: #f0f4f8;
  padding: 12px 20px;
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  font-weight: 500;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.08);
  animation: toastIn 0.3s ease-out;
  display: flex;
  align-items: center;
  gap: 8px;
}

.toast.success {
  border-left: 3px solid #34d399;
}

.toast.error {
  border-left: 3px solid #f87171;
}

.toast.info {
  border-left: 3px solid #60a5fa;
}

.toast-exit {
  animation: toastOut 0.25s ease-in forwards;
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateY(16px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes toastOut {
  to {
    opacity: 0;
    transform: translateY(16px);
  }
}

/* ========== UNDO/REDO BUTTONS ========== */
.toolbar-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  pointer-events: auto;
}

.toolbar-btn:disabled:hover {
  background: #ffffff;
  color: #475569;
  transform: none;
  box-shadow: none;
}

/* ========== PROJECTS SECTION ========== */
.project-save-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.project-save-row input {
  flex: 1;
  min-width: 0;
}

.project-save-btn {
  width: auto !important;
  flex-shrink: 0;
  white-space: nowrap;
  padding: 9px 16px !important;
}

.projects-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 300px;
  overflow-y: auto;
}

.projects-list::-webkit-scrollbar {
  width: 4px;
}

.projects-list::-webkit-scrollbar-track {
  background: transparent;
}

.projects-list::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 10px;
}

.project-item {
  background: rgba(0, 0, 0, 0.2);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border: 1px solid transparent;
  transition: all var(--transition-fast);
  gap: 10px;
}

.project-item:hover {
  border-color: var(--border-medium);
  background: rgba(0, 0, 0, 0.3);
}

.project-item-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-primary);
  font-weight: 500;
}

.project-item-date {
  font-size: 0.68rem;
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}

.project-item-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.project-load-btn,
.project-delete-btn {
  background: none;
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 0.72rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
  display: flex;
  align-items: center;
  gap: 3px;
}

.project-load-btn {
  color: #a5b4fc;
  border-color: rgba(99, 102, 241, 0.2);
}

.project-load-btn:hover {
  background: rgba(99, 102, 241, 0.1);
  border-color: rgba(99, 102, 241, 0.4);
}

.project-delete-btn {
  color: #fca5a5;
  border-color: rgba(239, 68, 68, 0.15);
}

.project-delete-btn:hover {
  background: rgba(239, 68, 68, 0.1);
  border-color: rgba(239, 68, 68, 0.3);
}

.projects-empty {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-style: italic;
  text-align: center;
  padding: 20px 0;
}

.projects-divider {
  height: 1px;
  background: var(--border-subtle);
  margin: 4px 0;
}

/* ========== PROJECTS MODAL ========== */
.projects-modal {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: modalFadeIn 0.25s ease-out;
}

.projects-modal.hidden {
  display: none !important;
}

.projects-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.projects-modal-content {
  position: relative;
  z-index: 1;
  width: 90%;
  max-width: 480px;
  max-height: 80vh;
  background: var(--glass-bg);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-xl);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.6);
  overflow: hidden;
  animation: modalPopIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  display: flex;
  flex-direction: column;
}

.projects-modal-header {
  padding: 18px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border-subtle);
  background: rgba(255, 255, 255, 0.03);
}

.projects-modal-header h3 {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
}

.projects-modal-header h3 svg {
  color: var(--accent-primary);
}

.modal-close-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.6rem;
  cursor: pointer;
  line-height: 1;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
}

.modal-close-btn:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.06);
}

.projects-modal-body {
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
}

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

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

/* ========== RESPONSIVENESS ========== */

/* --- Tablet & Mobile (≤900px) --- */
@media (max-width: 900px) {
  body {
    overflow: auto;
    overflow-x: hidden;
  }

  .app-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    height: auto;
    min-height: 100vh;
    min-height: 100dvh;
    padding: 8px;
    gap: 8px;
    overflow: visible;
  }

  /* --- Left Panel: Compact Card --- */
  .left-panel {
    overflow: visible;
    padding: 16px;
    gap: 14px;
    border-radius: var(--radius-lg);
    max-height: none;
  }

  .brand-header {
    padding-bottom: 14px;
    gap: 10px;
  }

  .brand-icon {
    width: 36px;
    height: 36px;
  }

  .brand-icon svg {
    width: 24px;
    height: 24px;
  }

  .brand-text h1 {
    font-size: 1.15rem;
  }

  .brand-tagline {
    font-size: 0.75rem;
  }

  /* Tabs */
  .tab-btn {
    padding: 8px 10px;
    font-size: 0.8rem;
  }

  /* Inputs */
  textarea {
    min-height: 80px;
    font-size: 0.85rem;
    padding: 10px 12px;
    margin-bottom: 8px;
  }

  input {
    font-size: 0.85rem;
    padding: 9px 12px;
  }

  .input-label {
    font-size: 0.7rem;
    margin-bottom: 4px;
  }

  /* Buttons */
  .primary-btn {
    padding: 11px 16px;
    font-size: 0.88rem;
  }

  .secondary-btn,
  .destructive-btn {
    padding: 8px 12px;
    font-size: 0.8rem;
  }

  /* Settings section */
  .collapsible-header {
    padding: 8px 12px;
  }

  .collapsible-content {
    padding: 10px;
  }

  /* Manual builder */
  .manual-section {
    padding: 12px;
    gap: 8px;
  }

  .input-row {
    gap: 6px;
  }

  .elements-list li {
    padding: 6px 10px;
    font-size: 0.78rem;
  }

  /* Status */
  .status-header {
    font-size: 0.8rem;
  }

  #statusList li {
    padding: 5px 0;
    font-size: 0.78rem;
  }

  /* Creator credit */
  .creator-credit {
    padding-top: 12px !important;
    font-size: 0.72rem !important;
  }

  /* --- Right Panel: Full-Height Canvas --- */
  .right-panel {
    border-radius: var(--radius-lg);
    min-height: 65vh;
    min-height: 65dvh;
  }

  /* Canvas Toolbar: Compact & Scrollable */
  .canvas-toolbar {
    margin: 8px 8px 0 8px;
    padding: 6px 8px;
    gap: 4px;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .canvas-toolbar::-webkit-scrollbar {
    display: none;
  }

  .toolbar-group {
    gap: 4px;
    flex-shrink: 0;
  }

  .toolbar-divider {
    height: 20px;
    margin: 0 2px;
  }

  .toolbar-select {
    padding: 5px 24px 5px 8px;
    font-size: 0.72rem;
    min-width: 0;
  }

  .toolbar-btn {
    padding: 5px 8px;
    font-size: 0.72rem;
    white-space: nowrap;
    flex-shrink: 0;
  }

  .toolbar-btn span {
    display: none;
  }

  .toolbar-btn svg {
    width: 14px;
    height: 14px;
  }

  /* Canvas */
  .canvas-container {
    padding: 12px 16px 32px 16px;
    -webkit-overflow-scrolling: touch;
  }

  /* Welcome State */
  .welcome-state {
    margin-top: 8vh;
    gap: 12px;
  }

  .welcome-icon {
    width: 72px;
    height: 72px;
    border-radius: 18px;
  }

  .welcome-icon svg {
    width: 56px;
    height: 56px;
  }

  .welcome-title {
    font-size: 1.2rem;
  }

  .welcome-desc {
    font-size: 0.82rem;
    max-width: 300px;
  }

  .welcome-shortcuts {
    display: none;
  }

  /* Zoom Controls */
  .zoom-controls {
    bottom: 12px;
    right: 12px;
    padding: 4px;
    gap: 3px;
  }

  .zoom-controls button {
    width: 34px;
    height: 34px;
    font-size: 0.7rem;
  }

  /* Node Editor: Bottom Sheet Style */
  .node-editor {
    position: fixed;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    top: auto !important;
    width: 100% !important;
    max-width: 100%;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    box-shadow: 0 -8px 40px rgba(0, 0, 0, 0.5);
    animation: editorSlideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    max-height: 55vh;
    overflow-y: auto;
  }

  @keyframes editorSlideUp {
    from {
      opacity: 0;
      transform: translateY(100%);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }

  .editor-body {
    padding: 16px 20px 24px 20px;
    padding-bottom: max(24px, env(safe-area-inset-bottom));
  }

  /* Toast */
  .toast-container {
    bottom: 16px;
    left: 16px;
    right: 16px;
    transform: none;
  }

  .mobile-only-header {
    display: flex !important;
  }

  /* Export Dropdown: Bottom Sheet Style */
  .dropdown-menu {
    position: fixed;
    top: auto !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    max-width: 100%;
    margin-top: 0;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    border-left: none;
    border-right: none;
    border-bottom: none;
    z-index: 2000;
    padding: 24px 20px 32px 20px;
    padding-bottom: max(32px, env(safe-area-inset-bottom));
    transform-origin: bottom center;
    transform: translateY(0);
    box-shadow: 0 -8px 40px rgba(0, 0, 0, 0.5);
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.3s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.3s;
  }

  .dropdown-menu.hidden {
    transform: translateY(100%);
    opacity: 0;
  }

  .dropdown-item {
    padding: 16px;
    font-size: 1.05rem;
    gap: 16px;
    border-radius: var(--radius-md);
  }

  .dropdown-item svg {
    width: 20px;
    height: 20px;
  }

  .toast {
    width: 100%;
    font-size: 0.82rem;
    padding: 10px 16px;
  }

  /* Background blobs: smaller for performance */
  .blob-1 {
    width: 250px;
    height: 250px;
  }
  .blob-2 {
    width: 200px;
    height: 200px;
  }
  .blob-3 {
    width: 150px;
    height: 150px;
  }
}

/* --- Small Phones (≤480px) --- */
@media (max-width: 480px) {
  .app-layout {
    padding: 6px;
    gap: 6px;
  }

  .left-panel {
    padding: 14px;
    gap: 12px;
    border-radius: var(--radius-md);
  }

  .brand-header {
    gap: 8px;
    padding-bottom: 12px;
  }

  .brand-icon {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
  }

  .brand-icon svg {
    width: 20px;
    height: 20px;
  }

  .brand-text h1 {
    font-size: 1.05rem;
  }

  .brand-tagline {
    font-size: 0.7rem;
  }

  .tabs {
    border-radius: var(--radius-sm);
    padding: 3px;
  }

  .tab-btn {
    padding: 7px 8px;
    font-size: 0.75rem;
    gap: 4px;
  }

  textarea {
    min-height: 72px;
    font-size: 0.82rem;
    padding: 8px 10px;
  }

  input,
  .left-panel select {
    padding: 8px 10px;
    font-size: 0.82rem;
  }

  .primary-btn {
    padding: 10px 14px;
    font-size: 0.85rem;
    border-radius: var(--radius-sm);
  }

  .right-panel {
    border-radius: var(--radius-md);
    min-height: 60vh;
    min-height: 60dvh;
  }

  .canvas-toolbar {
    margin: 6px 6px 0 6px;
    padding: 5px 6px;
    border-radius: var(--radius-sm);
    gap: 3px;
  }

  .toolbar-select {
    padding: 4px 22px 4px 6px;
    font-size: 0.68rem;
    border-radius: 6px;
  }

  .toolbar-btn {
    padding: 4px 6px;
    border-radius: 6px;
  }

  .canvas-container {
    padding: 8px 10px 28px 10px;
  }

  .welcome-state {
    margin-top: 6vh;
    gap: 10px;
  }

  .welcome-icon {
    width: 60px;
    height: 60px;
    border-radius: 14px;
  }

  .welcome-icon svg {
    width: 44px;
    height: 44px;
  }

  .welcome-title {
    font-size: 1.05rem;
  }

  .welcome-desc {
    font-size: 0.78rem;
    max-width: 260px;
    line-height: 1.4;
  }

  .zoom-controls {
    bottom: 10px;
    right: 10px;
  }

  .zoom-controls button {
    width: 32px;
    height: 32px;
  }

  .settings-section {
    border-radius: var(--radius-sm);
  }

  .manual-section {
    padding: 10px;
    border-radius: var(--radius-sm);
  }
}

/* --- Tiny Phones (≤380px) --- */
@media (max-width: 380px) {
  .app-layout {
    padding: 4px;
    gap: 4px;
  }

  .left-panel {
    padding: 12px;
    gap: 10px;
  }

  .brand-text h1 {
    font-size: 0.95rem;
  }

  .tab-btn {
    font-size: 0.7rem;
    padding: 6px 6px;
  }

  textarea {
    min-height: 64px;
  }

  .primary-btn {
    padding: 9px 12px;
    font-size: 0.82rem;
  }

  .right-panel {
    min-height: 55vh;
    min-height: 55dvh;
  }
}