// Shared parts for the Skrrs portal UI kit: Icon, Photo, Container, viewport hook,
// Header (responsive + drawer), MobileBar, Footer, PageHero, Crumbs.
const { Button, Avatar, Badge } = window.SkrrsDesignSystem_6013e8;

// ── Lucide-style inline icons ───────────────────────────────
const ICON_PATHS = {
  search: '<circle cx="11" cy="11" r="8"/><path d="m21 21-4.3-4.3"/>',
  heart: '<path d="M19 14c1.49-1.46 3-3.21 3-5.5A5.5 5.5 0 0 0 16.5 3c-1.76 0-3 .5-4.5 2-1.5-1.5-2.74-2-4.5-2A5.5 5.5 0 0 0 2 8.5c0 2.29 1.51 4.04 3 5.5l7 7Z"/>',
  phone: '<path d="M13.832 16.568a1 1 0 0 0 1.213-.303l.355-.465A2 2 0 0 1 17 15h3a2 2 0 0 1 2 2v3a2 2 0 0 1-2 2A18 18 0 0 1 2 4a2 2 0 0 1 2-2h3a2 2 0 0 1 2 2v3a2 2 0 0 1-.8 1.6l-.468.351a1 1 0 0 0-.292 1.233 14 14 0 0 0 6.392 6.384"/>',
  user: '<circle cx="12" cy="8" r="5"/><path d="M20 21a8 8 0 0 0-16 0"/>',
  menu: '<line x1="4" x2="20" y1="6" y2="6"/><line x1="4" x2="20" y1="12" y2="12"/><line x1="4" x2="20" y1="18" y2="18"/>',
  x: '<path d="M18 6 6 18"/><path d="m6 6 12 12"/>',
  chevR: '<polyline points="9 18 15 12 9 6"/>',
  chevL: '<polyline points="15 18 9 12 15 6"/>',
  chevD: '<polyline points="6 9 12 15 18 9"/>',
  pin: '<path d="M20 10c0 4.993-5.539 10.193-7.399 11.799a1 1 0 0 1-1.202 0C9.539 20.193 4 14.993 4 10a8 8 0 0 1 16 0"/><circle cx="12" cy="10" r="3"/>',
  train: '<rect x="4" y="3" width="16" height="16" rx="2"/><path d="M4 11h16"/><path d="M12 3v8"/><path d="m8 19-2 3"/><path d="m18 22-2-3"/><path d="M8 15h.01"/><path d="M16 15h.01"/>',
  ruler: '<path d="M21.3 15.3a2.4 2.4 0 0 1 0 3.4l-2.6 2.6a2.4 2.4 0 0 1-3.4 0L2.7 8.7a2.41 2.41 0 0 1 0-3.4l2.6-2.6a2.41 2.41 0 0 1 3.4 0Z"/><path d="m14.5 12.5 2-2"/><path d="m11.5 9.5 2-2"/><path d="m8.5 6.5 2-2"/><path d="m17.5 15.5 2-2"/>',
  building: '<path d="M6 22V4a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v18Z"/><path d="M6 12H4a2 2 0 0 0-2 2v6a2 2 0 0 0 2 2h2"/><path d="M18 9h2a2 2 0 0 1 2 2v9a2 2 0 0 1-2 2h-2"/><path d="M10 6h4M10 10h4M10 14h4M10 18h4"/>',
  doc: '<path d="M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z"/><path d="M14 2v4a2 2 0 0 0 2 2h4"/><path d="M16 13H8M16 17H8M10 9H8"/>',
  arrowR: '<line x1="5" y1="12" x2="19" y2="12"/><polyline points="12 5 19 12 12 19"/>',
  plus: '<line x1="12" x2="12" y1="5" y2="19"/><line x1="5" x2="19" y1="12" y2="12"/>',
  clock: '<circle cx="12" cy="12" r="10"/><polyline points="12 6 12 12 16 14"/>',
  check: '<path d="M20 6 9 17l-5-5"/>',
  mail: '<rect width="20" height="16" x="2" y="4" rx="2"/><path d="m22 7-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 7"/>',
  calendar: '<path d="M8 2v4M16 2v4"/><rect width="18" height="18" x="3" y="4" rx="2"/><path d="M3 10h18"/>',
  briefcase: '<path d="M16 20V4a2 2 0 0 0-2-2h-4a2 2 0 0 0-2 2v16"/><rect width="20" height="14" x="2" y="6" rx="2"/>',
  award: '<path d="m15.477 12.89 1.515 8.526a.5.5 0 0 1-.81.47l-3.58-2.687a1 1 0 0 0-1.197 0l-3.586 2.686a.5.5 0 0 1-.81-.469l1.514-8.526"/><circle cx="12" cy="8" r="6"/>',
  users: '<path d="M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2"/><circle cx="9" cy="7" r="4"/><path d="M22 21v-2a4 4 0 0 0-3-3.87"/><path d="M16 3.13a4 4 0 0 1 0 7.75"/>',
  layers: '<path d="M12.83 2.18a2 2 0 0 0-1.66 0L2.6 6.08a1 1 0 0 0 0 1.83l8.58 3.91a2 2 0 0 0 1.66 0l8.58-3.9a1 1 0 0 0 0-1.83Z"/><path d="m22 17.65-9.17 4.16a2 2 0 0 1-1.66 0L2 17.65"/><path d="m22 12.65-9.17 4.16a2 2 0 0 1-1.66 0L2 12.65"/>',
  target: '<circle cx="12" cy="12" r="10"/><circle cx="12" cy="12" r="6"/><circle cx="12" cy="12" r="2"/>',
  sparkles: '<path d="M9.937 15.5A2 2 0 0 0 8.5 14.063l-6.135-1.582a.5.5 0 0 1 0-.962L8.5 9.936A2 2 0 0 0 9.937 8.5l1.582-6.135a.5.5 0 0 1 .963 0L14.063 8.5A2 2 0 0 0 15.5 9.937l6.135 1.581a.5.5 0 0 1 0 .964L15.5 14.063a2 2 0 0 0-1.437 1.437l-1.582 6.135a.5.5 0 0 1-.963 0z"/>',
  quote: '<path d="M3 21c3 0 7-1 7-8V5c0-1.25-.756-2.017-2-2H4c-1.25 0-2 .75-2 1.972V11c0 1.25.75 2 2 2 1 0 1 0 1 1v1c0 1-1 2-2 2s-1 .008-1 1.031V20c0 1 0 1 1 1z"/><path d="M15 21c3 0 7-1 7-8V5c0-1.25-.757-2.017-2-2h-4c-1.25 0-2 .75-2 1.972V11c0 1.25.75 2 2 2h.75c0 2.25.25 4-2.75 4v3c0 1 0 1 1 1z"/>',
  store: '<path d="m2 7 4.41-4.41A2 2 0 0 1 7.83 2h8.34a2 2 0 0 1 1.42.59L22 7"/><path d="M4 12v8a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-8"/><path d="M2 7h20"/>',
  arrowUp: '<path d="m5 12 7-7 7 7"/><path d="M12 19V5"/>',
  filter: '<polygon points="22 3 2 3 10 12.46 10 19 14 21 14 12.46 22 3"/>',
  grid: '<rect width="7" height="7" x="3" y="3" rx="1"/><rect width="7" height="7" x="14" y="3" rx="1"/><rect width="7" height="7" x="14" y="14" rx="1"/><rect width="7" height="7" x="3" y="14" rx="1"/>',
  warehouse: '<path d="M22 8.35V20a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V8.35A2 2 0 0 1 3.26 6.5l8-3.2a2 2 0 0 1 1.48 0l8 3.2A2 2 0 0 1 22 8.35Z"/><path d="M6 18h12M6 14h12M6 22V10h12v12"/>',
  factory: '<path d="M2 20a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V8l-7 5V8l-7 5V4a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2Z"/><path d="M17 18h.01M13 18h.01M9 18h.01"/>',
  school: '<path d="M14 22v-4a2 2 0 0 0-4 0v4"/><path d="m18 10 4 2v8a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2v-8l4-2"/><path d="M18 5v17"/><path d="m4 6 8-4 8 4"/><path d="M6 5v17"/><circle cx="12" cy="9" r="2"/>',
  handshake: '<path d="m11 17 2 2a1 1 0 1 0 3-3"/><path d="m14 14 2.5 2.5a1 1 0 1 0 3-3l-3.88-3.88a3 3 0 0 0-4.24 0l-.88.88a1 1 0 1 1-3-3l2.81-2.81a5.79 5.79 0 0 1 7.06-.87l.47.28a2 2 0 0 0 1.42.25L21 4"/><path d="m21 3 1 11h-2"/><path d="M3 3 2 14l6.5 6.5a1 1 0 1 0 3-3"/><path d="M3 4h8"/>',
  shield: '<path d="M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z"/><path d="m9 12 2 2 4-4"/>',
  car: '<path d="M19 17h2c.6 0 1-.4 1-1v-3c0-.9-.7-1.7-1.5-1.9C18.7 10.6 16 10 16 10s-1.3-1.4-2.2-2.3c-.5-.4-1.1-.7-1.8-.7H5c-.6 0-1.1.4-1.4.9l-1.4 2.9A3.7 3.7 0 0 0 2 12v4c0 .6.4 1 1 1h2"/><circle cx="7" cy="17" r="2"/><path d="M9 17h6"/><circle cx="17" cy="17" r="2"/>',
  snow: '<path d="M2 12h20M12 2v20m6.36-15.36L5.64 18.36m12.72 0L5.64 5.64"/><path d="m8 4 4 2 4-2M8 20l4-2 4 2M4 8l2 4-2 4M20 8l-2 4 2 4"/>',
  wifi: '<path d="M12 20h.01"/><path d="M2 8.82a15 15 0 0 1 20 0"/><path d="M5 12.859a10 10 0 0 1 14 0"/><path d="M8.5 16.429a5 5 0 0 1 7 0"/>',
  maximize: '<path d="M8 3H5a2 2 0 0 0-2 2v3M21 8V5a2 2 0 0 0-2-2h-3M3 16v3a2 2 0 0 0 2 2h3M16 21h3a2 2 0 0 0 2-2v-3"/>',
  zap: '<path d="M4 14a1 1 0 0 1-.78-1.63l9.9-10.2a.5.5 0 0 1 .86.46l-1.92 6.02A1 1 0 0 0 13 10h7a1 1 0 0 1 .78 1.63l-9.9 10.2a.5.5 0 0 1-.86-.46l1.92-6.02A1 1 0 0 0 11 14z"/>',
  droplet: '<path d="M12 22a7 7 0 0 0 7-7c0-2-1-3.9-3-5.5s-3.5-4-4-6.5c-.5 2.5-2 4.9-4 6.5C6 11.1 5 13 5 15a7 7 0 0 0 7 7z"/>',
  key: '<path d="m15.5 7.5 2.3 2.3a1 1 0 0 0 1.4 0l2.1-2.1a1 1 0 0 0 0-1.4L19 4"/><path d="m21 2-9.6 9.6"/><circle cx="7.5" cy="15.5" r="5.5"/>',
  video: '<path d="m16 13 5.223 3.482a.5.5 0 0 0 .777-.416V7.87a.5.5 0 0 0-.752-.432L16 10.5"/><rect x="2" y="6" width="14" height="12" rx="2"/>',
  download: '<path d="M12 15V3"/><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><path d="m7 10 5 5 5-5"/>',
  star: '<path d="M11.525 2.295a.53.53 0 0 1 .95 0l2.31 4.679a2.123 2.123 0 0 0 1.595 1.16l5.166.756a.53.53 0 0 1 .294.904l-3.736 3.638a2.123 2.123 0 0 0-.611 1.878l.882 5.14a.53.53 0 0 1-.771.56l-4.618-2.428a2.122 2.122 0 0 0-1.973 0L6.396 21.01a.53.53 0 0 1-.77-.56l.881-5.139a2.122 2.122 0 0 0-.611-1.879L2.16 9.795a.53.53 0 0 1 .294-.906l5.165-.755a2.122 2.122 0 0 0 1.597-1.16z"/>',
};
function Icon({ name, size = 20, stroke = 1.75, fill = 'none', style }) {
  return <svg width={size} height={size} viewBox="0 0 24 24" fill={fill} stroke="currentColor"
    strokeWidth={stroke} strokeLinecap="round" strokeLinejoin="round" style={{ display:'block', flex:'none', ...style }}
    dangerouslySetInnerHTML={{ __html: ICON_PATHS[name] || '' }} />;
}

// ── Viewport hook ───────────────────────────────────────────
function useViewport() {
  const get = () => (typeof window !== 'undefined' ? window.innerWidth : 1280);
  const [w, setW] = React.useState(get());
  React.useEffect(() => {
    const on = () => setW(get());
    window.addEventListener('resize', on);
    return () => window.removeEventListener('resize', on);
  }, []);
  return { w, isMobile: w < 768, isTablet: w >= 768 && w < 1024, isDesktop: w >= 1024 };
}

// ── Brand lockup (real Skrrs wordmark) ──────────────────────
function Logo({ white = false, size = 30 }) {
  const data = (typeof window !== 'undefined' && window.SKRRS_LOGO) ? window.SKRRS_LOGO : null;
  const src = data
    ? (white ? data.white : data.blue)
    : `../../assets/logo/${white ? 'skrrs-wordmark-white.png' : 'skrrs-wordmark.png'}`;
  return (
    <img
      src={src}
      alt="Skrrs — 事業用不動産ポータル"
      style={{ height: size * 1.18, width: 'auto', maxWidth: 'none', display: 'block', alignSelf: 'flex-start', flex: 'none' }}
    />
  );
}

// ── Photo: real image when `src` is given, designed gradient otherwise ──
const IMG_BASE = '../../assets/photos/';
function Photo({ src, alt, hue = 'var(--blue-700)', label, icon = 'building', ratio = '16 / 10',
  radius = 0, position = 'center', overlay = 0, eager = false, style }) {
  const wrap = { position:'relative', aspectRatio:ratio, borderRadius:radius, overflow:'hidden',
    background:`linear-gradient(140deg, ${hue}, color-mix(in srgb, ${hue} 62%, #000))`, ...style };
  if (src) {
    const data = (typeof window !== 'undefined' && window.SKRRS_PHOTO_DATA) ? window.SKRRS_PHOTO_DATA[src] : null;
    const url = data || (/^(https?:|data:|\.|\/)/.test(src) ? src : IMG_BASE + src);
    return (
      <div role="img" aria-label={alt || label || '物件イメージ'} style={wrap}>
        <img src={url} alt="" loading={eager ? 'eager' : 'lazy'} decoding="async" fetchpriority={eager ? 'high' : 'auto'}
          style={{ position:'absolute', inset:0, width:'100%', height:'100%', objectFit:'cover', objectPosition:position, display:'block' }} />
        {overlay > 0 && <div style={{ position:'absolute', inset:0, background:`rgba(7,24,43,${overlay})` }} />}
      </div>
    );
  }
  return (
    <div role="img" aria-label={label || '物件イメージ'} style={wrap}>
      <div style={{ position:'absolute', inset:0, opacity:0.14,
        backgroundImage:'repeating-linear-gradient(135deg, #fff 0 1px, transparent 1px 16px)' }} />
      <div style={{ position:'absolute', inset:0, display:'flex', flexDirection:'column',
        alignItems:'center', justifyContent:'center', gap:8, color:'rgba(255,255,255,0.78)' }}>
        <Icon name={icon} size={30} stroke={1.4} />
        {label && <span style={{ font:'600 0.6875rem/1 var(--font-latin)', letterSpacing:'0.14em',
          textTransform:'uppercase' }}>{label}</span>}
      </div>
    </div>
  );
}

function Container({ children, wide = false, style }) {
  return <div style={{ width:'100%', maxWidth: wide ? 'var(--container-wide)' : 'var(--container)',
    margin:'0 auto', padding:'0 var(--gutter)', ...style }}>{children}</div>;
}

// ── Header (responsive) ─────────────────────────────────────
// サービスは「借りたい方へ / 貸したい方へ」の2分岐をメガメニューで表示。
const SERVICE_MENU = [
  { en:'For Tenants', label:'借りたい方へ', sub:'事業用不動産 賃貸仲介', route:'lease',
    desc:'物件探しから条件交渉・契約まで一括代行。本業に集中いただけます。', icon:'handshake' },
  { en:'For Owners', label:'貸したい方へ', sub:'事業用不動産 物件管理', route:'manage',
    desc:'攻めのリーシングと丁寧な管理で、空室を早期成約へ。', icon:'shield' },
];
const NAV = [
  { label:'物件を探す',     route:'search'   },
  { label:'サービス',       route:'services', mega:true },
  { label:'お客様の声',     route:'projects' },
  { label:'不動産コラム',   route:'columns'  },
  { label:'はじめての方へ', route:'guide'    },
  { label:'会社概要',       route:'company'  },
];
function Header({ onNav, favCount = 0, current = 'home' }) {
  const { isDesktop } = useViewport();
  const [open, setOpen] = React.useState(false);
  const [mega, setMega] = React.useState(false);
  const megaTimer = React.useRef(null);
  React.useEffect(() => { setOpen(false); setMega(false); }, [current]);
  React.useEffect(() => () => { if (megaTimer.current) clearTimeout(megaTimer.current); }, []);
  const openMega  = () => { if (megaTimer.current) clearTimeout(megaTimer.current); setMega(true); };
  const closeMega = () => { if (megaTimer.current) clearTimeout(megaTimer.current); megaTimer.current = setTimeout(()=>setMega(false), 220); };

  const navLink = (n) => {
    const active = current === n.route;
    if (n.mega) {
      return (
        <div key={n.route} style={{ position:'relative' }}
          onMouseEnter={openMega} onMouseLeave={closeMega}>
          <a onClick={() => onNav(n.route)} style={{ cursor:'pointer', display:'inline-flex', alignItems:'center', gap:5,
            font:`${active?'var(--fw-bold)':'var(--fw-medium)'} var(--t-sm)/1 var(--font-body)`,
            color: active ? 'var(--blue-700)' : 'var(--text-strong)',
            paddingBottom:4, borderBottom: active ? '2px solid var(--blue-600)' : '2px solid transparent' }}>
            {n.label}<Icon name="chevD" size={14} style={{ transform: mega?'rotate(180deg)':'none', transition:'transform var(--dur-fast) var(--ease-out)' }}/>
          </a>
          {mega && (
            // 透明ブリッジ込み：top:100% + paddingTop で「サービス」とパネルの間の隙間を埋め、
            // マウスが下に移動しても hover が途切れないようにする。
            <div onMouseEnter={openMega} onMouseLeave={closeMega}
              style={{ position:'absolute', top:'100%', left:'50%', transform:'translateX(-50%)',
                paddingTop:14, zIndex:70 }}>
              <div style={{ width:560, maxWidth:'90vw', background:'var(--surface)', border:'1px solid var(--border-subtle)', borderRadius:'var(--r-md)',
                boxShadow:'var(--shadow-lg)', padding:'var(--sp-5)', display:'grid', gridTemplateColumns:'1fr 1fr', gap:'var(--sp-4)' }}>
                {SERVICE_MENU.map(s=>(
                  <a key={s.label} onClick={()=>onNav(s.route)} style={{ cursor:'pointer', display:'flex', flexDirection:'column', gap:8,
                    padding:'var(--sp-4)', borderRadius:'var(--r-sm)', border:'1px solid var(--border-subtle)', background:'var(--surface)',
                    transition:'background var(--dur-fast) var(--ease-out)' }}
                    onMouseEnter={e=>e.currentTarget.style.background='var(--blue-50)'}
                    onMouseLeave={e=>e.currentTarget.style.background='var(--surface)'}>
                    <span style={{ display:'flex', alignItems:'center', gap:8, color:'var(--blue-600)' }}>
                      <Icon name={s.icon} size={20}/>
                      <span style={{ font:'600 var(--t-2xs)/1 var(--font-latin)', letterSpacing:'0.14em', textTransform:'uppercase', color:'var(--blue-500)' }}>{s.en}</span>
                    </span>
                    <span style={{ font:'var(--fw-bold) var(--t-base)/1.3 var(--font-display)', color:'var(--text-strong)' }}>{s.label}</span>
                    <span style={{ font:'var(--fw-medium) var(--t-xs)/1 var(--font-body)', color:'var(--blue-700)' }}>{s.sub}</span>
                    <span style={{ font:'var(--fw-regular) var(--t-xs)/1.6 var(--font-body)', color:'var(--text-muted)' }}>{s.desc}</span>
                  </a>
                ))}
              </div>
            </div>
          )}
        </div>
      );
    }
    return (
      <a key={n.route} onClick={() => onNav(n.route)} style={{ cursor:'pointer',
        font:`${active?'var(--fw-bold)':'var(--fw-medium)'} var(--t-sm)/1 var(--font-body)`,
        color: active ? 'var(--blue-700)' : 'var(--text-strong)',
        paddingBottom:4, borderBottom: active ? '2px solid var(--blue-600)' : '2px solid transparent' }}>{n.label}</a>
    );
  };

  return (
    <header style={{ position:'sticky', top:0, zIndex:50 }}>
      {/* utility strip */}
      <div style={{ background:'var(--blue-900)', color:'rgba(255,255,255,0.86)' }}>
        <Container style={{ display:'flex', alignItems:'center', justifyContent:'space-between', height:36 }}>
          <span style={{ font:'var(--fw-medium) var(--t-2xs)/1 var(--font-body)', letterSpacing:'0.03em',
            whiteSpace:'nowrap', overflow:'hidden', textOverflow:'ellipsis', minWidth:0 }}>
            {isDesktop ? '事業用不動産の総合パートナー｜オフィス・店舗・教室・倉庫・工場' : '事業用不動産の総合パートナー'}
          </span>
          <span style={{ display:'flex', alignItems:'center', gap:16, flex:'none', font:'var(--fw-medium) var(--t-2xs)/1 var(--font-body)' }}>
            {isDesktop && <a onClick={()=>onNav('company')} style={{ cursor:'pointer', color:'rgba(255,255,255,0.86)' }}>会社概要</a>}
            {isDesktop && <a onClick={()=>onNav('news')} style={{ cursor:'pointer', color:'rgba(255,255,255,0.86)' }}>お知らせ</a>}
            {isDesktop && <span style={{ display:'inline-flex', alignItems:'center', gap:6 }}><Icon name="clock" size={13}/>平日 10:00〜18:00</span>}
            <a href="tel:0359377544" style={{ display:'inline-flex', alignItems:'center', gap:6, color:'#fff', fontWeight:700, textDecoration:'none' }}><Icon name="phone" size={13}/>03-5937-7544</a>
          </span>
        </Container>
      </div>
      {/* main bar */}
      <div style={{ background:'rgba(255,255,255,0.92)', backdropFilter:'blur(8px)',
        borderBottom:'1px solid var(--border-subtle)', boxShadow:'var(--shadow-xs)' }}>
        <Container style={{ display:'flex', alignItems:'center', justifyContent:'space-between', height:'var(--header-h)', gap:16 }}>
          <a onClick={()=>onNav('home')} aria-label="ホーム" style={{ cursor:'pointer', flex:'none' }}><Logo size={isDesktop?30:26}/></a>

          {isDesktop && (
            <nav aria-label="メインナビゲーション" style={{ display:'flex', alignItems:'center', gap:26 }}>
              {NAV.map(navLink)}
            </nav>
          )}

          <div style={{ display:'flex', alignItems:'center', gap:isDesktop?14:10 }}>
            <a onClick={()=>onNav('favorites')} aria-label="お気に入り" style={{ cursor:'pointer', position:'relative', display:'inline-flex',
              flexDirection:'column', alignItems:'center', gap:2, color:'var(--blue-800)' }}>
              <span style={{ position:'relative' }}>
                <Icon name="heart" size={20}/>
                <span style={{ position:'absolute', top:-7, right:-9, minWidth:16, height:16, padding:'0 4px',
                  borderRadius:8, background:'var(--blue-600)', color:'#fff',
                  font:'var(--fw-bold) 0.625rem/16px var(--font-num)', textAlign:'center' }}>{favCount}</span>
              </span>
              {isDesktop && <span style={{ font:'var(--fw-medium) 0.625rem/1 var(--font-body)', color:'var(--text-muted)' }}>お気に入り</span>}
            </a>
            {isDesktop ? (
              <Button variant="primary" size="sm" pill iconLeft={<Icon name="mail" size={15}/>} onClick={()=>onNav('contact')}>無料相談・お問い合わせ</Button>
            ) : (
              <button aria-label="メニュー" onClick={()=>setOpen(true)} style={{ display:'inline-flex', alignItems:'center', justifyContent:'center',
                width:42, height:42, border:'1px solid var(--border-default)', borderRadius:'var(--r-sm)', background:'var(--surface)', color:'var(--blue-900)', cursor:'pointer' }}>
                <Icon name="menu" size={22}/>
              </button>
            )}
          </div>
        </Container>
      </div>

      {/* mobile drawer */}
      {open && (
        <div onClick={()=>setOpen(false)} style={{ position:'fixed', inset:0, zIndex:60, background:'rgba(7,24,43,0.5)' }}>
          <div onClick={e=>e.stopPropagation()} style={{ position:'absolute', top:0, right:0, bottom:0, width:'min(86vw, 360px)',
            background:'var(--surface)', boxShadow:'var(--shadow-xl)', display:'flex', flexDirection:'column', padding:'18px 20px', overflowY:'auto' }}>
            <div style={{ display:'flex', alignItems:'center', justifyContent:'space-between', marginBottom:18 }}>
              <Logo size={26}/>
              <button aria-label="閉じる" onClick={()=>setOpen(false)} style={{ width:40, height:40, border:'none', background:'var(--surface-sunken)', borderRadius:'var(--r-sm)', color:'var(--blue-900)', cursor:'pointer', display:'grid', placeItems:'center' }}><Icon name="x" size={20}/></button>
            </div>
            <nav style={{ display:'flex', flexDirection:'column' }}>
              {NAV.map(n=> n.mega ? (
                <React.Fragment key={n.route}>
                  <span style={{ display:'flex', alignItems:'center', justifyContent:'space-between', padding:'15px 4px 8px',
                    font:'var(--fw-bold) var(--t-base)/1 var(--font-body)', color:'var(--text-strong)' }}>{n.label}</span>
                  {SERVICE_MENU.map(s=>(
                    <a key={s.label} onClick={()=>onNav(s.route)} style={{ cursor:'pointer', display:'flex', alignItems:'center', justifyContent:'space-between',
                      padding:'12px 4px 12px 18px', borderBottom:'1px solid var(--border-subtle)',
                      font:'var(--fw-medium) var(--t-sm)/1.3 var(--font-body)', color:'var(--blue-700)' }}>
                      <span style={{ display:'flex', flexDirection:'column', gap:3 }}>{s.label}<span style={{ font:'var(--fw-regular) var(--t-2xs)/1 var(--font-body)', color:'var(--text-muted)' }}>{s.sub}</span></span>
                      <Icon name="chevR" size={16} style={{ color:'var(--text-faint)' }}/>
                    </a>
                  ))}
                </React.Fragment>
              ) : (
                <a key={n.route} onClick={()=>{ onNav(n.route); }} style={{ cursor:'pointer', display:'flex', alignItems:'center', justifyContent:'space-between',
                  padding:'15px 4px', borderBottom:'1px solid var(--border-subtle)',
                  font:`${current===n.route?'var(--fw-bold)':'var(--fw-medium)'} var(--t-base)/1 var(--font-body)`,
                  color: current===n.route ? 'var(--blue-700)' : 'var(--text-strong)' }}>
                  {n.label}<Icon name="chevR" size={16} style={{ color:'var(--text-faint)' }}/>
                </a>
              ))}
              <a onClick={()=>onNav('news')} style={{ cursor:'pointer', display:'flex', alignItems:'center', justifyContent:'space-between', padding:'15px 4px', borderBottom:'1px solid var(--border-subtle)', font:'var(--fw-medium) var(--t-base)/1 var(--font-body)', color:'var(--text-strong)' }}>お知らせ<Icon name="chevR" size={16} style={{ color:'var(--text-faint)' }}/></a>
            </nav>
            <div style={{ display:'flex', flexDirection:'column', gap:10, marginTop:20 }}>
              <Button variant="primary" full pill onClick={()=>onNav('contact')}>無料相談・お問い合わせ</Button>
            </div>
            <a href="tel:0359377544" style={{ marginTop:18, display:'inline-flex', alignItems:'center', justifyContent:'center', gap:8, color:'var(--blue-900)', textDecoration:'none' }}>
              <Icon name="phone" size={18}/><span style={{ font:'700 1.2rem/1 var(--font-num)' }}>03-5937-7544</span>
            </a>
            <span style={{ textAlign:'center', font:'var(--fw-regular) var(--t-2xs)/1 var(--font-body)', color:'var(--text-faint)', marginTop:6 }}>営業時間／平日 10:00〜18:00</span>
          </div>
        </div>
      )}
    </header>
  );
}

// ── Mobile sticky bottom action bar ─────────────────────────
function MobileBar({ onNav, current }) {
  const { isDesktop } = useViewport();
  if (isDesktop) return null;
  const items = [
    { route:'home', label:'ホーム', icon:'building' },
    { route:'search', label:'物件検索', icon:'search' },
    { route:'favorites', label:'お気に入り', icon:'heart' },
    { route:'contact', label:'相談', icon:'mail' },
  ];
  return (
    <nav aria-label="クイックナビ" style={{ position:'fixed', bottom:0, left:0, right:0, zIndex:55,
      background:'rgba(255,255,255,0.96)', backdropFilter:'blur(8px)', borderTop:'1px solid var(--border-subtle)',
      display:'grid', gridTemplateColumns:'repeat(4,1fr)', boxShadow:'0 -2px 12px rgba(7,48,75,0.08)', paddingBottom:'env(safe-area-inset-bottom)' }}>
      {items.map(it=>{
        const on = current===it.route;
        return (
          <a key={it.route} onClick={()=>onNav(it.route)} style={{ cursor:'pointer', display:'flex', flexDirection:'column', alignItems:'center', gap:3,
            padding:'9px 0', color: on ? 'var(--blue-600)' : 'var(--text-muted)' }}>
            <Icon name={it.icon} size={21} fill={on&&it.icon==='heart'?'currentColor':'none'}/>
            <span style={{ font:`${on?'var(--fw-bold)':'var(--fw-medium)'} 0.625rem/1 var(--font-body)` }}>{it.label}</span>
          </a>
        );
      })}
    </nav>
  );
}

// ── Reusable page hero band + breadcrumb ────────────────────
function Crumbs({ items = [], onNav }) {
  return (
    <nav aria-label="パンくず" style={{ display:'flex', alignItems:'center', gap:8, flexWrap:'wrap',
      font:'var(--fw-regular) var(--t-xs)/1.4 var(--font-body)', color:'rgba(255,255,255,0.6)' }}>
      {items.map((it, i) => (
        <React.Fragment key={i}>
          {i>0 && <Icon name="chevR" size={12} style={{ color:'rgba(255,255,255,0.4)' }}/>}
          {it.route && i < items.length-1
            ? <a onClick={()=>onNav(it.route)} style={{ cursor:'pointer', color:'rgba(255,255,255,0.7)' }}>{it.label}</a>
            : <span style={{ color: i===items.length-1 ? '#fff' : 'rgba(255,255,255,0.7)' }}>{it.label}</span>}
        </React.Fragment>
      ))}
    </nav>
  );
}

function PageHero({ marker, title, lead, crumbs, onNav, icon = 'building', image, position = 'center' }) {
  return (
    <section style={{ position:'relative', background:'var(--blue-900)', overflow:'hidden' }}>
      <Photo src={image} hue="var(--blue-800)" icon={icon} ratio="auto" position={position} eager style={{ position:'absolute', inset:0, aspectRatio:'auto' }} />
      <div style={{ position:'absolute', inset:0, background:'linear-gradient(100deg, rgba(7,24,43,0.94), rgba(7,48,75,0.62))' }} />
      <Container style={{ position:'relative', paddingTop:'var(--sp-12)', paddingBottom:'var(--sp-12)' }}>
        {crumbs && <div style={{ marginBottom:18 }}><Crumbs items={crumbs} onNav={onNav}/></div>}
        {marker && <span style={{ display:'block', font:'600 var(--t-xs)/1 var(--font-latin)', letterSpacing:'0.18em',
          textTransform:'uppercase', color:'var(--blue-300)', marginBottom:12 }}>{marker}</span>}
        <h1 style={{ margin:0, font:'900 var(--t-h1)/1.25 var(--font-display)', color:'#fff', letterSpacing:'-0.02em' }}
          dangerouslySetInnerHTML={{ __html: title }} />
        {lead && <p style={{ margin:'18px 0 0', maxWidth:680, font:'var(--fw-regular) var(--t-lead)/1.85 var(--font-body)', color:'rgba(255,255,255,0.84)' }}>{lead}</p>}
      </Container>
    </section>
  );
}

// ── スマホ用：横スクロール＋自動スライドのカルーセル（ループ） ──
function AutoCarousel({ children, basis = '46%' }) {
  const ref = React.useRef(null);
  const items = React.Children.toArray(children);
  React.useEffect(() => {
    const el = ref.current;
    if (!el) return;
    let i = 0;
    const id = setInterval(() => {
      if (!el.children.length) return;
      i = (i + 1) % el.children.length;
      const c = el.children[i];
      el.scrollTo({ left: c.offsetLeft - el.offsetLeft, behavior: 'smooth' });
    }, 3000);
    return () => clearInterval(id);
  }, [items.length]);
  return (
    <div ref={ref} className="skrrs-carousel" style={{ display:'flex', gap:'var(--sp-4)', overflowX:'auto',
      scrollSnapType:'x mandatory', WebkitOverflowScrolling:'touch', paddingBottom:10, scrollbarWidth:'none', msOverflowStyle:'none' }}>
      {items.map((ch, idx) => (
        <div key={idx} style={{ flex:`0 0 ${basis}`, minWidth:0, scrollSnapAlign:'start', display:'flex' }}>{ch}</div>
      ))}
    </div>
  );
}

// ── Full-bleed photo band（テキスト/アイコン連続区間のビジュアルブレイク） ──
function PhotoBand({ src, eyebrow, title, sub, position = 'center 45%', cta, ctaRoute, onNav, height }) {
  const { isMobile } = useViewport();
  return (
    <section style={{ position:'relative', overflow:'hidden' }}>
      <Photo src={src} hue="var(--blue-800)" ratio="auto" position={position} style={{ position:'absolute', inset:0, aspectRatio:'auto' }} />
      <div style={{ position:'absolute', inset:0, background:'linear-gradient(100deg, rgba(7,24,43,0.86) 0%, rgba(7,48,75,0.5) 100%)' }} />
      <Container style={{ position:'relative', minHeight: isMobile ? (height||240) : (height||330),
        display:'flex', flexDirection:'column', justifyContent:'center', gap:14,
        paddingTop:'var(--sp-14)', paddingBottom:'var(--sp-14)' }}>
        {eyebrow && (
          <span style={{ display:'inline-flex', alignItems:'center', gap:8 }}>
            <span style={{ width:26, height:2, background:'var(--blue-400)' }} />
            <span style={{ font:'600 var(--t-2xs)/1 var(--font-latin)', letterSpacing:'0.18em', textTransform:'uppercase', color:'var(--blue-200)' }}>{eyebrow}</span>
          </span>
        )}
        {title && <p style={{ margin:0, maxWidth:640, font:`900 ${isMobile?'var(--t-h3)':'var(--t-h1)'}/1.5 var(--font-display)`, color:'#fff', letterSpacing:'-0.01em' }}>{title}</p>}
        {sub && <p style={{ margin:0, maxWidth:560, font:'var(--fw-regular) var(--t-base)/1.85 var(--font-body)', color:'rgba(255,255,255,0.84)' }}>{sub}</p>}
        {cta && onNav && (
          <div style={{ marginTop:6 }}>
            <Button variant="inverse" pill iconLeft={<Icon name="mail" size={17}/>} onClick={()=>onNav(ctaRoute||'contact')}>{cta}</Button>
          </div>
        )}
      </Container>
    </section>
  );
}

// ── Footer (responsive, route-linked) ───────────────────────
const FOOTER_COLS = [
  { h:'物件を探す', links:[['オフィスを探す','search'],['店舗を探す','search'],['教室を探す','search'],['倉庫を探す','search'],['工場を探す','search']] },
  { h:'エリアから探す', links:[['東京都','search'],['神奈川県','search'],['埼玉県','search']] },
  { h:'サービス', links:[['借りたい方へ（賃貸仲介）','lease'],['貸したい方へ（物件管理）','manage'],['不動産コラム','columns'],['お客様の声','projects']] },
  { h:'お役立ち情報', links:[['はじめての方へ','guide'],['よくあるご質問','guide'],['お知らせ','news'],['ご相談・お問い合わせ','contact']] },
  { h:'会社情報', links:[['会社概要','company'],['プライバシーポリシー','company'],['ご相談・お問い合わせ','contact']] },
];
const LEGAL = [['プライバシーポリシー','company'],['利用規約','company'],['個人情報のお取扱い','company'],['Cookie設定','company']];
function Footer({ onNav }) {
  const { isDesktop } = useViewport();
  return (
    <footer style={{ background:'var(--blue-950)', color:'rgba(255,255,255,0.72)' }}>
      <Container style={{ paddingTop:'var(--sp-16)', paddingBottom:'var(--sp-10)' }}>
        <div style={{ display:'grid', gridTemplateColumns: isDesktop ? '1.2fr repeat(5, 1fr)' : '1fr 1fr', gap:'var(--sp-8) var(--sp-6)', marginBottom:'var(--sp-12)' }}>
          <div style={{ display:'flex', flexDirection:'column', gap:16, gridColumn: isDesktop ? 'auto' : '1 / -1' }}>
            <Logo white/>
            <p style={{ margin:0, font:'var(--fw-regular) var(--t-xs)/1.8 var(--font-body)', color:'rgba(255,255,255,0.6)' }}>
              豊富な実績と専門知識で、事業用不動産のあらゆる課題を最適解へ導きます。
            </p>
            <a href="tel:0359377544" style={{ display:'inline-flex', alignItems:'center', gap:8, color:'#fff', textDecoration:'none' }}>
              <Icon name="phone" size={16}/><span style={{ font:'var(--fw-bold) var(--t-base)/1 var(--font-num)' }}>03-5937-7544</span>
            </a>
          </div>
          {FOOTER_COLS.map(col=>(
            <div key={col.h} style={{ display:'flex', flexDirection:'column', gap:11 }}>
              <span style={{ font:'var(--fw-bold) var(--t-sm)/1 var(--font-body)', color:'#fff' }}>{col.h}</span>
              {col.links.map(([l,r])=>(
                <a key={l} onClick={()=>onNav(r)} style={{ cursor:'pointer', font:'var(--fw-regular) var(--t-xs)/1.4 var(--font-body)', color:'rgba(255,255,255,0.66)' }}>{l}</a>
              ))}
            </div>
          ))}
        </div>
        <div style={{ borderTop:'1px solid rgba(255,255,255,0.12)', paddingTop:'var(--sp-6)',
          display:'flex', alignItems:'center', justifyContent:'space-between', gap:16, flexWrap:'wrap' }}>
          <div style={{ display:'flex', gap:14, flexWrap:'wrap' }}>
            {LEGAL.map(([l,r])=>(<a key={l} onClick={()=>onNav(r)} style={{ cursor:'pointer', font:'var(--fw-regular) 0.6875rem/1 var(--font-body)', color:'rgba(255,255,255,0.55)' }}>{l}</a>))}
          </div>
          <span style={{ font:'var(--fw-regular) 0.6875rem/1 var(--font-num)', color:'rgba(255,255,255,0.45)' }}>© 2026 Skrrs Inc. All rights reserved.</span>
        </div>
      </Container>
    </footer>
  );
}

Object.assign(window, { Icon, Logo, Photo, Container, useViewport, Header, Footer, MobileBar, PageHero, PhotoBand, AutoCarousel, Crumbs });
