/* =========================================================
   Collab layer — sticky-note overlay on the deck.
   Activated by `?collab=1`, which adds `body.collab-active`.
   Off otherwise: every rule below is namespaced under that
   class, so loading the file on the production deck is inert.

   Palette: yellow = comment, teal = edit. Both sit OUTSIDE the
   deck's amber/coral/grid palette so a reviewer never confuses
   a collab affordance with a slide accent.
   ========================================================= */

body.collab-active {
  --collab-paper:       oklch(0.96 0.02 85);
  --collab-paper-dim:   oklch(0.96 0.02 85 / 0.18);
  --collab-paper-line:  oklch(0.78 0.06 85);
  --collab-yellow:      oklch(0.88 0.14 90);
  --collab-yellow-dim:  oklch(0.88 0.14 90 / 0.16);
  --collab-yellow-line: oklch(0.74 0.13 90);
  --collab-teal:        oklch(0.78 0.13 210);
  --collab-teal-dim:    oklch(0.78 0.13 210 / 0.18);
  --collab-teal-line:   oklch(0.65 0.13 210);
  --collab-ink:         oklch(0.22 0.02 80);
  --collab-ink-dim:     oklch(0.45 0.02 80);
}

/* In Comment/Edit modes, force all reveal.js fragments visible so
   the reviewer can comment on anything. Restored to normal in View. */
body.collab-active[data-collab-mode="comment"] .reveal .fragment,
body.collab-active[data-collab-mode="edit"]    .reveal .fragment {
  opacity: 1 !important;
  visibility: inherit !important;
  transform: none !important;
}

/* =========================================================
   1 · Mode pill — top-right, viewport-fixed
   ========================================================= */
.collab-bar {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 10000;
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-sans, "Inter", -apple-system, sans-serif);
  font-size: 13px;
  user-select: none;
}

.collab-bar .collab-export {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  padding: 0 14px;
  background: oklch(0.22 0.01 80);
  color: oklch(0.94 0.01 80);
  border: 1px solid oklch(0.40 0.01 80);
  border-radius: 4px;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  letter-spacing: 0.01em;
  transition: background 120ms ease, border-color 120ms ease;
}
.collab-bar .collab-export:hover {
  background: oklch(0.30 0.01 80);
  border-color: oklch(0.55 0.01 80);
}
.collab-bar .collab-export[disabled] {
  opacity: 0.45;
  cursor: not-allowed;
}

.collab-bar .collab-save-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: oklch(0.74 0.16 145);
  box-shadow: 0 0 6px oklch(0.74 0.16 145 / 0.55);
  cursor: help;
  transition: background 200ms ease;
}
.collab-bar .collab-save-dot[data-state="saving"] {
  background: var(--collab-yellow);
  box-shadow: 0 0 6px var(--collab-yellow);
}
.collab-bar .collab-save-dot[data-state="error"] {
  background: oklch(0.65 0.20 25);
  box-shadow: 0 0 6px oklch(0.65 0.20 25);
}

.collab-pill {
  display: inline-flex;
  background: var(--collab-paper);
  border: 1px solid var(--collab-paper-line);
  border-radius: 4px;
  overflow: hidden;
  box-shadow: 0 2px 10px oklch(0.05 0 0 / 0.45),
              0 1px 0 oklch(0.05 0 0 / 0.6);
}
.collab-pill button {
  appearance: none;
  background: transparent;
  border: none;
  border-right: 1px solid var(--collab-paper-line);
  padding: 0 14px;
  height: 36px;
  font: inherit;
  font-weight: 500;
  color: var(--collab-ink-dim);
  cursor: pointer;
  letter-spacing: 0.01em;
  transition: background 120ms ease, color 120ms ease;
}
.collab-pill button:last-child { border-right: none; }
.collab-pill button:hover { color: var(--collab-ink); background: oklch(0.94 0.02 85); }

.collab-pill button[data-mode="view"][aria-pressed="true"] {
  background: oklch(0.92 0.01 85);
  color: var(--collab-ink);
}
.collab-pill button[data-mode="comment"][aria-pressed="true"] {
  background: var(--collab-yellow);
  color: var(--collab-ink);
}
.collab-pill button[data-mode="edit"][aria-pressed="true"] {
  background: var(--collab-teal);
  color: oklch(0.18 0.04 210);
}

/* =========================================================
   2 · Page-edge tint — peripheral cue for active mode
   ========================================================= */
.collab-edge {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9999;
  box-shadow: inset 0 0 0 0 transparent;
  transition: box-shadow 200ms ease;
}
body.collab-active[data-collab-mode="comment"] .collab-edge {
  box-shadow: inset 0 0 0 4px var(--collab-yellow),
              inset 0 0 36px oklch(0.88 0.14 90 / 0.18);
}
body.collab-active[data-collab-mode="edit"] .collab-edge {
  box-shadow: inset 0 0 0 4px var(--collab-teal),
              inset 0 0 36px oklch(0.78 0.13 210 / 0.20);
}

/* =========================================================
   3 · Hover & active affordances per mode
   ========================================================= */

/* Comment mode: any clickable target gets a dashed yellow ring on hover.
   Slide-background also picks up a yellow cell cursor. */
body.collab-active[data-collab-mode="comment"] .reveal .slides section {
  cursor: cell;
}
body.collab-active[data-collab-mode="comment"] .collab-commentable:hover {
  outline: 1.5px dashed var(--collab-yellow);
  outline-offset: 4px;
  cursor: pointer;
}

/* Edit mode: editable elements get a dotted teal underline on hover; when
   actively contentEditable, a solid teal box + ring. Locked elements show
   a "no-go" indicator only when the reviewer tries them. */
body.collab-active[data-collab-mode="edit"] .collab-editable {
  cursor: text;
}
body.collab-active[data-collab-mode="edit"] .collab-editable:hover {
  text-decoration: underline 1.5px dashed var(--collab-teal);
  text-underline-offset: 6px;
  text-decoration-skip-ink: none;
}
body.collab-active[data-collab-mode="edit"] .collab-editable[contenteditable="true"] {
  outline: 2px solid var(--collab-teal);
  outline-offset: 4px;
  background: oklch(0.78 0.13 210 / 0.06);
  text-decoration: none;
  box-shadow: 0 0 0 4px oklch(0.78 0.13 210 / 0.12);
}

/* Locked elements: in Edit mode, telegraph "no-go" on hover. */
body.collab-active[data-collab-mode="edit"] .collab-locked:hover {
  outline: 1.5px dashed oklch(0.60 0.02 80);
  outline-offset: 4px;
  cursor: not-allowed;
}

/* =========================================================
   4 · Review indicators — visible in ALL modes so a refresh
   doesn't make the reviewer think their work vanished.
   View mode dims them so the deck still presents cleanly.
   ========================================================= */
.collab-edited {
  border-left: 3px solid var(--collab-teal);
  padding-left: 12px;
  margin-left: -15px;
}
body.collab-active[data-collab-mode="view"] .collab-edited {
  border-left-color: oklch(0.45 0.06 210);
}

.collab-pin {
  position: absolute;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--collab-yellow);
  border: 2px solid var(--collab-yellow-line);
  box-shadow: 0 2px 6px oklch(0.05 0 0 / 0.6);
  z-index: 50;
  pointer-events: none;
}
body.collab-active[data-collab-mode="view"] .collab-pin {
  opacity: 0.55;
  box-shadow: 0 1px 3px oklch(0.05 0 0 / 0.4);
}

.collab-slide-pin {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--collab-yellow);
  border: 2px solid var(--collab-yellow-line);
  box-shadow: 0 2px 8px oklch(0.05 0 0 / 0.55);
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: var(--collab-ink);
  font-weight: 700;
}
body.collab-active[data-collab-mode="view"] .collab-slide-pin {
  opacity: 0.55;
  box-shadow: 0 1px 3px oklch(0.05 0 0 / 0.4);
}

/* Per-edit revert button — appears on hover of an edited element in Edit
   mode. Lets the reviewer back out one edit at a time without nuking all
   their work. */
.collab-revert {
  position: absolute;
  top: -12px;
  right: -12px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--collab-teal);
  border: 1.5px solid var(--collab-teal-line);
  color: oklch(0.18 0.04 210);
  font-size: 14px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  z-index: 55;
  display: none;
  padding: 0;
  align-items: center;
  justify-content: center;
  user-select: none;
  box-shadow: 0 2px 6px oklch(0.05 0 0 / 0.55);
}
body.collab-active[data-collab-mode="edit"] .collab-edited:hover .collab-revert {
  display: flex;
}
.collab-revert:hover { background: oklch(0.70 0.13 210); }
.collab-revert::after {
  content: "Revert this edit";
  position: absolute;
  right: 30px;
  top: 50%;
  transform: translateY(-50%);
  background: var(--collab-paper);
  border: 1px solid var(--collab-paper-line);
  color: var(--collab-ink);
  font-family: var(--font-sans, "Inter", sans-serif);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0;
  padding: 4px 8px;
  border-radius: 3px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 120ms ease;
}
.collab-revert:hover::after { opacity: 1; }

/* =========================================================
   5 · Comment popover — yellow sticky card, anchored to element
   ========================================================= */
.collab-popover {
  position: fixed;
  z-index: 10100;
  width: 320px;
  max-width: calc(100vw - 32px);
  background: var(--collab-paper);
  border: 1px solid var(--collab-paper-line);
  border-radius: 4px;
  box-shadow: 0 16px 48px oklch(0.05 0 0 / 0.55),
              0 2px 6px oklch(0.05 0 0 / 0.4);
  padding: 14px 14px 12px;
  color: var(--collab-ink);
  font-family: var(--font-sans, "Inter", sans-serif);
  font-size: 13px;
  line-height: 1.4;
}
.collab-popover .collab-popover-head {
  font-size: 10.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-weight: 700;
  color: var(--collab-ink-dim);
  margin-bottom: 6px;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}
.collab-popover .collab-popover-target {
  font-size: 11.5px;
  color: var(--collab-ink-dim);
  font-style: italic;
  margin-bottom: 8px;
  max-height: 36px;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.collab-popover textarea {
  width: 100%;
  min-height: 84px;
  resize: vertical;
  background: oklch(0.99 0.01 85);
  border: 1px solid oklch(0.82 0.04 85);
  border-radius: 3px;
  padding: 8px 10px;
  font: inherit;
  color: var(--collab-ink);
  outline: none;
  transition: border-color 120ms ease;
}
.collab-popover textarea:focus {
  border-color: var(--collab-yellow-line);
  box-shadow: 0 0 0 3px oklch(0.88 0.14 90 / 0.3);
}
.collab-popover-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  justify-content: flex-end;
}
.collab-popover-actions button {
  appearance: none;
  border: 1px solid var(--collab-paper-line);
  background: oklch(0.94 0.02 85);
  color: var(--collab-ink);
  border-radius: 3px;
  padding: 6px 12px;
  font: inherit;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background 120ms ease;
}
.collab-popover-actions button:hover { background: oklch(0.90 0.03 85); }
.collab-popover-actions button.collab-primary {
  background: var(--collab-yellow);
  border-color: var(--collab-yellow-line);
}
.collab-popover-actions button.collab-primary:hover {
  background: oklch(0.84 0.16 90);
}
.collab-popover-actions button.collab-danger {
  color: oklch(0.45 0.18 28);
  margin-right: auto;
}

/* =========================================================
   6 · Onboarding toast — sticky-note in lower-right
   ========================================================= */
.collab-onboard {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 10050;
  width: 340px;
  max-width: calc(100vw - 40px);
  background: var(--collab-paper);
  border: 1px solid var(--collab-paper-line);
  border-radius: 4px;
  padding: 16px 16px 14px;
  box-shadow: 0 12px 36px oklch(0.05 0 0 / 0.55);
  color: var(--collab-ink);
  font-family: var(--font-sans, "Inter", sans-serif);
  font-size: 13px;
  line-height: 1.5;
}
.collab-onboard h2 {
  margin: 0 0 8px;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0;
  color: var(--collab-ink);
  font-family: inherit;
}
.collab-onboard p { margin: 0 0 8px; }
.collab-onboard p.collab-onboard-quiet {
  color: var(--collab-ink-dim);
  font-size: 12px;
}
.collab-onboard-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 10px;
}
.collab-onboard-actions button {
  appearance: none;
  background: var(--collab-yellow);
  border: 1px solid var(--collab-yellow-line);
  color: var(--collab-ink);
  border-radius: 3px;
  padding: 7px 14px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.collab-onboard-actions button:hover { background: oklch(0.84 0.16 90); }

/* =========================================================
   7 · Export preview sheet — slides down from top
   ========================================================= */
.collab-sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 10200;
  background: oklch(0.05 0 0 / 0.55);
  animation: collab-fade 180ms ease;
}
.collab-sheet {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10201;
  width: min(720px, calc(100vw - 32px));
  max-height: calc(100vh - 40px);
  display: flex;
  flex-direction: column;
  background: var(--collab-paper);
  border: 1px solid var(--collab-paper-line);
  border-radius: 6px;
  box-shadow: 0 30px 80px oklch(0.05 0 0 / 0.7);
  color: var(--collab-ink);
  font-family: var(--font-sans, "Inter", sans-serif);
  animation: collab-slide-down 240ms cubic-bezier(.2,.8,.2,1);
}
@keyframes collab-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes collab-slide-down {
  from { transform: translate(-50%, -24px); opacity: 0; }
  to   { transform: translate(-50%, 0);     opacity: 1; }
}
.collab-sheet-head {
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--collab-paper-line);
}
.collab-sheet-head h2 {
  margin: 0 0 4px;
  font-size: 17px;
  font-weight: 700;
  color: var(--collab-ink);
  font-family: inherit;
}
.collab-sheet-head .collab-sheet-sub {
  font-size: 12.5px;
  color: var(--collab-ink-dim);
}
.collab-sheet-body {
  padding: 14px 20px 18px;
  overflow-y: auto;
  font-size: 13px;
}
.collab-sheet-body .collab-sheet-empty {
  color: var(--collab-ink-dim);
  font-style: italic;
  padding: 16px 0;
}
.collab-sheet-body h3 {
  font-size: 12px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--collab-ink-dim);
  margin: 14px 0 6px;
  font-weight: 700;
  font-family: inherit;
}
.collab-sheet-body ul {
  margin: 0;
  padding-left: 18px;
}
.collab-sheet-body li { margin: 4px 0; line-height: 1.45; }
.collab-sheet-body .collab-banner {
  background: oklch(0.92 0.07 85);
  border: 1px solid oklch(0.74 0.10 85);
  border-radius: 4px;
  padding: 10px 12px;
  font-size: 12.5px;
  color: var(--collab-ink);
  margin-bottom: 12px;
}
.collab-sheet-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  padding: 14px 20px 18px;
  border-top: 1px solid var(--collab-paper-line);
}
.collab-sheet-actions button {
  appearance: none;
  border: 1px solid var(--collab-paper-line);
  background: oklch(0.94 0.02 85);
  color: var(--collab-ink);
  border-radius: 4px;
  padding: 8px 14px;
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 120ms ease;
}
.collab-sheet-actions button:hover { background: oklch(0.90 0.03 85); }
.collab-sheet-actions button.collab-primary {
  background: var(--collab-yellow);
  border-color: var(--collab-yellow-line);
}
.collab-sheet-actions button.collab-primary:hover { background: oklch(0.84 0.16 90); }

/* Persistent hint in Comment mode — sits left of the mode pill, reminds the
   reviewer that the slide background itself is clickable for slide-level
   notes. Hidden in View/Edit. */
.collab-hint {
  position: fixed;
  top: 20px;
  left: 16px;
  z-index: 9998;
  background: var(--collab-paper);
  border: 1px solid var(--collab-paper-line);
  border-radius: 4px;
  padding: 8px 12px;
  font-family: var(--font-sans, "Inter", sans-serif);
  font-size: 12px;
  color: var(--collab-ink-dim);
  box-shadow: 0 2px 8px oklch(0.05 0 0 / 0.45);
  display: none;
  max-width: 320px;
  line-height: 1.4;
}
.collab-hint strong { color: var(--collab-ink); font-weight: 600; }
body.collab-active[data-collab-mode="comment"] .collab-hint { display: block; }

/* "Clear all" link inside the export sheet header — small, secondary. */
.collab-sheet-clear {
  appearance: none;
  background: transparent;
  border: none;
  color: oklch(0.50 0.16 28);
  font: inherit;
  font-size: 12px;
  text-decoration: underline;
  cursor: pointer;
  padding: 0;
  margin-top: 4px;
}
.collab-sheet-clear:hover { color: oklch(0.40 0.18 28); }

/* Name field in the export sheet. */
.collab-name-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 10px 0 14px;
}
.collab-name-row label {
  font-size: 12px;
  color: var(--collab-ink-dim);
  flex: 0 0 auto;
}
.collab-name-row input {
  flex: 1;
  height: 28px;
  padding: 0 8px;
  background: oklch(0.99 0.01 85);
  border: 1px solid oklch(0.82 0.04 85);
  border-radius: 3px;
  font: inherit;
  font-size: 13px;
  color: var(--collab-ink);
  outline: none;
}
.collab-name-row input:focus {
  border-color: var(--collab-yellow-line);
  box-shadow: 0 0 0 3px oklch(0.88 0.14 90 / 0.3);
}

/* File breakdown in the export sheet. */
.collab-files {
  margin-top: 14px;
  font-size: 12px;
}
.collab-files > div {
  background: oklch(0.94 0.02 85);
  border: 1px solid oklch(0.82 0.04 85);
  border-radius: 3px;
  padding: 8px 10px;
}
.collab-files .collab-file-name {
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 11px;
  color: var(--collab-ink);
  margin-bottom: 2px;
}
.collab-files .collab-file-desc { color: var(--collab-ink-dim); }

/* Locked elements: a subtle tag visible only on hover in edit mode. */
body.collab-active[data-collab-mode="edit"] .collab-locked::after {
  content: "locked";
  position: absolute;
  top: -10px;
  right: -10px;
  background: oklch(0.45 0.02 80);
  color: oklch(0.96 0.01 80);
  font-size: 9px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 2px 6px;
  border-radius: 2px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 120ms ease;
}
body.collab-active[data-collab-mode="edit"] .collab-locked:hover::after { opacity: 1; }
.collab-locked { position: relative; }
