/* ── Presence circles (in header, left of account avatar) ── */

.presence-circles {
  display: flex;
  align-items: center;
  overflow: visible;
  padding: 2px;
  margin: -2px;
}

/* Overlapping circles — Google Docs style */
.presence-circles .presence-circle {
  margin-left: -6px;
}
.presence-circles .presence-circle:first-child {
  margin-left: 0;
}

.presence-circle {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 600;
  font-family: system-ui, sans-serif;
  background: var(--accent);
  color: white;
  position: relative;
  flex-shrink: 0;
  user-select: none;
  cursor: default;
  border: 2px solid var(--color-bg, #fff);
  transition: transform 0.15s, z-index 0s;
  z-index: 1;
}

.presence-circle:hover {
  transform: translateY(-2px);
  z-index: 10;
}

/* Hover: spread circles apart for clarity */
.presence-circles:hover .presence-circle {
  margin-left: 2px;
}
.presence-circles:hover .presence-circle:first-child {
  margin-left: 0;
}

/* Tooltip — pops DOWN below the circle */
.presence-tooltip {
  position: absolute;
  top: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink, #1e293b);
  color: #fff;
  font-size: 11px;
  font-weight: 500;
  line-height: 1.3;
  padding: 4px 8px;
  border-radius: 6px;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  z-index: 100;
}

/* Arrow points UP toward the circle */
.presence-tooltip::after {
  content: '';
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 4px solid transparent;
  border-bottom-color: var(--ink, #1e293b);
}

.presence-circle:hover .presence-tooltip {
  opacity: 1;
}

/* Edge-aware: pin tooltip near right edge (last circles are closest to account menu) */
.presence-circle:last-child .presence-tooltip,
.presence-circle:nth-last-child(2) .presence-tooltip {
  left: auto;
  right: 0;
  transform: none;
}
.presence-circle:last-child .presence-tooltip::after,
.presence-circle:nth-last-child(2) .presence-tooltip::after {
  left: auto;
  right: 10px;
  transform: none;
}

/* Single circle: centered */
.presence-circle:only-child .presence-tooltip {
  left: 50%;
  right: auto;
  transform: translateX(-50%);
}
.presence-circle:only-child .presence-tooltip::after {
  left: 50%;
  right: auto;
  transform: translateX(-50%);
}

.presence-tooltip-page {
  font-weight: 400;
  opacity: 0.7;
  font-size: 10px;
}

/* Anonymous */
.presence-circle.is-anon {
  background: var(--surface);
  color: var(--muted);
  border-color: var(--line);
}

/* Teacher ring */
.presence-circle.is-teacher {
  box-shadow: 0 0 0 2px #2563eb;
}

/* Admin ring */
.presence-circle.is-admin {
  box-shadow: 0 0 0 2px #d97706;
}

/* Current user pulse */
.presence-circle.is-you {
  animation: presence-pulse 2.5s ease-in-out infinite;
}
.presence-circle.is-you:not(.is-teacher):not(.is-admin) {
  box-shadow: 0 0 0 2px var(--accent);
}

@keyframes presence-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

@media (prefers-reduced-motion: reduce) {
  .presence-circle.is-you {
    animation: none;
    outline: 2px dashed var(--accent);
    outline-offset: 1px;
  }
  .presence-circle.is-you.is-teacher {
    outline-color: #2563eb;
  }
  .presence-circle.is-you.is-admin {
    outline-color: #d97706;
  }
}

/* Badge (positioned bottom-right of circle) */
.presence-badge {
  position: absolute;
  bottom: -3px;
  right: -3px;
  width: 12px;
  height: 12px;
  background: var(--panel);
  border-radius: 50%;
  padding: 1px;
}

/* Overflow "+N" */
.presence-circle.is-overflow {
  background: var(--surface);
  color: var(--muted);
  font-size: 10px;
  font-weight: 500;
  flex-shrink: 0;
}

/* Small dismiss × button next to presence circles in header */
.presence-dismiss-sm {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 2px 4px;
  border-radius: 4px;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s;
}
.presence-group:hover .presence-dismiss-sm {
  opacity: 0.5;
}
.presence-dismiss-sm:hover {
  opacity: 1 !important;
  color: var(--ink);
}

/* ── Shared restore button + group wrapper ── */

.presence-restore-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--panel);
  color: var(--muted);
  cursor: pointer;
  flex-shrink: 0;
}

.presence-restore-btn:hover {
  color: var(--ink);
  border-color: var(--accent);
}

.presence-group {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

/* Print: hide everything */
@media print {
  .presence-group,
  .presence-restore-btn {
    display: none !important;
  }
}
