* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg-primary: #ffffff;
  --bg-secondary: #f8f9fa;
  --bg-tertiary: #e9ecef;
  --text-primary: #000000;
  --text-secondary: #6c757d;
  --border-color: #dee2e6;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.15);
  --accent: #000000;
  --grid-color: #e9ecef;
}

body.dark-theme {
  --bg-primary: #1a1a1a;
  --bg-secondary: #2d2d2d;
  --bg-tertiary: #3d3d3d;
  --text-primary: #ffffff;
  --text-secondary: #a0a0a0;
  --border-color: #404040;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.4);
  --accent: #ffffff;
  --grid-color: #2d2d2d;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  background: var(--bg-secondary);
  color: var(--text-primary);
  overflow: hidden;
}

.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.header {
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border-color);
  padding: 1rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: var(--shadow);
  z-index: 100;
}

.header-left {
  display: flex;
  align-items: baseline;
  gap: 1rem;
}

.header-left h1 {
  font-size: 1.5rem;
  font-weight: 600;
}

.subtitle {
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.header-actions {
  display: flex;
  gap: 0.5rem;
}

.btn {
  padding: 0.5rem 1rem;
  border: 1px solid var(--border-color);
  background: var(--bg-primary);
  color: var(--text-primary);
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.875rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  transition: all 0.2s;
}

.btn:hover {
  background: var(--bg-secondary);
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

.btn:active {
  transform: translateY(0);
}

.btn-primary {
  background: var(--accent);
  color: var(--bg-primary);
  border-color: var(--accent);
}

.btn-primary:hover {
  opacity: 0.9;
}

.btn-secondary {
  padding: 0.5rem;
}

.btn-sm {
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
}

.btn-icon {
  padding: 0.5rem;
  border: none;
  background: transparent;
  color: var(--text-primary);
  cursor: pointer;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.btn-icon:hover {
  background: var(--bg-secondary);
}

.main-content {
  display: flex;
  flex: 1;
  overflow: hidden;
}

.toolbar {
  width: 200px;
  background: var(--bg-primary);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  transition: transform 0.3s;
}

.toolbar.collapsed {
  transform: translateX(-100%);
}

.toolbar-header {
  padding: 1rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.toolbar-header h3 {
  font-size: 1rem;
  font-weight: 600;
}

.toolbar-items {
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  overflow-y: auto;
}

.toolbar-item {
  padding: 0.75rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  cursor: grab;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  transition: all 0.2s;
}

.toolbar-item:hover {
  background: var(--bg-tertiary);
  transform: translateX(4px);
  box-shadow: var(--shadow);
}

.toolbar-item:active {
  cursor: grabbing;
}

.toolbar-item span {
  font-size: 0.875rem;
}

.node-preview {
  width: 40px;
  height: 30px;
  border: 2px solid var(--text-primary);
  background: var(--bg-primary);
  flex-shrink: 0;
}

.start-node {
  border-radius: 15px;
}

.process-node {
  border-radius: 4px;
}

.decision-node {
  transform: rotate(45deg);
  width: 30px;
  height: 30px;
}

.io-node {
  clip-path: polygon(10% 0%, 100% 0%, 90% 100%, 0% 100%);
}

.connector-node {
  border-radius: 50%;
  width: 30px;
  height: 30px;
}

.custom-node {
  border-radius: 4px;
  border-style: dashed;
}

.canvas-container {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: var(--bg-secondary);
}

.canvas-controls {
  position: absolute;
  bottom: 1rem;
  right: 1rem;
  display: flex;
  gap: 0.5rem;
  align-items: center;
  background: var(--bg-primary);
  padding: 0.5rem;
  border-radius: 8px;
  box-shadow: var(--shadow-lg);
  z-index: 10;
}

#zoomLevel {
  font-size: 0.875rem;
  min-width: 50px;
  text-align: center;
}

#canvas {
  width: 100%;
  height: 100%;
  cursor: grab;
}

#canvas.panning {
  cursor: grabbing;
}

#canvas.connecting {
  cursor: crosshair;
}

.selection-box {
  position: absolute;
  border: 2px dashed var(--accent);
  background: rgba(0, 0, 0, 0.05);
  pointer-events: none;
  display: none;
}

.inspector {
  width: 280px;
  background: var(--bg-primary);
  border-left: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  transition: transform 0.3s;
}

.inspector.collapsed {
  transform: translateX(100%);
}

.inspector-header {
  padding: 1rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.inspector-header h3 {
  font-size: 1rem;
  font-weight: 600;
}

.inspector-content {
  padding: 1rem;
  overflow-y: auto;
}

.no-selection {
  color: var(--text-secondary);
  font-size: 0.875rem;
  text-align: center;
  padding: 2rem 1rem;
}

.property-group {
  margin-bottom: 1.5rem;
}

.property-group h4 {
  font-size: 0.875rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.property-item {
  margin-bottom: 1rem;
}

.property-item label {
  display: block;
  font-size: 0.875rem;
  margin-bottom: 0.5rem;
  color: var(--text-primary);
}

.input {
  width: 100%;
  padding: 0.5rem;
  border: 1px solid var(--border-color);
  background: var(--bg-secondary);
  color: var(--text-primary);
  border-radius: 6px;
  font-size: 0.875rem;
  transition: border-color 0.2s;
}

.input:focus {
  outline: none;
  border-color: var(--accent);
}

.color-input {
  width: 100%;
  height: 40px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  cursor: pointer;
}

.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal.active {
  display: flex;
}

.modal-content {
  background: var(--bg-primary);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  width: 90%;
  max-width: 500px;
  max-height: 80vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.modal-header {
  padding: 1.5rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h2 {
  font-size: 1.25rem;
  font-weight: 600;
}

.modal-body {
  padding: 1.5rem;
  overflow-y: auto;
}

.modal-body h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-top: 1.5rem;
  margin-bottom: 0.75rem;
}

.modal-body h3:first-child {
  margin-top: 0;
}

.modal-body ul {
  list-style: none;
  padding: 0;
}

.modal-body li {
  padding: 0.5rem 0;
  font-size: 0.875rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

kbd {
  padding: 0.25rem 0.5rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  font-size: 0.75rem;
  font-family: monospace;
}

.text-editor {
  position: absolute;
  border: 2px solid var(--accent);
  background: var(--bg-primary);
  color: var(--text-primary);
  padding: 0.5rem;
  font-size: 14px;
  font-family: inherit;
  z-index: 1000;
  min-width: 100px;
  resize: none;
}

.context-menu {
  position: fixed;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  box-shadow: var(--shadow-lg);
  display: none;
  z-index: 2000;
  min-width: 150px;
}

.context-menu-item {
  padding: 0.75rem 1rem;
  cursor: pointer;
  font-size: 0.875rem;
  transition: background 0.2s;
}

.context-menu-item:hover {
  background: var(--bg-secondary);
}

.context-menu-item:first-child {
  border-radius: 8px 8px 0 0;
}

.context-menu-item:last-child {
  border-radius: 0 0 8px 8px;
}

.modal-large {
  max-width: 800px;
}

.history-actions {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.history-actions .input {
  flex: 1;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  max-height: 500px;
  overflow-y: auto;
}

.history-item {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: all 0.2s;
}

.history-item:hover {
  background: var(--bg-tertiary);
  box-shadow: var(--shadow);
}

.history-item-info h4 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.history-item-info p {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-bottom: 0.25rem;
}

.history-item-actions {
  display: flex;
  gap: 0.5rem;
}

@media (max-width: 768px) {
  .toolbar {
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    z-index: 50;
    box-shadow: var(--shadow-lg);
  }

  .inspector {
    position: absolute;
    right: 0;
    top: 0;
    height: 100%;
    z-index: 50;
    box-shadow: var(--shadow-lg);
  }

  .header-left h1 {
    font-size: 1.25rem;
  }

  .subtitle {
    display: none;
  }

  .header-actions {
    gap: 0.25rem;
  }

  .btn {
    padding: 0.5rem;
  }

  .history-item {
    flex-direction: column;
    align-items: flex-start;
    gap: 1rem;
  }

  .history-item-actions {
    width: 100%;
    justify-content: flex-end;
  }
}