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

:root {
  --bg: #0a0a0a;
  --surface: #141414;
  --surface2: #1a1a1a;
  --border: #27272a;
  --text: #ededed;
  --muted: #a1a1aa;
  --accent: #0070f3;
  --accent-hover: #0060d0;
  --green: #22c55e;
  --amber: #f59e0b;
  --purple: #8b5cf6;
  --red: #ef4444;
  --blue: #0070f3;
  --slate: #64748b;
  --font-sans: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'IBM Plex Mono', monospace;
}

.theme-dark {
  --bg: #0a0a0a;
  --surface: #141414;
  --surface2: #1a1a1a;
  --border: #27272a;
  --text: #ededed;
  --muted: #a1a1aa;
}

.theme-light {
  --bg: #ffffff;
  --surface: #fafafa;
  --surface2: #f4f4f5;
  --border: #e5e7eb;
  --text: #171717;
  --muted: #6b7280;
}

html, body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  height: 100%;
  width: 100%;
}

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

/* Canvas dot grid */
.canvas-svg {
  background-image: radial-gradient(circle, rgba(128,128,128,0.12) 1px, transparent 1px);
  background-size: 20px 20px;
  display: block;
}

/* Animated edges */
@keyframes dashFlow {
  to { stroke-dashoffset: -20; }
}

.edge-animated {
  stroke-dasharray: 5 5;
  animation: dashFlow 1s linear infinite;
}

/* Node SVG handles */
.node-handle-svg {
  transition: all 150ms ease;
}
.node-handle-svg:hover {
  fill: var(--accent) !important;
  filter: drop-shadow(0 0 4px var(--accent));
}

/* Floating toolbar */
.floating-toolbar {
  border-radius: 999px;
  background: rgba(20,20,20,0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  box-shadow: 0 8px 32px rgba(0,0,0,0.3);
  padding: 6px 10px;
  display: flex;
  gap: 2px;
  align-items: center;
}

.theme-light .floating-toolbar {
  background: rgba(255,255,255,0.9);
  box-shadow: 0 8px 32px rgba(0,0,0,0.1);
}

.toolbar-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font-size: 15px;
  transition: all 150ms ease;
  flex-shrink: 0;
}

.toolbar-btn:hover {
  background: rgba(255,255,255,0.1);
}

.theme-light .toolbar-btn:hover {
  background: rgba(0,0,0,0.06);
}

/* Sidebar */
.sidebar {
  width: 320px;
  min-width: 320px;
  max-width: 320px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: all 200ms ease;
  flex-shrink: 0;
}

.sidebar-collapsed {
  width: 0 !important;
  min-width: 0 !important;
  max-width: 0 !important;
  border-right: none;
  padding: 0 !important;
}

.sidebar-inner {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px;
}

/* Button styles */
.btn-primary {
  background: linear-gradient(135deg, #0070f3, #0050d0);
  color: white;
  border: none;
  border-radius: 8px;
  padding: 10px 20px;
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: all 150ms ease;
  width: 100%;
  position: relative;
  overflow: hidden;
}

.btn-primary:hover {
  box-shadow: 0 4px 16px rgba(0,112,243,0.35);
  transform: translateY(-1px);
}

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

.btn-primary:disabled {
  opacity: 0.7;
  cursor: not-allowed;
  transform: none;
}

.btn-outline {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 14px;
  font-family: var(--font-sans);
  font-weight: 500;
  font-size: 13px;
  cursor: pointer;
  transition: all 150ms ease;
  width: 100%;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-outline:hover {
  background: var(--surface2);
  border-color: var(--muted);
}

/* Chat bubbles */
.chat-user {
  background: rgba(0,112,243,0.12);
  border: 1px solid rgba(0,112,243,0.2);
  border-radius: 12px 12px 4px 12px;
  padding: 8px 12px;
  font-size: 13px;
  max-width: 85%;
  margin-left: auto;
  word-break: break-word;
}

.chat-system {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 12px 12px 12px 4px;
  padding: 8px 12px;
  font-size: 13px;
  max-width: 85%;
  word-break: break-word;
}

/* Template cards */
.template-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 8px;
  cursor: pointer;
  transition: all 150ms ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: var(--bg);
  font-family: var(--font-sans);
  color: var(--text);
}

.template-card:hover {
  border-color: var(--accent);
  transform: scale(1.03);
  background: var(--surface2);
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 5px;
}

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

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

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

/* Toast */
@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

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

.toast-enter {
  animation: slideIn 200ms ease forwards;
}

.toast-exit {
  animation: slideOut 200ms ease forwards;
}

/* Shimmer */
@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

.shimmer {
  background: linear-gradient(90deg, transparent 25%, rgba(255,255,255,0.15) 50%, transparent 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  position: absolute;
  inset: 0;
  border-radius: 8px;
}

/* Minimap container */
.minimap-container {
  position: absolute;
  bottom: 12px;
  right: 12px;
  width: 150px;
  height: 100px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  z-index: 30;
}

/* Node inline edit */
.node-inline-edit {
  background: var(--bg) !important;
  border: 1px solid var(--accent) !important;
  border-radius: 4px;
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 600;
  padding: 2px 4px;
  outline: none;
  width: 100%;
  display: block;
}

/* Add node dropdown */
.add-node-dropdown {
  position: absolute;
  top: 44px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.3);
  padding: 6px;
  z-index: 100;
  min-width: 170px;
}

.add-node-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  transition: background 100ms ease;
  border: none;
  background: none;
  color: var(--text);
  width: 100%;
  text-align: left;
  font-family: var(--font-sans);
}

.add-node-item:hover {
  background: var(--surface2);
}

/* Node detail panel */
.node-detail-panel {
  position: absolute;
  top: 60px;
  right: 12px;
  width: 260px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.3);
  padding: 14px;
  z-index: 50;
}

.detail-input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 13px;
  padding: 6px 10px;
  outline: none;
  transition: border-color 150ms ease;
}

.detail-input:focus {
  border-color: var(--accent);
}

.detail-select {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 13px;
  padding: 6px 10px;
  outline: none;
  cursor: pointer;
}

/* Empty state */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--muted);
  text-align: center;
  padding: 20px;
}

/* Accordion */
.accordion-body {
  max-height: 0;
  overflow: hidden;
  transition: max-height 250ms ease;
}

.accordion-body.open {
  max-height: 500px;
}

/* Textarea */
.prompt-textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 13px;
  padding: 10px 12px;
  font-family: var(--font-sans);
  resize: vertical;
  outline: none;
  transition: border-color 150ms ease;
  min-height: 80px;
  line-height: 1.5;
}

.prompt-textarea:focus {
  border-color: var(--accent);
}

.refine-input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 13px;
  padding: 8px 12px;
  font-family: var(--font-sans);
  outline: none;
  min-width: 0;
}

.refine-input:focus {
  border-color: var(--accent);
}

.refine-send {
  background: var(--accent);
  border: none;
  border-radius: 8px;
  color: #fff;
  width: 36px;
  height: 36px;
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 150ms ease;
}

.refine-send:hover {
  background: var(--accent-hover);
}

/* Nav */
.nav-bar {
  height: 48px;
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  z-index: 100;
  flex-shrink: 0;
}

.nav-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.nav-center {
  display: flex;
  align-items: center;
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
}

.nav-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.sidebar-toggle {
  background: none;
  border: 1px solid var(--border);
  color: var(--text);
  cursor: pointer;
  font-size: 14px;
  padding: 4px 8px;
  border-radius: 6px;
  transition: all 150ms ease;
  font-family: var(--font-sans);
}

.sidebar-toggle:hover {
  background: var(--surface2);
}

.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  font-size: 15px;
  padding: 4px 8px;
  transition: all 150ms ease;
}

.theme-toggle:hover {
  background: var(--surface2);
}

.diagram-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  padding: 2px 8px;
  border-radius: 6px;
  transition: color 150ms ease;
  white-space: nowrap;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.diagram-name:hover {
  color: var(--text);
}

.diagram-name-input {
  background: transparent;
  border: 1px solid var(--accent);
  border-radius: 6px;
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  padding: 2px 8px;
  font-family: var(--font-sans);
  text-align: center;
  outline: none;
  width: 200px;
}

.avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: linear-gradient(135deg, #0070f3, #8b5cf6);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: #fff;
  font-weight: 700;
  flex-shrink: 0;
}

.main-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

.canvas-area {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: var(--bg);
  min-width: 0;
}

/* Section label */
.section-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.section-divider {
  width: 100%;
  height: 1px;
  background: var(--border);
  margin: 16px 0;
}

.accordion-toggle {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  padding: 8px 0;
  font-family: var(--font-sans);
}

.accordion-chevron {
  transition: transform 200ms ease;
  font-size: 12px;
}

.accordion-chevron.open {
  transform: rotate(180deg);
}

.footer-link {
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  font-size: 11px;
}

.footer-link a {
  color: var(--muted);
  text-decoration: none;
}

.footer-link a:hover {
  color: var(--text);
}

/* ========= RESPONSIVE ========= */

/* Mobile: sidebar becomes bottom drawer */
@media (max-width: 768px) {
  .nav-center {
    display: none;
  }

  .sidebar {
    position: fixed;
    left: 0;
    bottom: 0;
    width: 100% !important;
    min-width: 100% !important;
    max-width: 100% !important;
    height: 55vh;
    max-height: 55vh;
    border-right: none !important;
    border-top: 1px solid var(--border);
    z-index: 200;
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -4px 32px rgba(0,0,0,0.3);
  }

  .sidebar-collapsed {
    height: 0 !important;
    max-height: 0 !important;
    min-height: 0 !important;
    border-top: none !important;
    box-shadow: none !important;
  }

  .sidebar-inner {
    padding: 12px 14px;
  }

  .floating-toolbar {
    padding: 4px 8px;
    gap: 1px;
  }

  .toolbar-btn {
    width: 30px;
    height: 30px;
    font-size: 13px;
  }

  .node-detail-panel {
    top: auto;
    bottom: 12px;
    right: 12px;
    left: 12px;
    width: auto;
  }

  .minimap-container {
    width: 120px;
    height: 80px;
    bottom: 8px;
    right: 8px;
  }
}

/* Tablet */
@media (min-width: 769px) and (max-width: 1024px) {
  .sidebar {
    width: 280px !important;
    min-width: 280px !important;
    max-width: 280px !important;
  }
}

/* Mobile drawer handle */
.drawer-handle {
  width: 36px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 8px auto 4px;
}