/* Shared icon glyphs + small helpers. Inline stroke SVGs, ~14×14. */
/* Loaded as a Babel script; exported on window. */

const { useState, useEffect, useRef, useMemo } = React;

const I = {
  Search: (p) => (
    <svg width="14" height="14" viewBox="0 0 14 14" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" {...p}>
      <circle cx="6" cy="6" r="4.5"/><path d="M9.4 9.4 L12 12"/>
    </svg>
  ),
  Chev: (p) => (
    <svg width="10" height="10" viewBox="0 0 10 10" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" {...p}>
      <path d="M2.5 3.5 L5 6 L7.5 3.5"/>
    </svg>
  ),
  ChevR: (p) => (
    <svg width="10" height="10" viewBox="0 0 10 10" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" {...p}>
      <path d="M3.5 2.5 L6 5 L3.5 7.5"/>
    </svg>
  ),
  X: (p) => (
    <svg width="12" height="12" viewBox="0 0 12 12" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" {...p}>
      <path d="M3 3 L9 9 M9 3 L3 9"/>
    </svg>
  ),
  Check: (p) => (
    <svg width="12" height="12" viewBox="0 0 12 12" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}>
      <path d="M2.5 6 L5 8.5 L9.5 3.5"/>
    </svg>
  ),
  Bldg: (p) => (
    <svg width="14" height="14" viewBox="0 0 14 14" fill="none" stroke="currentColor" strokeWidth="1.3" strokeLinecap="round" strokeLinejoin="round" {...p}>
      <rect x="2.5" y="2" width="9" height="10.5" rx="0.5"/>
      <path d="M4.5 4.5 H6 M4.5 6.5 H6 M4.5 8.5 H6 M8 4.5 H9.5 M8 6.5 H9.5 M8 8.5 H9.5"/>
      <path d="M5.5 12.5 V10.5 H8.5 V12.5"/>
    </svg>
  ),
  Co: (p) => (
    <svg width="14" height="14" viewBox="0 0 14 14" fill="none" stroke="currentColor" strokeWidth="1.3" strokeLinecap="round" strokeLinejoin="round" {...p}>
      <circle cx="4.5" cy="5" r="1.8"/>
      <path d="M2 11 C2.2 9 3.3 8.5 4.5 8.5 C5.7 8.5 6.8 9 7 11"/>
      <circle cx="10" cy="6" r="1.4"/>
      <path d="M8 11 C8.2 9.5 9 9.2 10 9.2 C11 9.2 11.8 9.5 12 11"/>
    </svg>
  ),
  History: (p) => (
    <svg width="14" height="14" viewBox="0 0 14 14" fill="none" stroke="currentColor" strokeWidth="1.4" strokeLinecap="round" strokeLinejoin="round" {...p}>
      <path d="M2.5 4 A4.5 4.5 0 1 1 2.6 8.5"/>
      <path d="M2.5 2 V4.2 H4.7"/>
      <path d="M7 5 V7.5 L8.8 8.5"/>
    </svg>
  ),
  Card: (p) => (
    <svg width="14" height="14" viewBox="0 0 14 14" fill="none" stroke="currentColor" strokeWidth="1.4" strokeLinecap="round" strokeLinejoin="round" {...p}>
      <rect x="1.5" y="3" width="11" height="8" rx="1"/>
      <path d="M1.5 5.5 H12.5"/>
    </svg>
  ),
  Gear: (p) => (
    <svg width="14" height="14" viewBox="0 0 14 14" fill="none" stroke="currentColor" strokeWidth="1.3" strokeLinecap="round" strokeLinejoin="round" {...p}>
      <circle cx="7" cy="7" r="2"/>
      <path d="M7 1.5 V3 M7 11 V12.5 M2.5 7 H1 M13 7 H11.5 M3.6 3.6 L2.6 2.6 M11.4 11.4 L10.4 10.4 M3.6 10.4 L2.6 11.4 M11.4 2.6 L10.4 3.6"/>
    </svg>
  ),
  Users: (p) => (
    <svg width="14" height="14" viewBox="0 0 14 14" fill="none" stroke="currentColor" strokeWidth="1.3" strokeLinecap="round" strokeLinejoin="round" {...p}>
      <circle cx="5" cy="5" r="1.8"/>
      <path d="M2 11 C2.2 8.8 3.5 8.2 5 8.2 C6.5 8.2 7.8 8.8 8 11"/>
      <circle cx="10" cy="5.5" r="1.4"/>
      <path d="M9 8.5 C10.7 8.5 11.8 9.2 12 11"/>
    </svg>
  ),
  Chart: (p) => (
    <svg width="14" height="14" viewBox="0 0 14 14" fill="none" stroke="currentColor" strokeWidth="1.3" strokeLinecap="round" strokeLinejoin="round" {...p}>
      <path d="M2 11.5 H12.5"/>
      <rect x="3" y="7"  width="1.6" height="4" fill="currentColor" opacity="0.7" stroke="none"/>
      <rect x="6"   y="4"  width="1.6" height="7" fill="currentColor" opacity="0.7" stroke="none"/>
      <rect x="9"   y="6"  width="1.6" height="5" fill="currentColor" opacity="0.7" stroke="none"/>
    </svg>
  ),
  Download: (p) => (
    <svg width="14" height="14" viewBox="0 0 14 14" fill="none" stroke="currentColor" strokeWidth="1.4" strokeLinecap="round" strokeLinejoin="round" {...p}>
      <path d="M7 2 V9 M4.2 6.3 L7 9 L9.8 6.3"/>
      <path d="M2.5 11.5 H11.5"/>
    </svg>
  ),
  Plus: (p) => (
    <svg width="12" height="12" viewBox="0 0 12 12" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" {...p}>
      <path d="M6 2 V10 M2 6 H10"/>
    </svg>
  ),
  Dots: (p) => (
    <svg width="14" height="14" viewBox="0 0 14 14" fill="currentColor" {...p}>
      <circle cx="3" cy="7" r="1.2"/><circle cx="7" cy="7" r="1.2"/><circle cx="11" cy="7" r="1.2"/>
    </svg>
  ),
  Tag: (p) => (
    <svg width="12" height="12" viewBox="0 0 12 12" fill="none" stroke="currentColor" strokeWidth="1.3" strokeLinecap="round" strokeLinejoin="round" {...p}>
      <path d="M1.8 1.8 H5 L10.2 7 L7 10.2 L1.8 5 Z"/>
      <circle cx="3.5" cy="3.5" r="0.6" fill="currentColor"/>
    </svg>
  ),
  Open: (p) => (
    <svg width="11" height="11" viewBox="0 0 11 11" fill="none" stroke="currentColor" strokeWidth="1.3" strokeLinecap="round" strokeLinejoin="round" {...p}>
      <path d="M4.5 1.5 H1.5 V9.5 H9.5 V6.5"/>
      <path d="M6 1.5 H9.5 V5"/>
      <path d="M5.5 5.5 L9.5 1.5"/>
    </svg>
  ),
  Mail: (p) => (
    <svg width="12" height="12" viewBox="0 0 12 12" fill="none" stroke="currentColor" strokeWidth="1.4" strokeLinecap="round" strokeLinejoin="round" {...p}>
      <rect x="1" y="2.5" width="10" height="7" rx="1"/>
      <path d="M1.5 3 L6 6.3 L10.5 3"/>
    </svg>
  ),
  Pause: (p) => (
    <svg width="12" height="12" viewBox="0 0 12 12" fill="none" stroke="currentColor" strokeWidth="1.4" strokeLinecap="round" {...p}>
      <path d="M4 2.5 V9.5 M8 2.5 V9.5"/>
    </svg>
  ),
  Refresh: (p) => (
    <svg width="12" height="12" viewBox="0 0 12 12" fill="none" stroke="currentColor" strokeWidth="1.4" strokeLinecap="round" strokeLinejoin="round" {...p}>
      <path d="M2 6 A4 4 0 0 1 9.5 4"/>
      <path d="M9.5 1.5 V4 H7"/>
      <path d="M10 6 A4 4 0 0 1 2.5 8"/>
      <path d="M2.5 10.5 V8 H5"/>
    </svg>
  ),
  Logout: (p) => (
    <svg width="12" height="12" viewBox="0 0 12 12" fill="none" stroke="currentColor" strokeWidth="1.4" strokeLinecap="round" strokeLinejoin="round" {...p}>
      <path d="M5 2.5 H2 V9.5 H5"/>
      <path d="M5 6 H10.5 M8.5 4 L10.5 6 L8.5 8"/>
    </svg>
  ),
  Shield: (p) => (
    <svg width="14" height="14" viewBox="0 0 14 14" fill="none" stroke="currentColor" strokeWidth="1.3" strokeLinecap="round" strokeLinejoin="round" {...p}>
      <path d="M7 1.5 L12 3 V7 C12 9.5 9.8 11.5 7 12.5 C4.2 11.5 2 9.5 2 7 V3 L7 1.5 Z"/>
    </svg>
  ),
  Pin: (p) => (
    <svg width="14" height="14" viewBox="0 0 14 14" fill="none" stroke="currentColor" strokeWidth="1.3" strokeLinecap="round" strokeLinejoin="round" {...p}>
      <path d="M7 1.5 C4.5 1.5 2.8 3.2 2.8 5.5 C2.8 8.5 7 12.5 7 12.5 C7 12.5 11.2 8.5 11.2 5.5 C11.2 3.2 9.5 1.5 7 1.5 Z"/>
      <circle cx="7" cy="5.5" r="1.5"/>
    </svg>
  ),
  Eye: (p) => (
    <svg width="14" height="14" viewBox="0 0 14 14" fill="none" stroke="currentColor" strokeWidth="1.3" strokeLinecap="round" strokeLinejoin="round" {...p}>
      <path d="M1 7 C2.5 4 4.5 2.5 7 2.5 C9.5 2.5 11.5 4 13 7 C11.5 10 9.5 11.5 7 11.5 C4.5 11.5 2.5 10 1 7 Z"/>
      <circle cx="7" cy="7" r="2"/>
    </svg>
  ),
  Sparkle: (p) => (
    <svg width="14" height="14" viewBox="0 0 14 14" fill="none" stroke="currentColor" strokeWidth="1.3" strokeLinecap="round" strokeLinejoin="round" {...p}>
      <path d="M7 2 L8 6 L12 7 L8 8 L7 12 L6 8 L2 7 L6 6 Z"/>
    </svg>
  ),
  Box: (p) => (
    <svg width="14" height="14" viewBox="0 0 14 14" fill="none" stroke="currentColor" strokeWidth="1.3" strokeLinecap="round" strokeLinejoin="round" {...p}>
      <path d="M2 4 L7 1.5 L12 4 V10 L7 12.5 L2 10 Z"/>
      <path d="M2 4 L7 6.5 L12 4 M7 6.5 V12.5"/>
    </svg>
  ),
};

// Browser logos for the landing page — flat duotone, small
const Browser = {
  Chrome: () => (
    <svg width="28" height="28" viewBox="0 0 28 28" aria-label="Chrome">
      <circle cx="14" cy="14" r="13" fill="#fff" stroke="rgba(15,23,42,0.1)"/>
      <circle cx="14" cy="14" r="4" fill="#2563eb"/>
      <path d="M14 4 A10 10 0 0 1 22.66 9 L14 14 Z" fill="#dc2626" opacity="0.85"/>
      <path d="M22.66 9 A10 10 0 0 1 22.66 19 L14 14 Z" fill="#16a34a" opacity="0.85"/>
      <path d="M22.66 19 A10 10 0 0 1 5.34 19 L14 14 Z" fill="#facc15" opacity="0.85"/>
      <path d="M5.34 19 A10 10 0 0 1 5.34 9 L14 14 Z" fill="#16a34a" opacity="0.85"/>
      <path d="M5.34 9 A10 10 0 0 1 14 4 L14 14 Z" fill="#dc2626" opacity="0.85"/>
      <circle cx="14" cy="14" r="3.5" fill="#2563eb"/>
    </svg>
  ),
  Firefox: () => (
    <svg width="28" height="28" viewBox="0 0 28 28" aria-label="Firefox">
      <circle cx="14" cy="14" r="13" fill="#1e293b"/>
      <path d="M7 7 Q14 4 21 7 Q24 14 21 21 Q14 24 7 21 Q4 14 7 7 Z" fill="#ea580c"/>
      <circle cx="14" cy="14" r="5" fill="#facc15"/>
      <circle cx="14" cy="14" r="3" fill="#ea580c"/>
    </svg>
  ),
  Edge: () => (
    <svg width="28" height="28" viewBox="0 0 28 28" aria-label="Edge">
      <circle cx="14" cy="14" r="13" fill="#fff" stroke="rgba(15,23,42,0.1)"/>
      <path d="M4 14 Q4 4 14 4 Q22 4 23 12 Q18 9 14 12 Q9 15 4 14 Z" fill="#0891b2"/>
      <path d="M4 14 Q4 22 14 24 Q22 24 24 16 Q19 18 14 18 Q9 18 4 14 Z" fill="#2563eb"/>
    </svg>
  ),
  Safari: () => (
    <svg width="28" height="28" viewBox="0 0 28 28" aria-label="Safari">
      <circle cx="14" cy="14" r="13" fill="#fff" stroke="rgba(15,23,42,0.1)"/>
      <circle cx="14" cy="14" r="11" fill="#dbeafe"/>
      <path d="M14 6 L15 14 L22 14 L13 15 L14 22 L13 14 L6 14 L13 13 Z" fill="#dc2626"/>
      <circle cx="14" cy="14" r="1" fill="#fff"/>
    </svg>
  ),
};

// Tiny logo component
function Logo({ size = "md" }) {
  return (
    <span className={"logo " + (size === "lg" ? "lg" : size === "xl" ? "xl" : "")}>
      AI<span className="dot">.</span>CONTACTIQ
    </span>
  );
}

// Avatar from name
function Avatar({ name, size = "md" }) {
  const initials = (name || "?")
    .split(/\s+/).map(p => p[0]).slice(0, 2).join("").toUpperCase();
  // Stable hue per name for a touch of variety
  const hue = useMemo(() => {
    let h = 0;
    for (const c of name || "") h = (h * 31 + c.charCodeAt(0)) % 360;
    return h;
  }, [name]);
  return (
    <span
      className={"avatar " + (size === "sm" ? "sm" : size === "lg" ? "lg" : "")}
      style={{ background: `oklch(0.62 0.12 ${hue})` }}
    >{initials}</span>
  );
}

// Status pill for a plan
function PlanPill({ plan }) {
  const map = {
    active:    { cls: "green",  label: "Active" },
    trial:     { cls: "accent", label: "Trial" },
    trialing:  { cls: "accent", label: "Trial" },
    past_due:  { cls: "amber",  label: "Past due" },
    canceled:  { cls: "",       label: "Canceled" },
  };
  const m = map[plan] || map.canceled;
  return <span className={"pill " + m.cls}>{m.label}</span>;
}

// Type pill for a lookup (building / company)
function TypePill({ type }) {
  if (type === "building") {
    return <span className="pill" style={{ color: "var(--src-business)", background: "rgba(99,102,241,0.08)", borderColor: "rgba(99,102,241,0.2)" }}>
      <I.Bldg style={{ width: 11, height: 11 }}/> Building
    </span>;
  }
  return <span className="pill" style={{ color: "var(--src-attorney)", background: "rgba(15,118,110,0.08)", borderColor: "rgba(15,118,110,0.2)" }}>
    <I.Co style={{ width: 11, height: 11 }}/> Company
  </span>;
}

// Google "G" logo (Google Pay button)
function GoogleG({ size = 14 }) {
  return (
    <svg width={size} height={size} viewBox="0 0 24 24" aria-hidden="true">
      <path fill="#4285F4" d="M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92c-.26 1.37-1.04 2.53-2.21 3.31v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.09Z"/>
      <path fill="#34A853" d="M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.99.66-2.25 1.06-3.71 1.06-2.85 0-5.26-1.92-6.13-4.51H2.18v2.84A11 11 0 0 0 12 23Z"/>
      <path fill="#FBBC04" d="M5.87 14.12A6.6 6.6 0 0 1 5.53 12c0-.74.13-1.45.34-2.12V7.04H2.18A11 11 0 0 0 1 12c0 1.78.42 3.46 1.18 4.96l3.69-2.84Z"/>
      <path fill="#EA4335" d="M12 5.38c1.62 0 3.06.56 4.21 1.65l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.04l3.69 2.84C6.74 7.3 9.15 5.38 12 5.38Z"/>
    </svg>
  );
}

Object.assign(window, { I, Browser, Logo, Avatar, PlanPill, TypePill, GoogleG });
