/* global React */
/* Page views — part B. Depends on window.MA + window.MA_DATA + Photo. */
const MB = window.MA;
const DB = window.MA_DATA;
const { Icon: IconB, Button: BtnB, Card: CardB, StatBlock: StatB, PageHeader: PH, SectionHead: SH, Input: InB, Textarea: TaB, Select: SelB, Alert: AlertB, refreshIcons: refB, trackCta: trackCtaB, useGallery: useGalleryB, useArticles: useArticlesB, GalleryPhoto: GPhoto, CallLabel: CallLabelB } = MB;
const PhotoB = window.MA_PAGES_A.Photo;
const { useState: useStateB, useEffect: useEffB, useRef: useRefB } = React;

const WRAPB = { maxWidth: "var(--container-lg)", margin: "0 auto", padding: "clamp(44px, 7vw, 72px) var(--gutter)" };

/* ===================================================== CONTACT FORM ======
   The "put your details in and we'll get back to you" form. Used as the CTA at
   the bottom of the Commercial & Residential page and as the contact page's own
   form, so a builder and a homeowner reach the same inbox.

   Posts JSON to /api/contact, which stores the lead in Firestore and emails it
   (functions/app.js). The visitor's first-touch attribution rides along, the
   same way the AI-preview form sends it, so a lead can be traced back to the
   traffic that produced it.
   ======================================================================== */
const CONTACT_ENDPOINT = (window.MA_CONFIG && window.MA_CONFIG.contactBase) || "/api/contact";

function ContactForm({ submitLabel = "Request a Quote", sectors }) {
  useEffB(refB);
  const [status, setStatus] = useStateB("idle"); // idle | sending | sent | error
  const [errorMsg, setErrorMsg] = useStateB("");

  async function onSubmit(e) {
    e.preventDefault();
    if (status === "sending") return;
    const payload = Object.fromEntries(new FormData(e.currentTarget).entries());
    setStatus("sending");
    setErrorMsg("");
    try {
      if (window.MA_ANALYTICS) {
        try { payload.attribution = JSON.stringify(window.MA_ANALYTICS.attribution()); } catch (_) { /* optional */ }
      }
      const res = await fetch(CONTACT_ENDPOINT, {
        method: "POST",
        headers: { "Content-Type": "application/json" },
        body: JSON.stringify(payload),
      });
      if (!res.ok) {
        let msg = "Something went wrong sending your details. Please try again — or call us.";
        try { const j = await res.json(); if (j && j.error) msg = j.error; } catch (_) { /* non-JSON error */ }
        throw new Error(msg);
      }
      setStatus("sent");
      window.scrollTo({ top: window.scrollY - 80, behavior: "smooth" });
    } catch (err) {
      setStatus("error");
      setErrorMsg(err && err.message ? err.message : "Network error. Please try again.");
    }
  }

  if (status === "sent") {
    return (
      <AlertB tone="success" title="Thanks — we've got it">
        We'll get back to you within {DB.QUOTE_TURNAROUND}. If it's urgent, call us on {DB.PHONE.display}.
      </AlertB>
    );
  }

  return (
    <form onSubmit={onSubmit} noValidate>
      {status === "error" && (
        <div style={{ marginBottom: 16 }}>
          <AlertB tone="danger" title="Couldn't send your details">{errorMsg}</AlertB>
        </div>
      )}
      <div className="ma-form-grid" style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: 16 }}>
        <InB name="name" label="Full name" placeholder="Jane Mason" autoComplete="name" required />
        <InB name="company" label="Company (optional)" placeholder="Ridgeline Homes" autoComplete="organization" />
        <InB name="email" label="Email" type="email" placeholder="you@email.com" autoComplete="email" required />
        <InB name="phone" label="Phone" type="tel" placeholder="(208) 555-0123" autoComplete="tel" />
        {sectors && (
          <div style={{ gridColumn: "1 / -1" }}>
            <SelB name="sector" label="What kind of work?" defaultValue={sectors[0]}>
              {sectors.map((s) => <option key={s}>{s}</option>)}
            </SelB>
          </div>
        )}
        <div style={{ gridColumn: "1 / -1" }}>
          <TaB name="message" label="Tell us about the project" rows={4} required
            placeholder="Scope, location, timeline, and anything else we should know — plan sets and specs welcome." />
        </div>
        <div style={{ gridColumn: "1 / -1" }}>
          <BtnB variant="primary" size="lg" fullWidth type="submit" disabled={status === "sending"}
            trailingIcon={status === "sending" ? null : <IconB name="arrow-right" size={20} />}>
            {status === "sending" ? "Sending…" : submitLabel}
          </BtnB>
        </div>
        <p style={{ gridColumn: "1 / -1", margin: 0, fontSize: 12.5, color: "var(--text-muted)", textAlign: "center" }}>
          We only use your details to reply about this project. No spam, ever.{" "}
          <MB.NavLink to="/privacy" style={{ color: "var(--text-muted)", borderBottom: "1px solid var(--border-default)" }}>How we handle your information</MB.NavLink>.
        </p>
      </div>
    </form>
  );
}

/* ======================================================== LIGHTBOX ======
   Click a gallery photo to see it at full size. Deliberately small: an overlay,
   the image, the caption, and keyboard control (Escape closes, arrows move).
   Body scroll is locked while it's open so the page behind doesn't drift.
   ======================================================================== */
function Lightbox({ items, index, labels, onClose, onMove }) {
  useEffB(() => {
    function onKey(e) {
      if (e.key === "Escape") onClose();
      else if (e.key === "ArrowRight") onMove(1);
      else if (e.key === "ArrowLeft") onMove(-1);
    }
    window.addEventListener("keydown", onKey);
    const previous = document.body.style.overflow;
    document.body.style.overflow = "hidden";
    return () => {
      window.removeEventListener("keydown", onKey);
      document.body.style.overflow = previous;
    };
  }, [onClose, onMove]);

  const item = items[index];
  if (!item) return null;
  const arrow = {
    position: "absolute", top: "50%", transform: "translateY(-50%)", zIndex: 2,
    width: 46, height: 46, borderRadius: "var(--radius-full)", border: "1px solid rgba(255,255,255,0.3)",
    background: "rgba(28,26,23,0.55)", color: "#fff", cursor: "pointer", display: "grid", placeItems: "center",
  };

  return (
    <div
      onClick={onClose}
      style={{ position: "fixed", inset: 0, zIndex: 200, background: "rgba(20,18,16,0.92)", display: "grid", placeItems: "center", padding: "clamp(16px,4vw,48px)" }}
      role="dialog"
      aria-modal="true"
      aria-label={item.title}
    >
      <button onClick={onClose} aria-label="Close" style={{ position: "absolute", top: 18, right: 18, zIndex: 2, width: 42, height: 42, borderRadius: "var(--radius-full)", border: "1px solid rgba(255,255,255,0.3)", background: "rgba(28,26,23,0.55)", color: "#fff", cursor: "pointer", display: "grid", placeItems: "center" }}>
        <IconB name="x" size={22} />
      </button>
      {items.length > 1 && (
        <React.Fragment>
          <button onClick={(e) => { e.stopPropagation(); onMove(-1); }} aria-label="Previous" style={{ ...arrow, left: 14 }}>
            <IconB name="chevron-left" size={24} />
          </button>
          <button onClick={(e) => { e.stopPropagation(); onMove(1); }} aria-label="Next" style={{ ...arrow, right: 14 }}>
            <IconB name="chevron-right" size={24} />
          </button>
        </React.Fragment>
      )}
      <figure onClick={(e) => e.stopPropagation()} style={{ margin: 0, maxWidth: 1100, maxHeight: "100%", display: "flex", flexDirection: "column", gap: 14 }}>
        <img src={item.imageUrl} alt={item.title || ""} style={{ maxWidth: "100%", maxHeight: "76vh", objectFit: "contain", borderRadius: "var(--radius-lg)", display: "block", margin: "0 auto" }} />
        <figcaption style={{ textAlign: "center", color: "var(--stone-300)" }}>
          <div style={{ fontFamily: "var(--font-display)", fontWeight: 600, fontSize: 21, color: "var(--stone-50)" }}>{item.title}</div>
          {item.caption && <p style={{ margin: "6px 0 0", fontSize: 15, lineHeight: 1.5, maxWidth: 620, marginLeft: "auto", marginRight: "auto" }}>{item.caption}</p>}
          {item.tags.length > 0 && (
            <div style={{ display: "flex", gap: 7, flexWrap: "wrap", justifyContent: "center", marginTop: 12 }}>
              {item.tags.map((slug) => (
                <span key={slug} style={{ fontSize: 12, fontWeight: 600, letterSpacing: "0.04em", textTransform: "uppercase", color: "var(--sand-300)", border: "1px solid rgba(255,255,255,0.22)", borderRadius: 4, padding: "3px 9px" }}>
                  {labels[slug] || slug}
                </span>
              ))}
            </div>
          )}
          <div style={{ fontSize: 12.5, color: "var(--stone-400)", marginTop: 14 }}>{index + 1} of {items.length}</div>
        </figcaption>
      </figure>
    </div>
  );
}

/* ======================================================== CAROUSEL ======
   A horizontal strip of project photos with scroll-snap. Native overflow
   scrolling does the work — it drags on a trackpad, swipes on a phone, and the
   buttons are there for a mouse. No autoplay: this sits in the middle of a page
   a builder is reading, and motion they didn't ask for is just noise.
   ======================================================================== */
function GalleryCarousel({ items, labels, onOpen }) {
  const strip = useRefB(null);
  function nudge(direction) {
    const node = strip.current;
    if (!node) return;
    node.scrollBy({ left: direction * Math.max(300, node.clientWidth * 0.8), behavior: "smooth" });
  }
  return (
    <div>
      <div style={{ display: "flex", justifyContent: "flex-end", gap: 8, marginBottom: 12 }}>
        {[["chevron-left", -1, "Scroll left"], ["chevron-right", 1, "Scroll right"]].map(([ic, dir, label]) => (
          <button key={label} onClick={() => nudge(dir)} aria-label={label}
            style={{ width: 38, height: 38, borderRadius: "var(--radius-md)", border: "1px solid var(--border-default)", background: "var(--surface-raised)", color: "var(--stone-700)", cursor: "pointer", display: "grid", placeItems: "center" }}>
            <IconB name={ic} size={19} />
          </button>
        ))}
      </div>
      <div ref={strip} className="ma-carousel"
        style={{ display: "flex", gap: 16, overflowX: "auto", scrollSnapType: "x mandatory", paddingBottom: 10, scrollbarWidth: "thin" }}>
        {items.map((item, i) => (
          <figure key={item.id} onClick={() => onOpen(i)}
            style={{ margin: 0, flex: "0 0 auto", width: "min(360px, 78vw)", scrollSnapAlign: "start", cursor: "zoom-in" }}>
            <GPhoto item={item} h={240} />
            <figcaption style={{ display: "flex", justifyContent: "space-between", alignItems: "center", gap: 10, padding: "11px 2px 0" }}>
              <span style={{ fontFamily: "var(--font-display)", fontWeight: 600, fontSize: 16.5, color: "var(--text-strong)" }}>{item.title}</span>
              <span style={{ fontSize: 12.5, color: "var(--text-muted)", whiteSpace: "nowrap" }}>{labels[item.tags[0]] || ""}</span>
            </figcaption>
          </figure>
        ))}
      </div>
    </div>
  );
}

/* Placeholder carousel for a site whose gallery is still empty. */
function PlaceholderCarousel() {
  return (
    <div className="ma-carousel" style={{ display: "flex", gap: 16, overflowX: "auto", scrollSnapType: "x mandatory", paddingBottom: 10 }}>
      {DB.PROJECTS.slice(0, 6).map(([name, cat, stone, tint]) => (
        <figure key={name} style={{ margin: 0, flex: "0 0 auto", width: "min(360px, 78vw)", scrollSnapAlign: "start" }}>
          <PhotoB tint={tint} h={240} cat={cat} />
          <figcaption style={{ display: "flex", justifyContent: "space-between", alignItems: "center", padding: "11px 2px 0" }}>
            <span style={{ fontFamily: "var(--font-display)", fontWeight: 600, fontSize: 16.5 }}>{name}</span>
            <span style={{ fontSize: 12.5, color: "var(--text-muted)" }}>{stone}</span>
          </figcaption>
        </figure>
      ))}
    </div>
  );
}

/* ==================================== COMMERCIAL & RESIDENTIAL ========= */
/* The slug the gallery stores for a photo tagged "Commercial" in /admin — see
   slugify() in functions/gallery.js. The carousel below shows those photos
   first. Until at least one photo carries that tag, it shows the real
   exterior jobs instead (the page covers residential too), so the strip is
   never left on the tinted placeholder boxes while the gallery has photos in
   it. It stays a quiet rule: nothing on the page mentions tags, and a
   commercial job missing from the strip is fixed by tagging the photo, not by
   editing this file. */
const COMMERCIAL_TAG = "commercial";
const CAROUSEL_FALLBACK_TAG = "exterior";

function CommercialPage() {
  useEffB(refB);
  const gal = useGalleryB();
  const [lightbox, setLightbox] = useStateB(-1);
  const taggedWith = (tag) => gal.items.filter((item) => (item.tags || []).indexOf(tag) >= 0);
  const commercialItems = taggedWith(COMMERCIAL_TAG);
  const carouselItems = (commercialItems.length ? commercialItems : taggedWith(CAROUSEL_FALLBACK_TAG)).slice(0, 12);

  const sectors = [
    ["home", "Production & Custom Home Builders", "Stone, stucco and siding packages priced per elevation and built to your plan set — subdivision or one-off customs."],
    ["building-2", "Multifamily & Mixed-Use", "Apartments, townhomes, and podium builds — veneer and stucco at scale, on schedule."],
    ["store", "Retail & Hospitality", "Storefronts, restaurants, and hotels where the exterior is the first impression."],
    ["warehouse", "Commercial & Institutional", "Office, medical, schools and light-industrial exteriors, tenant improvements, and repairs."],
  ];
  const steps = [
    ["Plans & Takeoff", "Send drawings or a spec. We do the takeoff and return a detailed, line-item bid — no vague allowances."],
    ["Scope & Schedule", "We lock scope, materials, and a milestone schedule that fits your critical path."],
    ["Mobilize & Build", "Daily coordination with your superintendent, safety compliance, and clean staging."],
    ["Inspect & Close Out", "Punch, warranty documentation, and O&M turnover — the paperwork done right the first time."],
  ];
  const caps = [
    ["file-check-2", "Licensed, bonded & insured", "Commercial GL and workers' comp on file; bonding available by project."],
    ["hard-hat", "Done right the first time", "One standard from mobilization to close-out, so the work stays off your punch list."],
    ["clipboard-list", "Spec & submittal ready", "Mock-ups, samples, and submittals handled to your architect's requirements."],
    ["calendar-clock", "Schedule accountability", "We build to the milestone schedule and communicate daily on site."],
  ];

  return (
    <div>
      <PH
        eyebrow="Commercial & Residential"
        title="Masonry your schedule can be built around"
        lede="For builders, GCs and developers across the Treasure Valley: how we bid, build, and close out — and why the same team that sets a custom home's elevation can carry a 40-unit run."
        photo={{ ...DB.photo(DB.COMMERCIAL_PHOTO), position: "center 38%" }}
      />
      <div style={WRAPB}>
        {/* Sectors */}
        <SH eyebrow="Who We Work With" title="Sectors we serve" />
        <div style={{ display: "grid", gridTemplateColumns: "repeat(auto-fit,minmax(min(240px,100%),1fr))", gap: 18 }}>
          {sectors.map(([ic, t, d]) => (
            <CardB key={t} padding="lg" accent>
              <div style={{ width: 46, height: 46, borderRadius: 6, background: "var(--brick-50)", display: "grid", placeItems: "center", marginBottom: 14 }}>
                <IconB name={ic} size={24} color="var(--brick-600)" />
              </div>
              <h3 style={{ fontSize: 19, margin: "0 0 8px" }}>{t}</h3>
              <p style={{ fontSize: 14.5, color: "var(--text-body)", margin: 0, lineHeight: 1.55 }}>{d}</p>
            </CardB>
          ))}
        </div>

        {/* How it works */}
        <div style={{ marginTop: 64 }}>
          <SH eyebrow="How It Works" title="Contracting with us, start to finish" lede="Four steps from plan set to close-out. Predictable, documented, and coordinated with your team." />
          <div style={{ display: "grid", gridTemplateColumns: "repeat(auto-fit,minmax(min(240px,100%),1fr))", gap: 18 }}>
            {steps.map(([t, d], i) => (
              <div key={t} style={{ position: "relative", background: "var(--surface-raised)", border: "1px solid var(--border-hairline)", borderTop: "3px solid var(--brick-500)", borderRadius: "var(--radius-lg)", padding: "22px 22px 24px", boxShadow: "var(--shadow-sm)" }}>
                <div style={{ fontFamily: "var(--font-display)", fontWeight: 700, fontSize: 34, color: "var(--brick-200)", lineHeight: 1 }}>{`0${i + 1}`}</div>
                <h3 style={{ fontSize: 18, margin: "10px 0 8px" }}>{t}</h3>
                <p style={{ fontSize: 14, color: "var(--text-body)", margin: 0, lineHeight: 1.55 }}>{d}</p>
              </div>
            ))}
          </div>
        </div>

        {/* ---- The work itself, in the middle of the page ---- */}
        <div style={{ marginTop: 64 }}>
          <SH eyebrow="The Work" title="Elevations we've delivered" lede="Scroll through recent jobs. Every photo is our own crew's work — no stock, no other company's elevations." />
          {carouselItems.length > 0
            ? <GalleryCarousel items={carouselItems} labels={gal.labels} onOpen={setLightbox} />
            : gal.loading ? <div style={{ minHeight: 280 }} /> : <PlaceholderCarousel />}
          <div style={{ marginTop: 18 }}>
            <BtnB variant="outline" href="/gallery" trailingIcon={<IconB name="arrow-right" size={18} />}>Browse the full gallery</BtnB>
          </div>
        </div>

        {/* Capabilities + stats */}
        <div style={{ marginTop: 64, display: "grid", gridTemplateColumns: "1.2fr 1fr", gap: 44, alignItems: "start" }} className="ma-detail-grid">
          <div>
            <SH eyebrow="Why Builders Choose Us" title="Built for the way you run a job" />
            <div style={{ display: "flex", flexDirection: "column", gap: 4 }}>
              {caps.map(([ic, t, d], i) => (
                <div key={t} style={{ display: "flex", gap: 14, padding: "16px 0", borderTop: i ? "1px solid var(--border-hairline)" : "none" }}>
                  <IconB name={ic} size={22} color="var(--brick-500)" style={{ marginTop: 2 }} />
                  <div>
                    <h3 style={{ fontSize: 17, margin: "0 0 3px" }}>{t}</h3>
                    <p style={{ fontSize: 14, color: "var(--text-body)", margin: 0, lineHeight: 1.5 }}>{d}</p>
                  </div>
                </div>
              ))}
            </div>
          </div>
          <CardB padding="lg">
            <div style={{ display: "flex", justifyContent: "space-between", gap: 12 }}>
              <StatB value="20" suffix="+" label="Years Building" />
              <StatB value="500k" suffix="+" label="Sq Ft Set" />
            </div>
            <MB.Divider style={{ margin: "18px 0" }} />
            <div style={{ fontFamily: "var(--font-display)", fontWeight: 600, fontSize: 18, marginBottom: 6 }}>Prefer to talk first?</div>
            <p style={{ fontSize: 14, color: "var(--text-muted)", margin: "0 0 14px", lineHeight: 1.5 }}>Call the office {DB.HOURS.display}. {DB.HOURS.note}</p>
            <BtnB variant="outline" fullWidth href={DB.PHONE.href} onClick={() => trackCtaB("call")} aria-label={`Call now — ${DB.PHONE.display}`} leadingIcon={<IconB name="phone" size={18} />}><CallLabelB numberSize={16} /></BtnB>
          </CardB>
        </div>
      </div>

      {/* ---- The ask, at the bottom: leave your details ---- */}
      <section id="builder-contact" className="tex-stone" style={{ background: "var(--stone-900)" }}>
        <div className="ma-sect" style={{ maxWidth: "var(--container-lg)", margin: "0 auto", padding: "clamp(48px,7vw,72px) var(--gutter)" }}>
          <div className="ma-callcard-grid" style={{ display: "grid", gridTemplateColumns: "1.05fr 1fr", gap: 48, alignItems: "center" }}>
            <div>
              <span style={{ fontSize: 11, fontWeight: 600, letterSpacing: "0.16em", textTransform: "uppercase", color: "var(--sand-300)" }}>Let's Talk</span>
              <h2 style={{ color: "var(--stone-50)", fontSize: "clamp(30px,4vw,46px)", margin: "12px 0 12px", lineHeight: 1.05, maxWidth: 520 }}>
                Leave your details. We'll get back to you.
              </h2>
              <p style={{ color: "var(--stone-300)", fontSize: 17, lineHeight: 1.6, margin: "0 0 20px", maxWidth: 480 }}>
                No plan set required to start a conversation. Tell us what you're building and when, and we'll come back with availability and a realistic number.
              </p>
              <ul style={{ listStyle: "none", margin: 0, padding: 0, display: "flex", flexDirection: "column", gap: 10 }}>
                {[
                  ["clock", `A reply within ${DB.QUOTE_TURNAROUND}.`],
                  ["file-text", "Line-item bids from drawings or a spec."],
                  ["handshake", "Masonry, stucco, and siding bid from the same plan set."],
                ].map(([ic, t]) => (
                  <li key={t} style={{ display: "flex", alignItems: "center", gap: 11, color: "var(--stone-300)", fontSize: 15 }}>
                    <IconB name={ic} size={18} color="var(--sand-300)" /> {t}
                  </li>
                ))}
              </ul>
            </div>
            <div style={{ background: "var(--surface-raised)", border: "1px solid var(--border-hairline)", borderRadius: "var(--radius-xl)", padding: "26px 24px", boxShadow: "var(--shadow-lg)" }}>
              <ContactForm
                submitLabel="Request a Quote"
                sectors={["Custom / production homes", "Multifamily & mixed-use", "Retail & hospitality", "Commercial & institutional", "Repair or remedial work", "Something else"]}
              />
            </div>
          </div>
        </div>
      </section>

      {lightbox >= 0 && (
        <Lightbox
          items={carouselItems}
          index={lightbox}
          labels={gal.labels}
          onClose={() => setLightbox(-1)}
          onMove={(d) => setLightbox((i) => (i + d + carouselItems.length) % carouselItems.length)}
        />
      )}
    </div>
  );
}

/* ============================================================ GALLERY ===
   Everything the owner has uploaded from /admin, filtered by tag.

   Selecting more than one tag narrows rather than widens — "Stucco" plus
   "Meridian" means both, not either. That's what makes the filter useful on a
   gallery that will eventually hold hundreds of photos, and the empty state
   below exists precisely because narrowing can reach zero.
   ======================================================================== */
function GalleryPage() {
  useEffB(refB);
  const gal = useGalleryB();
  const [selected, setSelected] = useStateB([]);
  const [lightbox, setLightbox] = useStateB(-1);

  function toggle(slug) {
    setSelected((current) => (current.indexOf(slug) >= 0 ? current.filter((s) => s !== slug) : current.concat(slug)));
    setLightbox(-1);
  }

  const shown = selected.length
    ? gal.items.filter((item) => selected.every((slug) => item.tags.indexOf(slug) >= 0))
    : gal.items;

  const chip = (active) => ({
    fontFamily: "var(--font-body)", fontSize: 14, fontWeight: 600, padding: "8px 15px", borderRadius: 4,
    cursor: "pointer", border: `1px solid ${active ? "var(--brick-500)" : "var(--border-default)"}`,
    background: active ? "var(--brick-500)" : "transparent", color: active ? "var(--stone-50)" : "var(--stone-700)",
    display: "inline-flex", alignItems: "center", gap: 7,
  });

  return (
    <div>
      <PH eyebrow="Gallery" title="Where vision meets craftsmanship." lede="Filter by tag to find work like yours. Every photo is our own crew's work — no stock, no other company's jobs." tint="stone-800" />
      <div style={WRAPB}>
        {gal.loading && <p style={{ color: "var(--text-muted)", fontSize: 16 }}>Loading the gallery…</p>}

        {/* A gallery with nothing in it yet: show the placeholders rather than
            an empty page, and don't offer filters there is nothing to filter. */}
        {!gal.loading && gal.items.length === 0 && (
          <div>
            <SH eyebrow="Our Work" title="Recent projects" />
            <div style={{ display: "grid", gridTemplateColumns: "repeat(auto-fill,minmax(min(300px,100%),1fr))", gap: 18 }}>
              {DB.PROJECTS.map(([name, cat, stone, tint]) => (
                <figure key={name} style={{ margin: 0, borderRadius: "var(--radius-lg)", overflow: "hidden", border: "1px solid var(--border-hairline)", boxShadow: "var(--shadow-sm)" }}>
                  <PhotoB tint={tint} h={200} cat={cat} style={{ borderRadius: 0 }} />
                  <figcaption style={{ padding: "14px 16px", display: "flex", justifyContent: "space-between", alignItems: "center", background: "var(--surface-raised)" }}>
                    <span style={{ fontFamily: "var(--font-display)", fontWeight: 600, fontSize: 17 }}>{name}</span>
                    <span style={{ fontSize: 13, color: "var(--text-muted)" }}>{stone}</span>
                  </figcaption>
                </figure>
              ))}
            </div>
          </div>
        )}

        {!gal.loading && gal.items.length > 0 && (
          <div>
            <SH
              eyebrow="Browse by Tag"
              title={selected.length ? `${shown.length} ${shown.length === 1 ? "project" : "projects"}` : "Our work"}
              lede={gal.tags.length ? "Pick as many tags as you like — each one narrows the results." : null}
            />

            {gal.tags.length > 0 && (
              <div style={{ display: "flex", gap: 8, flexWrap: "wrap", marginBottom: 28 }}>
                <button onClick={() => { setSelected([]); setLightbox(-1); }} style={chip(selected.length === 0)}>
                  All
                  <span style={{ fontSize: 12, opacity: 0.75 }}>{gal.items.length}</span>
                </button>
                {gal.tags.map((tag) => {
                  const active = selected.indexOf(tag.slug) >= 0;
                  return (
                    <button key={tag.slug} onClick={() => toggle(tag.slug)} style={chip(active)} aria-pressed={active}>
                      {active && <IconB name="check" size={15} stroke={2.6} />}
                      {tag.label}
                      <span style={{ fontSize: 12, opacity: 0.75 }}>{tag.count}</span>
                    </button>
                  );
                })}
              </div>
            )}

            {shown.length === 0 ? (
              <div style={{ textAlign: "center", padding: "48px 20px", background: "var(--surface-raised)", border: "1px solid var(--border-hairline)", borderRadius: "var(--radius-lg)" }}>
                <IconB name="search-x" size={30} color="var(--stone-400)" />
                <h3 style={{ fontSize: 20, margin: "12px 0 6px" }}>No projects match all of those tags</h3>
                <p style={{ fontSize: 15, color: "var(--text-muted)", margin: "0 0 18px" }}>Try removing one, or start again from everything.</p>
                <BtnB variant="outline" onClick={() => setSelected([])}>Clear filters</BtnB>
              </div>
            ) : (
              <div style={{ display: "grid", gridTemplateColumns: "repeat(auto-fill,minmax(min(300px,100%),1fr))", gap: 18 }}>
                {shown.map((item, i) => (
                  <figure key={item.id} onClick={() => setLightbox(i)}
                    style={{ margin: 0, borderRadius: "var(--radius-lg)", overflow: "hidden", border: "1px solid var(--border-hairline)", boxShadow: "var(--shadow-sm)", cursor: "zoom-in" }}>
                    <GPhoto item={item} h={220} style={{ borderRadius: 0 }} />
                    <figcaption style={{ padding: "14px 16px", background: "var(--surface-raised)" }}>
                      <div style={{ fontFamily: "var(--font-display)", fontWeight: 600, fontSize: 17, color: "var(--text-strong)" }}>{item.title}</div>
                      {item.caption && <p style={{ fontSize: 13.5, color: "var(--text-muted)", margin: "4px 0 0", lineHeight: 1.5 }}>{item.caption}</p>}
                      {item.tags.length > 0 && (
                        <div style={{ display: "flex", gap: 6, flexWrap: "wrap", marginTop: 10 }}>
                          {item.tags.map((slug) => (
                            <span key={slug} style={{ fontSize: 11, fontWeight: 600, letterSpacing: "0.05em", textTransform: "uppercase", color: "var(--brick-600)", background: "var(--brick-50)", borderRadius: 3, padding: "3px 7px" }}>
                              {gal.labels[slug] || slug}
                            </span>
                          ))}
                        </div>
                      )}
                    </figcaption>
                  </figure>
                ))}
              </div>
            )}
          </div>
        )}
      </div>

      {lightbox >= 0 && shown.length > 0 && (
        <Lightbox
          items={shown}
          index={Math.min(lightbox, shown.length - 1)}
          labels={gal.labels}
          onClose={() => setLightbox(-1)}
          onMove={(d) => setLightbox((i) => (i + d + shown.length) % shown.length)}
        />
      )}
    </div>
  );
}

/* =========================================================== ARTICLES ====
   The blog. Every article answers one question a homeowner actually asks on a
   first phone call, and every article ends where that call ends: with an offer
   to come and look at the wall. The original text is data in nav-data.js; the
   owner edits it, and chooses which articles are shown, from /admin →
   Articles (useArticles). These two components are the index and the reader. */

/* The cover image: one uploaded or picked from the gallery in /admin, else the
   built-in photo nav-data.js names. */
function articlePhoto(article) {
  return article.imageUrl ? { src: article.imageUrl, alt: article.title } : DB.photo(article.photo);
}

/* While the show/hide settings load, hold the page's height rather than flash
   an empty index or bounce the visitor somewhere else. */
function ArticlesLoading() {
  return <div style={{ minHeight: "70vh" }} aria-busy="true" />;
}

/* The Articles page while no article is shown: the same header as the index,
   and an honest note that there's nothing to read here yet. */
function ArticlesEmpty() {
  return (
    <div>
      <PH
        eyebrow="Articles"
        title="Learn more about the kinds of projects we do"
        lede="Stone veneer, siding, stucco and masonry repair: how each one works, the choices involved, and what a typical project looks like."
        tint="stone-800"
      />
      <div style={WRAPB}>
        <CardB padding="lg" style={{ textAlign: "center", maxWidth: 640, margin: "0 auto" }}>
          <IconB name="book-open" size={28} color="var(--brick-500)" />
          <h2 style={{ fontSize: "clamp(22px,2.6vw,28px)", margin: "12px 0 10px" }}>Articles are on the way</h2>
          <p style={{ fontSize: 16, color: "var(--text-body)", lineHeight: 1.6, margin: "0 0 22px" }}>
            We're putting together guides to the questions homeowners ask us most. In the meantime, take a look at our recent work, or ask us directly — we're happy to talk through your project.
          </p>
          <div style={{ display: "flex", gap: 12, justifyContent: "center", flexWrap: "wrap" }}>
            <BtnB variant="outline" size="md" href="/gallery" style={{ color: "var(--stone-800)" }}>See the Gallery</BtnB>
            <BtnB variant="primary" size="md" href="/contact" onClick={() => trackCtaB("estimate")}>Request an Estimate</BtnB>
          </div>
        </CardB>
      </div>
    </div>
  );
}

/* One article card, used by the index grid and by the "keep reading" strip. */
function ArticleCard({ article, h = 170 }) {
  return (
    <MB.NavLink to={`/learn/${article.slug}`} style={{ display: "block", height: "100%" }}>
      <CardB interactive style={{ padding: 0, height: "100%", display: "flex", flexDirection: "column", overflow: "hidden" }}>
        <PhotoB tint={article.tint} h={h} style={{ borderRadius: 0 }} {...articlePhoto(article)} />
        <div style={{ padding: "18px 20px 20px", display: "flex", flexDirection: "column", flex: 1 }}>
          <div style={{ display: "flex", alignItems: "center", gap: 8, fontSize: 12, color: "var(--text-muted)", marginBottom: 9 }}>
            <span style={{ fontWeight: 600, letterSpacing: "0.1em", textTransform: "uppercase", color: "var(--brick-600)" }}>{article.category}</span>
            <span>·</span>
            <span>{article.minutes} min read</span>
          </div>
          <h3 style={{ fontSize: 19, lineHeight: 1.25, margin: "0 0 10px" }}>{article.title}</h3>
          <p style={{ fontSize: 14.5, color: "var(--text-body)", lineHeight: 1.5, margin: "0 0 14px" }}>{article.excerpt}</p>
          <span style={{ marginTop: "auto", fontSize: 14, fontWeight: 600, color: "var(--brick-600)", display: "inline-flex", alignItems: "center", gap: 6 }}>
            Read the article <IconB name="arrow-right" size={16} />
          </span>
        </div>
      </CardB>
    </MB.NavLink>
  );
}

/* The call to action every article closes on. Kept in one place so the ask is
   worded identically across the whole section — a blog that asks for the job
   three different ways reads as three different companies. */
function ArticleCTA() {
  return (
    <div className="tex-brick" style={{ position: "relative", borderRadius: "var(--radius-xl)", overflow: "hidden", border: "1px solid var(--border-default)" }}>
      <div style={{ position: "relative", zIndex: 2, padding: "36px 32px", display: "flex", alignItems: "center", gap: 24, flexWrap: "wrap" }}>
        <div style={{ flex: 1, minWidth: "min(340px, 100%)" }}>
          <span className="eyebrow">Still deciding?</span>
          <h3 style={{ fontSize: "clamp(22px,2.8vw,28px)", margin: "10px 0 8px" }}>Have us walk the wall with you.</h3>
          <p style={{ margin: 0, fontSize: 16, color: "var(--text-body)", lineHeight: 1.55, maxWidth: 520 }}>
            An hour on site, sample boards left with you, and a fixed scope in writing within {DB.QUOTE_TURNAROUND}. No charge, no obligation.
          </p>
        </div>
        <div style={{ display: "flex", gap: 12, flexWrap: "wrap" }}>
          <BtnB variant="primary" size="lg" href="/contact" onClick={() => trackCtaB("estimate")}>Request an Estimate</BtnB>
          <BtnB variant="outline" size="lg" href={DB.PHONE.href} onClick={() => trackCtaB("call")} aria-label={`Call now — ${DB.PHONE.display}`} leadingIcon={<IconB name="phone" size={18} />} style={{ color: "var(--stone-800)" }}><CallLabelB numberSize={17} /></BtnB>
        </div>
      </div>
    </div>
  );
}

function LearnPage() {
  useEffB(refB);
  const { loading, visible } = useArticlesB();
  if (loading) return <ArticlesLoading />;
  // Nothing is switched on in /admin → Articles yet: a general page saying
  // more is on the way, rather than an empty index or someone else's page.
  if (visible.length === 0) return <ArticlesEmpty />;

  const featured = visible.find((a) => a.featured) || visible[0];
  const rest = visible.filter((a) => a !== featured);
  const categories = [...new Set(visible.map((a) => a.category))];
  return (
    <div>
      <PH
        eyebrow="Articles"
        title="Learn more about the kinds of projects we do"
        lede="Stone veneer, siding, stucco and masonry repair: how each one works, the choices involved, and what a typical project looks like."
        tint="stone-800"
      />
      <div style={WRAPB}>
        {/* Featured article — the lead, given the width it deserves */}
        <MB.NavLink to={`/learn/${featured.slug}`} style={{ display: "block" }}>
          <CardB interactive style={{ padding: 0, overflow: "hidden" }}>
            <div style={{ display: "grid", gridTemplateColumns: "1.1fr 1fr", alignItems: "stretch" }} className="ma-detail-grid">
              <PhotoB tint={featured.tint} h={300} style={{ borderRadius: 0, height: "100%", minHeight: 260 }} {...articlePhoto(featured)} />
              <div style={{ padding: "34px 32px", display: "flex", flexDirection: "column", justifyContent: "center" }}>
                <div style={{ marginBottom: 12 }}><MB.Badge tone="brick">Featured</MB.Badge></div>
                <div style={{ display: "flex", alignItems: "center", gap: 8, fontSize: 12.5, color: "var(--text-muted)", marginBottom: 10 }}>
                  <span style={{ fontWeight: 600, letterSpacing: "0.1em", textTransform: "uppercase", color: "var(--brick-600)" }}>{featured.category}</span>
                  <span>·</span><span>{featured.date}</span><span>·</span><span>{featured.minutes} min read</span>
                </div>
                <h2 style={{ fontSize: "clamp(24px,3vw,34px)", lineHeight: 1.15, margin: "0 0 14px" }}>{featured.title}</h2>
                <p style={{ fontSize: 16.5, color: "var(--text-body)", lineHeight: 1.6, margin: "0 0 20px" }}>{featured.excerpt}</p>
                <span style={{ fontSize: 15, fontWeight: 600, color: "var(--brick-600)", display: "inline-flex", alignItems: "center", gap: 7 }}>
                  Read the article <IconB name="arrow-right" size={17} />
                </span>
              </div>
            </div>
          </CardB>
        </MB.NavLink>

        {/* What's in here — the topic list doubles as a promise about scope */}
        <div style={{ display: "flex", flexWrap: "wrap", gap: 8, marginTop: 28 }}>
          {categories.map((c) => (
            <span key={c} style={{ fontSize: 13, color: "var(--text-body)", background: "var(--surface-raised)", border: "1px solid var(--border-hairline)", borderRadius: "var(--radius-sm)", padding: "6px 12px" }}>
              {c} · {visible.filter((a) => a.category === c).length}
            </span>
          ))}
        </div>

        {rest.length > 0 && (
          <div style={{ marginTop: 52 }}>
            <SH eyebrow="The Archive" title="Everything else worth reading first" />
            <div style={{ display: "grid", gridTemplateColumns: "repeat(auto-fill,minmax(min(300px,100%),1fr))", gap: 20 }}>
              {rest.map((a) => <ArticleCard key={a.slug} article={a} />)}
            </div>
          </div>
        )}

        <div style={{ marginTop: 52 }}><ArticleCTA /></div>
      </div>
    </div>
  );
}

/* ---------------------------------------------------------- Prose blocks
   The [kind, value] renderer shared by the articles and the privacy policy.
   Both are long-form prose held as plain data in nav-data.js, and both should
   set type the same way — a policy that renders at different measure and
   leading than the rest of the site reads like it was bought off a generator.

   "note" is the one kind articles don't use: a bordered callout for a line
   that has to be findable by someone scanning rather than reading. */
function ProseBlocks({ blocks }) {
  return blocks.map(([kind, value], i) => {
    if (kind === "h") return <h2 key={i} style={{ fontSize: "clamp(21px,2.6vw,26px)", margin: "38px 0 14px" }}>{value}</h2>;
    if (kind === "note") {
      return (
        <div key={i} style={{ background: "var(--surface-raised)", border: "1px solid var(--border-default)", borderLeft: "4px solid var(--brick-500)", borderRadius: "var(--radius-lg)", padding: "20px 24px", margin: "36px 0 0", display: "flex", gap: 16, alignItems: "flex-start" }}>
          <IconB name="mail" size={22} color="var(--brick-500)" style={{ flexShrink: 0, marginTop: 3 }} />
          <p style={{ margin: 0, fontSize: 16.5, lineHeight: 1.6, color: "var(--text-body)", minWidth: 0, overflowWrap: "anywhere" }}>{value}</p>
        </div>
      );
    }
    if (kind === "ul") {
      return (
        <ul key={i} style={{ margin: "0 0 20px", padding: 0, listStyle: "none", display: "flex", flexDirection: "column", gap: 12 }}>
          {value.map((point) => (
            // A neutral marker rather than a green tick: half these
            // lists are the symptoms of a wall in trouble, and a
            // success icon next to "spalling brick" reads as approval.
            <li key={point} style={{ display: "flex", gap: 11, alignItems: "flex-start" }}>
              <IconB name="chevron-right" size={18} color="var(--brick-500)" stroke={2.6} style={{ marginTop: 4 }} />
              <span style={{ fontSize: 17, lineHeight: 1.6, color: "var(--text-body)" }}>{point}</span>
            </li>
          ))}
        </ul>
      );
    }
    return <p key={i} style={{ fontSize: 17.5, lineHeight: 1.75, color: "var(--text-body)", margin: "0 0 20px", textWrap: "pretty" }}>{value}</p>;
  });
}

function ArticlePage({ slug }) {
  useEffB(refB);
  const { loading, visible } = useArticlesB();
  if (loading) return <ArticlesLoading />;
  const article = visible.find((a) => a.slug === slug);
  // An article that doesn't exist or is hidden — a stale link, a typo — lands
  // on the index rather than an error page.
  if (!article) return <LearnPage />;
  const more = visible.filter((a) => a.slug !== article.slug).slice(0, 3);

  return (
    <div>
      <PH eyebrow={`${article.category} · ${article.minutes} min read`} title={article.title} lede={article.excerpt} tint="stone-800" />
      <div style={{ maxWidth: "var(--container-md)", margin: "0 auto", padding: "clamp(40px, 6vw, 60px) var(--gutter)" }}>
        <MB.NavLink to="/learn" style={{ display: "inline-flex", alignItems: "center", gap: 7, fontSize: 14, fontWeight: 600, color: "var(--brick-600)", marginBottom: 26 }}>
          <IconB name="arrow-left" size={16} /> All articles
        </MB.NavLink>

        <article style={{ maxWidth: 720 }}>
          <div style={{ fontSize: 13.5, color: "var(--text-muted)", paddingBottom: 22, marginBottom: 30, borderBottom: "1px solid var(--border-hairline)" }}>
            {article.date} · Mickelsen Accents, Inc.
          </div>
          <ProseBlocks blocks={article.body} />
        </article>

        <div style={{ marginTop: 48 }}><ArticleCTA /></div>

        {more.length > 0 && (
          <div style={{ marginTop: 56 }}>
            <SH eyebrow="Keep Reading" title="More from the crew" />
            <div style={{ display: "grid", gridTemplateColumns: "repeat(auto-fit,minmax(min(260px,100%),1fr))", gap: 18 }}>
              {more.map((a) => <ArticleCard key={a.slug} article={a} h={140} />)}
            </div>
          </div>
        )}
      </div>
    </div>
  );
}

/* ======================================================= COST GUIDE =====
   Predates the blog and keeps its own URL (/cost), because it is linked from
   the nav and from the articles. The owner would rather quote than publish
   prices and has not yet decided whether this page stays, so it is framed as
   context for a quote request rather than as a price list. */
function CostPage() {
  useEffB(refB);
  const planning = useArticlesB().visible.filter((a) => a.category === "Cost & Planning").slice(0, 3);
  return (
    <div>
      <PH eyebrow="Cost Guide" title="What goes into a stone veneer quote" lede="What moves the number, and the ranges we see in the Treasure Valley. Every job is quoted as a fixed scope after we walk the site — request an estimate and we'll give you a real number for yours." />
      <div style={WRAPB}>
        {/* Cost table */}
        <SH eyebrow="Stone Veneer Cost Guide" title="Typical ranges" lede="Your number depends on wall height, material choice, and detail — we quote a fixed scope after we walk the site." />
        <div style={{ border: "1px solid var(--border-hairline)", borderRadius: "var(--radius-lg)", overflow: "hidden", boxShadow: "var(--shadow-sm)" }}>
          {DB.COST_ROWS.map(([scope, range, note], i) => (
            <div key={scope} style={{ display: "grid", gridTemplateColumns: "1.2fr 0.9fr 1.4fr", gap: 16, padding: "18px 22px", alignItems: "center", background: i % 2 ? "var(--surface-page)" : "var(--surface-raised)", borderTop: i ? "1px solid var(--border-hairline)" : "none" }} className="ma-cost-row">
              <span style={{ fontWeight: 600, fontSize: 15.5, color: "var(--text-strong)" }}>{scope}</span>
              <span style={{ fontFamily: "var(--font-mono)", fontSize: 16, color: "var(--brick-600)", fontWeight: 500 }}>{range}</span>
              <span style={{ fontSize: 14, color: "var(--text-muted)" }}>{note}</span>
            </div>
          ))}
        </div>

        {/* Compare */}
        <div style={{ marginTop: 64 }}>
          <SH eyebrow="Compare" title="Stone vs. the alternatives" />
          <div style={{ display: "grid", gridTemplateColumns: "repeat(auto-fit,minmax(min(220px,100%),1fr))", gap: 16 }}>
            {[["Stone Veneer", "50+ yrs"], ["Fiber Cement Siding", "30–50 yrs"], ["Brick", "50+ yrs"], ["Stucco", "30–50 yrs"]].map(([m, life]) => (
              <CardB key={m} padding="lg">
                <h3 style={{ fontSize: 19, margin: "0 0 10px" }}>{m}</h3>
                <div style={{ fontSize: 13.5, color: "var(--text-muted)" }}>
                  <span><strong style={{ color: "var(--text-body)" }}>Lifespan:</strong> {life}</span>
                </div>
              </CardB>
            ))}
          </div>
        </div>

        {/* The numbers answer "how much"; the articles answer everything a
            homeowner asks straight afterwards. Only the ones that are shown. */}
        {planning.length > 0 && (
          <div style={{ marginTop: 56 }}>
            <SH eyebrow="Articles" title="Read before you commit" />
            <div style={{ display: "grid", gridTemplateColumns: "repeat(auto-fit,minmax(min(260px,100%),1fr))", gap: 18 }}>
              {planning.map((a) => <ArticleCard key={a.slug} article={a} h={140} />)}
            </div>
          </div>
        )}
      </div>
    </div>
  );
}

/* ============================================================== ABOUT === */
function AboutPage() {
  useEffB(refB);
  const values = [["hammer", "Done right the first time", "Every job, from a feature wall to a whole elevation, is held to the same standard."], ["ruler", "Done right behind the wall", "The parts you never see — flashing, drainage, and a solid backing — are why masonry outlasts everything around it."], ["handshake", "Straight talk", "We'll tell you when manufactured beats natural, or when a repair beats a rebuild."]];
  return (
    <div>
      <PH eyebrow="About" title="Four generations, one standard" lede="Mickelsen Accents has laid stone across Idaho's Treasure Valley for over twenty years. The name on the truck is the family on the job." />
      <div style={WRAPB}>
        <div style={{ display: "grid", gridTemplateColumns: "1.2fr 1fr", gap: 44, alignItems: "center" }} className="ma-about-grid">
          <div>
            <SH eyebrow="Our Craft" title="Built to last a lifetime" />
            <p style={{ fontSize: 17, lineHeight: 1.65, color: "var(--text-body)" }}>We started as a two-man brick crew and grew the same way we build — one solid course at a time. Today we set brick, block, natural and manufactured stone, siding, and stucco on homes across the Treasure Valley, and we still look at every job and ask if this is good enough for our own home.</p>
            <p style={{ fontSize: 17, lineHeight: 1.65, color: "var(--text-body)" }}>You get the owner on your job, a written warranty, and a crew that treats your property like their own.</p>
          </div>
          {/* A finished fireplace wall until there's a real crew photo — the old
              "The crew, on site" caption would be a claim this picture can't make. */}
          <PhotoB tint="stone-600" h={300} {...DB.photo(DB.ABOUT_PHOTO)} />
        </div>

        <div style={{ marginTop: 56, display: "grid", gridTemplateColumns: "repeat(auto-fit,minmax(min(260px,100%),1fr))", gap: 18 }}>
          {values.map(([ic, t, d]) => (
            <CardB key={t} padding="lg" accent>
              <IconB name={ic} size={26} color="var(--brick-500)" />
              <h3 style={{ fontSize: 20, margin: "12px 0 8px" }}>{t}</h3>
              <p style={{ fontSize: 15, color: "var(--text-body)", margin: 0, lineHeight: 1.55 }}>{d}</p>
            </CardB>
          ))}
        </div>

        {/* Reviews */}
        <div style={{ marginTop: 56 }}>
          <SH eyebrow="Reviews" title="What homeowners say" center />
          <div style={{ display: "grid", gridTemplateColumns: "repeat(auto-fit,minmax(min(280px,100%),1fr))", gap: 18 }}>
            {[["They refaced our chimney and we ended up doing the whole front. Best decision we've made on this house.", "— Dana R., Boise"], ["Plumb, level, clean, on time. The joint work is genuinely beautiful.", "— Marcus T., Meridian"], ["Told us honestly that a repair would hold instead of selling us a rebuild. Earned a customer for life.", "— The Alveys, Nampa"]].map(([q, who]) => (
              <CardB key={who} padding="lg">
                <div style={{ display: "flex", gap: 3, marginBottom: 10 }}>{[0,1,2,3,4].map((i) => <IconB key={i} name="star" size={16} color="var(--sand-400)" stroke={0} style={{ fill: "var(--sand-400)" }} />)}</div>
                <p style={{ fontFamily: "var(--font-display)", fontSize: 17, lineHeight: 1.45, color: "var(--text-strong)", margin: "0 0 12px" }}>"{q}"</p>
                <div style={{ fontSize: 14, color: "var(--text-muted)" }}>{who}</div>
              </CardB>
            ))}
          </div>
        </div>
      </div>
    </div>
  );
}

/* ============================================================ CONTACT === */
function ContactPage() {
  useEffB(refB);
  return (
    <div>
      <PH eyebrow="Free On-Site Estimate" title="Send us your plans" lede={`Tell us about the project — scope, location, and timeline. We'll walk the site and give you a real number within ${DB.QUOTE_TURNAROUND}.`} />
      <div style={{ maxWidth: "var(--container-md)", margin: "0 auto", padding: "56px var(--gutter)" }}>
        <CardB padding="lg">
          <ContactForm
            submitLabel="Request My Estimate"
            sectors={DB.SERVICE_COLUMNS.map((c) => c.title).concat("Repair or restoration", "Not sure yet")}
          />
        </CardB>
        <div style={{ display: "grid", gridTemplateColumns: "repeat(auto-fit,minmax(min(200px,100%),1fr))", gap: 16, marginTop: 24 }}>
          {[
            ["phone", "Call", DB.PHONE.display, DB.PHONE.href, "call"],
            ["mail", "Email", DB.EMAIL, `mailto:${DB.EMAIL}`, null],
            ["map-pin", "Visit", DB.ADDRESS.display, null, null],
            ["clock", "Hours", `${DB.HOURS.display} · ${DB.HOURS.note}`, null, null],
          ].map(([ic, label, value, href, cta]) => (
            <div key={label} style={{ display: "flex", gap: 12, alignItems: "flex-start", background: "var(--surface-raised)", border: "1px solid var(--border-hairline)", borderRadius: "var(--radius-lg)", padding: "16px 18px" }}>
              <IconB name={ic} size={20} color="var(--brick-500)" style={{ marginTop: 2 }} />
              {/* `minWidth: 0` + `overflowWrap` so a long email address wraps
                  inside its card instead of running out of it. */}
              <div style={{ minWidth: 0 }}>
                <div style={{ fontSize: 11, fontWeight: 600, letterSpacing: "0.14em", textTransform: "uppercase", color: "var(--text-muted)" }}>{label}</div>
                {href
                  ? <a href={href} onClick={cta ? () => trackCtaB(cta) : undefined} style={{ fontSize: 15, fontWeight: 600, color: "var(--text-strong)", borderBottom: "none", textDecoration: "none", overflowWrap: "anywhere" }}>{value}</a>
                  : <div style={{ fontSize: 15, color: "var(--text-body)", lineHeight: 1.45 }}>{value}</div>}
              </div>
            </div>
          ))}
        </div>
        <p style={{ textAlign: "center", fontSize: 14, color: "var(--text-muted)", marginTop: 20 }}>
          Serving {DB.AREAS.slice(0, 6).map(([c]) => c).join(", ")} and the wider Treasure Valley.
        </p>
      </div>
    </div>
  );
}

/* ============================================================ PRIVACY ===
   Reachable from the footer and from the fine print under both forms. It is
   set at the articles' measure rather than the full page width, because the
   only thing worse than an unread policy is one that's unreadable. */
function PrivacyPage() {
  useEffB(refB);
  const { PRIVACY } = DB;
  return (
    <div>
      <PH eyebrow="Privacy" title="What we collect, and what we don't" lede={PRIVACY.lede} tint="stone-800" />
      <div style={{ maxWidth: "var(--container-md)", margin: "0 auto", padding: "clamp(40px, 6vw, 60px) var(--gutter)" }}>
        <article style={{ maxWidth: 720 }}>
          <div style={{ fontSize: 13.5, color: "var(--text-muted)", paddingBottom: 22, marginBottom: 30, borderBottom: "1px solid var(--border-hairline)" }}>
            Last updated {PRIVACY.updated} · Mickelsen Accents, Inc.
          </div>
          <ProseBlocks blocks={PRIVACY.blocks} />
        </article>
      </div>
    </div>
  );
}

Object.assign(window, { MA_PAGES_B: { CommercialPage, GalleryPage, LearnPage, ArticlePage, CostPage, AboutPage, ContactPage, PrivacyPage, ContactForm, GalleryCarousel, Lightbox } });
