*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%; width: 100%;
  overflow: hidden;
  font-family: var(--font-main);
  background: var(--bg);
  color: var(--text);
}

#app {
  display: block;
  height: 100vh;
  width: 100vw;
  position: relative;
}

/* Sidebar is now a floating glass widget on the left of the canvas */
#sidebar {
  position: absolute;
  top: 38px; /* below sprint label bar (52px) + gap */
  left: 12px;
  width: 260px;
  height: calc(100vh - 50px);
  background: var(--glass-surface);
  backdrop-filter: blur(14px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 30;
  box-shadow: 0 4px 32px rgba(0,0,0,0.4);
}

/* Top-right canvas overlay: project dropdown + legend in one row */
#canvas-topright {
  position: absolute;
  top: 38px;
  right: 12px;
  z-index: 30;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 10px;
  background: var(--glass-chrome);
  backdrop-filter: blur(10px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  padding: 6px 12px;
  pointer-events: auto;
}
#canvas-topright > * > button,
#canvas-topright > button {
  height: 28px;
  box-sizing: border-box;
}

#btn-sync-local {
  background: rgba(255,255,255,0.08);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  padding: 3px 8px;
  font-size: 13px;
  cursor: pointer;
  font-family: var(--font-main);
  transition: color 0.15s, background 0.15s;
}
#btn-sync-local:hover { color: var(--text); background: var(--hover-bg); }
#btn-sync-local:focus-visible { outline: 2px solid rgba(255,255,255,0.5); outline-offset: 2px; }
#btn-sync-local:disabled { opacity: 0.4; cursor: default; }

/* AI button fan-out wrapper */
#ai-btn-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
}

#collect-for-ai {
  background: rgba(255,255,255,0.08);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  padding: 3px 8px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font-main);
  transition: color 0.15s, background 0.15s;
  position: relative;
  z-index: 2;
}
#ai-btn-wrap:hover #collect-for-ai { color: transparent; background: rgba(255,255,255,0.04); border-color: transparent; }

/* Fan-out labels */
.ai-fan-label {
  position: absolute;
  bottom: calc(100% + 6px);
  transform: scale(0.7);
  opacity: 0;
  pointer-events: none;
  white-space: nowrap;
  font-size: 9px;
  font-weight: 600;
  font-family: var(--font-main);
  line-height: 1.2;
  text-align: center;
  color: var(--text-muted);
  background: var(--glass-popup);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 3px 6px;
  z-index: 1;
  transition: opacity 0.2s ease, transform 0.2s ease;
  transform-origin: bottom center;
}
#ai-label-left  { right: calc(50% + 5px); }
#ai-label-right { left:  calc(50% + 5px); }

#ai-btn-wrap:hover .ai-fan-label {
  opacity: 1;
  transform: scale(1);
  pointer-events: auto;
}

/* Flash feedback on click */
.ai-fan-flash {
  color: #fff !important;
  background: rgba(56,161,105,0.85) !important;
  border-color: rgba(56,161,105,0.6) !important;
  transition: none !important;
}

#role-toggle {
  background: rgba(255,105,180,0.15);
  border: 1px solid rgba(255,105,180,0.5);
  border-radius: var(--radius-sm);
  color: #ff69b4;
  padding: 3px 8px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font-main);
  transition: background 0.15s;
  white-space: nowrap;
}
#role-toggle:hover { background: rgba(255,105,180,0.28); }
#role-toggle:focus-visible { outline: 2px solid rgba(255,255,255,0.5); outline-offset: 2px; }
#role-toggle.is-owner {
  background: rgba(255,105,180,0.08);
  color: rgba(255,105,180,0.6);
}

#changes-dropdown-btn {
  background: rgba(214,158,46,0.15);
  border: 1px solid rgba(214,158,46,0.4);
  border-radius: var(--radius-sm);
  color: #d69e2e;
  padding: 3px 8px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font-main);
  transition: background 0.15s;
}
#changes-dropdown-btn:hover { background: rgba(214,158,46,0.25); }
#changes-dropdown-btn:focus-visible { outline: 2px solid rgba(255,255,255,0.5); outline-offset: 2px; }

.workspace-switcher-btn {
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
  font-family: var(--font-main);
  min-width: 100px;
  text-align: left;
  white-space: nowrap;
  transition: background var(--transition);
}
.workspace-switcher-btn:hover { background: var(--hover-bg); }
.workspace-switcher-btn:focus-visible { outline: 2px solid rgba(255,255,255,0.5); outline-offset: 2px; }
.workspace-switcher-menu {
  position: absolute;
  top: 100%;
  right: 0;
  min-width: 180px;
  z-index: 300;
  padding: 10px 0 4px;
}
.workspace-switcher-item {
  padding: 6px 14px;
  font-size: 12px;
  color: var(--text);
  cursor: pointer;
  transition: background var(--transition);
  display: flex;
  align-items: center;
  gap: 6px;
}
.workspace-switcher-name {
  flex: 1;
  text-align: right;
}
.workspace-backup-btn,
.workspace-rename-btn {
  font-size: 9px;
  padding: 1px 6px;
  border-radius: 3px;
  border: 1px solid var(--glass-border);
  background: rgba(255,255,255,0.05);
  color: var(--text-muted);
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}
.workspace-backup-btn:hover,
.workspace-rename-btn:hover {
  background: rgba(255,255,255,0.12);
  color: var(--text);
}
.workspace-rename-btn { margin-left: 6px; }
.workspace-switcher-item:hover { background: var(--hover-bg); }
.workspace-switcher-item.active { color: #90cdf4; background: var(--active-bg); }
.workspace-switcher-divider { border: none; border-top: 1px solid var(--border); margin: 4px 0; }
.workspace-switcher-create {
  padding: 6px 14px;
  font-size: 12px;
  color: #68d391;
  cursor: pointer;
  transition: background var(--transition);
}
.workspace-switcher-create:hover { background: rgba(56,161,105,0.1); }

/* Sign-in button */
#btn-sign-in {
  background: rgba(0,71,171,0.15);
  border: 1px solid rgba(0,71,171,0.5);
  border-radius: var(--radius-sm);
  color: #6ba3ff;
  padding: 3px 8px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font-main);
  transition: background 0.15s;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
#btn-sign-in:hover { background: rgba(0,71,171,0.28); }
#btn-sign-in:focus-visible { outline: 2px solid rgba(255,255,255,0.5); outline-offset: 2px; }

.user-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--glass-border);
  vertical-align: middle;
}
.user-avatar-initials {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,71,171,0.4);
  color: #6ba3ff;
  font-size: 10px;
  font-weight: 700;
}

/* Shared top-bar action button style (AI, Share, Members) */
.topbar-action-btn {
  background: rgba(255,255,255,0.08);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  padding: 3px 8px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font-main);
  transition: color 0.15s, background 0.15s;
  white-space: nowrap;
}
.topbar-action-btn:hover { color: var(--text); background: var(--hover-bg); }
.topbar-action-btn:focus-visible { outline: 2px solid rgba(255,255,255,0.5); outline-offset: 2px; }

#canvas-legend {
  position: absolute;
  bottom: 16px;
  right: 16px;
  z-index: 30;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 10px;
  background: var(--glass-chrome);
  backdrop-filter: blur(10px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  padding: 5px 12px;
  pointer-events: none;
}

/* Keyboard shortcut hints shown inside the legend */
.legend-shortcuts {
  display: flex;
  gap: 8px;
  margin-left: 6px;
  padding-left: 8px;
  border-left: 1px solid var(--glass-border);
  font-size: 9px;
  color: rgba(255,255,255,0.3);
  white-space: nowrap;
}
.legend-shortcut-key {
  font-family: var(--font-mono);
  font-size: 9px;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 2px;
  padding: 0 3px;
  margin-right: 2px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
}

.legend-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
  display: inline-block;
}

#sidebar-actions {
  position: absolute;
  top: 38px;
  left: 280px;
  z-index: 31;
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: flex-start;
}

#sidebar-actions-row1 {
  display: flex;
  gap: 4px;
  align-items: center;
}

.sidebar-action-btn {
  background: var(--glass-surface);
  backdrop-filter: blur(10px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  color: var(--text-muted);
  font-family: var(--font-main);
  font-size: 11px;
  font-weight: 600;
  padding: 5px 10px;
  cursor: pointer;
  white-space: nowrap;
  transition: color 0.15s, background 0.15s;
}
.sidebar-action-btn:hover { color: var(--text); background: var(--hover-bg); }
.sidebar-action-btn:focus-visible { outline: 2px solid rgba(255,255,255,0.5); outline-offset: 2px; }
.sidebar-action-btn:disabled { opacity: 0.5; cursor: default; }
#context-filter.active { background: rgba(56,161,105,0.3); border-color: #38a169; color: #38a169; }

.sort-btn {
  font-size: 10px;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-family: var(--font-main);
  transition: all 0.15s;
}
.sort-btn:hover { color: var(--text); background: var(--hover-bg); }
.sort-btn.active { background: var(--active-bg); color: var(--text); border-color: var(--active-border); }

#sidebar-sections {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.sidebar-section {
  display: flex;
  flex-direction: column;
  min-height: 80px;
  overflow: hidden;
  border-bottom: 1px solid var(--border);
}

.sidebar-section:last-child { border-bottom: none; }

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px 4px;
  flex-shrink: 0;
}

.section-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
}

.section-add-btn {
  font-size: 10px;
  color: var(--text-muted);
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1px 6px;
  cursor: pointer;
  transition: color var(--transition);
}
.section-add-btn:hover { color: var(--text); }

.section-search {
  flex-shrink: 0;
  margin: 0 14px 4px;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 3px 8px;
  font-size: 11px;
}
.section-search::placeholder { color: var(--text-muted); }
.section-search:focus { border-color: rgba(255,255,255,0.25); outline: none; }

.section-list {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
  padding: 0 14px 6px;
}

.section-list::-webkit-scrollbar { width: 3px; }
.section-list::-webkit-scrollbar-track { background: transparent; }
.section-list::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 2px; }

#canvas-container {
  width: 100vw;
  height: 100vh;
  position: relative;
  overflow: hidden;
}

#canvas-svg {
  width: 100%;
  height: 100%;
  display: block;
}

#mode-bar-container {
  position: absolute;
  top: 0; left: 0; right: 0;
  z-index: 20;
  pointer-events: none;
}

.mode-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 16px;
  font-size: 12px;
  color: #fff;
  pointer-events: none;
  opacity: 0;
  transform: translateY(-100%);
  transition: opacity 0.15s ease, transform 0.15s ease;
  position: absolute;
  top: 0; left: 0; right: 0;
}
.mode-bar.active {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

/* Global: no text cursor on canvas or interactive elements */
#canvas-container, #canvas-container * { cursor: default; }
#canvas-container .wp-node, #canvas-container .vision-node,
#canvas-container .halo-btn, #canvas-container [style*='cursor: pointer'],
#canvas-container path[style*='cursor'], #canvas-container g[style*='cursor'] { cursor: pointer !important; }
svg text, svg tspan { cursor: default !important; user-select: none; }

.workspace-switcher-create-form {
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* CR hover emphasis: applied to solid and ghost nodes/paths whose data-cr-id
   matches the CR card the owner is hovering in the Changes panel. */
.cr-emphasis {
  filter: drop-shadow(0 0 6px #63b3ed) drop-shadow(0 0 2px #fff);
}
path.cr-emphasis { stroke-width: 8 !important; }
.wp-node-ghost.cr-emphasis, .vision-node-ghost.cr-emphasis {
  filter: drop-shadow(0 0 8px #d69e2e);
}

.workspace-switcher-create-input {
  width: 100%;
  box-sizing: border-box;
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 5px 8px;
  font-size: 12px;
  font-family: var(--font-main);
}

.workspace-switcher-create-input::placeholder {
  color: var(--text-muted);
}

.workspace-switcher-create-actions {
  display: flex;
  gap: 6px;
}

.workspace-delete-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
  border-radius: var(--radius-sm);
  transition: color 0.15s, background 0.15s;
  flex-shrink: 0;
  margin-left: 6px;
}
.workspace-delete-btn:hover { color: #fc8181; background: rgba(252,129,129,0.1); }
.workspace-delete-btn:focus-visible { outline: 2px solid rgba(255,255,255,0.5); outline-offset: 1px; }

/* Inline rename input inside the workspace switcher button */
.workspace-rename-input {
  background: transparent;
  border: none;
  border-bottom: 1px solid rgba(255,255,255,0.4);
  color: inherit;
  font: inherit;
  font-size: 13px;
  outline: none;
  width: 140px;
  padding: 0 2px;
}
.workspace-rename-input::placeholder { color: rgba(255,255,255,0.4); }

/* Role badge on workspace switcher button */
.workspace-role-badge {
  margin-left: 6px;
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #68d391;
  background: rgba(56,161,105,0.15);
  border: 1px solid rgba(56,161,105,0.3);
  border-radius: 3px;
  padding: 1px 5px;
  vertical-align: middle;
  line-height: 1.4;
}
