/**
 * link-preview.css — Link previews: inline hover links, popovers, block
 * cards (block / strip / tower) and the override modal.
 *
 * The cards reuse the paper palette so they sit naturally inside the editor
 * and the print/read view. The card foreground (title/desc) is kept simple:
 * --color-text, --color-text-muted, --color-border, --color-surface-2.
 */

/* ===== Hover links ===== */
.lp-hover {
  position: relative;
  color: var(--color-link, #2f6f9f);
  text-underline-offset: 2px;
  text-decoration: underline;
  text-decoration-style: dotted;
  cursor: help;
}

.lp-link {
  color: var(--color-link, #2f6f9f);
}

/* ===== Read-renderer popover (markdown-print) ===== */
.lp-pop {
  display: inline-flex;
  flex-direction: column;
  gap: 4px;
  max-width: 320px;
  padding: 10px 12px;
  background: var(--color-surface-2, #fff);
  border: 1px solid var(--color-border, #ddd);
  border-radius: var(--radius-md, 8px);
  box-shadow: var(--shadow-lg, 0 8px 24px rgba(0, 0, 0, 0.16));
  font-size: 0.85rem;
  line-height: 1.45;
}

.lp-pop-title {
  font-weight: 600;
  color: var(--color-text, #1f1b16);
}

.lp-pop-desc {
  color: var(--color-text-muted, #6b6257);
}

.lp-pop .lp-media {
  order: -1;
}

.lp-pop .lp-meta .lp-url {
  display: none;
}

/* ===== Block cards ===== */
.lp-card {
  position: relative;
  display: flex;
  gap: 12px;
/*   margin: 12px 0; */
  padding: 12px 14px;
  background: var(--color-surface-2, #fff);
  border: 1px solid var(--color-border, #e3ddd2);
  border-radius: var(--radius-md, 8px);
}

.lp-media {
  position: relative;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 64px;
  height: 64px;
  overflow: hidden;
  background: var(--color-surface-1, #f6f2ea);
  border-radius: var(--radius-sm, 6px);
}

.lp-media .lp-image {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.lp-fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  color: var(--color-text-muted, #6b6257);
  font-family: var(--font-serif, Georgia, serif);
  font-size: 1.6rem;
}

.lp-fallback-icon,
.lp-favicon {
  width: 24px;
  height: 24px;
  object-fit: contain;
}

.lp-body {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.lp-title {
  color: var(--color-text, #1f1b16);
  font-weight: 600;
  line-height: 1.35;
}

.lp-desc {
  color: var(--color-text-muted, #6b6257);
  font-size: 0.85rem;
  line-height: 1.45;
}

.lp-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
  color: var(--color-text-muted, #6b6257);
  font-size: 0.78rem;
}

.lp-domain {
  font-weight: 500;
}

.lp-url {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Whole-card click target for block/tower templates. */
.lp-click {
  position: absolute;
  inset: 0;
}

.lp-click:hover {
  background: rgba(0, 0, 0, 0.02);
}

.lp-edit {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
  display: none;
  padding: 2px 6px;
  background: var(--color-surface-2, #fff);
  border: 1px solid var(--color-border, #e3ddd2);
  border-radius: var(--radius-sm, 6px);
  color: var(--color-text-muted, #6b6257);
  cursor: pointer;
}

.lp-card:hover .lp-edit {
  display: block;
}

/* ===== Strip (compact) ===== */
.lp-card--strip {
  gap: 8px;
  align-items: center;
  padding: 8px 10px;
  margin: 8px 0;
}

.lp-card--strip .lp-media {
  width: 32px;
  height: 32px;
}

.lp-card--strip .lp-body {
  flex-direction: row;
  align-items: center;
  gap: 8px;
}

.lp-card--strip .lp-title {
  flex: 0 1 auto;
  font-size: 0.9rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lp-card--strip .lp-desc {
  display: none;
}

.lp-card--strip .lp-meta {
  margin-top: 0;
  white-space: nowrap;
}

.lp-card--strip .lp-meta .lp-url {
  max-width: 220px;
}

/* ===== Tower (image-led) ===== */
.lp-card--tower {
  flex-direction: column;
  gap: 10px;
  max-width: 520px;
}

.lp-card--tower .lp-media {
  width: 100%;
  height: auto;
  max-height: 260px;
  aspect-ratio: 16 / 9;
}

.lp-card--tower .lp-media .lp-image {
  position: static;
  width: 100%;
  height: auto;
  object-fit: cover;
}

/* ===== Editor widgets ===== */
.lp-widget {
  position: relative;
  margin: 2px 0;
}

.lp-widget-hint {
  color: var(--color-text-muted, #6b6257);
  margin-left: 4px;
}

/* ===== Settings gear (edit mode only) =====
   Mirrors `.cm-fence-gear`: in flow whether revealed or not, so hovering the
   card never reflows it — only opacity and hit-testing change. Sits top-right
   of the card, above the whole-card `.lp-click` overlay. */
.lp-gear {
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 3;
  display: inline-flex;
  align-items: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 120ms ease;
}

.lp-card:hover .lp-gear,
.lp-widget:hover .lp-gear,
.lp-gear:focus-within,
.lp-gear.is-open {
  opacity: 1;
  pointer-events: auto;
}

.lp-gear-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  padding: 0;
  border: none;
  border-radius: 4px;
  background: var(--color-surface-2, #fff);
  color: var(--color-text-muted, #6b6257);
  font-size: 15px;
  line-height: 1;
  opacity: 0.75;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}

.lp-gear-btn:hover {
  opacity: 1;
  background: var(--color-surface-hover, rgba(0, 0, 0, 0.06));
}

.lp-gear-btn:focus-visible {
  opacity: 1;
  outline: 2px solid var(--color-accent, #606c67);
  outline-offset: 1px;
}

/* The no-meta fallback has no `.lp-card`; the gear rides on the wrap. */
.lp-widget > .lp-gear {
  top: 0;
}

/* ===== Settings popover =====
   Shares the fence popover's chrome (fixed, z-index, border, shadow) via
   `cm-fence-popover`, but stacks vertically with fields instead of the
   swatch row. Mounted on document.body like the fence popover. */
.lp-popover {
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  min-width: 240px;
  max-width: 300px;
  white-space: normal;
}

.lp-popover .cm-fence-popover-label {
  display: block;
  font-weight: 600;
}

.lp-popover-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

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

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

.lp-popover .cm-fence-popover-btn.is-active {
  border-color: var(--color-accent, #2f6f9f);
  background: var(--color-accent-soft, rgba(47, 111, 159, 0.12));
  font-weight: 600;
}

.lp-popover-field {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.lp-popover-field-label {
  font-size: 0.7rem;
  color: var(--color-text-muted, #6a737d);
}

.lp-popover-field .input {
  width: 100%;
  box-sizing: border-box;
  padding: 5px 7px;
  border: 1px solid var(--color-border, #d0d7de);
  border-radius: var(--radius-sm, 6px);
  background: var(--color-surface, #fff);
  color: var(--color-text, #1a1a1a);
  font-size: 0.8rem;
}

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

.lp-popover-footer {
  align-items: center;
  justify-content: space-between;
  padding-top: 6px;
  border-top: 1px solid var(--color-border, #e3ddd2);
}

.lp-popover-remove {
  padding: 4px 8px;
  border: 1px solid var(--color-danger-border, #d73a49);
  border-radius: var(--radius-sm, 6px);
  background: transparent;
  color: var(--color-danger, #b31d28);
  font-size: 0.78rem;
  cursor: pointer;
}

.lp-popover-remove:hover {
  background: var(--color-danger-soft, rgba(215, 58, 73, 0.1));
}

/* Hover-marked prose links inside the editor. */
.cm-lp .lp-render-hover,
.lp-render-hover {
  text-underline-offset: 2px;
  text-decoration: underline;
  text-decoration-style: dotted;
  cursor: help;
}

/* Editor popover (mirrors .lp-pop, positioned inside the editor DOM). */
.cm-lp-popover {
  position: absolute;
  z-index: 40;
  pointer-events: none;
}

.cm-lp-popover .lp-pop {
  box-shadow: var(--shadow-lg, 0 8px 24px rgba(0, 0, 0, 0.18));
}

.cm-lp-popover .lp-pop .lp-url {
  max-width: 240px;
}

/* ===== Tower inside paste-card media (fits the 140px media slot) ===== */
.paste-card-media .lp-card--tower {
  position: relative;
  width: 100%;
  height: 140px;
  max-width: none;
  max-height: 140px;
  margin: 0;
  padding: 0;
  gap: 0;
  border: 0;
  border-radius: 0;
  overflow: hidden;
}

.paste-card-media .lp-card--tower .lp-media {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  max-height: none;
  aspect-ratio: auto;
  border-radius: 0;
  background: var(--color-surface, #f6f2ea);
}

.paste-card-media .lp-card--tower .lp-media .lp-image {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.paste-card-media .lp-card--tower .lp-fallback {
  font-size: 1.2rem;
}

.paste-card-media .lp-card--tower .lp-body {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 18px 10px 7px;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.68), transparent);
}

.paste-card-media .lp-card--tower .lp-title {
  color: #fff;
  font-size: 0.85rem;
  font-weight: 600;
}

.paste-card-media .lp-card--tower .lp-desc {
  display: none;
}

.paste-card-media .lp-card--tower .lp-meta {
  margin-top: 2px;
  color: rgba(255, 255, 255, 0.9);
}

.paste-card-media .lp-card--tower .lp-url {
  max-width: 150px;
  color: rgba(255, 255, 255, 0.75);
}

.paste-card-media .lp-card--tower .lp-favicon {
  width: 14px;
  height: 14px;
}

/** The whole-card click target would hijack paste-card navigation. */
.paste-card-media .lp-card--tower .lp-click {
  display: none;
}

/* ===== Override modal ===== */
.lp-override-modal {
  max-width: 460px;
}

.lp-override-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.lp-override-summary {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  padding: 8px 10px;
  background: var(--color-surface-1, #f6f2ea);
  border-radius: var(--radius-sm, 6px);
}

.lp-override-summary .lp-favicon {
  width: 20px;
  height: 20px;
}

.lp-override-url {
  color: var(--color-text-muted, #6b6257);
  font-size: 0.82rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lp-override-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--color-text-muted, #6b6257);
  margin-top: 6px;
}

.lp-override-modal textarea.input {
  resize: vertical;
  min-height: 64px;
}