/**
 * image-controls.css — chrome for the local image plugin.
 *
 * The rendered figure itself keeps draftly's classes and theme. This file adds
 * the media wrapper, settings gear, resize handles, and the body-mounted
 * settings popover.
 */

.cm-draftly-image-figure {
  position: relative;
  /* Keep the gear and corner handles on the image, not on the whole line. */
  width: fit-content;
  max-width: 100%;
}

.cm-image-media {
  position: relative;
  display: block;
  max-width: 100%;
  line-height: 0;
}

.cm-image-media > .cm-image-link {
  display: block;
  max-width: 100%;
}

.cm-image-media > .cm-image-link > img {
  display: block;
}

.cm-image-gear {
  position: absolute;
  top: 6px;
  right: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  padding: 0;
  border: 1px solid var(--color-border, #d0d7de);
  border-radius: var(--radius-sm, 6px);
  background: var(--color-surface, #fff);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.14);
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transition: opacity 120ms ease;
  z-index: 2;
}

.cm-image-gear img {
  width: 15px;
  height: 15px;
  pointer-events: none;
}

.cm-draftly-image-figure:hover .cm-image-gear,
.cm-draftly-image-figure:focus-within .cm-image-gear,
.cm-image-gear.is-open {
  opacity: 1;
  pointer-events: auto;
}

.cm-image-gear:hover {
  background: var(--color-surface-hover, rgba(0, 0, 0, 0.06));
}

.cm-image-gear:focus-visible {
  outline: 2px solid var(--color-accent, #606c76);
  outline-offset: 1px;
}

.cm-image-handle {
  position: absolute;
  width: 12px;
  height: 12px;
  border: 1px solid var(--color-accent, #606c76);
  border-radius: 2px;
  background: var(--color-surface, #fff);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.18);
  opacity: 0;
  pointer-events: none;
  transition: opacity 120ms ease;
  z-index: 2;
}

.cm-draftly-image-figure:hover .cm-image-handle,
.cm-draftly-image-figure:focus-within .cm-image-handle,
.cm-draftly-image-figure.is-resizing .cm-image-handle {
  opacity: 1;
  pointer-events: auto;
}

.cm-image-handle-nw { top: -6px; left: -6px; cursor: nwse-resize; }
.cm-image-handle-ne { top: -6px; right: -6px; cursor: nesw-resize; }
.cm-image-handle-sw { bottom: -6px; left: -6px; cursor: nesw-resize; }
.cm-image-handle-se { bottom: -6px; right: -6px; cursor: nwse-resize; }

.cm-image-resizing,
.cm-image-resizing * {
  user-select: none !important;
}

/* ===== Settings popover ===== */

.cm-image-popover {
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  min-width: 260px;
  padding: 10px;
  white-space: normal;
}

.cm-image-popover-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.cm-image-popover-label {
  display: block;
  flex: 0 0 76px;
  color: var(--color-text-muted, #6a737d);
  font-size: 0.75rem;
}

.cm-image-popover-input {
  flex: 1 1 auto;
  min-width: 0;
  height: 28px;
  padding: 4px 7px;
  font-size: 0.78rem;
}

.cm-image-popover-section {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-top: 8px;
  border-top: 1px solid var(--color-border, #d0d7de);
}

.cm-image-popover-actions {
  display: flex;
  gap: 6px;
}

.cm-image-popover-btn {
  padding: 4px 9px;
  border: 1px solid var(--color-border, #d0d7de);
  border-radius: var(--radius-sm, 6px);
  background: var(--color-surface, #fff);
  color: var(--color-text, #1a1a1a);
  font: inherit;
  font-size: 0.78rem;
  line-height: 1.3;
  cursor: pointer;
}

.cm-image-popover-btn:hover {
  background: var(--color-surface-hover, rgba(0, 0, 0, 0.06));
}

.cm-image-popover-btn:focus-visible {
  outline: 2px solid var(--color-accent, #606c76);
  outline-offset: 1px;
}

.cm-image-popover .cm-fence-popover-footer {
  margin-top: 2px;
}
