// Variant A — the six screens
// Each screen is a self-contained component that renders inside SapShell.

function SapScreen_Main() {
  const stepNav = [
    ['Pod model', 'done'],
    ['External dimensions', 'done'],
    ['Interior acoustic finish', 'done'],
    ['Exterior finish', 'done'],
    ['Glazing', 'done'],
    ['Electrical outlets', 'active'],
    ['Ventilation & lighting', 'draft'],
    ['Furniture & floor', 'draft'],
    ['Add-ons', 'draft'],
  ];
  return (
    <SapShell>
      <SapLayout
        left={stepNav.map(([l, s], i) => <SapNavItem key={i} n={i + 1} label={l} status={s} active={s === 'active'} />)}
        right={
          <>
            {/* Validation banner */}
            <div style={{ background: sapTokens.accentBg, border: `1px solid #b9d5f0`, borderLeft: `3px solid ${sapTokens.accent}`, padding: '10px 14px', marginBottom: 12, fontSize: 12, color: sapTokens.text, display: 'flex', alignItems: 'center', gap: 10 }}>
              <span style={{ color: sapTokens.accent, fontWeight: 700 }}>ℹ</span>
              <span>Configuration auto-saved at 14:38. Pricing applied from <b>Wholesale EUR→CZK · 04/2026</b>.</span>
            </div>

            <SapStep num={1} totalSteps={9} title="Pod model" required complete subtitle="Base product — determines available options downstream.">
              <div style={{ display: 'grid', gridTemplateColumns: 'repeat(3, 1fr)', gap: 8 }}>
                <SapTile title="SOLO S1" desc="1 person · ø 1100 mm · phone booth" price="38 400,00" thumb={<PodIcon variant="solo"/>}/>
                <SapTile title="DUO M2" desc="2 persons · 1500 × 1500 · meeting" price="52 800,00" thumb={<PodIcon variant="duo"/>}/>
                <SapTile selected title="QUAD L4" desc="4 persons · 2400 × 2400 · team room" price="62 400,00" badge="SELECTED" thumb={<PodIcon variant="quad"/>}/>
              </div>
            </SapStep>

            <SapStep num={2} totalSteps={9} title="External dimensions" required complete subtitle="Footprint in millimeters. Height fixed at 2250 mm for QUAD L4.">
              <div style={{ display: 'grid', gridTemplateColumns: 'repeat(4, 1fr)', gap: 8 }}>
                <SapTile title="2100 × 2100" desc="Compact" price="−4 200,00" priceDelta="−6.7%"/>
                <SapTile selected title="2400 × 2400" desc="Standard" price="Included" badge="STANDARD"/>
                <SapTile title="2800 × 2400" desc="Extended depth" priceDelta="+8 600,00"/>
                <SapTile title="3200 × 2400" desc="Large" priceDelta="+14 200,00"/>
              </div>
            </SapStep>

            <SapStep num={3} totalSteps={9} title="Interior acoustic finish" required complete subtitle="Absorption class A. Fabric covering of the interior panels.">
              <div style={{ display: 'grid', gridTemplateColumns: 'repeat(3, 1fr)', gap: 8 }}>
                <SapTile title="Technical felt" desc="Recycled PET, NRC 0.95" price="Included" info="Made of 60% recycled PET bottles. 35 mm thick panels."/>
                <SapTile title="Wool fabric" desc="100% wool, warm acoustic tone" priceDelta="+3 200,00"/>
                <SapTile selected title="Premium wool blend" desc="Wool + linen, designer palette" priceDelta="+5 800,00" badge="SELECTED"/>
              </div>
            </SapStep>

            <SapStep num={4} totalSteps={9} title="Exterior finish" required complete subtitle="Visible from outside. Match to surrounding interior.">
              <div style={{ display: 'grid', gridTemplateColumns: 'repeat(4, 1fr)', gap: 8 }}>
                <SapTile title="Powder-coated steel" desc="RAL 9005 · matte" price="Included"/>
                <SapTile selected title="Oak veneer" desc="Natural rift-cut, matte lacquer" priceDelta="+12 400,00" badge="PREMIUM"/>
                <SapTile title="Walnut veneer" desc="Dark, warm tone" priceDelta="+16 800,00"/>
                <SapTile title="Laminate (10 colors)" desc="HPL by Egger, 10 colors available" priceDelta="+2 800,00" info="HPL by Egger, 10 colors."/>
              </div>
            </SapStep>

            <SapStep num={5} totalSteps={9} title="Glazing" required complete subtitle="Door glass type. Door hinge direction is set in the next step.">
              <div style={{ display: 'grid', gridTemplateColumns: 'repeat(3, 1fr)', gap: 8 }}>
                <SapTile title="Single glazing" desc="8 mm safety glass, clear" price="Included"/>
                <SapTile title="Double glazing" desc="+6 dB attenuation" priceDelta="+6 200,00"/>
                <SapTile title="Privacy film" desc="Switchable or frosted" priceDelta="+4 400,00"/>
              </div>
            </SapStep>

            <SapStep num={6} totalSteps={9} title="Electrical outlets" required subtitle="Installed in the integrated table panel. Quantity adjustable per type.">
              <div style={{ display: 'grid', gridTemplateColumns: 'repeat(4, 1fr)', gap: 8 }}>
                <SapTile selected title="EU socket (230 V)" desc="Schuko, white" priceDelta="+ 680,00 / pc" qty={4}/>
                <SapTile selected title="USB-C (PD 60 W)" desc="Fast-charge capable" priceDelta="+ 540,00 / pc" qty={2}/>
                <SapTile title="RJ45 (Cat 6)" desc="Wired network jack" priceDelta="+ 420,00 / pc" qty={0}/>
                <SapTile title="HDMI pass-through" desc="Type A, 2 m tail" priceDelta="+ 780,00 / pc" qty={0}/>
              </div>
            </SapStep>
          </>
        }
      />
    </SapShell>
  );
}

// ─────────────────────────────────────────────────────────────
// Screen 2 — Items list (expanded)
// ─────────────────────────────────────────────────────────────
function SapScreen_Items() {
  const items = [
    { n: '010', model: 'SOLO S1', dim: '1100 × 1100', status: 'done', price: '42 800,00', summary: 'Felt · Charcoal · Oak · Std ventilation' },
    { n: '020', model: 'DUO M2', dim: '1500 × 1500', status: 'done', price: '64 300,00', summary: 'Wool · Dune · Laminate white' },
    { n: '030', model: 'QUAD L4', dim: '2400 × 2400', status: 'active', price: '110 412,50', summary: 'Premium wool · Charcoal · Oak · HEPA · 4 sockets · Table+4' },
    { n: '040', model: 'SOLO S1', dim: '1100 × 1100', status: 'draft', price: '— in progress', summary: 'Step 3 of 8 · interior finish pending' },
    { n: '050', model: 'DUO M2', dim: '1500 × 1500', status: 'draft', price: '— pending', summary: 'Not started' },
    { n: '060', model: 'Add-ons bundle', dim: '—', status: 'draft', price: '— pending', summary: 'Cleaning kit, wall mount' },
  ];
  return (
    <SapShell items={6} itemsDone={2}>
      <div style={{ padding: 16 }}>
        <div style={{ background: '#fff', border: `1px solid ${sapTokens.border}` }}>
          <div style={{ padding: '10px 16px', borderBottom: `1px solid ${sapTokens.border}`, display: 'flex', alignItems: 'center', gap: 12 }}>
            <h3 style={{ margin: 0, fontSize: 14, fontWeight: 600 }}>Quotation items — 6</h3>
            <span style={{ fontSize: 11, color: sapTokens.textMuted }}>2 complete · 4 in progress</span>
            <div style={{ flex: 1 }} />
            <SapGhostBtn>Duplicate item</SapGhostBtn>
            <SapGhostBtn>Load template</SapGhostBtn>
            <SapPrimaryBtn>+ New item</SapPrimaryBtn>
          </div>
          <div style={{ display: 'grid', gridTemplateColumns: '60px 1fr 140px 180px 1fr 140px 60px', padding: '8px 16px', background: '#fafbfc', borderBottom: `1px solid ${sapTokens.border}`, fontSize: 11, color: sapTokens.textMuted, textTransform: 'uppercase', letterSpacing: 0.5, fontWeight: 600 }}>
            <div>Line</div>
            <div>Status · Item</div>
            <div>Footprint</div>
            <div>Configuration</div>
            <div style={{ gridColumn: '5 / 7', textAlign: 'right' }}>Summary · Price</div>
            <div/>
          </div>
          {items.map(it => (
            <div key={it.n} style={{
              display: 'grid', gridTemplateColumns: '60px 1fr 140px 180px 1fr 140px 60px',
              padding: '12px 16px', alignItems: 'center', gap: 8,
              borderBottom: `1px solid ${sapTokens.border}`,
              background: it.status === 'active' ? sapTokens.selectedBg : '#fff',
              borderLeft: it.status === 'active' ? `3px solid ${sapTokens.accent}` : '3px solid transparent',
              fontSize: 12,
              cursor: 'pointer',
            }}>
              <div style={{ fontFamily: 'ui-monospace, monospace', color: sapTokens.textMuted }}>{it.n}</div>
              <div style={{ display: 'flex', alignItems: 'center', gap: 10 }}>
                <StatusDot status={it.status} />
                <div>
                  <div style={{ fontWeight: 600 }}>{it.model}</div>
                  <div style={{ fontSize: 11, color: sapTokens.textMuted }}>
                    {it.status === 'done' && 'Complete'}
                    {it.status === 'active' && 'In progress — current'}
                    {it.status === 'draft' && 'Not started'}
                  </div>
                </div>
              </div>
              <div style={{ fontFamily: 'ui-monospace, monospace', color: sapTokens.textMuted }}>{it.dim}</div>
              <div style={{ fontSize: 11, color: sapTokens.textMuted }}>{it.summary.split(' · ').slice(0, 2).join(' · ')}</div>
              <div style={{ fontSize: 11, color: sapTokens.textMuted, gridColumn: 5 }}>{it.summary}</div>
              <div style={{ fontFamily: 'ui-monospace, monospace', textAlign: 'right', fontWeight: 600 }}>{it.price}</div>
              <div style={{ textAlign: 'right', color: sapTokens.textMuted }}>⋯</div>
            </div>
          ))}
          <div style={{ padding: '12px 16px', display: 'flex', alignItems: 'center', justifyContent: 'space-between', background: '#fafbfc' }}>
            <span style={{ fontSize: 11, color: sapTokens.textMuted }}>All prices in CZK, excl. VAT. From price list: Wholesale EUR→CZK · 04/2026.</span>
            <div style={{ display: 'flex', gap: 24 }}>
              <div><span style={{ fontSize: 11, color: sapTokens.textMuted }}>Subtotal: </span><b style={{ fontFamily: 'ui-monospace, monospace' }}>217 512,50</b></div>
              <div><span style={{ fontSize: 11, color: sapTokens.textMuted }}>VAT 21%: </span><b style={{ fontFamily: 'ui-monospace, monospace' }}>45 677,63</b></div>
              <div style={{ fontSize: 14 }}><span style={{ fontSize: 11, color: sapTokens.textMuted }}>Total: </span><b style={{ fontFamily: 'ui-monospace, monospace' }}>263 190,13 CZK</b></div>
            </div>
          </div>
        </div>
      </div>
    </SapShell>
  );
}

// ─────────────────────────────────────────────────────────────
// Screen 3 — Completed with total
// ─────────────────────────────────────────────────────────────
function SapScreen_Complete() {
  return (
    <SapShell>
      <div style={{ padding: 16, display: 'grid', gridTemplateColumns: '1fr 380px', gap: 16, alignItems: 'start' }}>
        <main>
          <div style={{ background: sapTokens.successBg, border: `1px solid #b6d7bf`, borderLeft: `3px solid ${sapTokens.success}`, padding: '14px 16px', marginBottom: 16, display: 'flex', alignItems: 'center', gap: 14 }}>
            <svg width="28" height="28" viewBox="0 0 28 28"><circle cx="14" cy="14" r="13" stroke={sapTokens.success} strokeWidth="1.5" fill="none"/><path d="M8 14L12 18L20 10" stroke={sapTokens.success} strokeWidth="2" fill="none"/></svg>
            <div style={{ flex: 1 }}>
              <div style={{ fontSize: 14, fontWeight: 600 }}>Item 030 · QUAD L4 is complete</div>
              <div style={{ fontSize: 12, color: sapTokens.textMuted, marginTop: 2 }}>All 9 mandatory steps filled. Ready to update quotation in SAP B1.</div>
            </div>
            <SapGhostBtn>Edit configuration</SapGhostBtn>
            <SapPrimaryBtn>Next item →</SapPrimaryBtn>
          </div>

          <div style={{ background: '#fff', border: `1px solid ${sapTokens.border}` }}>
            <div style={{ padding: '12px 16px', borderBottom: `1px solid ${sapTokens.border}`, display: 'flex', alignItems: 'center', gap: 10 }}>
              <h3 style={{ margin: 0, fontSize: 14, fontWeight: 600 }}>Configuration summary</h3>
              <div style={{ flex: 1 }}/>
              <SapGhostBtn>Duplicate</SapGhostBtn>
              <SapGhostBtn>Save as template</SapGhostBtn>
              <SapGhostBtn>Print preview</SapGhostBtn>
            </div>
            {[
              ['01 · Pod model', 'QUAD L4 — 4 persons team room'],
              ['02 · External dimensions', '2400 × 2400 × 2250 mm'],
              ['03 · Interior acoustic finish', 'Premium wool blend · Charcoal'],
              ['04 · Exterior finish', 'Oak veneer — natural rift-cut, matte'],
              ['05 · Glazing & door', 'Double glazing · Right-hinged'],
              ['06 · Ventilation & lighting', 'HEPA 80 m³/h · Dimmable 3000 K'],
              ['07 · Electrical outlets', '4× EU socket, 2× USB-C, RJ45 network'],
              ['08 · Furniture & floor', 'Integrated table + 4 upholstered seats · Carpet floor'],
              ['09 · Add-ons', 'Whiteboard (reverse side), Wireless charger ×2'],
            ].map(([k, v], i) => (
              <div key={i} style={{ display: 'grid', gridTemplateColumns: '220px 1fr auto', padding: '10px 16px', gap: 16, alignItems: 'center', borderBottom: i < 8 ? `1px dashed ${sapTokens.border}` : 'none', fontSize: 12 }}>
                <div style={{ color: sapTokens.textMuted, fontFamily: 'ui-monospace, monospace', fontSize: 11 }}>{k}</div>
                <div style={{ fontWeight: 500 }}>{v}</div>
                <SapCheckIcon/>
              </div>
            ))}
          </div>
        </main>

        <aside style={{ background: '#fff', border: `1px solid ${sapTokens.border}`, position: 'sticky', top: 140 }}>
          <div style={{ padding: '12px 16px', borderBottom: `1px solid ${sapTokens.border}`, fontWeight: 600, fontSize: 13 }}>Price breakdown</div>
          <div style={{ padding: '8px 16px' }}>
            {[
              ['Base QUAD L4', '62 400,00'],
              ['Dimensions upgrade 2400×2400', '—'],
              ['Premium wool blend + Charcoal', '+ 5 800,00'],
              ['Oak veneer exterior', '+ 12 400,00'],
              ['Double glazing', '+ 6 200,00'],
              ['HEPA ventilation', '+ 8 900,00'],
              ['Dimmable LED 3000 K', '+ 3 400,00'],
              ['4× EU + 2× USB-C + RJ45', '+ 4 200,00'],
              ['Furniture set (table + 4 seats)', '+ 9 800,00'],
              ['Carpet floor', '+ 2 400,00'],
              ['Whiteboard add-on', '+ 1 900,00'],
              ['Wireless chargers ×2', '+ 3 600,00'],
            ].map(([k, v], i) => (
              <div key={i} style={{ display: 'flex', justifyContent: 'space-between', padding: '4px 0', fontSize: 12, color: sapTokens.textMuted }}>
                <span>{k}</span><span style={{ fontFamily: 'ui-monospace, monospace', color: sapTokens.text }}>{v}</span>
              </div>
            ))}
          </div>
          <div style={{ padding: '10px 16px', background: '#fafbfc', borderTop: `1px solid ${sapTokens.border}` }}>
            <div style={{ display: 'flex', justifyContent: 'space-between', fontSize: 12, color: sapTokens.textMuted, marginBottom: 4 }}><span>Subtotal</span><span style={{ fontFamily: 'ui-monospace, monospace' }}>91 250,00</span></div>
            <div style={{ display: 'flex', justifyContent: 'space-between', fontSize: 12, color: sapTokens.textMuted, marginBottom: 8 }}><span>VAT 21%</span><span style={{ fontFamily: 'ui-monospace, monospace' }}>19 162,50</span></div>
            <div style={{ display: 'flex', justifyContent: 'space-between', fontSize: 16, fontWeight: 700, paddingTop: 8, borderTop: `1px solid ${sapTokens.border}` }}><span>Item total</span><span style={{ fontFamily: 'ui-monospace, monospace' }}>110 412,50 CZK</span></div>
            <div style={{ fontSize: 11, color: sapTokens.textMuted, marginTop: 6 }}>Discounts (if applicable) will be applied on the quotation level in SAP B1.</div>
          </div>
        </aside>
      </div>
    </SapShell>
  );
}

// ─────────────────────────────────────────────────────────────
// Screen 4 — Invalid configuration (inactive SKU warning)
// ─────────────────────────────────────────────────────────────
function SapScreen_Invalid() {
  return (
    <SapShell>
      <div style={{ padding: 16 }}>
        <div style={{ background: sapTokens.errorBg, border: `1px solid #e6b8b8`, borderLeft: `3px solid ${sapTokens.error}`, padding: '14px 16px', marginBottom: 16, display: 'flex', alignItems: 'flex-start', gap: 14 }}>
          <svg width="24" height="24" viewBox="0 0 24 24" style={{ marginTop: 2 }}><circle cx="12" cy="12" r="11" stroke={sapTokens.error} strokeWidth="1.5" fill="none"/><line x1="12" y1="6" x2="12" y2="13" stroke={sapTokens.error} strokeWidth="2"/><circle cx="12" cy="17" r="1.2" fill={sapTokens.error}/></svg>
          <div style={{ flex: 1 }}>
            <div style={{ fontSize: 14, fontWeight: 600, color: sapTokens.error, marginBottom: 4 }}>Configuration no longer valid — 2 issues require attention</div>
            <div style={{ fontSize: 12, color: sapTokens.text, lineHeight: 1.55 }}>
              This configuration was loaded from a template saved on <b>12/01/2026</b>. Some options have changed since. You cannot save or update the quotation until the issues are resolved.
            </div>
          </div>
          <SapGhostBtn>Dismiss</SapGhostBtn>
        </div>

        <div style={{ background: '#fff', border: `1px solid ${sapTokens.border}`, marginBottom: 12 }}>
          <div style={{ padding: '10px 16px', borderBottom: `1px solid ${sapTokens.border}`, fontSize: 13, fontWeight: 600 }}>Issues detected</div>
          {[
            { sev: 'error', step: 'Step 04 · Exterior finish', item: 'ART-VENEER-WLN-05 — Walnut veneer (discontinued)', msg: 'This article has been marked inactive in SAP. Select a replacement finish to continue.', action: 'Pick replacement' },
            { sev: 'warn', step: 'Step 06 · Ventilation', item: 'ART-VENT-STD-H60 — HEPA 60 m³/h', msg: 'Price changed by +14.2% since template was saved (now 10 160,00 CZK). Review before updating the quotation.', action: 'Review price' },
          ].map((iss, i) => (
            <div key={i} style={{ padding: '14px 16px', borderBottom: i === 0 ? `1px solid ${sapTokens.border}` : 'none', display: 'grid', gridTemplateColumns: '26px 1fr 140px', gap: 12, alignItems: 'flex-start' }}>
              <div style={{
                width: 22, height: 22, borderRadius: 2, display: 'grid', placeItems: 'center',
                background: iss.sev === 'error' ? sapTokens.error : sapTokens.warn, color: '#fff', fontWeight: 700, fontSize: 13,
              }}>{iss.sev === 'error' ? '×' : '!'}</div>
              <div>
                <div style={{ fontSize: 11, color: sapTokens.textMuted, fontFamily: 'ui-monospace, monospace', marginBottom: 2 }}>{iss.step}</div>
                <div style={{ fontSize: 13, fontWeight: 600, marginBottom: 4 }}>{iss.item}</div>
                <div style={{ fontSize: 12, color: sapTokens.textMuted, lineHeight: 1.5 }}>{iss.msg}</div>
              </div>
              <SapPrimaryBtn>{iss.action}</SapPrimaryBtn>
            </div>
          ))}
        </div>

        {/* Inline fix on the broken step */}
        <SapStep num={4} totalSteps={9} title="Exterior finish — select a valid replacement" required valid={false}>
          <div style={{ fontSize: 12, color: sapTokens.error, marginBottom: 10, display: 'flex', alignItems: 'center', gap: 6 }}>
            <span style={{ fontWeight: 600 }}>Walnut veneer</span> is no longer available. Suggested alternatives sorted by visual similarity:
          </div>
          <div style={{ display: 'grid', gridTemplateColumns: 'repeat(4, 1fr)', gap: 8 }}>
            <SapTile invalid title="Walnut veneer" desc="Discontinued from 01/03/2026" badge="INACTIVE" disabled/>
            <SapTile title="Oak veneer — smoked" desc="Dark, warm tone (closest match)" priceDelta="+13 900,00" badge="SUGGESTED" thumb={<div style={{color:'#6a4a2c'}}><svg width="40" height="40" viewBox="0 0 40 40"><rect width="40" height="40" fill="currentColor"/></svg></div>}/>
            <SapTile title="Oak veneer — natural" desc="Lighter oak tone" priceDelta="+12 400,00" thumb={<div style={{color:'#b48a5a'}}><svg width="40" height="40" viewBox="0 0 40 40"><rect width="40" height="40" fill="currentColor"/></svg></div>}/>
            <SapTile title="Laminate Walnut Dark" desc="HPL imitation, cost-effective" priceDelta="+3 400,00" thumb={<div style={{color:'#5a3a24'}}><svg width="40" height="40" viewBox="0 0 40 40"><rect width="40" height="40" fill="currentColor"/></svg></div>}/>
          </div>
        </SapStep>
      </div>
    </SapShell>
  );
}

// ─────────────────────────────────────────────────────────────
// Screen 5 — Save as template modal
// ─────────────────────────────────────────────────────────────
function SapScreen_SaveTemplate() {
  return (
    <SapShell>
      <div style={{ padding: 16, position: 'relative', minHeight: 560 }}>
        {/* Blurred/dimmed background */}
        <div style={{ display: 'grid', gridTemplateColumns: '1fr 380px', gap: 16, filter: 'blur(1.5px)', opacity: 0.55, pointerEvents: 'none' }}>
          <div style={{ background: '#fff', border: `1px solid ${sapTokens.border}`, height: 520 }}/>
          <div style={{ background: '#fff', border: `1px solid ${sapTokens.border}`, height: 520 }}/>
        </div>
        {/* Modal backdrop */}
        <div style={{ position: 'absolute', inset: 0, background: 'rgba(32,40,50,0.45)' }}/>
        {/* Modal */}
        <div style={{ position: 'absolute', top: 40, left: '50%', transform: 'translateX(-50%)', width: 560, background: '#fff', border: `1px solid ${sapTokens.borderStrong}`, boxShadow: '0 8px 32px rgba(0,0,0,0.2)' }}>
          <div style={{ padding: '14px 20px', borderBottom: `1px solid ${sapTokens.border}`, display: 'flex', alignItems: 'center' }}>
            <h3 style={{ margin: 0, fontSize: 14, fontWeight: 600 }}>Save configuration as template</h3>
            <div style={{ flex: 1 }}/>
            <button style={{ background: 'none', border: 'none', fontSize: 16, color: sapTokens.textMuted, cursor: 'pointer' }}>×</button>
          </div>
          <div style={{ padding: 20 }}>
            <div style={{ fontSize: 12, color: sapTokens.textMuted, marginBottom: 16 }}>
              Source: <b style={{ color: sapTokens.text }}>Item 030 · QUAD L4 · 2400×2400 · Premium wool / Oak</b>
            </div>

            <label style={{ fontSize: 11, fontWeight: 600, color: sapTokens.textMuted, textTransform: 'uppercase', letterSpacing: 0.5 }}>Template name <span style={{ color: sapTokens.mandatory }}>*</span></label>
            <input defaultValue="Brezina Architects – QUAD oak standard" style={{ width: '100%', padding: '8px 10px', fontSize: 13, border: `1px solid ${sapTokens.borderStrong}`, borderRadius: 2, marginTop: 6, marginBottom: 14, fontFamily: sapFont }}/>

            <label style={{ fontSize: 11, fontWeight: 600, color: sapTokens.textMuted, textTransform: 'uppercase', letterSpacing: 0.5 }}>Description</label>
            <textarea defaultValue="Quad room, oak exterior, premium wool Charcoal interior, double glazing, HEPA. Use for Brezina-style projects." style={{ width: '100%', padding: '8px 10px', fontSize: 13, border: `1px solid ${sapTokens.borderStrong}`, borderRadius: 2, marginTop: 6, marginBottom: 14, fontFamily: sapFont, minHeight: 64, resize: 'vertical' }}/>

            <label style={{ fontSize: 11, fontWeight: 600, color: sapTokens.textMuted, textTransform: 'uppercase', letterSpacing: 0.5, display: 'block', marginBottom: 8 }}>Visibility</label>
            <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 8, marginBottom: 14 }}>
              <div style={{ padding: 12, border: `1px solid ${sapTokens.border}`, background: '#fff', cursor: 'pointer' }}>
                <div style={{ display: 'flex', alignItems: 'center', gap: 6, marginBottom: 4 }}>
                  <div style={{ width: 14, height: 14, borderRadius: '50%', border: `1.5px solid ${sapTokens.borderStrong}` }}/>
                  <b style={{ fontSize: 12 }}>Private</b>
                </div>
                <div style={{ fontSize: 11, color: sapTokens.textMuted, lineHeight: 1.4 }}>Only visible to you (<b>J. Novák</b>).</div>
              </div>
              <div style={{ padding: 12, border: `2px solid ${sapTokens.accent}`, background: sapTokens.selectedBg, cursor: 'pointer' }}>
                <div style={{ display: 'flex', alignItems: 'center', gap: 6, marginBottom: 4 }}>
                  <div style={{ width: 14, height: 14, borderRadius: '50%', border: `1.5px solid ${sapTokens.accent}`, background: 'radial-gradient(circle,#fff 40%,' + sapTokens.accent + ' 40%)' }}/>
                  <b style={{ fontSize: 12 }}>Global</b>
                </div>
                <div style={{ fontSize: 11, color: sapTokens.textMuted, lineHeight: 1.4 }}>Available to all SilentLab sales users.</div>
              </div>
            </div>

            <div style={{ display: 'flex', alignItems: 'center', gap: 8, fontSize: 12, color: sapTokens.textMuted, padding: '10px 12px', background: '#fafbfc', border: `1px solid ${sapTokens.border}` }}>
              <input type="checkbox" defaultChecked style={{ margin: 0 }}/>
              <span>Validate configuration against current BOM before saving (recommended)</span>
            </div>
          </div>
          <div style={{ padding: '12px 20px', borderTop: `1px solid ${sapTokens.border}`, display: 'flex', justifyContent: 'flex-end', gap: 8, background: '#fafbfc' }}>
            <SapGhostBtn>Cancel</SapGhostBtn>
            <SapPrimaryBtn>Save template</SapPrimaryBtn>
          </div>
        </div>
      </div>
    </SapShell>
  );
}

// ─────────────────────────────────────────────────────────────
// Screen 6 — Load from template modal
// ─────────────────────────────────────────────────────────────
function SapScreen_LoadTemplate() {
  const templates = [
    { name: 'QUAD oak standard', scope: 'global', by: 'T. Veselý', date: '04/03/2026', used: 12, summary: 'QUAD L4 · 2400×2400 · Oak · Premium wool Charcoal', price: '110 412,50 CZK', valid: true },
    { name: 'DUO budget white', scope: 'global', by: 'M. Dvořáková', date: '22/02/2026', used: 34, summary: 'DUO M2 · 1500×1500 · Laminate white · Felt', price: '64 300,00 CZK', valid: true, featured: true },
    { name: 'SOLO executive walnut', scope: 'private', by: 'J. Novák', date: '15/01/2026', used: 3, summary: 'SOLO S1 · Walnut · Wool Dune — contains 1 discontinued item', price: '74 100,00 CZK', valid: false },
    { name: 'QUAD focus room (HEPA+)', scope: 'global', by: 'P. Horák', date: '08/01/2026', used: 8, summary: 'QUAD L4 · HEPA 120 · Double glazing · Acoustic door', price: '128 450,00 CZK', valid: true },
    { name: 'DUO — Brezina house style', scope: 'private', by: 'J. Novák', date: '12/12/2025', used: 5, summary: 'DUO M2 · Oak · Premium wool Charcoal', price: '78 900,00 CZK', valid: true },
  ];
  return (
    <SapShell>
      <div style={{ padding: 16, position: 'relative', minHeight: 620 }}>
        <div style={{ display: 'grid', gridTemplateColumns: '1fr 380px', gap: 16, filter: 'blur(1.5px)', opacity: 0.55, pointerEvents: 'none' }}>
          <div style={{ background: '#fff', border: `1px solid ${sapTokens.border}`, height: 600 }}/>
          <div style={{ background: '#fff', border: `1px solid ${sapTokens.border}`, height: 600 }}/>
        </div>
        <div style={{ position: 'absolute', inset: 0, background: 'rgba(32,40,50,0.45)' }}/>
        <div style={{ position: 'absolute', top: 24, left: '50%', transform: 'translateX(-50%)', width: 780, background: '#fff', border: `1px solid ${sapTokens.borderStrong}`, boxShadow: '0 8px 32px rgba(0,0,0,0.2)' }}>
          <div style={{ padding: '14px 20px', borderBottom: `1px solid ${sapTokens.border}`, display: 'flex', alignItems: 'center' }}>
            <h3 style={{ margin: 0, fontSize: 14, fontWeight: 600 }}>Load configuration from template</h3>
            <div style={{ flex: 1 }}/>
            <button style={{ background: 'none', border: 'none', fontSize: 16, color: sapTokens.textMuted, cursor: 'pointer' }}>×</button>
          </div>

          <div style={{ padding: '12px 20px', display: 'flex', alignItems: 'center', gap: 10, borderBottom: `1px solid ${sapTokens.border}` }}>
            <input placeholder="Search templates…" style={{ flex: 1, padding: '7px 10px', fontSize: 13, border: `1px solid ${sapTokens.borderStrong}`, borderRadius: 2, fontFamily: sapFont }}/>
            <select style={{ padding: '6px 10px', fontSize: 12, border: `1px solid ${sapTokens.borderStrong}`, borderRadius: 2, fontFamily: sapFont }}>
              <option>All templates</option><option>Global only</option><option>My templates</option>
            </select>
            <select style={{ padding: '6px 10px', fontSize: 12, border: `1px solid ${sapTokens.borderStrong}`, borderRadius: 2, fontFamily: sapFont }}>
              <option>Model: all</option><option>SOLO</option><option>DUO</option><option>QUAD</option>
            </select>
          </div>

          <div style={{ maxHeight: 380, overflow: 'auto' }}>
            {templates.map((t, i) => (
              <div key={i} style={{
                padding: '12px 20px', display: 'grid',
                gridTemplateColumns: '1fr 160px 120px 90px',
                gap: 16, alignItems: 'center',
                borderBottom: i < templates.length - 1 ? `1px solid ${sapTokens.border}` : 'none',
                background: t.featured ? sapTokens.selectedBg : '#fff',
                borderLeft: t.featured ? `3px solid ${sapTokens.accent}` : '3px solid transparent',
                cursor: 'pointer',
              }}>
                <div style={{ minWidth: 0 }}>
                  <div style={{ display: 'flex', alignItems: 'center', gap: 8, marginBottom: 2 }}>
                    <span style={{ fontSize: 13, fontWeight: 600 }}>{t.name}</span>
                    <span style={{ fontSize: 10, padding: '1px 5px', border: `1px solid ${sapTokens.border}`, color: sapTokens.textMuted, fontWeight: 600, letterSpacing: 0.2 }}>{t.scope === 'global' ? 'GLOBAL' : 'PRIVATE'}</span>
                    {!t.valid && <span style={{ fontSize: 10, padding: '1px 5px', background: sapTokens.errorBg, color: sapTokens.error, fontWeight: 600 }}>INVALID</span>}
                  </div>
                  <div style={{ fontSize: 11, color: sapTokens.textMuted }}>{t.summary}</div>
                  <div style={{ fontSize: 10, color: sapTokens.textFaint, marginTop: 3, fontFamily: 'ui-monospace, monospace' }}>
                    by {t.by} · {t.date} · used {t.used}×
                  </div>
                </div>
                <div style={{ fontSize: 12, fontFamily: 'ui-monospace, monospace', color: sapTokens.text, fontWeight: 600, textAlign: 'right' }}>{t.price}</div>
                <div style={{ fontSize: 11, color: sapTokens.textMuted, textAlign: 'right' }}>{t.valid ? 'Up to date' : '1 conflict'}</div>
                <div style={{ textAlign: 'right' }}>
                  {t.featured
                    ? <SapPrimaryBtn>Apply</SapPrimaryBtn>
                    : <SapGhostBtn>Apply</SapGhostBtn>}
                </div>
              </div>
            ))}
          </div>

          <div style={{ padding: '12px 20px', borderTop: `1px solid ${sapTokens.border}`, background: '#fafbfc', display: 'flex', alignItems: 'center', gap: 10 }}>
            <span style={{ fontSize: 11, color: sapTokens.textMuted, flex: 1 }}>Loading a template will replace current selections. Configuration is validated against the active BOM.</span>
            <SapGhostBtn>Cancel</SapGhostBtn>
          </div>
        </div>
      </div>
    </SapShell>
  );
}

Object.assign(window, {
  SapScreen_Main, SapScreen_Items, SapScreen_Complete, SapScreen_Invalid,
  SapScreen_SaveTemplate, SapScreen_LoadTemplate,
});
