// Mobile shared components.
// Same tokens (R3_TOK), simpler chrome. Designed for iPhone width ~390-402.

const S_M = window.Site;
const SL_M = window.SL;
const T_M = window.R3_TOK;
const { COMPANY: CO_M, CoverImg: Img_M, Icon: Ic_M, BrandMark: Brand_M, BrandLockup: Lockup_M, PlaceholderTag: PT_M, BudouXText: BT_M, copyText: copyText_M } = S_M;
const { slHref, slServiceHref, slCaseHref, slNavHref, dialablePhone } = SL_M;

// --- B-option orange palette (design.md colors). Additive only: existing T_M keys untouched.
if (T_M.oMain == null) {
  Object.assign(T_M, {
    oMain: T_M.orange,       // primary action orange
    oDeep: T_M.orangeDeep,   // gradient bottom / orange text on white
    oMark: T_M.orangeMark,   // logo mark
    oSoft: T_M.orangeSoft,   // pale orange surface
    oLine: T_M.orangeLine,   // thin orange border
  });
}

const mobileHref = slHref;
const mobileServiceHref = slServiceHref;
const mobileCaseHref = slCaseHref;
const mobileNavHref = slNavHref;
const mobilePhoneHref = `tel:${dialablePhone(CO_M.phone)}`;
const mobilePrivacyHref = `${mobileHref('contact')}#privacy-notice`;
const mobileHours = String(CO_M.hours || '').trim();
const mobileFooterHref = (label) => ({
  '雨漏り診断': mobileServiceHref('leak'),
  '部分・応急補修': mobileServiceHref('spot'),
  '定期メンテナンス': mobileServiceHref('maint'),
  '全体改修': mobileServiceHref('full'),
  '外壁・内装・水回り': mobileServiceHref('reform'),
  '施工事例': mobileHref('cases'),
  'お役立ち情報': mobileHref('knowledge'),
  '相談の流れ': `${mobileHref('top')}#flow`,
  '会社案内': mobileHref('company'),
  'メールフォーム': mobileHref('contact'),
  [CO_M.phone]: mobilePhoneHref,
}[label]);

// ---------- Buttons (touch-target 44px+) ----------
function MBtn({ children, icon, kind = 'primary', size = 'md', full, href, style }) {
  const base = {
    fontFamily: 'inherit', fontWeight: 700, letterSpacing: 0.4,
    fontSize: size === 'sm' ? 13 : 14.5,
    minHeight: size === 'sm' ? 40 : 48,
    padding: size === 'sm' ? '0 16px' : '0 18px',
    cursor: 'pointer', border: 'none', borderRadius: 8,
    display: 'inline-flex', alignItems: 'center', justifyContent: 'center', gap: 8,
    width: full ? '100%' : 'auto',
    whiteSpace: 'nowrap',
    ...style,
  };
  // B-option: phone/primary = orange fill + white text, email = white + orange border + orange text.
  let finalStyle = { ...base, background: '#fff', color: T_M.ink, border: `1.5px solid ${T_M.ink}` };
  if (kind === 'phone')   finalStyle = { ...base, background: T_M.oMain, color: '#fff' };
  if (kind === 'email')   finalStyle = { ...base, background: '#fff',    color: T_M.oDeep, border: `1.5px solid ${T_M.oLine}` };
  if (kind === 'primary') finalStyle = { ...base, background: T_M.oMain, color: '#fff' };
  if (kind === 'dark')    finalStyle = { ...base, background: T_M.ink,   color: '#fff' };
  if (href) return <a href={href} style={{ ...finalStyle, textDecoration: 'none' }}>{icon}{children}</a>;
  return <button type="button" style={finalStyle}>{icon}{children}</button>;
}

// ---------- Header ----------
const M_ORANGE = T_M.orange;
function MHeader({ active = 'home', onOpenMenu, menuButtonRef, menuOpen = false }) {
  return (
    <header style={{ position: 'sticky', top: 0, zIndex: 30, background: '#fff', borderBottom: `1px solid ${T_M.line}` }}>
      <div style={{
        display: 'flex', alignItems: 'center', justifyContent: 'space-between',
        padding: '7px 14px',
      }}>
        <a href={mobileHref('top')} aria-label={CO_M.name} style={{ display: 'inline-flex', alignItems: 'center', gap: 8, textDecoration: 'none' }}>
          <Lockup_M height={48} maxWidth={240} fallback={
            <React.Fragment>
              <Brand_M size={36} tone="orange" />
              <span style={{ display: 'grid', gap: 1, lineHeight: 1 }}>
                <span style={{ color: M_ORANGE, fontSize: 21, fontWeight: 800, letterSpacing: 0.2, fontFamily: '"Noto Sans JP", sans-serif' }}>Smartlife</span>
                <span style={{ color: T_M.ink70, fontSize: 10, fontWeight: 700, letterSpacing: 0.2 }}>{CO_M.name}</span>
              </span>
            </React.Fragment>
          } />
        </a>
        <div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
          <a href={mobilePhoneHref} aria-label="電話する" style={{
            width: 40, height: 40, borderRadius: 10, background: M_ORANGE,
            display: 'inline-flex', alignItems: 'center', justifyContent: 'center',
            textDecoration: 'none', boxShadow: '0 8px 18px -10px rgba(232,93,24,0.7)',
          }}>
            <Ic_M.phone width="20" height="20" color="#fff" />
          </a>
          <button
            ref={menuButtonRef}
            onClick={onOpenMenu}
            aria-label="メニュー"
            aria-controls="mobile-menu-drawer"
            aria-expanded={menuOpen}
            style={{
              width: 40, height: 40, borderRadius: 10, background: '#fff', border: `1px solid ${T_M.line}`,
              display: 'inline-flex', alignItems: 'center', justifyContent: 'center', cursor: 'pointer', padding: 0,
            }}
          >
            <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke={T_M.ink} strokeWidth="2" strokeLinecap="round">
              <path d="M3 7h18M3 12h18M3 17h18" />
            </svg>
          </button>
        </div>
      </div>
    </header>
  );
}

// ---------- Menu drawer (collapsed by default; shows when state on) ----------
function MMenu({ open, onClose, active }) {
  const closeButtonRef = React.useRef(null);
  React.useEffect(() => {
    if (!open) return undefined;
    const previousOverflow = document.body.style.overflow;
    document.body.style.overflow = 'hidden';
    window.setTimeout(() => {
      if (closeButtonRef.current) closeButtonRef.current.focus();
    }, 0);
    const onKeyDown = (event) => {
      if (event.key === 'Escape') onClose();
    };
    document.addEventListener('keydown', onKeyDown);
    return () => {
      document.body.style.overflow = previousOverflow;
      document.removeEventListener('keydown', onKeyDown);
    };
  }, [open, onClose]);
  if (!open) return null;
  const nav = [
    { id: 'home',      label: 'ホーム' },
    { id: 'services',  label: 'サービス' },
    { id: 'cases',     label: '施工事例' },
    { id: 'flow',      label: '相談の流れ' },
    { id: 'knowledge', label: 'お役立ち情報' },
    { id: 'company',   label: '会社案内' },
    { id: 'contact',   label: 'お問い合わせ' },
  ];
  return (
    <div id="mobile-menu-drawer" role="dialog" aria-modal="true" aria-label="サイトメニュー" style={{ position: 'fixed', inset: 0, zIndex: 50, background: 'rgba(0,0,0,0.4)' }}>
      <div style={{ position: 'absolute', top: 0, right: 0, width: '88%', maxHeight: '100%', overflowY: 'auto', background: '#fff', padding: '14px 0 0', display: 'flex', flexDirection: 'column' }}>
        <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', padding: '4px 18px 14px', borderBottom: `1px solid ${T_M.line}` }}>
          <Lockup_M height={44} maxWidth={220} fallback={<Brand_M size={36} tone="orange" />} />
          <button ref={closeButtonRef} onClick={onClose} aria-label="メニューを閉じる" style={{ width: 36, height: 36, background: 'transparent', border: 'none', cursor: 'pointer' }}>
            <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke={T_M.ink} strokeWidth="2" strokeLinecap="round"><path d="M6 6l12 12M18 6L6 18" /></svg>
          </button>
        </div>
        <nav>
          {nav.map((n) => (
            <a key={n.id} href={mobileNavHref(n.id)} style={{
              display: 'flex', alignItems: 'center',
              padding: '16px 22px',
              fontFamily: '"Noto Sans JP", sans-serif', fontSize: 16, fontWeight: 600,
              color: active === n.id ? T_M.oDeep : T_M.ink,
              borderBottom: `1px solid ${T_M.line}`,
              textDecoration: 'none',
            }}>
              <span>{n.label}</span>
            </a>
          ))}
        </nav>
        <div style={{ padding: '18px 22px', background: T_M.paper, borderTop: `1px solid ${T_M.line}` }}>
          <div style={{ fontSize: 11, color: T_M.oDeep, fontWeight: 700, letterSpacing: 1.5, marginBottom: 6 }}>お電話でのご相談</div>
          <a href={mobilePhoneHref} style={{ fontSize: 22, fontWeight: 800, color: T_M.ink, display: 'flex', alignItems: 'center', gap: 8, textDecoration: 'none' }}>
            <Ic_M.phone width="20" height="20" color={T_M.oMain} /> {CO_M.phone}
          </a>
          {mobileHours && <div style={{ fontSize: 11, color: T_M.ink70, marginTop: 4 }}>受付 {mobileHours}</div>}
        </div>
      </div>
    </div>
  );
}

// ---------- Sticky bottom CTA bar ----------
// 2 equal-weight primary actions (電話 / メール) — uniform shape.
function MBottomBar() {
  const btn = (kind, label, icon, href) => {
    const filled = kind === 'phone';
    const style = filled
      ? { background: M_ORANGE, color: '#fff', border: `1.5px solid ${M_ORANGE}` }
      : { background: '#fff', color: M_ORANGE, border: `1.5px solid ${M_ORANGE}` };
    return (
      <a href={href} style={{
        ...style, borderRadius: 8, height: 48,
        display: 'inline-flex', alignItems: 'center', justifyContent: 'center', gap: 'clamp(4px, 1.6vw, 7px)',
        fontFamily: 'inherit', fontWeight: 800, fontSize: 'clamp(11.5px, 3.4vw, 13.5px)', letterSpacing: 0.1,
        lineHeight: 1, whiteSpace: 'nowrap', padding: '0 3px',
        textDecoration: 'none',
      }}>{icon}{label}</a>
    );
  };
  return (
    <div data-mobile-bottom-bar style={{
      position: 'sticky', bottom: 0, zIndex: 25, background: '#fff',
      borderTop: `1px solid ${T_M.line}`, padding: '9px 12px 12px',
      display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 10,
      boxShadow: '0 -8px 20px -10px rgba(0,0,0,0.12)',
    }}>
      {btn('phone', 'お電話で相談',     <Ic_M.phone width="16" height="16" />, mobilePhoneHref)}
      {btn('email', 'メールでお問い合わせ', <Ic_M.chat  width="16" height="16" color={M_ORANGE} />, mobileHref('contact'))}
    </div>
  );
}

// ---------- Area pill (白ピル・緑1.5px罫・緑のピンアイコン。2026-07-27に信頼色の緑へ統一) ----------
function MAreaPill({ label = CO_M.area, style }) {
  // CMSでエリアが空にされたら、ピンだけの空チップを出さない
  if (!String(label || '').trim()) return null;
  // CMSのエリア表記が長いと（例: 広島市周辺/近郊地域もご対応可能）パンくずを押しつぶすため、
  // 「/」の塊ごとに改行できるようにする。短い表記は従来どおり1行。
  const lines = String(label || '').split('/')
    .map((segment) => segment.trim()).filter(Boolean)
    .map((segment, index, all) => (index < all.length - 1 ? `${segment} /` : segment));
  // 塊が短いときだけ、折返し後の実幅に箱を合わせる（長い塊は普通に流し込んで、はみ出しを防ぐ）
  const fitsLines = lines.length > 1 && lines.every((line) => line.length <= 12);
  return (
    <span style={{
      display: 'inline-flex', alignItems: 'center', gap: 4,
      background: '#fff', color: T_M.green, fontWeight: 800, fontSize: 11,
      padding: '5px 8px', border: `1.5px solid ${T_M.green}`, borderRadius: 999,
      whiteSpace: 'normal', wordBreak: 'keep-all', overflowWrap: 'anywhere',
      lineHeight: 1.35, textAlign: 'left', minWidth: 0, maxWidth: '60%', ...style,
    }}>
      <Ic_M.pin width="12" height="12" color={T_M.green} style={{ flexShrink: 0 }} />
      <span style={{ minWidth: 0, maxWidth: '100%', ...(fitsLines ? { display: 'block', width: 'min-content' } : null) }}>
        {lines.length > 1
          ? lines.map((line, index) => (
            <React.Fragment key={`${line}-${index}`}>
              <span style={{ whiteSpace: line.length <= 12 ? 'nowrap' : 'normal' }}>{line}</span>
              {index < lines.length - 1 ? ' ' : null}
            </React.Fragment>
          ))
          : label}
      </span>
    </span>
  );
}

// ---------- Section heading (mobile, B-option pattern 13) ----------
// Default: white + ink serif 22px/700 + 1px bottom rule.
// band: case-proof-card 型（1px罫・radius 9・greenSoftの見出し帯。オレンジは押す場所だけに残す）。
// (num/en props kept for call-site compatibility; English eyebrows are no longer rendered per design.md.)
function MSectionHeading({ num, en, title, lead, band = false, children }) {
  if (band) {
    return (
      <div style={{ border: `1px solid ${T_M.line}`, borderRadius: 9, overflow: 'hidden', background: '#fff', marginBottom: 20 }}>
        {/* 見出し帯は情報表示なので中立色（オレンジは押す場所だけに残す） */}
        <div style={{ background: T_M.greenSoft, color: T_M.greenInk, textAlign: 'center', fontSize: 15, fontWeight: 800, padding: '9px 12px', letterSpacing: 0.3, borderBottom: `1px solid ${T_M.line}` }}>
          {title}
        </div>
        {(lead || children) && (
          <div style={{ padding: 10 }}>
            {lead && <p style={{ fontFamily: '"Noto Sans JP", sans-serif', fontSize: 13.5, color: T_M.ink70, lineHeight: 2, margin: 0, wordBreak: 'auto-phrase', overflowWrap: 'break-word' }}><BT_M>{lead}</BT_M></p>}
            {children}
          </div>
        )}
      </div>
    );
  }
  return (
    <div style={{ marginBottom: 20, paddingBottom: 14, borderBottom: `1px solid ${T_M.line}` }}>
      <h2 style={{ fontFamily: '"Noto Sans JP", sans-serif', fontSize: 20, fontWeight: 900, color: T_M.ink, margin: 0, lineHeight: 1.5, letterSpacing: -0.3, fontFeatureSettings: "'palt'", wordBreak: 'auto-phrase', overflowWrap: 'break-word' }}>{title}</h2>
      {lead && <p style={{ fontFamily: '"Noto Sans JP", sans-serif', fontSize: 13.5, color: T_M.ink70, lineHeight: 2, margin: '12px 0 0', wordBreak: 'auto-phrase', overflowWrap: 'break-word' }}><BT_M>{lead}</BT_M></p>}
    </div>
  );
}

// ---------- Sub-page hero (B-option pattern 12) ----------
// White surface, breadcrumb (11.5px) → serif title (30px/700 ink) → lead, 1px bottom rule.
// areaPill: re-states the area declaration pill (same component as TOP hero).
// (num/en props kept for call-site compatibility; English eyebrows are no longer rendered per design.md.)
// divider: 直後のセクションが両側細罫つき見出しで始まるページでは false を渡す
// （ヒーロー下線と見出し細罫の水平線が二重に見えるため）。既定 true で既存ページに影響なし。
function MPageHero({ num, en, title, lead, areaPill = true, breadcrumb, divider = true }) {
  return (
    <section style={{ background: '#fff', padding: '16px 16px 22px', borderBottom: divider ? `1px solid ${T_M.line}` : 'none' }}>
      {/* パンくず＋エリアチップで1段、その下に見出しの2段構成。 */}
      <div style={{ display: 'flex', alignItems: 'center', gap: 10, marginBottom: 12 }}>
        <div style={{
          fontSize: 11.5, color: T_M.ink70, fontFamily: '"Noto Sans JP", sans-serif',
          minWidth: 0, flexShrink: 1, whiteSpace: 'normal', overflow: 'hidden',
          wordBreak: 'auto-phrase', overflowWrap: 'break-word', lineHeight: 1.5,
          display: '-webkit-box', WebkitLineClamp: 2, WebkitBoxOrient: 'vertical',
        }}>
          {breadcrumb || <>ホーム ／ <span style={{ color: T_M.ink }}>{title}</span></>}
        </div>
        {areaPill && <MAreaPill style={{ marginLeft: 'auto', flexShrink: 0 }} />}
      </div>
      <h1 style={{ fontFamily: '"Noto Sans JP", sans-serif', fontSize: 26, fontWeight: 900, color: T_M.ink, margin: 0, lineHeight: 1.4, letterSpacing: -0.5, fontFeatureSettings: "'palt'", wordBreak: 'auto-phrase', overflowWrap: 'break-word' }}>
        {title}
      </h1>
      {lead && <p data-text-contract="subpage-hero-lead" style={{ fontFamily: '"Noto Sans JP", sans-serif', fontSize: 14, color: T_M.ink70, lineHeight: 2, marginTop: 14, marginBottom: 0, wordBreak: 'auto-phrase', overflowWrap: 'break-word' }}><BT_M>{lead}</BT_M></p>}
    </section>
  );
}

// ---------- Large phone CTA card (B-option pattern 10) ----------
function MPhoneCTACard({ style }) {
  return (
    <div style={{ border: `1.5px solid ${T_M.oLine}`, borderRadius: 12, background: '#fff', padding: '14px 16px 16px', textAlign: 'center', maxWidth: 560, margin: '0 auto', display: 'grid', justifyItems: 'center', rowGap: 7, ...style }}>
      <div style={{ color: T_M.oDeep, fontWeight: 900, fontSize: 14, letterSpacing: 1 }}>お電話で相談</div>
      <a href={mobilePhoneHref} style={{ display: 'inline-flex', alignItems: 'center', justifyContent: 'center', gap: 10, color: T_M.oMain, textDecoration: 'none', fontFamily: '"M PLUS 1p", "Helvetica Neue", Arial, sans-serif', fontSize: 'clamp(28px, 5vw, 33px)', fontWeight: 800, lineHeight: 1.1, letterSpacing: -0.5, maxWidth: '100%', whiteSpace: 'nowrap' }}>
        <span style={{ width: 44, height: 44, borderRadius: '50%', background: T_M.oMain, color: '#fff', display: 'inline-flex', alignItems: 'center', justifyContent: 'center', flexShrink: 0 }}>
          <Ic_M.phone width="23" height="23" color="#fff" />
        </span>
        <span>{CO_M.phone}</span>
      </a>
      {/* 受付時間は補足情報なので塗りピルにせず、細罫下の静かな1行に（長いCMS表記でも上品に収まる） */}
      {mobileHours && <div style={{ width: '100%', marginTop: 3, paddingTop: 9, borderTop: `1px solid ${T_M.line}`, fontSize: 11.5, fontWeight: 600, color: T_M.ink70, letterSpacing: -0.2, lineHeight: 1.55 }}>
        <span style={{ color: T_M.ink70, marginRight: 6 }}>受付</span>{mobileHours}
      </div>}
    </div>
  );
}

// ---------- Mobile breadcrumb (inline) ----------
function MBreadcrumb({ items = [] }) {
  const hrefFor = (label) => ({
    'ホーム': mobileHref('top'),
    'サービス': mobileHref('services'),
    'サービス一覧': mobileHref('services'),
    '施工事例': mobileHref('cases'),
    'お役立ち情報': mobileHref('knowledge'),
    '住まいのお役立ちコラム': mobileHref('knowledge'),
    '会社案内': mobileHref('company'),
    'お問い合わせ': mobileHref('contact'),
  }[label]);
  return (
    <div style={{ display: 'flex', alignItems: 'center', gap: 8, fontSize: 11.5, color: T_M.ink70, fontFamily: '"Noto Sans JP", sans-serif', flexWrap: 'wrap' }}>
      {items.map((item, i) => {
        const label = typeof item === 'string' ? item : item.label;
        const href = i === items.length - 1 ? null : (typeof item === 'string' ? hrefFor(item) : item.href);
        const style = { color: i === items.length - 1 ? T_M.ink : T_M.ink70, textDecoration: 'none' };
        return (
        <React.Fragment key={i}>
          {href ? <a href={href} style={style}>{label}</a> : <span style={style}>{label}</span>}
          {i < items.length - 1 && <span style={{ color: T_M.ink70 }}>／</span>}
        </React.Fragment>
      )})}
    </div>
  );
}

// ---------- CTA band (mobile) ----------
function MCTABand() {
  return (
    <section style={{ background: T_M.greenDeep, color: '#fff', padding: '36px 18px 40px' }}>
      <h2 style={{ fontFamily: '"Noto Sans JP", sans-serif', fontSize: 26, fontWeight: 700, margin: '0 0 14px', lineHeight: 1.5 }}>
        {copyText_M('cta.title', 'お問い合わせ')}
      </h2>
      <p style={{ fontSize: 13.5, lineHeight: 2, opacity: 0.85, margin: '0 0 22px' }}>
        <BT_M>{copyText_M('cta.lead1', '屋根や外壁、住まいのことで気になることはありませんか？')}</BT_M><br />
        <BT_M>{copyText_M('cta.lead2', '小さなことでも、お電話またはメールフォームよりお気軽にご相談ください。')}</BT_M>
      </p>
      <div style={{ background: '#fff', color: T_M.ink, padding: 18, borderRadius: 6 }}>
        <div style={{ fontSize: 11, color: T_M.oDeep, fontWeight: 700, letterSpacing: 1.5, marginBottom: 2 }}>お電話でのご相談</div>
        {/* 長い受付表記でも崩れないよう、受付時間はラベルに連結せず控えめな別行にする */}
        {mobileHours && <div style={{ fontSize: 11, fontWeight: 600, color: T_M.ink70, letterSpacing: -0.2, marginBottom: 4 }}>受付 {mobileHours}</div>}
        <a href={mobilePhoneHref} style={{ fontSize: 26, fontWeight: 800, color: T_M.ink, display: 'flex', alignItems: 'center', gap: 8, marginBottom: 14, letterSpacing: 0.3, textDecoration: 'none' }}>
          <Ic_M.phone width="20" height="20" color={T_M.oMain} /> {CO_M.phone}
        </a>
        <MBtn kind="email" href={mobileHref('contact')} full icon={<Ic_M.chat width="16" height="16" />}>メールでお問い合わせ</MBtn>
      </div>
    </section>
  );
}

// ---------- Footer (mobile, compact accordion) ----------
function MFooter() {
  const groups = [
    { h: 'サービス', items: ['雨漏り診断', '部分・応急補修', '定期メンテナンス', '全体改修', '外壁・内装・水回り'] },
    { h: 'コンテンツ', items: ['施工事例', 'お役立ち情報', '相談の流れ', '会社案内'] },
    { h: 'お問い合わせ', items: [CO_M.phone, mobileHours ? '受付 ' + mobileHours : null, 'メールフォーム'].filter(Boolean) },
  ];
  return (
    <footer style={{ background: '#fff', padding: '32px 18px 24px', borderTop: `1px solid ${T_M.line}` }}>
      <div style={{ fontSize: 12.5, color: T_M.ink70, lineHeight: 1.9, marginBottom: 22 }}>
        {copyText_M('footer.description.1', '広島市・周辺エリアの屋根・外壁・住まいの相談窓口です。')}
      </div>
      {groups.map((g) => (
        <details key={g.h} style={{ borderTop: `1px solid ${T_M.line}` }}>
          <summary style={{
            padding: '14px 0',
            fontFamily: '"Noto Sans JP", sans-serif', fontSize: 13.5, color: T_M.ink, fontWeight: 700,
            cursor: 'pointer', listStyle: 'none', display: 'flex', justifyContent: 'space-between', alignItems: 'center',
          }}>
            {g.h}
            <span style={{ color: T_M.ink70, fontSize: 18, fontFamily: 'ui-monospace, monospace' }}>＋</span>
          </summary>
          <div style={{ paddingBottom: 14 }}>
            {g.items.map((it) => {
              const href = mobileFooterHref(it);
              const itemStyle = { fontSize: 12.5, color: T_M.ink70, padding: '6px 0', textDecoration: 'none', display: 'block' };
              return href
                ? <a key={it} href={href} style={itemStyle}>{it}</a>
                : <div key={it} style={itemStyle}>{it}</div>;
            })}
          </div>
        </details>
      ))}
      <div style={{ marginTop: 14, paddingTop: 12, borderTop: `1px solid ${T_M.line}`, fontSize: 11, color: T_M.ink70, display: 'flex', justifyContent: 'space-between' }}>
        <div>© Smartlife</div>
        <a href={mobilePrivacyHref} style={{ color: T_M.ink70, textDecoration: 'underline', textUnderlineOffset: 3 }}>個人情報の取り扱いについて</a>
      </div>
    </footer>
  );
}

// ---------- Mobile page wrapper ----------
function MPage({ active, children }) {
  const [menuOpen, setMenuOpen] = React.useState(false);
  const menuButtonRef = React.useRef(null);
  const closeMenu = React.useCallback(() => {
    setMenuOpen(false);
    window.setTimeout(() => {
      if (menuButtonRef.current) menuButtonRef.current.focus();
    }, 0);
  }, []);
  return (
    <div style={{
      fontFamily: '"Noto Sans JP", "Hiragino Sans", sans-serif',
      color: T_M.ink, background: '#fff', minHeight: '100%',
      position: 'relative',
    }}>
      <MHeader active={active} onOpenMenu={() => setMenuOpen(true)} menuButtonRef={menuButtonRef} menuOpen={menuOpen} />
      <MMenu open={menuOpen} onClose={closeMenu} active={active} />
      {/* 緑のお問い合わせ帯は2026-06-12に廃止（ページ末の電話CTAカード＋固定バーと重複するため） */}
      <main data-mobile-main style={{ paddingBottom: 28 }}>{children}</main>
      <MFooter />
      <MBottomBar />
    </div>
  );
}

window.MobileSite = {
  T: T_M, MBtn, MHeader, MMenu, MBottomBar, MSectionHeading, MPageHero, MBreadcrumb,
  MAreaPill, MPhoneCTACard,
  MCTABand, MFooter, MPage, Img: Img_M, Ic: Ic_M, Brand: Brand_M, PT: PT_M,
  mobileHref, mobileServiceHref, mobileCaseHref, mobileNavHref, mobilePhoneHref,
};
