// fc-empty.jsx, first-run & empty states — what a brand-new paid user actually
// sees before any data exists. Same "balanced" system + shared kit. Each empty
// keeps the real screen's chrome (banner, title, tab bar, chart frame) so the
// shell never shifts when data arrives; only the content well changes.
//   EmptyToday      · dashboard before the first weigh-in
//   EmptyTrend      · trend chart with zero readings
//   EmptyPastCamps  · archive before any camp is finished
//   EmptyWeekly     · weekly check-in before the first full week closes

const { Phone: EPhone, StatusBar: EStatusBar, HomeIndicator: EHome, LargeTitle: ELargeTitle,
        CompactNav: ECompactNav, TabBar: ETabBar, GearButton: EGear, DashBanner: EDashBanner,
        CoachTip: ECoachTip, Eyebrow: EEyebrow } = window;

// Big primary "log" CTA matching the kit's button language (ink + accent plus).
function LogFirstCTA({ label = 'LOG YOUR FIRST WEIGHT' }) {
  return (
    <button style={{ width: '100%', background: 'var(--accent)', color: '#fff', border: 'none', borderRadius: 'var(--radius-ctl)', minHeight: 56, display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 12, fontFamily: 'var(--display)', fontSize: 14, letterSpacing: '0.13em', fontWeight: 600 }}>
      <span aria-hidden="true" style={{ width: 24, height: 24, background: 'rgba(255,255,255,0.22)', borderRadius: '50%', display: 'flex', alignItems: 'center', justifyContent: 'center', flexShrink: 0 }}>
        <svg width="11" height="11" viewBox="0 0 10 10" fill="none"><line x1="5" y1="1.5" x2="5" y2="8.5" stroke="#fff" strokeWidth="1.6" strokeLinecap="round"/><line x1="1.5" y1="5" x2="8.5" y2="5" stroke="#fff" strokeWidth="1.6" strokeLinecap="round"/></svg>
      </span>
      {label}
    </button>
  );
}

// ── TODAY · before the first weigh-in ─────────────────────────────────────────
function EmptyToday({ styleKey = 'balanced' }) {
  return (
    <EPhone styleKey={styleKey} label="Today · First run">
      <EStatusBar />
      <EDashBanner tone="ink" label="IN CAMP · DAY 1" meta="50 DAYS OUT" />
      <ELargeTitle title="Today" trailing={<EGear />} />
      <div style={{ flex: 1, padding: '2px 20px 24px', display: 'flex', flexDirection: 'column', gap: 20 }}>
        {/* placeholder hero — dashed ghost of the big number */}
        <div>
          <div style={{ display: 'flex', alignItems: 'baseline', gap: 12, marginTop: 4 }}>
            <span style={{ fontFamily: 'var(--num)', fontWeight: 300, fontSize: 104, lineHeight: 0.8, letterSpacing: '-0.04em', color: 'var(--rule-2)' }}>—.—</span>
            <span style={{ fontFamily: 'var(--mono)', fontSize: 13, letterSpacing: '0.16em', color: 'var(--rule-2)', fontWeight: 600 }}>KG</span>
          </div>
          <div style={{ fontFamily: 'var(--mono)', fontSize: 11.5, letterSpacing: '0.14em', textTransform: 'uppercase', color: 'var(--ink-3)', fontWeight: 700, marginTop: 14 }}>No weigh-in logged yet</div>
        </div>

        <LogFirstCTA />

        {/* opt-in refine — precision pulled, not pushed (BFM: get to the first win first) */}
        <button data-screen-label="Sharpen your plan card" style={{ width: '100%', textAlign: 'left', display: 'flex', alignItems: 'center', gap: 14, background: 'var(--paper)', border: '1px solid var(--rule)', borderRadius: 'var(--radius)', boxShadow: 'var(--card-shadow)', padding: '15px 17px', cursor: 'pointer' }}>
          <span style={{ flexShrink: 0, width: 38, height: 38, borderRadius: 11, background: 'var(--accent-soft)', display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
            <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="var(--accent)" strokeWidth="1.8" strokeLinecap="round"><line x1="4" y1="8" x2="20" y2="8"/><circle cx="9" cy="8" r="2.4" fill="var(--paper)"/><line x1="4" y1="16" x2="20" y2="16"/><circle cx="15" cy="16" r="2.4" fill="var(--paper)"/></svg>
          </span>
          <span style={{ flex: 1, minWidth: 0 }}>
            <span style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
              <span style={{ fontFamily: 'var(--sans)', fontSize: 15.5, fontWeight: 600, color: 'var(--ink)' }}>Sharpen your plan</span>
              <span style={{ fontFamily: 'var(--mono)', fontSize: 8.5, letterSpacing: '0.08em', textTransform: 'uppercase', color: 'var(--ink-3)', border: '1px solid var(--rule)', borderRadius: 100, padding: '2px 7px', fontWeight: 600 }}>Optional · 2 min</span>
            </span>
            <span style={{ display: 'block', fontFamily: 'var(--sans)', fontSize: 12.5, color: 'var(--ink-3)', lineHeight: 1.5, marginTop: 3, textWrap: 'pretty' }}>Add your weigh-in time, promotion rules and cycle so every target is dialled in. Do it now, or anytime from Plan.</span>
          </span>
          <svg width="7" height="12" viewBox="0 0 7 12" fill="none" style={{ flexShrink: 0 }}><path d="M1 1 L6 6 L1 11" stroke="var(--rule-2)" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round"/></svg>
        </button>

        {/* what happens next — the trend needs a few days */}
        <div style={{ background: 'var(--paper)', borderRadius: 'var(--radius)', boxShadow: 'var(--card-shadow)', border: 'var(--card-border)', padding: '20px' }}>
          <EEyebrow color="var(--accent)">How tracking works</EEyebrow>
          <div style={{ fontFamily: 'var(--sans)', fontSize: 16.5, fontWeight: 600, color: 'var(--ink)', marginTop: 11, textWrap: 'balance' }}>Log fasted, every morning. The trend builds from there.</div>
          <div style={{ display: 'flex', flexDirection: 'column', gap: 13, marginTop: 16 }}>
            {[
              ['1', 'Weigh in first thing', 'Same time daily, before food or water — the only fair comparison.'],
              ['2', 'We read the trend, not the day', 'Daily swings are mostly water. Give it 3–4 logs before the line means anything.'],
              ['3', 'Your plan adapts', 'Once we see your real pace, every target sharpens around it.'],
            ].map((s, i) => (
              <div key={i} style={{ display: 'flex', gap: 13, alignItems: 'flex-start' }}>
                <span style={{ flexShrink: 0, width: 26, height: 26, borderRadius: '50%', border: '1.5px solid var(--rule-2)', display: 'flex', alignItems: 'center', justifyContent: 'center', fontFamily: 'var(--num)', fontSize: 13, fontWeight: 400, color: 'var(--ink-2)' }}>{s[0]}</span>
                <div style={{ flex: 1 }}>
                  <div style={{ fontFamily: 'var(--sans)', fontSize: 14.5, fontWeight: 600, color: 'var(--ink)' }}>{s[1]}</div>
                  <div style={{ fontFamily: 'var(--sans)', fontSize: 12.5, color: 'var(--ink-3)', lineHeight: 1.5, marginTop: 2, textWrap: 'pretty' }}>{s[2]}</div>
                </div>
              </div>
            ))}
          </div>
        </div>
      </div>
      <ETabBar active="home" /><EHome />
    </EPhone>
  );
}

// Empty chart frame — real axes/grid, dashed plan line, centred prompt.
// ── TREND · zero readings ──────────────────────────────────────────────────────
function EmptyTrend({ styleKey = 'balanced' }) {
  return (
    <EPhone styleKey={styleKey} label="Trend · Empty">
      <EStatusBar />
      <ELargeTitle eyebrow="50 days to weigh-in" title="Trend" trailing={<EGear />} />
      <div style={{ flex: 1, padding: '2px 20px 24px', display: 'flex', flexDirection: 'column' }}>
        <div style={{ flex: 1, display: 'flex', flexDirection: 'column', justifyContent: 'center', alignItems: 'center', textAlign: 'center', paddingBottom: 8 }}>
          <div style={{ fontFamily: 'var(--sans)', fontSize: 20, fontWeight: 700, letterSpacing: '-0.02em', color: 'var(--ink)', textWrap: 'balance' }}>No trend yet.</div>
          <div style={{ fontFamily: 'var(--sans)', fontSize: 14.5, lineHeight: 1.55, color: 'var(--ink-2)', marginTop: 11, maxWidth: '30ch', textWrap: 'pretty' }}>Your trend line draws itself once you’ve logged a few mornings. Weigh in fasted at the same time each day and your pace to fight day appears here.</div>
        </div>
        <LogFirstCTA label="LOG YOUR FIRST WEIGHT" />
      </div>
      <ETabBar active="progress" /><EHome />
    </EPhone>
  );
}

// ── PAST CAMPS · empty archive ───────────────────────────────────────────────
function EmptyPastCamps({ styleKey = 'balanced' }) {
  return (
    <EPhone styleKey={styleKey} label="Past Camps · Empty">
      <EStatusBar />
      <ECompactNav title="Past camps" trailing={<span style={{ width: 40 }} />} />
      <div style={{ flex: 1, padding: '6px 26px 28px', display: 'flex', flexDirection: 'column', alignItems: 'center', textAlign: 'center', justifyContent: 'center' }}>
        <div style={{ width: 84, height: 84, borderRadius: 20, background: 'var(--paper)', border: '1px solid var(--rule)', boxShadow: 'var(--card-shadow)', display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
          <svg width="38" height="38" viewBox="0 0 44 44" fill="none"><rect x="6" y="12" width="32" height="26" rx="3" stroke="var(--rule-2)" strokeWidth="1.8"/><path d="M4 12 L8 7 H36 L40 12" stroke="var(--rule-2)" strokeWidth="1.8" strokeLinejoin="round"/><line x1="17" y1="20" x2="27" y2="20" stroke="var(--rule-2)" strokeWidth="1.8" strokeLinecap="round"/></svg>
        </div>
        <div style={{ fontFamily: 'var(--sans)', fontSize: 22, fontWeight: 700, letterSpacing: '-0.02em', color: 'var(--ink)', marginTop: 22, textWrap: 'balance' }}>No camps yet.</div>
        <div style={{ fontFamily: 'var(--sans)', fontSize: 14.5, lineHeight: 1.55, color: 'var(--ink-2)', marginTop: 10, maxWidth: '30ch', textWrap: 'pretty' }}>When you finish your first camp, it lands here — your division, result, and how the cut actually went. Each one makes the next plan smarter.</div>
        <div style={{ marginTop: 22 }}>
          <button style={{ background: 'transparent', border: '1px solid var(--rule-2)', borderRadius: 'var(--radius-ctl)', minHeight: 48, padding: '0 24px', fontFamily: 'var(--display)', fontSize: 13, letterSpacing: '0.12em', fontWeight: 600, color: 'var(--ink)' }}>VIEW YOUR CURRENT CAMP</button>
        </div>
      </div>
      <EHome />
    </EPhone>
  );
}

// ── WEEKLY CHECK-IN · before the first week closes ─────────────────────────────
function EmptyWeekly({ styleKey = 'balanced' }) {
  const logged = 3, need = 7;
  return (
    <EPhone styleKey={styleKey} label="Weekly · First week">
      <EStatusBar />
      <ELargeTitle title="Weekly" trailing={<EGear />} />
      <div style={{ flex: 1, padding: '2px 20px 24px', display: 'flex', flexDirection: 'column', gap: 20 }}>
        <div style={{ background: 'var(--paper)', borderRadius: 'var(--radius)', boxShadow: 'var(--card-shadow)', border: 'var(--card-border)', padding: '22px 20px' }}>
          <EEyebrow color="var(--accent)">Week 1 · in progress</EEyebrow>
          <div style={{ fontFamily: 'var(--sans)', fontSize: 18, fontWeight: 700, color: 'var(--ink)', marginTop: 11, textWrap: 'balance' }}>Your first check-in lands Sunday.</div>
          <div style={{ fontFamily: 'var(--sans)', fontSize: 13.5, lineHeight: 1.55, color: 'var(--ink-2)', marginTop: 8, textWrap: 'pretty' }}>We need a full week of mornings before we can call your pace. Keep logging — you’re most of the way there.</div>
          {/* week dots */}
          <div style={{ display: 'flex', gap: 7, marginTop: 20 }}>
            {['M','T','W','T','F','S','S'].map((d, i) => {
              const done = i < logged;
              return (
                <div key={i} style={{ flex: 1, display: 'flex', flexDirection: 'column', alignItems: 'center', gap: 7 }}>
                  <div style={{ width: '100%', height: 8, borderRadius: 4, background: done ? 'var(--t-green)' : 'var(--rule)' }} />
                  <span style={{ fontFamily: 'var(--mono)', fontSize: 9.5, color: done ? 'var(--ink-2)' : 'var(--ink-3)', fontWeight: 600 }}>{d}</span>
                </div>
              );
            })}
          </div>
          <div style={{ fontFamily: 'var(--mono)', fontSize: 10.5, letterSpacing: '0.08em', textTransform: 'uppercase', color: 'var(--ink-3)', fontWeight: 600, marginTop: 16 }}>{logged} of {need} mornings logged</div>
        </div>

        <ECoachTip chip="Day 3" headline="Three down. Don’t chase the daily number." body="A morning can swing half a kilo on water alone. The weekly view smooths that out so you’re judging the cut, not the noise." coach />

        <div style={{ background: 'var(--paper)', borderRadius: 'var(--radius)', boxShadow: 'var(--card-shadow)', border: 'var(--card-border)', padding: '20px', opacity: 0.7 }}>
          <div style={{ fontFamily: 'var(--mono)', fontSize: 10.5, letterSpacing: '0.1em', textTransform: 'uppercase', color: 'var(--ink-3)', fontWeight: 600 }}>Past weeks</div>
          <div style={{ fontFamily: 'var(--sans)', fontSize: 13.5, color: 'var(--ink-3)', marginTop: 8 }}>Completed weeks appear here with your pace verdict.</div>
        </div>
      </div>
      <ETabBar active="progress" /><EHome />
    </EPhone>
  );
}

Object.assign(window, { EmptyToday, EmptyTrend, EmptyPastCamps, EmptyWeekly });
