:root {
  --bg-deep: #020617;
  --bg-surface: rgba(255, 255, 255, 0.03);
  --bg-glass: rgba(15, 23, 42, 0.7);
  --bg-input: rgba(0, 0, 0, 0.2);

  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --text-dim: #64748b;

  --accent-primary: #06b6d4;
  /* Cyan */
  --accent-secondary: #10b981;
  /* Emerald */
  --accent-tertiary: #f59e0b;
  /* Amber */
  --accent-glow: rgba(6, 182, 212, 0.5);

  --border-light: rgba(255, 255, 255, 0.08);
  --border-hover: rgba(255, 255, 255, 0.15);

  --success: #10b981;
  --danger: #ef4444;

  --shadow-sm: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.3);

  --font-main: 'Outfit', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-full: 9999px;

  --header-height: 64px;
  --message-collapse-lines: 3;
  --message-expand-max-height: min(60vh, 520px);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  height: 100vh;
  background-color: var(--bg-deep);
  color: var(--text-main);
  font-family: var(--font-main);
  overflow: hidden;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* --- Animated Backgrounds --- */
.bg-blur {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  z-index: -1;
  opacity: 0.4;
  animation: float 10s infinite ease-in-out;
}

.bg-blur--1 {
  width: 600px;
  height: 600px;
  background: var(--accent-primary);
  top: -100px;
  left: -100px;
  opacity: 0.3;
}

.bg-blur--2 {
  width: 500px;
  height: 500px;
  background: var(--accent-secondary);
  bottom: -100px;
  right: -100px;
  opacity: 0.25;
  animation-delay: -5s;
}

.bg-blur--3 {
  position: absolute;
  width: 450px;
  height: 450px;
  background: var(--accent-tertiary);
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  filter: blur(100px);
  z-index: -1;
  opacity: 0.2;
  animation: float 15s infinite ease-in-out reverse;
}

@keyframes float {

  0%,
  100% {
    transform: translate(0, 0);
  }

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

/* Lava animation removed */

/* --- Layout --- */
.app-container {
  display: flex;
  height: 100%;
  width: 100%;
  position: relative;
}

.canvas-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
  isolation: isolate;
  /* background: radial-gradient(circle at center, rgba(255,255,255,0.02) 0%, transparent 70%); */
}

.canvas-area > * {
  position: relative;
  z-index: 2;
}

.canvas-area::before,
.canvas-area::after {
  content: "";
  position: absolute;
  inset: 6%;
  border-radius: 32px;
  opacity: 0;
  pointer-events: none;
  z-index: 1;
  filter: blur(55px);
  transition: opacity 0.25s ease;
  animation: overlayGradientPulse var(--pulse-duration, 2400ms) ease-in-out infinite;
  animation-play-state: paused;
}

.canvas-area::before {
  background: var(--glow-gradient);
}

.canvas-area::after {
  inset: 12%;
  border-radius: 40px;
  background: var(--glow-solid);
  filter: blur(40px);
  animation-name: overlaySolidPulse;
}

.canvas-area--generating {
  animation: siteGlowPulse var(--pulse-duration, 2400ms) ease-in-out infinite;
}

.canvas-area--generating::before,
.canvas-area--generating::after {
  opacity: 1;
  animation-play-state: running;
}

/* --- Header --- */
.topbar {
  height: var(--header-height);
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  backdrop-filter: blur(12px);
  /* background: linear-gradient(180deg, rgba(0,0,0,0.4) 0%, transparent 100%); */
  z-index: 10;
}

.topbar__left {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.btn--new-chat {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  color: var(--text-main);
  border-color: rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.08);
}

.btn--new-chat svg {
  width: 18px;
  height: 18px;
}

.btn--new-chat:hover {
  border-color: rgba(255, 255, 255, 0.35);
  background: rgba(255, 255, 255, 0.16);
}

.brand__logo {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 20px;
  color: #020617;
  /* Dark text on bright gradient */
  box-shadow: 0 4px 12px var(--accent-glow);
}

.brand__info {
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.brand__title {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  line-height: 1.1;
  letter-spacing: -0.02em;
}

.brand__subtitle {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 400;
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border-light);
  background: var(--bg-surface);
  color: var(--text-muted);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.btn:hover {
  background: var(--border-hover);
  color: var(--text-main);
  border-color: var(--text-muted);
}

.btn:active {
  transform: scale(0.96);
}

.btn--icon {
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: var(--radius-sm);
}

.btn--icon.is-active {
  background: rgba(6, 182, 212, 0.15);
  color: var(--accent-primary);
  border-color: rgba(6, 182, 212, 0.4);
}

.btn--small {
  height: 30px;
  padding: 0 12px;
  font-size: 12px;
  border-radius: 8px;
}

.btn--danger:hover {
  background: rgba(239, 68, 68, 0.15);
  color: var(--danger);
  border-color: rgba(239, 68, 68, 0.3);
}

.btn-text {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 12px;
  cursor: pointer;
  padding: 4px 8px;
  transition: color 0.2s;
}

.btn-text:hover {
  color: var(--accent-primary);
  text-decoration: underline;
}

/* --- Canvas Wrapper --- */
.canvas-wrapper {
  flex: 1;
  position: relative;
  overflow: hidden;
  background-image:
    radial-gradient(circle at 1px 1px, rgba(255, 255, 255, 0.05) 1px, transparent 0);
  background-size: 24px 24px;
}

.canvas-wrapper--generating {
  --glow-color: rgba(6, 182, 212, 0.35);
  --glow-color-strong: rgba(6, 182, 212, 0.6);
  --glow-solid: rgba(6, 182, 212, 0.18);
  --glow-gradient: radial-gradient(circle at 50% 50%, rgba(6, 182, 212, 0.45) 0%, rgba(6, 182, 212, 0.2) 55%, transparent 75%);
  --glow-text: rgba(226, 247, 255, 0.85);
  --pulse-duration: 2400ms;
  animation: canvasPulse var(--pulse-duration) ease-in-out infinite;
}

.canvas-wrapper.multi-view.canvas-wrapper--generating {
  animation: none;
}

.canvas-wrapper.multi-view.canvas-wrapper--generating .diagram-stage {
  animation: canvasPulse var(--pulse-duration) ease-in-out infinite;
}

.diagram-canvas {
  width: 100%;
  height: 100%;
  cursor: grab;
}

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

.diagram-canvas--selecting {
  cursor: crosshair;
}

.diagram-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  z-index: 8;
}

.diagram-overlay::before {
  content: "";
  position: absolute;
  inset: 10%;
  border-radius: 24px;
  background: var(--glow-gradient);
  filter: blur(35px);
  opacity: 0;
  animation: overlayGradientPulse var(--pulse-duration) ease-in-out infinite;
  animation-play-state: paused;
}

.diagram-overlay::after {
  content: "";
  position: absolute;
  inset: 16%;
  border-radius: 28px;
  background: var(--glow-solid);
  filter: blur(26px);
  opacity: 0;
  animation: overlaySolidPulse var(--pulse-duration) ease-in-out infinite;
  animation-play-state: paused;
}

.diagram-overlay.is-active {
  opacity: 1;
}

.diagram-overlay.is-active::before {
  opacity: 1;
  animation-play-state: running;
}

.diagram-overlay.is-active::after {
  opacity: 1;
  animation-play-state: running;
}

.canvas-wrapper.multi-view .diagram-overlay {
  left: 180px;
  width: calc(100% - 180px);
}

.diagram-overlay__label {
  position: relative;
  font-size: clamp(22px, 3.5vw, 44px);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--glow-text);
  text-shadow: 0 0 20px var(--glow-color-strong);
  font-weight: 600;
  display: inline-grid;
  place-items: center;
  text-align: center;
  padding: 0 24px;
  max-width: min(80vw, 720px);
  perspective: 700px;
}

.diagram-overlay__label-text,
.diagram-overlay__label-next {
  grid-area: 1 / 1;
  text-align: center;
}

.diagram-overlay__label-next {
  opacity: 0;
  transform: translateY(12px) rotateX(-35deg);
}

.diagram-overlay__label.is-rotating .diagram-overlay__label-text {
  animation: diagramLabelOut 520ms ease forwards;
}

.diagram-overlay__label.is-rotating .diagram-overlay__label-next {
  animation: diagramLabelIn 520ms ease forwards;
}

.diagram-overlay.is-active .diagram-overlay__label {
  animation: labelPulse var(--pulse-duration) ease-in-out infinite;
}

@keyframes canvasPulse {

  0%,
  100% {
    box-shadow: 0 0 30px var(--glow-color), inset 0 0 25px var(--glow-color);
  }

  50% {
    box-shadow: 0 0 70px var(--glow-color-strong), inset 0 0 55px var(--glow-color-strong);
  }
}

@keyframes overlayGradientPulse {

  0%,
  100% {
    opacity: 0.25;
    transform: scale(0.98);
  }

  50% {
    opacity: 0.7;
    transform: scale(1.02);
  }
}

@keyframes overlaySolidPulse {

  0%,
  100% {
    opacity: 0.55;
  }

  50% {
    opacity: 0.15;
  }
}

@keyframes labelPulse {

  0%,
  100% {
    opacity: 0.7;
    transform: scale(0.98);
  }

  50% {
    opacity: 1;
    transform: scale(1.02);
  }
}

@keyframes diagramLabelOut {

  0% {
    opacity: 1;
    transform: translateY(0) rotateX(0deg);
  }

  100% {
    opacity: 0;
    transform: translateY(-12px) rotateX(35deg);
  }
}

@keyframes diagramLabelIn {

  0% {
    opacity: 0;
    transform: translateY(12px) rotateX(-35deg);
  }

  100% {
    opacity: 1;
    transform: translateY(0) rotateX(0deg);
  }
}

@keyframes siteGlowPulse {

  0%,
  100% {
    box-shadow: 0 0 40px var(--glow-color);
  }

  50% {
    box-shadow: 0 0 120px var(--glow-color-strong);
  }
}

/* --- Canvas Assistant --- */
.canvas-assistant__star {
  position: absolute;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid rgba(6, 182, 212, 0.4);
  background: radial-gradient(circle at 30% 30%, rgba(6, 182, 212, 0.45), rgba(2, 6, 23, 0.9));
  color: var(--accent-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transform: scale(0.8);
  pointer-events: none;
  box-shadow: 0 0 20px rgba(6, 182, 212, 0.35);
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 12;
}

.canvas-assistant__star svg {
  width: 18px;
  height: 18px;
}

.canvas-assistant__star.is-visible {
  opacity: 1;
  transform: scale(1);
  pointer-events: auto;
  animation: starPulse 2.6s ease-in-out infinite;
}

@keyframes starPulse {
  0%,
  100% {
    box-shadow: 0 0 16px rgba(6, 182, 212, 0.3);
  }
  50% {
    box-shadow: 0 0 28px rgba(6, 182, 212, 0.55);
  }
}

.canvas-assistant {
  position: absolute;
  min-width: 260px;
  max-width: 340px;
  background: rgba(2, 6, 23, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 14px;
  padding: 12px;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transform: translateY(10px) scale(0.98);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 12;
}

.canvas-assistant.is-open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.canvas-assistant__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.canvas-assistant__actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.canvas-assistant__heading {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.canvas-assistant__title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-main);
}

.canvas-assistant__selection {
  font-size: 11px;
  color: var(--text-muted);
}

.canvas-assistant__action {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px;
  display: flex;
  align-items: center;
  transition: color 0.2s ease;
}

.canvas-assistant__action:hover {
  color: var(--text-main);
}

.canvas-assistant__messages {
  max-height: 220px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-right: 4px;
}

.canvas-assistant__message {
  display: flex;
}

.canvas-assistant__message--user {
  justify-content: flex-end;
}

.canvas-assistant__message--assistant {
  justify-content: flex-start;
}

.canvas-assistant__bubble {
  padding: 8px 12px;
  border-radius: 14px;
  font-size: 12px;
  line-height: 1.4;
  max-width: 100%;
  word-break: break-word;
}

.canvas-assistant__message--user .canvas-assistant__bubble {
  background: linear-gradient(135deg, rgba(6, 182, 212, 0.85), rgba(8, 145, 178, 0.95));
  color: #f8fafc;
  border-bottom-right-radius: 4px;
}

.canvas-assistant__message--assistant .canvas-assistant__bubble {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--text-main);
  border-bottom-left-radius: 4px;
}

.canvas-assistant__bubble p {
  margin: 0 0 6px;
}

.canvas-assistant__bubble p:last-child {
  margin-bottom: 0;
}

.canvas-assistant__bubble ul,
.canvas-assistant__bubble ol {
  margin: 0 0 6px 16px;
  padding: 0;
}

.canvas-assistant__bubble code {
  font-family: var(--font-mono);
  font-size: 11px;
  background: rgba(255, 255, 255, 0.12);
  padding: 2px 4px;
  border-radius: 6px;
}

.canvas-assistant__typing {
  align-self: flex-start;
  width: 100%;
}

.canvas-assistant__typing.typing-indicator {
  --typing-indicator-width: 100%;
  width: 100%;
  padding: 6px 0;
  border-radius: 0;
  background: transparent;
  border: none;
}

.canvas-assistant__typing.typing-indicator--processing {
  padding: 6px 0;
  background: transparent;
  border: none;
}

.canvas-assistant__typing .thinking-content {
  font-size: 12px;
}

.canvas-assistant__typing .thinking-icon {
  width: 14px;
  height: 14px;
}

.canvas-assistant__composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin-top: 10px;
}

.canvas-assistant__input {
  flex: 1;
  min-height: 32px;
  max-height: 200px;
  resize: none;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  background: rgba(15, 23, 42, 0.6);
  color: var(--text-main);
  padding: 6px 8px;
  font-size: 12px;
  font-family: inherit;
  outline: none;
}

.canvas-assistant__input::placeholder {
  color: var(--text-dim);
}

.canvas-assistant__send {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1px solid rgba(6, 182, 212, 0.35);
  background: rgba(6, 182, 212, 0.15);
  color: var(--accent-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.canvas-assistant__send:hover {
  color: #e0f7ff;
  border-color: rgba(6, 182, 212, 0.6);
  transform: translateY(-1px);
}

.canvas-assistant__send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* --- Chat Sidebar --- */
.chat-sidebar {
  width: 400px;
  background: linear-gradient(160deg, rgba(0, 0, 0, 0.6) 0%, rgba(255, 255, 255, 0.05) 50%, rgba(255, 215, 0, 0.05) 100%);
  /* Black -> White transparent -> Yellow transparent */
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-left: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  flex-direction: column;
  z-index: 20;
  box-shadow: -10px 0 30px rgba(0, 0, 0, 0.4);
  transition: margin-right 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s ease, transform 0.3s ease, width 0.3s ease;
  overflow: hidden;
}

.chat-sidebar__topbar {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-light);
  background: rgba(2, 6, 23, 0.55);
}

.chat-sidebar.collapsed {
  width: 0;
  padding: 0;
  opacity: 0;
  border-left: none;
  pointer-events: none;
}

.chat-toggle-handle {
  position: absolute;
  top: 16px;
  right: 16px;
  display: none;
  z-index: 30;
  background: rgba(2, 6, 23, 0.75);
  border-color: rgba(255, 255, 255, 0.2);
}

.chat-toggle-handle:hover {
  border-color: rgba(255, 255, 255, 0.35);
  background: rgba(2, 6, 23, 0.85);
}

.chat-sidebar.collapsed + .chat-toggle-handle {
  display: inline-flex;
}

.selection-indicator {
  padding: 16px 18px 12px;
  border-bottom: 1px solid var(--border-light);
  background: rgba(2, 6, 23, 0.55);
  display: flex;
  flex-direction: column;
  gap: 10px;
  display: none;
}

.selection-indicator__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.selection-indicator__title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--text-dim);
  font-weight: 600;
}

.selection-indicator__diagram {
  font-size: 12px;
  color: var(--accent-primary);
  font-weight: 600;
}

.selection-indicator__empty {
  font-size: 12px;
  color: var(--text-muted);
}

.selection-indicator__section {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.selection-indicator__section.is-hidden {
  display: none;
}

.selection-indicator__label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-dim);
}

.selection-indicator__tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.selection-tag {
  font-size: 11px;
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-main);
  white-space: nowrap;
}

.selection-tag--node {
  border-color: rgba(6, 182, 212, 0.45);
  background: rgba(6, 182, 212, 0.12);
  color: #bff5ff;
}

.selection-tag--edge {
  border-color: rgba(16, 185, 129, 0.45);
  background: rgba(16, 185, 129, 0.12);
  color: #c7ffea;
}

.chat-actions {
  padding: 10px 18px;
  border-bottom: 1px solid var(--border-light);
  background: rgba(2, 6, 23, 0.4);
  display: flex;
  justify-content: flex-end;
}

.chat-action-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: color 0.2s ease, border-color 0.2s ease, background 0.2s ease, transform 0.2s ease;
}

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

.chat-action-btn:hover {
  color: var(--text-main);
  border-color: rgba(255, 255, 255, 0.35);
  background: rgba(255, 255, 255, 0.12);
  transform: translateY(-1px);
}

/* Chat Header / Settings */
.chat-header {
  padding: 16px;
  border-bottom: 1px solid var(--border-light);
}

.chat-settings {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.setting-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.setting-label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
}

/* Modern Select */
.select-wrapper {
  position: relative;
}

.select {
  appearance: none;
  background: var(--bg-input);
  border: 1px solid var(--border-light);
  color: var(--text-main);
  padding: 6px 30px 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  transition: border-color 0.2s;
}

.select:hover,
.select:focus {
  border-color: var(--accent-primary);
  outline: none;
}

.select-wrapper::after {
  content: '';
  position: absolute;
  right: 10px;
  top: 50%;
  margin-top: -2px;
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 4px solid var(--text-muted);
  pointer-events: none;
}

/* Switch */
.switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  gap: 8px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: relative;
  width: 36px;
  height: 20px;
  background-color: var(--bg-input);
  border: 1px solid var(--border-light);
  border-radius: 20px;
  transition: .3s;
}

.slider:before {
  position: absolute;
  content: "";
  height: 14px;
  width: 14px;
  left: 2px;
  bottom: 2px;
  background-color: var(--text-muted);
  border-radius: 50%;
  transition: .3s;
}

input:checked+.slider {
  background-color: var(--accent-primary);
  border-color: var(--accent-primary);
}

input:checked+.slider:before {
  transform: translateX(16px);
  background-color: white;
}

.switch-label {
  font-size: 12px;
  color: var(--text-muted);
}

/* Chat History */
.chat-history {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scroll-behavior: smooth;
}

/* Messages */
.message {
  max-width: 90%;
  animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

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

.message--user {
  align-self: flex-end;
}

.message--system {
  align-self: flex-start;
}

.message__bubble {
  padding: 12px 16px;
  border-radius: 18px;
  font-size: 14px;
  line-height: 1.4;
  position: relative;
  word-wrap: break-word;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.message__content {
  max-width: 100%;
  overflow-wrap: anywhere;
}

.message__bubble--collapsible.is-collapsed .message__content {
  max-height: var(--collapsed-height, 72px);
  overflow: hidden;
}

.message__bubble--collapsible.is-expanded .message__content {
  max-height: var(--message-expand-max-height);
  overflow: auto;
  padding-right: 6px;
}

.message__expand {
  align-self: flex-start;
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(15, 23, 42, 0.35);
  color: var(--text-muted);
  cursor: pointer;
  transition: color 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.message__expand:hover {
  color: var(--text-main);
  border-color: rgba(255, 255, 255, 0.4);
  background: rgba(15, 23, 42, 0.55);
}

.message__expand:focus-visible {
  outline: 2px solid rgba(6, 182, 212, 0.6);
  outline-offset: 2px;
}

.message__bubble.is-expanded .message__expand {
  color: var(--accent-primary);
  border-color: rgba(6, 182, 212, 0.6);
  box-shadow: 0 0 12px rgba(6, 182, 212, 0.25);
}

.message--user .message__expand {
  background: rgba(2, 6, 23, 0.25);
  color: rgba(255, 255, 255, 0.9);
  border-color: rgba(255, 255, 255, 0.35);
}

.message__bubble h1,
.message__bubble h2,
.message__bubble h3,
.message__bubble h4 {
  margin: 0 0 10px;
  font-size: 16px;
  line-height: 1.3;
}

.message__bubble p {
  margin: 0 0 10px;
}

.message__bubble p:last-child {
  margin-bottom: 0;
}

.message__bubble ul,
.message__bubble ol {
  margin: 0 0 10px 18px;
  padding: 0;
}

.message__bubble li {
  margin: 2px 0;
}

.message__bubble blockquote {
  margin: 0 0 10px;
  padding-left: 12px;
  border-left: 2px solid var(--border-light);
  color: var(--text-muted);
}

.message__bubble code {
  font-family: var(--font-mono);
  font-size: 12px;
  background: rgba(255, 255, 255, 0.08);
  padding: 2px 6px;
  border-radius: 6px;
}

.message__bubble pre {
  margin: 0 0 10px;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.35);
  overflow: auto;
  font-family: var(--font-mono);
  font-size: 12px;
}

.message__bubble pre code {
  background: none;
  padding: 0;
}

.message__bubble a {
  color: var(--accent-primary);
  text-decoration: underline;
}

.message--user .message__bubble {
  background: linear-gradient(135deg, var(--accent-primary), #0891b2);
  color: white;
  border-bottom-right-radius: 4px;
  box-shadow: 0 4px 12px rgba(6, 182, 212, 0.3);
}

.message--system .message__bubble {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-light);
  color: var(--text-main);
  border-bottom-left-radius: 4px;
}

.message--system.error .message__bubble {
  border-color: rgba(239, 68, 68, 0.4);
  background: rgba(239, 68, 68, 0.1);
  color: #fca5a5;
}

.message__meta {
  font-size: 10px;
  color: var(--text-dim);
  margin-top: 4px;
  margin-left: 4px;
}

.message--user .message__meta {
  text-align: right;
  margin-right: 4px;
}

/* Thinking Indicator (Replaces Dots) */
.typing-indicator {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  padding: 8px 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  width: var(--typing-indicator-width, fit-content);
  max-width: 100%;
  align-self: flex-start;
  margin-bottom: 8px;
  animation: fadeIn 0.3s ease-out;
  overflow: hidden;
}

.typing-indicator--processing {
  background: transparent;
  border: none;
  padding: 0;
}

.typing-indicator--locked {
  width: var(--typing-indicator-width);
}

.typing-indicator__toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: none;
  border: none;
  color: inherit;
  padding: 0;
  cursor: pointer;
  width: 100%;
}

.typing-indicator__toggle:disabled {
  cursor: default;
}

.typing-indicator__toggle:focus-visible {
  outline: 2px solid rgba(6, 182, 212, 0.6);
  outline-offset: 3px;
  border-radius: 8px;
}

.typing-indicator__caret {
  width: 14px;
  height: 14px;
  color: var(--text-muted);
  transition: transform 0.2s ease;
}

.typing-indicator__toggle:disabled .typing-indicator__caret,
.typing-indicator--processing .typing-indicator__caret {
  opacity: 0;
}

.typing-indicator--open .typing-indicator__caret {
  transform: rotate(180deg);
}

.typing-indicator__panel {
  width: 100%;
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  transition: max-height 0.25s ease, opacity 0.2s ease;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  padding-top: 0;
}

.typing-indicator__toggle:disabled + .typing-indicator__panel,
.typing-indicator--processing .typing-indicator__panel {
  display: none;
}

.typing-indicator--open .typing-indicator__panel {
  max-height: 280px;
  opacity: 1;
  padding-top: 10px;
}

.typing-indicator__panel-title {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 8px;
}

.typing-indicator__panel-body {
  font-size: 13px;
  color: var(--text-main);
  max-height: 210px;
  overflow-y: auto;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
  line-height: 1.5;
  padding: 10px 12px;
  background: rgba(2, 6, 23, 0.45);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
}

.typing-indicator__panel-body code {
  font-family: var(--font-mono);
  font-size: 11px;
  background: rgba(255, 255, 255, 0.08);
  padding: 2px 4px;
  border-radius: 6px;
}

.typing-indicator__panel-body pre {
  margin: 0 0 8px;
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.35);
  max-width: 100%;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

.typing-indicator__panel-body pre code {
  background: none;
  padding: 0;
}

.thinking-content {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-main);
}

.thinking-content__text {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.typing-indicator__timer {
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: none;
  color: var(--text-muted);
  opacity: 0;
  transition: opacity 0.2s ease;
}

.typing-indicator__timer.is-active {
  opacity: 1;
}

.typing-indicator--done .loading-shimmer {
  animation: none;
  background: none;
  color: var(--text-main);
  -webkit-text-fill-color: currentColor;
}

.typing-indicator--done .brain-pulse,
.typing-indicator--done .processing-spin,
.typing-indicator--done .diagram-pulse {
  animation: none;
  filter: none;
  opacity: 0.85;
}

.typing-indicator__panel-body ol,
.typing-indicator__panel-body ul {
  padding-left: 18px;
  margin: 0 0 10px;
}

.typing-indicator__panel-body li {
  margin: 4px 0;
}

.typing-indicator__panel-body p {
  margin: 0 0 8px;
}

.typing-indicator__panel-body p:last-child {
  margin-bottom: 0;
}

.loading-shimmer {
  background: linear-gradient(90deg,
      var(--text-main) 0%,
      var(--accent-primary) 50%,
      var(--text-main) 100%);
  background-size: 200% auto;
  background-clip: text;
  -webkit-background-clip: text;
  color: transparent;
  animation: shimmer 2s linear infinite;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.thinking-icon {
  width: 18px;
  height: 18px;
  color: var(--accent-primary);
  flex-shrink: 0;
}

.thinking-icon--processing {
  display: none;
}

.typing-indicator--processing .thinking-icon--processing {
  display: inline-flex;
}

.typing-indicator--processing .thinking-icon--brain {
  display: none;
}

.typing-indicator--processing .thinking-icon {
  color: rgba(148, 163, 184, 0.9);
}

.typing-indicator--diagram .thinking-icon {
  color: var(--accent-secondary);
}

.brain-pulse {
  animation: brainPulse 2s ease-in-out infinite;
}

.processing-spin {
  animation: processingSpin 1.4s linear infinite;
}

.diagram-pulse {
  animation: diagramPulse 2.2s ease-in-out infinite;
  transform-origin: 50% 50%;
}

@keyframes brainPulse {

  0%,
  100% {
    transform: scale(1);
    opacity: 1;
    filter: drop-shadow(0 0 0px var(--accent-glow));
  }

  50% {
    transform: scale(1.15);
    opacity: 0.8;
    filter: drop-shadow(0 0 5px var(--accent-glow));
  }
}

@keyframes diagramPulse {

  0%,
  100% {
    transform: scale(1) rotate(0deg);
    opacity: 1;
    filter: drop-shadow(0 0 0px rgba(16, 185, 129, 0.45));
  }

  25% {
    transform: scale(1.06) rotate(18deg);
    opacity: 0.9;
    filter: drop-shadow(0 0 4px rgba(16, 185, 129, 0.5));
  }

  50% {
    transform: scale(1.12) rotate(0deg);
    opacity: 0.85;
    filter: drop-shadow(0 0 6px rgba(16, 185, 129, 0.55));
  }

  75% {
    transform: scale(1.06) rotate(-18deg);
    opacity: 0.9;
    filter: drop-shadow(0 0 4px rgba(16, 185, 129, 0.5));
  }
}

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

@keyframes shimmer {
  to {
    background-position: 200% center;
  }
}

/* Chat Input Area Refactor */
.chat-input-area {
  padding: 0;
  background: transparent;
  border-top: 1px solid rgba(255, 255, 255, 0.15);
  /* Made border more visible */
  background-image: linear-gradient(to top, rgba(0, 0, 0, 0.4), rgba(0, 0, 0, 0.1));
}

.input-container {
  background: transparent;
  border: none;
  border-radius: 0;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  position: relative;
}

.input-container:focus-within {
  box-shadow: none;
}

.context-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #2d2d2d;
  border: 1px solid #444;
  color: #ccc;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 13px;
  width: fit-content;
  cursor: pointer;
  transition: background 0.2s;
}

.context-badge:hover {
  background: #3d3d3d;
}

.chat-textarea {
  background: transparent;
  border: none;
  color: #eee;
  font-family: inherit;
  font-size: 15px;
  padding: 4px 0;
  resize: none;
  max-height: 120px;
  overflow-y: auto;
  outline: none;
  width: 100%;
}

.chat-textarea::placeholder {
  color: #666;
}

.mention-list {
  position: absolute;
  left: 20px;
  bottom: 100px;
  width: 260px;
  background: rgba(15, 23, 42, 0.95);
  border: 1px solid var(--border-light);
  border-radius: 12px;
  padding: 6px;
  box-shadow: var(--shadow-lg);
  display: none;
  z-index: 30;
}

.mention-list.open {
  display: block;
}

.mention-item {
  padding: 6px 8px;
  border-radius: 8px;
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
}

.mention-item:hover,
.mention-item.active {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-main);
}

.input-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 4px;
}

.controls-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

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

.select-label {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
  font-weight: 600;
}

.control-item {
  display: flex;
  align-items: center;
  gap: 4px;
  color: #aaa;
  font-size: 14px;
  cursor: pointer;
  transition: color 0.2s;
  background: none;
  border: none;
  padding: 0;
}

.control-item:hover {
  color: #fff;
}

.control-item svg {
  width: 16px;
  height: 16px;
}

/* Custom Select Dropdown */
.custom-select {
  position: relative;
  user-select: none;
  min-width: 120px;
}

.select-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  padding: 6px 12px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05), inset 0 1px 0 rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(4px);
  color: #eee;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.select-trigger:hover {
  background: rgba(255, 255, 255, 0.15);
  border-color: rgba(255, 255, 255, 0.25);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  color: #fff;
}

.select-options {
  position: absolute;
  bottom: 110%;
  /* Open upwards because it's at the bottom */
  left: 0;
  width: 100%;
  /* Or min-width: max-content */
  min-width: 140px;
  background: rgba(15, 23, 42, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 12px;
  padding: 6px;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(12px);
  z-index: 100;
  opacity: 0;
  visibility: hidden;
  transform: translateY(10px);
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  pointer-events: none;
}

.custom-select.open .select-options {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
  pointer-events: auto;
}

.option {
  padding: 8px 12px;
  border-radius: 8px;
  color: var(--text-muted);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
}

.option:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.option.selected {
  background: var(--accent-primary);
  color: #020617;
  font-weight: 600;
}

.model-select-wrapper,
.type-select-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  /* Slightly more rounded */
  padding: 4px 10px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  /* Glass border */
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05), inset 0 1px 0 rgba(255, 255, 255, 0.1);
  /* Glass highlight */
  transition: all 0.2s;
  backdrop-filter: blur(4px);
}

.model-select-wrapper:hover,
.type-select-wrapper:hover {
  background: rgba(255, 255, 255, 0.15);
  border-color: rgba(255, 255, 255, 0.2);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1), inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.model-select-wrapper:hover,
.type-select-wrapper:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.1);
}

.inline-select {
  background: transparent;
  border: none;
  color: #ccc;
  font-size: 13px;
  cursor: pointer;
  appearance: none;
  padding-right: 18px;
  outline: none;
  font-weight: 500;
}

.inline-select:hover {
  color: #fff;
}

.inline-select option {
  background-color: #0f172a;
  color: #eee;
}

.inline-arrow {
  width: 12px;
  height: 12px;
  stroke: currentColor;
  opacity: 0.7;
  transition: transform 0.2s;
}

.custom-select.open .inline-arrow {
  transform: rotate(180deg);
}

.controls-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.tool-btn {
  background: none;
  border: none;
  color: #aaa;
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
  transition: color 0.2s;
}

.tool-btn:hover {
  color: #fff;
}

.action-btn {
  background: transparent;
  border: none;
  color: #888;
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s, transform 0.1s;
}

.action-btn:hover {
  color: #fff;
}

.action-btn:active {
  transform: scale(0.9);
}

.action-btn.stop-btn {
  color: #fff;
}

.action-btn.stop-btn svg {
  fill: currentColor;
}

.action-btn svg {
  width: 24px;
  height: 24px;
}

/* Tips List in Chat */
.tips-list {
  padding-left: 20px;
  margin: 0;
}

.tips-list li {
  margin-bottom: 6px;
}

/* Toast */
.toast {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  padding: 12px 24px;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(8px);
  color: white;
  border-radius: var(--radius-full);
  font-size: 14px;
  pointer-events: none;
  opacity: 0;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  white-space: nowrap;
  border: 1px solid var(--border-light);
  box-shadow: var(--shadow-lg);
  z-index: 30;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast--error {
  background: rgba(239, 68, 68, 0.9);
  border-color: rgba(248, 113, 113, 0.6);
  color: #fff;
  box-shadow: 0 10px 20px rgba(239, 68, 68, 0.25);
}

.region-popup {
  position: absolute;
  min-width: 240px;
  max-width: 320px;
  background: rgba(2, 6, 23, 0.95);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 12px;
  box-shadow: var(--shadow-lg);
  z-index: 25;
}

.region-popup__title {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.region-popup__textarea {
  width: 100%;
  min-height: 60px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-light);
  color: var(--text-main);
  border-radius: 8px;
  padding: 6px 8px;
  font-family: inherit;
  font-size: 13px;
  resize: vertical;
  outline: none;
}

.region-popup__actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 8px;
}

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

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

::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
}

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

/* --- Multi-Diagram Display (Tabbed Left Sidebar) --- */

/* Modifier for canvas-wrapper when in multi-mode */
.canvas-wrapper.multi-view {
  display: flex;
  flex-direction: row;
  background-image: none;
  /* Remove background from wrapper, it moves to stage */
}

/* Dynamic Left Sidebar */
.left-sidebar {
  width: 180px;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(12px);
  border-right: 1px solid var(--border-light);
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
  gap: 24px;
  z-index: 5;
  animation: slideInLeft 0.3s ease-out;
}

@keyframes slideInLeft {
  from {
    transform: translateX(-20px);
    opacity: 0;
  }

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

.left-sidebar__header {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-dim);
  font-weight: 600;
  padding-left: 4px;
}

.sidebar-tabs {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sidebar-tab {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  cursor: pointer;
  color: var(--text-muted);
  border: 1px solid transparent;
  transition: all 0.2s;
  background: rgba(255, 255, 255, 0.02);
}

.sidebar-tab:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-main);
}

.sidebar-tab.active {
  background: linear-gradient(135deg, var(--accent-primary), rgba(6, 182, 212, 0.5));
  color: white;
  border-color: rgba(255, 255, 255, 0.1);
  box-shadow: 0 4px 12px rgba(6, 182, 212, 0.2);
}

/* Specific Tab Colors */
.sidebar-tab[data-type="usecase"].active {
  background: linear-gradient(135deg, var(--accent-primary), #0891b2);
}

.sidebar-tab[data-type="activity"].active {
  background: linear-gradient(135deg, var(--accent-secondary), #059669);
}

.sidebar-tab[data-type="class"].active {
  background: linear-gradient(135deg, #f97316, #ea580c);
}

.tab-icon {
  width: 18px;
  height: 18px;
  opacity: 0.8;
}

.tab-label {
  font-size: 13px;
  font-weight: 500;
}

/* Diagram Stage */
.diagram-stage {
  flex: 1;
  position: relative;
  overflow: hidden;
  background-image: radial-gradient(circle at 1px 1px, rgba(255, 255, 255, 0.05) 1px, transparent 0);
  background-size: 24px 24px;
}

/* Diagram Layers (Overlapping) */
.diagram-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease;
  pointer-events: none;
  /* Let clicks pass through inactive layers */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.diagram-layer.active {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  z-index: 10;
}

.diagram-layer canvas {
  width: 100%;
  height: 100%;
}

/* Loading State in Layer */
.diagram-layer__loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  color: var(--text-muted);
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.canvas-wrapper--generating .diagram-layer__loading {
  opacity: 0;
  transform: scale(0.98);
}

@media (max-width: 1024px) {
  .chat-sidebar {
    width: 320px;
  }

  .selection-indicator {
    padding: 12px 14px 10px;
  }

  .canvas-assistant {
    max-width: 280px;
  }
}

@media (max-width: 768px) {
  .chat-sidebar {
    width: 280px;
  }

  .canvas-assistant {
    max-width: 240px;
  }
}
