// Store-finder page for Xedap.vn — layout: intro card → system picker + search + list/map → galleries → contact table.
// Exports a single unique global: StoreLocator.
const { Button, Card } = window.XedapVnDesignSystem_03b1c0;

const STORE_PROVINCES = [
  "TP. Hồ Chí Minh", "Thành phố Hà Nội", "Thành phố Đà Nẵng",
  "Thành phố Cần Thơ", "Tỉnh Bình Dương", "Tỉnh Đồng Nai", "Tỉnh Khánh Hòa",
];

const STORE_LIST = [
  { name: "Nguyễn Cơ Thạch", coord: [10.7746, 106.7217], city: "TP. Hồ Chí Minh", district: "TP. Thủ Đức", address: "Shop B1-00.05, Sarimi, 72 Nguyễn Cơ Thạch, P. An Khánh, TP. Thủ Đức", phone: "1800 9473", hours: "08:00 - 21:00" },
  { name: "Nguyễn Duy Trinh", coord: [10.7856, 106.7615], city: "TP. Hồ Chí Minh", district: "TP. Thủ Đức", address: "585 Nguyễn Duy Trinh, P. Bình Trưng, TP. Thủ Đức", phone: "1800 9473", hours: "09:00 - 21:00" },
  { name: "Võ Thị Sáu", coord: [10.7869, 106.6903], city: "TP. Hồ Chí Minh", district: "Quận 3", address: "63C Võ Thị Sáu, P. Võ Thị Sáu", phone: "1800 9473", hours: "09:00 - 21:00" },
  { name: "Đặng Văn Bi", coord: [10.8492, 106.7546], city: "TP. Hồ Chí Minh", district: "TP. Thủ Đức", address: "200-202 Đặng Văn Bi, P. Thủ Đức, TP. Thủ Đức", phone: "1800 9473", hours: "09:00 - 21:00" },
  { name: "Nguyễn Thị Thập", coord: [10.7405, 106.7059], city: "TP. Hồ Chí Minh", district: "Quận 7", address: "458 Nguyễn Thị Thập, P. Tân Hưng", phone: "1800 9473", hours: "09:00 - 21:00", tag: "TRUNG TÂM KỸ THUẬT" },
  { name: "Hải Thượng Lãn Ông", coord: [10.7524, 106.6547], city: "TP. Hồ Chí Minh", district: "Quận 5", address: "100 Hải Thượng Lãn Ông, P. Chợ Lớn", phone: "1800 9473", hours: "09:00 - 19:00" },
  { name: "Bờ Bao Tân Thắng", coord: [10.801, 106.6193], city: "TP. Hồ Chí Minh", district: "Tân Phú", address: "93C Bờ Bao Tân Thắng, P. Tân Thành", phone: "1800 9473", hours: "09:00 - 21:00" },
  { name: "Tên Lửa - Bình Tân", coord: [10.7448, 106.6116], city: "TP. Hồ Chí Minh", district: "Bình Tân", address: "122 Tên Lửa, P. An Lạc", phone: "1800 9473", hours: "09:00 - 21:00" },
  { name: "Tô Ký - Hóc Môn", coord: [10.8722, 106.6206], city: "TP. Hồ Chí Minh", district: "Hóc Môn", address: "14/1A Tô Ký, Xã Đông Thạnh", phone: "1800 9473", hours: "09:00 - 21:00" },
  { name: "Emart Gò Vấp", coord: [10.8355, 106.669], city: "TP. Hồ Chí Minh", district: "Gò Vấp", address: "366 Phan Văn Trị, P. An Nhơn", phone: "1800 9473", hours: "09:00 - 21:00" },
  { name: "Emart Phan Huy Ích", coord: [10.842, 106.632], city: "TP. Hồ Chí Minh", district: "Gò Vấp", address: "385 Phan Huy Ích, P. An Hội Tây", phone: "1800 9473", hours: "07:30 - 22:30" },
  { name: "Nguyễn Oanh - Gò Vấp", coord: [10.8332, 106.6784], city: "TP. Hồ Chí Minh", district: "Gò Vấp", address: "144 Nguyễn Oanh, Gò Vấp", phone: "090 551 1144", hours: "09:00 - 21:00" },
  { name: "Phạm Văn Đồng - Hà Nội", coord: [21.0709, 105.7876], city: "Thành phố Hà Nội", district: "Bắc Từ Liêm", address: "427 Phạm Văn Đồng, P. Xuân Đỉnh", phone: "1800 9473", hours: "09:00 - 21:00" },
  { name: "Thái Hà - Hà Nội", coord: [21.0122, 105.8195], city: "Thành phố Hà Nội", district: "Đống Đa", address: "112 Thái Hà, P. Trung Liệt", phone: "1800 9473", hours: "09:00 - 21:00" },
  { name: "Nguyễn Văn Cừ - Hà Nội", coord: [21.0459, 105.8724], city: "Thành phố Hà Nội", district: "Long Biên", address: "215 Nguyễn Văn Cừ, P. Ngọc Lâm", phone: "1800 9473", hours: "09:00 - 21:00", tag: "TRUNG TÂM KỸ THUẬT" },
  { name: "Nguyễn Văn Linh - Đà Nẵng", coord: [16.0603, 108.2166], city: "Thành phố Đà Nẵng", district: "Hải Châu", address: "175 Nguyễn Văn Linh, P. Nam Dương", phone: "1800 9473", hours: "08:30 - 21:00" },
  { name: "Ngô Quyền - Đà Nẵng", coord: [16.0678, 108.2306], city: "Thành phố Đà Nẵng", district: "Sơn Trà", address: "388 Ngô Quyền, P. An Hải Bắc", phone: "1800 9473", hours: "09:00 - 21:00" },
  { name: "Nguyễn Văn Cừ - Cần Thơ", coord: [10.0284, 105.7563], city: "Thành phố Cần Thơ", district: "Ninh Kiều", address: "126 Nguyễn Văn Cừ, P. An Hòa", phone: "1800 9473", hours: "08:30 - 21:00" },
  { name: "30/4 - Cần Thơ", coord: [10.0233, 105.7739], city: "Thành phố Cần Thơ", district: "Ninh Kiều", address: "88 Đường 30/4, P. Hưng Lợi", phone: "1800 9473", hours: "09:00 - 20:30" },
  { name: "Đại lộ Bình Dương", coord: [10.9804, 106.6519], city: "Tỉnh Bình Dương", district: "TP. Thủ Dầu Một", address: "512 Đại lộ Bình Dương, P. Hiệp Thành", phone: "1800 9473", hours: "08:30 - 21:00" },
  { name: "Dĩ An - Bình Dương", coord: [10.9063, 106.7694], city: "Tỉnh Bình Dương", district: "TP. Dĩ An", address: "29 Nguyễn An Ninh, P. Dĩ An", phone: "1800 9473", hours: "09:00 - 21:00", tag: "TRẠM BẢO HÀNH" },
];

const STORE_SYSTEMS = [
  { id: "showroom", label: "Xedap.vn", note: "(Hệ thống showroom bán lẻ)" },
  { id: "service", label: "Xedap Service", note: "(Trung tâm kỹ thuật - bảo dưỡng)" },
  { id: "warranty", label: "Xedap Care", note: "(Trạm bảo hành uỷ quyền)" },
];

const STORE_STATS = [
  { key: "showroom", src: "../../assets/logo-full.png", logo: "Logo Xedap.vn", value: "13 cửa hàng" },
  { key: "member", src: "https://cdn.hstatic.net/files/200001188264/file/member.png", logo: "Logo Member", value: ">120.000 Xedap Member" },
  { key: "service", src: "https://cdn.hstatic.net/files/200001188264/file/screen_shot_2021-03-18_at_9.11.20_pm__43394.webp", logo: "Logo Service", value: "6 trung tâm kỹ thuật" },
  { key: "care", src: "https://cdn.hstatic.net/files/200001188264/file/logo_brand_xedap.svg", logo: "Logo Care", value: "4 trạm bảo hành" },
];

const STORE_AMENITIES = [
  { icon: "ph-shield-check", label: "Bảo hành chính hãng" },
  { icon: "ph-arrows-clockwise", label: "Đổi trả 1 - 12 tháng" },
  { icon: "ph-credit-card", label: "Trả góp 0% lãi suất" },
  { icon: "ph-truck", label: "Giao & lắp xe tận nơi" },
  { icon: "ph-bicycle", label: "Chạy thử xe miễn phí" },
];

const STORE_GALLERIES = [
  { key: "showroom", title: "Dạo online showroom Xedap.vn", shots: ["Mặt tiền showroom", "Khu trưng bày xe đạp thể thao", "Quầy phụ kiện & đồ bảo hộ", "Khu trải nghiệm xe điện", "Tư vấn chọn size xe"] },
  { key: "service", title: "Dạo online trung tâm kỹ thuật Xedap Service", shots: ["Khu tiếp nhận xe", "Bàn cân chỉnh groupset", "Khu vệ sinh & bảo dưỡng", "Kho phụ tùng chính hãng", "Kỹ thuật viên kiểm tra xe"] },
];

// Bản đồ Google Maps nhúng (style mặc định của Google, ghim đỏ + thẻ thông tin).
// Khi có API key nên chuyển sang Maps Embed API chính thức:
// https://www.google.com/maps/embed/v1/place?key=<KEY>&q=<lat,lng>&zoom=15
function StoreLocatorMap({ stores, activeIndex, onSelect }) {
  const store = stores[activeIndex] || stores[0];
  const c = (store && store.coord) || [10.7769, 106.7009];
  const src = `https://maps.google.com/maps?q=${c[0]},${c[1]}&z=15&hl=vi&output=embed`;
  return (
    <React.Fragment>
      <iframe key={src} title="Bản đồ cửa hàng" src={src} loading="lazy" referrerPolicy="no-referrer-when-downgrade" style={{ position: "absolute", inset: 0, width: "100%", height: "100%", border: "none" }}></iframe>
      {store ? (
        <div style={{ position: "absolute", left: 16, top: 16, maxWidth: 320, background: "#fff", borderRadius: 8, boxShadow: "0 2px 12px rgba(15,23,42,.24)", padding: "14px 16px", display: "flex", gap: 12, alignItems: "flex-start" }}>
          <div style={{ minWidth: 0 }}>
            <div style={{ fontSize: "calc(13px + 2.5px*var(--ts))", fontWeight: 700, lineHeight: 1.35 }}>Xedap.vn {store.name}</div>
            <div style={{ marginTop: 4, fontSize: 13, lineHeight: 1.45, color: "var(--muted-foreground)" }}>{store.address}</div>
            <div style={{ marginTop: 6, fontSize: 13, color: "var(--muted-foreground)" }}>{store.hours} · {store.phone}</div>
          </div>
          <a href={`https://www.google.com/maps/dir/?api=1&destination=${c[0]},${c[1]}`} target="_blank" rel="noreferrer" aria-label="Chỉ đường" style={{ flexShrink: 0, width: 36, height: 36, borderRadius: "50%", background: "var(--primary)", color: "#fff", display: "grid", placeItems: "center", textDecoration: "none" }}>
            <i className="ph-fill ph-navigation-arrow" style={{ fontSize: "calc(13px + 3px*var(--ts))" }}></i>
          </a>
        </div>
      ) : null}
    </React.Fragment>
  );
}

function storeLocatorMapLink(store) {
  const c = (store && store.coord) || [10.7769, 106.7009];
  return `https://www.openstreetmap.org/?mlat=${c[0]}&mlon=${c[1]}#map=15/${c[0]}/${c[1]}`;
}

function StoreLocatorSelect({ value, onChange, options, placeholder }) {
  return (
    <div style={{ position: "relative", flex: 1, minWidth: 180 }}>
      <select value={value} onChange={(e) => onChange(e.target.value)} style={{
        width: "100%", appearance: "none", WebkitAppearance: "none",
        padding: "13px 42px 13px 16px", borderRadius: "var(--radius)",
        border: "1px solid var(--input, #cccccc)", background: "#fff",
        fontFamily: "var(--font-sans)", fontSize: "calc(13px + 1.5px*var(--ts))", fontWeight: 500,
        color: value ? "var(--foreground)" : "var(--muted-foreground)", cursor: "pointer",
      }}>
        <option value="">{placeholder}</option>
        {options.map((o) => <option key={o} value={o}>{o}</option>)}
      </select>
      <i className="ph ph-caret-down" style={{ position: "absolute", right: 15, top: "50%", transform: "translateY(-50%)", pointerEvents: "none", color: "var(--muted-foreground)", fontSize: "calc(13px + 2px*var(--ts))" }}></i>
    </div>
  );
}

function StoreLocatorRow({ store, active, onSelect }) {
  const go = (e) => { e.preventDefault(); window.location.href = "cua-hang-nguyen-co-thach.html#" + encodeURIComponent(store.name); };
  const pill = { flex: 1, display: "inline-flex", alignItems: "center", justifyContent: "center", gap: 6, padding: "6px 8px", borderRadius: 999, border: "1px solid var(--primary)", background: "#fff", color: "var(--primary)", font: "inherit", fontSize: 12.5, fontWeight: 600, textDecoration: "none", cursor: "pointer", whiteSpace: "nowrap" };
  return (
    <div onClick={onSelect} style={{ padding: "14px 16px", borderRadius: "var(--radius)", border: "1px solid " + (active ? "#c9cffb" : "var(--border)"), background: active ? "var(--accent, #eef0fe)" : "#fff", cursor: "pointer" }}>
      <a href="cua-hang-nguyen-co-thach.html" onClick={go} style={{ display: "block", fontSize: "calc(13px + 1px*var(--ts))", fontWeight: 700, lineHeight: 1.5, color: "var(--foreground)", textDecoration: "none" }}>
        {store.address}
      </a>
      {store.tag ? (
        <div style={{ marginTop: 7, display: "inline-flex", alignItems: "center", gap: 7, fontSize: 12, fontWeight: 800, letterSpacing: "0.02em", color: "var(--primary)" }}>
          <i className="ph-fill ph-sparkle" style={{ fontSize: "calc(13px + 1px*var(--ts))" }}></i>{store.tag}
        </div>
      ) : null}
      <div style={{ marginTop: 9, display: "flex", flexDirection: "column", gap: 6, fontSize: "calc(13px + 0.5px*var(--ts))", color: "var(--muted-foreground)" }}>
        <span style={{ display: "inline-flex", alignItems: "center", gap: 9 }}><i className="ph ph-map-pin" style={{ fontSize: "calc(13px + 2.5px*var(--ts))" }}></i>{store.hours} (tất cả các ngày trong tuần)</span>
        <span style={{ display: "inline-flex", alignItems: "center", gap: 9 }}><i className="ph ph-phone" style={{ fontSize: "calc(13px + 2.5px*var(--ts))" }}></i>{store.phone}</span>
      </div>
      <div style={{ marginTop: 12, display: "flex", alignItems: "center", gap: 8 }}>
        <a href="tel:18009473" onClick={(e) => e.stopPropagation()} style={pill}>Gọi điện</a>
        <a href="#" onClick={(e) => { e.preventDefault(); e.stopPropagation(); }} style={pill}>Chat Zalo</a>
        <a href={storeLocatorMapLink(store)} target="_blank" rel="noreferrer" onClick={(e) => e.stopPropagation()} style={pill}>Xem đường đi</a>
      </div>
    </div>
  );
}

function StoreLocatorGallery({ item }) {
  const [page, setPage] = React.useState(0);
  const pages = 3;
  return (
    <section style={{ marginTop: 40 }}>
      <h2 style={{ margin: "0 0 16px", fontSize: "calc(13px + 6px*var(--ts))", fontWeight: 800, fontFamily: "var(--font-heading)", letterSpacing: "-0.01em", color: "var(--primary)" }}>{item.title}</h2>
      <div style={{ position: "relative" }}>
        <div style={{ display: "grid", gridTemplateColumns: "repeat(5, 1fr)", gap: 12 }}>
          {item.shots.map((s, i) => (
            <div key={i} style={{ aspectRatio: "4/3", borderRadius: "var(--radius)", overflow: "hidden", background: "var(--secondary)", border: "1px solid var(--border)" }}>
              <image-slot id={`store-v2-${item.key}-${page}-${i}`} shape="rect" fit="cover" placeholder={`${s} — 800×600`} style={{ width: "100%", height: "100%", display: "block" }}></image-slot>
            </div>
          ))}
        </div>
        <button onClick={() => setPage((page + 1) % pages)} aria-label="Ảnh tiếp theo" style={{ position: "absolute", right: -14, top: "50%", transform: "translateY(-50%)", width: 34, height: 34, borderRadius: "50%", border: "1px solid var(--border)", background: "#fff", boxShadow: "0 2px 10px rgba(15,23,42,0.12)", cursor: "pointer", display: "grid", placeItems: "center" }}>
          <i className="ph ph-caret-right" style={{ fontSize: "calc(13px + 3px*var(--ts))" }}></i>
        </button>
      </div>
      <div style={{ marginTop: 14, display: "flex", justifyContent: "center", gap: 8 }}>
        {Array.from({ length: pages }).map((_, i) => (
          <button key={i} onClick={() => setPage(i)} aria-label={`Trang ${i + 1}`} style={{ width: 8, height: 8, padding: 0, borderRadius: "50%", border: "none", cursor: "pointer", background: i === page ? "var(--primary)" : "var(--border)" }}></button>
        ))}
      </div>
    </section>
  );
}

// Popup: toàn bộ cửa hàng trong hệ thống, gom nhóm theo tỉnh/thành phố.
function StoreLocatorAllModal({ onClose, onPick }) {
  const [q, setQ] = React.useState("");
  React.useEffect(() => {
    const esc = (e) => { if (e.key === "Escape") onClose(); };
    window.addEventListener("keydown", esc);
    return () => window.removeEventListener("keydown", esc);
  }, [onClose]);
  const norm = (s) => s.toLowerCase();
  const matched = STORE_LIST.filter((s) => !q.trim() || norm(s.name + " " + s.address + " " + s.district + " " + s.city).includes(norm(q.trim())));
  const groups = STORE_PROVINCES.map((p) => ({ province: p, stores: matched.filter((s) => s.city === p) })).filter((g) => g.stores.length);
  return (
    <div onClick={onClose} role="dialog" aria-modal="true" aria-label="Danh sách toàn bộ cửa hàng" style={{ position: "fixed", inset: 0, zIndex: 120, background: "rgba(15,23,42,0.55)", display: "grid", placeItems: "center", padding: 24 }}>
      <div onClick={(e) => e.stopPropagation()} style={{ width: "min(960px, 100%)", maxHeight: "86vh", display: "flex", flexDirection: "column", background: "#fff", borderRadius: "var(--radius-lg)", overflow: "hidden", boxShadow: "0 24px 64px rgba(15,23,42,0.32)" }}>
        <div style={{ flexShrink: 0, padding: "18px 22px", borderBottom: "1px solid var(--border)", display: "flex", alignItems: "center", gap: 16 }}>
          <div style={{ minWidth: 0 }}>
            <div style={{ fontSize: "calc(13px + 4px*var(--ts))", fontWeight: 800, fontFamily: "var(--font-heading)", letterSpacing: "-0.01em", color: "var(--primary)" }}>Toàn bộ hệ thống cửa hàng</div>
            <div style={{ marginTop: 3, fontSize: 13, color: "var(--muted-foreground)" }}>{matched.length} cửa hàng tại {groups.length} tỉnh/thành phố</div>
          </div>
          <div style={{ position: "relative", marginLeft: "auto", flex: "0 1 280px" }}>
            <i className="ph ph-magnifying-glass" style={{ position: "absolute", left: 13, top: "50%", transform: "translateY(-50%)", color: "var(--muted-foreground)", fontSize: "calc(13px + 2px*var(--ts))" }}></i>
            <input value={q} onChange={(e) => setQ(e.target.value)} placeholder="Tìm theo tên, địa chỉ, quận/huyện" style={{ width: "100%", boxSizing: "border-box", padding: "10px 14px 10px 38px", borderRadius: "var(--radius)", border: "1px solid var(--input, #cccccc)", background: "#fff", fontFamily: "var(--font-sans)", fontSize: "calc(13px + 0.5px*var(--ts))" }} />
          </div>
          <button onClick={onClose} aria-label="Đóng" style={{ flexShrink: 0, width: 38, height: 38, borderRadius: "50%", border: "1px solid var(--border)", background: "#fff", cursor: "pointer", display: "grid", placeItems: "center" }}>
            <i className="ph ph-x" style={{ fontSize: "calc(13px + 3px*var(--ts))" }}></i>
          </button>
        </div>
        <div style={{ overflowY: "auto", padding: "4px 22px 22px" }}>
          {groups.length === 0 ? (
            <div style={{ padding: "40px 0", textAlign: "center", fontSize: "calc(13px + 1px*var(--ts))", color: "var(--muted-foreground)" }}>Không tìm thấy cửa hàng phù hợp.</div>
          ) : groups.map((g) => (
            <section key={g.province} style={{ marginTop: 18 }}>
              <div style={{ paddingBottom: 8, display: "flex", alignItems: "center", gap: 10 }}>
                <i className="ph-fill ph-map-pin-line" style={{ fontSize: "calc(13px + 4px*var(--ts))", color: "var(--primary)" }}></i>
                <h3 style={{ margin: 0, fontSize: "calc(13px + 2px*var(--ts))", fontWeight: 800, letterSpacing: "0.01em" }}>{g.province}</h3>
                <span style={{ fontSize: 12, fontWeight: 700, color: "var(--primary)", background: "var(--accent, #eef0fe)", padding: "3px 9px", borderRadius: 999 }}>{g.stores.length}</span>
                <span style={{ flex: 1, height: 1, background: "var(--border)" }}></span>
              </div>
              <div style={{ display: "grid", gridTemplateColumns: "repeat(auto-fill, minmax(280px, 1fr))", gap: 10 }}>
                {g.stores.map((s) => (
                  <button key={s.name} onClick={() => onPick(s)} style={{ textAlign: "left", font: "inherit", cursor: "pointer", padding: "13px 15px", borderRadius: "var(--radius)", border: "1px solid var(--border)", background: "var(--secondary, #f5f6fb)", display: "flex", flexDirection: "column", gap: 6 }}>
                    <span style={{ fontSize: "calc(13px + 1.5px*var(--ts))", fontWeight: 700, color: "var(--primary)", lineHeight: 1.4 }}>Xedap.vn {s.name}</span>
                    <span style={{ fontSize: 13, lineHeight: 1.5, color: "var(--muted-foreground)" }}>{s.address}</span>
                    <span style={{ display: "flex", flexWrap: "wrap", gap: "4px 14px", fontSize: 12.5, color: "var(--muted-foreground)" }}>
                      <span style={{ display: "inline-flex", alignItems: "center", gap: 6 }}><i className="ph ph-clock"></i>{s.hours}</span>
                      <span style={{ display: "inline-flex", alignItems: "center", gap: 6 }}><i className="ph ph-phone"></i>{s.phone}</span>
                    </span>
                    {s.tag ? <span style={{ display: "inline-flex", alignItems: "center", gap: 6, fontSize: 11.5, fontWeight: 800, letterSpacing: "0.02em", color: "var(--primary)" }}><i className="ph-fill ph-sparkle"></i>{s.tag}</span> : null}
                  </button>
                ))}
              </div>
            </section>
          ))}
        </div>
      </div>
    </div>
  );
}

function StoreLocator() {
  const [system, setSystem] = React.useState("showroom");
  const [allOpen, setAllOpen] = React.useState(false);
  const [province, setProvince] = React.useState("TP. Hồ Chí Minh");
  const [district, setDistrict] = React.useState("");
  const [query, setQuery] = React.useState("");
  const [activeStore, setActiveStore] = React.useState(0);

  const list = STORE_LIST.filter((s) => (!province || s.city === province) && (!district || s.district === district));
  const districts = Array.from(new Set(STORE_LIST.filter((s) => !province || s.city === province).map((s) => s.district)));

  return (
    <main style={{ paddingTop: 106, background: "#fff" }}>
      <style>{`.store-locator-scroll{scrollbar-width:thin;scrollbar-color:var(--accent,#eef0fe) transparent}.store-locator-scroll::-webkit-scrollbar{width:6px}.store-locator-scroll::-webkit-scrollbar-track{background:transparent}.store-locator-scroll::-webkit-scrollbar-thumb{background:var(--accent,#eef0fe);border-radius:999px}.store-locator-scroll:hover::-webkit-scrollbar-thumb{background:#c9cffb}.store-locator-intro{display:grid;grid-template-columns:360px minmax(0,1fr);gap:28px;align-items:start}@media (max-width:1100px){.store-locator-intro{grid-template-columns:280px minmax(0,1fr)}}@media (max-width:700px){.store-locator-intro{grid-template-columns:minmax(0,1fr)}}@media (max-width:640px){.store-locator-stats{grid-template-columns:repeat(2,minmax(0,1fr))}}.store-locator-contact{display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1.05fr);gap:28px;align-items:start}@media (max-width:860px){.store-locator-contact{grid-template-columns:minmax(0,1fr)}}`}</style>
      <div style={{ maxWidth: 1280, margin: "0 auto", padding: "28px 24px 72px" }}>

        {/* INTRO — ảnh + số liệu hệ thống + giới thiệu */}
        <Card style={{ padding: 28 }}>
          <div className="store-locator-intro">
          <div style={{ aspectRatio: "1.4 / 1", borderRadius: "var(--radius)", overflow: "hidden", background: "var(--secondary)", border: "1px solid var(--border)" }}>
            <image-slot id="store-intro-photo-v2" shape="rect" fit="cover" placeholder="Ảnh mặt tiền showroom Xedap.vn — 1200×900" style={{ width: "100%", height: "100%", display: "block" }}></image-slot>
          </div>
          <div>
            <div className="store-locator-stats" style={{ display: "grid", gridTemplateColumns: "repeat(4, minmax(0, 1fr))", gap: "22px 18px", padding: "6px 0 4px" }}>
              {STORE_STATS.map((s) => (
                <div key={s.key} style={{ display: "flex", flexDirection: "column", alignItems: "center", gap: 14, minWidth: 0, textAlign: "center" }}>
                  <div style={{ width: "100%", maxWidth: 104, aspectRatio: "1 / 1", display: "grid", placeItems: "center" }}>
                    {s.src
                      ? <img src={s.src} alt={s.logo} style={{ width: "100%", height: "100%", objectFit: "contain", display: "block" }} />
                      : <image-slot id={`store-intro-logo-${s.key}`} shape="rect" fit="contain" placeholder={s.logo} style={{ width: "100%", height: "100%", aspectRatio: "1 / 1", display: "block" }}></image-slot>}
                  </div>
                  <div style={{ fontSize: "calc(13px + 1.5px*var(--ts))", fontWeight: 800, lineHeight: 1.3, color: "var(--primary)" }}>{s.value}</div>
                </div>
              ))}
            </div>
            <p style={{ margin: "26px 0 0", fontSize: "calc(13px + 1.5px*var(--ts))", lineHeight: 1.85, color: "var(--primary)", textWrap: "pretty" }}>
              Xedap.vn là hệ thống bán lẻ chính hãng xe đạp thể thao, xe đạp trẻ em, xe đạp điện và phụ kiện của Giant, Trek, Specialized, Cannondale, Java, Fornix… Tất cả showroom đều có khu chạy thử, dịch vụ đo size và lắp ráp hoàn thiện trước khi giao xe. Xedap Service là chuỗi trung tâm kỹ thuật bảo dưỡng - sửa chữa - nâng cấp xe, còn Xedap Care là các trạm bảo hành uỷ quyền của hãng. Toàn hệ thống áp dụng trả góp 0% lãi suất, đổi trả từ 1 - 12 tháng và miễn phí giao lắp tận nhà.
            </p>
          </div>
          </div>
        </Card>

        {/* TIỆN ÍCH */}
        <div style={{ marginTop: 16, display: "grid", gridTemplateColumns: "repeat(5, 1fr)", gap: 12 }}>
          {STORE_AMENITIES.map((a) => (
            <div key={a.label} style={{ display: "flex", alignItems: "center", gap: 10, padding: "12px 14px", borderRadius: "var(--radius)", border: "1px solid var(--border)", background: "var(--secondary, #f5f6fb)" }}>
              <i className={"ph " + a.icon} style={{ fontSize: "calc(13px + 7px*var(--ts))", color: "var(--primary)", flexShrink: 0 }}></i>
              <span style={{ fontSize: "calc(13px + 0.5px*var(--ts))", fontWeight: 600, lineHeight: 1.35 }}>{a.label}</span>
            </div>
          ))}
        </div>

        {/* BỘ LỌC + DANH SÁCH + BẢN ĐỒ */}
        <div style={{ marginTop: 24, borderRadius: "var(--radius-lg)", overflow: "hidden", border: "1px solid var(--border)" }}>
          <div style={{ background: "var(--primary, #142ff7)", padding: "22px 24px 26px", color: "#fff" }}>

          <div style={{ display: "flex", alignItems: "center", gap: 16, flexWrap: "wrap" }}>
            <h2 style={{ margin: 0, fontSize: "calc(13px + 5px*var(--ts))", fontWeight: 800, fontFamily: "var(--font-heading)", letterSpacing: "-0.01em", color: "#fff" }}>Tìm cửa hàng gần bạn</h2>
            <button onClick={() => setAllOpen(true)} style={{ marginLeft: "auto", display: "inline-flex", alignItems: "center", gap: 8, padding: "11px 18px", borderRadius: 999, border: "1px solid rgba(255,255,255,0.55)", background: "transparent", color: "#fff", font: "inherit", fontSize: "calc(13px + 0.5px*var(--ts))", fontWeight: 700, cursor: "pointer", whiteSpace: "nowrap" }}>
              <i className="ph-fill ph-list-bullets" style={{ fontSize: "calc(13px + 3px*var(--ts))" }}></i>Danh sách toàn bộ cửa hàng
            </button>
          </div>

          <div style={{ marginTop: 16, display: "grid", gridTemplateColumns: "minmax(0,1.4fr) minmax(0,1fr) minmax(0,1fr)", gap: 12 }}>
            <div style={{ position: "relative" }}>
              <i className="ph ph-magnifying-glass" style={{ position: "absolute", left: 15, top: "50%", transform: "translateY(-50%)", color: "var(--muted-foreground)", fontSize: "calc(13px + 3px*var(--ts))" }}></i>
              <input value={query} onChange={(e) => setQuery(e.target.value)} placeholder="Nhập vị trí để tìm cửa hàng gần nhất" style={{ width: "100%", boxSizing: "border-box", padding: "13px 16px 13px 42px", borderRadius: "var(--radius)", border: "1px solid var(--input, #cccccc)", background: "#fff", fontFamily: "var(--font-sans)", fontSize: "calc(13px + 1.5px*var(--ts))" }} />
            </div>
            <StoreLocatorSelect value={province} onChange={(v) => { setProvince(v); setDistrict(""); }} options={STORE_PROVINCES} placeholder="Chọn tỉnh/thành phố" />
            <StoreLocatorSelect value={district} onChange={setDistrict} options={districts} placeholder="Chọn quận/huyện" />
          </div>
          </div>

          <div style={{ background: "var(--secondary, #f5f6fb)", padding: 20, display: "grid", gridTemplateColumns: "repeat(auto-fit, minmax(320px, 1fr))", gap: 18, alignItems: "start" }}>
            <div style={{ background: "#fff", borderRadius: "var(--radius)", border: "1px solid var(--border)", padding: 16, display: "flex", flexDirection: "column", maxHeight: 620, boxSizing: "border-box" }}>
              <div style={{ padding: "12px 18px", borderRadius: "var(--radius)", background: "var(--primary, #142ff7)", color: "#fff", fontSize: "calc(13px + 3px*var(--ts))", fontWeight: 800, fontFamily: "var(--font-heading)", letterSpacing: "-0.01em", flexShrink: 0 }}>
                Có {list.length} cửa hàng gần bạn
              </div>
              <div className="store-locator-scroll" style={{ marginTop: 14, overflowY: "auto", display: "flex", flexDirection: "column", gap: 10, paddingRight: 4 }}>
                {list.length === 0
                  ? <div style={{ padding: 28, fontSize: "calc(13px + 1px*var(--ts))", color: "var(--muted-foreground)", textAlign: "center" }}>Chưa có cửa hàng phù hợp với lựa chọn của bạn.</div>
                  : list.map((s, i) => <StoreLocatorRow key={s.name} store={s} active={i === activeStore} onSelect={() => setActiveStore(i)} />)}
              </div>
            </div>
            <div style={{ position: "relative", minHeight: 620, borderRadius: "var(--radius)", overflow: "hidden", border: "1px solid var(--border)", background: "#fff" }}>
              <StoreLocatorMap stores={list} activeIndex={activeStore} onSelect={setActiveStore} />
              <a href={storeLocatorMapLink(list[activeStore] || list[0])} target="_blank" rel="noreferrer" style={{ position: "absolute", right: 14, bottom: 14, display: "inline-flex", alignItems: "center", gap: 8, padding: "9px 14px", borderRadius: 999, background: "#fff", border: "1px solid var(--border)", boxShadow: "0 2px 10px rgba(15,23,42,0.14)", fontSize: "calc(13px + 0.5px*var(--ts))", fontWeight: 700, textDecoration: "none", whiteSpace: "nowrap" }}>
                <i className="ph-fill ph-navigation-arrow" style={{ fontSize: "calc(13px + 2px*var(--ts))", color: "var(--primary)" }}></i>Xem bản đồ lớn
              </a>
            </div>
          </div>
        </div>

        {allOpen ? <StoreLocatorAllModal onClose={() => setAllOpen(false)} onPick={(s) => { setProvince(s.city); setDistrict(""); setQuery(""); const idx = STORE_LIST.filter((x) => x.city === s.city).findIndex((x) => x.name === s.name); setActiveStore(idx < 0 ? 0 : idx); setAllOpen(false); }} /> : null}

        {STORE_GALLERIES.map((g) => <StoreLocatorGallery key={g.key} item={g} />)}

        <StoreLocatorContact />

      </div>
    </main>
  );
}

Object.assign(window, { StoreLocator });
