// screens-mobile.jsx — 방문객 모바일 QR (in iOS frame) + 식당 직원 모바일 스캐너

// ═══════════════════════════════════════════════════════════════
// 방문객 핸드폰 — 동적 QR 표시 화면
// ═══════════════════════════════════════════════════════════════
function VisitorMobileQR() {
  return (
    <IOSDevice width={390} height={844}>
      <div style={{ width: '100%', height: '100%', background: 'var(--paper-1)', color: 'var(--ink-0)', fontFamily: 'var(--font-sans)', display: 'flex', flexDirection: 'column' }}>
        {/* nav */}
        <div style={{ padding: '12px 20px', display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}>
          <Icon name="x" size={20} color="var(--ink-2)" />
          <div className="serif" style={{ fontSize: 15, fontWeight: 500 }}>방문 QR</div>
          <Icon name="settings" size={18} color="var(--ink-2)" />
        </div>

        {/* hero greeting */}
        <div style={{ padding: '8px 24px 14px' }}>
          <div className="serif" style={{ fontSize: 26, fontWeight: 500, lineHeight: 1.18, letterSpacing: '-0.015em' }}>
            김도현님,<br/>
            오늘 잘 다녀오세요.
          </div>
          <div style={{ fontSize: 12.5, color: 'var(--ink-3)', marginTop: 6 }}>박정민 책임 · 5F 회의실 304 · 15:00</div>
        </div>

        {/* QR card */}
        <div style={{ margin: '0 20px', background: 'var(--paper-0)', borderRadius: 18, padding: 22, border: '0.5px solid var(--paper-stroke)', boxShadow: 'var(--shadow-2)' }}>
          <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', marginBottom: 16 }}>
            <div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
              <span style={{ width: 7, height: 7, borderRadius: 100, background: 'var(--celadon)', boxShadow: '0 0 0 4px rgba(122, 155, 142, 0.18)' }} />
              <span style={{ fontSize: 11.5, color: 'var(--celadon-deep)', fontWeight: 500 }}>활성 · 정문 입장 가능</span>
            </div>
            <span className="mono tabular" style={{ fontSize: 11, color: 'var(--ink-3)' }}>VST-7892</span>
          </div>

          <div style={{ position: 'relative', display: 'flex', alignItems: 'center', justifyContent: 'center', padding: '14px 0' }}>
            {/* corner brackets */}
            {['tl','tr','bl','br'].map(k => (
              <div key={k} style={{
                position: 'absolute', width: 22, height: 22,
                borderColor: 'var(--ink-0)', borderStyle: 'solid', borderWidth: 0,
                ...(k==='tl'?{top:8,left:8,borderTopWidth:1.5,borderLeftWidth:1.5}:{}),
                ...(k==='tr'?{top:8,right:8,borderTopWidth:1.5,borderRightWidth:1.5}:{}),
                ...(k==='bl'?{bottom:8,left:8,borderBottomWidth:1.5,borderLeftWidth:1.5}:{}),
                ...(k==='br'?{bottom:8,right:8,borderBottomWidth:1.5,borderRightWidth:1.5}:{}),
              }} />
            ))}
            <QRBlock size={250} seed="VST-7892-DYNAMIC-A4F3" dark="var(--ink-0)" />
            <div style={{ position: 'absolute', top: '50%', left: '50%', transform: 'translate(-50%, -50%)', background: 'var(--paper-0)', padding: 6, borderRadius: 8 }}>
              <Seal size={36} label="出" />
            </div>
          </div>

          {/* refresh ring */}
          <div style={{ marginTop: 14, padding: '12px 14px', background: 'var(--paper-1)', borderRadius: 10, display: 'flex', alignItems: 'center', gap: 12 }}>
            <svg width="32" height="32" viewBox="0 0 32 32">
              <circle cx="16" cy="16" r="13" fill="none" stroke="var(--paper-stroke)" strokeWidth="2" />
              <circle cx="16" cy="16" r="13" fill="none" stroke="var(--celadon)" strokeWidth="2"
                strokeDasharray={`${2*Math.PI*13}`} strokeDashoffset={`${2*Math.PI*13*0.55}`}
                strokeLinecap="round" transform="rotate(-90 16 16)" />
              <text x="16" y="20" textAnchor="middle" fontSize="10" fontWeight="600" fill="var(--ink-0)" fontFamily="var(--font-mono)">14</text>
            </svg>
            <div style={{ flex: 1 }}>
              <div style={{ fontSize: 12.5, fontWeight: 500, color: 'var(--ink-0)' }}>14초 후 자동 갱신</div>
              <div style={{ fontSize: 10.5, color: 'var(--ink-3)', marginTop: 2 }}>스크린샷·캡쳐로는 입장할 수 없어요</div>
            </div>
            <Icon name="refresh" size={14} color="var(--ink-2)" />
          </div>
        </div>

        {/* details */}
        <div style={{ flex: 1, padding: '18px 20px', display: 'flex', flexDirection: 'column', gap: 10 }}>
          <MobileTile icon="building" title="본관 정문" sub="활성 · 14:30 — 17:30" tone="approved" />
          <MobileTile icon="users" title="5F 회의실 304" sub="입실 · 15:00 — 17:00" />
          <MobileTile icon="food" title="구내식당 식권" sub="1매 · 11:30 — 14:00" badge="식권" />
          <MobileTile icon="car" title="주차장 25가 4719" sub="2시간 무료" />
        </div>

        {/* bottom action */}
        <div style={{ padding: '12px 20px 22px', background: 'var(--paper-1)' }}>
          <button style={{ width: '100%', padding: '14px 0', background: 'var(--ink-0)', color: 'var(--paper-0)', border: 'none', borderRadius: 12, fontSize: 13, fontWeight: 500, cursor: 'pointer', fontFamily: 'inherit', display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 8 }}>
            <Icon name="location" size={14} color="var(--paper-0)" />
            지도로 안내받기
          </button>
        </div>
      </div>
    </IOSDevice>
  );
}

function MobileTile({ icon, title, sub, tone, badge }) {
  return (
    <div style={{ display: 'flex', alignItems: 'center', gap: 12, padding: '12px 14px', background: 'var(--paper-0)', borderRadius: 10, border: '0.5px solid var(--paper-stroke)' }}>
      <div style={{ width: 32, height: 32, borderRadius: 8, background: tone === 'approved' ? 'var(--celadon-soft)' : 'var(--paper-2)', display: 'flex', alignItems: 'center', justifyContent: 'center', flexShrink: 0 }}>
        <Icon name={icon} size={15} color={tone === 'approved' ? 'var(--celadon-deep)' : 'var(--ink-1)'} />
      </div>
      <div style={{ flex: 1, minWidth: 0 }}>
        <div style={{ fontSize: 12.5, fontWeight: 500, color: 'var(--ink-0)' }}>{title}</div>
        <div style={{ fontSize: 11, color: 'var(--ink-3)', marginTop: 1 }}>{sub}</div>
      </div>
      {badge && <Pill tone="approved" soft>{badge}</Pill>}
      <Icon name="chevron" size={13} color="var(--ink-3)" />
    </div>
  );
}

// ═══════════════════════════════════════════════════════════════
// 식당 직원 모바일 스캐너 화면
// ═══════════════════════════════════════════════════════════════
function CanteenScanner() {
  return (
    <IOSDevice width={390} height={844} dark>
      <div style={{ width: '100%', height: '100%', background: '#1B1916', color: '#EFEBE0', fontFamily: 'var(--font-sans)', display: 'flex', flexDirection: 'column', position: 'relative' }}>
        {/* nav */}
        <div style={{ padding: '12px 20px', display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}>
          <Icon name="x" size={20} color="#A6A095" />
          <div className="serif" style={{ fontSize: 15, fontWeight: 500 }}>식권 스캐너</div>
          <div style={{ fontSize: 11, color: '#8FB1A4', display: 'flex', alignItems: 'center', gap: 4 }}>
            <span style={{ width: 5, height: 5, borderRadius: 100, background: '#8FB1A4' }} /> 온라인
          </div>
        </div>

        {/* viewfinder area */}
        <div style={{ flex: 1, position: 'relative', overflow: 'hidden' }}>
          {/* simulated camera (gradient + grain) */}
          <div style={{ position: 'absolute', inset: 0, background: 'radial-gradient(ellipse at 50% 40%, #2D2A24 0%, #15140F 70%)' }} />
          <div style={{ position: 'absolute', inset: 0, opacity: 0.06,
            backgroundImage: 'radial-gradient(circle at 20% 30%, #fff 0px, transparent 1.5px), radial-gradient(circle at 70% 80%, #fff 0px, transparent 1px)',
            backgroundSize: '4px 4px, 6px 6px',
          }} />

          {/* viewfinder corners */}
          <div style={{ position: 'absolute', inset: '20% 16%', display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
            {['tl','tr','bl','br'].map(k => (
              <div key={k} style={{
                position: 'absolute', width: 36, height: 36,
                borderColor: '#8FB1A4', borderStyle: 'solid', borderWidth: 0,
                ...(k==='tl'?{top:0,left:0,borderTopWidth:2.5,borderLeftWidth:2.5,borderTopLeftRadius:8}:{}),
                ...(k==='tr'?{top:0,right:0,borderTopWidth:2.5,borderRightWidth:2.5,borderTopRightRadius:8}:{}),
                ...(k==='bl'?{bottom:0,left:0,borderBottomWidth:2.5,borderLeftWidth:2.5,borderBottomLeftRadius:8}:{}),
                ...(k==='br'?{bottom:0,right:0,borderBottomWidth:2.5,borderRightWidth:2.5,borderBottomRightRadius:8}:{}),
              }} />
            ))}

            {/* scanning line */}
            <div style={{ position: 'absolute', inset: 0, overflow: 'hidden', borderRadius: 8 }}>
              <div style={{ position: 'absolute', left: 0, right: 0, height: 2, top: '50%', background: 'linear-gradient(90deg, transparent, #8FB1A4 50%, transparent)', boxShadow: '0 0 16px rgba(143,177,164,0.6)' }} />
            </div>

            {/* simulated QR being scanned */}
            <div style={{ opacity: 0.55, padding: 10, background: 'rgba(255,255,255,0.06)', borderRadius: 6 }}>
              <QRBlock size={140} seed="MEAL-0428" dark="#EFEBE0" />
            </div>
          </div>

          <div style={{ position: 'absolute', top: 20, left: 0, right: 0, textAlign: 'center', fontSize: 12, color: '#A6A095' }}>
            QR을 사각형 안에 맞춰주세요
          </div>
        </div>

        {/* result toast — successful scan */}
        <div style={{ position: 'absolute', left: 16, right: 16, bottom: 220, background: 'rgba(35,33,28,0.96)', backdropFilter: 'blur(10px)', borderRadius: 14, padding: '14px 16px', border: '0.5px solid rgba(143,177,164,0.3)', display: 'flex', alignItems: 'center', gap: 12 }}>
          <div style={{ width: 38, height: 38, borderRadius: 100, background: '#8FB1A4', display: 'flex', alignItems: 'center', justifyContent: 'center', flexShrink: 0 }}>
            <Icon name="check" size={20} color="#15140F" />
          </div>
          <div style={{ flex: 1, minWidth: 0 }}>
            <div style={{ fontSize: 13.5, fontWeight: 600, color: '#EFEBE0' }}>식권 사용 완료</div>
            <div style={{ fontSize: 11.5, color: '#A6A095', marginTop: 2 }}>이지훈 · 디자인팀 · 한식 1매</div>
          </div>
          <span className="mono" style={{ fontSize: 11, color: '#8FB1A4' }}>12:18:04</span>
        </div>

        {/* recent scan log */}
        <div style={{ background: '#1B1916', padding: '14px 20px 22px', borderTop: '0.5px solid #2D2A24' }}>
          <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', marginBottom: 10 }}>
            <div style={{ display: 'flex', gap: 14, fontSize: 12, color: '#EFEBE0' }}>
              <span style={{ fontWeight: 500 }}>오늘 <span className="tabular" style={{ color: '#8FB1A4' }}>847</span>식</span>
              <span style={{ color: '#807A6F' }}>한식 412 · 양식 268 · 분식 167</span>
            </div>
            <Icon name="list" size={14} color="#A6A095" />
          </div>
          <div style={{ display: 'flex', flexDirection: 'column', gap: 4 }}>
            {[
              { t:'12:18:04', name:'이지훈', team:'디자인팀', menu:'한식', tone:'ok' },
              { t:'12:17:51', name:'한지원', team:'영업팀', menu:'양식', tone:'ok' },
              { t:'12:17:38', name:'박서연', team:'개발팀', menu:'한식', tone:'ok' },
              { t:'12:17:14', name:'최도윤', team:'IT팀', menu:'중복사용', tone:'err' },
            ].map((r, i) => (
              <div key={i} style={{ display: 'grid', gridTemplateColumns: '52px 1fr auto', gap: 10, padding: '6px 0', alignItems: 'center', fontSize: 11.5 }}>
                <span className="mono" style={{ color: '#807A6F', fontSize: 10.5 }}>{r.t}</span>
                <div style={{ minWidth: 0 }}>
                  <div style={{ color: '#EFEBE0' }}>{r.name} <span style={{ color: '#807A6F' }}>· {r.team}</span></div>
                </div>
                <span style={{ fontSize: 10.5, color: r.tone === 'ok' ? '#8FB1A4' : '#D87968', fontWeight: 500 }}>{r.menu}</span>
              </div>
            ))}
          </div>
        </div>
      </div>
    </IOSDevice>
  );
}

Object.assign(window, { VisitorMobileQR, CanteenScanner, MobileTile });
