// flow-tab.jsx
// 「動線・暮らし」タブ。
// GitHub版のSVG間取り図 + 1日タイムライン と、既存の BEFORE/AFTER 動線改善を併存。

const { useState: useStateFlow } = React;
const { MOTIONS } = window.HOUSE_DATA;

// ─── SVG 間取り図 + 動線 ───
// 実際の1F平面図 (9,555mm × 7,735mm) に準拠。
// 部屋配置：北辺=UB/脱衣/洗面/WC/階段/畳コーナー、中段西=玄関/ホール、
//          南半分=FCL+パントリー(南西)、LDK19帖(中央〜東)、外部西=駐車場
function FloorPlanFlow({ selection }) {
  const drum   = selection.laundry === 'drum';
  const dish   = selection.dish !== 'nodish';
  const robot  = selection.robot !== 'nrobot';
  const ih     = selection.cooking === 'ih';

  const kitchenLabel = ih ? 'IH+食洗機' : 'ガス+食洗機';
  const laundryLabel = selection.laundry === 'drum' ? 'ドラム式洗乾' :
                       selection.laundry === 'kantan' ? 'タテ型+乾太くん' : 'タテ型洗濯機';

  // 部屋色定義
  const wet = {fill:'#0e1a22', stroke:'#1f3550'}; // 水回り
  const sleep = {fill:'#1a1410', stroke:'#3a2a18'}; // 玄関
  const wood = {fill:'#1a160e', stroke:'#3a2e1a'}; // 畳・木質
  const ldk = {fill:'#13161e', stroke:'#2a3045'}; // LDK
  const store = {fill:'#141420', stroke:'#2a2a3a'}; // 収納

  return (
    <div style={{
      background:'var(--surface)',
      border:'1px solid var(--border)',
      borderRadius:'10px',
      padding:'20px'
    }}>
      {/* 凡例 */}
      <div style={{display:'flex', gap:'18px', marginBottom:'14px', fontSize:'11px', flexWrap:'wrap'}}>
        <div style={{display:'flex', alignItems:'center', gap:'6px'}}>
          <div style={{width:'10px', height:'10px', borderRadius:'50%', background:'var(--green)'}}/>
          <span style={{color:'var(--text2)'}}>自動化タスク</span>
        </div>
        <div style={{display:'flex', alignItems:'center', gap:'6px'}}>
          <div style={{width:'10px', height:'10px', borderRadius:'50%', background:'var(--amber)'}}/>
          <span style={{color:'var(--text2)'}}>手動タスク</span>
        </div>
        <div style={{display:'flex', alignItems:'center', gap:'6px'}}>
          <div style={{width:'10px', height:'10px', borderRadius:'50%', background:'var(--blue)'}}/>
          <span style={{color:'var(--text2)'}}>移動経路</span>
        </div>
        <div style={{marginLeft:'auto', fontSize:'10px', color:'var(--text3)', fontFamily:'var(--mono)'}}>
          1F平面図 9,555 × 7,735mm
        </div>
      </div>

      <svg viewBox="0 0 820 620" style={{width:'100%', display:'block', maxHeight:'620px'}}>
        <defs>
          <marker id="arr-g" markerWidth="8" markerHeight="8" refX="6" refY="3" orient="auto">
            <path d="M0,0 L0,6 L8,3 z" fill="#2dd98f"/>
          </marker>
          <marker id="arr-a" markerWidth="8" markerHeight="8" refX="6" refY="3" orient="auto">
            <path d="M0,0 L0,6 L8,3 z" fill="#f0a500"/>
          </marker>
          <marker id="arr-b" markerWidth="8" markerHeight="8" refX="6" refY="3" orient="auto">
            <path d="M0,0 L0,6 L8,3 z" fill="#5b9cf6"/>
          </marker>
          <marker id="arr-p" markerWidth="8" markerHeight="8" refX="6" refY="3" orient="auto">
            <path d="M0,0 L0,6 L8,3 z" fill="#9b7bf4"/>
          </marker>
          <pattern id="tatami" patternUnits="userSpaceOnUse" width="20" height="20" patternTransform="rotate(0)">
            <rect width="20" height="20" fill="#1a160e"/>
            <line x1="0" y1="0" x2="20" y2="0" stroke="#2a2418" strokeWidth="0.5"/>
            <line x1="0" y1="0" x2="0" y2="20" stroke="#2a2418" strokeWidth="0.5"/>
          </pattern>
        </defs>

        {/* 方位コンパス */}
        <g transform="translate(770, 30)">
          <circle r="20" fill="rgba(0,0,0,0.3)" stroke="var(--border2)" strokeWidth="0.5"/>
          <path d="M0,-15 L4,0 L0,4 L-4,0 z" fill="#f05858"/>
          <path d="M0,15 L4,0 L0,-4 L-4,0 z" fill="#545e75"/>
          <text y="-22" fontSize="9" fill="#f05858" textAnchor="middle" fontWeight="700">N</text>
        </g>

        {/* 外部西側 駐車場 */}
        <rect x="10" y="200" width="80" height="280" fill="#0a0c14" stroke="#252b3b" strokeWidth="1" strokeDasharray="3,2"/>
        <text x="50" y="335" fontSize="11" fontWeight="700" fill="#8892aa" textAnchor="middle">🚗</text>
        <text x="50" y="355" fontSize="10" fontWeight="600" fill="#dde2f0" textAnchor="middle">駐車場</text>
        <text x="50" y="370" fontSize="9" fill="#545e75" textAnchor="middle">カーポート</text>

        {/* 建物外枠 */}
        <rect x="100" y="30" width="700" height="566" fill="none" stroke="#3a4258" strokeWidth="1.5"/>

        {/* ═══ 北辺：水回り＋階段＋畳コーナー (y 30-163) ═══ */}
        {/* UB (浴室) — 1820×1820 */}
        <rect x="100" y="30" width="133" height="133" fill={wet.fill} stroke={wet.stroke} strokeWidth="1"/>
        <text x="166" y="90" fontSize="11" fontWeight="700" fill="#dde2f0" textAnchor="middle">🛁 UB</text>
        <text x="166" y="106" fontSize="9" fill="#545e75" textAnchor="middle">浴室</text>

        {/* 脱衣室 — 1365×1820 */}
        <rect x="233" y="30" width="100" height="133" fill={wet.fill} stroke={wet.stroke} strokeWidth="1"/>
        <text x="283" y="78" fontSize="10" fontWeight="700" fill="#dde2f0" textAnchor="middle">脱衣室</text>
        <text x="283" y="92" fontSize="8" fill="#545e75" textAnchor="middle">{laundryLabel}</text>

        {/* 洗面 — 1365×1820 */}
        <rect x="333" y="30" width="100" height="133" fill={wet.fill} stroke={wet.stroke} strokeWidth="1"/>
        <text x="383" y="90" fontSize="10" fontWeight="700" fill="#dde2f0" textAnchor="middle">洗面</text>

        {/* トイレ — 910×1820 */}
        <rect x="433" y="30" width="67" height="133" fill={wet.fill} stroke={wet.stroke} strokeWidth="1"/>
        <text x="466" y="90" fontSize="9" fontWeight="700" fill="#dde2f0" textAnchor="middle">🚽</text>
        <text x="466" y="105" fontSize="8" fill="#545e75" textAnchor="middle">WC</text>

        {/* 階段 — 1820×2730 */}
        <rect x="500" y="30" width="133" height="200" fill={store.fill} stroke={store.stroke} strokeWidth="1"/>
        <text x="566" y="115" fontSize="11" fontWeight="700" fill="#dde2f0" textAnchor="middle">階段</text>
        <text x="566" y="131" fontSize="9" fill="#545e75" textAnchor="middle">UP ↑ 2F</text>

        {/* 畳コーナー 3.1帖 — 2275×2730 */}
        <rect x="633" y="30" width="167" height="200" fill="url(#tatami)" stroke={wood.stroke} strokeWidth="1"/>
        <text x="716" y="120" fontSize="11" fontWeight="700" fill="#dde2f0" textAnchor="middle">畳コーナー</text>
        <text x="716" y="136" fontSize="9" fill="#c9a468" textAnchor="middle">3.1帖</text>

        {/* ═══ 中段西：玄関＋ホール (y 163-297) ═══ */}
        {/* 玄関 — 1820×1820 */}
        <rect x="100" y="163" width="133" height="133" fill={sleep.fill} stroke={sleep.stroke} strokeWidth="1"/>
        <text x="166" y="223" fontSize="11" fontWeight="700" fill="#dde2f0" textAnchor="middle">🚪 玄関</text>
        <text x="166" y="239" fontSize="9" fill="#545e75" textAnchor="middle">エントランス</text>

        {/* ホール — 1365×910 */}
        <rect x="233" y="163" width="100" height="67" fill="#161821" stroke={ldk.stroke} strokeWidth="1"/>
        <text x="283" y="200" fontSize="9" fontWeight="600" fill="#dde2f0" textAnchor="middle">ホール</text>

        {/* 階段下収納 — 2275×910 */}
        <rect x="333" y="163" width="167" height="67" fill={store.fill} stroke={store.stroke} strokeWidth="1"/>
        <text x="416" y="200" fontSize="8" fontWeight="600" fill="#8892aa" textAnchor="middle">階段下収納</text>

        {/* ═══ 中央＋東：LDK 19帖 (y 230-597) ═══ */}
        {/* LDK 全体 */}
        <rect x="233" y="230" width="567" height="367" fill={ldk.fill} stroke={ldk.stroke} strokeWidth="1"/>

        {/* キッチンアイランド — 中央配置 */}
        <rect x="343" y="320" width="60" height="200" rx="3" fill="#1f2530" stroke="#3a4258" strokeWidth="1"/>
        <circle cx="373" cy="350" r="6" fill="#2a3a50" stroke="#5b9cf6" strokeWidth="0.8"/>
        <circle cx="373" cy="380" r="6" fill="#2a3a50" stroke="#5b9cf6" strokeWidth="0.8"/>
        <text x="373" y="430" fontSize="9" fontWeight="700" fill="#dde2f0" textAnchor="middle">🍳</text>
        <text x="373" y="450" fontSize="8" fontWeight="600" fill="#dde2f0" textAnchor="middle">キッチン</text>
        <text x="373" y="463" fontSize="7" fill="#545e75" textAnchor="middle">{kitchenLabel}</text>
        <text x="373" y="500" fontSize="7" fill="#545e75" textAnchor="middle">アイランド</text>

        {/* ダイニング エリア（中央南） */}
        <text x="450" y="555" fontSize="9" fontWeight="600" fill="#8892aa" textAnchor="middle">🪑 ダイニング</text>

        {/* リビング エリア（東中央） */}
        <text x="620" y="380" fontSize="11" fontWeight="700" fill="#dde2f0" textAnchor="middle">LDK</text>
        <text x="620" y="395" fontSize="9" fill="#c9a468" textAnchor="middle">19帖</text>
        <text x="620" y="450" fontSize="8" fill="#545e75" textAnchor="middle">🛋 リビング</text>

        {/* ═══ 南西：FCL＋パントリー (y 297-597) ═══ */}
        {/* FCL — 1820×2275 */}
        <rect x="100" y="297" width="133" height="166" fill={store.fill} stroke={store.stroke} strokeWidth="1"/>
        <text x="166" y="370" fontSize="10" fontWeight="700" fill="#dde2f0" textAnchor="middle">FCL</text>
        <text x="166" y="385" fontSize="8" fill="#545e75" textAnchor="middle">ファミリー</text>
        <text x="166" y="397" fontSize="8" fill="#545e75" textAnchor="middle">クローゼット</text>

        <text x="166" y="410" fontSize="9" fill="#9b7bf4" textAnchor="middle">👜 鞄置き</text>

        {/* パントリー — 1820×1820 */}
        <rect x="100" y="463" width="133" height="134" fill={store.fill} stroke={store.stroke} strokeWidth="1"/>
        <text x="166" y="525" fontSize="10" fontWeight="700" fill="#dde2f0" textAnchor="middle">パントリー</text>
        <text x="166" y="540" fontSize="8" fill="#545e75" textAnchor="middle">食品庫</text>

        {/* 外部南：物干し */}
        <rect x="500" y="600" width="200" height="14" fill="none" stroke="#545e75" strokeWidth="1" strokeDasharray="3,2"/>
        <text x="600" y="613" fontSize="9" fill="#8892aa" textAnchor="middle">物干しスペース（屋外南）</text>

        {/* ロボステーション（LDK北側、階段下収納の南面に設置） */}
        <rect x="345" y="240" width="55" height="20" rx="2" fill="rgba(45,217,143,.08)" stroke="rgba(45,217,143,.3)" strokeWidth="0.8"/>
        <text x="372" y="254" fontSize="8" fontWeight="600" fill="#2dd98f" textAnchor="middle">🤖 ロボ基地</text>

        {/* ═══ 動線矢印 ═══ */}
        {/* ① 外出時ロボスタート → LDK全体を巡回（円弧で表現） */}
        {robot && (
          <path d="M 400,260 Q 550,280 620,420 Q 550,520 400,500 Q 280,460 320,330"
                stroke="#2dd98f" strokeWidth="1.8" fill="none" strokeDasharray="4,3" markerEnd="url(#arr-g)" opacity="0.7"/>
        )}

        {/* ② 入浴後洗濯スタート（脱衣室） */}
        <path d="M 166,120 Q 200,100 250,80" stroke="#2dd98f" strokeWidth="2" fill="none" strokeDasharray="6,3" markerEnd="url(#arr-g)" opacity={drum ? 1 : 0.3}/>

        {/* ③ 食洗機 → 外出前ON（キッチンへ） */}
        {dish && <path d="M 373,310 L 373,320" stroke="#2dd98f" strokeWidth="2.5" fill="none" markerEnd="url(#arr-g)"/>}

        {/* ④ 出勤 — 玄関→外（西） */}
        <path d="M 100,228 L 88,228" stroke="#5b9cf6" strokeWidth="2" fill="none" markerEnd="url(#arr-b)"/>

        {/* ⑤ 帰宅 — 駐車場→玄関 */}
        <path d="M 90,300 Q 95,230 100,228" stroke="#5b9cf6" strokeWidth="2" fill="none" strokeDasharray="4,3" markerEnd="url(#arr-b)"/>

        {/* ⑥ 帰宅後動線 — 玄関→ホール→キッチン */}
        <path d="M 233,228 L 333,200 L 343,400" stroke="#5b9cf6" strokeWidth="1.8" fill="none" strokeDasharray="3,3" markerEnd="url(#arr-b)" opacity="0.65"/>

        {/* ⑦ 買い物搬入（内側ルート）— ホール→FCL→パントリー */}
        <path d="M 283,230 Q 220,260 166,297 L 166,463"
              stroke="#f0a500" strokeWidth="2" fill="none" strokeDasharray="4,3" markerEnd="url(#arr-a)"/>

        {/* LDK↔洗面接続マーカー（ホール経由） */}
        <line x1="333" y1="163" x2="333" y2="163" stroke="none"/>
        <rect x="326" y="157" width="14" height="12" rx="2" fill="rgba(91,156,246,.25)" stroke="var(--blue)" strokeWidth="0.8"/>
        <text x="333" y="166" fontSize="7" fill="var(--blue)" textAnchor="middle">扉</text>

        {/* ⑧ 買い物搬入（外側ルート）— キッチン南窓から直接搬入 */}
        <path d="M 370,616 L 370,580 Q 280,565 166,530"
              stroke="#f0a500" strokeWidth="1.8" fill="none" strokeDasharray="3,4" markerEnd="url(#arr-a)" opacity="0.75"/>
        {/* 南窓マーカー */}
        <rect x="354" y="593" width="32" height="6" rx="1" fill="#f0a500" opacity="0.5"/>
        <text x="370" y="612" fontSize="8" fill="#f0a500" textAnchor="middle" opacity="0.85">南窓</text>

        {/* ⑨ 帰宅後手洗い — 玄関→ホール→洗面 */}
        <path d="M 166,230 Q 250,200 333,150"
              stroke="#9b7bf4" strokeWidth="1.8" fill="none" strokeDasharray="3,3" markerEnd="url(#arr-p)" opacity="0.8"/>

        {/* ═══ ステップ番号 ═══ */}
        <g fontFamily="JetBrains Mono, monospace">
          <circle cx="372" cy="250" r="9" fill="#2dd98f"/><text x="372" y="250" fontSize="10" fontWeight="700" fill="#0b0d12" textAnchor="middle" dominantBaseline="central">1</text>
          <circle cx="283" cy="50" r="9" fill="#2dd98f"/><text x="283" y="50" fontSize="10" fontWeight="700" fill="#0b0d12" textAnchor="middle" dominantBaseline="central">2</text>
          <circle cx="343" cy="340" r="9" fill="#2dd98f"/><text x="343" y="340" fontSize="10" fontWeight="700" fill="#0b0d12" textAnchor="middle" dominantBaseline="central">3</text>
          <circle cx="120" cy="195" r="9" fill="#5b9cf6"/><text x="120" y="195" fontSize="10" fontWeight="700" fill="#0b0d12" textAnchor="middle" dominantBaseline="central">4</text>
          <circle cx="50" cy="270" r="9" fill="#5b9cf6"/><text x="50" y="270" fontSize="10" fontWeight="700" fill="#fff" textAnchor="middle" dominantBaseline="central">5</text>
          <circle cx="375" cy="500" r="9" fill="#2dd98f"/><text x="375" y="500" fontSize="10" fontWeight="700" fill="#0b0d12" textAnchor="middle" dominantBaseline="central">6</text>
          <circle cx="220" cy="260" r="9" fill="#f0a500"/><text x="220" y="260" fontSize="10" fontWeight="700" fill="#0b0d12" textAnchor="middle" dominantBaseline="central">7</text>
          <circle cx="370" cy="560" r="9" fill="#f0a500"/><text x="370" y="560" fontSize="10" fontWeight="700" fill="#0b0d12" textAnchor="middle" dominantBaseline="central">8</text>
          {/* ⑨ 番号 */}
          <circle cx="250" cy="185" r="9" fill="#9b7bf4"/><text x="250" y="185" fontSize="10" fontWeight="700" fill="#fff" textAnchor="middle" dominantBaseline="central">9</text>
        </g>
      </svg>

      {/* 凡例（ステップ説明） */}
      <div className="mobile-flow-steps" style={{
        marginTop:'12px', padding:'10px 14px',
        background:'var(--surface2)', borderRadius:'6px',
        fontSize:'10px', color:'var(--text3)', fontFamily:'var(--mono)',
        display:'grid', gridTemplateColumns:'repeat(3, 1fr)', gap:'4px 12px', lineHeight:1.7
      }}>
        <div>① 外出時ロボスタート（LDK巡回）</div>
        <div>② 入浴後 洗濯スタート（脱衣室）</div>
        <div>③ 食洗機ON（外出前）</div>
        <div>④ 出勤（玄関→外）</div>
        <div>⑤ 帰宅（駐車場→玄関）</div>
        <div>⑥ 夕食後 食洗機ON</div>
        <div>⑦ 搬入：ホール→FCL→パントリー（内側）</div>
        <div>⑧ 搬入：キッチン南窓から直接搬入</div>
        <div>⑨ 帰宅後 手洗い（玄関→洗面）</div>
      </div>
    </div>
  );
}

// ─── 1日のタイムライン ───
function DailyTimeline({ selection, tweaks }) {
  const drum  = selection.laundry === 'drum';
  const dish  = selection.dish !== 'nodish';
  const robot = selection.robot !== 'nrobot';
  const ih    = selection.cooking === 'ih';

  const phases = [
    {t:'朝 6:00〜', events:[
      {tx:'起床・朝食準備', auto:false, eq: ih ? 'IHで素早く調理' : 'ガスコンロで調理'},
      drum  ? {tx:'昨夜の洗濯 乾燥完了・取り出し（5分）', auto:true, eq:'干す・取り込む作業が不要'}
            : {tx:'洗濯物を取り込んでたたむ（25分）', auto:false, eq:'毎日の手作業'},
    ]},
    {t:'外出前 7:30〜', events:[
      dish ? {tx:'食洗機スタート（外出前ON）', auto:true, eq:'帰宅時には食器が洗浄済み'}
           : {tx:'食器を手洗い（15〜20分）', auto:false, eq:'毎朝の手作業'},
      robot ? {tx:'ロボット 外出時スタート', auto:true, eq:'帰宅時には床がきれいな状態に'}
            : {tx:'外出（帰宅後に手動掃除）', auto:false, eq:'帰宅後15〜20分の手作業'},
      {tx:'出勤', auto:false, eq:'家電に任せて安心して外出'},
    ]},
    {t:'夕方 18:00〜', events:[
      {tx:'帰宅', auto:false, eq: robot ? '床がきれいな状態で迎えてくれる' : '床掃除が残っている'},
      {tx:'夕食準備・食事', auto:false, eq: ih ? 'IHで安全・効率的に調理' : 'ガスコンロで調理'},
      dish ? {tx:'食後 食洗機スタート', auto:true, eq:'食後すぐにキッチンが片付く'}
           : {tx:'食器を手洗い（20〜25分）', auto:false, eq:'食後の手作業'},
    ]},
    {t:'夜 入浴後〜', events:[
      drum  ? {tx:'入浴後 洗濯スタート（就寝前）', auto:true, eq:'翌朝には乾燥完了・今日着た服もそのまま洗える'}
            : {tx:'洗濯機スタート→翌朝干す（25分）', auto:false, eq:'干す場所と時間が必要'},
      {tx:'就寝', auto:false, eq:'自由時間が確保できる'},
    ]},
  ];

  // 年間時短目安
  const ds = dish  ? (tweaks.dishFreq * 0.35 * 52) : 0;
  const ls = drum  ? (tweaks.laundryFreq * 0.35 * 52) : 0;
  const rs = robot ? (tweaks.robotFreq * 0.3 * 52) : 0;
  const tot = Math.round(ds + ls + rs);

  return (
    <div>
      <div className="mobile-stack" style={{display:'grid', gridTemplateColumns:'repeat(4, 1fr)', gap:'0', border:'1px solid var(--border)', borderRadius:'10px', overflow:'hidden'}}>
        {phases.map((ph, i) => (
          <div key={i} style={{
            padding:'14px',
            borderRight: i < 3 ? '1px solid var(--border)' : 'none',
            background:'var(--surface)'
          }}>
            <div style={{fontSize:'11px', color:'var(--text3)', fontFamily:'var(--mono)', fontWeight:700, marginBottom:'10px', letterSpacing:'.04em'}}>
              ⏰ {ph.t}
            </div>
            {ph.events.map((e, j) => (
              <div key={j} style={{
                borderRadius:'6px',
                padding:'7px 10px',
                marginBottom:'6px',
                fontSize:'11px', lineHeight:1.5,
                background: e.auto ? 'rgba(45,217,143,.07)' : 'rgba(240,165,0,.06)',
                border: `1px solid ${e.auto ? 'rgba(45,217,143,.22)' : 'rgba(240,165,0,.18)'}`,
                color: e.auto ? 'var(--green)' : 'var(--amber)'
              }}>
                <div style={{fontWeight:600}}>
                  {e.auto ? '⚡ ' : ''}{e.tx}
                </div>
                <div style={{fontSize:'10px', color:'var(--text3)', marginTop:'2px', fontWeight:400}}>{e.eq}</div>
              </div>
            ))}
          </div>
        ))}
      </div>

      <div style={{
        marginTop:'14px',
        background:'var(--surface)',
        border:'1px solid var(--border)',
        borderRadius:'8px',
        padding:'14px 16px',
        fontSize:'12px', color:'var(--text2)', lineHeight:1.7
      }}>
        年間時短の目安：食洗機 <b style={{color:'var(--text)'}}>{Math.round(ds)}時間</b> +
        洗濯乾燥 <b style={{color:'var(--text)'}}>{Math.round(ls)}時間</b> +
        床掃除 <b style={{color:'var(--text)'}}>{Math.round(rs)}時間</b> ＝ <span style={{fontSize:'18px', fontWeight:700, color:'var(--green)', fontFamily:'var(--mono)'}}>{tot}時間/年</span>
        <span style={{color:'var(--text3)'}}>（月{Math.round(tot/12)}時間相当）</span>
      </div>
    </div>
  );
}

// ─── BEFORE/AFTER 動線改善（既存ロジック） ───
function BeforeAfterSection() {
  const [sel, setSel] = useStateFlow(0);
  const item = MOTIONS[sel];
  const totalH = MOTIONS.reduce((s,d)=>s+d.annual, 0);

  return (
    <div>
      <div className="mobile-stat-grid" style={{display:'grid', gridTemplateColumns:'repeat(3,1fr)', gap:'10px', marginBottom:'18px'}}>
        <StatBox label="TOTAL TIME SAVED" value={totalH.toFixed(0)} unit="時間/年" color="var(--purple)" sub="全動線改善の合計効果" />
        <StatBox label="改善ゾーン" value={MOTIONS.length} unit="箇所" color="var(--blue)" />
        <StatBox label="最大削減単位" value={`${MOTIONS.reduce((m,d)=>Math.max(m,d.saved), 0)}`} unit="秒/回" color="var(--amber)" sub="ゴミ出し動線" />
      </div>
      <div className="mobile-stack" style={{display:'grid', gridTemplateColumns:'190px 1fr', gap:'14px'}}>
        <div style={{display:'flex', flexDirection:'column', gap:'6px'}}>
          {MOTIONS.map((d,i)=>(
            <button key={d.id} onClick={()=>setSel(i)} style={{
              padding:'11px 12px', borderRadius:'8px', border:'1px solid', textAlign:'left',
              background: sel===i ? 'var(--surface2)' : 'var(--surface)',
              borderColor: sel===i ? 'var(--border2)' : 'var(--border)',
              transition:'all .15s'
            }}>
              <div style={{fontSize:'18px', marginBottom:'4px'}}>{d.icon}</div>
              <div style={{fontSize:'13px', fontWeight:sel===i ? 600 : 400, color:sel===i ? 'var(--text)' : 'var(--text2)'}}>{d.zone}</div>
              <div style={{fontSize:'11px', color:'var(--purple)', fontFamily:'var(--mono)', marginTop:'2px'}}>−{d.saved}秒/回</div>
            </button>
          ))}
        </div>
        <div style={{background:'var(--surface)', border:'1px solid var(--border)', borderRadius:'10px', padding:'20px'}}>
          <div style={{fontSize:'22px', marginBottom:'10px'}}>{item.icon}</div>
          <h3 style={{fontSize:'16px', fontWeight:700, marginBottom:'16px'}}>{item.zone}</h3>
          <div className="mobile-stack" style={{display:'grid', gridTemplateColumns:'1fr 1fr', gap:'10px', marginBottom:'16px'}}>
            <div style={{background:'rgba(240,88,88,.07)', border:'1px solid rgba(240,88,88,.18)', borderRadius:'8px', padding:'12px'}}>
              <div style={{fontSize:'10px', color:'var(--red)', fontFamily:'var(--mono)', fontWeight:600, marginBottom:'6px'}}>BEFORE</div>
              <div style={{fontSize:'12px', color:'var(--text2)', lineHeight:1.7}}>{item.before}</div>
            </div>
            <div style={{background:'rgba(45,217,143,.07)', border:'1px solid rgba(45,217,143,.18)', borderRadius:'8px', padding:'12px'}}>
              <div style={{fontSize:'10px', color:'var(--green)', fontFamily:'var(--mono)', fontWeight:600, marginBottom:'6px'}}>AFTER</div>
              <div style={{fontSize:'12px', color:'var(--text2)', lineHeight:1.7}}>{item.after}</div>
            </div>
          </div>
          <div style={{marginBottom:'14px', display:'flex', gap:'8px', alignItems:'center'}}>
            <div style={{flex:1, height:'6px', background:'var(--bg)', borderRadius:'3px', overflow:'hidden'}}>
              <div style={{height:'100%', borderRadius:'3px', background:'linear-gradient(90deg, var(--purple), var(--blue))', width:`${Math.min(100, (item.saved/60)*100)}%`}}/>
            </div>
            <span style={{fontSize:'14px', fontWeight:700, color:'var(--purple)', fontFamily:'var(--mono)', whiteSpace:'nowrap'}}>年{item.annual}h短縮</span>
          </div>
          <div style={{fontSize:'10px', color:'var(--text3)', fontWeight:600, letterSpacing:'.05em', marginBottom:'8px', fontFamily:'var(--mono)'}}>IMPLEMENTATION</div>
          <div style={{display:'flex', flexDirection:'column', gap:'5px'}}>
            {item.tips.map((t,i)=>(
              <div key={i} style={{display:'flex', gap:'8px', alignItems:'flex-start'}}>
                <span style={{color:'var(--purple)', fontFamily:'var(--mono)', fontSize:'12px', marginTop:'1px', flexShrink:0}}>→</span>
                <span style={{fontSize:'12px', color:'var(--text2)', lineHeight:1.65}}>{t}</span>
              </div>
            ))}
          </div>
        </div>
      </div>
    </div>
  );
}

// ─── メインタブ ───
function FlowTab({ selection, tweaks }) {
  return (
    <div>
      <SecHead icon="🏠" title="生活動線 — フロアプランと一日の流れ"
        sub="緑の矢印 = 設備が自動でこなすフロー　黄の矢印 = 手作業が発生するフロー　青の矢印 = 移動経路" />
      <div style={{marginBottom:'18px'}}>
        <FloorPlanFlow selection={selection} />
      </div>

      <SecHead icon="⏰" title="1日のタスクタイムライン"
        sub="現在の設備構成における朝〜夜の家事フロー。自動化タスクは設備が肩代わりします。" />
      <div style={{marginBottom:'22px'}}>
        <DailyTimeline selection={selection} tweaks={tweaks} />
      </div>

      <SecHead icon="🏃" title="間取り動線の改善案（BEFORE/AFTER）"
        sub="設備だけでなく、間取り設計レベルで動線を最適化すると、年間で丸1日以上の家事時間がさらに削減できます。" />
      <BeforeAfterSection />
    </div>
  );
}

window.FlowTab = FlowTab;
