:root {
  /* Core Studio Light Theme (Default Spatial Canvas) */
  --bg-canvas: hsl(220, 20%, 96%);
  --bg-dot: hsl(220, 14%, 82%);
  --surface-glass: hsla(0, 0%, 100%, 0.92);
  --surface-solid: hsl(0, 0%, 100%);
  --surface-muted: hsl(220, 18%, 94%);
  --surface-hover: hsl(220, 20%, 91%);
  --border-subtle: hsl(220, 16%, 88%);
  --border-strong: hsl(220, 16%, 78%);
  --text-primary: hsl(222, 32%, 12%);
  --text-secondary: hsl(220, 14%, 38%);
  --text-muted: hsl(220, 10%, 54%);

  /* Brand & Functional Accents */
  --accent-primary: hsl(224, 82%, 54%);
  --accent-primary-hover: hsl(224, 82%, 46%);
  --accent-primary-soft: hsla(224, 82%, 54%, 0.12);
  --accent-ai: hsl(168, 76%, 36%);
  --accent-ai-soft: hsla(168, 76%, 36%, 0.12);
  --accent-warn: hsl(32, 92%, 50%);
  --accent-danger: hsl(354, 78%, 56%);
  --accent-success: hsl(152, 68%, 38%);

  /* Elevations */
  --shadow-sm: 0 2px 6px -1px rgba(15, 23, 42, 0.06), 0 1px 2px -1px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 10px 24px -4px rgba(15, 23, 42, 0.09), 0 4px 8px -2px rgba(15, 23, 42, 0.05);
  --shadow-lg: 0 20px 40px -8px rgba(15, 23, 42, 0.14), 0 8px 16px -4px rgba(15, 23, 42, 0.06);
  --shadow-node-selected: 0 0 0 2.5px hsl(224, 82%, 54%), 0 14px 28px -6px rgba(37, 99, 235, 0.22);

  /* Typography */
  --font-sans: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  /* Radius */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-pill: 9999px;
}

[data-theme="dark"] {
  --bg-canvas: hsl(222, 24%, 10%);
  --bg-dot: hsl(220, 16%, 22%);
  --surface-glass: hsla(222, 22%, 14%, 0.92);
  --surface-solid: hsl(222, 22%, 15%);
  --surface-muted: hsl(222, 20%, 19%);
  --surface-hover: hsl(222, 20%, 23%);
  --border-subtle: hsl(222, 16%, 24%);
  --border-strong: hsl(222, 16%, 32%);
  --text-primary: hsl(210, 25%, 96%);
  --text-secondary: hsl(215, 16%, 72%);
  --text-muted: hsl(215, 12%, 52%);
  --shadow-sm: 0 2px 6px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 12px 28px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 24px 48px rgba(0, 0, 0, 0.6);
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: var(--font-sans);
  color: var(--text-primary);
  background-color: var(--bg-canvas);
  user-select: none;
  -webkit-font-smoothing: antialiased;
}

/* Spatial Dot Matrix Canvas */
#app-viewport {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  cursor: default;
  background-color: var(--bg-canvas);
  background-image: radial-gradient(var(--bg-dot) 1.35px, transparent 1.35px);
  background-size: 24px 24px;
  background-position: 0 0;
}

#app-viewport.panning {
  cursor: grabbing !important;
}

#app-viewport.tool-pan {
  cursor: grab;
}

#app-viewport.tool-pen {
  cursor: crosshair;
}

/* World Transform Layer */
#canvas-world {
  position: absolute;
  top: 0;
  left: 0;
  width: 0;
  height: 0;
  transform-origin: 0 0;
  will-change: transform;
}

#connections-svg {
  position: absolute;
  top: -10000px;
  left: -10000px;
  width: 20000px;
  height: 20000px;
  pointer-events: none;
  overflow: visible;
  z-index: 1;
}

#connections-svg path.connector-hit {
  pointer-events: stroke;
  cursor: pointer;
}

#nodes-layer {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 2;
}

#cursors-layer {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 50;
  pointer-events: none;
}

/* Top Floating Header Bar */
.top-bar {
  position: fixed;
  top: 14px;
  left: 16px;
  right: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  pointer-events: none;
  z-index: 100;
  gap: 12px;
}

.glass-island {
  pointer-events: auto;
  background: var(--surface-glass);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
}

.brand-badge {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 4px 8px 4px 4px;
  border-right: 1px solid var(--border-subtle);
}

.brand-logo {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: linear-gradient(135deg, hsl(224, 82%, 54%), hsl(195, 85%, 45%));
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 15px;
  letter-spacing: -0.03em;
  box-shadow: 0 2px 8px hsla(224, 82%, 54%, 0.35);
}

.board-title-input {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-weight: 700;
  font-size: 14px;
  padding: 4px 8px;
  border-radius: 6px;
  width: 230px;
  transition: all 0.15s ease;
}

.board-title-input:hover,
.board-title-input:focus {
  background: var(--surface-muted);
  border-color: var(--border-strong);
  outline: none;
}

/* Buttons & Controls */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-family: var(--font-sans);
  font-size: 12.5px;
  font-weight: 600;
  padding: 6px 11px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.btn:hover {
  background: var(--surface-hover);
  color: var(--text-primary);
}

.btn-primary {
  background: var(--accent-primary);
  color: #ffffff;
  box-shadow: 0 2px 6px hsla(224, 82%, 54%, 0.28);
}

.btn-primary:hover {
  background: var(--accent-primary-hover);
  color: #ffffff;
}

.btn-ai {
  background: var(--accent-ai-soft);
  color: var(--accent-ai);
  border-color: hsla(168, 76%, 36%, 0.28);
  font-weight: 700;
}

.btn-ai:hover {
  background: var(--accent-ai);
  color: #ffffff;
}

.btn-outline {
  border-color: var(--border-subtle);
  background: var(--surface-solid);
  color: var(--text-primary);
}

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

.btn-icon {
  padding: 7px;
  width: 34px;
  height: 34px;
}

/* Presence Avatars */
.presence-list {
  display: flex;
  align-items: center;
  gap: 4px;
  padding-right: 6px;
  border-right: 1px solid var(--border-subtle);
}

.avatar-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px 3px 4px;
  border-radius: var(--radius-pill);
  font-size: 12px;
  font-weight: 600;
  background: var(--surface-muted);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  cursor: pointer;
  transition: transform 0.15s ease;
}

.avatar-pill:hover {
  transform: translateY(-1px);
}

.avatar-circle {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  position: relative;
}

.status-dot {
  position: absolute;
  bottom: -1px;
  right: -1px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #10b981;
  border: 1.5px solid var(--surface-solid);
}

/* Left Vertical Creation Dock */
.left-dock {
  position: fixed;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px;
  z-index: 100;
}

.tool-btn {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
  transition: all 0.15s ease;
}

.tool-btn:hover {
  background: var(--surface-hover);
  color: var(--text-primary);
}

.tool-btn.active {
  background: var(--accent-primary);
  color: #ffffff;
  box-shadow: 0 4px 12px hsla(224, 82%, 54%, 0.35);
}

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

/* Tooltip on Left Dock */
.tool-btn[data-tooltip]:hover::after {
  content: attr(data-tooltip);
  position: absolute;
  left: 50px;
  background: hsl(222, 32%, 14%);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 6px;
  white-space: nowrap;
  box-shadow: var(--shadow-md);
  pointer-events: none;
  z-index: 200;
}

/* Bottom HUD Bar */
.bottom-bar {
  position: fixed;
  bottom: 16px;
  left: 16px;
  right: 16px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  pointer-events: none;
  z-index: 100;
}

/* Minimap */
.minimap-card {
  width: 190px;
  height: 120px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

#minimap-canvas {
  width: 100%;
  height: 100%;
  border-radius: 6px;
  background: var(--surface-muted);
  cursor: pointer;
}

/* Board Nodes */
.board-node {
  position: absolute;
  border-radius: var(--radius-md);
  transition: box-shadow 0.15s ease;
  user-select: none;
  cursor: grab;
}

.board-node:active {
  cursor: grabbing;
}

.board-node.selected {
  box-shadow: var(--shadow-node-selected) !important;
  z-index: 30 !important;
}

/* Frame Container Node */
.node-frame {
  background: hsla(220, 25%, 97%, 0.65);
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  z-index: 1 !important;
}

[data-theme="dark"] .node-frame {
  background: hsla(222, 22%, 14%, 0.45);
}

.frame-header {
  position: absolute;
  top: -30px;
  left: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 13px;
  color: var(--text-secondary);
  background: var(--surface-solid);
  padding: 3px 10px;
  border-radius: 6px;
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-sm);
}

/* Mind Map Node */
.node-mindmap {
  background: var(--surface-solid);
  border: 2px solid var(--accent-primary);
  border-radius: 999px;
  padding: 12px 22px;
  min-width: 160px;
  max-width: 300px;
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  z-index: 10;
}

.node-mindmap.mm-root {
  background: linear-gradient(135deg, hsl(224, 82%, 52%), hsl(204, 86%, 46%));
  color: #ffffff;
  border: none;
  padding: 16px 28px;
  font-size: 16px;
  font-weight: 800;
  box-shadow: 0 12px 28px hsla(224, 82%, 52%, 0.32);
}

.node-mindmap.mm-branch {
  border-radius: 14px;
  padding: 10px 18px;
}

.mm-quick-add {
  position: absolute;
  right: -14px;
  top: 50%;
  transform: translateY(-50%);
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent-primary);
  color: #fff;
  border: 2px solid var(--surface-solid);
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
}

.board-node:hover .mm-quick-add,
.board-node.selected .mm-quick-add {
  display: flex;
}

/* Sticky Note */
.node-sticky {
  padding: 16px;
  border-radius: 4px 14px 14px 14px;
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.1), 0 2px 4px rgba(15, 23, 42, 0.06);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  color: hsl(222, 32%, 14%);
  z-index: 12;
  border: 1px solid rgba(0, 0, 0, 0.06);
}

.sticky-yellow { background: #fef08a; }
.sticky-emerald { background: #a7f3d0; }
.sticky-sky { background: #bae6fd; }
.sticky-rose { background: #fecdd3; }
.sticky-amber { background: #fde68a; }
.sticky-lavender { background: #e9d5ff; }

/* Task Card */
.node-task {
  background: var(--surface-solid);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 14px;
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 14;
}

.task-top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.status-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.status-backlog { background: hsla(220, 14%, 50%, 0.15); color: var(--text-secondary); }
.status-progress { background: hsla(224, 82%, 54%, 0.15); color: hsl(224, 82%, 54%); }
.status-review { background: hsla(32, 92%, 50%, 0.16); color: hsl(32, 85%, 42%); }
.status-done { background: hsla(152, 68%, 38%, 0.16); color: hsl(152, 68%, 34%); }

.priority-dot {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 5px;
}

.prio-alta { background: hsla(354, 78%, 56%, 0.14); color: hsl(354, 78%, 52%); }
.prio-media { background: hsla(32, 92%, 50%, 0.14); color: hsl(32, 85%, 42%); }
.prio-baja { background: hsla(152, 68%, 38%, 0.14); color: hsl(152, 68%, 34%); }

/* Editable Content Inside Nodes */
.node-title {
  font-weight: 700;
  font-size: 14px;
  line-height: 1.35;
  outline: none;
  word-break: break-word;
}

.node-body {
  font-size: 12.5px;
  line-height: 1.45;
  opacity: 0.88;
  outline: none;
  word-break: break-word;
}

.node-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
}

.tag-chip {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 5px;
  background: rgba(15, 23, 42, 0.07);
  color: inherit;
}

[data-theme="dark"] .node-task .tag-chip,
[data-theme="dark"] .node-mindmap:not(.mm-root) .tag-chip {
  background: rgba(255, 255, 255, 0.1);
}

.node-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 8px;
  border-top: 1px solid rgba(128, 128, 128, 0.14);
  font-size: 11.5px;
  font-weight: 600;
  opacity: 0.85;
}

/* Connection Ports */
.port-handle {
  position: absolute;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--surface-solid);
  border: 2px solid var(--accent-primary);
  opacity: 0;
  transition: opacity 0.15s ease, transform 0.15s ease;
  cursor: crosshair;
  z-index: 40;
}

.board-node:hover .port-handle,
.board-node.selected .port-handle {
  opacity: 1;
}

.port-handle:hover {
  transform: scale(1.35);
  background: var(--accent-primary);
}

.port-top { top: -6px; left: calc(50% - 5.5px); }
.port-right { right: -6px; top: calc(50% - 5.5px); }
.port-bottom { bottom: -6px; left: calc(50% - 5.5px); }
.port-left { left: -6px; top: calc(50% - 5.5px); }

/* Resize Handle */
.resize-handle {
  position: absolute;
  width: 14px;
  height: 14px;
  right: 2px;
  bottom: 2px;
  cursor: nwse-resize;
  opacity: 0;
}

.board-node:hover .resize-handle,
.board-node.selected .resize-handle {
  opacity: 0.65;
}

/* Context Inspector Bar for Selected Node */
.selection-inspector {
  position: fixed;
  top: 68px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 110;
  display: none;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
}

.selection-inspector.visible {
  display: flex;
}

.color-swatch {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid rgba(0, 0, 0, 0.15);
  cursor: pointer;
  transition: transform 0.12s ease;
}

.color-swatch:hover {
  transform: scale(1.2);
}

/* AI Assistant Drawer */
.ai-drawer {
  position: fixed;
  top: 68px;
  right: 16px;
  width: 370px;
  max-height: calc(100vh - 150px);
  display: flex;
  flex-direction: column;
  z-index: 120;
  overflow: hidden;
  transition: transform 0.22s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.2s ease;
}

.ai-drawer.hidden {
  transform: translateX(400px);
  opacity: 0;
  pointer-events: none;
}

.ai-drawer-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.ai-drawer-body {
  padding: 14px 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.ai-action-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.ai-card-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  background: var(--surface-solid);
  color: var(--text-primary);
  cursor: pointer;
  text-align: left;
  transition: all 0.15s ease;
}

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

.ai-card-btn strong {
  font-size: 12.5px;
  display: flex;
  align-items: center;
  gap: 5px;
}

.ai-card-btn span {
  font-size: 11.5px;
  color: var(--text-secondary);
  line-height: 1.3;
}

.ai-prompt-textarea {
  width: 100%;
  min-height: 76px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface-solid);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 13px;
  resize: vertical;
}

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

.ai-log-box {
  background: var(--surface-muted);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--text-primary);
  max-height: 210px;
  overflow-y: auto;
  white-space: pre-wrap;
}

/* Remote Collaborator Cursor */
.remote-cursor {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
  transition: transform 0.08s linear;
  z-index: 90;
}

.remote-cursor-label {
  margin-left: 14px;
  margin-top: -4px;
  padding: 3px 8px;
  border-radius: 999px;
  color: #fff;
  font-size: 11.5px;
  font-weight: 700;
  white-space: nowrap;
  box-shadow: var(--shadow-sm);
}

/* Modal Dialog */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 300;
}

.modal-backdrop.open {
  display: flex;
}

.modal-card {
  width: 92%;
  max-width: 480px;
  background: var(--surface-solid);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

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

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

.form-input, .form-select {
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface-solid);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 13.5px;
}

/* Toast Notification */
.toast-container {
  position: fixed;
  bottom: 72px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 400;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast-msg {
  background: hsl(222, 32%, 14%);
  color: #fff;
  padding: 9px 16px;
  border-radius: var(--radius-pill);
  font-size: 12.5px;
  font-weight: 600;
  box-shadow: var(--shadow-md);
  display: flex;
  align-items: center;
  gap: 8px;
  animation: toastIn 0.2s ease;
}

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

@media (max-width: 768px) {
  .board-title-input { width: 130px; }
  .minimap-card { display: none; }
  .ai-drawer { width: calc(100vw - 32px); }
}
