function renderCloudPage(c, accounts){
  accounts = accounts || [];
  var h = '';

  // Render icon: URL → <img>, emoji/text → plain text
  function iconHtml(icon, size){
    if(!icon) return '';
    if(icon.indexOf('/')===0 || icon.indexOf('http')===0){
      return '<img src="'+icon+'" style="width:'+size+'px;height:'+size+'px;vertical-align:middle;margin-right:4px" onerror="this.remove()">';
    }
    return '<span style="font-size:'+(size-2)+'px;vertical-align:middle;margin-right:4px">'+icon+'</span>';
  }

  // Toggle grid
  h += '<div class="card"><div class="card-title">⚡ 搜索网盘类型控制</div>'+
    '<p style="color:var(--sub);font-size:12px;margin-bottom:14px">控制搜索引擎检索哪些网盘类型的资源</p>'+
    '<div class="stats-grid" style="grid-template-columns:repeat(auto-fill,minmax(170px,1fr))">';
  CLOUD_TYPES.forEach(function(ct){
    var on = __cloudToggles[ct.type];
    h += '<div class="stat-card" style="padding:8px 12px;display:flex;align-items:center;justify-content:space-between">'+
      '<span>'+iconHtml(ct.icon,20)+' <span style="font-size:12px">'+ct.label+'</span></span>'+
      '<label class="toggle"><input type="checkbox" '+(on?'checked':'')+' onchange="togCloudType(\''+ct.type+'\',this)"><span class="toggle-slider"></span></label>'+
    '</div>';
  });
  h += '</div></div>';

  // Account list — table style
  if(accounts.length > 0){
    h += '<div class="card"><div class="card-title">📋 已有账号 ('+accounts.length+') <button class="btn btn-pri btn-sm" onclick="openAddDialog()" style="margin-left:12px">➕ 新增</button></div>';
    h += '<div style="overflow-x:auto"><table style="width:100%;border-collapse:collapse;font-size:13px">';
    h += '<thead><tr style="background:var(--bg);border-bottom:2px solid var(--border);text-align:left">'+
      '<th style="padding:10px 12px;white-space:nowrap">📱推广平台</th>'+
      '<th style="padding:10px 12px;white-space:nowrap">推广平台账号</th>'+
      '<th style="padding:10px 12px;white-space:nowrap">网盘昵称</th>'+'<th style="padding:10px 12px;white-space:nowrap">网盘UID</th>'+
      '<th style="padding:10px 12px;white-space:nowrap">验证</th>'+
      '<th style="padding:10px 12px;white-space:nowrap">空间</th>'+
      '<th style="padding:10px 12px;white-space:nowrap">转存</th>'+
      '<th style="padding:10px 12px;white-space:nowrap">操作</th>'+
    '</tr></thead><tbody>';
    accounts.forEach(function(cfg){
      var label = CLOUD_TYPES.find(function(ct){ return ct.type===cfg.cloud_type; });
      var icon = (label||{}).icon||'⬜';
      var active = cfg.is_active===1||cfg.is_active===true;
      var ck = cfg.verification_status==='valid'?'✅':(cfg.verification_status==='invalid'?'❌':'⏳');
      h += '<tr style="border-bottom:1px solid var(--border)">'+
        '<td style="padding:10px 12px;white-space:nowrap">'+iconHtml(icon,18)+(label||{}).label+'</td>'+
        '<td style="padding:10px 12px;white-space:nowrap">'+(cfg.promotion_account||'—')+'</td>'+
        '<td style="padding:10px 12px;white-space:nowrap">'+(cfg.nickname||cfg.cloud_type)+'</td>'+
        '<td style="padding:10px 12px;white-space:nowrap;font-size:12px;color:var(--sub)">'+(cfg.cookie_uid||cfg.cloud_type)+'</td>'+
        '<td style="padding:10px 12px">'+ck+'</td>'+
        '<td style="padding:10px 12px;white-space:nowrap;font-size:12px;color:var(--sub)">'+(cfg.storage_used||cfg.storage_total?'💾 '+(cfg.storage_used||'?')+'/'+(cfg.storage_total||'?'):'—')+'</td>'+
        '<td style="padding:10px 12px;white-space:nowrap;font-size:12px;color:var(--sub)">'+(cfg.total_saves?'转存'+cfg.total_saves+'次':'—')+'</td>'+
        '<td style="padding:10px 12px;white-space:nowrap">'+
          '<label class="toggle"><input type="checkbox" '+(active?'checked':'')+' onchange="togCloudAcc('+cfg.id+',this)"><span class="toggle-slider"></span></label>'+
          '<button class="btn btn-danger btn-sm" onclick="delCloudAcc('+cfg.id+')" style="margin-left:8px">🗑</button>'+
        '</td>'+
      '</tr>';
    });
    h += '</tbody></table></div></div>';
  }
  // No accounts yet — show add button
  if(accounts.length === 0){
    h += '<div class="card"><div class="card-title">📋 已有账号 (0)</div><p style="color:var(--sub);font-size:13px;margin-bottom:12px">还没有添加任何网盘账号</p><button class="btn btn-pri" onclick="openAddDialog()">➕ 新增网盘</button></div>';
  }

  // Modal dialog
  h += '<div id="modalBg" style="display:none;position:fixed;top:0;left:0;right:0;bottom:0;background:rgba(0,0,0,.4);z-index:100;align-items:center;justify-content:center" onclick="if(event.target===this)closeDialog()">'+
    '<div class="card" style="width:500px;max-width:95vw;max-height:90vh;overflow-y:auto" onclick="event.stopPropagation()">'+
    '<div style="display:flex;justify-content:space-between;align-items:center;margin-bottom:12px">'+
    '<span style="font-weight:600;font-size:15px">新增网盘账号</span>'+
    '<button class="btn btn-outline btn-sm" onclick="closeDialog()">✕</button></div>'+
    '<div class="form-group"><label>网盘类型</label><select id="dlg_type" class="form-control" style="max-width:200px" onchange="onDlgTypeChange()">';
  CLOUD_TYPES.forEach(function(ct){ h+='<option value="'+ct.type+'">'+ct.label+'</option>'; });
  h+='</select></div>'+
    '<div class="form-group"><label>推广平台账号</label><input id="dlg_promo" class="form-control" placeholder="平台注册所用手机号" style="max-width:250px"></div>'+
    '<div class="form-group"><label>Cookie</label><textarea id="dlg_cookie" class="form-control wide" rows="5" placeholder="粘贴 Cookie 或通过下方扫码获取"></textarea></div>'+
    '<div class="form-group"><label>网盘昵称</label><input id="dlg_nick" class="form-control" placeholder="扫码后自动获取" style="max-width:250px;background:#f5f6fa" readonly></div>'+
    '<div class="form-group"><label>空间信息</label><span id="dlg_storage_info" style="font-size:13px;color:var(--sub);padding-top:6px">扫码后自动获取</span></div>'+
    '<div id="dlg_qr_section" style="margin-top:12px;padding:12px;background:#f9fafb;border-radius:8px">'+
    '<p style="font-size:12px;font-weight:600;margin-bottom:8px">📱 扫码获取 Cookie（仅夸克/百度）</p>'+
    '<div id="dlg_qr_status" style="font-size:12px;color:var(--sub);margin-bottom:8px">点击下方按钮生成扫码链接</div>'+
    ''+
    '<div style="margin-top:8px;display:flex;gap:8px;align-items:center">'+
    '<button class="btn btn-pri btn-sm" id="dlg_qr_btn" onclick="doStartQR()">生成扫码链接</button>'+
    '<span id="dlg_qr_hint" style="font-size:11px;color:var(--sub)"></span></div></div>'+
    '<div style="margin-top:16px;display:flex;gap:8px">'+
    '<button class="btn btn-pri" onclick="doSaveAccount()">💾 保存账号</button>'+
    '<button class="btn btn-outline" onclick="closeDialog()">取消</button></div></div></div>';

  c.innerHTML = h;
}

