/**
 * Copy text to clipboard with fallback for HTTP (non-secure) contexts.
 * navigator.clipboard.writeText requires HTTPS or localhost.
 */
export function copyToClipboard(text) {
  if (navigator.clipboard && window.isSecureContext) {
    return navigator.clipboard.writeText(text)
  }
  // Fallback: hidden textarea + execCommand
  const textarea = document.createElement('textarea')
  textarea.value = text
  textarea.style.position = 'fixed'
  textarea.style.left = '-9999px'
  textarea.style.top = '-9999px'
  document.body.appendChild(textarea)
  textarea.focus()
  textarea.select()
  try {
    document.execCommand('copy')
  } catch (e) {
    console.error('Copy failed:', e)
  }
  document.body.removeChild(textarea)
  return Promise.resolve()
}
