// ---------- CONTACT CONFIG (single source of truth) ----------
const GMR = {
  phone: "+1 786 695 6441",   // Brytez business phone
  phoneTel: "+17866956441",  // tel: href
  whatsapp: "17866956441",   // wa.me number (E.164, no +)
  email: "info@brytez.com",
  instagram: "https://www.instagram.com/brytezmia/", // Account to be created before launch
  instagramHandle: "@brytezmia",
};

// Build a WhatsApp deep link with a pre-filled message.
const waLink = (text) =>
  GMR.whatsapp ? `https://wa.me/${GMR.whatsapp}?text=${encodeURIComponent(
    text || "Hi Brytez — I'd like to speak with a specialist."
  )}` : `mailto:${GMR.email}`;

// Build a mailto link with subject + body.
const mailLink = (subject, body) =>
  `mailto:${GMR.email}?subject=${encodeURIComponent(subject || "Brytez Inquiry")}` +
  (body ? `&body=${encodeURIComponent(body)}` : "");

// POST a lead to /api/contact, which emails it to Brytez and archives it.
// Never throws: a failed capture must not block the WhatsApp handoff.
// Resolves { ok, delivered } — `delivered:false` means "archived but no email
// went out", so the caller can fall back to the visitor's own mail client.
const sendLead = async (payload) => {
  try {
    const res = await fetch("/api/contact", {
      method: "POST",
      headers: { "content-type": "application/json" },
      body: JSON.stringify(payload),
    });
    if (!res.ok) return { ok: false, delivered: false };
    return await res.json();
  } catch {
    return { ok: false, delivered: false };
  }
};

// ---------- DATA ----------
// Se llena en runtime desde /api/catalog (app.jsx). No meter datos de muestra:
// el seed falso se veia un instante en cada carga (y para siempre si la API fallaba).
const WATCHES = [];


// ---------- USD ----------
const usd = (n) =>
  new Intl.NumberFormat("en-US", { style: "currency", currency: "USD", maximumFractionDigits: 0 }).format(n);

// ---------- WATCH ILLUSTRATION ----------
// Generated luxury watch illustrations (original, not recreating branded designs).
// Each watch gets a subtly different style determined by `style` in `tone`.
const WatchArt = ({ watch, size = 260 }) => {
  const { tone } = watch;
  const dialBg = tone.dialBg || "#F5F2EA";
  const dialTxt = tone.dialTxt || "#1A1A1A";
  const caseColor = tone.caseColor || "#C9C7C2";
  const caseEdge = tone.caseEdge || "#7B7A76";
  const braceletColor = tone.braceletColor || caseColor;
  const hands = tone.hands || dialTxt;
  const lume = tone.lume || "#E8D9A8";
  const accent = tone.accent;
  const type = tone.type || "diver"; // diver | dress | gmt | chrono

  return (
    <svg viewBox="0 0 300 300" width="100%" height="100%" preserveAspectRatio="xMidYMid meet" style={{ display: "block" }}>
      <defs>
        <radialGradient id={`dial-${watch.id}`} cx="50%" cy="42%" r="60%">
          <stop offset="0%" stopColor={shade(dialBg, 8)} />
          <stop offset="100%" stopColor={shade(dialBg, -14)} />
        </radialGradient>
        <linearGradient id={`case-${watch.id}`} x1="0" y1="0" x2="1" y2="1">
          <stop offset="0%" stopColor={shade(caseColor, 12)} />
          <stop offset="45%" stopColor={caseColor} />
          <stop offset="100%" stopColor={shade(caseColor, -18)} />
        </linearGradient>
        <linearGradient id={`brac-${watch.id}`} x1="0" y1="0" x2="1" y2="0">
          <stop offset="0%" stopColor={shade(braceletColor, -20)} />
          <stop offset="50%" stopColor={shade(braceletColor, 8)} />
          <stop offset="100%" stopColor={shade(braceletColor, -20)} />
        </linearGradient>
        <radialGradient id={`bezel-${watch.id}`} cx="50%" cy="40%" r="60%">
          <stop offset="0%" stopColor={shade(caseColor, 14)} />
          <stop offset="100%" stopColor={shade(caseColor, -22)} />
        </radialGradient>
      </defs>

      {/* Upper bracelet */}
      <g opacity="0.95">
        {[0,1,2].map(i => (
          <rect key={`u${i}`}
            x={110 + i * 0} y={20 + i * 12}
            width={80} height={10}
            fill={`url(#brac-${watch.id})`}
            stroke={shade(braceletColor, -30)} strokeWidth="0.4"
          />
        ))}
        <rect x="115" y="54" width="70" height="8" fill={`url(#brac-${watch.id})`} stroke={shade(braceletColor, -30)} strokeWidth="0.4" />
      </g>
      {/* Lower bracelet */}
      <g opacity="0.95">
        <rect x="115" y="238" width="70" height="8" fill={`url(#brac-${watch.id})`} stroke={shade(braceletColor, -30)} strokeWidth="0.4" />
        {[0,1,2].map(i => (
          <rect key={`l${i}`}
            x={110} y={252 + i * 12}
            width={80} height={10}
            fill={`url(#brac-${watch.id})`}
            stroke={shade(braceletColor, -30)} strokeWidth="0.4"
          />
        ))}
      </g>

      {/* Crown */}
      <rect x="237" y="143" width="8" height="14" fill={`url(#case-${watch.id})`} stroke={caseEdge} strokeWidth="0.6" />
      {type === "chrono" && (
        <>
          <rect x="237" y="125" width="6" height="6" fill={`url(#case-${watch.id})`} stroke={caseEdge} strokeWidth="0.5" />
          <rect x="237" y="168" width="6" height="6" fill={`url(#case-${watch.id})`} stroke={caseEdge} strokeWidth="0.5" />
        </>
      )}

      {/* Case */}
      <circle cx="150" cy="150" r="88" fill={`url(#case-${watch.id})`} stroke={caseEdge} strokeWidth="1.2" />

      {/* Bezel */}
      <circle cx="150" cy="150" r="84" fill={`url(#bezel-${watch.id})`} />
      {type === "diver" && (
        <g>
          {/* Diver bezel markers */}
          {Array.from({ length: 60 }).map((_, i) => {
            const a = (i / 60) * Math.PI * 2 - Math.PI / 2;
            const isMajor = i % 5 === 0;
            const r1 = isMajor ? 76 : 79;
            const r2 = 82;
            return (
              <line key={i}
                x1={150 + Math.cos(a) * r1} y1={150 + Math.sin(a) * r1}
                x2={150 + Math.cos(a) * r2} y2={150 + Math.sin(a) * r2}
                stroke={accent} strokeWidth={isMajor ? 1.6 : 0.6} opacity="0.85" strokeLinecap="round"
              />
            );
          })}
          {/* Pip */}
          <circle cx="150" cy="68" r="3" fill={lume} stroke={accent} strokeWidth="0.6" />
        </g>
      )}
      {type === "gmt" && (
        <g>
          {/* Two-tone GMT bezel ring */}
          <path d="M150 66 A 84 84 0 0 1 234 150" fill="none" stroke={accent} strokeWidth="8" strokeLinecap="round" opacity="0.85" />
          <path d="M234 150 A 84 84 0 0 1 150 234" fill="none" stroke={shade(accent, -30)} strokeWidth="8" strokeLinecap="round" opacity="0.85" />
          <path d="M150 234 A 84 84 0 0 1 66 150" fill="none" stroke={accent} strokeWidth="8" strokeLinecap="round" opacity="0.85" />
          <path d="M66 150 A 84 84 0 0 1 150 66" fill="none" stroke={shade(accent, -30)} strokeWidth="8" strokeLinecap="round" opacity="0.85" />
          {Array.from({ length: 24 }).map((_, i) => {
            const a = (i / 24) * Math.PI * 2 - Math.PI / 2;
            return (
              <text key={i}
                x={150 + Math.cos(a) * 72} y={150 + Math.sin(a) * 72 + 2}
                textAnchor="middle"
                fontSize="5" fontFamily="Inter, sans-serif" fontWeight="600"
                fill="#fff" opacity="0.95"
              >
                {i === 0 ? "24" : i * (24/24) === i ? (i).toString().padStart(2,"0") : ""}
              </text>
            );
          })}
        </g>
      )}
      {type === "dress" && (
        <g>
          {/* Fluted bezel */}
          {Array.from({ length: 72 }).map((_, i) => {
            const a = (i / 72) * Math.PI * 2;
            return (
              <line key={i}
                x1={150 + Math.cos(a) * 78} y1={150 + Math.sin(a) * 78}
                x2={150 + Math.cos(a) * 83} y2={150 + Math.sin(a) * 83}
                stroke={shade(caseColor, -30)} strokeWidth="0.7" opacity="0.6"
              />
            );
          })}
        </g>
      )}
      {type === "chrono" && (
        <g>
          {/* Tachy bezel */}
          <circle cx="150" cy="150" r="80" fill="none" stroke={shade(caseColor, -30)} strokeWidth="0.5" />
          {Array.from({ length: 60 }).map((_, i) => {
            const a = (i / 60) * Math.PI * 2 - Math.PI / 2;
            const isMajor = i % 5 === 0;
            return (
              <line key={i}
                x1={150 + Math.cos(a) * (isMajor ? 76 : 78)} y1={150 + Math.sin(a) * (isMajor ? 76 : 78)}
                x2={150 + Math.cos(a) * 82} y2={150 + Math.sin(a) * 82}
                stroke={dialTxt} strokeWidth={isMajor ? 1.2 : 0.4} opacity="0.65"
              />
            );
          })}
        </g>
      )}

      {/* Dial */}
      <circle cx="150" cy="150" r="72" fill={`url(#dial-${watch.id})`} />

      {/* Dial markers */}
      {Array.from({ length: 12 }).map((_, i) => {
        const a = (i / 12) * Math.PI * 2 - Math.PI / 2;
        const x1 = 150 + Math.cos(a) * 62;
        const y1 = 150 + Math.sin(a) * 62;
        const x2 = 150 + Math.cos(a) * 68;
        const y2 = 150 + Math.sin(a) * 68;
        if (type === "dress" && (i === 0 || i === 3 || i === 6 || i === 9)) {
          // Roman numerals for dress
          const nums = { 0: "XII", 3: "III", 6: "VI", 9: "IX" };
          return (
            <text key={i}
              x={150 + Math.cos(a) * 58} y={150 + Math.sin(a) * 58 + 3}
              textAnchor="middle"
              fontSize="8" fontFamily="Cormorant Garamond, serif"
              fill={dialTxt} fontWeight="500"
            >
              {nums[i]}
            </text>
          );
        }
        return (
          <g key={i}>
            <line x1={x1} y1={y1} x2={x2} y2={y2}
              stroke={dialTxt} strokeWidth={i === 0 ? 3 : (i % 3 === 0 ? 2.4 : 1.8)} strokeLinecap="round" />
            {i !== 0 && type !== "dress" && (
              <circle cx={(x1+x2)/2} cy={(y1+y2)/2} r="1.5" fill={lume} />
            )}
          </g>
        );
      })}

      {/* Sub-dials for chrono */}
      {type === "chrono" && (
        <g opacity="0.9">
          <circle cx="150" cy="110" r="14" fill={shade(dialBg, -8)} stroke={dialTxt} strokeWidth="0.5" />
          <circle cx="122" cy="150" r="14" fill={shade(dialBg, -8)} stroke={dialTxt} strokeWidth="0.5" />
          <circle cx="178" cy="150" r="14" fill={shade(dialBg, -8)} stroke={dialTxt} strokeWidth="0.5" />
        </g>
      )}

      {/* Brand text */}
      <text x="150" y="128" textAnchor="middle"
        fontFamily="Cormorant Garamond, serif" fontSize="9" fontWeight="600"
        letterSpacing="1.2" fill={dialTxt}>
        GMR
      </text>
      <text x="150" y="138" textAnchor="middle"
        fontFamily="Inter, sans-serif" fontSize="4.4" fontWeight="400"
        letterSpacing="0.8" fill={dialTxt} opacity="0.75">
        {watch.brand.toUpperCase()}
      </text>

      {/* Date window (not for chrono/dress to vary) */}
      {type !== "chrono" && (
        <g>
          <rect x="194" y="145" width="14" height="10" fill="#fff" stroke={dialTxt} strokeWidth="0.4" />
          <text x="201" y="153" textAnchor="middle" fontSize="6" fontFamily="Inter, sans-serif" fontWeight="600" fill={dialTxt}>24</text>
        </g>
      )}

      {/* Hands */}
      <g>
        {/* Hour hand — pointing roughly 10:10 */}
        <line x1="150" y1="150" x2="118" y2="130" stroke={hands} strokeWidth="4.2" strokeLinecap="round" />
        {/* Minute hand */}
        <line x1="150" y1="150" x2="188" y2="110" stroke={hands} strokeWidth="3" strokeLinecap="round" />
        {/* Seconds — thin accent */}
        <line x1="150" y1="150" x2="150" y2="92" stroke={accent} strokeWidth="1" strokeLinecap="round" />
        {/* GMT hand */}
        {type === "gmt" && (
          <line x1="150" y1="150" x2="205" y2="155" stroke={accent} strokeWidth="1.6" strokeLinecap="round" />
        )}
        <circle cx="150" cy="150" r="3.2" fill={hands} />
        <circle cx="150" cy="150" r="1.2" fill={accent} />
      </g>
    </svg>
  );
};

// ---------- WATCH PLATE (card frame holding the illustration or real photo) ----------
const WatchPlate = ({ watch, large = false, label = true }) => {
  const { tone } = watch;
  const imageUrl = watch.image || watch.hero_image;
  const isPhoto = Boolean(imageUrl);

  return (
    <div
      style={{
        position: "relative",
        width: "100%",
        aspectRatio: large ? "4 / 5" : "1 / 1",
        background: isPhoto
          ? "#FFFFFF"
          : `radial-gradient(120% 100% at 50% 20%, ${shade(tone.bg, 8)} 0%, ${tone.bg} 55%, ${shade(tone.bg, -14)} 100%)`,
        overflow: "hidden",
        borderRadius: 2,
        border: isPhoto ? "1px solid var(--rule)" : "none",
      }}
    >
      {!isPhoto && (
        <>
          {/* Soft ground reflection */}
          <div style={{
            position: "absolute", left: 0, right: 0, bottom: "8%",
            height: "10%",
            background: `radial-gradient(ellipse at center, ${hexA("#000", 0.25)} 0%, transparent 60%)`,
            filter: "blur(6px)",
          }} />
          {/* Subtle ring accents */}
          <svg viewBox="0 0 100 100" preserveAspectRatio="xMidYMid meet" width="100%" height="100%"
               style={{ position: "absolute", inset: 0, opacity: 0.1 }}>
            <circle cx="50" cy="50" r="38" fill="none" stroke={tone.accent} strokeWidth="0.15" />
            <circle cx="50" cy="50" r="30" fill="none" stroke={tone.accent} strokeWidth="0.1" />
          </svg>
          <div style={{ position: "absolute", inset: "8%", display: "grid", placeItems: "center" }}>
            <div style={{ width: "92%", aspectRatio: "1" }}>
              <WatchArt watch={watch} />
            </div>
          </div>
        </>
      )}

      {isPhoto && (
        <img
          src={imageUrl}
          alt={`${watch.brand} ${watch.model}`}
          loading="lazy"
          style={{
            position: "absolute", inset: 0,
            width: "100%", height: "100%",
            objectFit: "contain",
            padding: large ? "5%" : "8%",
          }}
        />
      )}

      {label && !isPhoto && (
        <div style={{
          position: "absolute",
          left: 14, bottom: 12,
          fontFamily: "var(--mono)",
          fontSize: 9.5,
          letterSpacing: "0.14em",
          color: hexA(tone.accent, 0.85),
          textTransform: "uppercase"
        }}>
          {tone.label}
        </div>
      )}
    </div>
  );
};

// Util: lighten/darken hex
function shade(hex, pct) {
  const { r, g, b } = hexToRgb(hex);
  const f = pct < 0 ? 0 : 255;
  const p = Math.abs(pct) / 100;
  const t = (c) => Math.round((f - c) * p + c);
  return `rgb(${t(r)}, ${t(g)}, ${t(b)})`;
}
function hexA(hex, a) {
  const { r, g, b } = hexToRgb(hex);
  return `rgba(${r}, ${g}, ${b}, ${a})`;
}
function hexToRgb(hex) {
  const h = hex.replace("#", "");
  const n = parseInt(h.length === 3 ? h.split("").map(c => c + c).join("") : h, 16);
  return { r: (n >> 16) & 255, g: (n >> 8) & 255, b: n & 255 };
}

// ---------- BUTTONS ----------
const PrimaryButton = ({ children, onClick, icon, full, style, type = "button" }) => {
  const [hover, setHover] = React.useState(false);
  return (
    <button
      type={type}
      onClick={onClick}
      onMouseEnter={() => setHover(true)}
      onMouseLeave={() => setHover(false)}
      style={{
        width: full ? "100%" : "auto",
        padding: "14px 28px",
        background: hover ? "var(--green-hover)" : "var(--green)",
        color: "#fff",
        fontFamily: "var(--sans)",
        fontSize: 13,
        fontWeight: 500,
        letterSpacing: "0.16em",
        textTransform: "uppercase",
        borderRadius: 2,
        display: "inline-flex",
        alignItems: "center",
        justifyContent: "center",
        gap: 10,
        transition: "all .2s ease",
        boxShadow: hover ? "0 8px 22px -12px rgba(15,58,43,0.45)" : "0 4px 14px -10px rgba(15,58,43,0.3)",
        ...style
      }}
    >
      {icon}
      {children}
    </button>
  );
};

const GoldButton = ({ children, onClick, icon, full, style }) => {
  const [hover, setHover] = React.useState(false);
  return (
    <button
      onClick={onClick}
      onMouseEnter={() => setHover(true)}
      onMouseLeave={() => setHover(false)}
      style={{
        width: full ? "100%" : "auto",
        padding: "13px 28px",
        background: hover ? hexA("#A86137", 0.08) : "transparent",
        color: hover ? "var(--gold-deep)" : "var(--gold-deep)",
        border: `1px solid ${hover ? "var(--gold-deep)" : "var(--gold)"}`,
        fontFamily: "var(--sans)",
        fontSize: 13,
        fontWeight: 500,
        letterSpacing: "0.16em",
        textTransform: "uppercase",
        borderRadius: 2,
        display: "inline-flex",
        alignItems: "center",
        justifyContent: "center",
        gap: 10,
        transition: "all .2s ease",
        ...style
      }}
    >
      {icon}
      {children}
    </button>
  );
};

const GhostButton = ({ children, onClick, full, style, disabled }) => {
  const [hover, setHover] = React.useState(false);
  return (
    <button
      onClick={onClick}
      disabled={disabled}
      onMouseEnter={() => setHover(true)}
      onMouseLeave={() => setHover(false)}
      style={{
        width: full ? "100%" : "auto",
        padding: "13px 24px",
        opacity: disabled ? 0.55 : 1,
        cursor: disabled ? "not-allowed" : "pointer",
        background: hover && !disabled ? "#F4F2EF" : "transparent",
        color: "var(--ink)",
        border: `1px solid ${hover ? "#1F2630" : "#D9D6CF"}`,
        fontFamily: "var(--sans)",
        fontSize: 13,
        fontWeight: 500,
        letterSpacing: "0.12em",
        textTransform: "uppercase",
        borderRadius: 2,
        transition: "all .2s ease",
        ...style
      }}
    >
      {children}
    </button>
  );
};

// Instagram icon — inline SVG, no external icon dependency.
const IconInstagram = ({ size = 18, color = "currentColor" }) => (
  <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke={color}
       strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">
    <rect x="2.5" y="2.5" width="19" height="19" rx="5" />
    <circle cx="12" cy="12" r="4.2" />
    <circle cx="17.6" cy="6.5" r="1" fill={color} stroke="none" />
  </svg>
);

// ---------- HEADER ----------
const Header = ({ onNav, page, onMobileMenu }) => {
  const [scrolled, setScrolled] = React.useState(false);
  React.useEffect(() => {
    const s = () => setScrolled(window.scrollY > 10);
    s();
    window.addEventListener("scroll", s, { passive: true });
    return () => window.removeEventListener("scroll", s);
  }, []);
  return (
    <header
      style={{
        position: "sticky",
        top: 0,
        zIndex: 40,
        background: scrolled ? "rgba(255,255,255,0.94)" : "rgba(255,255,255,1)",
        borderBottom: `1px solid ${scrolled ? "var(--rule)" : "transparent"}`,
        backdropFilter: "blur(10px)",
        transition: "all .25s ease",
      }}
    >
      <div style={{
        maxWidth: 1440, margin: "0 auto",
        padding: "14px clamp(18px, 4vw, 44px)",
        display: "grid",
        gridTemplateColumns: "1fr auto 1fr",
        alignItems: "center",
        gap: 20,
      }}>
        <nav className="nav-left" style={{ display: "flex", gap: 22, alignItems: "center", fontSize: 12, letterSpacing: "0.08em" }}>
          <button onClick={() => onNav("shop")} style={{ color: (page === "shop" || page === "home" || page === "product") ? "var(--ink)" : "var(--muted)" }}>SHOP</button>
          <button onClick={() => onNav("accessories")} style={{ color: page === "accessories" ? "var(--ink)" : "var(--muted)" }}>ACCESSORIES</button>
          <button onClick={() => onNav("sell")} style={{ color: page === "sell" ? "var(--ink)" : "var(--muted)" }}>SELL</button>
          <button onClick={() => onNav("journal")} style={{ color: (page === "journal" || page === "article") ? "var(--ink)" : "var(--muted)" }}>JOURNAL</button>
          <button onClick={() => onNav("auth")} style={{ color: page === "auth" ? "var(--ink)" : "var(--muted)" }}>AUTHENTICATION</button>
          <button onClick={() => onNav("about")} style={{ color: page === "about" ? "var(--ink)" : "var(--muted)" }}>ABOUT</button>
        </nav>

        <button onClick={() => onNav("home")} style={{ display: "flex", alignItems: "center", gap: 10 }}>
          <img src="/assets/01_Brytez_Lockup_Navy-Oscuro.svg" alt="Brytez" style={{ width: 160, maxWidth: "32vw", height: "auto", display: "block" }} />
        </button>

        <div style={{ display: "flex", gap: 18, alignItems: "center", justifyContent: "flex-end", color: "var(--muted)" }}>
          {GMR.phoneTel && <a href={`tel:${GMR.phoneTel}`} className="hide-m mono" style={{ fontSize: 12, letterSpacing: "0.02em", color: "var(--ink)", whiteSpace: "nowrap" }}>{GMR.phone}</a>}
          {GMR.whatsapp && <a href={waLink()} target="_blank" rel="noopener noreferrer" className="hide-m" aria-label="Chat on WhatsApp" style={{ color: "var(--whatsapp)", display: "inline-flex" }}><IconWhatsApp size={18} /></a>}
          <a href={mailLink()} className="hide-m" aria-label="Email us" style={{ display: "inline-flex" }}><IconMail size={18} /></a>
          {GMR.instagram && <a href={GMR.instagram} target="_blank" rel="noopener noreferrer" aria-label="Brytez on Instagram" style={{ display: "inline-flex", color: "var(--ink)" }}><IconInstagram size={18} /></a>}
          <button className="show-m" aria-label="Menu" onClick={onMobileMenu}><IconMenu size={20} /></button>
        </div>
      </div>

      <style>{`
        @media (max-width: 820px) {
          .nav-left { display: none !important; }
          .hide-m { display: none !important; }
          header > div { grid-template-columns: auto 1fr auto !important; }
          header > div > button:nth-child(2) { justify-self: center; }
          .wordmark { font-size: 16px !important; }
        }
        @media (min-width: 821px) {
          .show-m { display: none !important; }
        }
      `}</style>
    </header>
  );
};

// Brytez emblem using the official brand SVG on light and dark backgrounds.
const Monogram = ({ size = 28, tone = "green" }) => (
  <img src={tone === "cream" ? "/assets/05_Brytez_Lockup_Beige.svg" : "/assets/01_Brytez_Lockup_Navy-Oscuro.svg"}
       alt="Brytez" style={{ width: size * 2.8, height: "auto", maxWidth: "100%", display: "inline-block", verticalAlign: "middle" }} />
);

// ---------- FOOTER ----------
// Shared style so footer nav "links" (now real buttons) keep the anchor look.
const FOOTER_LINK_STYLE = {
  color: "inherit", fontSize: 13, textAlign: "left",
  padding: 0, cursor: "pointer", fontFamily: "inherit", letterSpacing: "inherit",
};
const Footer = ({ onNav, onInquire }) => (
  <footer style={{ background: "#131620", color: "#C9C5BD", marginTop: 80, paddingTop: 72 }}>
    <div style={{ maxWidth: 1440, margin: "0 auto", padding: "0 clamp(18px, 4vw, 44px)" }}>
      <div style={{ display: "grid", gridTemplateColumns: "repeat(auto-fit, minmax(200px, 1fr))", gap: 48, paddingBottom: 56 }}>
        <div>
          <div style={{ display: "flex", alignItems: "center", gap: 10, marginBottom: 18 }}>
            <img src="/assets/05_Brytez_Lockup_Beige.svg" alt="Brytez" style={{ width: 168, height: "auto" }} />
          </div>
          <p style={{ fontSize: 13, lineHeight: 1.7, color: "#9A948A", maxWidth: 300 }}>
            A Miami-based dealer of pre-owned and unworn luxury timepieces — Rolex, Patek Philippe and Audemars Piguet. Every watch verified before it reaches you.
          </p>
          <div style={{ marginTop: 22, display: "grid", gap: 9, fontSize: 13 }}>
            {GMR.whatsapp && <a href={waLink()} target="_blank" rel="noopener noreferrer" style={{ color: "#EDE9E0", display: "inline-flex", alignItems: "center", gap: 8 }}>
              <IconWhatsApp size={15} color="#25D366" /> {GMR.phone}
            </a>}
            <a href={mailLink()} style={{ color: "#C9C5BD", display: "inline-flex", alignItems: "center", gap: 8 }}>
              <IconMail size={15} /> {GMR.email}
            </a>
          </div>
          <div style={{ display: "flex", gap: 14, marginTop: 20, color: "#9A948A" }}>
            
            <a href={mailLink()} aria-label="Mail"><IconMail size={18} /></a>
            {GMR.phoneTel && <a href={`tel:${GMR.phoneTel}`} aria-label="Phone"><IconPhone size={18} /></a>}
            {GMR.instagram && <a href={GMR.instagram} target="_blank" rel="noopener noreferrer" aria-label="Brytez on Instagram" style={{ display: "inline-flex" }}><IconInstagram size={18} /></a>}
          </div>
        </div>

        <div>
          <div className="eyebrow" style={{ color: "#A86137", marginBottom: 18 }}>Services</div>
          <ul style={{ listStyle: "none", padding: 0, margin: 0, display: "grid", gap: 10, fontSize: 13 }}>
            <li><button onClick={() => onNav && onNav("sell")} style={FOOTER_LINK_STYLE}>Sell Your Watch</button></li>
            <li><button onClick={() => onNav && onNav("sell")} style={FOOTER_LINK_STYLE}>Trade-In Program</button></li>
            <li><button onClick={() => onNav && onNav("auth")} style={FOOTER_LINK_STYLE}>Authentication</button></li>
            <li><button onClick={() => onInquire && onInquire(null)} style={FOOTER_LINK_STYLE}>Sourcing Requests</button></li>
            <li><button onClick={() => onNav && onNav("accessories")} style={FOOTER_LINK_STYLE}>Accessories</button></li>
          </ul>
        </div>

        <div>
          <div className="eyebrow" style={{ color: "#A86137", marginBottom: 18 }}>{GMR.instagramHandle}</div>
          <div style={{ display: "grid", gridTemplateColumns: "repeat(3, 1fr)", gap: 4 }}>
            {WATCHES.slice(0, 6).map((w, i) => (
              <div key={i} style={{ aspectRatio: "1", overflow: "hidden" }}>
                <WatchPlate watch={w} label={false} />
              </div>
            ))}
          </div>
          
        </div>
      </div>

      <div style={{
        borderTop: "1px solid #222220",
        padding: "24px 0 4px",
        fontSize: 11,
        lineHeight: 1.7,
        color: "#6F6A62",
        maxWidth: 960,
      }}>
        Brytez specializes in the retail of premium Swiss watches. It is important to clarify that we are not an authorized dealer for Audemars Piguet, Breitling, Cartier, IWC, Omega, Patek Philippe, Rolex, Tudor, or any other watch or jewelry brands. These brands maintain their trademark rights and are not affiliated with Brytez. Any warranties provided for our products are exclusively through Brytez, not the original manufacturers. Please be aware that the original manufacturer's warranty may not be applicable to watches purchased from Brytez. We operate as an independent entity and are not endorsed or associated with any watch or jewelry manufacturer or their subsidiaries.
      </div>

      <div style={{
        borderTop: "1px solid #222220",
        padding: "24px 0",
        display: "flex",
        flexWrap: "wrap",
        gap: 18,
        justifyContent: "space-between",
        alignItems: "center",
        fontSize: 12,
        color: "#6F6A62",
      }}>
        <div>© 2026 Brytez · Miami, FL</div>
        <div style={{ display: "flex", gap: 20 }}>
          <button onClick={() => onNav && onNav("privacy")} style={{ color: "inherit", fontSize: 12 }}>Privacy</button>
          <button onClick={() => onNav && onNav("terms")} style={{ color: "inherit", fontSize: 12 }}>Terms</button>
        </div>
      </div>
    </div>
  </footer>
);

// ---------- WHATSAPP FLOATING ----------
const WhatsAppFloat = ({ onClick }) => {
  const [hover, setHover] = React.useState(false);
  return (
    <button
      onClick={onClick}
      onMouseEnter={() => setHover(true)}
      onMouseLeave={() => setHover(false)}
      aria-label="Chat on WhatsApp"
      style={{
        position: "fixed",
        right: 20,
        bottom: 20,
        zIndex: 50,
        width: 58, height: 58,
        borderRadius: "50%",
        background: "var(--whatsapp)",
        color: "#fff",
        display: "grid",
        placeItems: "center",
        boxShadow: hover
          ? "0 16px 36px -10px rgba(37,211,102,0.55)"
          : "0 10px 24px -10px rgba(0,0,0,0.25)",
        transform: hover ? "translateY(-2px)" : "translateY(0)",
        transition: "all .22s ease",
      }}
    >
      <IconWhatsApp size={28} color="#fff" />
    </button>
  );
};

// ---------- INQUIRY MODAL ----------
// `lead` lets a caller (e.g. the sell wizard) carry its own collected data
// through to the email: { kind, details: [[label, value]], prefill, message }.
const InquiryModal = ({ watch, lead, onClose }) => {
  const [stage, setStage] = React.useState("form"); // form | sent
  const [name, setName] = React.useState(lead?.prefill?.name || "");
  const [contact, setContact] = React.useState(lead?.prefill?.contact || "");
  const [company, setCompany] = React.useState(""); // honeypot — humans never see it
  const [sending, setSending] = React.useState(false);
  const [msg, setMsg] = React.useState(
    lead?.message ||
    (watch
      ? `Hi Brytez team — I'd like to know more about the ${watch.brand} ${watch.model}. Is it still available?`
      : "Hi Brytez team — I'd like to speak with an expert.")
  );

  const subject = watch
    ? `Inquiry — ${watch.brand} ${watch.model}`
    : lead?.kind === "sell" ? "Sell request" : "Brytez Inquiry";

  const payload = () => ({
    kind: lead?.kind || "inquiry",
    name,
    contact,
    company,
    message: msg,
    watch: watch ? `${watch.brand} ${watch.model}` : lead?.watch || "",
    details: lead?.details || [],
  });

  React.useEffect(() => {
    document.body.style.overflow = "hidden";
    return () => { document.body.style.overflow = ""; };
  }, []);

  return (
    <div
      role="dialog"
      aria-modal="true"
      style={{
        position: "fixed", inset: 0, zIndex: 80,
        background: "rgba(15,15,14,0.55)",
        display: "grid", placeItems: "center",
        padding: 20,
        animation: "fadeIn .2s ease",
      }}
      onClick={onClose}
    >
      <style>{`
        @keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }
        @keyframes slideUp { from { opacity: 0; transform: translateY(14px) } to { opacity: 1; transform: translateY(0) } }
      `}</style>
      <div
        onClick={(e) => e.stopPropagation()}
        style={{
          width: "100%",
          maxWidth: 520,
          background: "#fff",
          padding: "clamp(26px, 4vw, 44px)",
          borderRadius: 3,
          position: "relative",
          animation: "slideUp .28s ease",
        }}
      >
        <button onClick={onClose} aria-label="Close" style={{ position: "absolute", top: 16, right: 16, color: "var(--muted)" }}>
          <IconClose size={20} />
        </button>

        {stage === "form" && (
          <>
            <div className="eyebrow" style={{ color: "var(--gold-deep)" }}>Private Inquiry</div>
            <span className="gold-rule" />
            <h2 className="serif" style={{ fontSize: 28, lineHeight: 1.15, margin: "4px 0 6px", color: "var(--ink)" }}>
              Speak with a Brytez specialist
            </h2>
            <p style={{ color: "var(--muted)", fontSize: 14, marginTop: 0 }}>
              We reply within the hour, Mon–Fri 9am–7pm ET. No account required — this is a human, not a form.
            </p>

            <div style={{ display: "grid", gap: 14, marginTop: 20 }}>
              <Field label="Your name" value={name} onChange={setName} placeholder="Marcus Thompson" />
              <Field label="Phone or email" value={contact} onChange={setContact} placeholder="Best phone or email to reach you" />
              <Field label="Message" value={msg} onChange={setMsg} textarea />
            </div>

            {/* Honeypot: off-screen, never announced, never tabbable. */}
            <input
              type="text" name="company" tabIndex={-1} autoComplete="off" aria-hidden="true"
              value={company} onChange={(e) => setCompany(e.target.value)}
              style={{ position: "absolute", left: "-9999px", width: 1, height: 1, opacity: 0 }}
            />

            <div style={{ display: "grid", gap: 10, marginTop: 22 }}>
              <PrimaryButton
                full
                icon={<IconWhatsApp size={18} color="#fff" />}
                onClick={() => {
                  const composed = [msg, name && `— ${name}`, contact].filter(Boolean).join("\n");
                  // Capture the lead server-side too — plenty of visitors open
                  // WhatsApp and never press send. Deliberately not awaited:
                  // the popup must open inside the click gesture.
                  sendLead(payload());
                  window.open(waLink(composed), "_blank", "noopener,noreferrer");
                  setStage("sent");
                }}
              >
                Send via WhatsApp
              </PrimaryButton>
              <GhostButton full disabled={sending} onClick={async () => {
                if (!name.trim() || !contact.trim() || !msg.trim()) {
  window.alert("Please enter your name, phone or email, and message.");
  return;
}
setSending(true);
                const result = await sendLead(payload());
                setSending(false);
                if (result.delivered) { setStage("sent"); return; }
                // Nothing went out — hand off to the visitor's own mail client
                // rather than pretending the message arrived.
                const composed = [msg, name && `— ${name}`, contact].filter(Boolean).join("\n");
                window.location.href = mailLink(subject, composed);
                setStage("sent");
              }}>{sending ? "Sending…" : "Send by email instead"}</GhostButton>
            </div>

            <p style={{ color: "var(--muted)", fontSize: 11, marginTop: 18, textAlign: "center", letterSpacing: "0.06em" }}>
              🔒  All conversations are confidential
            </p>
          </>
        )}

        {stage === "sent" && (
          <div style={{ textAlign: "center", padding: "12px 0" }}>
            <div style={{
              width: 64, height: 64, margin: "0 auto 18px",
              borderRadius: "50%",
              background: hexA("#212A3D", 0.08),
              color: "var(--green)",
              display: "grid", placeItems: "center",
            }}>
              <IconShield size={28} />
            </div>
            <div className="eyebrow" style={{ color: "var(--gold-deep)" }}>Message sent</div>
            <span className="gold-rule" style={{ margin: "10px auto" }} />
            <h2 className="serif" style={{ fontSize: 26, color: "var(--ink)", margin: "4px 0 8px" }}>
              Thank you. We'll be in touch.
            </h2>
            <p style={{ color: "var(--muted)", fontSize: 14, maxWidth: 360, margin: "0 auto" }}>
              Your message has been received. The Brytez team will follow up as soon as possible.
            </p>
            <div style={{ marginTop: 22 }}>
              <GhostButton onClick={onClose}>Close</GhostButton>
            </div>
          </div>
        )}
      </div>
    </div>
  );
};

const Field = ({ label, value, onChange, placeholder, textarea }) => {
  const [focus, setFocus] = React.useState(false);
  const Tag = textarea ? "textarea" : "input";
  return (
    <label style={{ display: "grid", gap: 6 }}>
      <span style={{ fontSize: 11, letterSpacing: "0.14em", textTransform: "uppercase", color: "var(--muted)" }}>{label}</span>
      <Tag
        value={value}
        onChange={(e) => onChange(e.target.value)}
        placeholder={placeholder}
        onFocus={() => setFocus(true)}
        onBlur={() => setFocus(false)}
        rows={textarea ? 4 : undefined}
        style={{
          border: "none",
          borderBottom: `1px solid ${focus ? "var(--green)" : "var(--rule)"}`,
          background: "transparent",
          padding: "10px 2px",
          fontFamily: "var(--sans)",
          fontSize: 14,
          color: "var(--ink)",
          outline: "none",
          resize: "vertical",
          transition: "border-color .15s ease",
        }}
      />
    </label>
  );
};

Object.assign(window, {
  GMR, waLink, mailLink,
  WATCHES, usd,
  WatchPlate, PrimaryButton, GoldButton, GhostButton,
  Header, Footer, Monogram, WhatsAppFloat, IconInstagram,
  InquiryModal, Field, hexA, shade,
});
