// TOP page (revised) — company portal hero, NOT a featured-article hero.
// Pattern 2 visual base, but the entry design is closer to Pattern 1.

const S_TOP = window.Site;
const { T: T_TOP, COMPANY: CO_TOP, FLOW_STEPS: FL_TOP, SERVICES: SV_TOP, CoverImg: Img_TOP, Icon: Ic_TOP, SectionHeading: SH_TOP, CASES: CASES_TOP, ARTICLES: ART_TOP, Page: Page_TOP, siteHref: hrefTop, siteServiceHref: serviceHrefTop, siteCaseHref: caseHrefTop, siteArticleHref: articleHrefTop, sitePhoneHref: phoneHrefTop, BudouXText: BT_TOP, FLOW_NO_BREAK: FLOW_NO_BREAK_TOP, copyText: copyTop, rawCopyValue: rawCopyTop, hasText: hasTextTop, hasImageRef: hasImageRefTop } = S_TOP;

function Top_HeroSlides() {
  const seen = new Set();
  return [S_TOP.ASSETS.heroMain, S_TOP.ASSETS.heroFlip, S_TOP.ASSETS.heroWide2].filter((src) => {
    if (typeof src !== 'string' || src === '' || seen.has(src)) return false;
    seen.add(src);
    return true;
  });
}

function Top_HeroRotator() {
  const slides = Top_HeroSlides();
  const [active, setActive] = React.useState(0);
  const reduceMotion = typeof window !== 'undefined'
    && window.matchMedia
    && window.matchMedia('(prefers-reduced-motion: reduce)').matches;

  React.useEffect(() => {
    setActive(0);
    if (slides.length < 2 || reduceMotion) return undefined;
    const timer = window.setInterval(() => {
      if (document.hidden) return;
      setActive((current) => (current + 1) % slides.length);
    }, 6000);
    return () => window.clearInterval(timer);
  }, [slides.join('\n'), reduceMotion]);

  if (slides.length < 2) {
    return <Img_TOP src={S_TOP.ASSETS.heroMain} sizes="(max-width: 1320px) 41vw, 540px" ratio="4/5" radius={6} priority />;
  }

  if (reduceMotion) {
    return <Img_TOP src={slides[0]} sizes="(max-width: 1320px) 41vw, 540px" ratio="4/5" radius={6} priority />;
  }

  return (
    <div style={{ position: 'relative', borderRadius: 6, overflow: 'hidden' }}>
      <Img_TOP src={slides[0]} sizes="(max-width: 1320px) 41vw, 540px" ratio="4/5" radius={6} priority />
      {slides.slice(1).map((src, index) => (
        <div
          key={src}
          aria-hidden="true"
          style={{
            position: 'absolute',
            inset: 0,
            opacity: active === index + 1 ? 1 : 0,
            transition: 'opacity 1.2s ease',
          }}
        >
          <Img_TOP src={src} sizes="(max-width: 1320px) 41vw, 540px" alt="" ratio="4/5" radius={6} />
        </div>
      ))}
    </div>
  );
}

function Top_Hero() {
  const hero = S_TOP.topHeroLines();
  return (
    <section className="top-hero-section" data-top-hero style={{ background: '#fff', padding: '64px 56px 72px' }}>
      <style>{`
        @media (min-width: 901px) and (max-width: 1320px) {
          .top-hero-section {
            padding: 56px 48px 68px !important;
          }
          .top-hero-grid {
            grid-template-columns: minmax(0, 1fr) clamp(420px, 41vw, 540px) !important;
            gap: 28px !important;
          }
          .top-hero-title {
            font-size: 52px !important;
          }
          .top-phone-card {
            max-width: 440px !important;
            padding: 16px 24px 18px !important;
          }
          .top-phone-card-title {
            font-size: 17px !important;
          }
          .top-phone-number {
            font-size: 38px !important;
            gap: 12px !important;
          }
          .top-phone-icon {
            width: 48px !important;
            height: 48px !important;
          }
          .top-phone-hours {
            font-size: 13.5px !important;
            padding: 6px 22px !important;
          }
        }
        @media (min-width: 901px) and (max-width: 1040px) {
          .top-hero-section {
            padding: 46px 34px 60px !important;
          }
          .top-hero-grid {
            grid-template-columns: minmax(0, 1.02fr) minmax(330px, 0.78fr) !important;
            gap: 24px !important;
            align-items: center !important;
          }
          .top-hero-title {
            font-size: 40px !important;
            line-height: 1.32 !important;
            letter-spacing: 0 !important;
          }
          .top-phone-card {
            max-width: 410px !important;
            padding: 14px 18px 16px !important;
          }
          .top-phone-number {
            font-size: 32px !important;
            gap: 10px !important;
          }
          .top-phone-icon {
            width: 42px !important;
            height: 42px !important;
          }
          .top-phone-hours {
            font-size: 12px !important;
            padding: 6px 18px !important;
          }
        }
        @media (min-width: 1321px) {
          .top-hero-grid {
            grid-template-columns: minmax(0, 520px) clamp(540px, 44vw, 640px) !important;
            gap: 64px !important;
            max-width: 1360px;
            margin: 0 auto;
            justify-content: center;
          }
        }
      `}</style>
      <div className="top-hero-grid" style={{ display: 'grid', gridTemplateColumns: '1.05fr 1fr', gap: 56, alignItems: 'center' }}>
        <div>
          <div style={{ display: 'inline-flex', alignItems: 'center', gap: 8, background: '#fff', color: T_TOP.orangeDeep, border: `1.5px solid ${T_TOP.orangeLine}`, fontWeight: 700, fontSize: 12.5, padding: '7px 14px', borderRadius: 999, marginBottom: 28, letterSpacing: 0.4 }}>
            <span style={{ width: 6, height: 6, borderRadius: '50%', background: T_TOP.orange }} />
            {copyTop('top.badge', '広島の屋根・外壁・住まいの相談窓口')}
          </div>
          <div className="top-hero-title" data-top-h1 style={{
            fontFamily: '"Noto Sans JP", "Hiragino Sans", sans-serif',
            color: T_TOP.ink, fontSize: 56, margin: '0 0 24px',
            fontFeatureSettings: "'palt'",
          }}>
            {hero.line1 && <h1 data-top-hero-line="line1" style={{ margin: 0, fontSize: '1em', fontWeight: 900, lineHeight: 1.3, letterSpacing: '-0.02em', wordBreak: 'auto-phrase', overflowWrap: 'break-word' }}><S_TOP.HeroAccentText>{hero.line1}</S_TOP.HeroAccentText></h1>}
            {hero.line2a && <div data-top-hero-line="line2a" style={{ marginTop: 8, fontSize: '0.5em', fontWeight: 800, lineHeight: 1.5, letterSpacing: '-0.01em', wordBreak: 'auto-phrase', overflowWrap: 'break-word' }}><BT_TOP>{hero.line2a}</BT_TOP></div>}
            <S_TOP.HeroBrandLogo
              height="auto"
              maxWidth={400}
              fallbackText={hero.line2b}
              style={{ marginTop: 18, marginBottom: 0, width: 400, height: 'auto' }}
              fallbackStyle={{ fontSize: '0.46em' }}
            />
            {hero.line2c && <div data-top-hero-line="line2c" style={{ marginTop: 8, color: T_TOP.orange, fontSize: '0.64em', fontWeight: 900, lineHeight: 1.35, letterSpacing: '-0.025em', whiteSpace: 'nowrap', WebkitTextStroke: '5px #fff', paintOrder: 'stroke fill' }}>{hero.line2c}</div>}
          </div>
          {(() => {
            // CMSに空で保存されたリード行は「消した」意図として非表示にする（既定文へ戻さない）
            const resolveLead = (id, fallback) => {
              const raw = rawCopyTop(id);
              return String(raw === undefined ? fallback : raw).trim();
            };
            const lead1 = resolveLead('top.hero.lead1', '住まいの修理は、株式会社スマートライフへ。');
            const lead2 = resolveLead('top.hero.lead2', '広島での屋根・外壁・住まいのメンテナンスを、ひとつの窓口で承ります。');
            if (!lead1 && !lead2) return null;
            return (
              <p data-text-contract="top-hero-leads" style={{ fontFamily: '"Noto Sans JP", sans-serif', fontSize: 17, lineHeight: 2.05, color: T_TOP.ink70, margin: '0 0 36px', maxWidth: 520 }}>
                {lead1 && <span style={{ display: 'block' }}><BT_TOP>{lead1}</BT_TOP></span>}
                {lead2 && <span style={{ display: 'block' }}><BT_TOP>{lead2}</BT_TOP></span>}
              </p>
            );
          })()}

          {/* Phone block — biggest CTA, since基本は電話 */}
          <div className="top-phone-card" style={{ background: '#fff', border: `1.5px solid ${T_TOP.orangeLine}`, borderRadius: 14, padding: '18px 28px 20px', marginBottom: 18, maxWidth: 520, textAlign: 'center' }}>
            <div className="top-phone-card-title" style={{ color: T_TOP.orangeDeep, fontSize: 19, fontWeight: 900, letterSpacing: 1, marginBottom: 6 }}>お電話で相談</div>
            <a href={phoneHrefTop} className="top-phone-number" style={{ display: 'inline-flex', alignItems: 'center', justifyContent: 'center', gap: 14, color: T_TOP.orange, textDecoration: 'none', fontFamily: '"M PLUS 1p", "Helvetica Neue", Arial, sans-serif', fontSize: 44, fontWeight: 800, lineHeight: 1.1, letterSpacing: -0.5, marginBottom: 10 }}>
              <span className="top-phone-icon" style={{ width: 54, height: 54, borderRadius: '50%', background: T_TOP.orange, color: '#fff', display: 'inline-flex', alignItems: 'center', justifyContent: 'center', flexShrink: 0 }}>
                <Ic_TOP.phone width="28" height="28" color="#fff" />
              </span>
              {CO_TOP.phone}
            </a>
            {CO_TOP.hours && <div className="top-phone-hours" style={{ display: 'inline-block', margin: '2px auto 0', background: T_TOP.orange, color: '#fff', borderRadius: 999, padding: '7px 24px', fontSize: 15, fontWeight: 800, lineHeight: 1.2 }}>
              受付 {CO_TOP.hours}
            </div>}
          </div>
        </div>
        <div style={{ position: 'relative' }}>
          <Top_HeroRotator />
        </div>
      </div>
    </section>
  );
}

// 4 short reassurance points — facts only, no claims of 無料 / 即日返信 / 自社施工
function Top_Promise() {
  const points = [
    { t: copyTop('top.promise.1.title', '住まいのことを窓口ひとつで'), d: copyTop('top.promise.1.body', '屋根・外壁・雨漏り・内装・水回りまで、まとめてご相談いただけます。'), ic: Ic_TOP.home },
    { t: copyTop('top.promise.2.title', '広島市・周辺エリア対応'), d: copyTop('top.promise.2.body', '地域密着で活動しているため、現地確認にも迅速に伺います。'), ic: Ic_TOP.pin  },
    { t: copyTop('top.promise.3.title', '写真を交えてご説明'), d: copyTop('top.promise.3.body', '屋根の上など見えにくい場所も、撮影した写真をお見せしながらご説明します。'), ic: Ic_TOP.camera },
  ];
  return (
    <section style={{ background: T_TOP.paper, padding: '56px 56px' }}>
      <div style={{ display: 'grid', gridTemplateColumns: 'repeat(3, 1fr)', gap: 0, borderTop: `1px solid ${T_TOP.line}`, borderBottom: `1px solid ${T_TOP.line}` }}>
        {points.map((p, i) => {
          const I = p.ic;
          return (
            <div key={i} style={{
              padding: '28px 28px 30px',
              borderRight: i < 2 ? `1px solid ${T_TOP.line}` : 'none',
              background: '#fff',
            }}>
              <I width="22" height="22" color={T_TOP.green} />
              <div style={{ fontFamily: '"Noto Sans JP", sans-serif', fontSize: 18, fontWeight: 700, color: T_TOP.ink, marginTop: 18, lineHeight: 1.5 }}>{p.t}</div>
              <div style={{ fontSize: 12.5, color: T_TOP.ink70, marginTop: 8, lineHeight: 1.85 }}><BT_TOP>{p.d}</BT_TOP></div>
            </div>
          );
        })}
      </div>
    </section>
  );
}

function Top_Purposes() {
  const items = S_TOP.topPurposeItems();
  return (
    <section style={{ background: '#fff', padding: '72px 56px 64px' }}>
      <div style={{ maxWidth: 1100, margin: '0 auto' }}>
        <SH_TOP en="CONSULTATION" title="ご相談内容から選べます" lead="工事名が分からなくても、気になっていることから相談先を選べます。" align="left" />
        <div data-top-purpose-grid style={{ display: 'grid', gridTemplateColumns: 'repeat(6, minmax(0, 1fr))', gap: 14 }}>
          {items.map((item, index) => {
            const PurposeIcon = Ic_TOP[item.icon] || Ic_TOP.home;
            const fullWidth = items.length % 3 === 1 && index === items.length - 1;
            const halfWidth = items.length % 3 === 2 && index >= items.length - 2;
            return (
              <a
                key={item.label}
                data-top-purpose
                data-top-purpose-label={item.label}
                data-top-purpose-full-width={fullWidth ? 'true' : 'false'}
                href={item.href}
                style={{
                  gridColumn: fullWidth ? '1 / -1' : halfWidth ? 'span 3' : 'span 2',
                  display: 'grid', gridTemplateColumns: '34px minmax(0, 1fr) 18px',
                  alignItems: 'center', gap: 14, minHeight: 84, padding: '18px 20px',
                  border: `1px solid ${T_TOP.line}`, borderRadius: 8, background: '#fff',
                  color: T_TOP.ink, textDecoration: 'none', fontSize: 15, fontWeight: 800,
                }}
              >
                <PurposeIcon width="30" height="30" color={T_TOP.green} />
                <span style={{ lineHeight: 1.5, wordBreak: 'auto-phrase' }}>{item.label}</span>
                <Ic_TOP.arrow width="17" height="17" color={T_TOP.orangeDeep} />
              </a>
            );
          })}
        </div>
      </div>
    </section>
  );
}

function Top_Services() {
  return (
    <section style={{ background: '#fff', padding: '88px 56px' }}>
      <style>{`
        .top-service-grid {
          grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
        }
        .top-service-card {
          padding: 8px 22px 32px !important;
          border-right: 1px solid ${T_TOP.line} !important;
          border-bottom: 1px solid ${T_TOP.line};
        }
        .top-service-card > div:first-child {
          max-height: 240px !important;
        }
        .top-service-card:nth-child(3n) {
          border-right: none !important;
        }
        .top-service-card:nth-child(n + 4) {
          padding-top: 32px !important;
          border-bottom: none;
        }
        .top-service-card:first-child {
          padding-left: 0 !important;
        }
      `}</style>
      <div style={{ maxWidth: 1280, margin: '0 auto' }}>
      <SH_TOP num="01" en="SERVICE" title="ご相談いただける内容" lead="屋根・外壁の修理から、内装・水回りまで、住まいのことをまとめてご相談いただけます。" anchorRight={
        <a href={hrefTop('services')} style={{ display: 'inline-flex', alignItems: 'center', gap: 6, marginTop: 14, color: T_TOP.ink, fontSize: 13.5, fontWeight: 700, borderBottom: `1.5px solid ${T_TOP.ink}`, paddingBottom: 3, textDecoration: 'none' }}>
          サービス一覧を見る <Ic_TOP.arrow width="14" height="14" />
        </a>
      } />
      <div className="top-service-grid" style={{ display: 'grid', gridTemplateColumns: 'repeat(6, 1fr)', gap: 0, borderBottom: `1px solid ${T_TOP.line}` }}>
        {SV_TOP.map((s, i) => {
          const iconKey = S_TOP.serviceIconKey(s);
          const ServiceIcon = Ic_TOP[iconKey] || Ic_TOP.home;
          return (
          <a key={s.id} href={serviceHrefTop(s.id)} className="top-service-card" style={{
            padding: i === 0 ? '4px 18px 28px 0' : '4px 18px 28px 18px',
            borderRight: i < 5 ? `1px solid ${T_TOP.line}` : 'none',
            textDecoration: 'none',
            minWidth: 0,
          }}>
            {hasImageRefTop(s.photo) && <Img_TOP src={s.photo} ratio="1/1" radius={4} style={{ maxHeight: 208 }} dataEmptyContract="service-card-photo" dataServiceId={s.id} />}
            <div style={{ display: 'flex', alignItems: 'center', gap: 8, fontFamily: '"Noto Sans JP", sans-serif', fontSize: 18, fontWeight: 700, color: T_TOP.ink, marginTop: 16, lineHeight: 1.5 }}><span data-service-icon={iconKey}><ServiceIcon width="22" height="22" color={T_TOP.green} /></span>{s.name}</div>
            {hasTextTop(s.blurb) && <div data-empty-contract="service-card-blurb" data-service-id={s.id} style={{ fontSize: 12.5, lineHeight: 1.85, color: T_TOP.ink70, marginTop: 8, wordBreak: 'auto-phrase', overflowWrap: 'break-word' }}><BT_TOP>{s.blurb}</BT_TOP></div>}
          </a>
          );
        })}
      </div>
      </div>
    </section>
  );
}

function Top_BeforeAfter() {
  const ba = CASES_TOP.slice(0, 3);
  return (
    <section style={{ background: T_TOP.paper, padding: '88px 56px' }}>
      <div data-pc-readable="top-cases" style={{ maxWidth: 1280, margin: '0 auto' }}>
      <SH_TOP num="02" en="WORKS — BEFORE / AFTER" title="施工事例（ビフォー・アフター）" lead="屋根は普段見えにくい場所だからこそ、工事の前後の写真を撮影し、お客様と一緒に状況を確認できるようにしています。" anchorRight={
        <a href={hrefTop('cases')} style={{ display: 'inline-flex', alignItems: 'center', gap: 6, marginTop: 14, color: T_TOP.ink, fontSize: 13.5, fontWeight: 700, borderBottom: `1.5px solid ${T_TOP.ink}`, paddingBottom: 3, textDecoration: 'none' }}>
          施工事例をすべて見る <Ic_TOP.arrow width="14" height="14" />
        </a>
      } />
      <div style={{ display: 'grid', gridTemplateColumns: '1fr', gap: 20 }}>
        {ba.map((c, i) => (
          <div key={c.id} style={{ display: 'grid', gridTemplateColumns: '76px 1fr 1fr 1fr', gap: 28, alignItems: 'start', background: '#fff', padding: 24, borderRadius: 6 }}>
            <div style={{ fontFamily: '"Noto Sans JP", sans-serif', fontSize: 40, color: T_TOP.green, fontWeight: 700, lineHeight: 1 }}>
              0{i + 1}
            </div>
            <div style={{ paddingTop: 4 }}>
              <div style={{ display: 'inline-flex', alignItems: 'center', gap: 6, fontSize: 12, color: T_TOP.green, fontWeight: 700, marginBottom: 10 }}>
                <Ic_TOP.pin width="13" height="13" /> {c.area}
              </div>
              <div style={{ fontFamily: '"Noto Sans JP", sans-serif', fontSize: 21, fontWeight: 700, color: T_TOP.ink, lineHeight: 1.5, marginBottom: 14 }}>{c.work}</div>
              <div style={{ fontSize: 12.5, color: T_TOP.ink70, lineHeight: 1.85, marginBottom: 14 }}><BT_TOP>{c.summary}</BT_TOP></div>
              <a href={caseHrefTop(c.id)} style={{ fontSize: 13, color: T_TOP.ink, fontWeight: 700, borderBottom: `1.5px solid ${T_TOP.ink}`, paddingBottom: 3, display: 'inline-flex', alignItems: 'center', gap: 6, textDecoration: 'none' }}>
                事例の詳細を見る <Ic_TOP.arrow width="13" height="13" />
              </a>
            </div>
            <div>
              <div style={{ fontFamily: 'ui-monospace, monospace', fontSize: 11, color: T_TOP.ink50, letterSpacing: 3, marginBottom: 8 }}>BEFORE</div>
              <Img_TOP src={c.before} ratio="4/3" radius={4} style={{ filter: 'saturate(0.65) brightness(0.95)' }} />
            </div>
            <div>
              <div style={{ fontFamily: 'ui-monospace, monospace', fontSize: 11, color: T_TOP.green, letterSpacing: 3, marginBottom: 8 }}>AFTER</div>
              <Img_TOP src={c.photo || c.after} ratio="4/3" radius={4} />
            </div>
          </div>
        ))}
      </div>
      </div>
    </section>
  );
}

function Top_Flow() {
  return (
    <section id="flow" style={{ background: '#fff', padding: '88px 56px' }}>
      <SH_TOP num="03" en="FLOW" title="ご相談から完工までの流れ" lead="まずはお客さまのご要望や現状を丁寧にお伺いします。" />
      <div style={{ display: 'grid', gridTemplateColumns: `repeat(${Math.max(FL_TOP.length, 1)}, 1fr)`, gap: 0 }}>
        {FL_TOP.map((s, i) => (
          <div key={s.n} style={{ paddingRight: 24, borderRight: i < FL_TOP.length - 1 ? `1px solid ${T_TOP.line}` : 'none', paddingLeft: i > 0 ? 24 : 0 }}>
            <div style={{ fontFamily: '"Noto Sans JP", sans-serif', fontSize: 44, color: T_TOP.green, fontWeight: 700, lineHeight: 1, marginBottom: 10 }}>{s.n}</div>
            <div style={{ height: 1, background: T_TOP.line, margin: '12px 0 16px' }} />
            <div style={{ fontFamily: '"Noto Sans JP", sans-serif', fontSize: 20, fontWeight: 700, color: T_TOP.ink, marginBottom: 12 }}>
              {s.title}
            </div>
            <div data-flow-body={s.n} style={{ fontSize: 13, color: T_TOP.ink70, lineHeight: 2, wordBreak: 'auto-phrase', overflowWrap: 'break-word' }}>
              <BT_TOP noBreakPhrases={FLOW_NO_BREAK_TOP}>{s.body}</BT_TOP>
            </div>
          </div>
        ))}
      </div>
    </section>
  );
}

function Top_Knowledge() {
  const top3 = S_TOP.knowledgeCardsFromArticles(ART_TOP, S_TOP.KNOWLEDGE).slice(0, 3);
  return (
    <section style={{ background: T_TOP.paper, padding: '88px 56px' }}>
      <SH_TOP num="04" en="KNOWLEDGE" title="住まいのお役立ちコラム" lead="ご相談の前に知っておきたい、屋根・外壁の基礎知識。" anchorRight={
        <a href={hrefTop('knowledge')} style={{ display: 'inline-flex', alignItems: 'center', gap: 6, marginTop: 14, color: T_TOP.ink, fontSize: 13.5, fontWeight: 700, borderBottom: `1.5px solid ${T_TOP.ink}`, paddingBottom: 3, textDecoration: 'none' }}>
          すべての記事を見る <Ic_TOP.arrow width="14" height="14" />
        </a>
      } />
      <div style={{ display: 'grid', gridTemplateColumns: 'repeat(3, 1fr)', gap: 24 }}>
        {top3.map((k) => (
          <a key={k.id} data-top-knowledge-card data-article-id={k.id} href={articleHrefTop(k.id)} style={{ background: '#fff', borderRadius: 6, overflow: 'hidden', display: 'block', textDecoration: 'none' }}>
            <Img_TOP src={k.photo} ratio="4/3" />
            <div style={{ padding: '20px 22px 24px' }}>
              <div style={{ fontFamily: 'ui-monospace, monospace', fontSize: 11, color: T_TOP.green, letterSpacing: 2, fontWeight: 700 }}>{k.tag.toUpperCase()}</div>
              <div style={{ fontFamily: '"Noto Sans JP", sans-serif', fontSize: 19, fontWeight: 700, color: T_TOP.ink, margin: '8px 0 8px', lineHeight: 1.5 }}>{k.title}</div>
              <div style={{ fontSize: 13, color: T_TOP.ink70, lineHeight: 1.95 }}><BT_TOP>{k.lead}</BT_TOP></div>
            </div>
          </a>
        ))}
      </div>
    </section>
  );
}

// 許可・資格（PC）— モバイルと同じ認可プレート。緑×黒のみ、装飾は最小限
function Top_License() {
  const { heading, name, number, certifications } = S_TOP.licenseContent();
  if (!name || !number) return null;
  const hasCertifications = certifications.length > 0;
  return (
    <section style={{ background: T_TOP.paper, padding: '64px 56px', borderTop: `1px solid ${T_TOP.line}` }}>
      {heading && (
        <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 10, marginBottom: 26, color: T_TOP.greenInk, fontFamily: '"Noto Sans JP", sans-serif', fontSize: 20, fontWeight: 800 }}>
          {heading}
        </div>
      )}
      <div data-top-license-grid style={{
        display: 'flex', flexWrap: 'wrap',
        gap: 18, maxWidth: 880, margin: '0 auto', justifyContent: 'center',
      }}>
        <div style={{ flex: hasCertifications ? '0 1 calc((100% - 18px) / 2)' : '0 1 720px', minWidth: 0 }}>
          <S_TOP.LicensePlate name={name} number={number} />
        </div>
        {certifications.map((certification, index) => (
          <div key={`${certification.label}-${certification.name}-${index}`} style={{ flex: '0 1 calc((100% - 18px) / 2)', minWidth: 0 }}>
            <S_TOP.LicensePlate {...certification} />
          </div>
        ))}
      </div>
    </section>
  );
}

// 大切な想い — トップの締め。写真はCMS assets.philosophyPhotoで設定。
// 空のときはグリーン背景（2026-08-08 クライアント依頼で写真なし状態を正式対応）
function Top_Philosophy() {
  const title = S_TOP.copyText('services.philosophy.title', 'スマートライフの大切な想い');
  const body = String(S_TOP.copyText('services.philosophy.body', '私たちは工事をする会社ではなく、お客様の暮らしに寄り添うパートナーでありたいと考えています。\n一つひとつのご縁を大切にし、「相談して良かった」「任せて良かった」そう思っていただける仕事を積み重ね、地域に必要とされる会社を目指します。'));
  const photo = S_TOP.ASSETS.philosophyPhoto;
  if (!String(title).trim() && !body.trim()) return null;
  return (
    <section data-philosophy-section style={{
      position: 'relative', overflow: 'hidden',
      background: photo ? T_TOP.ink : 'linear-gradient(120deg, #0a2f22 0%, #0f4d36 60%, #1f6f4f 100%)',
      borderTop: `1px solid ${T_TOP.line}`,
    }}>
      {photo && <img src={photo} alt="" aria-hidden="true" loading="lazy" decoding="async" style={{
        position: 'absolute', inset: 0, width: '100%', height: '100%',
        objectFit: 'cover', objectPosition: '62% 40%', display: 'block',
      }} />}
      {/* PCは横に広いので、左側だけを確実に暗くして本文の可読性を作る（写真は右側で見せる） */}
      {photo && <div aria-hidden="true" style={{
        position: 'absolute', inset: 0,
        background: 'linear-gradient(96deg, rgba(15,22,20,0.88) 0%, rgba(15,22,20,0.74) 34%, rgba(15,22,20,0.28) 58%, rgba(15,22,20,0.06) 78%, rgba(15,22,20,0) 100%)',
      }} />}
      <div style={{ position: 'relative', zIndex: 1, maxWidth: 1180, margin: '0 auto', padding: '92px 56px 96px', minHeight: 420, display: 'flex', alignItems: 'center' }}>
        <div style={{ maxWidth: 620 }}>
          <span style={{ display: 'inline-block', fontFamily: 'ui-monospace, monospace', fontSize: 11.5, letterSpacing: 3, color: 'rgba(255,255,255,0.68)', fontWeight: 700, marginBottom: 14 }}>OUR PHILOSOPHY</span>
          <h2 style={{
            fontFamily: '"Noto Sans JP", sans-serif', fontWeight: 900, fontSize: 32, lineHeight: 1.55,
            color: '#fff', margin: '0 0 18px', letterSpacing: -0.6, fontFeatureSettings: "'palt'",
            textShadow: '0 2px 20px rgba(0,0,0,0.45)',
          }}>{title}</h2>
          <span aria-hidden="true" style={{ display: 'block', width: 48, height: 2, background: 'rgba(255,255,255,0.5)', marginBottom: 24 }} />
          {body.split(/\n+/).filter(Boolean).map((para, pi) => (
            <p key={pi} style={{
              margin: '0 0 14px', color: 'rgba(255,255,255,0.93)', fontSize: 15.5, lineHeight: 2.1,
              fontFeatureSettings: "'palt'", textShadow: '0 1px 14px rgba(0,0,0,0.4)',
            }}>
              {para.split(/(「[^」]*」)/).map((chunk, ci) => (
                chunk.startsWith('「') && chunk.endsWith('」')
                  ? <span key={ci} style={{ fontWeight: 800, color: '#fff', letterSpacing: 0.2 }}>{chunk}</span>
                  : <React.Fragment key={ci}>{chunk}</React.Fragment>
              ))}
            </p>
          ))}
        </div>
      </div>
    </section>
  );
}

function PageTop() {
  return (
    <Page_TOP active="home">
      <Top_Hero />
      <Top_Promise />
      <Top_Purposes />
      <Top_Services />
      <Top_License />
      <Top_BeforeAfter />
      <Top_Flow />
      <Top_Knowledge />
      <Top_Philosophy />
    </Page_TOP>
  );
}

window.PageTop = PageTop;
window.TopPhilosophy = Top_Philosophy;
