// Results listing page — premium redesign

// Araç görseli — yerel dosya öncelikli, hata olursa SVG silhouette (page-home.jsx'ten)
const ResultVehicleImg = ({ cat, name, catLabel, accent }) => {
  const [src, setSrc] = React.useState(`img/vehicles/${cat}.jpg`);
  const [failed, setFailed] = React.useState(false);

  const onErr = () => {
    if (src.endsWith(".jpg"))  { setSrc(`img/vehicles/${cat}.webp`); return; }
    if (src.endsWith(".webp")) { setSrc(`img/vehicles/${cat}.png`);  return; }
    setFailed(true);
  };

  return (
    <div style={{ position:"absolute", inset:0, overflow:"hidden",
                  background:"linear-gradient(135deg,#F0F4FF,#E8F0FC)",
                  display:"flex", alignItems:"center", justifyContent:"center" }}>
      <div style={{ position:"absolute", top:14, left:14, zIndex:2,
                    padding:"5px 10px", background:accent, color:"white",
                    borderRadius:6, fontFamily:"var(--font-mono)",
                    fontSize:"10.5px", fontWeight:700, letterSpacing:".1em" }}>
        {catLabel}
      </div>
      {failed ? (
        <div style={{ display:"flex", alignItems:"center", justifyContent:"center",
                      width:"100%", height:"100%", color:accent, flexDirection:"column", gap:8, padding:16 }}>
          {typeof CAR_SVG !== "undefined" && CAR_SVG[cat]}
          <span style={{ fontFamily:"var(--font-mono)", fontSize:10, color:"var(--gray-400)",
                         letterSpacing:".1em", textTransform:"uppercase" }}>{name}</span>
        </div>
      ) : (
        <img src={src} alt={name} onError={onErr}
             style={{ width:"100%", height:"85%", objectFit:"contain",
                      objectPosition:"center bottom", display:"block", padding:"10px 8px 0" }}/>
      )}
    </div>
  );
};

// Statik fallback — API bağlanana kadar gösterilir
const RESULTS_DATA = [
  { id: "shuttle", cat: "shuttle", catLabel: "SHUTTLE", name: "Paylaşımlı Shuttle", model: "Mercedes Sprinter · 16 koltuk",
    pax: 16, bag: 16, doors: 4, priceTry: 280, perSeat: true, eco: true,
    features: ["A/C Klimalı", "Wi-Fi", "Profesyonel Şoför", "Paylaşımlı"], img: "Mercedes Sprinter Shuttle" },
  { id: "taxi", cat: "taxi", catLabel: "TAXI", name: "Özel Taksi Transfer", model: "Toyota Corolla / Renault Talisman",
    pax: 3, bag: 3, doors: 4, priceTry: 1200, perSeat: false,
    features: ["A/C Klimalı", "Özel Transfer", "Wi-Fi", "Su İkramı"], img: "Sedan Taxi" },
  { id: "vip", cat: "vip", catLabel: "VIP CAR", name: "VIP Premium Transfer", model: "Mercedes E-Class W213",
    pax: 3, bag: 3, doors: 4, priceTry: 2400, perSeat: false, featured: true,
    features: ["Premium Deri", "Wi-Fi", "Su & Atıştırmalık", "Karşılama Tabelası", "Lüks Şoför"], img: "Mercedes E-Class VIP" },
  { id: "minivan", cat: "minivan", catLabel: "MINIVAN", name: "Aile / Grup Minivan", model: "Mercedes Vito Tourer",
    pax: 7, bag: 7, doors: 5, priceTry: 1800, perSeat: false, family: true,
    features: ["A/C Klimalı", "Wi-Fi", "Geniş Bagaj", "Bebek Koltuğu Eklenebilir"], img: "Mercedes Vito Minivan" },
  { id: "vip-van", cat: "minivan", catLabel: "VIP MINIVAN", name: "VIP Minivan", model: "Mercedes V-Class",
    pax: 6, bag: 6, doors: 5, priceTry: 3200, perSeat: false,
    features: ["Premium Deri", "Wi-Fi", "Su & Atıştırmalık", "Geniş Bagaj"], img: "Mercedes V-Class VIP" },
];

const CAT_META = {
  shuttle:  { label: "Shuttle",  icon: "users",   accent: "#6B7596" },
  taxi:     { label: "Taxi",     icon: "car",     accent: "#0B3D91" },
  vip:      { label: "VIP Car",  icon: "sparkle", accent: "#B91C1C" },
  minivan:  { label: "Minivan",  icon: "bag",     accent: "#4F46A8" },
};

const addMinutes = (hhmm, mins) => {
  const [h, m] = hhmm.split(":").map(Number);
  const total = h * 60 + m + mins;
  const nh = Math.floor((total % (24 * 60)) / 60);
  const nm = total % 60;
  return `${String(nh).padStart(2, "0")}:${String(nm).padStart(2, "0")}`;
};

const ResultsPage = ({ lang, ccy, query, setQuery, onSearch, onSelect }) => {
  const [filter, setFilter] = React.useState({ shuttle: true, taxi: true, vip: true, minivan: true });
  const [features, setFeatures] = React.useState({ ac: true, wifi: false, baby: false, sign: false, water: false });
  const [sort, setSort] = React.useState("recommended");
  const [activeCat, setActiveCat] = React.useState("all");
  const [priceMax, setPriceMax] = React.useState(5000);

  // API'den araç listesi — hata olursa RESULTS_DATA fallback
  const [apiVehicles, setApiVehicles] = React.useState(null);
  React.useEffect(() => {
    const pax = (query.adults || 1) + (query.children || 0);
    engApi.get(`/api/vehicle/search?passengers=${pax}`)
      .then(data => setApiVehicles(data.map(mapVehicle)))
      .catch(() => setApiVehicles(null));
  }, [query.adults, query.children]);

  const allData = apiVehicles || RESULTS_DATA;

  const fromName = query.from?.name || "Antalya Havalimanı (AYT)";
  const toName = query.to?.name || "Lara Bölgesi";
  const distance = 42;
  const duration = 38;
  const pickupTime = query.pickupTime || "14:30";
  const dropoffTime = addMinutes(pickupTime, duration);

  const counts = { all: allData.length };
  allData.forEach(r => { counts[r.cat] = (counts[r.cat] || 0) + 1; });

  const visible = allData.filter(r => (activeCat === "all" || r.cat === activeCat) && filter[r.cat] && r.priceTry <= priceMax);
  const sorted = [...visible].sort((a, b) => {
    if (sort === "price-asc") return a.priceTry - b.priceTry;
    if (sort === "price-desc") return b.priceTry - a.priceTry;
    if (sort === "pax") return b.pax - a.pax;
    return (b.featured ? 1 : 0) - (a.featured ? 1 : 0) || a.priceTry - b.priceTry;
  });

  return (
    <div style={{ background: "var(--gray-50)" }}>
      {/* Compact widget */}
      <div style={{ background: "linear-gradient(180deg, var(--navy-900), var(--navy-800))", padding: "20px 32px", borderBottom: "1px solid rgba(255,255,255,.06)" }}>
        <div style={{ maxWidth: 1320, margin: "0 auto" }}>
          <SearchWidget lang={lang} ccy={ccy} query={query} setQuery={setQuery} onSearch={onSearch} compact/>
        </div>
      </div>

      {/* Trip overview banner */}
      <div style={{ background: "white", borderBottom: "1px solid var(--gray-200)" }}>
        <div style={{ maxWidth: 1320, margin: "0 auto", padding: "20px 32px", display: "flex", alignItems: "center", gap: 24, flexWrap: "wrap" }}>
          <div style={{ display: "flex", alignItems: "center", gap: 18, flex: 1, minWidth: 0 }}>
            <div style={{ display: "flex", flexDirection: "column", gap: 4, minWidth: 0 }}>
              <span style={{ fontFamily: "var(--font-mono)", fontSize: 10.5, color: "var(--gray-500)", textTransform: "uppercase", letterSpacing: ".12em" }}>{pickupTime} · ALIŞ</span>
              <span style={{ fontFamily: "var(--font-display)", fontSize: 18, fontWeight: 700, letterSpacing: "-.015em", display: "flex", alignItems: "center", gap: 8 }}>
                <Icon name="plane" size={17} style={{ color: "var(--blue)" }}/>
                {fromName}
              </span>
            </div>
            <div style={{ flex: "0 0 auto", display: "flex", flexDirection: "column", alignItems: "center", gap: 4, padding: "0 18px", borderLeft: "1px dashed var(--gray-200)", borderRight: "1px dashed var(--gray-200)" }}>
              <div style={{ fontFamily: "var(--font-mono)", fontSize: 11, color: "var(--gray-500)", display: "flex", gap: 10 }}>
                <span><Icon name="clock" size={11} style={{ verticalAlign: "middle" }}/> {duration} dk</span>
                <span><Icon name="map" size={11} style={{ verticalAlign: "middle" }}/> {distance} km</span>
              </div>
              <div style={{ width: 110, height: 2, background: "linear-gradient(90deg, var(--blue), var(--red))", borderRadius: 999, position: "relative" }}>
                <div style={{ position: "absolute", left: 0, top: -3, width: 8, height: 8, borderRadius: 999, background: "var(--blue)" }}></div>
                <div style={{ position: "absolute", right: 0, top: -3, width: 8, height: 8, borderRadius: 999, background: "var(--red)" }}></div>
              </div>
            </div>
            <div style={{ display: "flex", flexDirection: "column", gap: 4, minWidth: 0 }}>
              <span style={{ fontFamily: "var(--font-mono)", fontSize: 10.5, color: "var(--gray-500)", textTransform: "uppercase", letterSpacing: ".12em" }}>{dropoffTime} · BIRAKIŞ</span>
              <span style={{ fontFamily: "var(--font-display)", fontSize: 18, fontWeight: 700, letterSpacing: "-.015em", display: "flex", alignItems: "center", gap: 8 }}>
                <Icon name="pin" size={17} style={{ color: "var(--red)" }}/>
                {toName}
              </span>
            </div>
          </div>
          <div style={{ display: "flex", gap: 10, alignItems: "center" }}>
            <div style={{ padding: "8px 14px", background: "var(--gray-50)", borderRadius: 999, fontSize: 12.5, fontWeight: 600, color: "var(--gray-700)", display: "inline-flex", alignItems: "center", gap: 6 }}>
              <Icon name="users" size={14} style={{ color: "var(--blue)" }}/> {query.adults} yetişkin{query.children > 0 ? `, ${query.children} çocuk` : ""}
            </div>
            <div style={{ padding: "8px 14px", background: "var(--gray-50)", borderRadius: 999, fontSize: 12.5, fontWeight: 600, color: "var(--gray-700)", display: "inline-flex", alignItems: "center", gap: 6 }}>
              <Icon name="calendar" size={14} style={{ color: "var(--blue)" }}/> {query.pickupDate}
            </div>
          </div>
        </div>

        {/* Category tabs */}
        <div style={{ maxWidth: 1320, margin: "0 auto", padding: "0 32px 0", display: "flex", gap: 0, borderTop: "1px solid var(--gray-100)" }}>
          {[
            { id: "all", label: "Tüm Araçlar", icon: "car" },
            { id: "shuttle", label: "Shuttle", icon: "users" },
            { id: "taxi", label: "Taxi", icon: "car" },
            { id: "vip", label: "VIP Car", icon: "sparkle" },
            { id: "minivan", label: "Minivan", icon: "bag" },
          ].map(c => (
            <button key={c.id}
                    onClick={() => setActiveCat(c.id)}
                    style={{
                      padding: "16px 22px", display: "inline-flex", alignItems: "center", gap: 8,
                      fontWeight: 600, fontSize: 14,
                      color: activeCat === c.id ? "var(--ink)" : "var(--gray-500)",
                      borderBottom: "3px solid " + (activeCat === c.id ? "var(--red)" : "transparent"),
                      marginBottom: -1,
                    }}>
              <Icon name={c.icon} size={16} style={{ color: activeCat === c.id ? "var(--red)" : "var(--gray-400)" }}/>
              {c.label}
              <span style={{ fontFamily: "var(--font-mono)", fontSize: 11, padding: "2px 7px", borderRadius: 999, background: activeCat === c.id ? "var(--red)" : "var(--gray-100)", color: activeCat === c.id ? "white" : "var(--gray-700)" }}>{counts[c.id] || 0}</span>
            </button>
          ))}
        </div>
      </div>

      <div className="page-section">
        <div className="results-layout">
          <aside className="filters">
            <h3>Filtreler</h3>

            <div className="filter-group">
              <h4>Hızlı Filtre</h4>
              <label className="filter-row"><input type="checkbox" defaultChecked/> <span>Ücretsiz iptal</span><span className="count">5</span></label>
              <label className="filter-row"><input type="checkbox"/> <span>Hemen onaylı</span><span className="count">5</span></label>
              <label className="filter-row"><input type="checkbox"/> <span>Karşılama tabelası</span><span className="count">3</span></label>
            </div>

            <div className="filter-group">
              <h4>Yolcu Kapasitesi</h4>
              <label className="filter-row"><input type="checkbox" defaultChecked/> 1–3 yolcu</label>
              <label className="filter-row"><input type="checkbox" defaultChecked/> 4–7 yolcu</label>
              <label className="filter-row"><input type="checkbox" defaultChecked/> 8+ yolcu</label>
            </div>

            <div className="filter-group">
              <h4>Özellikler</h4>
              <label className="filter-row"><input type="checkbox" checked={features.ac} onChange={e => setFeatures(f => ({ ...f, ac: e.target.checked }))}/> Klima</label>
              <label className="filter-row"><input type="checkbox" checked={features.wifi} onChange={e => setFeatures(f => ({ ...f, wifi: e.target.checked }))}/> Wi-Fi</label>
              <label className="filter-row"><input type="checkbox" checked={features.baby} onChange={e => setFeatures(f => ({ ...f, baby: e.target.checked }))}/> Bebek koltuğu</label>
              <label className="filter-row"><input type="checkbox" checked={features.sign} onChange={e => setFeatures(f => ({ ...f, sign: e.target.checked }))}/> Karşılama tabelası</label>
              <label className="filter-row"><input type="checkbox" checked={features.water} onChange={e => setFeatures(f => ({ ...f, water: e.target.checked }))}/> Su ikramı</label>
            </div>

            <div className="filter-group">
              <h4>Fiyat Aralığı</h4>
              <input type="range" min="200" max="5000" step="100" value={priceMax} onChange={e => setPriceMax(Number(e.target.value))} style={{ width: "100%", accentColor: "var(--red)" }}/>
              <div style={{ display: "flex", justifyContent: "space-between", fontSize: 12, color: "var(--gray-700)", fontFamily: "var(--font-mono)", fontWeight: 600 }}>
                <span>{CURRENCIES[ccy].symbol}0</span>
                <span style={{ color: "var(--red)" }}>{CURRENCIES[ccy].symbol}{Math.round(priceMax * CURRENCIES[ccy].rate)}</span>
              </div>
            </div>

            <div className="filter-group">
              <h4>Marka</h4>
              <label className="filter-row"><input type="checkbox" defaultChecked/> Mercedes-Benz <span className="count">4</span></label>
              <label className="filter-row"><input type="checkbox" defaultChecked/> BMW <span className="count">2</span></label>
              <label className="filter-row"><input type="checkbox" defaultChecked/> Toyota <span className="count">2</span></label>
              <label className="filter-row"><input type="checkbox" defaultChecked/> VW <span className="count">2</span></label>
            </div>
          </aside>

          {/* Results main */}
          <div className="results-main">
            <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center", padding: "0 4px", marginBottom: 4 }}>
              <div>
                <div style={{ fontFamily: "var(--font-display)", fontSize: 22, fontWeight: 700, letterSpacing: "-.02em" }}>
                  {sorted.length} araç bulundu
                </div>
                <div style={{ fontSize: 13, color: "var(--gray-500)", marginTop: 2 }}>
                  Tüm fiyatlara KDV dahildir · ücretsiz iptal · sabit fiyat garantisi
                </div>
              </div>
              <div style={{ display: "flex", gap: 8, alignItems: "center" }}>
                <span style={{ fontSize: 12, color: "var(--gray-500)", fontFamily: "var(--font-mono)", textTransform: "uppercase", letterSpacing: ".08em" }}>Sırala</span>
                <select className="sort-select" value={sort} onChange={e => setSort(e.target.value)}>
                  <option value="recommended">Önerilen</option>
                  <option value="price-asc">Fiyat: Artan</option>
                  <option value="price-desc">Fiyat: Azalan</option>
                  <option value="pax">Yolcu kapasitesi</option>
                </select>
              </div>
            </div>

            {sorted.map((r, idx) => {
              const p = fmtPrice(r.priceTry, ccy);
              const meta = CAT_META[r.cat];
              return (
                <div key={r.id} className="rcard" style={{
                  background: "white",
                  borderRadius: "var(--r-lg)",
                  border: "1.5px solid " + (r.featured ? meta.accent : "var(--gray-200)"),
                  overflow: "hidden",
                  display: "grid",
                  gridTemplateColumns: "300px 1fr 240px",
                  position: "relative",
                  transition: "all .2s",
                  boxShadow: r.featured ? "0 12px 32px rgba(185,28,28,.12)" : "var(--shadow-sm)",
                }}>
                  {r.featured && (
                    <div style={{ position: "absolute", top: 0, left: 300, padding: "5px 14px",
                      background: meta.accent, color: "white",
                      fontFamily: "var(--font-mono)", fontSize: 10.5, fontWeight: 700, letterSpacing: ".12em",
                      borderBottomRightRadius: 8 }}>
                      ★ EN POPÜLER
                    </div>
                  )}

                  {/* Image */}
                  <div style={{ position: "relative", minHeight: 220, borderRight: "1px solid var(--gray-100)", overflow: "hidden" }}>
                    <ResultVehicleImg cat={r.cat} name={r.name} catLabel={r.catLabel} accent={meta.accent}/>
                    {r.eco && (
                      <div style={{ position: "absolute", top: 46, right: 14, padding: "4px 9px",
                        background: "rgba(22,163,74,.9)", color: "white", borderRadius: 999,
                        fontSize: 10.5, fontWeight: 700, fontFamily: "var(--font-mono)", letterSpacing: ".08em",
                        display: "inline-flex", alignItems: "center", gap: 4, zIndex: 3 }}>
                        <Icon name="leaf" size={11}/> EKO
                      </div>
                    )}
                    {r.family && (
                      <div style={{ position: "absolute", top: 46, right: 14, padding: "4px 9px",
                        background: "rgba(11,61,145,.9)", color: "white", borderRadius: 999,
                        fontSize: 10.5, fontWeight: 700, fontFamily: "var(--font-mono)", letterSpacing: ".08em",
                        display: "inline-flex", alignItems: "center", gap: 4, zIndex: 3 }}>
                        <Icon name="users" size={11}/> AİLE
                      </div>
                    )}
                    <div style={{ position: "absolute", bottom: 12, left: 14, right: 14, display: "flex", justifyContent: "space-between", alignItems: "end" }}>
                      <span style={{ fontFamily: "var(--font-mono)", fontSize: 10.5, fontWeight: 600, color: "var(--gray-700)", letterSpacing: ".08em" }}>
                        4 görsel ↓
                      </span>
                      <div style={{ display: "flex", gap: 4 }}>
                        {[0,1,2,3].map(i => <span key={i} style={{ width: 6, height: 6, borderRadius: 999, background: i === 0 ? meta.accent : "rgba(0,0,0,.15)" }}></span>)}
                      </div>
                    </div>
                  </div>

                  {/* Body */}
                  <div style={{ padding: "22px 26px", display: "flex", flexDirection: "column", gap: 12 }}>
                    <div>
                      <h3 style={{ fontFamily: "var(--font-display)", fontSize: 22, fontWeight: 700, letterSpacing: "-.02em", margin: "0 0 4px" }}>{r.name}</h3>
                      <div style={{ fontSize: 13.5, color: "var(--gray-500)" }}>{r.model}</div>
                    </div>

                    <div style={{ display: "flex", gap: 6, flexWrap: "wrap" }}>
                      <span style={{ display: "inline-flex", gap: 5, alignItems: "center", padding: "5px 10px", background: "var(--gray-50)", border: "1px solid var(--gray-100)", borderRadius: 6, fontSize: 12.5, fontWeight: 600, color: "var(--gray-700)" }}>
                        <Icon name="users" size={13} style={{ color: meta.accent }}/> {r.pax} yolcu
                      </span>
                      <span style={{ display: "inline-flex", gap: 5, alignItems: "center", padding: "5px 10px", background: "var(--gray-50)", border: "1px solid var(--gray-100)", borderRadius: 6, fontSize: 12.5, fontWeight: 600, color: "var(--gray-700)" }}>
                        <Icon name="luggage" size={13} style={{ color: meta.accent }}/> {r.bag} bagaj
                      </span>
                      <span style={{ display: "inline-flex", gap: 5, alignItems: "center", padding: "5px 10px", background: "var(--gray-50)", border: "1px solid var(--gray-100)", borderRadius: 6, fontSize: 12.5, fontWeight: 600, color: "var(--gray-700)" }}>
                        <Icon name="car" size={13} style={{ color: meta.accent }}/> {r.doors} kapı
                      </span>
                      <span style={{ display: "inline-flex", gap: 5, alignItems: "center", padding: "5px 10px", background: "var(--gray-50)", border: "1px solid var(--gray-100)", borderRadius: 6, fontSize: 12.5, fontWeight: 600, color: "var(--gray-700)" }}>
                        <Icon name="snow" size={13} style={{ color: meta.accent }}/> A/C
                      </span>
                    </div>

                    {/* Trip mini-strip */}
                    <div style={{ display: "grid", gridTemplateColumns: "1fr auto 1fr", gap: 14, alignItems: "center",
                      padding: "12px 14px", background: "var(--gray-50)", border: "1px dashed var(--gray-200)", borderRadius: 10 }}>
                      <div>
                        <div style={{ fontSize: 10.5, fontFamily: "var(--font-mono)", color: "var(--gray-500)", textTransform: "uppercase", letterSpacing: ".1em" }}>{pickupTime} · ALIŞ</div>
                        <div style={{ fontSize: 13, fontWeight: 600, marginTop: 2 }}>{fromName}</div>
                      </div>
                      <div style={{ display: "flex", flexDirection: "column", alignItems: "center", gap: 3, color: "var(--gray-500)" }}>
                        <span style={{ fontFamily: "var(--font-mono)", fontSize: 10.5, fontWeight: 600 }}>~{duration} dk</span>
                        <Icon name="arrowRight" size={16} style={{ color: meta.accent }}/>
                        <span style={{ fontFamily: "var(--font-mono)", fontSize: 10.5, fontWeight: 600 }}>{distance} km</span>
                      </div>
                      <div style={{ textAlign: "right" }}>
                        <div style={{ fontSize: 10.5, fontFamily: "var(--font-mono)", color: "var(--gray-500)", textTransform: "uppercase", letterSpacing: ".1em" }}>{dropoffTime} · BIRAKIŞ</div>
                        <div style={{ fontSize: 13, fontWeight: 600, marginTop: 2 }}>{toName}</div>
                      </div>
                    </div>

                    <div style={{ display: "flex", gap: 12, flexWrap: "wrap", fontSize: 12.5, color: "var(--gray-700)" }}>
                      {r.features.slice(0, 4).map(f => (
                        <span key={f} style={{ display: "inline-flex", gap: 5, alignItems: "center" }}>
                          <Icon name="check" size={13} style={{ color: "#16A34A" }}/> {f}
                        </span>
                      ))}
                      {r.features.length > 4 && (
                        <span style={{ color: "var(--blue)", fontWeight: 600 }}>+{r.features.length - 4} özellik</span>
                      )}
                    </div>
                  </div>

                  {/* Side / price */}
                  <div style={{ borderLeft: "1px solid var(--gray-100)", padding: "22px 22px 22px",
                    display: "flex", flexDirection: "column", justifyContent: "space-between",
                    background: r.featured ? "linear-gradient(180deg, " + meta.accent + "08, transparent)" : "var(--gray-50)" }}>
                    <div style={{ textAlign: "right" }}>
                      <div style={{ fontSize: 11, color: "var(--gray-500)", fontFamily: "var(--font-mono)", textTransform: "uppercase", letterSpacing: ".1em", marginBottom: 4 }}>
                        {r.perSeat ? "Kişi başı" : "Toplam fiyat"}
                      </div>
                      <div style={{ fontFamily: "var(--font-display)", fontSize: 36, fontWeight: 700, letterSpacing: "-.025em", lineHeight: 1, color: "var(--ink)" }}>
                        <span style={{ fontSize: 20, color: "var(--gray-500)", marginRight: 2 }}>{p.symbol}</span>{p.value}
                      </div>
                      <div style={{ fontSize: 11.5, color: "var(--gray-500)", marginTop: 6 }}>
                        · KDV dahil
                      </div>
                      {r.priceTry > 1500 && (
                        <div style={{ fontSize: 11.5, color: "#16A34A", marginTop: 4, fontFamily: "var(--font-mono)", fontWeight: 600 }}>
                          ya da 3 taksit{" "}
                          {fmtPrice(Math.round(r.priceTry / 3), ccy).symbol}{fmtPrice(Math.round(r.priceTry / 3), ccy).value}
                        </div>
                      )}
                    </div>
                    <div style={{ display: "flex", flexDirection: "column", gap: 8 }}>
                      <button className="btn btn-primary btn-block" style={{ background: meta.accent, boxShadow: "0 6px 18px " + meta.accent + "40" }} onClick={() => onSelect(r)}>
                        Seç ve Devam Et <Icon name="arrowRight" size={15}/>
                      </button>
                      <div style={{ fontSize: 11.5, color: "var(--gray-500)", textAlign: "center", display: "inline-flex", alignItems: "center", justifyContent: "center", gap: 5 }}>
                        <Icon name="check" size={11} style={{ color: "#16A34A" }}/> Ücretsiz iptal · 24 saat
                      </div>
                      <div style={{ fontSize: 11.5, color: "var(--gray-500)", textAlign: "center", display: "inline-flex", alignItems: "center", justifyContent: "center", gap: 5 }}>
                        <Icon name="bolt" size={11} style={{ color: "#F59E0B" }}/> Anında onay
                      </div>
                    </div>
                  </div>
                </div>
              );
            })}

            {sorted.length === 0 && (
              <div style={{ padding: 64, textAlign: "center", background: "white", borderRadius: "var(--r-lg)", border: "1px dashed var(--gray-300)" }}>
                <div style={{ fontFamily: "var(--font-display)", fontSize: 22, fontWeight: 700, marginBottom: 8 }}>Filtrelerle eşleşen araç yok</div>
                <p style={{ color: "var(--gray-500)", margin: 0 }}>Filtreleri sıfırlayın ya da kategoriyi "Tüm Araçlar" yapın.</p>
              </div>
            )}

            <div style={{ padding: 24, background: "white", borderRadius: "var(--r-lg)", border: "1px solid var(--gray-200)", display: "flex", gap: 18, alignItems: "center" }}>
              <div style={{ width: 48, height: 48, borderRadius: 12, background: "rgba(11,61,145,.1)", display: "grid", placeItems: "center", color: "var(--blue)" }}>
                <Icon name="headset" size={22}/>
              </div>
              <div style={{ flex: 1 }}>
                <div style={{ fontFamily: "var(--font-display)", fontSize: 17, fontWeight: 700 }}>Aradığınızı bulamadınız mı?</div>
                <div style={{ fontSize: 13, color: "var(--gray-500)", marginTop: 2 }}>7/24 müşteri hizmetlerimiz size özel araç ve fiyat teklifi hazırlasın.</div>
              </div>
              <button className="btn btn-secondary"><Icon name="whatsapp" size={15}/> WhatsApp</button>
              <button className="btn btn-ghost"><Icon name="phone" size={15}/> Ara</button>
            </div>
          </div>
        </div>
      </div>
    </div>
  );
};

window.ResultsPage = ResultsPage;
