/* ==========================================================================
   Design System & Modern Styling
   ========================================================================== */

:root {
  /* Common Variables */
  --font-family-sans: 'Inter', 'Noto Sans KR', sans-serif;
  --font-family-display: 'Outfit', 'Noto Sans KR', sans-serif;
  --font-family-mono: 'Fira Code', monospace;
  
  --transition-fast: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-normal: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 0.5s cubic-bezier(0.4, 0, 0.2, 1);
  
  --border-radius-sm: 6px;
  --border-radius-md: 12px;
  --border-radius-lg: 20px;
  --border-radius-pill: 9999px;

  --sidebar-width: 420px;
  --header-height: 70px;
}

/* ==========================================================================
   Theme Definitions
   ========================================================================== */

/* 1. Neon Dark Theme (Default) */
.theme-neon-dark {
  --bg-app: #070913;
  --bg-panel: rgba(15, 18, 36, 0.75);
  --bg-canvas: #0b0d1b;
  --bg-card: rgba(26, 32, 58, 0.4);
  --bg-card-hover: rgba(36, 44, 78, 0.65);
  --bg-input: rgba(11, 13, 27, 0.8);
  
  --border-color: rgba(255, 255, 255, 0.08);
  --border-color-hover: rgba(139, 92, 246, 0.4);
  --border-active: #8b5cf6;
  
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #475569;
  
  --accent-color: #8b5cf6; /* Violet */
  --accent-color-hover: #a78bfa;
  --accent-gradient: linear-gradient(135deg, #8b5cf6 0%, #ec4899 100%);
  --accent-shadow: rgba(139, 92, 246, 0.3);
  
  --grid-color: rgba(255, 255, 255, 0.03);
  --scrollbar-thumb: rgba(139, 92, 246, 0.3);
  
  /* Mermaid customization variables override in JS */
  --mermaid-theme: dark;
}

/* 2. Glass Light Theme */
.theme-glass-light {
  --bg-app: #f1f5f9;
  --bg-panel: rgba(255, 255, 255, 0.65);
  --bg-canvas: #f8fafc;
  --bg-card: rgba(255, 255, 255, 0.5);
  --bg-card-hover: rgba(255, 255, 255, 0.95);
  --bg-input: rgba(255, 255, 255, 0.9);
  
  --border-color: rgba(0, 0, 0, 0.08);
  --border-color-hover: rgba(14, 165, 233, 0.4);
  --border-active: #0ea5e9;
  
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  
  --accent-color: #0ea5e9; /* Sky Blue */
  --accent-color-hover: #0284c7;
  --accent-gradient: linear-gradient(135deg, #0ea5e9 0%, #2563eb 100%);
  --accent-shadow: rgba(14, 165, 233, 0.2);
  
  --grid-color: rgba(15, 23, 42, 0.04);
  --scrollbar-thumb: rgba(14, 165, 233, 0.3);
  
  --mermaid-theme: default;
}

/* 3. Cyberpunk Theme */
.theme-cyberpunk {
  --bg-app: #0b0c10;
  --bg-panel: rgba(31, 40, 51, 0.6);
  --bg-canvas: #1f2833;
  --bg-card: rgba(11, 12, 16, 0.6);
  --bg-card-hover: rgba(102, 252, 241, 0.15);
  --bg-input: #0b0c10;
  
  --border-color: #45f3ff;
  --border-color-hover: #66fcf1;
  --border-active: #66fcf1;
  
  --text-primary: #ffffff;
  --text-secondary: #c5c6c7;
  --text-muted: #66fcf1;
  
  --accent-color: #66fcf1; /* Neon Cyan */
  --accent-color-hover: #45f3ff;
  --accent-gradient: linear-gradient(135deg, #66fcf1 0%, #ff007f 100%);
  --accent-shadow: rgba(102, 252, 241, 0.3);
  
  --grid-color: rgba(102, 252, 241, 0.06);
  --scrollbar-thumb: #66fcf1;
  
  --mermaid-theme: dark;
}

/* 4. Ocean Theme */
.theme-ocean {
  --bg-app: #081b29;
  --bg-panel: rgba(10, 37, 64, 0.7);
  --bg-canvas: #051321;
  --bg-card: rgba(0, 171, 240, 0.05);
  --bg-card-hover: rgba(0, 171, 240, 0.2);
  --bg-input: #081b29;
  
  --border-color: rgba(0, 171, 240, 0.2);
  --border-color-hover: #00abf0;
  --border-active: #00abf0;
  
  --text-primary: #ededed;
  --text-secondary: #a0aec0;
  --text-muted: #00abf0;
  
  --accent-color: #00abf0; /* Electric Blue */
  --accent-color-hover: #008cc4;
  --accent-gradient: linear-gradient(135deg, #00abf0 0%, #00f2fe 100%);
  --accent-shadow: rgba(0, 171, 240, 0.35);
  
  --grid-color: rgba(0, 171, 240, 0.04);
  --scrollbar-thumb: #00abf0;
  
  --mermaid-theme: forest;
}

/* 5. Forest Theme */
.theme-forest {
  --bg-app: #0d1a15;
  --bg-panel: rgba(21, 38, 32, 0.75);
  --bg-canvas: #09130f;
  --bg-card: rgba(16, 185, 129, 0.05);
  --bg-card-hover: rgba(16, 185, 129, 0.15);
  --bg-input: #0d1a15;
  
  --border-color: rgba(16, 185, 129, 0.2);
  --border-color-hover: #10b981;
  --border-active: #10b981;
  
  --text-primary: #ecfdf5;
  --text-secondary: #a7f3d0;
  --text-muted: #10b981;
  
  --accent-color: #10b981; /* Emerald */
  --accent-color-hover: #059669;
  --accent-gradient: linear-gradient(135deg, #10b981 0%, #34d399 100%);
  --accent-shadow: rgba(16, 185, 129, 0.25);
  
  --grid-color: rgba(16, 185, 129, 0.04);
  --scrollbar-thumb: #10b981;
  
  --mermaid-theme: forest;
}


/* ==========================================================================
   Basic Boilerplate
   ========================================================================== */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font-family-sans);
  background-color: var(--bg-app);
  color: var(--text-primary);
  overflow: hidden;
  height: 100vh;
  width: 100vw;
  transition: background-color var(--transition-normal);
}

/* Scrollbars styling */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--accent-color);
}

/* Screen Reader Only utility */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

/* ==========================================================================
   Layout Containers
   ========================================================================== */

.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100vw;
}

/* Header styling */
.app-header {
  height: var(--header-height);
  background: var(--bg-panel);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 24px;
  z-index: 100;
  transition: background var(--transition-normal), border-bottom var(--transition-normal);
}

.header-logo {
  display: flex;
  align-items: center;
  gap: 16px;
}

.logo-icon {
  width: 42px;
  height: 42px;
  border-radius: var(--border-radius-md);
  background: var(--accent-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 20px;
  box-shadow: 0 4px 15px var(--accent-shadow);
  animation: pulse 2.5s infinite;
}

.logo-text h1 {
  font-family: var(--font-family-display);
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.5px;
}

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

.logo-text .tagline {
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 16px;
}

/* ==========================================================================
   Buttons and Forms
   ========================================================================== */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: var(--border-radius-md);
  font-size: 14px;
  font-weight: 500;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--transition-fast);
  font-family: var(--font-family-sans);
}

.btn-primary {
  background: var(--accent-gradient);
  color: #ffffff;
  box-shadow: 0 4px 12px var(--accent-shadow);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px var(--accent-shadow);
}

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

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-primary);
  border-color: var(--border-color);
}

.btn-secondary:hover {
  background: var(--bg-card-hover);
  border-color: var(--accent-color);
}

.btn-sm {
  padding: 6px 12px;
  font-size: 12px;
  border-radius: var(--border-radius-sm);
}

.icon-btn {
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  width: 36px;
  height: 36px;
  border-radius: var(--border-radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.icon-btn:hover {
  border-color: var(--accent-color);
  color: var(--accent-color-hover);
  background: rgba(255, 255, 255, 0.03);
}

/* Custom Select Dropdown */
.custom-select-wrapper {
  position: relative;
  min-width: 180px;
}

.custom-select-wrapper select {
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 10px 36px 10px 16px;
  border-radius: var(--border-radius-md);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  outline: none;
  transition: all var(--transition-fast);
}

.custom-select-wrapper select:hover {
  border-color: var(--border-color-hover);
}

.custom-select-wrapper select:focus {
  border-color: var(--border-active);
}

.select-arrow {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  font-size: 12px;
  color: var(--text-secondary);
}

/* ==========================================================================
   Workspace Division
   ========================================================================== */

.app-workspace {
  display: flex;
  flex: 1;
  height: calc(100vh - var(--header-height));
  overflow: hidden;
  position: relative;
}

/* Left Panel (Editor & Templates) */
.panel-left {
  width: var(--sidebar-width);
  background: var(--bg-panel);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  z-index: 10;
  transition: all var(--transition-normal);
}

/* Tab buttons bar */
.sidebar-tabs {
  display: flex;
  background: rgba(0, 0, 0, 0.15);
  border-bottom: 1px solid var(--border-color);
  padding: 8px 12px 0;
  gap: 4px;
}

.tab-btn {
  flex: 1;
  background: transparent;
  border: 1px solid transparent;
  border-bottom: none;
  color: var(--text-secondary);
  padding: 12px 6px;
  font-size: 13px;
  font-weight: 600;
  border-top-left-radius: var(--border-radius-sm);
  border-top-right-radius: var(--border-radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

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

.tab-btn.active {
  color: var(--accent-color);
  background: var(--bg-app);
  border-color: var(--border-color) var(--border-color) transparent;
}

/* Tab contents area */
.tab-content-wrapper {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  position: relative;
}

.tab-pane {
  display: none;
  height: 100%;
}

.tab-pane.active {
  display: flex;
  flex-direction: column;
}

.pane-title {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 8px;
  letter-spacing: -0.3px;
}

.pane-description {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 20px;
  line-height: 1.5;
}

/* 1. Templates Tab Layout */
.templates-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin-bottom: 24px;
}

.template-card {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-md);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.template-card:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-color-hover);
  transform: scale(1.02);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

.tmpl-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--border-radius-sm);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: var(--accent-color);
  transition: all var(--transition-fast);
}

.template-card:hover .tmpl-icon {
  background: var(--accent-gradient);
  color: #fff;
  border-color: transparent;
  box-shadow: 0 2px 10px var(--accent-shadow);
}

.tmpl-info h4 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 4px;
}

.tmpl-info p {
  font-size: 11px;
  color: var(--text-secondary);
  line-height: 1.4;
}

.info-box {
  background: rgba(139, 92, 246, 0.05);
  border: 1px dashed var(--accent-color);
  border-radius: var(--border-radius-md);
  padding: 16px;
  margin-top: auto;
}

.info-box h5 {
  font-size: 13px;
  color: var(--accent-color-hover);
  margin-bottom: 6px;
  font-weight: 600;
}

.info-box p {
  font-size: 11px;
  color: var(--text-secondary);
  line-height: 1.6;
}

/* 2. Editor Tab Layout */
.editor-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.editor-status {
  font-size: 12px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 6px;
}

.text-success {
  color: #10b981;
}

.text-danger {
  color: #ef4444;
  animation: heartbeat 1.5s infinite;
}

.editor-actions {
  display: flex;
  gap: 8px;
}

.code-area-wrapper {
  flex: 1;
  display: flex;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-md);
  overflow: hidden;
  position: relative;
  min-height: 250px;
}

.code-area-wrapper:focus-within {
  border-color: var(--border-active);
}

.line-numbers {
  width: 38px;
  padding: 16px 8px 16px 0;
  font-family: var(--font-family-mono);
  font-size: 12px;
  line-height: 1.6;
  text-align: right;
  color: var(--text-muted);
  background: rgba(0, 0, 0, 0.1);
  border-right: 1px solid var(--border-color);
  user-select: none;
}

#mermaid-code-input {
  flex: 1;
  height: 100%;
  border: none;
  background: transparent;
  color: var(--text-primary);
  font-family: var(--font-family-mono);
  font-size: 12.5px;
  line-height: 1.6;
  padding: 16px;
  resize: none;
  outline: none;
  overflow-y: auto;
  white-space: pre;
}

.syntax-helper-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 12px;
  overflow-x: auto;
  padding-bottom: 6px;
  flex-shrink: 0;
}

.helper-label {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
  white-space: nowrap;
}

.helper-chip {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  padding: 4px 8px;
  border-radius: var(--border-radius-sm);
  font-family: var(--font-family-mono);
  font-size: 11px;
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.helper-chip:hover {
  background: var(--bg-card-hover);
  border-color: var(--accent-color);
  color: var(--text-primary);
}

/* 3. History Tab Layout */
.history-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  flex: 1;
}

.history-card {
  padding: 14px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-md);
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: all var(--transition-fast);
  cursor: pointer;
}

.history-card:hover {
  border-color: var(--accent-color);
  background: var(--bg-card-hover);
}

.hist-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

.hist-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}

.hist-date {
  font-size: 10px;
  color: var(--text-secondary);
}

.hist-actions {
  display: flex;
  gap: 4px;
}

.hist-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  width: 28px;
  height: 28px;
  border-radius: var(--border-radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.hist-btn-del:hover {
  background: rgba(239, 68, 68, 0.15);
  color: #ef4444;
}

.hist-btn-load:hover {
  background: rgba(139, 92, 246, 0.15);
  color: var(--accent-color);
}

.empty-state {
  text-align: center;
  color: var(--text-secondary);
  font-size: 13px;
  padding: 40px 0;
}


/* Right Panel (SVG Preview Area) */
.panel-right {
  flex: 1;
  background: var(--bg-canvas);
  position: relative;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Canvas Header styling */
.canvas-topbar {
  height: 60px;
  background: rgba(0, 0, 0, 0.15);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 24px;
  z-index: 5;
}

.canvas-title-area {
  display: flex;
  flex-direction: column;
}

.canvas-subtitle {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--accent-color);
  font-weight: 700;
}

#diagram-title {
  background: transparent;
  border: none;
  border-bottom: 1.5px dashed transparent;
  color: var(--text-primary);
  font-size: 15px;
  font-weight: 600;
  outline: none;
  padding: 2px 0;
  width: 260px;
  transition: all var(--transition-fast);
}

#diagram-title:hover, #diagram-title:focus {
  border-bottom-color: var(--accent-color);
}

.canvas-actions {
  display: flex;
  gap: 12px;
}

/* Dropdown styling */
.dropdown-container {
  position: relative;
}

.dropdown-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.3);
  border-radius: var(--border-radius-md);
  padding: 8px;
  min-width: 220px;
  display: none;
  flex-direction: column;
  gap: 4px;
  z-index: 50;
  backdrop-filter: blur(25px);
  -webkit-backdrop-filter: blur(25px);
}

.dropdown-menu.active {
  display: flex;
  animation: fadeInUp 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-size: 13px;
  text-align: left;
  border-radius: var(--border-radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
  width: 100%;
}

.dropdown-item:hover {
  background: var(--bg-card-hover);
  color: var(--accent-color-hover);
}

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

/* Canvas Viewport */
.canvas-viewport {
  flex: 1;
  position: relative;
  overflow: hidden;
  cursor: grab;
  user-select: none;
}

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

.render-output {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  transform-origin: 0 0;
  position: absolute;
  top: 0;
  left: 0;
}

/* Mermaid SVG inner tweaks */
.render-output svg {
  max-width: none !important;
  display: block;
}

.viewport-grid {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-image: 
    radial-gradient(circle, var(--grid-color) 1.5px, transparent 1.5px);
  background-size: 30px 30px;
  pointer-events: none;
  z-index: 1;
}

/* Floating controls */
.canvas-controls {
  position: absolute;
  bottom: 24px;
  right: 24px;
  background: rgba(15, 18, 36, 0.65);
  border: 1px solid var(--border-color);
  backdrop-filter: blur(15px);
  -webkit-backdrop-filter: blur(15px);
  border-radius: var(--border-radius-pill);
  padding: 6px;
  display: flex;
  gap: 4px;
  z-index: 8;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

.control-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.control-btn:hover {
  background: var(--accent-gradient);
  color: #ffffff;
  box-shadow: 0 2px 8px var(--accent-shadow);
  transform: scale(1.1);
}

.control-divider {
  width: 1px;
  height: 24px;
  background: var(--border-color);
  align-self: center;
}

/* Floating Help tip */
.interaction-help {
  position: absolute;
  bottom: 24px;
  left: 24px;
  background: rgba(0, 0, 0, 0.4);
  padding: 8px 16px;
  border-radius: var(--border-radius-pill);
  font-size: 11px;
  color: var(--text-secondary);
  pointer-events: none;
  z-index: 8;
  border: 1px solid rgba(255, 255, 255, 0.04);
}

/* Error Console overlay */
.error-panel {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  background: rgba(220, 38, 38, 0.95);
  color: #fff;
  border-top: 1px solid #ef4444;
  z-index: 20;
  transform: translateY(100%);
  transition: transform var(--transition-normal);
  max-height: 40%;
  display: flex;
  flex-direction: column;
}

.error-panel.active {
  transform: translateY(0);
}

.error-panel-header {
  padding: 12px 24px;
  background: rgba(185, 28, 28, 0.95);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 14px;
}

.close-error-btn {
  background: transparent;
  border: none;
  color: #fff;
  font-size: 16px;
  cursor: pointer;
}

.error-panel-body {
  padding: 16px 24px;
  overflow-y: auto;
  font-family: var(--font-family-mono);
  font-size: 12px;
  line-height: 1.5;
}

/* ==========================================================================
   Modals & Popups
   ========================================================================== */

.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(8px);
  z-index: 999;
  display: none;
  align-items: center;
  justify-content: center;
}

.modal.active {
  display: flex;
  animation: fadeIn 0.3s ease-out;
}

.modal-content {
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-lg);
  width: 100%;
  max-width: 480px;
  overflow: hidden;
  box-shadow: 0 25px 50px rgba(0, 0, 0, 0.4);
  transform: scale(0.9);
  transition: transform 0.3s ease-out;
}

.modal.active .modal-content {
  transform: scale(1);
}

.modal-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-close {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 18px;
  cursor: pointer;
}

.modal-close:hover {
  color: var(--text-primary);
}

.modal-body {
  padding: 24px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.form-group label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
}

.form-group input {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  padding: 12px 16px;
  border-radius: var(--border-radius-md);
  color: #fff;
  font-size: 14px;
  outline: none;
}

.form-group input:focus {
  border-color: var(--border-active);
}

.modal-footer {
  padding: 16px 24px;
  background: rgba(0, 0, 0, 0.1);
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  border-top: 1px solid var(--border-color);
}


/* ==========================================================================
   Mobile Tab bar & Responsive Rules
   ========================================================================== */

.mobile-nav {
  display: none;
  height: 60px;
  background: var(--bg-panel);
  border-top: 1px solid var(--border-color);
  backdrop-filter: blur(15px);
  -webkit-backdrop-filter: blur(15px);
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  z-index: 100;
}

.mobile-nav-btn {
  flex: 1;
  background: transparent;
  border: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  color: var(--text-secondary);
  font-size: 10px;
  cursor: pointer;
}

.mobile-nav-btn i {
  font-size: 18px;
}

.mobile-nav-btn.active {
  color: var(--accent-color);
}

/* Animations */
@keyframes pulse {
  0% { box-shadow: 0 4px 15px var(--accent-shadow); }
  50% { box-shadow: 0 4px 25px rgba(139, 92, 246, 0.6); }
  100% { box-shadow: 0 4px 15px var(--accent-shadow); }
}

@keyframes heartbeat {
  0% { transform: scale(1); }
  50% { transform: scale(1.1); }
  100% { transform: scale(1); }
}

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

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

/* ==========================================================================
   Responsive Breakpoints
   ========================================================================== */

@media (max-width: 1024px) {
  :root {
    --sidebar-width: 360px;
  }
}

@media (max-width: 768px) {
  .app-header {
    padding: 0 16px;
  }
  
  .header-actions {
    display: none; /* Let actions be accessible on mobile via tabs/menus if needed */
  }

  .logo-text .tagline {
    display: none;
  }
  
  .app-workspace {
    flex-direction: column;
    height: calc(100vh - var(--header-height) - 60px); /* Adjust for mobile nav bar */
  }

  .panel-left {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    transform: translateX(0);
    border-right: none;
    border-bottom: 1px solid var(--border-color);
  }

  .panel-right {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    transform: translateX(100%);
  }

  /* Display control via Javascript matching active navigation classes */
  .view-state-editor .panel-left {
    transform: translateX(0);
  }
  .view-state-editor .panel-right {
    transform: translateX(100%);
  }

  .view-state-canvas .panel-left {
    transform: translateX(-100%);
  }
  .view-state-canvas .panel-right {
    transform: translateX(0);
  }

  /* Hide Templates tab and manage views directly */
  .view-state-templates .panel-left {
    transform: translateX(0);
  }
  .view-state-templates .panel-right {
    transform: translateX(100%);
  }

  .mobile-nav {
    display: flex;
  }

  .canvas-topbar {
    padding: 0 16px;
  }

  #diagram-title {
    width: 180px;
  }

  .interaction-help {
    display: none; /* Save space on mobile */
  }

  .canvas-controls {
    bottom: 16px;
    right: 16px;
  }
}
