/*
 * Copyright (c) 2026 Apurva Nakade. All rights reserved.
 * Released under Apache 2.0 license as described in the file LICENSE.
 * Authors: Apurva Nakade
 */

/* share.js inserts a "Share" button as the first row of every app's
 * <div class="vm-app">, opening a native <dialog> (appended to <body>, in
 * the top layer -- same reasoning as the play-speed popover in mathviz's
 * slider-play.js) that shows the page's own link, with and without the
 * current inputs, and builds the ?embed= <iframe> snippet. */

.vm-share-bar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 0.25rem;
}

.vm-share-button {
  padding: 0.25rem 0.65rem;
  border: 1px solid var(--vm-border);
  border-radius: var(--vm-radius-sm);
  background: var(--vm-surface);
  color: var(--vm-text-soft);
  font-size: 0.8rem;
  line-height: 1.2;
  cursor: pointer;
}

.vm-share-button:hover {
  background: var(--vm-surface-hover);
  color: var(--vm-text);
}

.vm-share-dialog {
  max-width: min(42rem, 92vw);
  padding: 1.25rem 1.5rem;
  border: 1px solid var(--vm-border);
  border-radius: var(--vm-radius);
  background: var(--vm-surface);
  color: var(--vm-text);
  box-shadow: var(--vm-shadow);
}

.vm-share-dialog::backdrop {
  background: rgba(0, 0, 0, 0.4);
}

.vm-share-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.vm-share-form h2 {
  margin: 0;
  font-size: 1.1rem;
}

.vm-share-form p {
  margin: 0;
  font-size: 0.9rem;
  color: var(--vm-text-soft);
}

.vm-share-form h3 {
  margin: 0.25rem 0 0;
  font-size: 0.95rem;
}

/* Label, URL, "Copied" status: one row per link. The URL column shrinks
 * (minmax(0, ...)) and breaks anywhere, so a long query string wraps
 * inside the dialog rather than widening it past a phone's screen. */
.vm-share-links {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) 3.5rem;
  align-items: baseline;
  gap: 0.35rem 0.75rem;
  font-size: 0.85rem;
}

.vm-share-link-label {
  color: var(--vm-text-soft);
  white-space: nowrap;
}

.vm-share-link {
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.8rem;
  overflow-wrap: anywhere;
}

.vm-share-link-status {
  color: var(--vm-text-soft);
  font-size: 0.8rem;
}

/* On a phone the label column would squeeze the URL into a sliver; put
 * each label on its own row above its link instead. */
@media (max-width: 575.98px) {
  .vm-share-links {
    grid-template-columns: minmax(0, 1fr) 3.5rem;
  }

  .vm-share-link-label {
    grid-column: 1 / -1;
  }
}

.vm-share-checkbox-row,
.vm-share-height-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
}

.vm-share-height {
  width: 6rem;
  padding: 0.2rem 0.4rem;
  border: 1px solid var(--vm-border);
  border-radius: var(--vm-radius-sm);
  background: var(--vm-bg);
  color: var(--vm-text);
}

.vm-share-code {
  width: 100%;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--vm-border);
  border-radius: var(--vm-radius-sm);
  background: var(--vm-bg);
  color: var(--vm-text);
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.8rem;
  resize: vertical;
}

.vm-share-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

.vm-share-actions button {
  padding: 0.35rem 0.75rem;
  border: 1px solid var(--vm-border);
  border-radius: var(--vm-radius-sm);
  background: var(--vm-surface);
  color: var(--vm-text);
  cursor: pointer;
}

.vm-share-actions .vm-share-copy {
  background: var(--vm-accent);
  border-color: var(--vm-accent);
  color: var(--vm-on-accent);
}

.vm-share-actions .vm-share-copy:hover {
  background: var(--vm-accent-hover);
  border-color: var(--vm-accent-hover);
}

.vm-share-actions .vm-share-close:hover {
  background: var(--vm-surface-hover);
}
