/* Pinned review comments (UX Pack F5b, restyled F5c) — pins, docked panel,
   composer, link modal. The panel look is ported from the CRM design-reviewer
   (.dr-rev-panel / .dr-feedback-card geometry) recolored with --pb-* tokens.
   SELF-SUFFICIENT BY DESIGN: /review.html loads tokens.css, builder.css,
   toast.css, this file and review.css — NOT property-panel.css, where the
   drawer-shell classes (.pb-spi-drawer*) are styled. They are therefore
   restyled here from scratch, and no rule below may depend on a sheet the
   review page does not load. */

/* Comment mode: every click pins feedback instead of editing or navigating,
   so nothing on the canvas may advertise drag/pointer/not-allowed. This is
   the PARENT half only — it covers the iframe element and the glass overlay
   (a sibling of the iframe inside .pb-iframe-wrap). A cursor set on the
   <iframe> element never reaches the document INSIDE it, so the other half
   lives in css-assembler.js's EDITING_CSS, keyed on a body class the bridge
   sets. Same two-sided treatment as AI pick mode (builder.css).

   NO `!important`, unlike pick mode's copy of this rule: that one lives in
   builder.css, which loads BEFORE glass-overlay.css, so it had to shout to win.
   comments.css loads last (index.html), so equal specificity already wins on
   source order — verified in a browser against the overlay's own cursors. */
.pb-comment-mode,
.pb-comment-mode .pb-preview-frame,
.pb-comment-mode iframe,
.pb-comment-mode .pb-glass-overlay,
.pb-comment-mode .pb-glass-overlay * {
  cursor: crosshair;
}

/* ── Canvas pins — numbered circles (open = danger, resolved = success) ── */

.pb-comment-pin-layer {
  position: absolute;
  inset: 0 auto auto 0;
  width: 100%;
  height: 0;
  overflow: visible;
  pointer-events: none;
}

.pb-comment-pin {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: auto;
  width: var(--pb-comment-pin-size);
  height: var(--pb-comment-pin-size);
  padding: 0;
  border-radius: 50%;
  border: 0;
  background: var(--pb-danger-fill);
  color: var(--pb-on-danger);
  font-size: var(--pb-font-sm);
  font-weight: 700;
  line-height: var(--pb-comment-pin-size);
  text-align: center;
  cursor: pointer;
  /* Ring + drop shadow, the CRM marker treatment (outline circle + disc). */
  box-shadow:
    0 0 0 2px var(--pb-surface),
    0 2px 6px rgba(0, 0, 0, 0.35);
}

/* Resolved: translucency lives on the FILL, never the element — the white
   number must stay fully readable. */
.pb-comment-pin.is-resolved {
  background: color-mix(in srgb, var(--pb-success) 55%, transparent);
}

.pb-comment-pin.is-active::after {
  content: '';
  position: absolute;
  inset: calc(-1 * var(--pb-space-2));
  border: 2px solid currentColor;
  border-radius: 50%;
  animation: pb-comment-ping 1.2s ease-out infinite;
  pointer-events: none;
}

@keyframes pb-comment-ping {
  0% {
    transform: scale(0.7);
    opacity: 0.9;
  }
  100% {
    transform: scale(1.25);
    opacity: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .pb-comment-pin.is-active::after {
    animation: none;
    transform: none;
    opacity: 0.7;
  }
}

/* Collapsed: re-point the rail's offset and it slides outward with no JS.
   Deliberately NOT `--pb-panel-width-comments: 0` — the panel is still 320px
   wide, merely hidden, and forking the width register would lie to every other
   reader of it (and fork a :root token for one subtree, which the design-token
   ledger counts). Re-pointing a dedicated offset is the honest form. */
.pb-comments-collapsed {
  --pb-comments-rail-right: var(--pb-space-6h);
}

.pb-comments-pill {
  position: fixed;
  top: 50%;
  /* Clear of the rail, which is also on the right edge when collapsed. */
  right: calc(var(--pb-comments-rail-right) + var(--pb-space-6));
  transform: translateY(-50%);
  z-index: var(--pb-z-docked-panel);
  display: inline-flex;
  align-items: center;
  gap: var(--pb-space-3);
  border: 1px solid var(--pb-border);
  border-radius: var(--pb-radius-pill);
  background: var(--pb-surface);
  box-shadow: var(--pb-shadow-panel);
}

.pb-comments-pill[hidden] {
  display: none;
}

.pb-comments-collapse-btn {
  min-width: 20px;
  padding: 0 var(--pb-space-2);
  line-height: 1;
}

/* ── Density rail — where the feedback is down this page ──
   Positioned against the panel width token, so collapsing the panel (which
   zeroes it on the scope) slides the rail outward with no JS. Same trick the
   CRM uses with --dr-panel-w. */

.pb-comment-rail {
  position: fixed;
  top: calc(var(--pb-toolbar-height-actual, var(--pb-toolbar-height)) + var(--pb-space-6));
  bottom: var(--pb-space-8);
  right: var(--pb-comments-rail-right);
  width: var(--pb-space-6);
  z-index: var(--pb-z-docked-panel);
  display: flex;
  justify-content: center;
  pointer-events: none;
}

.pb-comment-rail[hidden] {
  display: none;
}

/* The track itself — a hairline the dots hang on. */
.pb-comment-rail::before {
  content: '';
  position: absolute;
  inset: 0 auto 0 50%;
  width: 2px;
  transform: translateX(-50%);
  border-radius: var(--pb-radius-pill);
  background: var(--pb-border-soft);
}

.pb-comment-rail-dots {
  position: absolute;
  inset: 0;
}

.pb-comment-rail-band {
  position: absolute;
  left: 50%;
  width: 8px;
  transform: translateX(-50%);
  border-radius: var(--pb-radius-pill);
  background: var(--pb-accent-muted);
  border: 1px solid var(--pb-accent);
  opacity: 0.5;
}

.pb-comment-rail-dot {
  position: absolute;
  left: 50%;
  transform: translate(-50%, -50%);
  pointer-events: auto;
  min-width: 12px;
  height: 12px;
  padding: 0 3px;
  border: 0;
  border-radius: var(--pb-radius-pill);
  background: var(--pb-danger-fill);
  color: var(--pb-on-danger);
  font-size: 9px;
  font-weight: 700;
  line-height: 12px;
  text-align: center;
  cursor: pointer;
  box-shadow: 0 0 0 2px var(--pb-bg);
}

.pb-comment-rail-dot.is-resolved {
  background: color-mix(in srgb, var(--pb-success) 60%, transparent);
}

.pb-comment-rail-dot.is-cluster {
  height: 14px;
  line-height: 14px;
}

.pb-comment-rail-dot.is-active {
  box-shadow:
    0 0 0 2px var(--pb-bg),
    0 0 0 4px var(--pb-accent);
}

.pb-comment-rail-dot:hover {
  filter: brightness(1.1);
}

/* Threads on other pages have no position on THIS rail — counted, not faked. */
.pb-comment-rail-offpage {
  position: absolute;
  bottom: calc(-1 * var(--pb-space-6));
  left: 50%;
  transform: translateX(-50%);
  pointer-events: auto;
  font-size: 9px;
  font-weight: 700;
  color: var(--pb-text-dim);
  cursor: default;
}

@media (max-width: 640px) {
  /* The phone sheet covers the bottom half; a rail beside it has nowhere to go. */
  .pb-comment-rail {
    display: none;
  }
}

/* ── Minimap — the whole page, small, with the comments on it ── */

.pb-comment-minimap {
  position: fixed;
  top: calc(var(--pb-toolbar-height-actual, var(--pb-toolbar-height)) + var(--pb-space-6));
  right: calc(var(--pb-comments-rail-right) + var(--pb-space-6h));
  z-index: var(--pb-z-docked-panel);
  border: 1px solid var(--pb-border);
  border-radius: var(--pb-radius-lg);
  background: var(--pb-surface);
  box-shadow: var(--pb-shadow-panel);
  overflow: hidden;
}

.pb-comment-minimap[hidden] {
  display: none;
}

.pb-comment-minimap-head {
  display: flex;
  align-items: baseline;
  gap: var(--pb-space-3);
  padding: var(--pb-space-2) var(--pb-space-4);
  border-bottom: 1px solid var(--pb-border-soft);
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--pb-text-dim);
}

.pb-comment-minimap-note {
  margin-left: auto;
  text-transform: none;
  letter-spacing: 0;
  color: var(--pb-text-faint);
}

.pb-comment-minimap-body {
  position: relative;
  background: var(--pb-surface-2);
  cursor: pointer;
  touch-action: none;
}

/* The outline is always drawn; a shot simply covers it, so a slow or missing
   image never leaves an empty card. */
.pb-comment-minimap-schematic,
.pb-comment-minimap-dots {
  position: absolute;
  inset: 0;
}

.pb-comment-minimap-shot {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: top center;
}

.pb-comment-minimap-shot[hidden] {
  display: none;
}

.pb-comment-minimap-block {
  position: absolute;
  left: 8%;
  right: 8%;
  border-radius: 1px;
  background: var(--pb-border);
  opacity: 0.55;
}

.pb-comment-minimap-block.is-shared {
  background: var(--pb-text-faint);
}

.pb-comment-minimap-dot {
  position: absolute;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 8px;
  height: 8px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--pb-danger);
  cursor: pointer;
  box-shadow: 0 0 0 1.5px var(--pb-surface);
}

.pb-comment-minimap-dot.is-resolved {
  background: color-mix(in srgb, var(--pb-success) 65%, transparent);
}

.pb-comment-minimap-dot.is-active {
  box-shadow:
    0 0 0 1.5px var(--pb-surface),
    0 0 0 3px var(--pb-accent);
}

.pb-comment-minimap-viewport {
  position: absolute;
  left: 0;
  right: 0;
  border: 1px solid var(--pb-accent);
  background: var(--pb-accent-muted);
  pointer-events: none;
}

.pb-comment-minimap-viewport[hidden] {
  display: none;
}

@media (max-width: 640px) {
  .pb-comment-minimap {
    display: none;
  }
}

/* ── Docked panel (replaces the old centered modal) ── */

.pb-comments-panel {
  position: fixed;
  top: calc(var(--pb-toolbar-height-actual, var(--pb-toolbar-height)) + var(--pb-space-2));
  right: var(--pb-space-4h);
  bottom: var(--pb-space-4h);
  left: auto;
  width: var(--pb-panel-width-comments);
  z-index: var(--pb-z-docked-panel);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--pb-border);
  border-radius: var(--pb-radius-xl);
  background: var(--pb-surface);
  box-shadow: var(--pb-shadow-panel);
  /* The drawer shell ships enter-transition styling elsewhere; this panel is
     shown/removed synchronously. */
  opacity: 1;
  transform: none;
}

/* `display: flex` above outranks the UA stylesheet's `[hidden]` rule, so
   without this the collapse toggle set the property and changed nothing on
   screen. Caught by looking at a screenshot, not by the assertion — which was
   reading the hidden PROPERTY rather than the rendered result. */
.pb-comments-panel[hidden] {
  display: none;
}

/* The panel takes programmatic focus on open (tabIndex -1) so screen readers
   land inside it. Chromium matches :focus-visible on that programmatic focus,
   so the global control treatment (2px outline + 4px glow) would ring the
   ENTIRE dialog — measured, not assumed. A dialog container carries no focus
   ring; its interactive children keep theirs. */
.pb-comments-panel:focus,
.pb-comments-panel:focus-visible {
  outline: none;
  box-shadow: var(--pb-shadow-panel);
}

/* The guest review topbar wraps to a variable height; reserve room for two
   wrapped rows rather than measuring. */
.pb-comments-panel--review {
  top: calc(var(--pb-space-12) + var(--pb-space-12));
}

.pb-comments-panel .pb-drawer-panel-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: var(--pb-space-3);
  padding: var(--pb-space-5) var(--pb-space-6);
  border-bottom: 1px solid var(--pb-border-soft);
}

.pb-comments-panel .pb-drawer-panel-title {
  display: inline-flex;
  align-items: center;
  gap: var(--pb-space-3);
  font-size: var(--pb-font-md);
  font-weight: 600;
  color: var(--pb-text-bright);
}

.pb-comments-panel .pb-drawer-panel-close {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  padding: 0;
  border: 0;
  border-radius: var(--pb-radius);
  background: transparent;
  color: var(--pb-text-dim);
  cursor: pointer;
}

.pb-comments-panel .pb-drawer-panel-close:hover {
  color: var(--pb-text-bright);
  background: var(--pb-surface-hover);
}

.pb-comments-count {
  display: inline-flex;
  align-items: center;
  padding: 1px var(--pb-space-3);
  border-radius: var(--pb-radius-pill);
  background: var(--pb-danger-bg);
  color: var(--pb-danger-text);
  font-size: var(--pb-font-sm);
  font-weight: 700;
}

/* Prev/next stepper, in the header beside the title. */
.pb-comments-nav {
  display: inline-flex;
  align-items: center;
  gap: var(--pb-space-1);
  margin-left: var(--pb-space-3);
}

.pb-comments-nav-btn {
  min-width: 20px;
  padding: 0 var(--pb-space-2);
  line-height: 1;
}

.pb-comments-nav-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

.pb-comments-nav-pos {
  min-width: 44px;
  text-align: center;
  font-size: var(--pb-font-sm);
  color: var(--pb-text-dim);
  font-variant-numeric: tabular-nums;
}

.pb-comments-copy {
  margin-left: var(--pb-space-2);
}

.pb-comments-toolbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: var(--pb-space-3);
  padding: var(--pb-space-3) var(--pb-space-6);
  border-bottom: 1px solid var(--pb-border-soft);
}

/* The panel's primary action and the only comment-mode control. It keeps a
   fixed width across both labels so arming the mode does not reflow the filter
   chip and the hint sitting beside it — the label changes on every toggle. */
.pb-comments-pin-toggle {
  flex: 0 0 auto;
  min-width: 10.5rem;
  justify-content: center;
}

/* Armed. The canvas crosshair is hover-only, so this is the state a touch user
   or a stationary pointer actually reads. */
.pb-comments-pin-toggle.is-active {
  background: var(--pb-accent-muted);
  border-color: var(--pb-accent);
  color: var(--pb-accent);
}

/* Reads as a filter CHIP, not a text link — the ghost variant has no border
   of its own, so the pill outline is drawn here (CRM .dr-rev-panel__filter). */
.pb-comments-filter {
  border: 1px solid var(--pb-border);
  border-radius: var(--pb-radius-pill);
  padding: 2px var(--pb-space-4h);
}

.pb-comments-filter.is-active {
  background: var(--pb-accent-muted);
  border-color: var(--pb-accent);
  color: var(--pb-accent);
}

.pb-comments-hint {
  margin-left: auto;
  font-size: var(--pb-font-sm);
  color: var(--pb-text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pb-comments-panel .pb-drawer-panel-body {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 0;
}

.pb-comments-intro {
  margin: 0;
  padding: var(--pb-space-4) var(--pb-space-6) 0;
  font-size: 12px;
  color: var(--pb-text-dim);
}

.pb-comments-list {
  list-style: none;
  flex: 1 1 auto;
  margin: 0;
  padding: var(--pb-space-5) var(--pb-space-6);
  display: flex;
  flex-direction: column;
  gap: var(--pb-space-4);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.pb-comments-empty {
  margin: 0;
  padding: var(--pb-space-8) var(--pb-space-4);
  text-align: center;
  font-size: 12px;
  color: var(--pb-text-dim);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--pb-space-2);
}

.pb-comments-empty-title {
  font-size: var(--pb-font-md);
  font-weight: 600;
  color: var(--pb-text);
}

.pb-comments-empty-body {
  max-width: 30ch;
}

.pb-comments-empty .pb-illo {
  margin-bottom: var(--pb-space-1);
}

/* Phone: the panel becomes a bottom sheet (CSS only — no drag gestures v1). */
@media (max-width: 640px) {
  .pb-comments-panel,
  .pb-comments-panel--review {
    inset: auto 0 0 0;
    width: auto;
    height: 55dvh;
    border-radius: var(--pb-radius-xl) var(--pb-radius-xl) 0 0;
    border-bottom: 0;
  }
}

/* ── Cards (ported .dr-feedback-card geometry) ── */

.pb-comment-card {
  display: flex;
  gap: var(--pb-space-4);
  padding: var(--pb-space-4) var(--pb-space-4) var(--pb-space-4) var(--pb-space-4h);
  border-radius: var(--pb-radius-lg);
  background: var(--pb-surface);
  border: 1px solid var(--pb-border);
  border-left-width: 3px;
  border-left-color: var(--pb-danger);
  cursor: pointer;
  transition: border-color var(--pb-transition), box-shadow var(--pb-transition);
}

.pb-comment-card:hover {
  border-color: var(--pb-border-strong);
  border-left-color: var(--pb-danger);
  box-shadow: var(--pb-row-shadow-hover);
}

.pb-comment-card.is-active {
  background: var(--pb-accent-muted);
  border-color: var(--pb-accent);
  border-left-color: var(--pb-accent);
  box-shadow: 0 0 0 1px var(--pb-accent);
}

.pb-comment-card.is-resolved {
  opacity: 0.7;
  background: var(--pb-surface-2);
  border-left-color: var(--pb-success);
}

.pb-comment-card.is-orphaned {
  border-style: dashed;
  border-left-style: solid;
}

.pb-comment-card-avatar {
  flex: 0 0 auto;
  width: var(--pb-comment-avatar-size);
  height: var(--pb-comment-avatar-size);
  margin-top: 2px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: var(--pb-font-sm);
  font-weight: 700;
  background: var(--pb-danger-bg);
  color: var(--pb-danger-text);
}

.pb-comment-card.is-resolved .pb-comment-card-avatar {
  background: var(--pb-success-bg);
  color: var(--pb-success-text);
}

.pb-comment-card-body {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: var(--pb-space-2);
}

.pb-comment-card-head {
  display: flex;
  align-items: center;
  gap: var(--pb-space-3);
  flex-wrap: wrap;
  font-size: var(--pb-font-sm);
}

.pb-comment-author {
  font-size: 12px;
  font-weight: 600;
  color: var(--pb-text-bright);
  display: inline-flex;
  align-items: center;
  gap: var(--pb-space-3);
}

.pb-comment-date {
  color: var(--pb-text-dim);
}

.pb-comment-resolved-tag {
  color: var(--pb-success-text);
  font-weight: 600;
}

.pb-comment-card.is-orphaned .pb-comment-anchor-note {
  color: var(--pb-warning-icon);
}

.pb-comment-anchor-note {
  font-size: var(--pb-font-sm);
  color: var(--pb-text-dim);
}

.pb-comment-guest-chip {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  padding: 1px 6px;
  border-radius: var(--pb-radius-pill);
  background: color-mix(in srgb, var(--pb-accent) 14%, transparent);
  color: var(--pb-accent);
}

.pb-comment-body {
  margin: 0;
  font-size: 13px;
  color: var(--pb-text);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* Replies 2..n: compact author-prefixed rows over a dashed rule. */
.pb-comment-replies {
  list-style: none;
  margin: var(--pb-space-2) 0 0;
  padding: var(--pb-space-3) 0 0;
  border-top: 1px dashed var(--pb-border-soft);
  display: flex;
  flex-direction: column;
  gap: var(--pb-space-3);
}

.pb-comment-card-actions {
  display: flex;
  gap: var(--pb-space-3);
  justify-content: flex-end;
}

.pb-comment-reply-form {
  display: flex;
  flex-direction: column;
  gap: var(--pb-space-3);
}

.pb-comment-reply-form[hidden] {
  display: none;
}

.pb-comment-reply-form .pb-input {
  width: 100%;
  resize: vertical;
}

.pb-comment-reply-form-actions {
  display: flex;
  gap: var(--pb-space-3);
  justify-content: flex-end;
}

/* ── Composer ── */

.pb-comment-composer-input {
  width: 100%;
  resize: vertical;
}
