// ---------- AUTHENTICATION PAGE ----------
const AuthenticationPage = ({ onHome, onInquire }) => {
  React.useEffect(() => { window.scrollTo(0, 0); }, []);

  const checkpoints = [
    { n: "01", t: "Sourced from vetted dealers", b: "Every piece comes through an established dealer network we buy from directly — not anonymous marketplaces or auction lots." },
    { n: "02", t: "Serial & reference check", b: "Serial and reference numbers are checked against the supplying dealer's records before we confirm a single price. What we quote is what you pay." },
    { n: "03", t: "Documentation review", b: "Original papers, cards and service records are reviewed piece by piece. What exists is disclosed — and what's missing is disclosed too." },
    { n: "04", t: "See it before you commit", b: "High-resolution photos and a live video call of the exact watch, on request, before any money moves. Ask anything; we answer personally." },
  ];

  return (
    <main>
      {/* Hero */}
      <section style={{
        background: "#212A3D", color: "#F4F2EF",
        padding: "clamp(60px, 8vw, 112px) clamp(18px, 4vw, 44px)",
        position: "relative", overflow: "hidden",
      }}>
        <svg viewBox="0 0 100 100" preserveAspectRatio="none" width="700" height="700" style={{
          position: "absolute", right: -240, top: -180, opacity: 0.06, pointerEvents: "none",
        }}>
          <circle cx="50" cy="50" r="48" fill="none" stroke="#A86137" strokeWidth="0.2" />
          <circle cx="50" cy="50" r="36" fill="none" stroke="#A86137" strokeWidth="0.2" />
          <circle cx="50" cy="50" r="24" fill="none" stroke="#A86137" strokeWidth="0.2" />
        </svg>
        <div style={{ maxWidth: 1200, margin: "0 auto", position: "relative" }}>
          <button onClick={onHome} style={{ fontSize: 12, color: "#9A948A", letterSpacing: "0.14em", textTransform: "uppercase", marginBottom: 24 }}>
            ← Back to home
          </button>
          <div style={{
            display: "grid", gridTemplateColumns: "minmax(0,1.2fr) minmax(0,1fr)",
            gap: "clamp(28px, 4vw, 72px)", alignItems: "end",
          }} className="auth-hero-grid">
            <div>
              <div className="eyebrow" style={{ color: "#A86137" }}>Authentication Service</div>
              <span className="gold-rule" />
              <h1 className="serif" style={{
                fontSize: "clamp(40px, 5.4vw, 72px)", lineHeight: 1.02,
                margin: "8px 0 20px", color: "#F4F2EF", fontWeight: 500, letterSpacing: "-0.01em", textWrap: "balance",
              }}>
                Verified,<br/>
                <em style={{ color: "#A86137", fontStyle: "italic" }}>before it's yours.</em>
              </h1>
              <p style={{ color: "#B8B2A6", fontSize: 17, lineHeight: 1.65, maxWidth: 520, textWrap: "pretty" }}>
                Every watch we source is checked and documented before it ever reaches you. Nothing is confirmed — and no price is final — until we've verified the piece. You see everything, then you decide.
              </p>
            </div>
            <div>
              <div style={{
                background: "rgba(255,255,255,0.04)",
                border: "1px solid rgba(201,169,110,0.25)",
                padding: "24px 26px",
              }}>
                <div className="eyebrow" style={{ color: "#A86137" }}>Included with every Brytez watch</div>
                <span className="gold-rule" style={{ margin: "12px 0" }} />
                <div style={{ display: "grid", gap: 14, marginTop: 14 }}>
                  {[
                    ["Verification", "Every sale"],
                    ["Documentation", "Reviewed & disclosed"],
                    ["Delivery", "Arranged personally"],
                    ["Your contact", "Brytez team"],
                  ].map(([k, v]) => (
                    <div key={k} style={{ display: "flex", justifyContent: "space-between", gap: 20, fontSize: 14, paddingBottom: 10, borderBottom: "1px solid rgba(201,169,110,0.15)" }}>
                      <span style={{ color: "#9A948A", letterSpacing: "0.1em", textTransform: "uppercase", fontSize: 11 }}>{k}</span>
                      <span style={{ color: "#F4F2EF" }}>{v}</span>
                    </div>
                  ))}
                </div>
                <button
                  onClick={() => onInquire(null)}
                  style={{
                    width: "100%", marginTop: 18,
                    background: "#A86137", color: "#212A3D",
                    padding: "14px 22px", fontSize: 13,
                    letterSpacing: "0.16em", textTransform: "uppercase", fontWeight: 500,
                  }}
                >Contact Brytez</button>
              </div>
            </div>
          </div>
        </div>
        <style>{`@media (max-width: 900px) { .auth-hero-grid { grid-template-columns: 1fr !important; } }`}</style>
      </section>

      {/* 6 checkpoints */}
      <section style={{ padding: "clamp(60px, 8vw, 104px) clamp(18px, 4vw, 44px)" }}>
        <div style={{ maxWidth: 1200, margin: "0 auto" }}>
          <div style={{ textAlign: "center", marginBottom: 64 }}>
            <div className="eyebrow" style={{ color: "var(--gold-deep)" }}>The Process</div>
            <span className="gold-rule" style={{ margin: "14px auto" }} />
            <h2 className="serif" style={{ fontSize: "clamp(30px, 3.4vw, 46px)", margin: "6px 0 0", color: "var(--ink)", lineHeight: 1.1 }}>
              What Brytez verification actually covers.
            </h2>
          </div>
          <div style={{
            display: "grid", gridTemplateColumns: "repeat(auto-fit, minmax(280px, 1fr))",
            gap: "clamp(24px, 2.6vw, 48px)",
          }}>
            {checkpoints.map(c => (
              <div key={c.n} style={{ borderTop: "1px solid var(--gold)", paddingTop: 24 }}>
                <div className="serif" style={{ fontSize: 40, fontStyle: "italic", color: hexA("#A86137", 0.55), lineHeight: 1 }}>{c.n}</div>
                <h3 className="serif" style={{ fontSize: 22, color: "var(--ink)", fontWeight: 500, margin: "14px 0 10px" }}>{c.t}</h3>
                <p style={{ fontSize: 14, color: "var(--text)", lineHeight: 1.65, margin: 0, textWrap: "pretty" }}>{c.b}</p>
              </div>
            ))}
          </div>
        </div>
      </section>

      {/* Certificate preview */}
      <section style={{ padding: "clamp(60px, 8vw, 104px) clamp(18px, 4vw, 44px)", background: "var(--paper)" }}>
        <div style={{
          maxWidth: 1100, margin: "0 auto",
          display: "grid", gridTemplateColumns: "minmax(0,1fr) minmax(0,1fr)",
          gap: "clamp(32px, 4vw, 72px)", alignItems: "center",
        }} className="cert-grid">
          <div>
            <div className="eyebrow" style={{ color: "var(--gold-deep)" }}>Certificate of Authenticity</div>
            <span className="gold-rule" />
            <h2 className="serif" style={{
              fontSize: "clamp(28px, 3vw, 40px)", lineHeight: 1.1,
              margin: "8px 0 18px", color: "var(--ink)", fontWeight: 500, textWrap: "balance",
            }}>
              A register of where your watch has been.
            </h2>
            <p style={{ fontSize: 15, color: "var(--text)", lineHeight: 1.7, marginBottom: 20, textWrap: "pretty" }}>
              Every piece is verified before it reaches you, and arrives with its documentation reviewed and disclosed — reference, serial and condition, exactly as confirmed with you on WhatsApp. What we quote is what you pay.
            </p>
          </div>
          {/* Certificate card mock */}
          <div style={{
            background: "#FFFDF8",
            border: "1px solid var(--rule)",
            padding: "clamp(28px, 3vw, 44px)",
            position: "relative",
            boxShadow: "0 30px 60px -36px rgba(15,58,43,0.28)",
          }}>
            <div style={{ position: "absolute", inset: 12, border: "1px solid var(--gold)", pointerEvents: "none" }} />
            <div style={{ textAlign: "center", padding: "10px 4px" }}>
              <Monogram size={56} />
              <div style={{ fontFamily: "var(--serif)", fontSize: 11, letterSpacing: "0.3em", color: "var(--gold-deep)", marginTop: 8 }}>
                BRYTEZ · MIAMI
              </div>
              <div style={{ height: 1, background: "var(--gold)", margin: "18px auto", width: 60 }} />
              <div className="serif" style={{ fontSize: 22, color: "var(--ink)", fontStyle: "italic", marginBottom: 6, fontWeight: 400 }}>
                Certificate of Authenticity
              </div>
              <div style={{ fontFamily: "var(--mono)", fontSize: 10, letterSpacing: "0.2em", color: "var(--muted)", textTransform: "uppercase" }}>
                Recorded with every sale
              </div>

              <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: 14, marginTop: 26, textAlign: "left" }}>
                {[
                  ["Piece", "Make & model"],
                  ["Reference", "Factory reference"],
                  ["Serial", "Checked & recorded"],
                  ["Condition", "As verified"],
                  ["Documents", "Reviewed & disclosed"],
                  ["Confirmed by", "Brytez"],
                ].map(([k, v]) => (
                  <div key={k}>
                    <div style={{ fontSize: 9, letterSpacing: "0.18em", color: "var(--muted)", textTransform: "uppercase" }}>{k}</div>
                    <div style={{ fontSize: 13, color: "var(--ink)", marginTop: 2, fontFamily: "var(--serif)" }}>{v}</div>
                  </div>
                ))}
              </div>

              <div className="serif" style={{
                fontStyle: "italic", fontSize: 18, color: "var(--green)",
                borderTop: "1px solid var(--rule)", marginTop: 24, paddingTop: 14,
              }}>
                Brytez
              </div>
              <div style={{ fontSize: 10, letterSpacing: "0.18em", textTransform: "uppercase", color: "var(--muted)", marginTop: 2 }}>
                Verified &amp; documented · Miami
              </div>
            </div>
          </div>
        </div>
        <style>{`@media (max-width: 820px) { .cert-grid { grid-template-columns: 1fr !important; } }`}</style>
      </section>
    </main>
  );
};

// ---------- ABOUT / CONTACT PAGE ----------
const AboutPage = ({ onHome, onInquire }) => {
  React.useEffect(() => { window.scrollTo(0, 0); }, []);

  const founder = {
    name: "Gabriel",
    role: "Your direct contact · Miami",
    bio: "Gabriel began working in the luxury watch trade in New York’s Diamond District in 2020, before continuing in Miami across watch and diamond wholesale. At Brytez, he brings that hands-on market experience to a more personal way of buying, selling, and sourcing timepieces — working directly with each client from the first conversation to the final handover.",
  };

  return (
    <main>
      {/* Hero */}
      <section style={{ padding: "clamp(60px, 8vw, 112px) clamp(18px, 4vw, 44px)", borderBottom: "1px solid var(--rule)" }}>
        <div style={{ maxWidth: 1000, margin: "0 auto" }}>
          <button onClick={onHome} style={{ fontSize: 12, color: "var(--muted)", letterSpacing: "0.14em", textTransform: "uppercase", marginBottom: 24 }}>
            ← Back to home
          </button>
          <div className="eyebrow" style={{ color: "var(--gold-deep)" }}>About Brytez</div>
          <span className="gold-rule" />
          <h1 className="serif" style={{
            fontSize: "clamp(40px, 5.4vw, 72px)", lineHeight: 1.02,
            margin: "8px 0 24px", color: "var(--ink)", fontWeight: 500, letterSpacing: "-0.01em", textWrap: "balance",
          }}>
            A house built by collectors,<br/>
            <em style={{ color: "var(--green)", fontStyle: "italic" }}>for collectors.</em>
          </h1>
          <p style={{ fontSize: 18, color: "var(--text)", maxWidth: 680, lineHeight: 1.65, textWrap: "pretty" }}>
            Brytez is a Miami-based dealer with one job: get serious collectors the right watch — Rolex, Patek Philippe, Audemars Piguet — without the boutique waitlist, at a fair price quoted straight to you. Every piece is sourced on request, verified before delivery, and handed over personally.
          </p>
        </div>
      </section>

      {/* Values */}
      <section style={{ padding: "clamp(60px, 8vw, 104px) clamp(18px, 4vw, 44px)" }}>
        <div style={{ maxWidth: 1100, margin: "0 auto" }}>
          <div style={{
            display: "grid", gridTemplateColumns: "repeat(auto-fit, minmax(240px, 1fr))",
            gap: "clamp(28px, 3vw, 56px)",
          }}>
            {[
              ["Transparent", "What we know about a piece, you know — and what we don't know, we say so before you ask."],
              ["Patient", "We would rather not sell you a watch today than sell you the wrong one. Your specialist will say so."],
              ["Accountable", "Your watch arrives verified and documented. If anything is ever off, Contact the Brytez team directly."],
            ].map(([t, b]) => (
              <div key={t} style={{ borderTop: "1px solid var(--gold)", paddingTop: 20 }}>
                <h3 className="serif" style={{ fontSize: 26, color: "var(--ink)", fontWeight: 500, margin: "0 0 12px" }}>{t}</h3>
                <p style={{ fontSize: 14, color: "var(--text)", lineHeight: 1.65, margin: 0, textWrap: "pretty" }}>{b}</p>
              </div>
            ))}
          </div>
        </div>
      </section>

      {/* Team */}
      <section style={{ padding: "clamp(60px, 8vw, 104px) clamp(18px, 4vw, 44px)", background: "var(--paper)" }}>
        <div style={{ maxWidth: 1100, margin: "0 auto" }}>
          <div className="eyebrow" style={{ color: "var(--gold-deep)" }}>Who you're dealing with</div>
          <span className="gold-rule" />
          <h2 className="serif" style={{ fontSize: "clamp(28px, 3vw, 40px)", margin: "6px 0 48px", color: "var(--ink)", fontWeight: 500 }}>
            You deal directly with Gabriel.
          </h2>
          <div style={{
            display: "grid",
            gridTemplateColumns: "minmax(0, 220px) minmax(0, 1fr)",
            gap: "clamp(24px, 4vw, 56px)", alignItems: "center",
          }} className="founder-grid">
            <div style={{ maxWidth: 220, width: "100%" }}>
              <div style={{
                aspectRatio: "4 / 5",
                background: "linear-gradient(160deg, #E8E4DA, #C8C4B8)",
                position: "relative", overflow: "hidden",
              }}>
                <div style={{
                  position: "absolute", inset: 12, border: "1px solid rgba(201,169,110,0.4)",
                }} />
                <div style={{
                  position: "absolute", left: "50%", top: "50%", transform: "translate(-50%,-50%)",
                  fontFamily: "var(--serif)", fontSize: 54, color: "var(--green)", fontStyle: "italic",
                }}>G</div>
              </div>
            </div>
            <div>
              <div className="serif" style={{ fontSize: 27, color: "var(--ink)", fontWeight: 500 }}>{founder.name}</div>
              <div style={{ fontSize: 11, letterSpacing: "0.14em", textTransform: "uppercase", color: "var(--gold-deep)", marginTop: 6 }}>{founder.role}</div>
              <p style={{ fontSize: 15, color: "var(--text)", lineHeight: 1.75, margin: "18px 0 0", maxWidth: 620, textWrap: "pretty" }}>{founder.bio}</p>
            </div>
          </div>
          <style>{`@media (max-width: 600px) { .founder-grid { grid-template-columns: 1fr !important; } }`}</style>
        </div>
      </section>

      {/* Contact / Visit */}
      <section style={{ padding: "clamp(60px, 8vw, 104px) clamp(18px, 4vw, 44px)" }}>
        <div style={{
          maxWidth: 1100, margin: "0 auto",
          display: "grid", gridTemplateColumns: "minmax(0,1fr) minmax(0,1fr)",
          gap: "clamp(28px, 4vw, 72px)", alignItems: "start",
        }} className="contact-grid">
          <div>
            <div className="eyebrow" style={{ color: "var(--gold-deep)" }}>Based in Miami</div>
            <span className="gold-rule" />
            <h2 className="serif" style={{
              fontSize: "clamp(28px, 3vw, 40px)", lineHeight: 1.1,
              margin: "8px 0 18px", color: "var(--ink)", fontWeight: 500, textWrap: "balance",
            }}>
              By appointment only.
            </h2>
            <p style={{ fontSize: 15, color: "var(--text)", lineHeight: 1.65, marginBottom: 28, textWrap: "pretty" }}>
              We're based in Miami and see clients by appointment, Monday through Friday — for a private viewing, a second opinion on a piece you already own, or simply to talk watches. Message us on WhatsApp to set a time and we'll share the address.
            </p>

            <div style={{ display: "grid", gap: 22 }}>
              {[
                ...(GMR.whatsapp ? [[<IconWhatsApp size={18} />, GMR.phone, "WhatsApp", waLink()]] : []),
                ...(GMR.phoneTel ? [[<IconPhone size={18} />, GMR.phone, "Call or text", `tel:${GMR.phoneTel}`]] : []),
                [<IconMail size={18} />, GMR.email, "General & inquiries", mailLink()],
                [<IconShield size={18} />, "Verified before delivery", "Serial & documentation checked on every sale"],
              ].map((row, i) => {
                const st = {
                  display: "grid", gridTemplateColumns: "auto 1fr", gap: 16, alignItems: "start",
                  paddingBottom: 18, borderBottom: i < 3 ? "1px solid var(--rule)" : "none",
                };
                const inner = (
                  <>
                    <span style={{ color: "var(--green)", marginTop: 2 }}>{row[0]}</span>
                    <div>
                      <div style={{ fontSize: 15, color: "var(--ink)", fontWeight: 500 }}>{row[1]}</div>
                      <div style={{ fontSize: 12, color: "var(--muted)", marginTop: 2, letterSpacing: "0.06em" }}>{row[2]}</div>
                    </div>
                  </>
                );
                return row[3]
                  ? <a key={i} href={row[3]} target={row[3].startsWith("http") ? "_blank" : undefined} rel="noopener noreferrer" style={{ ...st, color: "inherit" }}>{inner}</a>
                  : <div key={i} style={st}>{inner}</div>;
              })}
            </div>
          </div>

          {/* No map: we don't publish a street address. It goes out when the appointment is set. */}
          <div style={{
            aspectRatio: "1 / 1",
            background: `
              linear-gradient(160deg, #F2EDE0 0%, #E5DDCA 100%)
            `,
            position: "relative", overflow: "hidden",
            display: "grid", placeItems: "center", textAlign: "center",
          }}>
            <div style={{
              position: "absolute", inset: "clamp(14px, 3%, 22px)",
              border: "1px solid var(--gold)", opacity: 0.45, pointerEvents: "none",
            }} />
            <div style={{ position: "relative", padding: "clamp(20px, 6%, 44px)" }}>
              <div className="eyebrow" style={{ color: "var(--gold-deep)" }}>Where we meet</div>
              <span className="gold-rule" style={{ margin: "14px auto" }} />
              <div className="serif" style={{
                fontSize: "clamp(28px, 4.2vw, 44px)", color: "var(--ink)",
                lineHeight: 1.1, fontWeight: 500, margin: "6px 0 12px",
              }}>
                Miami, Florida
              </div>
              <div style={{ fontSize: 14, color: "var(--text)", lineHeight: 1.6, maxWidth: 300, margin: "0 auto", textWrap: "pretty" }}>
                By appointment, Monday through Friday.
              </div>
              <div style={{
                marginTop: 30, paddingTop: 18,
                borderTop: `1px solid ${hexA("#A86137", 0.45)}`,
                maxWidth: 300, marginLeft: "auto", marginRight: "auto",
                fontFamily: "var(--mono)", fontSize: 10,
                letterSpacing: "0.16em", textTransform: "uppercase",
                color: "var(--gold-deep)", opacity: 0.8, lineHeight: 1.8,
              }}>Address shared once your appointment is confirmed</div>
            </div>
          </div>
        </div>
        <style>{`@media (max-width: 820px) { .contact-grid { grid-template-columns: 1fr !important; } }`}</style>

        <div style={{ maxWidth: 1100, margin: "48px auto 0", textAlign: "center" }}>
          <div style={{ display: "flex", justifyContent: "center", alignItems: "center", gap: 12, flexWrap: "wrap" }}>
            <PrimaryButton icon={<IconWhatsApp size={18} color="#fff" />} onClick={() => onInquire(null)}>
              Book a private viewing
            </PrimaryButton>
            {GMR.instagram && <GoldButton icon={<IconInstagram size={18} />} onClick={() => window.open(GMR.instagram, "_blank", "noopener,noreferrer")}>
              Follow us on Instagram
            </GoldButton>}
          </div>
        </div>
      </section>
    </main>
  );
};

// ---------- SHOP / CATALOG PAGE ----------
const ShopPage = ({ onHome, onOpenWatch, onInquire, initialFilters }) => {
  const init = initialFilters || {};
  const [brandFilter, setBrandFilter] = React.useState(init.brand || "All");
  const [modelFilter, setModelFilter] = React.useState(init.model || "All");
  const [categoryFilter, setCategoryFilter] = React.useState(init.category || "All");
  const [search, setSearch] = React.useState(init.q || "");
  const [unwornOnly, setUnwornOnly] = React.useState(!!init.unworn);
  const [visibleCount, setVisibleCount] = React.useState(48);

  React.useEffect(() => { window.scrollTo(0, 0); }, []);

  // Ruta nueva (deep link o re-click en Shop): re-aplica los filtros de la URL.
  React.useEffect(() => {
    const f = initialFilters || {};
    setBrandFilter(f.brand || "All");
    setModelFilter(f.model || "All");
    setCategoryFilter(f.category || "All");
    setSearch(f.q || "");
    setUnwornOnly(!!f.unworn);
  }, [initialFilters]);

  // La URL refleja los filtros activos (link copiable). replaceState para no
  // ensuciar el historial con cada click; no dispara hashchange.
  React.useEffect(() => {
    const params = new URLSearchParams();
    if (categoryFilter !== "All") params.set("category", categoryFilter);
    if (brandFilter !== "All") params.set("brand", brandFilter);
    if (modelFilter !== "All") params.set("model", modelFilter);
    if (search.trim()) params.set("q", search.trim());
    if (unwornOnly) params.set("unworn", "1");
    const qs = params.toString();
    window.history.replaceState(null, "", qs ? `#/shop?${qs}` : "#/shop");
  }, [brandFilter, categoryFilter, modelFilter, unwornOnly, search]);

  // Al cambiar cualquier filtro o la búsqueda, volver al primer bloque.
  React.useEffect(() => { setVisibleCount(48); }, [brandFilter, categoryFilter, modelFilter, unwornOnly, search]);

  // Brands sorted by count (Rolex first since it's the biggest slice)
  const BRANDS = React.useMemo(() => {
    const counts = {};
    WATCHES.forEach(w => { if (w.brand) counts[w.brand] = (counts[w.brand] || 0) + 1; });
    const sorted = Object.entries(counts).sort((a, b) => b[1] - a[1]).map(([b]) => b);
    return ["All", ...sorted];
  }, [WATCHES.length]);

  // Categorías reales del catálogo, con su label del scraper.
  const CATEGORIES = React.useMemo(() => {
    const counts = {}, labels = {};
    WATCHES.forEach(w => {
      if (!w.category) return;
      counts[w.category] = (counts[w.category] || 0) + 1;
      labels[w.category] = w.category_label || w.category;
    });
    const order = ["sport", "dress", "gmt", "chrono", "diver", "other"];
    const ids = [...order.filter(c => counts[c]), ...Object.keys(counts).filter(c => !order.includes(c)).sort()];
    return [{ id: "All", label: "All" }, ...ids.map(id => ({ id, label: labels[id] }))];
  }, [WATCHES.length]);

  // Models for the selected brand (within the selected category)
  const MODELS = React.useMemo(() => {
    if (brandFilter === "All") return ["All"];
    const counts = {};
    WATCHES.forEach(w => {
      if (w.brand === brandFilter && (categoryFilter === "All" || w.category === categoryFilter) && w.model) {
        counts[w.model] = (counts[w.model] || 0) + 1;
      }
    });
    const sorted = Object.entries(counts).sort((a, b) => b[1] - a[1]).map(([m]) => m);
    return ["All", ...sorted];
  }, [brandFilter, categoryFilter, WATCHES.length]);

  let list = WATCHES.slice();
  if (brandFilter !== "All") list = list.filter(w => w.brand === brandFilter);
  if (categoryFilter !== "All") list = list.filter(w => w.category === categoryFilter);
  if (modelFilter !== "All") list = list.filter(w => w.model === modelFilter);
  if (unwornOnly) list = list.filter(w => w.condition === "Unworn");
  const q = search.trim().toLowerCase();
  if (q) list = list.filter(w => `${w.brand} ${w.model} ${w.reference} ${w.title || ""} ${w.id}`.toLowerCase().includes(q));
  // published_at: updated_at es el refresco masivo diario del proveedor y ordenaría al azar.
  list.sort((a,b) => (b.published_at || b.updated_at || "").localeCompare(a.published_at || a.updated_at || ""));

  return (
    <main>
      <section style={{ padding: "clamp(40px, 5vw, 72px) clamp(18px, 4vw, 44px) clamp(20px, 3vw, 36px)", borderBottom: "1px solid var(--rule)" }}>
        <div style={{ maxWidth: 1440, margin: "0 auto" }}>
          <button onClick={onHome} style={{ fontSize: 12, color: "var(--muted)", letterSpacing: "0.14em", textTransform: "uppercase", marginBottom: 20 }}>
            ← Back to home
          </button>
          <div className="eyebrow" style={{ color: "var(--gold-deep)" }}>The Collection</div>
          <span className="gold-rule" />
          <h1 className="serif" style={{
            fontSize: "clamp(36px, 4.6vw, 60px)", lineHeight: 1.05,
            margin: "8px 0 4px", color: "var(--ink)", fontWeight: 500, letterSpacing: "-0.01em",
          }}>
            All timepieces.
          </h1>
          <div style={{ fontSize: 14, color: "var(--muted)" }}>
            {list.length} of {WATCHES.length} pieces · updated daily
          </div>
          <div style={{ marginTop: 18, maxWidth: 440, position: "relative" }}>
            <span style={{ position: "absolute", left: 14, top: "50%", transform: "translateY(-50%)", color: "var(--muted)", display: "flex" }}>
              <IconSearch size={16} />
            </span>
            <input
              value={search}
              onChange={(e) => setSearch(e.target.value)}
              placeholder="Search brand, model or reference…"
              style={{
                width: "100%", padding: "12px 16px 12px 42px",
                border: "1px solid var(--rule)", background: "#fff",
                fontFamily: "var(--sans)", fontSize: 14, color: "var(--ink)",
                outline: "none",
              }}
              onFocus={(e) => { e.target.style.borderColor = "var(--green)"; }}
              onBlur={(e) => { e.target.style.borderColor = "var(--rule)"; }}
            />
          </div>
        </div>
      </section>

      {/* Barra de marcas: una sola línea, scrolleable en pantallas angostas */}
      <section style={{ padding: "16px clamp(18px, 4vw, 44px)", background: "var(--paper)", borderBottom: "1px solid var(--rule)", position: "sticky", top: 64, zIndex: 20 }}>
        <div className="brand-row" style={{
          maxWidth: 1440, margin: "0 auto",
          display: "flex", gap: 26, alignItems: "center",
          flexWrap: "nowrap", overflowX: "auto",
          WebkitOverflowScrolling: "touch",
          scrollbarWidth: "none",
        }}>
          {BRANDS.map(b => (
            <button key={b} onClick={() => { setBrandFilter(b); setModelFilter("All"); }} style={{
              fontSize: 12, letterSpacing: "0.14em", textTransform: "uppercase",
              color: brandFilter === b ? "var(--ink)" : "var(--muted)",
              borderBottom: `1px solid ${brandFilter === b ? "var(--gold)" : "transparent"}`,
              paddingBottom: 4, transition: "all .15s ease",
              whiteSpace: "nowrap", flex: "0 0 auto",
            }}>{b}</button>
          ))}
        </div>
        <style>{`.brand-row::-webkit-scrollbar { display: none; }`}</style>
      </section>

      {/* Price range + grid */}
      <section style={{ padding: "clamp(32px, 4vw, 56px) clamp(18px, 4vw, 44px) clamp(60px, 8vw, 104px)" }}>
        <div style={{
          maxWidth: 1440, margin: "0 auto",
          display: "grid", gridTemplateColumns: "220px 1fr", gap: "clamp(24px, 3vw, 48px)",
        }} className="shop-grid">
          {/* Sidebar */}
          <aside className="shop-side" style={{ position: "sticky", top: 140, alignSelf: "start" }}>
            <div style={{ marginBottom: 32 }}>
              <div className="eyebrow" style={{ color: "var(--muted)", marginBottom: 14 }}>Category</div>
              <div style={{ display: "grid", gap: 4 }}>
                {CATEGORIES.map(c => (
                  <button key={c.id} onClick={() => { setCategoryFilter(c.id); setModelFilter("All"); }} style={{
                    textAlign: "left",
                    fontSize: 13,
                    padding: "6px 0",
                    color: categoryFilter === c.id ? "var(--ink)" : "var(--muted)",
                    fontWeight: categoryFilter === c.id ? 500 : 400,
                    borderLeft: `2px solid ${categoryFilter === c.id ? "var(--gold)" : "transparent"}`,
                    paddingLeft: 10,
                    transition: "all .15s ease",
                  }}>{c.label}</button>
                ))}
              </div>
            </div>

            {brandFilter !== "All" && MODELS.length > 1 && (
              <div style={{ marginBottom: 32 }}>
                <div className="eyebrow" style={{ color: "var(--muted)", marginBottom: 14 }}>
                  {brandFilter} — Model
                </div>
                <div style={{ display: "grid", gap: 4 }}>
                  {MODELS.map(m => (
                    <button key={m} onClick={() => setModelFilter(m)} style={{
                      textAlign: "left",
                      fontSize: 13,
                      padding: "6px 0",
                      color: modelFilter === m ? "var(--ink)" : "var(--muted)",
                      fontWeight: modelFilter === m ? 500 : 400,
                      borderLeft: `2px solid ${modelFilter === m ? "var(--gold)" : "transparent"}`,
                      paddingLeft: 10,
                      transition: "all .15s ease",
                    }}>{m}</button>
                  ))}
                </div>
              </div>
            )}

            <div>
              <div className="eyebrow" style={{ color: "var(--muted)", marginBottom: 14 }}>Condition</div>
              <label style={{ display: "flex", alignItems: "center", gap: 10, padding: "8px 0", cursor: "pointer" }}>
                <input type="checkbox" checked={unwornOnly} onChange={(e) => setUnwornOnly(e.target.checked)}
                  style={{ accentColor: "var(--green)" }} />
                <span style={{ fontSize: 13, color: "var(--text)" }}>Unworn only</span>
              </label>
            </div>
          </aside>

          {/* Grid */}
          <div style={{
            display: "grid",
            gridTemplateColumns: "repeat(auto-fit, minmax(240px, 1fr))",
            gap: "clamp(20px, 2.2vw, 32px)",
          }}>
            {list.length === 0 && (
              <div style={{ gridColumn: "1 / -1", padding: "40px 0", color: "var(--muted)", fontSize: 14 }}>
                No pieces match these filters.{" "}
                <button
                  onClick={() => { setBrandFilter("All"); setCategoryFilter("All"); setModelFilter("All"); setUnwornOnly(false); setSearch(""); }}
                  style={{ color: "var(--gold-deep)", textDecoration: "underline" }}
                >
                  Clear filters
                </button>
              </div>
            )}
            {list.slice(0, visibleCount).map(w => (
              <WatchCard key={w.id} watch={w} onOpen={() => onOpenWatch(w.id)} onInquire={() => onInquire(w)} />
            ))}
            {list.length > visibleCount && (
              <div style={{ gridColumn: "1 / -1", textAlign: "center", marginTop: 16 }}>
                <GhostButton onClick={() => setVisibleCount(v => v + 48)}>
                  Load more · {list.length - visibleCount} remaining
                </GhostButton>
              </div>
            )}
          </div>
        </div>
        <style>{`
          @media (max-width: 900px) {
            .shop-grid { grid-template-columns: 1fr !important; }
            .shop-side { position: static !important; }
          }
        `}</style>
      </section>
    </main>
  );
};

// ---------- ACCESSORIES PAGE ----------
// Placeholder storefront for luxury watch-care accessories (rolls, winders,
// cleaning kits, cases). Products are added later; for now every category is
// shown as "Coming soon" and routes the visitor to WhatsApp.
const AccessoriesPage = ({ onHome, onInquire }) => {
  React.useEffect(() => { window.scrollTo(0, 0); }, []);

  const categories = [
    { icon: <IconPackage size={24} />, t: "Watch Rolls", b: "Hand-stitched leather rolls to carry two, three or more pieces in safety." },
    { icon: <IconTruck size={24} />, t: "Travel Cases", b: "Hard and soft cases built to protect your watches in transit." },
    { icon: <IconShield size={24} />, t: "Cleaning Kits", b: "Microfibre cloths, soft brushes and safe solutions for case and bracelet." },
    { icon: <IconLock size={24} />, t: "Watch Winders", b: "Single and multi-watch winders to keep your automatics running and ready." },
    { icon: <IconEye size={24} />, t: "Care Tools & Loupes", b: "Spring-bar tools, loupes and pin removers for careful at-home maintenance." },
    { icon: <IconGem size={24} />, t: "Straps & Fittings", b: "Leather, rubber and NATO straps, plus deployant clasps and spring bars." },
  ];

  return (
    <main>
      {/* Hero */}
      <section style={{ position: "relative", overflow: "hidden", borderBottom: "1px solid var(--rule)" }}>
        <div style={{ position: "absolute", inset: 0, background: `radial-gradient(1000px 500px at 75% 20%, ${hexA("#212A3D", 0.08)} 0%, transparent 60%), linear-gradient(180deg, #F4F2EF 0%, #FFFFFF 70%)` }} />
        <div style={{ position: "relative", maxWidth: 1100, margin: "0 auto", padding: "clamp(48px, 6vw, 96px) clamp(18px, 4vw, 44px)" }}>
          <button onClick={onHome} style={{ fontSize: 12, color: "var(--muted)", letterSpacing: "0.14em", textTransform: "uppercase", marginBottom: 24 }}>
            ← Back to home
          </button>
          <div className="eyebrow" style={{ color: "var(--gold-deep)" }}>Accessories</div>
          <span className="gold-rule" />
          <h1 className="serif" style={{ fontSize: "clamp(38px, 5vw, 68px)", lineHeight: 1.04, margin: "8px 0 18px", color: "var(--ink)", fontWeight: 500, letterSpacing: "-0.01em", textWrap: "balance" }}>
            The finishing touches for <em style={{ fontStyle: "italic", color: "var(--green)" }}>your collection.</em>
          </h1>
          <p style={{ fontSize: "clamp(15px, 1.3vw, 17px)", color: "var(--text)", maxWidth: 560, lineHeight: 1.6, textWrap: "pretty" }}>
            A curated line of watch-care and storage accessories — rolls, cases, winders and cleaning kits — chosen to protect and present the pieces you love. Launching soon. Tell us what you're after and we'll let you know the moment it lands.
          </p>
          <div style={{ marginTop: 28 }}>
            <PrimaryButton icon={<IconWhatsApp size={18} color="#fff" />} onClick={() => onInquire(null)}>
              Ask about accessories
            </PrimaryButton>
          </div>
        </div>
      </section>

      {/* Category grid */}
      <section style={{ padding: "clamp(50px, 7vw, 96px) clamp(18px, 4vw, 44px)" }}>
        <div style={{ maxWidth: 1200, margin: "0 auto" }}>
          <div style={{ textAlign: "center", marginBottom: 56 }}>
            <div className="eyebrow" style={{ color: "var(--gold-deep)" }}>Coming soon</div>
            <span className="gold-rule" style={{ margin: "14px auto" }} />
            <h2 className="serif" style={{ fontSize: "clamp(28px, 3vw, 42px)", margin: "6px 0 0", color: "var(--ink)", lineHeight: 1.1 }}>
              What we're bringing in.
            </h2>
          </div>
          <div style={{ display: "grid", gridTemplateColumns: "repeat(auto-fit, minmax(260px, 1fr))", gap: "clamp(20px, 2.4vw, 36px)" }}>
            {categories.map((c) => (
              <div key={c.t} style={{ border: "1px solid var(--rule)", background: "#fff", padding: "clamp(24px, 2.6vw, 34px)", position: "relative" }}>
                <div style={{ position: "absolute", top: 16, right: 16, fontFamily: "var(--mono)", fontSize: 9.5, letterSpacing: "0.16em", textTransform: "uppercase", color: "var(--gold-deep)", border: "1px solid var(--gold)", padding: "4px 8px" }}>
                  Coming soon
                </div>
                <div style={{ color: "var(--green)", marginBottom: 18 }}>{c.icon}</div>
                <h3 className="serif" style={{ fontSize: 22, color: "var(--ink)", fontWeight: 500, margin: "0 0 10px" }}>{c.t}</h3>
                <p style={{ fontSize: 14, color: "var(--text)", lineHeight: 1.6, margin: 0, textWrap: "pretty" }}>{c.b}</p>
              </div>
            ))}
          </div>
        </div>
      </section>

      {/* CTA band */}
      <section style={{ padding: "clamp(50px, 6vw, 88px) clamp(18px, 4vw, 44px)", background: "#212A3D", color: "#F4F2EF", position: "relative", overflow: "hidden" }}>
        <svg viewBox="0 0 100 100" preserveAspectRatio="none" width="600" height="600" style={{ position: "absolute", right: -180, top: -120, opacity: 0.07, pointerEvents: "none" }}>
          <circle cx="50" cy="50" r="48" fill="none" stroke="#A86137" strokeWidth="0.2" />
          <circle cx="50" cy="50" r="36" fill="none" stroke="#A86137" strokeWidth="0.2" />
          <circle cx="50" cy="50" r="24" fill="none" stroke="#A86137" strokeWidth="0.2" />
        </svg>
        <div style={{ position: "relative", maxWidth: 820, margin: "0 auto", textAlign: "center" }}>
          <div className="eyebrow" style={{ color: "#A86137" }}>Looking for something specific?</div>
          <span className="gold-rule" style={{ margin: "14px auto" }} />
          <h2 className="serif" style={{ fontSize: "clamp(26px, 3vw, 40px)", lineHeight: 1.12, margin: "6px 0 16px", color: "#F4F2EF", fontWeight: 500, textWrap: "balance" }}>
            Tell us what you need — we'll source it.
          </h2>
          <p style={{ color: "#B8B2A6", fontSize: 15, lineHeight: 1.65, maxWidth: 520, margin: "0 auto 26px", textWrap: "pretty" }}>
            Winders, rolls, straps or a specific case — message us and we'll tell you what's available and when.
          </p>
          <button
            onClick={() => onInquire(null)}
            style={{ background: "#A86137", color: "#212A3D", padding: "14px 28px", fontSize: 13, letterSpacing: "0.16em", textTransform: "uppercase", fontWeight: 500, display: "inline-flex", alignItems: "center", gap: 10 }}
            onMouseEnter={(e) => { e.currentTarget.style.background = "#D6BA82"; }}
            onMouseLeave={(e) => { e.currentTarget.style.background = "#A86137"; }}
          >
            <IconWhatsApp size={18} color="#212A3D" /> Message us on WhatsApp
          </button>
        </div>
      </section>
    </main>
  );
};

Object.assign(window, { AuthenticationPage, AboutPage, ShopPage, AccessoriesPage });
