#collab-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 48px;
  background: linear-gradient(to bottom, #0f1419 0%, #0a0e14 100%);
  border-bottom: 1px solid #1e2530;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 99999;
  font-family: Inter, system-ui, -apple-system, sans-serif;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

#collab-bar * { box-sizing: border-box; }

.collab-users {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  overflow-x: auto;
  padding: 4px 0;
}

.collab-user {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 20px;
  font-size: 13px;
  color: #e2e8f0;
  white-space: nowrap;
  border: 1px solid transparent;
}

.collab-user.me {
  background: rgba(59, 130, 246, 0.15);
  border-color: rgba(59, 130, 246, 0.3);
}

.collab-user-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.collab-user-name {
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.collab-user-editing {
  font-size: 11px;
  color: #22c55e;
  margin-left: 4px;
  padding: 2px 6px;
  background: rgba(34, 197, 94, 0.15);
  border-radius: 8px;
}

.collab-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.collab-btn {
  padding: 8px 16px;
  background: #1e2530;
  border: 1px solid #2d3748;
  border-radius: 8px;
  color: #e2e8f0;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s;
}

.collab-btn:hover {
  background: #2d3748;
  border-color: #3b82f6;
}

.collab-btn-icon { font-size: 16px; }

.collab-modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  z-index: 999999;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.collab-modal-overlay.active { display: flex; }
#collab-name-modal.collab-modal-overlay { z-index: 99999999; }

.collab-modal {
  background: #0f1419;
  border: 1px solid #1e2530;
  border-radius: 16px;
  width: 100%;
  max-width: 420px;
  font-family: Inter, system-ui, sans-serif;
  animation: collabModalIn 0.2s ease;
}

@keyframes collabModalIn {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

.collab-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid #1e2530;
}

.collab-modal-header h3 {
  font-size: 18px;
  font-weight: 600;
  color: #e2e8f0;
  margin: 0;
}

.collab-modal-close {
  background: none;
  border: none;
  color: #8892a0;
  font-size: 24px;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
}

.collab-modal-close:hover { color: #e2e8f0; }

.collab-modal-body { padding: 20px; }

.collab-share-url {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
}

.collab-share-url input {
  flex: 1;
  padding: 12px;
  background: #0a0e14;
  border: 1px solid #1e2530;
  border-radius: 8px;
  color: #e2e8f0;
  font-size: 13px;
  font-family: monospace;
}

.collab-share-url button {
  padding: 12px 16px;
  background: #3b82f6;
  border: none;
  border-radius: 8px;
  color: white;
  font-size: 18px;
  cursor: pointer;
}

.collab-share-url button:hover { background: #2563eb; }

.collab-qr {
  display: flex;
  justify-content: center;
  padding: 20px;
  background: white;
  border-radius: 12px;
  margin-bottom: 16px;
}

.collab-qr svg { max-width: 180px; max-height: 180px; }

.collab-share-note {
  font-size: 13px;
  color: #8892a0;
  text-align: center;
  margin: 0;
}

#collab-menu-dropdown {
  display: none;
  position: fixed;
  background: #0f1419;
  border: 1px solid #1e2530;
  border-radius: 12px;
  min-width: 180px;
  z-index: 999999;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  overflow: hidden;
}

#collab-menu-dropdown.active { display: block; }

.collab-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  color: #e2e8f0;
  font-size: 14px;
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  font-family: inherit;
}

.collab-menu-item:hover { background: #1e2530; }
.collab-menu-item.danger { color: #ef4444; }
.collab-menu-item.danger:hover { background: rgba(239, 68, 68, 0.1); }
.collab-menu-divider { height: 1px; background: #1e2530; margin: 4px 0; }

.collab-info-row {
  display: flex;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid #1e2530;
}

.collab-info-row:last-child { border-bottom: none; }
.collab-info-label { color: #8892a0; font-size: 14px; }
.collab-info-value { color: #e2e8f0; font-size: 14px; font-weight: 500; }
.collab-info-id { font-family: monospace; font-size: 11px; word-break: break-all; }

.collab-input {
  width: 100%;
  padding: 14px 16px;
  background: #0a0e14;
  border: 1px solid #1e2530;
  border-radius: 8px;
  color: #e2e8f0;
  font-size: 16px;
  outline: none;
  font-family: inherit;
}

.collab-input:focus { border-color: #3b82f6; }
.collab-input::placeholder { color: #4a5568; }

.collab-name-actions {
  display: flex;
  gap: 12px;
  margin-top: 16px;
}

.collab-btn-secondary {
  flex: 1;
  padding: 12px;
  background: #1e2530;
  border: 1px solid #2d3748;
  border-radius: 8px;
  color: #e2e8f0;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
}

.collab-btn-secondary:hover { background: #2d3748; }

.collab-btn-primary {
  flex: 1;
  padding: 12px;
  background: #3b82f6;
  border: none;
  border-radius: 8px;
  color: white;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}

.collab-btn-primary:hover { background: #2563eb; }

.collab-pwd-error,
.collab-name-error {
  color: #ef4444;
  font-size: 13px;
  margin-top: 8px;
  display: none;
}

.collab-pwd-error.active,
.collab-name-error.active { display: block; }

.collab-node-indicator {
  position: absolute;
  bottom: -20px;
  left: 50%;
  transform: translateX(-50%);
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 500;
  white-space: nowrap;
  pointer-events: none;
  z-index: 1000;
  font-family: Inter, system-ui, sans-serif;
}

.collab-selection-ring {
  position: absolute;
  inset: -4px;
  border: 3px solid;
  border-radius: inherit;
  pointer-events: none;
  animation: collab-pulse 2s infinite;
}

@keyframes collab-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

body.collab-active { padding-top: 48px !important; }

@media (max-width: 640px) {
  #collab-bar { padding: 0 12px; }
  .collab-user { padding: 4px 8px; font-size: 12px; }
  .collab-user-name { max-width: 80px; }
  .collab-user-editing { display: none; }
  .collab-btn { padding: 6px 10px; font-size: 12px; }
  .collab-btn span:not(.collab-btn-icon) { display: none; }
}

#collab-sync-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 14, 20, 0.95);
  z-index: 9999999;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: Inter, system-ui, -apple-system, sans-serif;
  animation: syncFadeIn 0.3s ease;
}

#collab-sync-overlay.fade-out {
  animation: syncFadeOut 0.3s ease forwards;
}

@keyframes syncFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes syncFadeOut {
  from { opacity: 1; }
  to { opacity: 0; }
}

.collab-sync-content {
  text-align: center;
  position: relative;
}

.collab-sync-sword {
  width: 80px;
  height: 200px;
  margin: 0 auto 30px;
  position: relative;
  animation: swordFloat 2s ease-in-out infinite;
}

.collab-sync-sword::before {
  content: '';
  position: absolute;
  left: 50%;
  top: 0;
  transform: translateX(-50%);
  width: 8px;
  height: 140px;
  background: linear-gradient(to bottom, #e2e8f0 0%, #94a3b8 50%, #64748b 100%);
  border-radius: 2px 2px 0 0;
  box-shadow: 0 0 20px rgba(226, 232, 240, 0.5);
}

.collab-sync-sword::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 130px;
  transform: translateX(-50%);
  width: 50px;
  height: 12px;
  background: linear-gradient(to bottom, #92400e, #78350f);
  border-radius: 3px;
  box-shadow: 0 4px 0 #451a03;
}

@keyframes swordFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-15px); }
}

.collab-sync-lightning {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 200px;
  height: 200px;
  pointer-events: none;
}

.collab-sync-lightning::before,
.collab-sync-lightning::after {
  content: '';
  position: absolute;
  background: linear-gradient(180deg, transparent 0%, #3b82f6 50%, transparent 100%);
  animation: lightning 1.5s ease-in-out infinite;
}

.collab-sync-lightning::before {
  left: 20%;
  top: 0;
  width: 3px;
  height: 100%;
  animation-delay: 0s;
}

.collab-sync-lightning::after {
  right: 20%;
  top: 0;
  width: 3px;
  height: 100%;
  animation-delay: 0.3s;
}

@keyframes lightning {
  0%, 100% { opacity: 0; transform: scaleY(0); }
  10%, 30% { opacity: 1; transform: scaleY(1); }
  40% { opacity: 0; transform: scaleY(0); }
}

.collab-sync-text {
  font-size: 24px;
  font-weight: 700;
  color: #e2e8f0;
  margin-bottom: 12px;
  text-shadow: 0 0 30px rgba(59, 130, 246, 0.5);
  animation: textPulse 2s ease-in-out infinite;
}

@keyframes textPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

.collab-sync-subtext {
  font-size: 14px;
  color: #8892a0;
  animation: dotDotDot 1.5s steps(4, end) infinite;
}

.collab-sync-subtext::after {
  content: '';
  animation: dots 1.5s steps(4, end) infinite;
}

@keyframes dots {
  0% { content: ''; }
  25% { content: '.'; }
  50% { content: '..'; }
  75% { content: '...'; }
  100% { content: ''; }
}

#collab-chat-panel {
  display: none;
  position: fixed;
  top: 56px;
  right: 16px;
  width: 320px;
  max-width: calc(100vw - 32px);
  height: 400px;
  max-height: calc(100vh - 100px);
  background: #0f1419;
  border: 1px solid #1e2530;
  border-radius: 12px;
  z-index: 999998;
  flex-direction: column;
  font-family: Inter, system-ui, -apple-system, sans-serif;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  animation: collabModalIn 0.2s ease;
}

#collab-chat-panel.active { display: flex; }

.collab-chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid #1e2530;
  color: #e2e8f0;
  font-weight: 600;
  font-size: 14px;
  flex-shrink: 0;
}

.collab-chat-close {
  background: none;
  border: none;
  color: #8892a0;
  font-size: 20px;
  cursor: pointer;
  padding: 0;
  line-height: 1;
}

.collab-chat-close:hover { color: #e2e8f0; }

.collab-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.collab-chat-msg {
  padding: 8px 10px;
  background: rgba(255, 255, 255, 0.03);
  border-radius: 8px;
}

.collab-chat-name {
  font-weight: 600;
  font-size: 12px;
  margin-right: 8px;
}

.collab-chat-time {
  font-size: 10px;
  color: #64748b;
}

.collab-chat-text {
  font-size: 13px;
  color: #e2e8f0;
  margin-top: 4px;
  line-height: 1.4;
  word-break: break-word;
}

.collab-chat-input-wrap {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid #1e2530;
  flex-shrink: 0;
}

.collab-chat-input-wrap input {
  flex: 1;
  padding: 10px 12px;
  background: #0a0e14;
  border: 1px solid #1e2530;
  border-radius: 8px;
  color: #e2e8f0;
  font-size: 13px;
  outline: none;
  font-family: inherit;
}

.collab-chat-input-wrap input:focus { border-color: #3b82f6; }
.collab-chat-input-wrap input::placeholder { color: #4a5568; }

.collab-chat-input-wrap button {
  padding: 10px 16px;
  background: #3b82f6;
  border: none;
  border-radius: 8px;
  color: white;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
}

.collab-chat-input-wrap button:hover { background: #2563eb; }

.collab-chat-badge {
  display: none;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  background: #ef4444;
  color: white;
  font-size: 11px;
  font-weight: 700;
  border-radius: 10px;
  margin-left: 4px;
}

#collab-chat-btn { position: relative; }

.collab-user-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.collab-user-tab {
  font-size: 10px;
  color: #64748b;
}

.collab-remote-cursor {
  position: fixed;
  pointer-events: none;
  z-index: 999997;
  transform: translate(-2px, -2px);
}

.collab-remote-cursor svg {
  display: block;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.5));
}

.collab-cursor-name {
  position: absolute;
  left: 14px;
  top: 12px;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 500;
  color: white;
  white-space: nowrap;
  font-family: Inter, system-ui, -apple-system, sans-serif;
}

@media (max-width: 640px) {
  #collab-chat-panel {
    right: 8px;
    left: 8px;
    width: auto;
    max-width: none;
    height: 50vh;
  }
}
