// ECR Property Summary — UI components

// ── PhotoCanvas ────────────────────────────────────────────────────────────
// Generative "placeholder" photo using the property's palette + diagonal motif
function PhotoCanvas({ property, variant = 0, large = false }) {
  const [a, b, c] = property.palette;
  const seedHash = (property.id + variant).split('').reduce((s, ch) => s + ch.charCodeAt(0), 0);
  // Choose a layout based on variant
  const layoutIdx = (variant + seedHash) % 4;

  // Building geometry strokes
  const renderLayout = () => {
    if (property.type === 'Land') {
      return (
        <>
          <rect width="400" height="300" fill={a} />
          <path d="M 0 220 Q 100 180, 200 200 T 400 190 L 400 300 L 0 300 Z" fill={b} opacity="0.85" />
          <path d="M 0 250 Q 120 230, 240 250 T 400 240 L 400 300 L 0 300 Z" fill={ECR.charcoal} opacity="0.5" />
          {/* horizon line and sun */}
          <circle cx="310" cy="100" r="40" fill={c} opacity="0.85" />
          {[...Array(8)].map((_, i) => (
            <line key={i} x1={20 + i * 50} y1="220" x2={20 + i * 50} y2="280" stroke={c} strokeWidth="1" opacity="0.4" />
          ))}
        </>
      );
    }
    if (property.type === 'Industrial') {
      return (
        <>
          <rect width="400" height="300" fill={a} />
          {/* Warehouse silhouette */}
          <rect x="40" y="120" width="320" height="160" fill={ECR.charcoal} opacity="0.85" />
          <rect x="40" y="120" width="320" height="10" fill={c} opacity="0.6" />
          {/* dock doors */}
          {[0,1,2,3,4,5].map(i => (
            <rect key={i} x={70 + i * 48} y="200" width="32" height="80" fill={c} opacity="0.3" />
          ))}
          {/* sawtooth roof */}
          <path d="M 40 120 L 80 90 L 80 120 L 120 90 L 120 120 L 160 90 L 160 120 L 200 90 L 200 120 L 240 90 L 240 120 L 280 90 L 280 120 L 320 90 L 320 120 L 360 90 L 360 120 Z" fill={b} opacity="0.8" />
          {/* diagonal sky band — logo motif */}
          <path d="M 0 0 L 400 0 L 400 60 L 0 100 Z" fill={c} opacity="0.18" />
        </>
      );
    }
    if (property.type === 'Medical') {
      return (
        <>
          <rect width="400" height="300" fill={a} />
          {/* Med campus — multi-block */}
          <rect x="20" y="100" width="100" height="200" fill={ECR.charcoal} opacity="0.85" />
          <rect x="130" y="60" width="140" height="240" fill={b} opacity="0.95" />
          <rect x="280" y="130" width="100" height="170" fill={ECR.charcoal} opacity="0.85" />
          {/* windows grid */}
          {[0,1,2,3,4,5,6].map(row =>
            [0,1,2,3].map(col => (
              <rect key={`m${row}-${col}`} x={140 + col * 32} y={80 + row * 30} width="22" height="18" fill={c} opacity="0.35" />
            ))
          )}
          {[0,1,2,3,4,5,6].map(row =>
            [0,1].map(col => (
              <rect key={`l${row}-${col}`} x={30 + col * 44} y={120 + row * 26} width="32" height="14" fill={c} opacity="0.3" />
            ))
          )}
          {/* diagonal band */}
          <path d="M 0 250 L 400 220 L 400 300 L 0 300 Z" fill={ECR.charcoal} opacity="0.4" />
        </>
      );
    }
    // Office variants
    if (layoutIdx === 0) {
      // Tall tower centered
      return (
        <>
          <rect width="400" height="300" fill={a} />
          <rect x="120" y="40" width="160" height="260" fill={ECR.charcoal} opacity="0.9" />
          <rect x="40" y="160" width="80" height="140" fill={b} opacity="0.85" />
          <rect x="280" y="120" width="80" height="180" fill={b} opacity="0.85" />
          {/* window grid on tower */}
          {[...Array(10)].map((_, row) =>
            [0,1,2,3].map(col => (
              <rect key={`o${row}-${col}`} x={130 + col * 36} y={55 + row * 25} width="28" height="14" fill={c} opacity="0.5" />
            ))
          )}
          {/* diagonal stripe */}
          <path d="M 280 40 L 280 80 L 120 200 L 120 160 Z" fill={c} opacity="0.18" />
        </>
      );
    }
    if (layoutIdx === 1) {
      // Stepped horizontal
      return (
        <>
          <rect width="400" height="300" fill={a} />
          <rect x="0" y="180" width="160" height="120" fill={ECR.charcoal} opacity="0.92" />
          <rect x="120" y="120" width="160" height="180" fill={b} opacity="0.9" />
          <rect x="240" y="60" width="160" height="240" fill={ECR.charcoal} opacity="0.92" />
          {/* windows */}
          {[...Array(8)].map((_, row) =>
            [0,1,2,3].map(col => (
              <rect key={`o${row}-${col}`} x={250 + col * 36} y={75 + row * 26} width="28" height="14" fill={c} opacity="0.5" />
            ))
          )}
          {[...Array(6)].map((_, row) =>
            [0,1,2,3].map(col => (
              <rect key={`p${row}-${col}`} x={130 + col * 36} y={135 + row * 26} width="28" height="14" fill={c} opacity="0.45" />
            ))
          )}
        </>
      );
    }
    if (layoutIdx === 2) {
      // Mid-rise with foreground silhouette
      return (
        <>
          <rect width="400" height="300" fill={a} />
          {/* sky diagonal */}
          <path d="M 0 0 L 400 0 L 400 80 L 0 140 Z" fill={c} opacity="0.22" />
          <rect x="80" y="80" width="240" height="220" fill={ECR.charcoal} opacity="0.92" />
          {/* curtain wall vertical mullions */}
          {[...Array(8)].map((_, i) => (
            <line key={i} x1={80 + i * 30} y1="80" x2={80 + i * 30} y2="300" stroke={c} strokeWidth="1" opacity="0.45" />
          ))}
          {/* horizontal floor lines */}
          {[...Array(9)].map((_, i) => (
            <line key={i} x1="80" y1={102 + i * 22} x2="320" y2={102 + i * 22} stroke={c} strokeWidth="0.6" opacity="0.35" />
          ))}
          {/* foreground trees */}
          <ellipse cx="40" cy="260" rx="50" ry="30" fill={b} opacity="0.7" />
          <ellipse cx="370" cy="270" rx="60" ry="35" fill={b} opacity="0.7" />
        </>
      );
    }
    // layout 3 — twin towers
    return (
      <>
        <rect width="400" height="300" fill={a} />
        <rect x="50" y="50" width="130" height="250" fill={ECR.charcoal} opacity="0.92" />
        <rect x="220" y="80" width="130" height="220" fill={b} opacity="0.92" />
        {/* skybridge */}
        <rect x="180" y="180" width="40" height="18" fill={ECR.charcoal} opacity="0.92" />
        {/* windows */}
        {[...Array(11)].map((_, row) =>
          [0,1,2].map(col => (
            <rect key={`a${row}-${col}`} x={60 + col * 36} y={62 + row * 22} width="28" height="12" fill={c} opacity="0.5" />
          ))
        )}
        {[...Array(9)].map((_, row) =>
          [0,1,2].map(col => (
            <rect key={`b${row}-${col}`} x={230 + col * 36} y={92 + row * 22} width="28" height="12" fill={c} opacity="0.45" />
          ))
        )}
      </>
    );
  };

  return (
    <svg viewBox="0 0 400 300" preserveAspectRatio="xMidYMid slice" style={{ width: '100%', height: '100%', display: 'block', background: a }}>
      {renderLayout()}
      {large && (
        <>
          {/* Caption block bottom-left for hero photo */}
          <rect x="0" y="270" width="200" height="30" fill={ECR.charcoal} opacity="0.85" />
          <text x="14" y="289" fontFamily="Montserrat" fontWeight="700" fontSize="9" letterSpacing="2" fill={ECR.white}>
            {property.id} · {variant === 0 ? 'EXTERIOR' : variant === 1 ? 'LOBBY' : variant === 2 ? 'FLOOR PLATE' : variant === 3 ? 'AMENITIES' : 'SITE'}
          </text>
        </>
      )}
    </svg>
  );
}

// ── Header ─────────────────────────────────────────────────────────────────
function SiteHeader() {
  const links = ['Properties', 'Services', 'Team', 'About', 'Contact'];
  return (
    <header style={{ background: ECR.charcoal, height: 68, display: 'flex', alignItems: 'center', padding: '0 32px', gap: 40, borderBottom: `1px solid ${ECR.charcoal70}`, flexShrink: 0 }}>
      <img src="assets/ECR_Logo.png" alt="ECR" style={{ height: 36 }} />
      <nav style={{ display: 'flex', gap: 32, marginLeft: 8, flex: 1 }}>
        {links.map(l => (
          <a key={l} href="#" onClick={e => e.preventDefault()}
            style={{
              fontFamily: 'Montserrat', fontWeight: 600, fontSize: 9, letterSpacing: '0.22em', textTransform: 'uppercase',
              color: l === 'Properties' ? '#fff' : 'rgba(255,255,255,0.60)',
              textDecoration: 'none', borderBottom: l === 'Properties' ? '2px solid #D6001C' : 'none', paddingBottom: l === 'Properties' ? 2 : 0,
            }}>
            {l}
          </a>
        ))}
      </nav>
      <div style={{ display: 'flex', alignItems: 'center', gap: 16, fontFamily: 'Montserrat', fontSize: 9, letterSpacing: '0.18em', textTransform: 'uppercase', color: 'rgba(255,255,255,0.55)', fontWeight: 500 }}>
        <span>512.505.0000</span>
        <span style={{ width: 1, height: 14, background: 'rgba(255,255,255,0.2)' }}></span>
        <span>ecrtx.com</span>
      </div>
      <button style={{
        fontFamily: 'Montserrat', fontWeight: 700, fontSize: 9, letterSpacing: '0.22em', textTransform: 'uppercase',
        background: ECR.red, color: '#fff', border: 'none', padding: '12px 22px', cursor: 'pointer',
      }}>
        Get Started
      </button>
    </header>
  );
}

// ── Footer ─────────────────────────────────────────────────────────────────
function SiteFooter() {
  return (
    <footer style={{ background: '#2a2e2d', padding: '20px 32px', flexShrink: 0, display: 'flex', alignItems: 'center', gap: 32, borderTop: `1px solid ${ECR.charcoal70}` }}>
      <img src="assets/ECR_Logo.png" alt="ECR" style={{ height: 30 }} />
      <div style={{ fontFamily: 'Montserrat', fontWeight: 400, fontSize: 9, color: ECR.grayMid, letterSpacing: '0.12em' }}>
        ECR // 114 W 7TH ST // SUITE 1000 // AUSTIN, TX 78701
      </div>
      <div style={{ width: 1, height: 22, background: 'rgba(255,255,255,0.15)' }}></div>
      <div style={{ fontFamily: 'Montserrat', fontWeight: 600, fontSize: 9, color: ECR.grayMid, letterSpacing: '0.16em' }}>
        512.505.0000  ·  ecrtx.com
      </div>
      <div style={{ flex: 1 }}></div>
      <div style={{ display: 'flex', gap: 24 }}>
        {['Office', 'Industrial', 'Medical', 'Land', 'Team', 'Contact'].map(l => (
          <a key={l} href="#" onClick={e => e.preventDefault()} style={{ fontFamily: 'Montserrat', fontWeight: 600, fontSize: 8.5, color: ECR.grayMid, letterSpacing: '0.22em', textTransform: 'uppercase', textDecoration: 'none' }}>{l}</a>
        ))}
      </div>
      <div style={{ width: 1, height: 22, background: 'rgba(255,255,255,0.15)' }}></div>
      <div style={{ fontFamily: 'Montserrat', fontWeight: 700, fontSize: 9, letterSpacing: '0.24em', textTransform: 'uppercase', color: ECR.red }}>Beyond Real Estate</div>
    </footer>
  );
}

// ── Toolbar (filters / sort / favs) ────────────────────────────────────────
const TYPE_FILTERS = ['All', 'Office', 'Industrial', 'Medical', 'Land'];
const SORT_OPTIONS = [
  { id: 'default', label: 'Featured' },
  { id: 'sf-desc', label: 'Size · High → Low' },
  { id: 'sf-asc', label: 'Size · Low → High' },
  { id: 'rate-asc', label: 'Rate · Low → High' },
  { id: 'rate-desc', label: 'Rate · High → Low' },
];

function FilterToolbar({
  count, total,
  typeFilter, onTypeFilter,
  status, onStatus,
  sort, onSort,
  favCount, showFavs, onToggleFavs,
}) {
  return (
    <div style={{
      background: ECR.white, borderBottom: `1px solid ${ECR.grayLight}`, padding: '16px 32px',
      display: 'flex', alignItems: 'center', gap: 24, flexShrink: 0,
    }}>
      {/* Title block */}
      <div style={{ display: 'flex', flexDirection: 'column', gap: 2, marginRight: 8 }}>
        <div style={{ fontFamily: 'Montserrat', fontWeight: 600, fontSize: 9, letterSpacing: '0.28em', textTransform: 'uppercase', color: ECR.red }}>Property Summary</div>
        <div style={{ fontFamily: 'Montserrat', fontWeight: 700, fontSize: 16, letterSpacing: '0.10em', textTransform: 'uppercase', color: ECR.charcoal, lineHeight: 1 }}>
          Austin Market · 2026
        </div>
      </div>

      <div style={{ width: 1, height: 36, background: ECR.grayLight }}></div>

      {/* Type filter pills */}
      <div style={{ display: 'flex', gap: 0 }}>
        {TYPE_FILTERS.map(t => {
          const active = typeFilter === t;
          return (
            <button key={t} onClick={() => onTypeFilter(t)} style={{
              fontFamily: 'Montserrat', fontWeight: active ? 700 : 600, fontSize: 9, letterSpacing: '0.22em', textTransform: 'uppercase',
              padding: '10px 16px',
              background: active ? ECR.charcoal : 'transparent',
              color: active ? '#fff' : ECR.charcoal70,
              border: `1px solid ${active ? ECR.charcoal : ECR.grayLight}`,
              borderLeft: t === 'All' ? `1px solid ${active ? ECR.charcoal : ECR.grayLight}` : 'none',
              cursor: 'pointer',
              transition: 'background 150ms',
            }}>{t}</button>
          );
        })}
      </div>

      {/* Status filter */}
      <div style={{ display: 'flex', gap: 0 }}>
        {['All', 'For Lease', 'For Sale'].map(s => {
          const active = status === s;
          return (
            <button key={s} onClick={() => onStatus(s)} style={{
              fontFamily: 'Montserrat', fontWeight: active ? 700 : 600, fontSize: 9, letterSpacing: '0.22em', textTransform: 'uppercase',
              padding: '10px 16px',
              background: active ? ECR.charcoal : 'transparent',
              color: active ? '#fff' : ECR.charcoal70,
              border: `1px solid ${active ? ECR.charcoal : ECR.grayLight}`,
              borderLeft: s === 'All' ? `1px solid ${active ? ECR.charcoal : ECR.grayLight}` : 'none',
              cursor: 'pointer',
            }}>{s}</button>
          );
        })}
      </div>

      <div style={{ flex: 1 }}></div>

      {/* Result count */}
      <div style={{ display: 'flex', flexDirection: 'column', gap: 2, alignItems: 'flex-end' }}>
        <div style={{ fontFamily: 'Montserrat', fontWeight: 600, fontSize: 8, letterSpacing: '0.24em', textTransform: 'uppercase', color: ECR.grayMid }}>Showing</div>
        <div style={{ fontFamily: 'Montserrat', fontWeight: 700, fontSize: 14, letterSpacing: '0.10em', color: ECR.charcoal }}>
          {count} <span style={{ color: ECR.grayMid, fontWeight: 400 }}>/ {total}</span>
        </div>
      </div>

      <div style={{ width: 1, height: 36, background: ECR.grayLight }}></div>

      {/* Sort dropdown */}
      <div style={{ position: 'relative' }}>
        <div style={{ fontFamily: 'Montserrat', fontWeight: 600, fontSize: 8, letterSpacing: '0.24em', textTransform: 'uppercase', color: ECR.grayMid, marginBottom: 4 }}>Sort By</div>
        <select value={sort} onChange={e => onSort(e.target.value)} style={{
          fontFamily: 'Montserrat', fontWeight: 600, fontSize: 10, letterSpacing: '0.12em', textTransform: 'uppercase',
          background: ECR.white, color: ECR.charcoal, border: `1px solid ${ECR.grayLight}`, padding: '6px 28px 6px 10px',
          borderRadius: 0, cursor: 'pointer', appearance: 'none',
          backgroundImage: `url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 10 10'><path d='M2 3 L5 7 L8 3' fill='none' stroke='%233F4443' stroke-width='1.4'/></svg>")`,
          backgroundRepeat: 'no-repeat',
          backgroundPosition: 'right 8px center',
        }}>
          {SORT_OPTIONS.map(o => <option key={o.id} value={o.id}>{o.label}</option>)}
        </select>
      </div>

      {/* Favorites toggle */}
      <button onClick={onToggleFavs} style={{
        fontFamily: 'Montserrat', fontWeight: 700, fontSize: 9, letterSpacing: '0.22em', textTransform: 'uppercase',
        padding: '10px 16px', display: 'flex', alignItems: 'center', gap: 8,
        background: showFavs ? ECR.red : 'transparent',
        color: showFavs ? '#fff' : ECR.charcoal,
        border: `1px solid ${showFavs ? ECR.red : ECR.grayLight}`,
        cursor: 'pointer',
      }}>
        <HeartIcon size={11} filled={showFavs} color={showFavs ? '#fff' : ECR.red} />
        Shortlist · {favCount}
      </button>
    </div>
  );
}

// ── Icons ──────────────────────────────────────────────────────────────────
function HeartIcon({ size = 14, filled = false, color = '#D6001C' }) {
  return (
    <svg width={size} height={size} viewBox="0 0 24 24" fill={filled ? color : 'none'} stroke={color} strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
      <path d="M20.84 4.61a5.5 5.5 0 0 0-7.78 0L12 5.67l-1.06-1.06a5.5 5.5 0 0 0-7.78 7.78l1.06 1.06L12 21.23l7.78-7.78 1.06-1.06a5.5 5.5 0 0 0 0-7.78z" />
    </svg>
  );
}

function ArrowIcon({ size = 12, dir = 'right', color = '#3F4443' }) {
  const rot = { right: 0, left: 180, up: -90, down: 90 }[dir];
  return (
    <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke={color} strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" style={{ transform: `rotate(${rot}deg)` }}>
      <line x1="5" y1="12" x2="19" y2="12" />
      <polyline points="12 5 19 12 12 19" />
    </svg>
  );
}

function CloseIcon({ size = 14, color = '#3F4443' }) {
  return (
    <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke={color} strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
      <line x1="18" y1="6" x2="6" y2="18" />
      <line x1="6" y1="6" x2="18" y2="18" />
    </svg>
  );
}

// ── Compact list card (right column) ──────────────────────────────────────
function ListCard({ property, index, isActive, isFav, onClick, onHover, onToggleFav }) {
  const [hov, setHov] = React.useState(false);
  return (
    <div
      onClick={onClick}
      onMouseEnter={() => { setHov(true); onHover && onHover(property.id); }}
      onMouseLeave={() => { setHov(false); onHover && onHover(null); }}
      style={{
        display: 'flex', gap: 12, background: ECR.white, padding: 10,
        border: `1px solid ${isActive ? ECR.charcoal : ECR.grayLight}`,
        borderLeft: `4px solid ${isActive ? ECR.red : TYPE_COLORS[property.type]}`,
        cursor: 'pointer',
        boxShadow: isActive ? '0 6px 18px rgba(63,68,67,0.15)' : (hov ? '0 4px 10px rgba(63,68,67,0.08)' : 'none'),
        transition: 'box-shadow 180ms, border-color 180ms',
        position: 'relative',
      }}
    >
      {/* Pin number */}
      <div style={{
        position: 'absolute', top: -8, left: -8, width: 22, height: 22, borderRadius: 11,
        background: isActive ? ECR.red : TYPE_COLORS[property.type], color: '#fff',
        fontFamily: 'Montserrat', fontWeight: 700, fontSize: 10, letterSpacing: '0.05em',
        display: 'flex', alignItems: 'center', justifyContent: 'center',
        border: '2px solid #fff', boxShadow: '0 1px 3px rgba(63,68,67,0.25)',
      }}>{index + 1}</div>

      {/* Mini thumb */}
      <div style={{ width: 72, height: 72, flexShrink: 0, overflow: 'hidden' }}>
        <PhotoCanvas property={property} variant={0} />
      </div>

      {/* Body */}
      <div style={{ flex: 1, minWidth: 0, display: 'flex', flexDirection: 'column', gap: 3 }}>
        <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 8 }}>
          <div style={{ fontFamily: 'Montserrat', fontWeight: 700, fontSize: 7.5, letterSpacing: '0.22em', textTransform: 'uppercase', color: TYPE_COLORS[property.type] }}>
            {property.type} · {property.status}
          </div>
          <button
            onClick={(e) => { e.stopPropagation(); onToggleFav(property.id); }}
            style={{ background: 'transparent', border: 'none', padding: 0, cursor: 'pointer', display: 'flex' }}
          >
            <HeartIcon size={12} filled={isFav} color={isFav ? ECR.red : ECR.grayMid} />
          </button>
        </div>
        <div style={{ fontFamily: 'Montserrat', fontWeight: 700, fontSize: 11, letterSpacing: '0.06em', color: ECR.charcoal, whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>
          {property.name}
        </div>
        <div style={{ fontFamily: 'Montserrat', fontWeight: 400, fontSize: 9, color: ECR.grayMid, letterSpacing: '0.04em', whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>
          {property.submarket}
        </div>
        <div style={{ display: 'flex', gap: 12, marginTop: 4, paddingTop: 4, borderTop: `1px solid ${ECR.charcoal10}` }}>
          <div style={{ fontFamily: 'Montserrat', fontWeight: 600, fontSize: 9, letterSpacing: '0.08em', color: ECR.charcoal }}>
            {property.sf >= 100000 ? `${(property.sf / 43560).toFixed(0)} ` : property.sf.toLocaleString()} <span style={{ color: ECR.grayMid, fontWeight: 400 }}>{property.sf >= 100000 && property.type === 'Land' ? 'AC' : 'SF'}</span>
          </div>
          <div style={{ fontFamily: 'Montserrat', fontWeight: 600, fontSize: 9, letterSpacing: '0.08em', color: ECR.red, whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>
            {property.rate}
          </div>
        </div>
      </div>
    </div>
  );
}

// ── Detail Panel (the "photo box" on the right) ──────────────────────────
function DetailPanel({ property, isFav, onToggleFav, onOpenFullscreen }) {
  const [photoIdx, setPhotoIdx] = React.useState(0);
  React.useEffect(() => { setPhotoIdx(0); }, [property.id]);
  const photoLabels = ['Exterior', 'Lobby', 'Floor Plate', 'Amenities', 'Site'];

  const sfDisplay = property.type === 'Land'
    ? `${(property.sf / 43560).toFixed(1)} acres`
    : `${property.sf.toLocaleString()} SF`;

  return (
    <div style={{ display: 'flex', flexDirection: 'column', background: ECR.white, height: '100%', overflow: 'hidden' }}>
      {/* Hero photo */}
      <div style={{ position: 'relative', flexShrink: 0, height: 340, background: ECR.charcoal10 }}>
        <PhotoCanvas property={property} variant={photoIdx} large={true} />

        {/* Top-left type/status badge */}
        <div style={{ position: 'absolute', top: 16, left: 16, display: 'flex', gap: 0 }}>
          <span style={{
            fontFamily: 'Montserrat', fontWeight: 700, fontSize: 9, letterSpacing: '0.22em', textTransform: 'uppercase',
            background: TYPE_COLORS[property.type], color: '#fff', padding: '7px 12px',
          }}>{property.type}</span>
          <span style={{
            fontFamily: 'Montserrat', fontWeight: 700, fontSize: 9, letterSpacing: '0.22em', textTransform: 'uppercase',
            background: ECR.red, color: '#fff', padding: '7px 12px',
          }}>{property.status}</span>
        </div>

        {/* Top-right favorite */}
        <button onClick={onToggleFav} style={{
          position: 'absolute', top: 16, right: 16,
          width: 36, height: 36, background: 'rgba(255,255,255,0.95)', border: 'none', cursor: 'pointer',
          display: 'flex', alignItems: 'center', justifyContent: 'center',
        }}>
          <HeartIcon size={16} filled={isFav} color={ECR.red} />
        </button>

        {/* Photo nav arrows */}
        <button onClick={() => setPhotoIdx((photoIdx - 1 + photoLabels.length) % photoLabels.length)} style={{
          position: 'absolute', left: 0, top: '50%', transform: 'translateY(-50%)',
          width: 36, height: 56, background: 'rgba(63,68,67,0.6)', border: 'none', cursor: 'pointer',
          display: 'flex', alignItems: 'center', justifyContent: 'center',
        }}>
          <ArrowIcon size={14} dir="left" color="#fff" />
        </button>
        <button onClick={() => setPhotoIdx((photoIdx + 1) % photoLabels.length)} style={{
          position: 'absolute', right: 0, top: '50%', transform: 'translateY(-50%)',
          width: 36, height: 56, background: 'rgba(63,68,67,0.6)', border: 'none', cursor: 'pointer',
          display: 'flex', alignItems: 'center', justifyContent: 'center',
        }}>
          <ArrowIcon size={14} dir="right" color="#fff" />
        </button>

        {/* Photo index bottom right */}
        <div style={{
          position: 'absolute', bottom: 16, right: 16,
          background: 'rgba(255,255,255,0.95)', padding: '6px 12px',
          fontFamily: 'Montserrat', fontWeight: 700, fontSize: 9, letterSpacing: '0.18em', textTransform: 'uppercase', color: ECR.charcoal,
        }}>
          {photoIdx + 1} / {photoLabels.length} · {photoLabels[photoIdx]}
        </div>
      </div>

      {/* Thumbnail strip */}
      <div style={{ display: 'flex', gap: 6, padding: '10px 24px', background: ECR.cream80, borderBottom: `1px solid ${ECR.grayLight}`, flexShrink: 0 }}>
        {photoLabels.map((label, i) => (
          <div
            key={i}
            onClick={() => setPhotoIdx(i)}
            style={{
              width: 76, height: 56, cursor: 'pointer',
              outline: photoIdx === i ? `2px solid ${ECR.red}` : `1px solid ${ECR.grayLight}`,
              outlineOffset: photoIdx === i ? -2 : -1,
              opacity: photoIdx === i ? 1 : 0.75,
              transition: 'opacity 150ms',
            }}
          >
            <PhotoCanvas property={property} variant={i} />
          </div>
        ))}
      </div>

      {/* Scrollable details */}
      <div style={{ flex: 1, overflow: 'auto', padding: '22px 24px 24px' }}>

        {/* Header */}
        <div style={{ marginBottom: 18 }}>
          <div style={{ fontFamily: 'Montserrat', fontWeight: 600, fontSize: 9, letterSpacing: '0.28em', textTransform: 'uppercase', color: ECR.red, marginBottom: 8 }}>
            {property.submarket}
          </div>
          <h2 style={{ fontFamily: 'Montserrat', fontWeight: 700, fontSize: 24, letterSpacing: '0.06em', textTransform: 'uppercase', color: ECR.charcoal, lineHeight: 1.1, margin: 0, marginBottom: 8 }}>
            {property.name}
          </h2>
          <div style={{ fontFamily: 'Montserrat', fontWeight: 400, fontSize: 11, color: ECR.charcoal70, letterSpacing: '0.06em', lineHeight: 1.5 }}>
            {property.address}<br />{property.city}
          </div>
        </div>

        {/* Key stats — banner */}
        <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr 1fr', gap: 0, background: ECR.cream, marginBottom: 22 }}>
          {[
            { label: property.type === 'Land' ? 'Acreage' : 'Size', value: sfDisplay },
            { label: property.status === 'For Sale' ? 'Price' : 'Rate', value: property.rate },
            { label: 'Available', value: property.available },
          ].map((s, i) => (
            <div key={i} style={{ padding: '14px 16px', borderRight: i < 2 ? `1px solid ${ECR.grayLight}` : 'none' }}>
              <div style={{ fontFamily: 'Montserrat', fontWeight: 600, fontSize: 8, letterSpacing: '0.24em', textTransform: 'uppercase', color: ECR.grayMid, marginBottom: 4 }}>
                {s.label}
              </div>
              <div style={{ fontFamily: 'Montserrat', fontWeight: 700, fontSize: 13, letterSpacing: '0.06em', color: ECR.charcoal, lineHeight: 1.2 }}>
                {s.value}
              </div>
            </div>
          ))}
        </div>

        {/* Description */}
        <p style={{ fontFamily: 'FreightText', fontWeight: 400, fontSize: 14, lineHeight: 1.65, color: ECR.charcoal, marginBottom: 22 }}>
          {property.description}
        </p>

        {/* Detail grid */}
        <div style={{ marginBottom: 24 }}>
          <div style={{ fontFamily: 'Montserrat', fontWeight: 700, fontSize: 9, letterSpacing: '0.28em', textTransform: 'uppercase', color: ECR.charcoal, marginBottom: 12, paddingBottom: 8, borderBottom: `2px solid ${ECR.charcoal}` }}>
            Property Details
          </div>
          <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: '12px 32px' }}>
            {[
              ['Property ID', property.id],
              ['Type', property.type],
              ['Floor / Suite', property.floorSuite],
              ['Min. Divisible', property.minDivSf >= property.sf ? '— full only' : (property.type === 'Land' ? `${(property.minDivSf / 43560).toFixed(1)} acres` : `${property.minDivSf.toLocaleString()} SF`)],
              ['Year Built', property.yearBuilt || '—'],
              ['Renovated', property.renovated || '—'],
              ['Parking Ratio', property.parking],
              ['Walk Score®', `${property.walkScore} / 100`],
            ].map(([k, v]) => (
              <div key={k} style={{ display: 'flex', justifyContent: 'space-between', gap: 12, borderBottom: `1px solid ${ECR.charcoal10}`, paddingBottom: 8 }}>
                <span style={{ fontFamily: 'Montserrat', fontWeight: 600, fontSize: 8.5, letterSpacing: '0.2em', textTransform: 'uppercase', color: ECR.grayMid }}>{k}</span>
                <span style={{ fontFamily: 'Montserrat', fontWeight: 600, fontSize: 10, letterSpacing: '0.04em', color: ECR.charcoal, textAlign: 'right' }}>{v}</span>
              </div>
            ))}
          </div>
        </div>

        {/* Amenities */}
        <div style={{ marginBottom: 24 }}>
          <div style={{ fontFamily: 'Montserrat', fontWeight: 700, fontSize: 9, letterSpacing: '0.28em', textTransform: 'uppercase', color: ECR.charcoal, marginBottom: 12, paddingBottom: 8, borderBottom: `2px solid ${ECR.charcoal}` }}>
            Walkability + Amenities
          </div>
          <div style={{ display: 'flex', flexWrap: 'wrap', gap: 6 }}>
            {property.amenities.map(a => (
              <span key={a} style={{
                fontFamily: 'Montserrat', fontWeight: 500, fontSize: 9.5, letterSpacing: '0.06em',
                background: ECR.cream80, color: ECR.charcoal, padding: '7px 10px',
                border: `1px solid ${ECR.grayLight}`,
              }}>{a}</span>
            ))}
          </div>
        </div>

        {/* Broker */}
        <div style={{ marginBottom: 22, padding: 16, background: ECR.charcoal, color: '#fff' }}>
          <div style={{ display: 'flex', alignItems: 'center', gap: 12 }}>
            <div style={{ width: 44, height: 44, background: ECR.red, display: 'flex', alignItems: 'center', justifyContent: 'center', fontFamily: 'MADECanvas', fontWeight: 900, fontSize: 14, letterSpacing: '0.08em', color: '#fff' }}>
              {property.broker.name.split(' ').map(n => n[0]).slice(0,2).join('')}
            </div>
            <div style={{ flex: 1, minWidth: 0 }}>
              <div style={{ fontFamily: 'Montserrat', fontWeight: 600, fontSize: 8, letterSpacing: '0.24em', textTransform: 'uppercase', color: ECR.grayMid, marginBottom: 3 }}>Listing Broker</div>
              <div style={{ fontFamily: 'Montserrat', fontWeight: 700, fontSize: 11, letterSpacing: '0.10em', textTransform: 'uppercase', color: '#fff', marginBottom: 2 }}>{property.broker.name}</div>
              <div style={{ fontFamily: 'Montserrat', fontWeight: 400, fontSize: 9, color: ECR.grayLight, letterSpacing: '0.04em' }}>{property.broker.title}</div>
            </div>
            <div style={{ display: 'flex', flexDirection: 'column', gap: 3, alignItems: 'flex-end' }}>
              <div style={{ fontFamily: 'Montserrat', fontWeight: 600, fontSize: 9, letterSpacing: '0.12em', color: '#fff' }}>{property.broker.phone}</div>
              <div style={{ fontFamily: 'Montserrat', fontWeight: 400, fontSize: 9, color: ECR.grayLight, letterSpacing: '0.04em' }}>{property.broker.email}</div>
            </div>
          </div>
        </div>

        {/* Primary CTA */}
        <button onClick={onOpenFullscreen} style={{
          width: '100%', display: 'flex', alignItems: 'center', justifyContent: 'space-between',
          padding: '18px 22px', background: ECR.red, color: '#fff', border: 'none', cursor: 'pointer',
          fontFamily: 'Montserrat', fontWeight: 700, fontSize: 11, letterSpacing: '0.24em', textTransform: 'uppercase',
        }}
          onMouseEnter={e => e.currentTarget.style.background = '#b3001a'}
          onMouseLeave={e => e.currentTarget.style.background = ECR.red}
        >
          <span>View Full Property Detail</span>
          <ArrowIcon size={14} dir="right" color="#fff" />
        </button>

        {/* Secondary actions */}
        <div style={{ display: 'flex', gap: 8, marginTop: 8 }}>
          <button style={{ flex: 1, padding: '11px 14px', background: 'transparent', color: ECR.charcoal, border: `1px solid ${ECR.grayLight}`, cursor: 'pointer', fontFamily: 'Montserrat', fontWeight: 700, fontSize: 9, letterSpacing: '0.22em', textTransform: 'uppercase' }}>
            Download Brochure
          </button>
          <button style={{ flex: 1, padding: '11px 14px', background: 'transparent', color: ECR.charcoal, border: `1px solid ${ECR.grayLight}`, cursor: 'pointer', fontFamily: 'Montserrat', fontWeight: 700, fontSize: 9, letterSpacing: '0.22em', textTransform: 'uppercase' }}>
            Schedule Tour
          </button>
        </div>
      </div>
    </div>
  );
}

Object.assign(window, {
  SiteHeader, SiteFooter, FilterToolbar, ListCard, DetailPanel, PhotoCanvas,
  HeartIcon, ArrowIcon, CloseIcon, SORT_OPTIONS, TYPE_FILTERS,
});
